public string GetLeftMenuInfo() { string html = ""; //根据当前用户权限等级获取对应菜单 if (currentadminUser != null) { //int RoleId = Convert.ToInt32(currentadminUser.SopRoleId); //Sys_Role RoleMod = RoleService.GetModel(s => s.ID == RoleId); GetRoleClass GRC = GetRoleValueAndButton(currentadminUser.RoleID.ToString()); if (GRC != null) { //当前用户权限真实存在 string RoleStr = GRC.ROLEVALUE; //去掉字符串生成时可能出现的多余逗号 string Rval = ""; string[] RoleArr = RoleStr.Split(','); foreach (string Str in RoleArr) { if (!string.IsNullOrEmpty(Str)) { Rval += Str + ","; } } //获取当前权限下最上级菜单 string SQL = "select * from Mpr_Admin_Menu where id in (" + Rval.TrimEnd(',') + ") order by Sort asc"; DataTable DT = SQLSerivice.Query(SQL).Tables[0]; foreach (DataRow Dr in DT.Select(" RightParent = 0")) { html += GetNextMenu(Dr, DT); } } } return(html); }
/// <summary> /// 获取 当前用户对应权限数据 /// </summary> /// <returns></returns> public List <Mpr_Admin_ButtonRole> ButtonRoleList(int pageID) { if (currentadminUser != null) { //首先通过入参的参数获取对应数据信息 List <Mpr_Admin_ButtonRole> ButtonRoleList = ButtonRoleService.FindByParam(s => s.PageID == pageID); if (ButtonRoleList.Count > 0) { //获取对应按钮权限字符串 //Sys_Role RoleMod = RoleServivce.GetModel(s => s.ID == currentadminUser.SopRoleId); GetRoleClass GRC = GetRoleValueAndButton(currentadminUser.RoleID.ToString()); if (GRC != null) { string ButtonRole = GRC.ButtonRole; if (!string.IsNullOrEmpty(ButtonRole)) { List <Mpr_Admin_ButtonRole> ResultList = new List <Mpr_Admin_ButtonRole>(); //通过字符串获取对应数据列表 List <string> StrList = ButtonRole.Split(',').ToList(); foreach (string str in StrList) { if (!string.IsNullOrEmpty(str)) { int Roleinfoid = Convert.ToInt32(str); //筛选出权限数据进行返回 Mpr_Admin_ButtonRole ButtonRoleId = ButtonRoleList.Where(s => s.ID == Roleinfoid).FirstOrDefault(); if (ButtonRoleId != null) { ResultList.Add(ButtonRoleId); } } } return(ResultList); } else { return(null); } } else { //还是没权限 return(null); } } else { //当前连按钮都没做 有个P的用户权限 return(null); } } else { //如果这里为空 表示表示什么权限都没有,此处未登录默认无任何页面按钮权限 return(null); } }
/// <summary> /// /// </summary> /// <returns></returns> public GetRoleClass GetRoleValueAndButton(string SopRoleId) { //获取权限列表,返回按钮权限以菜单权限 if (!string.IsNullOrEmpty(SopRoleId)) { GetRoleClass RoleValue = new GetRoleClass(); try { string[] Spr = SopRoleId.Split(','); foreach (string Str in Spr) { //获取ID Sys_Role RoleMod = RoleServivce.GetModel(s => s.ID == Str); if (RoleMod != null) { RoleValue.ROLEVALUE += RoleMod.ROLEVALUE + ","; RoleValue.ButtonRole += RoleMod.ButtonRole + ","; } } if (!string.IsNullOrEmpty(RoleValue.ROLEVALUE)) { RoleValue.ROLEVALUE = RoleValue.ROLEVALUE.TrimEnd(','); } if (!string.IsNullOrEmpty(RoleValue.ButtonRole)) { RoleValue.ButtonRole = RoleValue.ButtonRole.TrimEnd(','); } return(RoleValue); } catch (Exception ex) { return(null); } } else { return(null); } }