以文本方式查看主题

-  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=130773)

--  作者:huangjiacai
--  发布时间:2019/1/31 16:39:00
--  [求助]自动编号
我很纳闷,在表属性-打datacolchanged中设置了代码,想完成自动编号功能,结果自动编号出来都是**001,代码如下,请教了。
Select e.DataCol.Name
    Case "部门"
        If e.DataRow.IsNull("部门") Then
            e.DataRow("人员编号") = Nothing
        Else
            Dim lb As String = GetPinYin(e.DataRow("部门"),1)
            If e.DataRow("人员编号").StartsWith(lb) = False \'如果人员编号前缀不符
                Dim max As String
                Dim idx As Integer
                max = e.DataTable.Compute("Max(人员编号)","部门 = \'" & lb & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该部门的最大编号
                If max > "" Then \'如果存在最大编号
                    idx = CInt(max.Substring(2,3)) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("人员编号") = lb & Format(idx,"000")
            End If
        End If
End Select

图片点击可在新窗口打开查看此主题相关图片如下:360截图165504228912895.png
图片点击可在新窗口打开查看
[此贴子已经被作者于2019/1/31 16:40:21编辑过]

--  作者:有点蓝
--  发布时间:2019/2/1 8:44:00
--  
Select e.DataCol.Name
    Case "部门"
        If e.DataRow.IsNull("部门") Then
            e.DataRow("人员编号") = Nothing
        Else
            Dim lb As String = GetPinYin(e.DataRow("部门"),1)
            If e.DataRow("人员编号").StartsWith(lb) = False \'如果人员编号前缀不符
                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(lb.Length,3)) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("人员编号") = lb & Format(idx,"000")
            End If
        End If
End Select

--  作者:huangjiacai
--  发布时间:2019/2/14 16:53:00
--  
谢谢老师,我试一下。