要实现收据编号的后5位是流水号。编码是帮助里的:
'收据编号自动录入 (项目代码-制单日期-流水号)
Select e.DataCol.Name
Case "zdrq","sjid"
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") & "-" '生成编号的前缀
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")
max = e.DataTable.Compute("Max(sjid)",flt) '取得该月的相同项目代码的最大单据编号
If max > "" Then '如果存在最大单据编号
idx = CInt(max.Substring(13,5)) + 1 '获得最大单据编号的后五位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("sjid") = bh & Format(idx,"00000")
e.DataRow.Save
End If
End If
End Select
能帮我看看是错在什么地方吗?谢谢!