这样写也是把已保存的控件数值改为空,自动生成的凭证号变成1,要再点一次新增才变为空,因为自动生成编号代码是:e.Sender.WriteValue()
Dim yzdh As WinForm.TextBox = e.Form.Controls("dh")'dh是单号控件
Dim di As String = yzdh.Value 'di单号控件中的变量
Dim d As Date = e.Sender.Value
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 Max0 As String
Dim idx As Integer
Dim s As String = e.Form.Controls("TextBox2").text
If s.length > 2 Then
s = s.SubString(0,2)
Dim flt As String = "[字号] = '" & s & "' And [日期] >= #" & fd & "# And [日期] <= #" & ld & "#"
Dim dts As Integer = DataTables("财务数据源").Compute("Count([会计科目])","[字号] = '" & s & "' And [日期] >= #" & fd & "# And [日期] <= #" & ld & "# And [凭证号] = '" & di & "'")
If dts = 0 Then
Max0 = DataTables("财务数据源").Compute("Max(凭证号)",flt) '取得该月的相同工程代码的最大单据编号
If Max0 > "" Then '如果存在最大单据编号
idx = CInt(Max0) + 1 '获得最大单据编号的后四位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
di = idx
yzdh.Value = di
End If
End If
另外我还设了一个单号,防止保存时生成重复号,因此,当窗口不是新打开的窗口,保存控件上的数据,只会是修改原控件单号,不生成新单号:
Dim yzdh1 As WinForm.TextBox = e.Form.Controls("dh1")'dh是单号控件
Dim di1 As String = yzdh1.Value 'di单号控件中的变量
Dim max1 As String
Dim idx1 As Integer
If s.length > 2 Then
s = s.SubString(0,2)
Dim flt As String = "[字号] = '" & s & "' And [日期] >= #" & fd & "# And [日期] <= #" & ld & "#"
Dim dts As Integer = DataTables("财务数据源").Compute("Count([会计科目])","[字号] = '" & s & "' And [日期] >= #" & fd & "# And [日期] <= #" & ld & "# And [凭证号] = '" & di & "'")
If dts = 0 Then
Dim bh As String = (e.Form.Controls("TextBox2").text).SubString(0,2) & "-" & Format(d,"yyyyMM") & "-" '生成编号的前缀
max1 = DataTables("财务数据源").Compute("Max(安日期生成单号辅助列)",flt) '取得该月的相同工程代码的最大单据编号
If max1 > "" Then '如果存在最大单据编号
idx1 = CInt(max1.Substring(10,5)) + 1 '获得最大单据编号的后四位顺序号,并加1
Else
idx1 = 1 '否则顺序号等于1
End If
di1 = bh & Format(idx1,"00000")
yzdh1.Value = di1
End If
End If
[此贴子已经被作者于2021/6/9 11:26:20编辑过]