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


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

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

帅哥哟,离线,有人找我吗?
大红袍
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | 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

 回到顶部