Select e.DataCol.Name
Case "送检_送检日期","代号","预算编号"
If e.DataRow.IsNull("送检_送检日期") OrElse 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") & "-"
Dim max As String
Dim idx As Integer
Dim flt As String
flt = "代号 = '"& e.DataRow("代号") & "' And 预算编号 = '"& e.DataRow("预算编号") & "' and 送检_送检日期 >= #" & fd & "# And 送检_送检日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")
Dim flt2 = "代号 = '"& e.DataRow("代号") & "' and 送检_送检日期 >= #" & fd & "# And 送检_送检日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")
Dim fdr As DataRow = e.DataTable.find(flt & " and 送检_送检单编号 is not null and 送检_送检日期 = #" & d & "#")
If fdr Is Nothing Then
max = e.DataTable.Compute("Max(送检_送检单编号)",flt2) '取得该月的相同部门代号的最大报告单送检_送检单编号
If max > "" Then '如果存在最大报告单送检_送检单编号
idx = CInt(max.Substring(bh.length+1)) + 1 '获得最大报告单送检_送检单编号的后四位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("送检_送检单编号") = bh & Format(idx,"0000")
Else
e.DataRow("送检_送检单编号") = fdr("送检_送检单编号")
End If
End If
End Select