表中Date.Now自动生成的时间格式是DateTime,忽略时间,只根据Date短日期自动生成编号
请问如何让新生编号不会冲突呢?
此主题相关图片如下:2017-08-01_112433.png

出库单_DataColChanged
If e.DataCol.Name
= "部门" Then '如果更改的是身份证号码列
If e.DataRow.IsNull("部门") Then '身份证号码是否为空
e.DataRow("出库日期") = Nothing '如果为空,则清除出生日期
ElseIf e.DataRow("出库单号") =
Nothing AndAlso e.DataRow("出库日期")
= Nothing
'否则从身份证号码列中提取出生日期
e.DataRow("出库日期") = Date.Now
End If
End If
If e.DataCol.Name
= "出库日期" Then
If e.DataRow.IsNull("出库日期") Then
e.DataRow("出库单号") = Nothing
ElseIf e.DataRow("出库单号") =
Nothing Then
Dim bh As String =
Format(e.DataRow("出库日期"),"yyyyMMdd") '取得编号的8位前缀
If e.DataRow("出库单号").StartsWith(bh)
= False '如果编号的前8位不符
Dim max As String
Dim idx As Integer
max =
e.DataTable.Compute("Max(出库单号)","出库日期 = #" &
e.DataRow("出库日期") & "# And [_Identify] <> " &
e.DataRow("_Identify")) '取得该天的最大编号
If max > "" AndAlso
max.Length >= bh.Length +3 Then '如果存在最大编号
idx =
CInt(max.Substring(bh.Length+1,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("出库单号") = bh
& "-" & Format(idx,"000")
End If
End If
End If
[此贴子已经被作者于2017/8/1 11:50:07编辑过]