以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]关于代码的问题(昨天还在用的代码今天突然不行了)  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=99426)

--  作者:an_1288
--  发布时间:2017/4/19 10:15:00
--  [求助]关于代码的问题(昨天还在用的代码今天突然不行了)
If e.DataCol.Name = "内转日期" Then
    If e.DataRow.IsNull("内转日期") Then
        e.DataRow("内转单号") = Nothing
    Else
        Dim d As Date = e.DataRow("内转日期")
        Dim bh As String = Format(d,"yyyy") \'生成编号的前6位,4位年,2位月.
        Dim max As String
        Dim idx As Integer
        If e.DataRow("内转单号").StartsWith(bh) = False \'如果编号的前6位不符
            max = e.DataTable.Compute("Max(内转单号)","内转单号 like \'" & bh & "%\'") \'取得该月的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(bh.length)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("内转单号") = bh & Format(idx,"000内")
        End If
    End If
End If

上面这串代码在“内转日期”列输入2017-01-01后,在"内转单号"列可自动生成内转单号:2017001内,不知道为什么今天继续录入的时候突然不行了,

显示:
运行错误
.NET Framework 版本:2.0.50727.5485
Foxtable 版本:2017.3.18.1
错误所在事件:表,内转,DataColChanged
详细错误信息:
调用的目标发生了异常。
从字符串“001内”到类型“Integer”的转换无效。
输入字符串的格式不正确。

各位老师麻烦了!


--  作者:an_1288
--  发布时间:2017/4/19 10:33:00
--  
我知道了:把e.DataRow("内转单号") = bh & Format(idx,"000内"),改为e.DataRow("内转单号") = bh & Format(idx,"000")就可以了,但生成“内转单号”为:2017001
如果要想生成“内转单号”为:2017001内,这种格式,要怎么修改代码呢?

--  作者:有点色
--  发布时间:2017/4/19 10:50:00
--  

 改成

 

e.DataRow("内转单号") = bh & Format(idx,"000") & "内"


--  作者:an_1288
--  发布时间:2017/4/19 14:18:00
--  
好像还是不行呢,还是和上面一样报错,麻烦了。
--  作者:有点色
--  发布时间:2017/4/19 14:54:00
--  

 

[此贴子已经被作者于2017/4/19 14:57:40编辑过]

--  作者:有点色
--  发布时间:2017/4/19 14:58:00
--  
If e.DataCol.Name = "内转日期" Then
    If e.DataRow.IsNull("内转日期") Then
        e.DataRow("内转单号") = Nothing
    Else
        Dim d As Date = e.DataRow("内转日期")
        Dim bh As String = Format(d,"yyyy") \'生成编号的前6位,4位年,2位月.
        Dim max As String
        Dim idx As Integer
        If e.DataRow("内转单号").StartsWith(bh) = False \'如果编号的前6位不符
            max = e.DataTable.Compute("Max(内转单号)","内转单号 like \'" & bh & "%\'") \'取得该月的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(bh.length, max.length-1-bh.length)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("内转单号") = bh & Format(idx,"000") & "内"
        End If
    End If
End If