Foxtable(狐表)用户栏目专家坐堂 → [求助] 关于授权不起作用是什么问题


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

主题:[求助] 关于授权不起作用是什么问题

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


加好友 发短信
等级:幼狐 帖子:140 积分:1463 威望:0 精华:0 注册:2017/9/3 22:32:00
[求助] 关于授权不起作用是什么问题  发帖心情 Post By:2018/1/1 22:46:00 [只看该作者]

我在菜单的最低层click事件中写:

 

If Functions.Execute("ShouQuan","编辑","添加") Then
    Forms("信息添加").open
Else
    msgbox("权限不足!")
End If

 

我的users表 ,授权表,及提示错误


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


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

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

我检查了,但没有查出有什么问题。


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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/1/1 23:04:00 [只看该作者]

在授权函数加入msgbox弹出各个值,如

 

msgbox(user.name)

 

msgbox(_userName)

 

贴出你shouquan函数的代码看看。


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


加好友 发短信
等级:幼狐 帖子:140 积分:1463 威望:0 精华:0 注册:2017/9/3 22:32:00
  发帖心情 Post By:2018/1/2 14:48:00 [只看该作者]

msgbox(user.name)

msgbox(_userName)

分别弹出的窗口是:


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

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

 

甜老师,是我哪个地方设置的不对吗? 在线等。

[此贴子已经被作者于2018/1/2 14:50:38编辑过]

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/1/2 14:52:00 [只看该作者]

贴出你授权代码,或者改成这样

 


Dim dt As DataTable = DataTables("授权")
Dim dr As DataRow
'首先判断分组的授权用户是否包括此用户或此用户所属的分组
dr = dt.Find("分组 = '" & args(0) & "' And 权限 Is Null" )
If dr Is Nothing Then
    MessageBox.show("不存在名为""" & args(0) & "分组!","提示",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 OrElse nm = _UserName Then '如果授权用户包括登录用户所属的分组或其用户名
            Return True '返回True
        End If
    Next

End If
'然后判断权限的授权用户是否包括此用户或此用户所属的分组
If Args(1) = "" Then
    Return False
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 OrElse nm = _UserName Then '如果授权用户包括登录用户所属的分组或其用户名
            Return True '返回True
        End If
    Next
End If
Return False


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


加好友 发短信
等级:幼狐 帖子:140 积分:1463 威望:0 精华:0 注册:2017/9/3 22:32:00
  发帖心情 Post By:2018/1/2 15:03:00 [只看该作者]

授权代码:

1、treeview1:  afterselectnode

Dim trv1 As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim trv2 As WinForm.TreeView = e.Form.Controls("TreeView2")
Dim dr As DataRow
If e.node.Level = 0 Then
    dr = DataTables("授权").Find("分组 = '" & e.Node.Name & "' And 权限 Is Null")
Else
    dr = DataTables("授权").Find("分组 = '" & e.Node.ParentNode.Name & "' And 权限 = '" & e.Node.Name & "'")
End If
Dim nms As New List(of String)
If dr IsNot Nothing AndAlso dr.IsNull("用户") = False
    nms.AddRange(dr("用户").Split(","))
End If
For Each nd As WinForm.TreeNode In trv2.AllNodes
    nd.Checked = nms.Contains(nd.Name)
Next

2、treeview2:  afterselectnode

Dim trv1 As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim trv2 As WinForm.TreeView = e.Form.Controls("TreeView2")
Dim nd1 As WinForm.TreeNode = trv1.SelectedNode
Dim dr As DataRow
If e.Node.ParentNode IsNot Nothing Then '取消父节点的选中标记,因为选中子节点,就不要选中父节点了
    e.Node.ParentNode.Checked = False
End If
For Each cnd As WinForm.TreeNode In e.Node.Nodes '取消子节点的选中标记,因为选中父节点,就不要选中子节点了
    cnd.Checked = False
Next
If nd1.Level = 0 Then
    dr = DataTables("授权").Find("分组 = '" & nd1.Name & "' And 权限 Is Null")
Else
    dr = DataTables("授权").Find("分组 = '" & nd1.ParentNode.Name & "' And 权限 = '" & nd1.Name & "'")
End If
If dr IsNot Nothing Then
    Dim nms As String
    For Each nd2 As WinForm.TreeNode In trv2.AllNodes
        If nd2.Checked  Then
            nms  = nms & "," &  nd2.Name
        End If
    Next
    If nms > "" Then
        dr("用户") = nms.Trim(",")
    Else
        dr("用户") = Nothing
    End If
End If

3、添加分类

Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim i As Integer
Do
    i = i+ 1
    Dim nm As String = "分组" & i
    If trv.Nodes.Contains(nm) = False
        Dim dr As DataRow = DataTables("授权").AddNew
        Dim nd As WinForm.TreeNode =  trv.Nodes.Add(nm)
        dr("分组") = nm
        trv.SelectedNode = nd
        trv.BeginEdit
        Exit Do
    End If
Loop

4、增加授权

Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim pd As WinForm.TreeNode = trv.SelectedNode
If pd.Level = 1 Then
    pd = pd.ParentNode
End If
Dim i As Integer
Do
    i = i+ 1
    Dim nm As String  =  "权限" & i
    If pd.Nodes.Contains(nm) = False
        Dim nd As WinForm.TreeNode = pd.Nodes.Add(nm)
        Dim dr As DataRow = DataTables("授权").AddNew()
        dr("分组") = pd.name
        dr("权限") = nm
        trv.SelectedNode = nd
        trv.BeginEdit
        Exit Do
    End If
Loop

5、窗口的afterload

Dim trv1 As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim trv2 As WinForm.TreeView = e.Form.Controls("TreeView2")
trv1.BuildTree("授权","分组|权限")
trv2.BuildTree("Users","Group|Name")
If Trv1.Nodes.Count > 0 Then
Trv1.Nodes(0).Expand()
End If
trv2.ExpandAll()

 

6、shouquan

If User.Type <> UserTypeEnum.User Then ' 如果是开发者或者管理员
    Return True '则具备所有权限
End If
Dim dt As DataTable = DataTables("授权")
Dim dr As DataRow
'首先判断分组的授权用户是否包括此用户或此用户所属的分组
dr = dt.Find("分组 = '" & args(0) & "' And 权限 Is Null" )
If dr Is Nothing Then
    MessageBox.show("不存在名为""" & args(0) & "分组!","提示",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 = User.Group OrElse nm = User.Name Then '如果授权用户包括登录用户所属的分组或其用户名
            Return True '返回True
        End If
    Next
End If
'然后判断权限的授权用户是否包括此用户或此用户所属的分组
If Args(1) = "" Then
    Return False
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 = User.Group OrElse nm = User.Name Then '如果授权用户包括登录用户所属的分组或其用户名
            Return True '返回True
        End If
    Next
End If
Return False

甜老师,我是新手,请您教我,谢谢。

[此贴子已经被作者于2018/1/2 15:17:37编辑过]

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/1/2 15:29:00 [只看该作者]

参考4楼,修改shouquan函数的代码。

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


加好友 发短信
等级:幼狐 帖子:140 积分:1463 威望:0 精华:0 注册:2017/9/3 22:32:00
  发帖心情 Post By:2018/1/2 15:41:00 [只看该作者]

谢谢,我明白了,非常感谢甜老师。

 回到顶部