using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Data.SqlClient; using Lskj.Util; using Lskj.Model; namespace Lskj.Business.Impl { public class PowerImpl : BaseImpl { /// /// 说明:获取只读或操作权限表 /// 创建人:王一帆 /// 创建日期:2019-09-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// DataTable. public static DataTable GetPurview(string condition) { if (string.IsNullOrWhiteSpace(condition)) { string allSql = string.Format("select * from p_formmenuconfigtab where len(MenuStruct)>2"); return GetDataTableResult(allSql); } string sqlValue = string.Format("select * from p_formmenuconfigtab where len(MenuStruct)>2 and menuId in({0})", condition); return GetDataTableResult(sqlValue); } /// /// 说明:获取子系统表 /// 创建人:王一帆 /// 创建日期:2019-09-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// DataTable. public static DataTable GetSystemsTitle() { string sqlValue = "select * from P_SubSystemTab where UseEd='1'"; return GetDataTableResult(sqlValue); } /// /// 说明:获取子系统表模块 /// 创建人:王一帆 /// 创建日期:2019-09-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// DataTable. public static DataTable GetSystemsTable(string way, bool isChildren) { string sqlValue = isChildren ? "select * from p_formmenuconfigtab where " + way : "select * from p_formmenuconfigtab where ParentMenuId='-1' and LEN(MenuStruct)=2 " + way; return GetDataTableResult(sqlValue); } /// /// 说明:获取员工表 /// 创建人:王一帆 /// 创建日期:2019-09-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// DataTable. public static DataTable GetWorkEmployee() { string sqlValue = "select * from P_employeeBaseView"; return GetDataTableResult(sqlValue); } /// /// 说明:获取员工表,除当前员工 /// 创建人:王一帆 /// 创建日期:2019-09-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// DataTable. public static DataTable GetWorkEmployee(string id) { string sqlValue = string.Format("select 员工ID,员工姓名 from P_employeeBaseView where 员工ID<>'{0}'", id); return GetDataTableResult(sqlValue); } /// /// 说明:获取角色表 /// 创建人:王一帆 /// 创建日期:2019-09-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// DataTable. public static DataTable GetWorkRole(string depid, string mf) { string where = string.Empty; if (!string.IsNullOrEmpty(depid)) where = string.Format(" where operatorid='{0}'", depid); if (!string.IsNullOrEmpty(mf)) where = string.Format(" and (loginaccount like '%{0}%' or employeename like '%{0}%' or dbo.P_getpy(employeename) like '%{0}%')", mf); string sqlValue = "select * from p_systemRoleSetTab" + where; return GetDataTableResult(sqlValue); } /// /// 说明:获取角色表,除当前角色 /// 创建人:王一帆 /// 创建日期:2019-09-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// DataTable. public static DataTable GetWorkRole(string id) { string sqlValue = string.Format("select id,roleName from p_systemRoleSetTab where id<>'{0}'", id); return GetDataTableResult(sqlValue); } /// /// 说明:获取人员权限表 /// 创建人:王一帆 /// 创建日期:2019-09-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// DataTable. public static DataTable GetWorkUsers(string roleId) { string where = string.Empty; if (!string.IsNullOrEmpty(roleId)) where = " and roleId=" + roleId; string sqlValue = "select roleOperatorId as 员工ID,JobNumber as 员工工号,emp.employeename as 员工姓名,department as 所属部门 from p_systemRoleOperSetTab ro right join p_employeetab emp on ro.roleOperatorId=emp.employeeid where ISNULL(emp.sign, 0) = 0 " + where; if (SystemInfo.Instance.DisplayResignation) { sqlValue = "select roleOperatorId as 员工ID,JobNumber as 员工工号,emp.employeename as 员工姓名,department as 所属部门, p_emp_endworksf as 是否离职 from p_systemRoleOperSetTab ro right join p_employeetab emp on ro.roleOperatorId=emp.employeeid where ISNULL(emp.sign, 0) = 0 " + where; } return GetDataTableResult(sqlValue); } /// /// 说明:获取表树形结构表 /// 创建人:王一帆 /// 创建日期:2019-09-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// DataTable. public static DataTable GetMenuTreeViewData() { string sqlValue = @" WITH tmenu(id,MenuCaption,ParentId,menuid,SubSysId,level) as ( SELECT convert(varchar(50), menu.SubSysId)+'_'+ MenuStruct id,MenuCaption,CONVERT(varchar(50), -CONVERT(int, menu.SubSysId)) ParentId,menu.menuid,menu.SubSysId,1 level FROM p_formmenuconfigtab menu inner join P_SubSystemTab sub on menu.SubSysId=sub.SubSysId and ISNULL(UseEd,0)=1 where ISNULL(UseFlag,1)=1 and LEN(menustruct)=2 UNION ALL SELECT convert(varchar(50), a.SubSysId)+'_'+A.MenuStruct id, A.MenuCaption,CONVERT(varchar(50),convert(varchar(50), a.SubSysId)+'_'+ SUBSTRING(a.MenuStruct,1,case when LEN(a.MenuStruct)>2 then LEN(a.MenuStruct)-2 else 0 end)) ParentId,a.MenuId,a.SubSysId ,b.level+1 FROM p_formmenuconfigtab A,tmenu b where LEN(a.MenuStruct)>2 and ISNULL(UseFlag,1)=1 and convert(varchar(50), a.SubSysId)+'_'+ SUBSTRING(a.MenuStruct,1,case when LEN(a.MenuStruct)>2 then LEN(a.MenuStruct)-2 else 0 end) = b.id and a.SubSysId=b.SubSysId ) select tm.MenuId, lm.id id,tm.urlparams menucode,tm.MenuCaption,tm.DllFileName library,lm.ParentId parentId,tm.SubSysId, lm.level,'' readflag, '' writeflag from tmenu lm left join p_formmenuconfigtab tm on lm.menuid=tm.menuid where isnull(tm.useFlag,1)=1 union all select '' menuid,convert(varchar(10), -SubSysId) MenuStruct ,'' menucode,subsysname MenuCaption,'' library,'' parentid,SubSysId,0 level,'' editflag, '' Readflag from P_SubSystemTab where ISNULL(UseEd,0)=1 ORDER BY SubSysId,id"; return GetDataTableResult(sqlValue); } /// /// 说明:保存人员权限设置 /// 创建人:王一帆 /// 创建日期:2019-10-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static bool SaveRoleOperDate(string OperId, string OperName, string departemnt, string readdate, string editdate) { string sqlValue = string.Format(" if exists (select * from p_systemRoleOperSetTab s where s.operatorid='{0}' and roleId='0' ) update p_systemRoleOperSetTab set ReadPurview='{4}',EditPurview='{5}' where operatorid = '{0}' and roleId='0' ELSE insert into p_systemRoleOperSetTab (roleId,roleOperatorId,operatorid,operatorname,operatedate,department,ReadPurview,EditPurview) values ('0','{0}','{0}','{1}','{2}','{3}','{4}','{5}')", OperId, OperName, DateTime.Now, departemnt, readdate, editdate); return ExecSqlValue(sqlValue) > 0; } /// /// 说明:保存人员权限设置,模块分角色 /// 创建人:王一帆 /// 创建日期:2019-10-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static bool SaveRoleOperDate(string OperId, string OperName, string departemnt, string readdate, string editdate, bool IsBrowse) { string sqlValue = string.Empty; if (IsBrowse) { sqlValue = string.Format(" if exists (select * from p_systemRoleOperSetTab s where s.operatorid='{0}') update p_systemRoleOperSetTab set ReadPurview='{4}' where operatorid = '{0}' ELSE insert into p_systemRoleOperSetTab (roleId,roleOperatorId,operatorid,operatorname,operatedate,department,ReadPurview,EditPurview) values ('0','{0}','{0}','{1}','{2}','{3}','{4}','{5}')", OperId, OperName, DateTime.Now, departemnt, readdate, ""); } else { sqlValue = string.Format(" if exists (select * from p_systemRoleOperSetTab s where s.operatorid='{0}') update p_systemRoleOperSetTab set EditPurview='{5}' where operatorid = '{0}' ELSE insert into p_systemRoleOperSetTab (roleId,roleOperatorId,operatorid,operatorname,operatedate,department,ReadPurview,EditPurview) values ('0','{0}','{0}','{1}','{2}','{3}','{4}','{5}')", OperId, OperName, DateTime.Now, departemnt, "", editdate); } return ExecSqlValue(sqlValue) > 0; } /// /// 说明:获取角色模块信息 /// 创建人:王一帆 /// 创建日期:2019-10-10 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu code. /// DataRow. /// public static DataRow GetRoleRow(string id) { string sqlValue = string.Format("select * from p_systemRoleSetTab where id='{0}'", id); DataTable dtTable = GetDataTableResult(sqlValue); return dtTable.Rows.Count > 0 ? dtTable.Rows[0] : null; } /// /// 说明:获取角色模块信息 /// 创建人:王一帆 /// 创建日期:2019-10-10 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The menu code. /// DataRow. /// public static DataRow GeRoleOperRow(string id) { string sqlValue = string.Format("select * from P_employeeBaseView where 员工ID='{0}' ", id); DataTable dtTable = GetDataTableResult(sqlValue); return dtTable.Rows.Count > 0 ? dtTable.Rows[0] : null; } /// /// 说明:拖拽人员修改权限设置 /// 创建人:王一帆 /// 创建日期:2019-10-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static bool DropDate(int OperId, string JobNumber, string OperName, string departemnt, string id) { string sqlValue = string.Format("INSERT INTO p_systemRoleOperSetTab (roleId, roleOperatorId,operatorid,operatorname,department,operatedate,JobNumber) VALUES ('{0}','{1}','{1}','{2}','{3}','{4}','{5}')", id, OperId, OperName, departemnt, DateTime.Now, JobNumber); return ExecSqlValue(sqlValue) > 0; } /// /// 说明:保存角色权限设置 /// 创建人:王一帆 /// 创建日期:2019-10-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static bool SaveRoleDate(string id, string readdate, string editdate) { string sqlValue = string.Format("UPDATE p_systemRoleSetTab SET ReadPurview = '{0}',EditPurview = '{1}' WHERE id = {2}", readdate, editdate, id); return ExecSqlValue(sqlValue) > 0; } /// /// 说明:删除人员权限设置 /// 创建人:王一帆 /// 创建日期:2019-10-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static bool deletRoleDate(string id, string roleId) { string sqlValue = string.Format("DELETE FROM p_systemRoleOperSetTab WHERE operatorid = '{0}' and roleId='{1}'", id, roleId); return ExecSqlValue(sqlValue) > 0; } /// /// 说明:删除角色权限设置 /// 创建人:王一帆 /// 创建日期:2019-10-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static bool deletRoleoperDate(string id) { string sqlValue = string.Format("DELETE FROM p_systemRoleSetTab WHERE id = '{0}'", id); return ExecSqlValue(sqlValue) > 0; } /// /// 说明:获取小类设置操作员 /// 创建人:龚宇超 /// 创建日期:2019-06-24 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// DataTable. public static DataTable GetWorkFlowUsers(string mc, string dc) { string where = string.Empty; if (!string.IsNullOrEmpty(mc)) where = string.Format(" where (员工姓名 like '%{0}%' or dbo.P_getpy(员工姓名) like '%{0}%')", mc); if (!string.IsNullOrEmpty(dc)) { where += string.IsNullOrWhiteSpace(mc) ? string.Format(" where 员工工号 like '%{0}%'", dc) : string.Format(" and 员工工号 like '%{0}%'", dc); } string sqlValue = "select 员工ID,员工工号,员工姓名,所属部门 from P_employeeBaseView " + where; return GetDataTableResult(sqlValue); } /// /// 说明:添加新的角色 /// 创建人:王一帆 /// 创建日期:2019-10-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static bool intnewOper(string OperName) { string sqlValue = string.Format("INSERT INTO p_systemRoleSetTab (roleName,operatedate) VALUES ('{0}','{1}')", OperName, DateTime.Now); return ExecSqlValue(sqlValue) > 0; } /// /// 说明:修改角色 /// 创建人:王一帆 /// 创建日期:2019-10-08 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static bool UpdOper(string OperName, string id) { string sqlValue = string.Format("Update p_systemRoleSetTab set roleName='{0}',operatedate='{1}' where id={2} ", OperName, DateTime.Now, id); return ExecSqlValue(sqlValue) > 0; } /// /// 说明:获得全部模块内容 /// 创建人:曹屹峰 /// 创建日期:2022-6-17 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static DataTable GetAllModulesData() { //string sqlValue = "select convert(varchar(50), SubSysId)+'_'+ MenuStruct ID ,MenuId,MenuCaption,PurviewId,'0' as Editflag ,'0' as Readflag,DllFilename from P_FormMenuConfigTab order by MenuId"; string sqlValue = @"select b.subsysname as FirstDirectory, (select MenuCaption from P_FormMenuConfigTab where subsysid=a.SubSysId and len(menustruct)=2 and MenuStruct=left(a.menustruct,2) and useFlag=1) as SecondaryDirectory, convert(varchar(50), a.SubSysId)+'_'+ MenuStruct ID ,MenuId,MenuCaption,PurviewId,'0' as Editflag ,'0' as Readflag,DllFilename from P_FormMenuConfigTab a left join P_SubSystemTab b on a.SubSysId=b.SubSysId order by FirstDirectory,SecondaryDirectory"; return GetDataTableResult(sqlValue); } /// /// 说明:获得全部模块内容(提示格式) /// 创建人:曹屹峰 /// 创建日期:2022-6-17 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static DataTable GetAllModulesDataSpecial() { string sqlValue = @"select convert(varchar(50), aa.SubSysId)+'_'+ MenuStruct ID , ss.SubSysName as 主模块,MenuId,aa.MenuCaption as 菜单名字,PurviewId,'0' as Editflag ,'0' as Readflag,DllFilename from P_FormMenuConfigTab aa join P_SubSystemTab ss on ss.SubSysId=aa.SubSysId order by MenuId"; return GetDataTableResult(sqlValue); } /// /// 说明:获得全部基础模块内容 /// 创建人:曹屹峰 /// 创建日期:2022-6-17 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static DataTable GetBasisData(string tab) { string basisSql = string.Format(@"select * from ( select formkey,DataFormat,addVisible, id,tab,orderid,fieldName,sysname,username1,width,vislble,vislble1,tagid,fieldsqltag,edit,defaultdate,UserBak,UserOpname,UserOpDt,privilegeView,privilegeOper from p_systemwordbooktab where 1=1 and (isnull(vislble,0)=0 or ISNULL(addVisible,0)=0) and width>0 ) a where 1=1 and tab='{0}' order By orderid", tab); DataTable table = GetDataTableResult(basisSql); if (!table.Columns.Contains("username"))//表格中的列不包含指定列名 { table.Columns["username1"].ColumnName = "userName"; } return table; } /// /// 说明:获得单据抬头 /// 创建人:曹屹峰 /// 创建日期:2022-6-17 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static DataTable GetBillAboveData(string tab) { //string Sql = string.Format(@" select * from // (select top 1000 formkey,typeCode,id,orderid,fieldName,sysName,userName,fieldTypeId,nullable,isVisible,edited, width, defaultValue,UserBak,UserOpname,UserOpDt,privilegeView,privilegeOper,'0' as OperValue,'0' as ViewValue from p_systembillInfo // where 1=1 and isnull(isvisible,0)=0 order by orderid ) a // where 1=1 and typeCode='{0}'", tab); string Sql = string.Format(@" select * from (select formkey,typeCode,id,orderid,fieldName,sysName,userName,fieldTypeId,nullable,isVisible,edited, width, defaultValue,UserBak,UserOpname,UserOpDt,privilegeView,privilegeOper from p_systembillInfo where 1=1 and isnull(isvisible,0)=0) a where 1=1 and typeCode='{0}' order by orderid ", tab); return GetDataTableResult(Sql); } /// /// 说明:获得单据明细 /// 创建人:曹屹峰 /// 创建日期:2022-6-17 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static DataTable GetBillDetailData(string tab) { //string Sql = string.Format(@" select * from // (select top 1000 DataFormat,typeCode,id,orderid,fieldName,sysName,userName,fieldTypeId,nullable,isVisible,edited, width, defaultValue,UserBak,UserOpname,UserOpDt,privilegeView,privilegeOper,'0' as OperValue,'0' as ViewValue from p_systembilldetail // where 1=1 and isnull(isvisible,0)=0 and width>0 order by orderid )a // where 1=1 and typeCode='{0}' ", tab); string Sql = string.Format(@" select * from (select DataFormat,typeCode,id,orderid,fieldName,sysName,userName,fieldTypeId,nullable,isVisible,edited, width, defaultValue,UserBak,UserOpname,UserOpDt,privilegeView,privilegeOper from p_systembilldetail where 1=1 and isnull(isvisible,0)=0 and width>0 )a where 1=1 and typeCode='{0}' order by orderid ", tab); return GetDataTableResult(Sql); } //获得全部权限人员 public static string getAllPersonnel(string name) { if (string.IsNullOrWhiteSpace(name)) return ""; //获得所有角色 List condition = ReplaceHelper.GetParamFields(name); DataTable dataTable = GetWorkRole("", ""); foreach (string role in condition) { string newName = string.Empty; string roleName = role.Replace("{&", "").Replace("&}", ""); DataRow[] drs = dataTable.Select("roleName='" + roleName + "'"); if (drs.Length < 1) continue; string id = drs[0]["id"] + ""; DataTable PersonnelDt = GetWorkUsers(id); foreach (DataRow dr in PersonnelDt.Rows) { newName += dr["员工姓名"] + ","; } name = name.Replace(role, newName.TrimEnd(',')); } return name; } /// /// 说明:获得权限分类 /// 创建人:曹屹峰 /// 创建日期:2024-03-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static DataTable GetModuleAuthority(string tab) { BaseImpl.HasExistsColumn("p_systemPrivilege", "roleid", "int"); // select CAST(privTypeId AS VARCHAR) + ',' + privTypeName as DisplayName,*from p_systemPrivilege where isnull(isVisible, 0) = 0 and modId = '{0}' string Sql = string.Format(@"select CAST(privTypeId AS VARCHAR) + ','+privTypeName as DisplayName,id,privTypeId,privTypeName,modId,userList,remark,isnull(isVisible,0) AS isVisible,roleid from p_systemPrivilege where modId='{0}' order by privTypeId", tab); return GetDataTableResult(Sql); } /// /// 说明:获得启用的权限分类 /// 创建人:曹屹峰 /// 创建日期:2024-03-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static DataTable GetModuleAuthorityEnable(string tab) { string Sql = string.Format(@"select * from P_SYSTEMPRIVILEGE where modId='{0}' and isnull(isVisible,0)=0 order by privTypeId", tab); return GetDataTableResult(Sql); } /// /// 说明:角色中人员变化后,刷新对应的权限分类 /// 创建人:曹屹峰 /// 创建日期:2024-03-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static void RefreshElementPermissions(string roleid) { DataTable Roledetailed = PowerImpl.GetWorkUsers(roleid); string text = string.Empty; if (Roledetailed != null && Roledetailed.Rows.Count > 0) { foreach (DataRow dr in Roledetailed.Rows) { text += dr["员工姓名"] + ","; } } string Sql = string.Format(@"update p_systemPrivilege set userList='{0}' where roleid='{1}'", text, roleid); ExecSqlValue(Sql); } /// /// 说明:删除权限分类(删除角色权限设置时删除对应的) /// 创建人:曹屹峰 /// 创建日期:2024-04-14 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static bool deletPermissionClassification(string id) { if (BaseImpl.HasExistsColumn("p_systemPrivilege", "roleid")) { string sqlValue = string.Format("DELETE FROM p_systemPrivilege WHERE roleid = '{0}'", id); return ExecSqlValue(sqlValue) > 0; } return false; } /// /// 说明:获得右键权限信息 /// 创建人:曹屹峰 /// 创建日期:2024-04-11 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// System.Int32. public static DataTable GetRightMenus(string ModuleCode, ModuleType type = ModuleType.BaseModule) { string where = string.Empty; switch (type) { case ModuleType.MrpClickBtn: if (BaseImpl.HasExistsColumn("P_systempopupmenu", "isMrpClickBtn", "int")) { where = " and isnull(isMrpClickBtn,0)=1 and visible1=0 "; } break; case ModuleType.BillDetail: where = " and isnull(menutype,0)=1 and visible1=0 "; break; case ModuleType.BillAuditDetail: where = " and isnull(menutype,0)=0 and visible2=0 "; break; case ModuleType.BaseAudit: where = " and isnull(menutype,0)=1 and isnull(visible1,0)=0 "; break; case ModuleType.BaseModuleAdd: where = " and isnull(menutype,0)=1"; break; case ModuleType.MESTOOL: where = " and isnull(ShowToolBar,0)=1"; break; case ModuleType.MESGRIDRIGHT: where = " and isnull(ShowToolBar,0)=0"; break; default: where = " and isnull(menutype,0)=0"; break; } string sqlValue = string.Format("select * from P_systempopupmenu where isnull(visible,0)=0 and tab='{0}' ", ModuleCode) + where + " order by orderid"; //return SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@tab", key) }); return GetDataTableResult(sqlValue); } /// /// 设置角色权限后生成对应的权限分类 /// /// /// /// public static void SetRolePermissionclassification(string roleid, string roleName, DataTable Module) { BaseImpl.HasExistsColumn("p_systemPrivilege", "roleid", "int"); //获取角色对应人员 DataTable Roledetailed = PowerImpl.GetWorkUsers(roleid); string text = string.Empty; if (Roledetailed != null && Roledetailed.Rows.Count > 0) { foreach (DataRow dr in Roledetailed.Rows) { text += dr["员工姓名"] + ","; } } List NewModule = new List();//当前设置的权限模块 List OldModule = new List();//之前在权限分类表中存在当前角色的模块 foreach (DataRow item in Module.Rows) { string PurviewId = item["PurviewId"] + ""; if (!string.IsNullOrWhiteSpace(PurviewId) && !NewModule.Contains(PurviewId)) { NewModule.Add(PurviewId); } } DataTable dataTable = GetDataTableResult(string.Format("select * from p_systemPrivilege where roleid='{0}'", roleid)); foreach (DataRow item in dataTable.Rows) { string PurviewId = item["modId"] + ""; if (!string.IsNullOrWhiteSpace(PurviewId) && !OldModule.Contains(PurviewId)) { OldModule.Add(PurviewId); } } string Sql = string.Empty; List AddList = NewModule.Except(OldModule).ToList(); List DeleteList = OldModule.Except(NewModule).ToList(); //添加新增的权限模块 foreach (string item in AddList) { DataRow dr = GetDataRowResult(string.Format("select top 1 privTypeId from p_systemPrivilege where modId='{0}' order by privTypeId desc ", item)); int privTypeId = 1; if (dr != null) privTypeId = int.Parse(dr["privTypeId"] + "") + 1; Sql += string.Format(" insert into p_systemPrivilege(privTypeId,privTypeName,modId,userList,remark,roleid) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}'); ", privTypeId + "", roleName, item, text, "", roleid); } //删除移除的权限模块 foreach (string item in DeleteList) { Sql += string.Format(" delete p_systemPrivilege where roleid='{0}' and modId='{1}'; ", roleid, item); } ExecSqlValue(Sql); //拼接添加权限分类sql //List moduleNumbers = new List(); //string Sql = string.Format("delete p_sy