以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  自动编号混合手工编号时出错如何处理?(已OK)  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=23884)

--  作者:zpx_2012
--  发布时间:2012/9/22 19:18:00
--  自动编号混合手工编号时出错如何处理?(已OK)

各位老师,

 

当入库单中的入库单号列全部统一为自动编号时没问题,但有时会手工录入一些其他杂的单据号码,这样运行后就会出问题,如下:

 


此主题相关图片如下:360截图201209221-10.jpg
按此在新窗口浏览图片
代码如下:

\'为入库单号自动编号
        If 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 = "rk" & Format(d,"yyMM") \'生成编号的前6位,4位年,2位月.
            If e.DataRow("入库单号").StartsWith(bh) = False \'如果编号的前6位不符
                Dim max As String
                Dim idx As Integer
                max = e.DataTable.Compute("Max(入库单号)","入库日期 >= #" & fd & "# And 入库日期 <= #" & ld & "# and e.DataRow("入库单号").StartsWith(bh) = true") \'取得符合条件的最大编号
                If max > "" Then \'如果存在最大编号
                    idx = CInt(max.Substring(7,3)) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("入库单号") = "rk" & bh & "-" & Format(idx,"000")
            End If

所以在取得最大编号后面加了(红色的)的那部分想只取"rk1209"开头的入库单号来得到最大号,但这行总是出错,通不过。

 

请大家指点要怎么加这个条件。还是有其他办法达到这种效果?

谢谢!

[此贴子已经被作者于2012-9-23 11:01:11编辑过]

--  作者:e-png
--  发布时间:2012/9/22 23:15:00
--  
left(e.DataRow("入库单号"),2) = "bh"
--  作者:zpx_2012
--  发布时间:2012/9/22 23:57:00
--  

谢谢e-png,但好像还是不行噢


--  作者:zpx_2012
--  发布时间:2012/9/23 11:01:00
--  
换了种方式,可以了,谢谢!