想实现 按年度 按制品类别 自动编号,代码如下.可编号不正确,请教是那里出错了?
制品编号 入库日期 制品类别
AA☆-2013-001 2013-12-20 AA
BBB-2013-002 2013-12-20 BBB
BBB-2013-002 2013-12-20 BBB
BBB-2013-002 2013-12-20 BBB
出错
'入库编号
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 fd As Date = New Date(y,1,1) '
Dim ld As Date = New Date(y,12,31) '获得该年的最后一天
Dim bh As String = Format(e.DataRow("入库日期"),"yyyy") '取得编号的 位前缀
Dim qz As String = e.DataRow("制品类别").PadRight(3,"☆") & "-" & bh & "-"
If e.DataRow("制品编号").StartsWith(qz) = 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(10,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("制品编号") = qz & Format(idx,"000")
End If
End If
End Select
[此贴子已经被作者于2013-12-29 20:39:24编辑过]