Foxtable(狐表)用户栏目专家坐堂 → [求助]一个自定义函数问题


  共有2421人关注过本帖树形打印复制链接

主题:[求助]一个自定义函数问题

帅哥哟,离线,有人找我吗?
blsu33
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:九尾狐 帖子:2928 积分:20184 威望:0 精华:0 注册:2012/2/3 17:45:00
[求助]一个自定义函数问题  发帖心情 Post By:2015/6/29 16:38:00 [只看该作者]

老师,
   一个涉及E参数的自定义函数,做的不对,请老师指点。
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:自定义代码.foxdb



 回到顶部
帅哥哟,离线,有人找我吗?
blsu33
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:九尾狐 帖子:2928 积分:20184 威望:0 精华:0 注册:2012/2/3 17:45:00
  发帖心情 Post By:2015/6/29 16:39:00 [只看该作者]


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

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By: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

 回到顶部