我按帮助仿写了一段自动编号的代码,试运行都没问题,但在大量录入时,居然编号居然出了几次错,最后的序列编号没有累加。基本编号思路是:按同年同一合同类别自动累加序列号。请教:
'自动编写"合同or费用代码"
Dim xmdm As String = forms("合同or费用台账录入").controls("DropBox3").text '项目代码
Dim htdm As String = forms("合同or费用台账录入").controls("TextBox6").text '合同or费用代码
Dim bh As String '合同or费用编号
'根据(表-合同or费用台账)的(列-项目代码,合同or费用代码,签约日期),自动分类编辑递增顺序号后缀:
Dim qyrq As String = forms("合同or费用台账录入").controls("DateTimePicker1").Value '签约日期
Dim d As Date = Cdate(qyrq)
Dim y As String = cstr(d.Year)
y = y.SubString(0,4)
'msgbox(y)
Dim m As Integer = d.Month
Dim Days As Integer = Date.DaysInMonth(y,m)
'msgbox(days)
If xmdm <> "" Then
bh = xmdm & "-" & htdm & "-" & Format(d,"yyyyMM") & "-"
End If
'msgbox(bh)
'If Tables("合同or费用台账").Current("合同or费用编号").StartsWith(bh) = False '如果合同编号前缀不符
Dim max As String
Dim idx As Integer
Dim flt As String
flt = "项目代码 = '"& xmdm & "' And 合同or费用代码 = '"& htdm &"'And SubString(Convert([签约日期],'System.String'),1,4) = '"& y &"' And [_Identify] <> " & Tables("合同or费用台账").Current("_Identify")
'msgbox(flt)
max = DataTables("合同or费用台账").Compute("Max(合同or费用编号)",flt) '取得相同合同代码的最大合同编号
'msgbox(max)
If max = "" Then '如果最大合同编号是空
idx = 1 '顺序号等于1
Else
Dim ma As Integer
ma = max.length - 3 '或者 ma = max.LastIndexof("-")+1
idx = CInt(max.SubString((ma),3)) + 1 '获得最大合同编号的后三位顺序号,并加1
'msgbox(idx)
End If
forms("合同or费用台账录入").controls("TextBox2").text = bh & Format(idx,"000")
'检查合同编号是否正确
Dim xh As List(Of String) ' 序号
Dim xhh As Integer
xh = DataTables("合同or费用台账").GetValues("合同or费用编号")
xhh = xh.Count - 1
Dim idxx As Integer = CurrentTable.Position
msgbox(xhh)
msgbox(idxx)
If xhh <> idxx Then
msgbox("编号错误,请检查!",0,"警告:")
End If
'
'End If