以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  自动编号  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=85634)

--  作者:674140303
--  发布时间:2016/5/30 16:46: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.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("编号") = bh & "-" & Format(idx,"000")
        End If
    End
If

End
If



这段代码生成的编号为“日期+000”型,想给前面加两个字母,为“AA+日期+000”型,该怎么改?


--  作者:大红袍
--  发布时间:2016/5/30 16:48:00
--  
If e.DataCol.Name = "日期" Then
    If e.DataRow.IsNull("日期") Then
        e.DataRow("编号") = Nothing
    Else
        Dim bh As String = "AA" & 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(bh.length+1)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = bh & "-" & Format(idx,"000")
        End If
    End If
End If

--  作者:674140303
--  发布时间:2016/5/30 17:09:00
--  
谢谢