下面帮助,每个先看3遍
然后学会调试
Select e.DataCol.Name
Case "分组", "分类名"
If e.DataRow.IsNull("分组") OrElse e.DataRow.IsNull("分类名") Then
e.DataRow("分类ID") = Nothing
Else
Dim d As String = e.DataRow("分组")
Dim bh As String = "G" & "-" '生成编号的前缀
If e.DataRow("分类ID").StartsWith(bh) = False Then'如果单据编号前缀不符
Dim max As String
Dim idx As Integer
Dim flt As String
flt = "分组 = '" & d & "' = '" & e.DataRow("分类名") & "' And [_Identify] <> " & e.DataRow("_Identify")
MsgBox(flt)
max = e.DataTable.Compute("Max(分类ID)", flt) '取得该月的相同工程代码的最大单据编号
If max > "" Then '如果存在最大单据编号
MsgBox(max)
idx = CInt(max.Substring(12, 4)) + 1 '获得最大单据编号的后四位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
MsgBox(bh & Format(idx, "0000"))
e.DataRow("分类ID") = bh & Format(idx, "0000")
End If
End If
End Select