'自动获取类别代码并生成机具编号
Sel ect e.DataCol.Name
Case "类别代码"
If e.DataRow.IsNull("定额编码")=False Or e.DataRow.IsNull("类别代码") Then
Return
Else
If e.DataRow.IsNull("类别代码")=False Then
Dim lb As String = e.DataRow("类别代码")
'If e.DataRow("定额编码").StartsWith(lb) =False '如果单据机具编号前缀
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(定额编码)","类别代码 = '" & lb & "' and 定额编码 like '" & lb & "%' And [_Identify] <> " & e.DataRow("_Identify")) '取得该类别代码的最大机具编号
If max > "" Then '如果存在最大机具编号
idx = CInt(max.Substring(2,5))+ 1 'CInt(max.Substring(2,5)) 获得最大机具编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("定额编码") = lb & Format(idx,"00000")
'End If
End If
End If
End Select
这样就可以了。满足我的使用了。