Select e.DataCol.Name
Case "零件分类","零件名称" ,"零件类型"
If e.DataRow.IsNull("零件分类") Or e.DataRow.IsNull("零件类型") Then
e.DataRow("零件代码") = Nothing
Else
Dim X As String = GetPY(e.DataRow("零件类型"),True)
Dim Y As String = GetPY(e.DataRow("零件分类"),True)
Dim lb As String
If X. Length = 2 And y.length = 3 Then
lb=GetPY(e.DataRow("零件类型"),True) & "-" & GetPY(e.DataRow("零件分类"),True)
Else
If x.length<3 Or Y.length <4 Then
lb=X.padright(2,"0") & "-" & Y.padright(3,"0")
Else
lb=x.SubString(0, 2) & "-" & Y.SubString(0, 3)
End If
End If
If e.DataRow("零件代码").StartsWith(lb) = False '如果单据零件代码前缀不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(零件代码)", lb & " ' And [_Identify] <> " & e.DataRow("_Identify")) '取得该首写简码的最大零件代码
If max > "" Then '如果存在最大零件代码
idx = CInt(max.Substring(7,4)) + 1 '获得最大零件代码的后四位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("零件代码") = lb & Format(idx,"0000")
End If
End If
End Select