以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  自动编号问题(按日期、国别和类别不同,产生自动编号)  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=48558)

--  作者:yangcin
--  发布时间:2014/3/31 20:57:00
--  自动编号问题(按日期、国别和类别不同,产生自动编号)
Select e.DataCol.Name
    Case "贸易国别","销售类型"
        If e.DataRow.IsNull("贸易国别") OrElse e.DataRow.IsNull("销售类型") Then
            e.DataRow("销售单号") = Nothing
        Else
            Dim gb As String = e.DataRow("贸易国别")
            If e.DataRow("贸易国别") = "中国" Then
                gb = "D"
            Else
                gb = "F"
            End If
            Dim lx As String = e.DataRow("销售类型")
            If e.DataRow("销售类型") = "零售" Then
                lx = "SS"
            Else
                lx = "SC"
            End If
            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 = gb & lx & "-" & Format(d,"yyMM") & "-" \'生成编号的前缀
            If e.DataRow("销售单号").StartsWith(bh) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "贸易国别 = \'gb\'And 销售类型 = \'lx\' And 制单日期 >= #" & fd & "# And 制单日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(销售单号)",flt) \'取得该月的相同贸易国别贸易方式的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(8,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("销售单号") = bh & Format(idx,"0000")
            End If
        End If
End Select

问题:

序号不自动增加。

--  作者:有点甜
--  发布时间:2014/3/31 21:20:00
--  
Select e.DataCol.Name
    Case "贸易国别","销售类型"
        If e.DataRow.IsNull("贸易国别") OrElse e.DataRow.IsNull("销售类型") Then
            e.DataRow("销售单号") = Nothing
        Else
            Dim gb As String = e.DataRow("贸易国别")
            If e.DataRow("贸易国别") = "中国" Then
                gb = "D"
            Else
                gb = "F"
            End If
            Dim lx As String = e.DataRow("销售类型")
            If e.DataRow("销售类型") = "零售" Then
                lx = "SS"
            Else
                lx = "SC"
            End If
            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 = gb & lx & "-" & Format(d,"yyMM") & "-" \'生成编号的前缀
            If e.DataRow("销售单号").StartsWith(bh) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "贸易国别 = \'gb\' And 销售类型 = \'lx\' And 制单日期 >= #" & fd & "# And 制单日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(销售单号)",flt) \'取得该月的相同贸易国别贸易方式的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(9,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("销售单号") = bh & Format(idx,"0000")
            End If
        End If
End Select
[此贴子已经被作者于2014-3-31 21:24:25编辑过]

--  作者:yangcin
--  发布时间:2014/3/31 21:41:00
--  
还是没变化呢?
--  作者:有点甜
--  发布时间:2014/3/31 21:44:00
--  
以下是引用yangcin在2014-3-31 21:41:00的发言:
还是没变化呢?

 

自动编号,不是你新增一行就编号的,是你必须先填入 制单日期、贸易国别、销售类型,才会自动生成的。


--  作者:有点甜
--  发布时间:2014/3/31 21:45:00
--  

呃,写错了

 

Select e.DataCol.Name
    Case "贸易国别","销售类型"
        If e.DataRow.IsNull("贸易国别") OrElse e.DataRow.IsNull("销售类型") Then
            e.DataRow("销售单号") = Nothing
        Else
            Dim gb As String = e.DataRow("贸易国别")
            If e.DataRow("贸易国别") = "中国" Then
                gb = "D"
            Else
                gb = "F"
            End If
            Dim lx As String = e.DataRow("销售类型")
            If e.DataRow("销售类型") = "零售" Then
                lx = "SS"
            Else
                lx = "SC"
            End If
            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 = gb & lx & "-" & Format(d,"yyMM") & "-" \'生成编号的前缀
            If e.DataRow("销售单号").StartsWith(bh) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "贸易国别 = \'" & gb & "\' And 销售类型 = \'" & lx & "\' And 制单日期 >= #" & fd & "# And 制单日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(销售单号)",flt) \'取得该月的相同贸易国别贸易方式的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(9,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("销售单号") = bh & Format(idx,"0000")
            End If
        End If
End Select

--  作者:yangcin
--  发布时间:2014/3/31 21:48:00
--  
有点甜,我新增了一行,设置了自动读取当前日期为制单日期,贸易国别,销售类型都填写了。但,编号序号后四位不会变化,前面的都会变。
图片点击可在新窗口打开查看此主题相关图片如下:qq图片20140331215046.jpg
图片点击可在新窗口打开查看

--  作者:yangcin
--  发布时间:2014/3/31 21:54:00
--  
还是没有变化啊,有点甜
求助啊
图片点击可在新窗口打开查看此主题相关图片如下:qq图片20140331215751.jpg
图片点击可在新窗口打开查看
[此贴子已经被作者于2014-3-31 21:54:42编辑过]

--  作者:有点甜
--  发布时间:2014/3/31 22:01:00
--  

 哦,明白,这句改一下。

 

 flt = "贸易国别 = \'" & gb & "\' And 销售类型 = \'" & lx & "\' And 制单日期 >= #" & fd & "# And 制单日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")

 

 改成

 

flt = "销售单号 like \'" & bh & "*\' And 制单日期 >= #" & fd & "# And 制单日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")

[此贴子已经被作者于2014-3-31 22:04:00编辑过]

--  作者:yangcin
--  发布时间:2014/4/1 8:41:00
--  
有点舔,还是不行呢...奇怪了,谢谢你的回复
--  作者:Bin
--  发布时间:2014/4/1 8:42:00
--  
例子发上来吧.