以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  按年生成流水号  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=22053)

--  作者:穆紫1212
--  发布时间:2012/8/1 12:07:00
--  按年生成流水号
请教一个问题,帮助菜单里有按月生成流水号的,我想按年生成流水号该怎么做?
--  作者:狐狸爸爸
--  发布时间:2012/8/1 13:54:00
--  

理解帮助提供的代码,然后在帮助的基础上修改:

 

If e.DataCol.Name = "日期" Then
    If e.DataRow.IsNull("日期") Then
        e.DataRow("编号") = Nothing
    Else
        Dim d As Date = e.DataRow("日期")
        Dim y As Integer = d.Year
        Dim fd As Date = New Date(y,1,1) \'获得该年的第一天
        Dim ld As Date = New Date(y,12,31) \'获得该年的最后一天
        Dim bh As String = Format(d,"yyyy") \'生成编号的前4位,4位年
        If e.DataRow("编号").StartsWith(bh) = False \'如果编号的前4位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(编号)","日期 >= #" & fd & "# And 日期 <= #" & ld & "#") \'取得该月的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(5,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = bh & "-" & Format(idx,"000")
        End If
    End If
End If

[此贴子已经被作者于2012-8-1 14:00:02编辑过]

--  作者:unverse
--  发布时间:2012/8/1 14:18:00
--  
帮助里一改就OK
--  作者:穆紫1212
--  发布时间:2012/8/1 14:53:00
--  
哦,是这样改呀,我差不多弄了一个星期,也没弄明白,就像狐爸说的那样,对代码的理解不够,但有的时候真的弄不明白呀,看起来菜鸟学习还真是费点尽。谢谢狐爸!