以文本方式查看主题

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

--  作者:sywgb168
--  发布时间:2017/1/8 19:45:00
--  取多列数据自动编号
编号列引用多列的数据自动编号,如果某些列没有数据则用编号自动用0代替,或者某些列的数据太长了只取该列前面的几个字符代替,请问各位老师怎么弄,参考帮助的哪些帮助和案列?
--  作者:有点色
--  发布时间:2017/1/8 23:03:00
--  

 参考代码

 

Select e.DataCol.Name
    Case "容量","电压","外壳直径","膜厚","相别"
        Dim lb As String = ""
        If e.DataRow.IsNull("外壳直径") Then
            lb &= "00"
        Else
            Dim s As String = e.DataRow("外壳直径")
            lb &= iif(s.length > 2, s.SubString(0,2), s)
        End If
        If e.DataRow.isnull("电压") Then
            lb &= "00"
        Else
            Dim s As String = e.DataRow("电压")
            lb &= iif(s.length > 2, s.SubString(0,2), s)
        End If
        If e.DataRow.isnull("膜厚") Then
            lb &= "00"
        Else
            Dim s As String = e.DataRow("膜厚")
            lb &= iif(s.length > 2, s.SubString(0,2), s)
        End If
        If e.DataRow.isnull("相别") Then
            lb &= "00"
        Else
            Dim s As String = e.DataRow("相别")
            lb &= iif(s.length > 2, s.SubString(0,2), s)
        End If
        If e.DataRow("产品编号").StartsWith(lb) = False \'如果单据编号前缀不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("max(产品编号)", "产品编号 like \'" & lb & "%\' and _Identify <> " & e.DataRow("_Identify"))  \'取得该类别的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(lb.length,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("产品编号") = lb & Format(idx,"000")
        End If
End Select


--  作者:sywgb168
--  发布时间:2017/1/9 10:35:00
--  
出现错误
图片点击可在新窗口打开查看此主题相关图片如下:qq截图20170109103333.png
图片点击可在新窗口打开查看

--  作者:有点色
--  发布时间:2017/1/9 10:37:00
--  
 把你的表格上传上来测试。
--  作者:sywgb168
--  发布时间:2017/1/9 11:47:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:工艺卡测试.foxdb


--  作者:有点色
--  发布时间:2017/1/9 12:02:00
--  
Select e.DataCol . Name
    Case "电压","容量","相别","膜厚","外壳直径"
        Dim lb As String = ""
        If e.DataRow.IsNull("电压") Then
            lb &= "00"
        Else
            Dim s As String = e.DataRow("电压")
            If s.Length > 2 Then
                lb &= s.SubString(0,2)
            Else
                lb &= s
            End If
        End If
        If e.DataRow.IsNull("容量") Then
            lb &= "00"
        Else
            Dim s As String = e.DataRow("容量")
            If s.Length > 2 Then
                lb &= s.SubString(0,2)
            Else
                lb &= s
            End If
        End If
       
        If e.DataRow.isnull("相别") Then
            lb &= "00"
        Else
            Dim s As String = e.DataRow("相别")
            If s.Length > 2 Then
                lb &= s.SubString(0,2)
            Else
                lb &= s
            End If
        End If
        If e.DataRow.isnull("膜厚") Then
            lb &= "00"
        Else
            Dim s As String = e.DataRow("膜厚")
            If s.Length > 2 Then
                lb &= s.SubString(0,2)
            Else
                lb &= s
            End If
        End If
        If e.DataRow.isnull("外壳直径") Then
            lb &= "00"
        Else
            Dim s As String = e.DataRow("外壳直径")
            If s.Length > 2 Then
                lb &= s.SubString(0,2)
            Else
                lb &= s
            End If
        End If
        If e.DataRow("产品编号").StartsWith(lb) = False \'如果单据编号前缀不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("max(产品编号)", "产品编号 like \'" & lb & "%\' and _Identify <> " & e.DataRow("_Identify"))  \'取得该类别的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(lb.length,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("产品编号") = lb & Format(idx,"000")
        End If
End Select

--  作者:sywgb168
--  发布时间:2017/1/9 14:59:00
--  

谢谢老师。