以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  用了可视化授权,又用了自定义用户与权限管理,可是可视化授权失效了,不知道改怎么改  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=7945)

--  作者:erdbeer
--  发布时间:2010/8/22 0:54: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

 

又用了帮助中的 自定义用户与权限管理

 

可是 可视化授权中的代码失效了,该怎么改啊?


--  作者:狐狸爸爸
--  发布时间:2010/8/23 8:28:00
--  

帮助的自定义权限管理,定义了两个变量:

 

Public _UserName As String
Public _UserGroup As String

 

分别用于代替user.Name和user.group,至于user.Type则没有对应的变量,要么你自己自定义修改用户管理的代码,增加对应的设置和变量,要么修改一楼的代码,用_UserGroup代替User.Type.

代码是灵活的,关键要理解,才能融会贯通。


--  作者:G流星雨
--  发布时间:2017/9/13 19:37: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 = ( _UserGroup <> 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/9/13 19:38:16编辑过]

--  作者:有点甜
--  发布时间:2017/9/13 22:42: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 = (_UserGroup <> "管理员分组")
If _UserGroup <> "管理员分组" Then
    For Each dr As DataRow In DataTables("授权表").Select("分组名 = \'" & _UserGroup & "\'" )
        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

--  作者:G流星雨
--  发布时间:2017/9/14 9:38: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 = (_UserGroup  <> UserTypeEnum.User )

If _UserGroup  = UserTypeEnum.User Then
    For Each dr As DataRow In DataTables("用户授权表").Select("姓名 = \'" & _UserName & "\'" )
MessageBox.Show("1")
        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/9/14 9:58:00
--  

直接写

 

r 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
 
    For Each dr As DataRow In DataTables("用户授权表").Select("姓名 = \'" & _UserName & "\'" )
MessageBox.Show("1")
        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
 

--  作者:G流星雨
--  发布时间:2017/9/14 11:23:00
--  
 For Each t As Table In Tables
            t.Visible = False
            t.AllowEdit = False
            For Each c As Col In t.Cols
                c.Visible = False               
                c.AllowEdit = False
            Next
        Next
        Tables("产品管理").Visible = True



For Each dr As DataRow In DataTables("用户授权表").Select("姓名 = \'" & _UserName & "\'" )
    
    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

主要是不可见的内容太多,设置麻烦。想把设置不可见转变成可见
1、一进入就为全部不可见.根据授权表要求的可见可编辑的列,显示出来。
2、假如设置权限有不可见,不可编辑,更改为设置,只可见,只可编辑的话,如何对代码进行修改?上面这么改?

[此贴子已经被作者于2017/9/14 12:00:34编辑过]

--  作者:有点甜
--  发布时间:2017/9/14 11:43:00
--  
For Each t As Table In Tables
    t.Visible = False
    t.AllowEdit = False
    For Each c As Col In t.Cols
        c.Visible = False
        c.AllowEdit = False
    Next
Next
For Each dr As DataRow In DataTables("用户授权表").Select("姓名 = \'" & _UserName & "\'" )
    If dr.IsNull("受限列的名称") Then
        Tables(dr("受限表的名称")).Visible = dr("可见")
        Tables(dr("受限表的名称")).AllowEdit = dr("可编辑")
    Else
        Tables(dr("受限表的名称")).Cols(dr("受限列的名称")).Visible = dr("可见")
        Tables(dr("受限表的名称")).Cols(dr("受限列的名称")).AllowEdit = dr("可编辑")
    End If
Next