权限和限权是一回事,只是被动式和主动式。是扩大还是缩小,要看具体的情况。以下是我权限缩小的完整代码,希望对你有帮助:
在AfterOpenProject事件中:
Forms("用户登录").Open()
If _UserName = "" Or _userroles="" Or _usergroup="" Then
Syscmd.Project.Exit()
Return
End If
'初始化:所有的表和列都可见和可编辑,可粘贴
For Each dt As DataTable In DataTables
dt.AllowEdit = True
dt.AllowClipBoard=True
Next
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
'进行权限管理
Dim drs As List (of DataRow)
Dim roles(),role,values() As String
roles=_userroles.split(",")
For index As Integer = 0 To roles.length-1
role="'*" & roles(index) & "*'"
drs = DataTables("权限管理").Select("角色名称 like " & role,"序号")
For Each dr As DataRow In drs
If dr.IsNull("列名")=True Then
Tables(dr("表名")).Visible =dr("可查阅")
DataTables(dr("表名")).AllowEdit =dr("可编辑")
Tables(dr("表名")).AllowEdit =dr("可编辑") ’必须加这句,否则失效
DataTables(dr("表名")).AllowClipBoard =dr("可粘贴")
Else
Values = dr("列名").split(",")
For I1 As Integer = 0 To Values.Length - 1
Tables(dr("表名")).cols(Values(I1)).Visible = dr("可查阅")
DataTables(dr("表名")).datacols(Values(I1)).AllowEdit = dr("可编辑")
Tables(dr("表名")).cols(Values(I1)).AllowEdit = dr("可编辑") ’必须加这句,否则失效
Next
End If
Next
Next