Select e.DataCol.Name
Case "编码日期","项目模式","省份","城市代码","合同甲方"
If e.DataRow.IsNull("编码日期") Or e.DataRow.IsNull("项目模式") Or e.DataRow.IsNull("城市代码") Or 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 dd As Integer = d.Day
Dim Days As Integer = Date.DaysInMonth(y,m)
Dim fd As Date = New Date(y,1,1) '获得该月的一天
Dim ld As Date = New Date(y+1,1,1) '获得该月的最后一天
Dim bh As String = e.DataRow("项目模式") & e.DataRow("省份") & e.DataRow("城市代码") & e.DataRow("合同甲方") & Format(d,"yyMMdd") '生成编号的前缀
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(bh.length)) + 1 '获得最大单据编号的后四位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("项目编号") = bh & Format(idx,"000")
End If
End If
End Select