哇,太感动了,居然帮我写出来。。。
这个我自己琢磨出来写的,也能行:
If e.DataCol.Name = "项目日期" Then
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 fd As Date = New Date(y,1,1)
Dim ld As Date = New Date(y,12,31)
Dim bh As String = Format(d,"yy")
If e.DataRow("项目编号").StartsWith(bh) = False
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(项目编号)","项目日期 >= #" & fd & "# And 项目日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify"))
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(2,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1
End If
e.DataRow("项目编号") = bh & Format(idx,"000") & e.DataRow("项目类型")
End If
End If
End If