以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]记录编号出现重复或空值  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=113766)

--  作者:沪上游客
--  发布时间:2018/1/22 18:36:00
--  [求助]记录编号出现重复或空值
老师你好!
我在表的DataColChanged设置了以下代码:
If e.DataCol.Name = "录入日期" Then
    If e.DataRow.IsNull("录入日期") Then
        e.DataRow("记录编号") = Nothing
    Else
        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 > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(11,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("记录编号") = "SZ" & bh & "-" & Format(idx,"000")
        End If
    End If
End If

“录入日期”列为增加行时自动填入,现在出现好多重复编号(同样的记录编号或空值),在一天中同时有不同的用户(有的部门不同)输入会出现,我的项目是按照部门加载记录的。
请老师指教有什么办法?谢谢!

--  作者:有点甜
--  发布时间:2018/1/22 18:38:00
--  
If e.DataCol.Name = "录入日期" Then
    If e.DataRow.IsNull("录入日期") Then
        e.DataRow("记录编号") = Nothing
    Else
        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.sqlCompute("Max(记录编号)","录入日期 = #" & e.DataRow("录入日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(11,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("记录编号") = "SZ" & bh & "-" & Format(idx,"000")
            e.DataRow.Save
        End If
    End If
End If

--  作者:沪上游客
--  发布时间:2018/1/22 22:42:00
--  
谢谢老师!
已解决,只是日期两边的#要改成单引号。查了半天。哈哈。。。