以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]编号  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=118684)

--  作者:江南小镇
--  发布时间:2018/5/8 20:15:00
--  [求助]编号
老师,下面编号不累加。


图片点击可在新窗口打开查看此主题相关图片如下:图像 002.png
图片点击可在新窗口打开查看



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(2,3)) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("菜单编号") = lb & Format(idx,"00")
            End If
        End If
End Select
[此贴子已经被作者于2018/5/8 20:15:53编辑过]

--  作者:有点蓝
--  发布时间:2018/5/8 20:37:00
--  
规则是什么?菜单编号不用管前缀编号是什么,后3位按行顺序累加?
--  作者:有点甜
--  发布时间:2018/5/9 9:33:00
--  

上传实例,并说明需要生成怎样的编号


--  作者:江南小镇
--  发布时间:2018/5/12 13:06: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(子菜单号)","类型 = \'" & lb & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该类别的最大编号
                If max > "" Then \'如果存在最大编号
                    idx = CInt(max.Substring(2,3)) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("子菜单号") = lb & Format(idx,"000")
            End If
        End If
End Select

--  作者:有点蓝
--  发布时间:2018/5/12 15:01:00
--  
idx = CInt(max.Substring(max.length - 3,3)) + 1