调试
Select e.DataCol.Name
Case "zdrq"
If e.DataRow.IsNull("zdrq") OrElse e.DataRow.IsNull("xmdm") Then
e.DataRow("sjid") = Nothing
Else
Dim d As Date = e.DataRow("zdrq")
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim Days As Integer = Date.DaysInMonth(y,m)
Dim fd As Date = New Date(y,m,1) '获得该月的第一天
Dim ld As Date = New Date(y,m,Days) '获得该月的最后一天
Dim bh As String = e.DataRow("xmdm") & "-" & Format(d,"yyyyMMdd") & "-" '生成编号的前缀
msgbox(bh )
If e.DataRow("sjid").StartsWith(bh) = False '如果单据编号前缀不符
Dim max As String
Dim idx As Integer
Dim flt As String
flt = "xmdm = '"& e.DataRow("xmdm") & "' And zdrq >= #" & fd & "# And zdrq <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")
msgbox(flt )
max = e.DataTable.Compute("Max(sjid)",flt) '取得该月的相同项目代码的最大单据编号
msgbox(max )
If max > "" Then '如果存在最大单据编号
idx = CInt(max.Substring(max.length - 5)) + 1 '获得最大单据编号的后五位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
msgbox(idx )
e.DataRow("sjid") = bh & Format(idx,"00000")
e.DataRow.Save
End If
End If
End Select