由于使用的是多人操作,所以为了使主表的编号尽量不同,所以想做一个以创建时间为基础的自动编号,每秒相同的再做递增。
主要代码如下:
Dim n As Date = Date.now
Dim bh As String = Format(n,"yyyyMMddHHmmss")
If e.DataCol.Name = "创建时间" Then '如果更改的是创建时间
If e.DataRow.IsNull("创建时间") Then
e.DataRow("编号2") = Nothing
Else
If e.DataRow("编号2").StartsWith(bh) = False '如果编号的前14位不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(编号2)","创建时间 = #" & e.DataRow("创建时间") & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该天的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.SubString(15,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("编号2") = bh & "-" & Format(idx,"000")
End If
End If
End If
但是,新增行后,同一时间(相同秒)并没有序号增加,请问错在哪里?
此主题相关图片如下:tim截图20190318195057.png