以文本方式查看主题

-  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=58433)

--  作者:audience68
--  发布时间:2014/10/16 16:18:00
--  编号生成的问题
甜版,又来请教了
我参照帮助做了一个自动生成编号功能,但是总是无法实现自动叠加的功能,请帮忙看看吧。谢谢
代码如下,不知问题在哪里?(去掉& "-"就可以,一加上就不行,每行总是CI201409001-001不变

表事件

 

监造周报_DataColChanged

 

Select e.DataCol.Name

    Case "监造流水号"

        If e.DataRow.IsNull("监造流水号") Then

            e.DataRow("周报编号") = Nothing

        Else

            Dim lb As String = e.DataRow("监造流水号") & "-" \'生成编号的前缀

            If e.DataRow("周报编号").StartsWith(lb) = False \'如果单据编号前缀不符

                Dim max As String

                Dim idx As Integer

                max = e.DataTable.Compute("Max(周报编号)","监造流水号 = \'" & lb & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该类别的最大编号

                If max > "" Then \'如果存在最大编号

                    idx = CInt(max.Substring(12,3)) + 1 \'获得最大编号的后三位顺序号,并加1

                Else

                    idx = 1 \'否则顺序号等于1

                End If

                e.DataRow("周报编号") = lb & Format(idx,"000")

            End If

        End If

End Select

希望的效果:

监造流水号

周报编号

CI201409001

CI201409001-001

CI201409001

CI201409001-002


--  作者:狐狸爸爸
--  发布时间:2014/10/16 16:58:00
--  

红色部分,你自己想想为什么:

 

Select e.DataCol.Name

    Case "监造流水号"

        If e.DataRow.IsNull("监造流水号") Then

            e.DataRow("周报编号") = Nothing

        Else

            Dim lb As String = e.DataRow("监造流水号") & "-" \'生成编号的前缀

            If e.DataRow("周报编号").StartsWith(lb) = False \'如果单据编号前缀不符

                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(12,3)) + 1 \'获得最大编号的后三位顺序号,并加1

                Else

                    idx = 1 \'否则顺序号等于1

                End If

                e.DataRow("周报编号") = lb & Format(idx,"000")

            End If

        End If

End Select


--  作者:有点甜
--  发布时间:2014/10/16 17:06:00
--  
Select e.DataCol.Name
   
    Case "监造流水号"
       
        If e.DataRow.IsNull("监造流水号") Then
           
            e.DataRow("周报编号") = Nothing
           
        Else
           
            Dim lb As String = e.DataRow("监造流水号")  \'生成编号的前缀
           
            Dim max As String
           
            Dim idx As Integer
           
            max = e.DataTable.Compute("Max(周报编号)","监造流水号 = \'" & lb & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该类别的最大编号
           
            If max > "" Then \'如果存在最大编号
               
                idx = CInt(max.Substring(lb.Length+1,3)) + 1 \'获得最大编号的后三位顺序号,并加1
               
            Else
               
                idx = 1 \'否则顺序号等于1
               
            End If
           
            e.DataRow("周报编号") = lb & "-" & Format(idx,"000")
           
        End If
       
End Select

--  作者:audience68
--  发布时间:2014/10/17 16:13:00
--  
感谢甜版,经你提示,我琢磨了一下,还是我对例子中的每一条语句体会的不透彻,还要认真学习啊