Foxtable(狐表)用户栏目专家坐堂 → [求助]帮助中授权的案例! 多层分级授权的代码疑惑~~


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

主题:[求助]帮助中授权的案例! 多层分级授权的代码疑惑~~

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


加好友 发短信
等级:五尾狐 帖子:1165 积分:9032 威望:0 精华:1 注册:2011/5/25 16:33:00
[求助]帮助中授权的案例! 多层分级授权的代码疑惑~~  发帖心情 Post By:2012/2/26 17:46:00 [只看该作者]

这段内部函数代码 是我根据帮助授权里的案例改编的

 

Dim dt As DataTable = DataTables("授权")
Dim dr As DataRow
'首先判断分组的授权用户是否包括此用户或此用户所属的分组
dr = dt.Find("分组 = '" & args(0) & "'" )
If dr Is Nothing Then
    MessageBox.show("不存在名为""" & args(0) & "分组!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return False
End If
'然后判断权限的授权用户是否包括此用户或此用户所属的分组
If Args(1) = "" Then
    Return True
End If
dr = dt.Find("分组 = '" & args(0) & "' And 权限 = '" & args(1) & "'")
If dr Is Nothing Then
    MessageBox.show("不存在名为""" & args(1) & "权限!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return False
End If
If dr.IsNull("用户") = False Then
    Dim nms() As String = dr("用户").Split(",")
    For Each nm As String In nms
        If nm = _UserGroup Then '如果授权用户包括登录用户所属的分组或其用户名
            Return True '返回True
        End If
    Next
End If
Return False

 

 

权限表如图:

 
图片点击可在新窗口打开查看此主题相关图片如下:未命名.jpg
图片点击可在新窗口打开查看

 

调用的时候,例如

Functions.Execute("shouquan","综合管理","绩效考核","绩效录入")

 

有时候只需判定是否有 【综合管理】权限即可  如果按照 我上面的代码的话麻烦了   需要多个判断

例如:A有综合管理 即可使用某个权限

if Functions.Execute("shouquan","综合管理","绩效考核","绩效录入") = true or Functions.Execute("shouquan","综合管理","绩效考核","绩效审核") = true 。。。。。

 

得把所有的判断一遍   请问怎么办

 

我最终是每一层权限调用一个内部函数 来返回值的

 

Dim dt As DataTable = DataTables("授权")
Dim drs As List(of DataRow)
drs = dt.Select("导航分组 = '" & args(0) & "'")
For Each mr As DataRow In drs
    If mr.IsNull("用户") = False Then
        Dim nms() As String = mr("用户").Split(",")
        For Each nm As String In nms
            If nm = _UserGroup Then '如果授权用户包括登录用户所属的分组或其用户名
                Return True '返回True
            End If
        Next
    End If
Next

 

我上面的要求 能否 设计在一个内部函数里即可? 

 

 

 


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


加好友 发短信
等级:五尾狐 帖子:1165 积分:9032 威望:0 精华:1 注册:2011/5/25 16:33:00
  发帖心情 Post By:2012/2/26 20:38:00 [只看该作者]

顶个~


 回到顶部