以文本方式查看主题

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

--  作者:kuangshp
--  发布时间:2014/12/27 14:13:00
--  自动编号
If e.DataCol.Name = "日期" Then
    If e.DataRow.IsNull("日期") Or e.DataRow.Isnull("工程代码") Then
        e.DataRow("编号") = Nothing
    Else
        Dim x As String = Format(e.DataRow("工程代码"))
        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(9,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = "xxxx" & "-" & bh & "-" & Format(idx,"0000")
        End If
    End If
End If


自动编号中,在表的事件里编写了代码结果为上图,我要求的结果是:cgrk-20141227-0001,cgrk-20141227-0002,cgrk-20141227-0003,cgrk-20141227-0004
图片点击可在新窗口打开查看此主题相关图片如下:1111.png
图片点击可在新窗口打开查看

--  作者:kuangshp
--  发布时间:2014/12/27 17:16:00
--  感谢
谢谢