protected void Page_Load(object sender, EventArgs e) { string _action = HTRequest.GetQueryString("action"); id = HTRequest.GetQueryInt("id"); if (!string.IsNullOrEmpty(_action) && _action == HTEnums.ActionEnum.Edit.ToString()) { action = HTEnums.ActionEnum.Edit.ToString();//修改类型 if (id == 0) { JscriptMsg("传输参数不正确!", "back"); return; } ht_manager_role temp = db.ht_manager_role.FirstOrDefault(x => x.id == id); if (temp == null) { JscriptMsg("角色不存在或已被删除!", "back"); return; } } if (!Page.IsPostBack) { ChkAdminLevel("manager_role", HTEnums.ActionEnum.View.ToString()); //检查权限 RoleTypeBind(); //绑定角色类型 NavBind(); //绑定导航 if (action == HTEnums.ActionEnum.Edit.ToString()) //修改 { ShowInfo(id); } } }
/// <summary> /// 检查是否有权限 /// </summary> /// <param name="roleid">角色id</param> /// <param name="navname">菜单名称</param> /// <param name="actiontype">操作类型</param> /// <returns>是否有权限</returns> private bool Exist(int roleid, string navname, string actiontype) { ht_manager_role role = db.ht_manager_role.FirstOrDefault(x => x.id == roleid); if (role == null) { return(false); } if (role.roletype == 1) { return(true); } ht_manager_role_value model = role.ht_manager_role_value.FirstOrDefault(x => x.navname == navname && x.actiontype == actiontype); return(model != null); }
private bool DoEdit(int _id) { try { //先删除该角色所有的权限 List <ht_manager_role_value> rolevalues = db.ht_manager_role_value.Where(x => x.roleid == _id).ToList(); db.ht_manager_role_value.RemoveRange(rolevalues); db.SaveChanges(); //重新设置权限 ht_manager_role model = db.ht_manager_role.FirstOrDefault(x => x.id == _id); model.rolename = txtRoleName.Text.Trim(); model.roletype = int.Parse(ddlRoleType.SelectedValue); //管理权限 List <ht_manager_role_value> ls = new List <ht_manager_role_value>(); for (int i = 0; i < rptList.Items.Count; i++) { string navName = ((HiddenField)rptList.Items[i].FindControl("hidName")).Value; CheckBoxList cblActionType = (CheckBoxList)rptList.Items[i].FindControl("cblActionType"); for (int n = 0; n < cblActionType.Items.Count; n++) { if (cblActionType.Items[n].Selected) { ls.Add(new ht_manager_role_value { ht_manager_role = model, navname = navName, actiontype = cblActionType.Items[n].Value, addtime = DateTime.Now }); } } } model.ht_manager_role_value = ls; db.SaveChanges(); AddAdminLog(HTEnums.ActionEnum.Edit.ToString(), "修改管理角色:" + model.rolename); //记录日志 return(true); } catch (Exception) { return(false); } }
private bool DoAdd() { try { ht_manager_role model = new ht_manager_role { rolename = txtRoleName.Text.Trim(), roletype = int.Parse(ddlRoleType.SelectedValue), addtime = DateTime.Now }; //管理权限 List <ht_manager_role_value> ls = new List <ht_manager_role_value>(); for (int i = 0; i < rptList.Items.Count; i++) { string navName = ((HiddenField)rptList.Items[i].FindControl("hidName")).Value; CheckBoxList cblActionType = (CheckBoxList)rptList.Items[i].FindControl("cblActionType"); for (int n = 0; n < cblActionType.Items.Count; n++) { if (cblActionType.Items[n].Selected) { ls.Add(new ht_manager_role_value { navname = navName, actiontype = cblActionType.Items[n].Value, addtime = DateTime.Now }); } } } model.ht_manager_role_value = ls; db.ht_manager_role.Add(model); db.SaveChanges(); AddAdminLog(HTEnums.ActionEnum.Add.ToString(), "添加管理角色:" + model.rolename); //记录日志 return(true); } catch (Exception) { return(false); } }
/// <summary> /// 获取后台导航字符串 /// </summary> private void get_navigation_list(HttpContext context) { ht_manager manager = new ManageBase().Manager; if (manager == null) { return; } ht_manager_role role = _db.ht_manager_role.FirstOrDefault(x => x.id == manager.roleid); if (role == null) { return; } List <ht_navigation> list = _db.ht_navigation.Where(x => x.id > 0).OrderBy(x => x.sortid).ThenBy(x => x.id).ToList(); List <ht_manager_role_value> values = _db.ht_manager_role_value.Where(x => x.roleid == manager.roleid).ToList(); List <Menu> menus = new List <Menu>(); _nav.GetChilds(list, ref menus, 0, 0); get_navigation_childs(context, menus, 0, Convert.ToInt32(role.roletype), values); }
protected void btnDelete_Click(object sender, EventArgs e) { ChkAdminLevel("manager_role", HTEnums.ActionEnum.Delete.ToString()); //检查权限 int sucCount = 0; for (int i = 0; i < rptList.Items.Count; i++) { int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value); CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId"); if (cb.Checked) { ht_manager_role role = db.ht_manager_role.FirstOrDefault(x => x.id == id); if (role != null) { db.ht_manager_role.Remove(role); db.SaveChanges(); sucCount++; } } } AddAdminLog(HTEnums.ActionEnum.Delete.ToString(), "删除角色" + sucCount + "条,及相关管理员"); //记录日志 JscriptMsg("删除成功" + sucCount + "条,及相关管理员", Utils.CombUrlTxt("role_list.aspx", "keywords={0}", this.keywords)); }
private void ShowInfo(int _id) { ht_manager_role model = db.ht_manager_role.FirstOrDefault(x => x.id == _id); txtRoleName.Text = model.rolename; ddlRoleType.SelectedValue = model.roletype.ToString(); //管理权限 if (model.ht_manager_role_value != null) { for (int i = 0; i < rptList.Items.Count; i++) { string navName = ((HiddenField)rptList.Items[i].FindControl("hidName")).Value; CheckBoxList cblActionType = (CheckBoxList)rptList.Items[i].FindControl("cblActionType"); for (int n = 0; n < cblActionType.Items.Count; n++) { ht_manager_role_value modelt = model.ht_manager_role_value.ToList().Find(x => x.navname == navName && x.actiontype == cblActionType.Items[n].Value.ToString()); if (modelt != null) { cblActionType.Items[n].Selected = true; } } } } }
/// <summary> /// 获取角色名称 /// </summary> /// <param name="roleid">角色id</param> protected string GetRoleName(int roleid) { ht_manager_role role = db.ht_manager_role.FirstOrDefault(x => x.id == roleid); return(role != null ? role.rolename : ""); }