各位老师,请问,我编写了如下代码,我发现以下代码自动编号时,我发现这段代码的自动编号列加顺序号的时候是判断最大值是从加载的表算起,不算没有加载的,比如,后台数据中有WLRK-201501-05,加载的表中最大是WLRK-201501-03,当我自动加行时生成的号时WLRK-201501-04,不是WLRK-201501-06
If e.DataCol.Name = "入库时间" Then
If e.DataRow.IsNull("入库时间") Then
e.DataRow("制单编号") = Nothing
Else
Dim d As Date = e.DataRow("入库时间")
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 = Format(d,"yyyyMM")
If e.DataRow("制单编号").StartsWith(bh) = False '如果制单编号的前8位不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(制单编号)","入库时间 >= '" & fd & "' and 入库时间 <= ' " & ld & " ' And [_Identify] <> " & e.DataRow("_Identify")) '取得该天的最大制单编号
If max > "" Then '如果存在最大制单编号
idx = CInt(max.Substring(12,2)) + 1 '获得最大制单编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("制单编号") = "WLRK-" & bh & "-" & Format(idx,"00")
End If
End If
End If