datacolchaned事件
Select Case e.DataCol.name
Case "签订日期", "领域"
Dim bh As String = e.DataRow("领域") & Format(e.DataRow("签订日期"),"yyMMdd") '取得编号的7位前缀
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(合同单号)","领域 = '" & e.DataRow("领域") & "' And 签订日期 = #" & e.DataRow("签订日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该天的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(bh.length,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号(起始号)等于1(有签订日期,无合同编号时的判断)
End If
e.DataRow("合同单号") = bh & Format(idx,"000")
end select