以文本方式查看主题

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

--  作者:txtxtttt1919
--  发布时间:2017/1/4 18:34:00
--  按年份自动编号
帮助里的自动编号有按月自动编号的,按日自动编号的,按类型自动编号的,但没有按年自动编号的,举的例子代码看不太懂,哪位老师能直接写个按年自动编号的代码?
--  作者:有点色
--  发布时间:2017/1/4 19:08: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 bh As String = Format(d,"yyyy") \'生成编号的前6位,4位年,2位月.
        If e.DataRow("编号").StartsWith(bh) = False \'如果编号的前6位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(编号)","日期 >= #" & fd & "# And 日期 < #" & fd.AddYears(1) & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(bh.Length,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = bh & "-" & Format(idx,"000")
        End If
    End If
End If

--  作者:txtxtttt1919
--  发布时间:2017/1/4 19:16:00
--  
很好用,谢谢呀。但max = e.DataTable.Compute("Max(编号)","来文日期 >= #" & fd & "# And 来文日期 < #" & fd.AddYears(1) & "# And [_Identify] <> " & e.DataRow("_Identify")) 这句代码应该怎么看?
--  作者:有点色
--  发布时间:2017/1/4 19:20:00
--  

根据下面的条件,取出最大的编号。

 

日期 >= #2017-1-1# and 日期 <= #2018-1-1# and 等于当前行


--  作者:txtxtttt1919
--  发布时间:2017/1/4 19:20:00
--  
代码好像有点问题,只能生成001呀
--  作者:有点色
--  发布时间:2017/1/4 19:23: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 bh As String = Format(d,"yyyy") \'生成编号的前6位,4位年,2位月.
        If e.DataRow("编号").StartsWith(bh) = False \'如果编号的前6位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(编号)","日期 >= #" & fd & "# And 日期 < #" & fd.AddYears(1) & "# 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


--  作者:txtxtttt1919
--  发布时间:2017/1/4 19:27:00
--  
好像还是不行,只能生成001
--  作者:txtxtttt1919
--  发布时间:2017/1/4 19:46:00
--  
好像还是不行,只能生成001
--  作者:txtxtttt1919
--  发布时间:2017/1/4 19:48:00
--  

删除了之后可以生成,重置列没用。。。。,不过还是可以用了,谢谢


--  作者:有点色
--  发布时间:2017/1/5 9:44:00
--  
以下是引用txtxtttt1919在2017/1/4 19:48:00的发言:

删除了之后可以生成,重置列没用。。。。,不过还是可以用了,谢谢

 

重置列,你要重置的是日期列。