以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  按日生成编号,需要加字符如何修改一下代码?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=88904)

--  作者:zch1104
--  发布时间:2016/8/11 12:09:00
--  按日生成编号,需要加字符如何修改一下代码?

如显示出来应该是“XSCK20160811-000

 

 

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


--  作者:大红袍
--  发布时间:2016/8/11 12:23:00
--  

If e.DataCol.Name = "日期" Then
    If e.DataRow.IsNull("日期") Then
        e.DataRow("编号") = Nothing
    Else
        Dim bh As String = "XSCK" & 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,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = bh & "-" & Format(idx,"000")
        End If
    End
If
End
If


--  作者:zch1104
--  发布时间:2016/8/11 12:59:00
--  

老师,用你的代码,没有变化,什么都没有。

你只改动了     idx = CInt(max.Substring(bh.length+1,3)) + 1 \'获得最大编号的后三位顺序号,并加1
还有“XSCK”字符应该加在那?

才会显示出来,我需要的编号“XSCK20160811-001


--  作者:zch1104
--  发布时间:2016/8/11 13:08:00
--  

谢谢,我找到原因了,但是我还想问,   

 

idx = CInt(max.Substring(bh.length+1,3)) + 1 \'获得最大编号的后三位顺序号,并加1   

 

  idx = CInt(max.Substring(9,3)) + 1 \'获得最大编号的后三位顺序号,并加1    有什么区别,就把原来的9改了   +1  为什么?


--  作者:大红袍
--  发布时间:2016/8/11 14:42:00
--  

因为你的编号是前面的 bh 加 - 加 数字

 

编号的长度+1以后,就是截取到数字的值