以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [新手求教]说明书这段如何在找不到表和列时不报错啊?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=97922)

--  作者:叶夜青
--  发布时间:2017/3/21 9:41:00
--  [新手求教]说明书这段如何在找不到表和列时不报错啊?

可视化授权的实现



For Each t As Table In Tables
    t.Visible =
True
    t.AllowEdit =
true

    For
Each c As Col In t.Cols
        c.Visible =
True
        c.AllowEdit =
True
    Next

Next
Tables
("授权表").Visible = (User.Type <> UserTypeEnum.User )
If
User.Type = UserTypeEnum.User Then
   
For Each dr As DataRow In DataTables("授权表").Select("分组名 = \'" & User.Group & "\'" )
        If
dr.IsNull("列名")
Then
           
Tables(dr("表名")).Visible = Not dr("不可见")
            Tables
(dr("表名")).AllowEdit = Not dr("不可编辑")

        Else
           
Tables(dr("表名")).Cols(dr("列名")).Visible = Not dr("不可见")
            Tables
(dr("表名")).Cols(dr("列名")).AllowEdit = Not dr("不可编辑")
        End
If
    Next
End
If




这段代码, 要是在某个用户的客户端没有载入某表某列, 然后授权表中又说到那表那列时, 就会报错。

如何简单修改下让其跳过找不到的表和列啊,然后其它行照样生效啊?


--  作者:有点色
--  发布时间:2017/3/21 11:22:00
--  

For Each t As Table In Tables
    t.Visible = True
    t.AllowEdit = True
    For Each c As Col In t.Cols
        c.Visible = True
        c.AllowEdit = True
    Next
Next
Tables("授权表").Visible = (User.Type <> UserTypeEnum.User )
If User.Type = UserTypeEnum.User Then
    For Each dr As DataRow In DataTables("授权表").Select("分组名 = \'" & User.Group & "\'" )
        If Tables.Contains(dr("表名")) Then
            If dr.IsNull("列名") Then
                Tables(dr("表名")).Visible = Not dr("不可见")
                Tables(dr("表名")).AllowEdit = Not dr("不可编辑")
            Else
                If  Tables(dr("表名")).Cols.Contains(dr("列名")) Then
                    Tables(dr("表名")).Cols(dr("列名")).Visible = Not dr("不可见")
                    Tables(dr("表名")).Cols(dr("列名")).AllowEdit = Not dr("不可编辑")
                End If
            End If
        End If
    Next
End If