Datacolchanged代码
Select e.DataCol.Name
Case "订货客户"
If e.DataRow.IsNull("订货客户") Then
e.DataRow("订单号") = Nothing
Else
Dim fdr As DataRow = DataTables("客户").Find("名称 = '" & e.DataRow("订货客户") & "'")
If fdr IsNot Nothing Then
Dim lb As String = fdr("客户代码")
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 If
End If
End Select