以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  通过角色控制列编辑权限问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=174912)

--  作者:xnsiwei
--  发布时间:2022/2/11 11:07:00
--  通过角色控制列编辑权限问题
通过角色控制列编辑权限问题,代码如下,但不然如愿,请版主帮看看

If User.IsRole("监测采样") = True  AndAlso User.IsRole("监测化验") = True  AndAlso User.IsRole("监测审核") = True  AndAlso User.IsRole("监测发布") = True Then
    If e.Col.Name = "采样时间"  AndAlso e.Col.Name = "采样地点" AndAlso e.Col.Name = "经度" AndAlso e.Col.Name = "纬度" AndAlso e.Col.Name = "检测项目" Then
        If User.IsRole("监测采样") = False Then
            e.Cancel = True
        End If
    End If
    If e.Col.Name = "检测限值"  AndAlso e.Col.Name = "检测结果" Then
        If User.IsRole("监测化验")  = False Then
            e.Cancel = True
        End If
    End If
    If e.Col.Name = "审核情况"  Then
        If User.IsRole("监测审核")  = False  Then
            e.Cancel = True
        End If
    End If
    If e.Col.Name = "发布情况"  Then
        If User.IsRole("监测发布")  = False  Then
            e.Cancel = True
        End If
    End If
Else
e.Cancel = True
End If

--  作者:有点蓝
--  发布时间:2022/2/11 11:56:00
--  
有什么问题?权限的处理逻辑或者说规则是什么?
--  作者:xnsiwei
--  发布时间:2022/2/11 14:25:00
--  
角色:“监测采样” ,只能编辑"采样时间"   "采样地点"  "经度" "纬度"  "检测项目"四列,其它列不能编辑
角色:“监测化验”,只能编辑"检测限值"   "检测结果"两列,其它列不能编辑
角色:"监测审核",只能编辑 "审核情况" 一列,其它列不能编辑
角色: "监测发布",只能编辑"发布情况"  一列,其它列不能编辑
      

--  作者:cd_tdh
--  发布时间:2022/2/11 14:41:00
--  

方法一:DataColChanging事件

Select Case e.DataCol.Name
    Case "采样时间","采样地点","经度","纬度","检测项目"
        If User.Roles <> "监测采样" Then
            msgbox("你不是监测采样人员,没有编辑权限!" )
            e.Cancel = True
            Return
        End If
    Case "检测限值","检测结果"
        If User.Roles <> "监测化验" Then
            msgbox("你不是监测化验人员,没有编辑权限!" )
            e.Cancel = True
            Return
        End If
End Select

方法二:PrepareEdit事件:

Select Case e.Col.Name
    Case "采样时间","采样地点","经度","纬度","检测项目"
        If User.Roles <> "监测采样" Then
            \'msgbox("你不是监测采样人员,没有编辑权限!" )
            e.Cancel = True
            Return
        End If
    Case "检测限值","检测结果"
        If User.Roles <> "监测化验" Then
            \'msgbox("你不是监测化验人员,没有编辑权限!" )
            e.Cancel = True
            Return
        End If
End Select

看是不是你要的效果:

[此贴子已经被作者于2022/2/11 14:45:33编辑过]

--  作者:有点蓝
--  发布时间:2022/2/11 14:45:00
--  
If User.Roles <> "监测采样" Then

改为

if User.IsRole("监测采样") = false then


Select Case e.Col.Name
    Case "采样时间","采样地点","经度","纬度","检测项目"
        if User.IsRole("监测采样") = false then
            e.Cancel = True
        End If
    Case "检测限值","检测结果"
        if User.IsRole("监测化验") = false then
            e.Cancel = True
        End If

--  作者:xnsiwei
--  发布时间:2022/2/11 15:55:00
--  
谢谢版主
搞定
Select Case e.Col.Name
    Case "采样时间","采样地点","经度","纬度","监测项目","备注","监测类别","监测项目","监测标准"
        If User.isRole("监测采样") = False Then \'不是监测采样人员,没有编辑权限
            e.Cancel = True
            Return
        End If
    Case "检测限值","检测结果","备注"
        If User.isRole("监测化验" ) = False Then \'不是监测化验人员,没有编辑权限
            e.Cancel = True
            Return
        End If
    Case "审核情况","备注"
        If User.isRole("监测审核" ) = False Then \'不是审核人员,没有编辑权限
            e.Cancel = True
            Return
        End If
    Case "发布情况"
        If User.isRole("监测发布" ) = False Then \'不是监测化验人员,没有编辑权限
            e.Cancel = True
            Return
        End If
    Case "编号","超标倍数","采样日志","监测日志","审核日志","发布日志"
        If User.isRole("超级管理员" ) = False Then \'不是超级管理员,没有编辑权限
            e.Cancel = True
            Return
        End If
End Select

--  作者:有点蓝
--  发布时间:2022/2/11 16:09:00
--  
有重复的列是有问题的,看看:http://www.foxtable.com/webhelp/topics/2242.htm
--  作者:xnsiwei
--  发布时间:2022/2/11 20:59:00
--  
好的,谢谢,马上修正