4、增加一个自定义函数,函数名为ShouQuan,代码为:
1,If
User.Type <> UserTypeEnum.User Then ' 如果是开发者或者管理员
2, Return True '则具备所有权限
3, End If
4, Dim dt As DataTable = DataTables("授权")
5, Dim dr As DataRow
'首先判断分组的授权用户是否包括此用户或此用户所属的分组
6, dr = dt.Find("分组 = '" & args(0) & "' And 权限 Is Null" )
7, If dr Is Nothing Then
8, MessageBox.show("不存在名为""" & args(0) & "分组!","提 示",MessageBoxButtons.OK,MessageBoxIcon.Information)
9, Return False
10, End If
11,If dr.IsNull("用户") = False Then
12, Dim nms() As String = dr("用户").Split(",")
13, For Each nm As String In nms
14, If nm = User.Group OrElse nm = User.Name Then '如果授权用户包括登录用户所属的分组或其用户名
15, Return True '返回True
16, End If
17, Next
18,End If
'然后判断权限的授权用户是否包括此用户或此用户所属的分组
19,If Args(1) = "" Then
20, Return False
21,End If
22,dr = dt.Find("分组 = '" & args(0) & "' And 权限 = '" & args(1) & "'")
23,If dr Is Nothing Then
24, MessageBox.show("不存在名为""" & args(1) & "权限!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
25, Return False
26,End If
27,If dr.IsNull("用户") = False Then
28, Dim nms() As String = dr("用户").Split(",")
29, For Each nm As String In nms
30, If nm = User.Group OrElse nm = User.Name Then '如果授权用户包括登录用户所属的分组或其用户名
31, Return True '返回True
32, End If
33, Next
34,End If
35,Return False
此主题相关图片如下:qq截图20120228155625.jpg

假如以图中第三行为例:当前用户为杨刚
执行:
If Functions.Execute("ShouQuan","订单管理","批准订单") Then
应当返回FALSE,但是却返回了TRUE,理由是执行到第6行的
dr = dt.Find("分组 = '" & args(0) & "' And 权限 Is Null" )
dr是第一行,然后
第14,15行的
If nm = User.Group OrElse nm = User.Name Then
Return True
返回的则是True了,但图中的第三行中没有用户呀,应当返回FALSE
还有就是如果 分组 对应的 权限 的每一行都录入有权限时,始终
MessageBox.show("不存在名为""" & args(0) & "分组!","提 示",MessageBoxButtons.OK,MessageBoxIcon.Information)
以上问题主要还是判断
args(0) 和args(1) 互相为空或不为空的问题,请狐爸指正!