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 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") 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.SqlCompute("Max(项目编码)",flt) '取得该年的相同项目模式的最大编号 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 If End Select
|