下面自动编号的代码,输入送检日期,编号最后三位流水不会自动,请老师帮忙看看
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("部门代号") & "-" & 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 类别代号 = '"& 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.SQLCompute("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,"000")
Else
e.DataRow("委托单编号") = fdr("委托单编号")
End If
End If
End Select