以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  编号问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=91902)

--  作者:lk15502
--  发布时间:2016/10/21 13:17:00
--  编号问题
 窗口中上面是订单表,下面是订单明细表,订单表有订单编号,订单明细表有订单1明细编号,订单明细编号根据订单编号产生,下面的代码没有作用,是什么原因,订单表和订单明细表都是sqltable
If e.DataCol.Name = "订单明细编号" Then
Dim r As Row = Tables("订单管理_table1").current
    If r Is Nothing OrElse r.Isnull("订单编号") = True Then
        e.DataRow("订单明细编号") = Nothing
    Else
        Dim lb As String = r("订单编号") & "-"  
        If e.DataRow("订单明细编号").StartsWith(lb) = False Then \'如果单据编号前缀不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.sqlCompute("Max(订单明细编号)","订单明细编号 like \'" & r("订单编号") & "%\'  And [_Identify] <> " &  e.DataRow("_Identify")) \'取得该类别的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(lb.length,2)) + 1 \'获得最大编号的后两位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("订单明细编号") = lb & Format(idx,"00")
            e.DataRow.Save
        End If
    End If
End If

--  作者:cbt
--  发布时间:2016/10/21 13:44:00
--  
你可以,某个地方,输出一下,看看是否运行流畅啊!
慢慢就找出来哪里写错了!

--  作者:cbt
--  发布时间:2016/10/21 13:45:00
--  
If e.DataCol.Name = "订单明细编号" Then
Dim r As Row = Tables("订单管理_table1").current
    If r Is Nothing OrElse r.Isnull("订单编号") = True Then
        output.show(1)
        e.DataRow("订单明细编号") = Nothing
    Else
        Dim lb As String = r("订单编号") & "-"  
        output.show(2)
        If e.DataRow("订单明细编号").StartsWith(lb) = False Then \'如果单据编号前缀不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.sqlCompute("Max(订单明细编号)","订单明细编号 like \'" & r("订单编号") & "%\'  And [_Identify] <> " &  e.DataRow("_Identify")) \'取得该类别的最大编号
            If max > "" Then \'如果存在最大编号
                output.show(3)
                idx = CInt(max.Substring(lb.length,2)) + 1 \'获得最大编号的后两位顺序号,并加1
            Else
                output.show(4)
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("订单明细编号") = lb & Format(idx,"00")
            e.DataRow.Save
        End If
    End If
End If


看看哪里停住了。。。。就找哪里

--  作者:有点蓝
--  发布时间:2016/10/21 14:36:00
--  
代码改到明细表DataRowAdded事件

Dim r As Row = Tables("订单管理_table1").current
If r Is Nothing OrElse r.Isnull("订单编号") Then
    e.DataRow("订单明细编号") = Nothing
Else
    Dim lb As String = r("订单编号") & "-"
    If e.DataRow("订单明细编号").StartsWith(lb) = False Then \'如果单据编号前缀不符
        Dim max As String
        Dim idx As Integer
        max = e.DataTable.sqlCompute("Max(订单明细编号)","订单明细编号 like \'" & r("订单编号") & "%\' ") \'取得该类别的最大编号
        If max > "" Then \'如果存在最大编号
            idx = CInt(max.Substring(lb.length,2)) + 1 \'获得最大编号的后两位顺序号,并加1
        Else
            idx = 1 \'否则顺序号等于1
        End If
        e.DataRow("订单明细编号") = lb & Format(idx,"00")
        e.DataRow.Save
    End If
End If
[此贴子已经被作者于2016/10/21 14:38:27编辑过]