以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  自动生成编号时,在输入某一个内容时,从字符串“6-00”到类型“Integer”的转换无效。帮看看什么问题引起的呢?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=184403)

--  作者:mengxxaa
--  发布时间:2022/12/6 10:41:00
--  自动生成编号时,在输入某一个内容时,从字符串“6-00”到类型“Integer”的转换无效。帮看看什么问题引起的呢?
代码如下:
Select e.DataCol.Name
    Case "dnd_date", "dnd_cust_zjm"
        If e.DataRow.IsNull("dnd_date") OrElse e.DataRow.IsNull("dnd_cust_zjm") Then
            e.DataRow("dnd_dn") = Nothing
        Else
            Dim d As Date = e.DataRow("dnd_date")
            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("dnd_cust_zjm") & "-" & Format(d, "yyyyMMdd") & "-" \'生成编号的前缀
            If e.DataRow("dnd_dn").StartsWith(bh) = False  Then\'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "dnd_cust_zjm = \'" & e.DataRow("dnd_cust_zjm") & "\' And dnd_date >= #" & fd & "# And dnd_date <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(dnd_dn)", flt) \'取得该月的相同工程代码的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(12, 4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("dnd_dn") = bh & Format(idx, "0000")
            End If
        End If
End Select

图片点击可在新窗口打开查看此主题相关图片如下:问题图.png
图片点击可在新窗口打开查看


--  作者:mengxxaa
--  发布时间:2022/12/6 10:45:00
--  
问题补充,这个表第一次录入这个TCL通力的时候,没有异常提示,在第二行再录入TCL通力的时候,就有异常提示了。
--  作者:有点蓝
--  发布时间:2022/12/6 10:52:00
--  
idx = CInt(max.Substring(12, 4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
改为
idx = CInt(max.Substring(max.length - 4)) + 1 \'获得最大单据编号的后四位顺序号,并加1