Select e.DataCol.Name
Case "KJN","KJY"
If e.DataRow.IsNull("KJN") OrElse e.DataRow.IsNull("KJY") Then
e.DataRow("PZH") = Nothing
Else
Dim lb As String = e.DataRow("KJN") & "-" & e.DataRow("KJY") & "-"
If e.DataRow("PZH").StartsWith(lb) = False '如果单据编号前缀不符
Dim max As String
Dim idx As Integer
Dim flt As String
flt = e.DataTable.Compute("Max(PZH)","PZH like '" & lb & "%' And [_Identify] <> " & e.DataRow("_Identify")) '取得该类别的最大编号
max = e.DataTable.Compute("Max(PZH)",flt)
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(lb.length)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("PZH") = lb & Format(idx,"0000")
End If
End If