Static Lastbh As String '通过这个Static变量可以访问上一次生成的编号,避免重复Compute
Dim prefix As String = Format(Date.now,"yyyyMMdd") '本次编号前缀
If Lastbh >"" AndAlso Lastbh.SubString(0,8) = prefix Then '如果上一次生成编号的前缀和本次相同
Lastbh = prefix & "-" & Format(Cint(Lastbh.SubString(8,3)) + 1,"000") '在上次编号的基础上递增1
Else
'取数据表中同前缀的最大编号
Dim max As String=DataTables("客户资料").sqlCompute("Max(销售日编号)","销售日编号 like '" & prefix & "%'")
If max = "" Then '如果不存在同前缀的编号
Lastbh = prefix & "001" '同前缀的第一个编号
Else
Lastbh = prefix & "-" & Format(CInt(max.SubString(8,3)) + 1,"000") '在同前缀最大编号的基础上递增1
End If
End If
Return Lastbh