以文本方式查看主题

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

--  作者:bigpeng
--  发布时间:2025/2/4 15:23:00
--  如何实现按年度自动编号
帮助里只看到按月编号和按日编号的,尝试了在按日编号基础上修正后进行按年自动编号出现错误,麻烦老师帮忙指正


If e.DataCol.Name = "录入时间" Then
    If e.DataRow.IsNull("录入时间") Then
        e.DataRow("年度编号") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("录入时间"), "yyyy") 
        If e.DataRow("年度编号").StartsWith(bh) = False Then
            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
            Else
                idx = 1
            End If
            e.DataRow("年度编号") = bh & "-" & Format(idx, "000")
        End If
    End If
End If

--  作者:有点蓝
--  发布时间:2025/2/5 9:53:00
--  
参考按月的用法

        If e.DataRow("年度编号").StartsWith(bh) = False Then
            Dim max As String
            Dim idx As Integer
            Dim fd As Date = New Date(y,1,1\'获得该年的第一天
            Dim ld As Date = 
fd.addyears(1) \'
获得下年的第一天
            max = e.DataTable.Compute("Max(年度编号)", "录入时间 >= #" & fd  & "# and 录入时间 < #" & ld  & "# And [_Identify] <> " & e.DataRow("_Identify")) 



--  作者:bigpeng
--  发布时间:2025/2/5 10:43:00
--  
非常感谢!