Select e.DataCol.Name Case "送检日期","外协单位" 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 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 = "AKP" & Format(d,"yyMM") 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") Dim fdr As DataRow = e.DataTable.find(flt & " and 送检编码 is not null and 送检日期 = #" & d & "#") If fdr Is Nothing Then 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") Else e.DataRow("送检编码") = fdr("送检编码") End If End If End If End Select
|