/// <summary> /// 修改角色的操作事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpt_Click(object sender, EventArgs e) { Application.Lock(); if (ViewState["roleid"] == null) { Response.Redirect("DeptRolesManage.aspx"); } if (txtRoleName.Text.Trim() == "") { ScriptHelper.SetAlert((Control)sender, GetTran("001183", "请输入角色名称!")); return; } else { if (this.txtRoleName.Text.Trim().Length < 3) { ScriptHelper.SetAlert((Control)sender, GetTran("000999", "角色名称必须3个字符以上!")); return; } } if (txtRoleName.Text != ViewState["Name"].ToString()) { if (DeptRoleBLL.CheckDeptRoleName(this.txtRoleName.Text.Trim(), (int)ViewState["roleid"]) != null) { ScriptHelper.SetAlert((Control)sender, GetTran("001001", "角色名称已经存在!")); return; } } int roleId = (int)ViewState["roleid"]; string number = Session["Company"].ToString(); string manageId = BLL.CommonClass.CommonDataBLL.getManageID(1); if (number != manageId) { if (!DeptRoleBLL.CheckAllot(number, roleId)) { ScriptHelper.SetAlert((Control)sender, GetTran("000975", "不能对该角色进行操作,没有权限!")); return; } } DeptRoleModel deptRole = new DeptRoleModel(roleId); deptRole.DeptID = int.Parse(this.ddlDepts.SelectedValue); string ids = Request.Form["qxCheckBox"]; //获取所有选中的菜单的值(pmID),在生成的页面可以查看(后台拼接而成),qxCheckBox是菜单的name(checkbox的name) string[] id = ids.Split(','); Hashtable htb = (Hashtable)Session["permission"]; htb = DeptRoleBLL.GetAllPermission(Session["Company"].ToString()); Hashtable htb2 = new Hashtable(); int i = -1; if (number != manageId) { foreach (string n in id) { if (htb.Contains(int.Parse(n))) { htb2.Add(n, "0"); } else { i = 0; } } } else { foreach (string n in id) { if (htb.Contains(int.Parse(n))) { htb2.Add(n, "0"); } } } if (i == -1) { BLL.CommonClass.ChangeLogs cl = new BLL.CommonClass.ChangeLogs("deptRole", "id"); cl.AddRecord(roleId); deptRole.htbPerssion = htb2; deptRole.Name = this.txtRoleName.Text.Trim(); deptRole.Allot = ((CheckBox)this.UCPermission1.FindControl("chkAllot")).Checked ? 1 : 0; if (DeptRoleBLL.UptDeptRole(deptRole)) //修改角色 { cl.AddRecord(roleId); cl.ModifiedIntoLogs(BLL.CommonClass.ChangeCategory.company25, "角色:" + deptRole.Name, BLL.CommonClass.ENUM_USERTYPE.objecttype7); ScriptHelper.SetAlert((Control)sender, GetTran("000001", "修改成功."), "DeptRolesManage.aspx"); } else { ScriptHelper.SetAlert((Control)sender, GetTran("000002", "修改失败."), "DeptRolesManage.aspx"); } } else { ScriptHelper.SetAlert((Control)sender, GetTran("001003", "异常数据"), "DeptRolesManage.aspx"); return; } Application.UnLock(); }
/// <summary> /// 添加角色的事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAdd_Click(object sender, EventArgs e) { string number = Session["Company"].ToString(); string manageId = BLL.CommonClass.CommonDataBLL.getManageID(1); if (number != manageId) { if (!DeptRoleBLL.CheckAllot(number)) { ScriptHelper.SetAlert((Control)sender, GetTran("000997", "当前登录用户没有给下级分配权限的权限!")); return; } } if (txtRoleName.Text.Trim() == "") { ScriptHelper.SetAlert((Control)sender, GetTran("000998", "请输入角色名称!")); return; } else { if (this.txtRoleName.Text.Trim().Length < 3) { ScriptHelper.SetAlert((Control)sender, GetTran("000999", "角色名称必须3个字符以上!")); return; } } if (DeptRoleBLL.CheckDeptRoleName(this.txtRoleName.Text, 0) != null) { ScriptHelper.SetAlert((Control)sender, GetTran("001001", "角色名称已经存在!")); return; } string ids = Request.Form["qxCheckBox"]; if (ids == null || ids == "") { ScriptHelper.SetAlert((Control)sender, GetTran("001002", "请选择要分配权限!")); return; } DeptRoleModel deptRole = new DeptRoleModel(); string[] id = ids.Split(','); Hashtable htb = (Hashtable)Session["permission"]; htb = DeptRoleBLL.GetAllPermission(Session["Company"].ToString()); Hashtable htb2 = new Hashtable(); int i = -1; foreach (string n in id) { if (htb.Contains(int.Parse(n))) { htb2.Add(n, "0"); } else { i = 0; break; } } manageId = BLL.CommonClass.CommonDataBLL.getManageID(1); if (number == manageId) { i = -1; } if (i == -1) { deptRole.htbPerssion = htb2; deptRole.Name = this.txtRoleName.Text.Trim(); ManageModel ma = ManagerBLL.GetManage(Session["Company"].ToString()); deptRole.PermissionManID = ma.ID; deptRole.DeptID = int.Parse(this.ddlDepts.SelectedValue); deptRole.Adddate = DateTime.Now; deptRole.ParentId = ma.RoleID; deptRole.Allot = ((CheckBox)this.UCPermission1.FindControl("chkAllot")).Checked?1:0; if (DeptRoleBLL.AddDeptRole(deptRole)) //添加角色 { ScriptHelper.SetAlert((Control)sender, GetTran("000006", "添加成功."), "DeptRolesManage.aspx"); } else { ScriptHelper.SetAlert((Control)sender, GetTran("000007", "添加失败."), "DeptRolesManage.aspx"); } } else { ScriptHelper.SetAlert((Control)sender, GetTran("001003", "异常数据"), "DeptRolesManage.aspx"); return; } }