authorize.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:5k
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using com.etong.DAL;
- using com.etong.Model;
- using com.etong.DBUtility;
- using com.etong.user;
- public partial class SysManage_authorize : System.Web.UI.Page
- {
- RoleManage rm = new RoleManage();
- Notice notice = new Notice();
- protected void Page_Load(object sender, EventArgs e)
- {
- IB_Cancel.Attributes.Add("onclick", "javascript:if(confirm('确定要退出吗?')) {window.close();return;} else {return;}");
- if (Session["RoleID"] == null || Session["RoleName"] == null)
- {
- this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色信息丢失,请重新选择角色!');window.close();</script>");
- return;
- }
- if (!this.Page.IsPostBack)
- {
- BindDDLUserRole();
- BindDDLCreateRole();
- this.CheckBoxList1.DataSource = rm.GetPermissionList();
- this.CheckBoxList1.DataTextField = "DisplayName";
- this.CheckBoxList1.DataValueField = "PermID";
- this.CheckBoxList1.DataBind();
- this.lbl_RoleName.Text = Convert.ToString(Session["RoleName"]);
- int roleid = Convert.ToInt32(Session["RoleID"]);
- DataTable dt = rm.GetRoleByID(roleid);
- if (dt.Rows.Count > 0)
- {
- this.TB_sRole_Name.Text = dt.Rows[0]["RoleName"].ToString();
- this.TB_sRole_Desc.Text = dt.Rows[0]["RoleDesc"].ToString();
- this.DDL_CreateRole.SelectedValue = dt.Rows[0]["CreateRole"].ToString();
- this.DDL_UserRole.SelectedValue = dt.Rows[0]["UserRole"].ToString();
- }
- this.LB_user.DataSource= notice.GetUser(roleid);
- this.LB_user.DataTextField = "EmpName";
- this.LB_user.DataValueField = "UserID";
- this.LB_user.DataBind();
- if (roleid == 2)
- {
- this.LB_user.Items.Insert(0,new ListItem("系统管理员","-1"));
- }
- DataTable dataTable = rm.GetPermissionList(roleid);
- foreach (DataRow row in dataTable.Rows)
- {
- for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
- {
- if (Convert.ToString(row["PermID"]) == this.CheckBoxList1.Items[i].Value.ToString())
- {
- this.CheckBoxList1.Items[i].Selected = true;
- }
- }
- }
- }
- }
- protected void BindDDLCreateRole()
- {
- this.DDL_CreateRole.DataSource = rm.GetAllRoles();
- this.DDL_CreateRole.DataTextField = "RoleName";
- this.DDL_CreateRole.DataValueField = "RoleID";
- this.DDL_CreateRole.DataBind();
- }
- protected void BindDDLUserRole()
- {
- this.DDL_UserRole.DataSource = rm.GetAllRoles();
- this.DDL_UserRole.DataTextField = "RoleName";
- this.DDL_UserRole.DataValueField = "RoleID";
- this.DDL_UserRole.DataBind();
- }
- protected void IB_Confirm_Click(object sender, EventArgs e)
- {
- RoleInfo roleInfo = new RoleInfo();
- roleInfo.RoleName = this.TB_sRole_Name.Text.ToString().Trim();
- roleInfo.RoleDesc = this.TB_sRole_Desc.Text.ToString().Trim();
- roleInfo.CreateRole = Convert.ToInt32(this.DDL_CreateRole.SelectedValue.ToString());
- roleInfo.UserRole = Convert.ToInt32(this.DDL_UserRole.SelectedValue.ToString());
- if (rm.UpdateRole(roleInfo) == true)
- {
- if (rm.UpdateRole(roleInfo) == true)
- {
- int roleid = Convert.ToInt32(Session["RoleID"]);
- rm.DeletePermissionInPermissionRole(roleid);
- string fromDate = "";
- string toDate = "";
- int permissionType = Convert.ToInt32(this.DDL_PermissionType.SelectedValue.ToString());
- int count = this.CheckBoxList1.Items.Count;
- foreach (ListItem list in this.CheckBoxList1.Items)
- {
- if (list.Selected == true)
- {
- rm.AddPermissionToRole(Convert.ToInt32(list.Value), roleid, permissionType, fromDate, toDate);
- }
- }
- this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色成功授权!');window.close();</script>");
- }
- }
- else
- {
- this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:编辑角色失败!');window.close();</script>");
- }
- }
- }