以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  求按类别分月自动编号  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=178070)

--  作者:13315253800
--  发布时间:2022/6/16 16:47:00
--  求按类别分月自动编号

老师您好!帮助中《自动编号生成方法》按类别编号的代码

Select e.DataCol.Name
    Case
"
类别"
       
If e.DataRow.IsNull("类别") Then
            e.DataRow("
编号") = Nothing
        Else
            Dim
lb As String = e.DataRow("
类别")
            If
e.DataRow("
编号").StartsWith(lb) = False \'如果单据编号前缀不符
               
Dim max As String
               
Dim idx As Integer
                max = e.DataTable.Compute("Max(
编号)","类别 = \'" & lb & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该类别的最大编号
               
If max > "" Then \'如果存在最大编号
                    idx = CInt(max.Substring(2,3)) + 1 \'
获得最大编号的后三位顺序号,并加1
               
Else
                    idx = 1 \'
否则顺序号等于1
               
End If
                e.DataRow("
编号") = lb & Format(idx,"000")
            End
If
        End
If
End
Select

我想按类别分月自动编号,代码不知怎么改一下,也翻阅了论坛中有关自动编号的帖子,我没能找到。我的需求是:

表中设有“类别”、“ 日期”、“ 编号”三列。编号为“类别”+3位顺序号,如“DM001”。只是分月单独编号,如6月份第一、第二个编号分别为“DM001”、“DM002”,到7月份的第一、第二个编号仍分别为“DM001”、“DM002”,其他以此类推。也就是一个月份一重新编号,当月编号无重复,全年有重复,编号中无日期,但与日期又相关。


--  作者:有点蓝
--  发布时间:2022/6/16 17:01:00
--  
加上月份做条件即可:http://www.foxtable.com/webhelp/topics/2403.htm
--  作者:有点蓝
--  发布时间:2022/6/16 17:02:00
--  
            Dim d As Date = e.DataRow("日期")
            Dim y As Integer = d.Year
            
Dim m As Integer = d.Month
            Dim Days As Integer = Date.DaysInMonth(y,m)
            Dim fd As Date = New Date(y,m,1
\'
获得该月的第一天
            Dim ld As Date = New Date(y,m,Days) 
\'
获得该月的最后一天
Dim lb As String = e.DataRow("类别")
            If
 e.DataRow("
编号").StartsWith(lb) = False \'如果单据编号前缀不符
                
Dim max As String
                
Dim idx As Integer
                max = e.DataTable.Compute("Max(
编号)","类别 = \'" & lb & "\'  And 日期 >= #" & fd & "# And 日期 <= #" & ld & "#  And [_Identify] <> " & e.DataRow("_Identify")) \'取得该类别的最大编号

--  作者:13315253800
--  发布时间:2022/6/16 17:40:00
--  
谢谢蓝老师