以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  条件生成编号  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=112998)

--  作者:有点蓝
--  发布时间:2018/1/6 15:43:00
--  
If e.DataCol.Name = "下单日期" orelse e.DataCol.Name = "客户编码" Then
    If e.DataRow.IsNull("下单日期") OrElse e.DataRow.IsNull("客户编码") Then
        e.DataRow("销售订单号") = Nothing
    Else
        Dim dr As DataRow = e.DataTable.Find("下单日期 = #" & e.DataRow("下单日期") & "# and 客户编码=\'" & e.DataRow("客户编码") & "\' and [_Identify] <> " & e.DataRow("_Identify"))
        If dr IsNot Nothing Then
            e.DataRow("销售订单号") = dr("销售订单号")
        Else
            Dim bh As String = Format(e.DataRow("下单日期"),"yyyyMM") \'取得编号的8位前缀
            If e.DataRow("销售订单号").StartsWith(bh) = False \'如果编号的前8位不符
                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,3)) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("销售订单号") = bh & Format(idx,"0000")
                
            End If
        End If
    End If
End If
[此贴子已经被作者于2018/1/6 15:49:03编辑过]

--  作者:有点蓝
--  发布时间:2018/1/6 15:49:00
--  
If e.DataCol.Name = "下单日期" orelse e.DataCol.Name = "客户编码" Then
--  作者:有点蓝
--  发布时间:2018/1/6 16:10:00
--  
就只见你问问题,从来不会思考为什么会出现错误

idx = CInt(max.Substring(6,4)) + 1