以文本方式查看主题

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

--  作者:sbfqpidt
--  发布时间:2016/11/28 22:16:00
--  分别自动编号

图片点击可在新窗口打开查看此主题相关图片如下:理想的编号图.png
图片点击可在新窗口打开查看



老师好:
    我想在一个表里,按月、分别按类别编号。上图是我想要做的理想编号。可是我做不到,下图是我的实际图,达不到我的理想:
   
图片点击可在新窗口打开查看此主题相关图片如下:分别自动编号.png
图片点击可在新窗口打开查看
 
     下面是我复制的改变后的代码:
\'按月生成编号
\'将表事件DataColChanged的代码设置为:

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 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 bh As String = Format(d,e.DataRow("帐套") & "-" & "yyMM") \'生成编号的前6位,2位年,2位月.
        If e.DataRow("合同评审单编号").StartsWith(bh) = False \'如果编号的前6位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(合同评审单编号)","生产下单日期 >= #" & fd & "# And 生产下单日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
            
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(6,4)) + 1 \'获得最大编号的后四位顺序号,并加1
                
            Else
                idx = 1 \'否则顺序号等于1
            End If
               e.DataRow("合同评审单编号") = bh & "" & Format(idx,"0000")
        End If
    End If
End If


  请万忙中给予指导!
  谢谢!

--  作者:有点蓝
--  发布时间:2016/11/28 22:22:00
--  
max = e.DataTable.Compute("Max(合同评审单编号)","帐套 = \'" & e.DataRow("帐套") & "\' and 生产下单日期 >= #" & fd & "# And 生产下单日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
--  作者:sbfqpidt
--  发布时间:2016/11/28 22:37:00
--  
谢谢老师!
帮助里说得很清楚了!
是我没认真看帮助。
这是我改的编码,已能达到我想要的效果了!
谢谢!
Select e.DataCol.Name
    Case "生产下单日期","帐套"
        If e.DataRow.IsNull("生产下单日期") OrElse e.DataRow.IsNull("帐套") Then
            e.DataRow("合同评审单编号") = Nothing
        Else
            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 bh As String = e.DataRow("帐套") & "-" & Format(d,"yyMM") \'生成编号的前缀
            If e.DataRow("合同评审单编号").StartsWith(bh) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "帐套 = \'"& e.DataRow("帐套") & "\' And 生产下单日期 >= #" & fd & "# And 生产下单日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(合同评审单编号)",flt) \'取得该月的相同工程代码的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(6,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("合同评审单编号") = bh & Format(idx,"0000")
            End If
        End If
End Select