参考代码
Select e.DataCol.Name
Case "容量","电压","外壳直径","膜厚","相别"
Dim lb As String = ""
If e.DataRow.IsNull("外壳直径") Then
lb &= "00"
Else
Dim s As String = e.DataRow("外壳直径")
lb &= iif(s.length > 2, s.SubString(0,2), s)
End If
If e.DataRow.isnull("电压") Then
lb &= "00"
Else
Dim s As String = e.DataRow("电压")
lb &= iif(s.length > 2, s.SubString(0,2), s)
End If
If e.DataRow.isnull("膜厚") Then
lb &= "00"
Else
Dim s As String = e.DataRow("膜厚")
lb &= iif(s.length > 2, s.SubString(0,2), s)
End If
If e.DataRow.isnull("相别") Then
lb &= "00"
Else
Dim s As String = e.DataRow("相别")
lb &= iif(s.length > 2, s.SubString(0,2), s)
End If
If e.DataRow("产品编号").StartsWith(lb) = False '如果单据编号前缀不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("max(产品编号)", "产品编号 like '" & lb & "%' and _Identify <> " & e.DataRow("_Identify")) '取得该类别的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(lb.length,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("产品编号") = lb & Format(idx,"000")
End If
End Select