比如,你要手动编号,就在前面加入字母 sd_ 如 sd_201705-005
代码修改成
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") '生成编号的前6位,4位年,2位月
If e.DataRow("单据编号").startswith(bh) = False '如果编号的前6位不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("max(单据编号)","单据编号 not like 'sd_%' and 制单日期 >= #" & fd & "# and 制单日期 <= #" & ld & "# and [_identify] <> " & e.DataRow("_identify")) '取得该月的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.SubString(7,3)) + 1 '获取最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("单据编号") = bh & "-" & Format(idx,"000")
End If
End If
End If