Select e.DataCol.Name
Case "销售日期","代码"
If e.DataRow.IsNull("销售日期") OrElse e.DataRow.IsNull("代码") Then
e.DataRow("销售单编号") = Nothing
Else
Dim dg As Date = e.DataRow("销售日期")
Dim yg As Integer = dg.Year
Dim mg As Integer = dg.Month
Dim Days As Integer = Date.DaysInMonth(yg,mg)
Dim fdg As Date = New Date(yg,mg,1) \'获得该月的第一天
Dim ldg As Date = New Date(yg,mg,Days) \'获得该月的最后一天
Dim bhg As String = e.DataRow("代码") & "-" & Format(dg,"yyyyMM") & "-"
If e.DataRow("销售单编号").StartsWith(bhg) = False \'如果单据编号前缀不符
Dim maxg As String
Dim idxg As Integer
Dim fltg As String
fltg = "代码 = \'"& e.DataRow("代码") & "\' And 销售日期 >= #" & fdg & "# And 销售日期 <= #" & ldg & "# And [_Identify] <> " & e.DataRow("_Identify")
maxg = e.DataTable.Compute("Max(销售单编号)",fltg)
If maxg > "" Then \'如果存在最大单据编号
idxg = CInt(maxg.Substring(12,3)) + 1
Else
idxg = 1 \'否则顺序号等于1
End If
e.DataRow("销售单编号") = bhg & Format(idxg,"000")
End If
End If
End Select