以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]一个自定义函数问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=70812)

--  作者:blsu33
--  发布时间:2015/6/29 16:38:00
--  [求助]一个自定义函数问题
老师,
   一个涉及E参数的自定义函数,做的不对,请老师指点。
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:自定义代码.foxdb



--  作者:blsu33
--  发布时间:2015/6/29 16:39:00
--  

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

--  作者:大红袍
--  发布时间:2015/6/29 17:14:00
--  

Functions.Execute("datacol",DataTables("部门档案"),e)

 

----------------

 

Dim dt As DataTable=args(0)
Dim e As object = args(1)
Dim dt1 As DataTable= DataTables("编码规则")
Dim dc As DataCol = e.DataCol
If dc.Name = "部门编码" AndAlso e.newValue <> Nothing Then
    Dim fdr As DataRow = dt1.Find("数据表名 = \'" & dt.Name & "\'")
    If fdr IsNot Nothing Then
        Dim reg As new System.Text.RegularExpressions.Regex(fdr("正则"))
        If reg.Ismatch(e.newValue) = False Then
            e.Cancel = True
        Else
            Dim count As Integer = 0
            Dim prev As String = ""
            For i As Integer = 0 To fdr("编码规则").length - 1
                count += val(fdr("编码规则").chars(i))
               
                Dim str As String = e.newValue.Substring(0, count)
                If count < e.Newvalue.length Then
                    If dt.Find("部门编码 = \'" & str & "\'") Is Nothing Then
                        msgbox("缺少:" & str)
                        e.Cancel = True
                        Exit For
                    End If
                Else If count = e.newvalue.length  Then
                    If i = fdr("编码规则").length - 1 Then
                        dt.DataRows(0)("是否末级") = True
                        dt.ReplaceFor("是否末级", False, "部门编码 = \'" & prev & "\'")
                    Else
                        Dim filter As String = "部门编码 <> \'" & str & "\' and 部门编码 like \'" & str & "*\'"
                        If  dt.Find(filter) Is Nothing Then
                            dt.DataRows(0)("是否末级") = True
                            filter = "部门编码 = \'" & prev & "\'"
                            dt.ReplaceFor("是否末级", False, filter)
                        Else
                            dt.DataRows(0)("是否末级") = False
                           
                        End If
                       
                        Exit For
                    End If
                End If
                prev = str
            Next
        End If
    End If
End If

Dim dt As DataTable=args(0)
Dim e As object = args(1)
Dim dt1 As DataTable= DataTables("编码规则")
Dim dc As DataCol = e.DataCol
If dc.Name = "部门编码" AndAlso e.newValue <> Nothing Then
    Dim fdr As DataRow = dt1.Find("数据表名 = \'" & dt.Name & "\'")
    If fdr IsNot Nothing Then
        Dim reg As new System.Text.RegularExpressions.Regex(fdr("正则"))
        If reg.Ismatch(e.newValue) = False Then
            e.Cancel = True
        Else
            Dim count As Integer = 0
            Dim prev As String = ""
            For i As Integer = 0 To fdr("编码规则").length - 1
                count += val(fdr("编码规则").chars(i))
               
                Dim str As String = e.newValue.Substring(0, count)
                If count < e.Newvalue.length Then
                    If dt.Find("部门编码 = \'" & str & "\'") Is Nothing Then
                        msgbox("缺少:" & str)
                        e.Cancel = True
                        Exit For
                    End If
                Else If count = e.newvalue.length  Then
                    If i = fdr("编码规则").length - 1 Then
                        dt.DataRows(0)("是否末级") = True
                        dt.ReplaceFor("是否末级", False, "部门编码 = \'" & prev & "\'")
                    Else
                        Dim filter As String = "部门编码 <> \'" & str & "\' and 部门编码 like \'" & str & "*\'"
                        If  dt.Find(filter) Is Nothing Then
                            dt.DataRows(0)("是否末级") = True
                            filter = "部门编码 = \'" & prev & "\'"
                            dt.ReplaceFor("是否末级", False, filter)
                        Else
                            dt.DataRows(0)("是否末级") = False
                           
                        End If
                       
                        Exit For
                    End If
                End If
                prev = str
            Next
        End If
    End If
End If