Dim d As Date = Date.Today
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim bh As String = Format(d,"yyyyMM") '生成编号的前6位,4位年,2位月.
Dim max As String
Dim idx As Integer
max = DataTables("配货单").SQLCompute("Max(入库单号)","入库单号 like '" & bh & "%'")
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(bh.length)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
For Each r As DataRow In DataTables("扫描配货明细").DataRows
Dim drs As List(of DataRow) = DataTables("配货单").SQLSelect("SN = '" & r("SN") & "'")
If drs.count >0 Then
For Each dr As DataRow In drs
dr("入库单号") = "RK" & bh & Format(idx,"000")
dr("预入库单号") = "RK" & bh & Format(idx,"000")
dr.save
DataTables("扫描配货明细").load
Next
End If
Next