以业务类型—年月—0000(按业务类型自动增加),1、合同编号改为了表达式列,重新打开后,再新增行,编号从1开始计,以前的编号都没有了成了空白。
代码DataColChanged表事件:
Select e.DataCol.Name
Case "日期","业务类型"
If e.DataRow.IsNull("日期") OrElse 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 = e.DataRow("业务类型") & "-" & Format(d,"yyyyMM") & "-" '生成编号的前缀
If e.DataRow("合同编号").StartsWith(bh) = False '如果单据编号前缀不符
Dim max As String
Dim idx As Integer
Dim flt As String
flt = "业务类型 = '"& e.DataRow("业务类型") & "' And 日期 >= #" & fd & "# And 日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")
max = e.DataTable.Compute("Max(合同编号)",flt) '取得该月的相同业务类型的最大单据编号
If max > "" Then '如果存在最大单据编号
idx = CInt(max.Substring(12,4)) + 1 '获得最大单据编号的后四位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("合同编号") = bh & Format(idx,"0000")
End If
End If
End Select
2、合同编号,在关联列里不出现,因为对应做了个合同号字符列,可是只有增加行时,合同号才出现,而不是在合同编号出现时接着出现合同号。
代码DataRowAdded表事件
For Each r As Row In Tables("合同录入").Rows '将编号从表达式列提取到字符列
r("合同号") = r("合同编号")
Next