public ActionResult create(string group_code) { try { var group = dbcontext.User_Group_Info.FirstOrDefault(m => m.User_Group_Code == group_code); var Per = new User_Permissions { User_Group_Code = group_code, Modified_By = group.User_Group_Desc }; ViewBag.module = dbcontext.permissions.Where(m => m.type_permission == type_permission.module).ToList().Select(m => new { Permission_Name = '[' + m.Permission_Name + ']', ID = m.ID }).ToList(); // ViewBag.submodule = dbcontext.permissions.Where(m => m.type_permission == type_permission.sub_module).ToList().Select(m => new { Permission_Name = '[' + m.Permission_Name + ']', ID = m.ID }).ToList(); return(View(Per)); } catch (Exception) { return(RedirectToAction("index")); } }
public IActionResult AddUser([FromBody] JObject jo) { var username = jo["user_name"].ToString(); if (string.IsNullOrEmpty(username)) { return(ResponseData(null, "Username is not empty", 422)); } if (_mainContext.user_permissions.Where(u => u.username.Equals(username)).FirstOrDefault() != null) { return(ResponseData(null, "User is exists in system", 422)); } User_Permissions user_prms = new User_Permissions(username, 3, 1, 0); _mainContext.user_permissions.Add(user_prms); _mainContext.SaveChanges(); return(ResponseData(null, "Add user success")); }
/// <summary> /// 修改时,绑定原来已有的页面权限 /// </summary> /// <param name="id">当前ID</param> private void GetPostDataBind(string id) { try { #region 权限集合 List <User_Permissions> UPermissions = new User_PermissionsBLL().GetListById(Guid.Parse(id));//mUser.DeptId User_Permissions mPost = UPermissions[0]; //权限集合 if (mPost != null) { this.txtRemark.Text = mPost.Remark; string[] value = mPost.Permissions.Split(','); //遍历权限 foreach (TreeNode childnodes in trvPagePower.Nodes) { foreach (TreeNode childnodes2 in childnodes.ChildNodes) { foreach (TreeNode childnodes3 in childnodes2.ChildNodes) { for (int i = 0; i < value.Length; i++) { if (value[i] == childnodes3.Value) { childnodes.Checked = true; childnodes2.Checked = true; childnodes.Expanded = true; childnodes2.Expanded = true; childnodes3.Expanded = true; childnodes3.Checked = true; } } } } } } #endregion } catch (Exception ex) { } }
/// <summary> /// /// </summary> public void GetPagePermissions() { try { hid_RoleType.Value = mCompany.RoleType.ToString(); User_Permissions mPost = null; if (m_UserPermissions != null) { //Session中获取登录用户页面权限 mPost = m_UserPermissions; } else { //数据库中读取用户权限 mPost = new PbProject.Logic.User.User_PermissionsBLL().GetById(mUser.DeptId); } if (mPost != null && !string.IsNullOrEmpty(mPost.Permissions)) { string strValue = "," + mPost.Permissions.Replace(",", ",") + ","; string strIndex = ","; //缓存获取菜单页面 List <Bd_Base_Page> iPostList = new PbProject.Logic.ControlBase.Bd_Base_PageBLL().GetListByCache(mCompany.RoleType); foreach (Bd_Base_Page item in iPostList) { if (strValue.Contains("," + item.PageIndex + ",") && !strIndex.Contains("," + item.ModuleIndex + ",")) { strIndex += item.ModuleIndex + ","; } } hid_ShowModuleIndex.Value = strIndex; } } catch (Exception ex) { } }
/// <summary> /// 生成菜单 /// </summary> /// <param name="type"></param> private void CreateLeft(string type) { try { PbProject.Logic.ControlBase.Bd_Base_PageBLL basePage = new PbProject.Logic.ControlBase.Bd_Base_PageBLL(); PbProject.Logic.User.User_PermissionsBLL uPermissions = new PbProject.Logic.User.User_PermissionsBLL(); List <Bd_Base_Page> iPostResult = new List <Bd_Base_Page>(); int roleType = mCompany.RoleType; //缓存获取菜单页面 List <Bd_Base_Page> iPost = basePage.GetListByCache(roleType); User_Permissions mPost = null; if (m_UserPermissions != null) { //Session中获取登录用户页面权限 mPost = m_UserPermissions; } else { //数据库中读取用户权限 mPost = uPermissions.GetById(mUser.DeptId); } string strValue = "," + mPost.Permissions.Replace(",", ",") + ","; string temp = ""; //得到一级菜单数 ArrayList listValue = new ArrayList(); ArrayList listName = new ArrayList(); for (int j = 0; j < iPost.Count; j++) { temp = "," + iPost[j].PageIndex + ","; //if (temp.Contains("138 ")) //{ // string str = temp;//测试 //} if (strValue.Contains(temp) && iPost[j].ModuleIndex.ToString() == type && iPost[j].TwoMenuIndex != 0 && iPost[j].RoleType == roleType) { if (!listValue.Contains(iPost[j].OneMenuIndex)) { listValue.Add(iPost[j].OneMenuIndex); listName.Add(iPost[j].OneMenuName); } iPostResult.Add(iPost[j]); } } //控制菜单高度 int[] iheight = new int[listValue.Count]; //生成二级菜单 string[] str = new string[listValue.Count]; for (int i = 0; i < iPostResult.Count; i++) { for (int j = 0; j < listValue.Count; j++) { if (iPostResult[i].OneMenuIndex.ToString() == listValue[j].ToString() && iPostResult[i].TwoMenuIndex != 0) { if (iPostResult[i].PageURL.Contains("/StrategyGroupList.aspx")) { //没有显示策略组的权限不显示菜单 } else if (iPostResult[i].PageName.Contains("高返政策")) { //判断是否允许放高返政策 True为有 False无 } else { string tempUrl = iPostResult[i].PageURL.IndexOf('?') < 0 ? string.Format("{0}?currentuserid={1}", iPostResult[i].PageURL, this.currentuserid.Value.ToString()) : string.Format("{0}¤tuserid={1}", iPostResult[i].PageURL, this.currentuserid.Value.ToString()); str[j] += "<li><a href=\"" + tempUrl + "\" target=\"ALLFrame\" style=\"height:30px;\">" + iPostResult[i].TwoMenuName + "</a></li>"; } iheight[j]++; } } } //追加一级菜单 for (int j = 0; j < listValue.Count; j++) { temp = str[j]; StringBuilder _sb = new StringBuilder(""); str[j] = "<h3><a href=\"javascript:void(0)\">" + listName[j].ToString() + "</a></h3><div style=\"padding: 0px;\"><ul>" + temp + _sb.ToString() + "</ul></div>"; } //合并字符串 StringBuilder sb = new StringBuilder(); for (int j = 0; j < listValue.Count; j++) { sb.Append(str[j]); } accordion.InnerHtml = sb.ToString(); } catch (Exception) { } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAdd_Click(object sender, EventArgs e) { string msg = ""; bool result = false; try { string strDeptName = txtDeptName.Text.Trim(); if (string.IsNullOrEmpty(strDeptName)) { msg = "该名称不能为空!"; } List <User_Permissions> iPost = new User_PermissionsBLL().GetListByCpyNo(mUser.CpyNo); foreach (var item in iPost) { if (item.DeptName == strDeptName && hidId.Value == "") { msg = "添加失败,该名称已经存在!"; break; } //else if (item.DeptName == strDeptName && hidId.Value != item.id.ToString()) //{ // msg = "修改失败,该名称已经存在!"; // break; //} } if (msg == "") { if (hidId.Value == "") { #region 添加 User_Permissions model = new User_Permissions(); model.id = Guid.NewGuid(); model.CpyNo = mUser.CpyNo; model.DeptName = strDeptName; model.ParentIndex = 1; model.DeptIndex = 1; model.Remark = txtRemark.Text.Trim(); model.Permissions = GetPermissions(); model.A1 = 1; model.A2 = 0.00M; model.A3 = DateTime.Now; model.A4 = ""; model.A5 = ""; result = (bool)baseDataManage.CallMethod("User_Permissions", "Insert", null, new Object[] { model }); if (result) { msg = "添加成功!"; } else { msg = "添加失败!"; } #endregion } else { #region 修改 IHashObject parameter = new HashObject(); //User_Permissions model = new User_Permissions(); parameter.Add("id", Guid.Parse(hidId.Value)); parameter.Add("DeptName", strDeptName); parameter.Add("Permissions", GetPermissions()); parameter.Add("Remark", txtRemark.Text.Trim()); result = (bool)baseDataManage.CallMethod("User_Permissions", "Update", null, new Object[] { parameter }); if (result) { msg = "修改成功!"; } else { msg = "修改失败!"; } #endregion } } } catch (Exception) { msg = "操作失败!"; } finally { ScriptManager.RegisterStartupScript(this, GetType(), DateTime.Now.Ticks.ToString(), "showdialog('" + msg + "');", true); } }
/// <summary> /// 原先设计用的是Session现在改为Application,但是方法名称未改变,避免过多改动引发系统不稳定.YYY 2013-6-17 /// </summary> public void LoadSession() { try { SessionContent sessionContent = new SessionContent(); string currentuserid = System.Web.HttpContext.Current.Request["currentuserid"] ?? string.Empty; if (!string.IsNullOrEmpty(currentuserid)) { //if (Session[currentuserid] == null) if (Application[currentuserid] == null) //if (HttpContext.Current.Application[currentuserid] == null) { FormsAuthentication.RedirectToLoginPage(); } else { //sessionContent = Session[currentuserid] as SessionContent; //sessionContent = HttpContext.Current.Application[currentuserid] as SessionContent; sessionContent = Application[currentuserid] as SessionContent; mUser = sessionContent.USER; mCompany = sessionContent.COMPANY; //mSupCompany = sessionContent.SUPCOMPANY; //如果保存的落地运营商的<公司信息>全局变量为空,则重新读取一次数据库 if (Application[sessionContent.parentCpyno + "Company"] == null) { string strwhere = "1=1 and unincode='" + sessionContent.parentCpyno + "'"; List <User_Company> listUser_Company = baseDataManage.CallMethod("User_Company", "GetList", null, new Object[] { strwhere }) as List <User_Company>; if (listUser_Company != null && listUser_Company.Count > 0) { Application[sessionContent.parentCpyno + "Company"] = listUser_Company[0]; } } mSupCompany = Application[sessionContent.parentCpyno + "Company"] as User_Company; baseParametersList = sessionContent.BASEPARAMETERS; //如果保存落地运营商的全局变量为空,则重新读取一次数据库 if (Application[sessionContent.parentCpyno + "Parameters"] == null) { string strwhere = "1=1 and cpyno='" + sessionContent.parentCpyno + "'"; List <Bd_Base_Parameters> listParameters = baseDataManage.CallMethod("Bd_Base_Parameters", "GetList", null, new Object[] { strwhere }) as List <Bd_Base_Parameters>; if (listParameters != null) { Application[sessionContent.parentCpyno + "Parameters"] = listParameters; } } supBaseParametersList = Application[sessionContent.parentCpyno + "Parameters"] as List <Bd_Base_Parameters>;//落地运营商和供应商公司参数信息 //supBaseParametersList = sessionContent.SupBASEPARAMETERS;//落地运营商和供应商公司参数信息 configparam = Bd_Base_ParametersBLL.GetConfigParam(supBaseParametersList); //configparam = sessionContent.CONFIGPARAM; //当前登录用户权限 m_UserPermissions = sessionContent.M_USERPERMISSIONS; // Limits(); } } else { FormsAuthentication.RedirectToLoginPage(); } /* * if (Session[sessionContent.USERLOGIN] == null) * { * FormsAuthentication.RedirectToLoginPage(); * } * else * { * sessionContent = Session[sessionContent.USERLOGIN] as SessionContent; * mUser = sessionContent.USER; * mCompany = sessionContent.COMPANY; * mSupCompany = sessionContent.SUPCOMPANY; * baseParametersList = sessionContent.BASEPARAMETERS; * supBaseParametersList = sessionContent.SupBASEPARAMETERS;//落地运营商和供应商公司参数信息 * configparam = sessionContent.CONFIGPARAM; * //当前登录用户权限 * m_UserPermissions = sessionContent.M_USERPERMISSIONS; * //权限验证 * Limits(); * }*/ //} } catch { // 跳转登陆页 } }
/// <summary> /// 页面权限 /// </summary> private void Limits() { try { string Url = Request.AppRelativeCurrentExecutionFilePath != null ? Request.AppRelativeCurrentExecutionFilePath : ""; Url = Url.Replace("~/", "").ToUpper(); //判断公共页面 foreach (string sTempComm in CommonUrl()) { if (Url.Contains(sTempComm.ToUpper())) { return; } } Bd_Base_PageBLL bd_Base_PageBLL = new Bd_Base_PageBLL(); PbProject.Logic.User.User_PermissionsBLL uPermissionsBLL = new PbProject.Logic.User.User_PermissionsBLL(); IList <Bd_Base_Page> iPostResult = new List <Bd_Base_Page>(); List <Bd_Base_Page> pageList = bd_Base_PageBLL.GetList(); User_Permissions userPermissions = uPermissionsBLL.GetById(mUser.DeptId); string valuePermissions = "," + userPermissions.Permissions + ","; string temp = ""; int pageListCount = pageList != null ? pageList.Count : 0; //得到权限 for (int j = 0; j < pageListCount; j++) { temp = "," + pageList[j].PageIndex.ToString() + ","; if (valuePermissions.Contains(temp) && pageList[j].RoleType == mCompany.RoleType) { iPostResult.Add(pageList[j]); } } int x = 0; for (int i = 0; i < iPostResult.Count; i++) { if (iPostResult[i].PageURL.ToUpper().Contains(Url.ToUpper())) { x++; break; } } if (x == 0) { string[] str = Url.Split('/'); if (str.Length > 2) { //无权限提示 Response.Redirect("../../Power.htm", true); } if (Url.Contains("/")) { //无权限提示 Response.Redirect("../Power.htm", true); } else { //无权限提示 Response.Redirect("Power.htm", true); } } } catch (Exception ex) { } }