Foxtable(狐表)用户栏目专家坐堂 → 自动编号问题


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

主题:自动编号问题

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


加好友 发短信
等级:婴狐 帖子:36 积分:686 威望:0 精华:0 注册:2015/6/14 11:27:00
自动编号问题  发帖心情 Post By:2015/9/11 16:06:00 [只看该作者]

老师,我用下面代码生成自动编号:

If e.DataCol.Name = "订购日期" Then
    If e.DataRow.IsNull("订购日期") Then
        e.DataRow("订单号") = Nothing
    Else
        Dim bh As String = "DG" & Format(e.DataRow("订购日期"),"yyMMdd")
        If e.DataRow("订单号").StartsWith(bh) = False
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(订单号)","订购日期 = #" & e.DataRow("订购日期") & "# And [_Identify] <> " & e.DataRow("_Identify"))
            If max > "" Then
                idx = CInt(max.Substring(9,2)) + 1
            Else
                idx = 1
            End If
            e.DataRow("订单号") = bh & "-" & Format(idx,"00")
        End If
    End If
End If

 

但有时要用自编的订单号,如:104239

之后再用当天的日期就无法生成编号,会出现调用错误,如下:

 

.NET Framework 版本:2.0.50727.5456
Foxtable 版本:2014.11.11.1
错误所在事件:表,辅料订购单,DataColChanged
详细错误信息:
调用的目标发生了异常。
startIndex 不能大于字符串长度。
参数名: startIndex

请教代码如何修改,谢谢!


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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/9/11 16:15:00 [只看该作者]

If e.DataCol.Name = "订购日期" Then
    If e.DataRow.IsNull("订购日期") Then
        e.DataRow("订单号") = Nothing
    Else
        Dim bh As String = "DG" & Format(e.DataRow("订购日期"),"yyMMdd")
        If e.DataRow("订单号").StartsWith(bh) = False
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(订单号)","订购日期 = #" & e.DataRow("订购日期") & "# And [_Identify] <> " & e.DataRow("_Identify"))
            If max > "" Then
                idx = CInt(max.Substring(bh.Length+1,2)) + 1
            Else
                idx = 1
            End If
            e.DataRow("订单号") = bh & "-" & Format(idx,"00")
        End If
    End If
End If

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


加好友 发短信
等级:婴狐 帖子:36 积分:686 威望:0 精华:0 注册:2015/6/14 11:27:00
  发帖心情 Post By:2015/9/11 17:00:00 [只看该作者]

老师,还是出现同样的错误!

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/9/11 17:11:00 [只看该作者]

编号一定要符合规范,不能不一致。否则就会出错

 

If e.DataCol.Name = "订购日期" Then
    If e.DataRow.IsNull("订购日期") Then
        e.DataRow("订单号") = Nothing
    Else
        Dim bh As String = "DG" & Format(e.DataRow("订购日期"),"yyMMdd")
        If e.DataRow("订单号").StartsWith(bh) = False
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(订单号)","订购日期 = #" & e.DataRow("订购日期") & "# And [_Identify] <> " & e.DataRow("_Identify"))
            If max > "" AndAlso max.Length >= bh.Length +3 Then
                idx = CInt(max.Substring(bh.Length+1,2)) + 1
            Else
                idx = 1
            End If
            e.DataRow("订单号") = bh & "-" & Format(idx,"00")
        End If
    End If
End If

 回到顶部