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(d,"yyyy") & "-" & e.DataRow("样品标识") & "-" '生成编号的前缀
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")
max = e.DataTable.Compute("Max(样品编号)",flt) '取得该年的相同样品标识的最大单据编号
If max > "" Then '如果存在最大单据编号
idx = CInt(max.Substring(12,3)) + 1 '获得最大单据编号的后四位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("样品编号") = "YP-" & bh & Format(idx,"000")
End If
End If
End Select
目前已经能按照不同样品类型和日期生成样品编号,但机构变化后,样品编号还是按照原来机构的编号顺排,不会重新开始编号。求助!