Foxtable(狐表)用户栏目专家坐堂 → 求助:自动编号只能实现一次


  共有2036人关注过本帖树形打印复制链接

主题:求助:自动编号只能实现一次

帅哥哟,离线,有人找我吗?
minxizai
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:175 积分:1646 威望:0 精华:0 注册:2015/6/10 13:50:00
求助:自动编号只能实现一次  发帖心情 Post By:2015/6/15 23:34:00 [只看该作者]

“DD、登记时间、编号”都是订单表的列,

 

DataRowAdded事件代码:

e.DataRow("登记时间") = Date.now
e.DataRow("DD")="DD"

 

DataColChanged事件代码:

Select e.DataCol.Name
    Case "DD","登记时间"
        If e.DataRow.IsNull("登记时间") OrElse e.DataRow.IsNull("DD") 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("DD") & "-" & Format(d,"yyyyMM") & "-" '生成编号的前缀
            If e.DataRow("编号").StartsWith(bh) = False '如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "DD = '"& e.DataRow("DD") & "' 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

 

按上述设置后,第一次新增行时没有问题,第二次开始出错。

提示信息:

.NET Framework 版本:2.0.50727.3053
Foxtable 版本:2014.11.11.1
错误所在事件:表,订单,DataColChanged
详细错误信息:
Exception has been thrown by the target of an invocation.
Index and length must refer to a location within the string.
Parameter name: length


 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47448 积分:251060 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2015/6/16 8:26:00 [只看该作者]

根据这句代码:

Dim bh As String = e.DataRow("DD") & "-" & Format(d,"yyyyMM") & "-" '生成编号的前缀

你变好的前缀是9位,不是12位,

 

所以:

 

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

应该改为:

 

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

 


 回到顶部