权限控制管理(用户与菜单项的关联)

摘要:
@uservarchar(50)=“”)ASBEGINupdateset[State]=f.Col,')tons.AuthorityTag=t.Col joindbo.FN _ SplitSTR(@State,')font.ID=f.ID其中。ModuleCode=@ModuleCodeinsertSys_ ModuleAuthList(ModuleCode,

GO

-- Description: <修改模块权限>
-- =============================================
ALTER PROCEDURE [dbo].[st_MES_ChgModuleAuth]--1.添加菜单的所具有的权限(对应程序清单的编辑/添加部分。)
( @ModuleCode varchar(50) = '',
@Auth varchar(2000)='',
@State varchar(2000) = '',
@user varchar(50)=''
)
AS
BEGIN
update s set [State] = f.Col,updateman=@user,updatetime=getdate()
from Sys_ModuleAuthList s 
join dbo.FN_SplitSTR(@Auth,',') t on s.AuthorityTag = t.Col 
join dbo.FN_SplitSTR(@State,',') f on t.ID = f.ID 
where s.ModuleCode = @ModuleCode

insert Sys_ModuleAuthList(ModuleCode, AuthorityTag, [State], CreateMan, CreateTime,UpdateMan,UpdateTime)
select ModuleCode = @ModuleCode, AuthorityTag = t.Col, [State] = f.Col, @User, getdate(), @User, getdate()
from dbo.FN_SplitSTR(@Auth,',') t
join dbo.FN_SplitSTR(@State,',') f on t.ID = f.ID
where not exists(select 1 from Sys_ModuleAuthList s 
where s.ModuleCode = @ModuleCode
and s.AuthorityTag = t.Col)

/*add by zhuss 2014-01-28*/
if exists(select 1 from master..sysdatabases where name='ChiefWMS')
exec ChiefWMS.dbo.st_Sys_ChgModuleAuth @ModuleCode,@Auth,@State,@user
END

----------------------------------------------------------------------------------------

2.对应组别权限页面
ALTER proc [dbo].[st_MES_EditGroupRight] (
@GroupCode varchar(50) = '',
@ModuleCode varchar(50) = '',
@Tag varchar(50) = '',
@Flag varchar(50) = '',
@User varchar(50)=''
)
/*************
Remark: 插入组别权限
**************/
as
BEGIN
DECLARE @TagInfo VARCHAR(50)

IF @Flag<>''
BEGIN
DECLARE tag CURSOR FOR
SELECT Col AS Tag FROM FN_SplitSTR(@Tag,',')
OPEN tag
FETCH NEXT FROM tag INTO @TagInfo
WHILE @@FETCH_STATUS=0 AND @TagInfo<>''
BEGIN
update s set Flag = @Flag, UpdateMan = @User, UpdateTime = getdate()
from Sys_GroupRight s
where s.GroupCode = @GroupCode and s.ModuleCode = @ModuleCode and s.AuthorityTag = @TagInfo

insert Sys_GroupRight(GroupCode, ModuleCode, AuthorityTag, Flag, CreateMan, CreateTime, UpdateMan, UpdateTime)
select @GroupCode, m.ModuleCode, m.AuthorityTag, @Flag, @User, getdate(), @User, getdate()
from Sys_ModuleAuthList m
left join Sys_GroupRight s on s.GroupCode = @GroupCode and s.ModuleCode = m.ModuleCode and s.AuthorityTag = m.AuthorityTag
where m.State = 1 and m.ModuleCode = @ModuleCode and m.AuthorityTag = @TagInfo and s.ModuleCode is NULL

FETCH NEXT FROM tag INTO @TagInfo

END
CLOSE tag
DEALLOCATE tag

 -----------------------------------------------------------------------------------------------------------------

3.个人组别权限页面

ALTER proc [dbo].[st_MES_EditPersonalRight] (
@UserCode varchar(50) = 'superadmin',
@ModuleCode nvarchar(50) = '150002',
@Tag varchar(50) = 'RGP_ADD',
@Flag varchar(50) = 'false',
@User varchar(50)='superadmin'
)
/*************
exec st_MES_EditPersonalRight ''
creator: Wuchun
create date: 2012.10.15
Remark: 插入个人权限
**************/
as
begin
update s set Flag = @Flag, UpdateMan = @User, UpdateTime = getdate()
from Sys_PersonalRight s
where s.UserCode = @UserCode and s.ModuleCode = @ModuleCode and (@Tag = '' or s.AuthorityTag = @Tag)

insert Sys_PersonalRight(UserCode, ModuleCode, AuthorityTag, Flag, CreateMan, CreateTime, UpdateMan, UpdateTime)
select @UserCode, m.ModuleCode, m.AuthorityTag, @Flag, @User, getdate(), @User, getdate()
from Sys_ModuleAuthList m
left join Sys_PersonalRight s on s.UserCode = @UserCode and s.ModuleCode = m.ModuleCode and s.AuthorityTag = m.AuthorityTag
where m.state = 1 and m.ModuleCode = @ModuleCode and (@Tag = '' or m.AuthorityTag = @Tag) and s.ModuleCode is null

/*add by zhuss 2014-01-28*/
exec ChangHongWMS612.dbo.[st_sys_EditPersonalRight] @UserCode,@ModuleCode,@Tag,@Flag,@User
end

--4.根据用户UserCode取出主菜单
ALTER proc [dbo].[st_MES_SelectAllMenu](
@UserCode varchar(50) = 'superadmin'

)
as
begin
if object_ID('tempdb..#Menu') is not null drop table #Menu
declare @Ver varchar(20), @VerName varchar(50)
select @VerName = ''
select @VerName = VerName, @Ver = ver from Sys_Version where state = 1

SELECT distinct m.MenuCode,m.Name as MenuName, m.ParentCode as ParentMenuCode, m.Iconic, MenuURL = m.URL, m.Sort
, IsDisable = isnull(m.IsDisable,0)
into #Menu
from Sys_Module a, Sys_Menu m, Sys_PersonalRight b
where a.MenuCode=m.MenuCode and a.ModuleCode=b.ModuleCode and a.State=1 and b.Flag = 1
and b.UserCode = @UserCode
and (@VerName = '' or (m.VerName = @VerName and m.Ver = @Ver and m.IsShow = 1))

insert into #Menu(MenuCode, MenuName, ParentMenuCode ,Iconic, MenuURL,Sort, IsDisable)
select distinct m.MenuCode, m.Name as MenuName, m.ParentCode as ParentMenuCode, m.Iconic, MenuURL = m.URL, m.Sort, IsDisable = isnull(m.IsDisable,0)
from Sys_Module a,Sys_GroupRight b,Sys_User c, Sys_Menu m
where a.MenuCode = m.MenuCode and a.ModuleCode=b.ModuleCode and b.GroupCode=c.GroupCode and a.State=1 and b.Flag = 1
and not exists(select 1 from #Menu t where a.MenuCode = t.MenuCode)
and c.UserCode = @UserCode
and (@VerName = '' or (m.VerName = @VerName and m.Ver = @Ver and m.IsShow = 1))

insert into #Menu(MenuCode, MenuName, ParentMenuCode ,Iconic, MenuURL,Sort, IsDisable)
select a.MenuCode,a.Name as MenuName, a.ParentCode, a.Iconic, a.URL, a.Sort,0
from Sys_Menu a
where a.Name='系统管理' AND a.State=1
and not exists(select 1 from #Menu t where a.MenuCode = t.MenuCode)

select *, VerName = @VerName from #Menu order by case when @VerName <> '' then IsDisable else 1 end , sort
end

 -------------------------------------------------------------------

5.根据用户UserCode与MenuCode 去主菜单下的子菜单
ALTER proc [dbo].[st_MES_SelModuleInfo] (
@MenuCode varchar(50) = '100'
,@UserCode varchar(50) = 'superadmin'

)
/*************
exec [st_MES_SelModuleInfo] '130','superadmin'
creator: Wuchun
create date: 2012.10.15
Remark: 生成程序模块列表
**************/
as
begin
if object_ID('tempdb..#ModuleInfo') is not null drop table #ModuleInfo
declare @Ver varchar(20), @VerName varchar(50)
select @VerName = ''
select @VerName = VerName, @Ver = ver from Sys_Version where state = 1

SELECT DISTINCT a.ModuleCode,a.Name as ModuleName,a.URL,a.Sort,a.MenuCode,a.Iconic , IsDisable = isnull(a.IsDisable,0)
into #ModuleInfo
from Sys_Module a,Sys_PersonalRight b
where a.ModuleCode=b.ModuleCode and a.State=1 and b.Flag = 1
and b.UserCode = @UserCode and a.MenuCode=@MenuCode
and (@VerName = '' or (a.VerName = @VerName and a.Ver = @Ver and a.IsShow = 1))

insert into #ModuleInfo(ModuleCode, ModuleName, URL ,Sort, MenuCode, Iconic, IsDisable)
select Distinct a.ModuleCode,a.Name as ModuleName,a.URL,a.Sort,a.MenuCode,a.Iconic, IsDisable = isnull(a.IsDisable,0)
from Sys_Module a,Sys_GroupRight b,Sys_User c
where a.ModuleCode=b.ModuleCode and b.GroupCode=c.GroupCode and a.State=1 and b.Flag = 1
and not exists(select 1 from #ModuleInfo t where a.ModuleCode = t.ModuleCode)
and c.UserCode = @UserCode and a.MenuCode=@MenuCode
and (@VerName = '' or (a.VerName = @VerName and a.Ver = @Ver and a.IsShow = 1))

insert into #ModuleInfo(ModuleCode, ModuleName, URL ,Sort, MenuCode, Iconic, IsDisable)
select Distinct a.ModuleCode,a.Name as ModuleName,a.URL,a.Sort,a.MenuCode,a.Iconic , IsDisable = isnull(a.IsDisable,0)
from Sys_Module a
where a.Name='用户密码变更' AND a.State=1
and not exists(select 1 from #ModuleInfo t where a.ModuleCode = t.ModuleCode)
select * from #ModuleInfo where moduleCode not in('50005','70016') order by sort
end

----------------------------------------------------------------------------

select * from dbo.Sys_Menu--主菜单表
select * from dbo.Sys_Module order by MenuCode asc,Sort asc--菜单模板表(菜单对应的子菜单表)
select * from Sys_GroupRight--用户组与菜单与权限表
select * from Sys_PersonalRight--用户与菜单与权限表

select * from Sys_ModuleAuthList --每一个菜单应该有的权限表

SELECT * FROM Sys_Authority where auttype='Function'--菜单应该有的权限 程序清单下面的checkbox多选从这里显示的。

select * from Sys_User--用户表

select * from dbo.MES_Employee--员工表

(表结构在百度云MES上面)

---------------------------------------------------

1.菜单清单:  SystemManage/Module.aspx

2.组别权限在:SystemManage/GroupRight.aspx

3.个人权限在:SystemManage/PersonalRight.aspx

  1.1程序清单列表查询SQL:

select distinct sm.ModuleCode Id,sm.ModuleCode,sm.Name,sm.Sort,sm.CreateMan,sm.CreateTime,

sm.UpdateMan,sm.UpdateTime from Sys_Module sm
left join sys_GroupRight sgr on sgr.ModuleCode=sm.ModuleCode
left join Sys_User su on su.GroupCode=sgr.GroupCode
where 1=1

----------------------------------------------------------

USE [ChangHong_612]
GO
/****** Object: UserDefinedFunction [dbo].[FN_SplitSTR] Script Date: 04/11/2016 12:27:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[FN_SplitSTR](
@s varchar(8000), --待分拆的字符串
@split varchar(10) --数据分隔符
)
RETURNS @re TABLE(ID int IDENTITY (1, 1), Col varchar(4000))
AS
BEGIN
--创建分拆处理的辅助表(用户定义函数中只能操作表变量)
DECLARE @t TABLE(ID int IDENTITY,b bit)
INSERT @t(b) SELECT TOP 8000 0 FROM syscolumns a,syscolumns b
INSERT @re SELECT SUBSTRING(@s,ID,CHARINDEX(@split,@s+@split,ID)-ID)
FROM @t
WHERE ID<=LEN(@s+'a')
AND CHARINDEX(@split,@split+@s,ID)=ID
RETURN
END

 附注:每一个页面的里面的CRUD权限在MES:MGridPageBase类下面赋值的。

protected virtual void InitAuthority()
{
Dictionary<string, bool> AuthorityDic = CBF.DAL.RightCtrl.RightCtrl.PageRightCtrl(this.Page.User.Identity.Name.Trim(), this.CurrentModuleID);
foreach (KeyValuePair<string, bool> entry in AuthorityDic)
{
string propertyName = "Enable" + entry.Key.Replace("RGP", "").Trim();
if (this.GetType().GetProperty(propertyName) != null)
{
this.GetType().GetProperty(propertyName)
.SetValue(this, Convert.ChangeType(entry.Value, this.GetType()
.GetProperty(propertyName).PropertyType), null);
}
}
}

免责声明:文章转载自《权限控制管理(用户与菜单项的关联)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Oracle Forms Services Architecture3.2.2奶骑指南:到80之后如何选择和更新装备下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

使用 vue3 的自定义指令给 element-plus 的 el-dialog 增加拖拽功能

element-plus 提供的 el-dialog 对话框功能非常强大,只是美中不足不能通过拖拽的方式改变位置,有点小遗憾,那么怎么办呢?我们可以通过 vue 的自定义指令来实现一个可以拖拽的对话框(el-dialog)。 拖拽演示 https://www.zhihu.com/zvideo/1380450791975731200 vue3 的自定义指令...

window下安装itchat库

itchat是一个开源的微信个人号接口,使用python调用微信从未如此简单。 pip 是 Python 著名的包管理工具,在 Python 开发中必不可少。 1、安装   检查你有没有安装了pip:运行,输入cmd,回车,输入pip,回车。如果提示“'pip' 不是内部或外部命令”,原因是电脑本地没有安装pip命令。   这有两种办法安装pip:   A...

报错:(未解决)java.lang.VerifyError: Instruction type does not match stack map

报错背景: CDH中集成kafka的服务,解决完kafka的jar包报错之后重启,发现这个报错。 报错现象: java.lang.VerifyError: Instruction type does not match stack map Exception Details: Location: org/eclipse/jetty/se...

vue-cli3使用less全局变量,不用每个组件引入less文件(亲测有效)

问题: 在global.less文件中定义一些全局使用的less变量; 结果组件使用这些全局变量时,都要@import "~@/styles/global.less"引入该文件,否则报错 解决方法和步骤 1. 安装style-resources-loader yarn add style-resources-loader 2. 在vue.config.j...

微信浏览器禁止页面下拉查看网址(不影响页面内部scroll)

开发项目跑在微信浏览器经常会遇到一个问题,微信浏览器下拉的时候会出现自带的黑色底色(显示网址)如下图: 此类事件是手机touchmove默认事件行为,可以通过js代码隐藏事件: $(‘body’).on(‘touchmove’, function (event) {event.preventDefault();}); or document.addEve...

用随机森林分类

分类方法有很多种,什么多分类逻辑回归,KNN,决策树,SVM,随机森林等, 比较好用的且比较好理解的还是随机森林,现在比较常见的有python和R的实现。原理就不解释了,废话不多说,show me the code import csv import numpy as np from sklearn.ensemble import RandomForest...