以文本方式查看主题

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

--  作者:a2994298
--  发布时间:2017/9/5 15:17: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,"yyyyMM") & "-" \'生成编号的前缀
            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(12,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("合同号") = bh & Format(idx,"0000")
            End If
        End If
End Select
[此贴子已经被作者于2017/9/5 15:17:07编辑过]

--  作者:有点甜
--  发布时间:2017/9/5 15:27:00
--  

代码没问题,选择大区或时间都可以触发代码。如果有问题,具体例子发上来看看。

 

idx = CInt(max.Substring(12,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1

 

最好改成

 

idx = CInt(max.Substring(bh.length,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1