以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [原创]改错  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=123894)

--  作者:有点甜
--  发布时间:2018/8/26 23:35:00
--  

Select e.DataCol.Name
    Case "KJN","KJY"
        If e.DataRow.IsNull("KJN") OrElse e.DataRow.IsNull("KJY") Then
            e.DataRow("PZH") = Nothing
        Else
            Dim lb As String = e.DataRow("KJN") & "-" & e.DataRow("KJY") & "-"
            If e.DataRow("PZH").StartsWith(lb) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = e.DataTable.Compute("Max(PZH)","PZH like \'" & lb & "%\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该类别的最大编号
                max = e.DataTable.Compute("Max(PZH)",flt)
                If max > "" Then \'如果存在最大编号
                    idx = CInt(max.Substring(lb.length)) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("PZH") = lb & Format(idx,"0000")
            End If
        End If