'需求说明:
'给在客户交易表(YW_XSYW_KHJY)中对客户交易编号字段:KHJY_CODE字段自动进行编号,编号形式类似:JY2016-000001234
'编号方法是:JY+项目编号(LXTZ_CODE)中的年份(e.DataROW("LXTZ_CODE").SubString(5,4)),加上-号,加上9位定长顺序号,000000001
If e.DataRow.IsBull("KHJY_NAME") OrElse e.DataRow.IsNull("LXTZ_CODE") Then
e.DataRow("KHJY_CODE") = Nothing
Else
Dim lb As String = "JY"
Dim max As String
Dim idx As Integer
Dim year As String = e.DataRow("LXTZ_CODE").SubString(4,4)
lb = lb & year & "-"
max = e.DataTable.Computer("Max(KHJY_CODE)",lb And [_Identify] <> &e.DatatRow("_Identify")) '取得该年编号的最大值
If max > "" Then '如果有最大编号
idx = CInt(max.SubString(7,9) + 1
Else
idx = 1
End If
e.DataRow("KHJY_CODE") = lb & Format(idx,"000000000")
End If
|