老师,我生成申请单号,以下代码还有出现重复情况,请老师看看怎么处理?
生成申请单号编码(代码放在保存按钮中):
If a.IsNull("申请单号") Then
a("登记人") = _UserXingMing
a("登记日期") = Functions.Execute("服务器时间")
a("申请单号") = Functions.Execute("委托支付编码")
a("审批状态") = "待财务部制单审批"
a("ID") = Guid.NewGuid.TOstring()
a("登记状态") = True
a.save
生成申请单号的内部函数如下:
''生成申请单号
Dim dt As DataTable = DataTables("委托支付管理")
Dim dr As Row = Tables("委托支付管理").Current
If dr.IsNull("登记日期") Then
dr("申请单号") = Nothing
Else
Dim d As Date = dr("登记日期")
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 dr("申请单号").StartsWith(bh) = False '如果申请单号的前6位不符
Dim max As String
Dim idx As Integer
max = dt.sqlCompute("Max(申请单号)","登记日期 >= '" & fd & "' And 登记日期 <= '" & ld & "' And [_Identify] <> " & dr("_Identify")) '取得该月的最大申请单号
If max > "" Then '如果存在最大申请单号
idx = CInt(max.Substring(7,3)) + 1 '获得最大申请单号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
dr("申请单号") = bh & "-" & Format(idx,"000")
End If
End If
Return dr("申请单号")
[此贴子已经被作者于2020/1/13 15:51:20编辑过]