If e.DataCol.Name = "下单日期" orelse e.DataCol.Name = "客户编码" Then
If e.DataRow.IsNull("下单日期") OrElse e.DataRow.IsNull("客户编码") Then
e.DataRow("销售订单号") = Nothing
Else
Dim dr As DataRow = e.DataTable.Find("下单日期 = #" & e.DataRow("下单日期") & "# and 客户编码='" & e.DataRow("客户编码") & "' and [_Identify] <> " & e.DataRow("_Identify"))
If dr IsNot Nothing Then
e.DataRow("销售订单号") = dr("销售订单号")
Else
Dim bh As String = Format(e.DataRow("下单日期"),"yyyyMM") '取得编号的8位前缀
If e.DataRow("销售订单号").StartsWith(bh) = False '如果编号的前8位不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(销售订单号)","下单日期 = #" & e.DataRow("下单日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该天的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(9,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("销售订单号") = bh & Format(idx,"0000")
End If
End If
End If
End If
[此贴子已经被作者于2018/1/6 15:49:03编辑过]