以文本方式查看主题

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

--  作者:taigor
--  发布时间:2011/12/28 15:59:00
--  [求助]自动编号前加前缀求教!
请教工程师,您看下下面代码,生成的编号格式为:20111228-001
我需要在这个编号前加前缀,比如生成 YP20111228-001,编号统一以“YP”开头,请教代码该怎么写?
多谢多谢!!!!!

If e.DataCol.Name = "日期" Then
    If e.DataRow.IsNull("日期") Then
        e.DataRow("编号") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("日期"),"yyyyMMdd") 
        If e.DataRow("编号").StartsWith(bh) = False 
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(编号)","日期 = #" & e.DataRow("日期") & "#") 
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(9,3)) + 1 
            Else
                idx = 1 
            End If
            e.DataRow("编号") = bh & "-" & Format(idx,"000")
        End If
    End If
End If

--  作者:狐狸爸爸
--  发布时间:2011/12/28 16:01:00
--  
If e.DataCol.Name = "日期" Then
    If e.DataRow.IsNull("日期") Then
        e.DataRow("编号") = Nothing
    Else
        Dim bh As String = "YP" & Format(e.DataRow("日期"),"yyyyMMdd")
        If e.DataRow("编号").StartsWith(bh) = False
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(编号)","日期 = #" & e.DataRow("日期") & "#")
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(11,3)) + 1
            Else
                idx = 1
            End If
            e.DataRow("编号") = bh & "-" & Format(idx,"000")
        End If
    End If
End If

--  作者:taigor
--  发布时间:2011/12/28 16:04:00
--  
多谢多谢!!真够效率!!