老师:您好! 我编号要找当日本月的最大编号,自动编号,如果有就接着编,如果没有就从1开始。我的代码是找到上一行的最大编号。
请求帮助!
Dim dl As Date = Date.Today
Dim y As Integer = dl.Year
Dim m As Integer = dl.Month
Dim d As Integer = dl.day
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 = Format(dl, "yyyyMM") '生成编号的前6位,4位年,2位月.
If e.DataRow("清单条码编码").StartsWith(bh) = False Then'如果编号的前8位不符
Dim max As String
Dim idx As Integer
max = e.DataTable.C ompute("Max(清单条码编码)", "[_Identify] <> " & e.DataRow("_Identify")) '取得该月的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(max.length - 6)) + 1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("清单条码编码") = bh & Format(idx, "000000")
End If
11
[此贴子已经被作者于2024/11/7 16:59:06编辑过]