请老师帮我看看这段代码,为什么有的时候他生成重复的条码???
Select e.DataCol.Name
Case "录入日期","服装资料_B"
If e.DataRow.IsNull("录入日期") OrElse e.DataRow.IsNull("服装资料_B") 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 Integer = e.DataRow("服装资料_B") & Format(d,"MMdd") '生成编号的前缀
If e.DataRow("条码").StartsWith(bh) = False '如果条码前缀不符
Dim max As String
Dim idx As Integer
Dim flt As String
flt = "服装资料_B = '"& e.DataRow("服装资料_B") & "' And 录入日期 >= #" & fd & "# And 录入日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")
max = e.DataTable.Compute("Max(条码)",flt) '取得该月的相同服装资料_B的最大条码
If max > "" Then '如果存在最大条码
idx = CInt(max.Substring(0,3)) + 1 '获得最大条码的后四位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("条码") = Format(idx,"000") & bh
End If
End If
End Select