authorize.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:5k
源码类别:

.net编程

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using com.etong.DAL;
  12. using com.etong.Model;
  13. using com.etong.DBUtility;
  14. using com.etong.user;
  15. public partial class SysManage_authorize : System.Web.UI.Page
  16. {
  17.     RoleManage rm = new RoleManage();
  18.     Notice notice = new Notice();
  19.     protected void Page_Load(object sender, EventArgs e)
  20.     {
  21.         IB_Cancel.Attributes.Add("onclick", "javascript:if(confirm('确定要退出吗?')) {window.close();return;} else {return;}");
  22.         if (Session["RoleID"] == null || Session["RoleName"] == null)
  23.         {
  24.             this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色信息丢失,请重新选择角色!');window.close();</script>");
  25.             return;
  26.         }
  27.         if (!this.Page.IsPostBack)
  28.         {
  29.             BindDDLUserRole();
  30.             BindDDLCreateRole();
  31.             this.CheckBoxList1.DataSource = rm.GetPermissionList();
  32.             this.CheckBoxList1.DataTextField = "DisplayName";
  33.             this.CheckBoxList1.DataValueField = "PermID";
  34.             this.CheckBoxList1.DataBind();
  35.             this.lbl_RoleName.Text = Convert.ToString(Session["RoleName"]);
  36.             int roleid = Convert.ToInt32(Session["RoleID"]);
  37.             DataTable dt = rm.GetRoleByID(roleid);
  38.             if (dt.Rows.Count > 0)
  39.             {
  40.                 this.TB_sRole_Name.Text = dt.Rows[0]["RoleName"].ToString();
  41.                 this.TB_sRole_Desc.Text = dt.Rows[0]["RoleDesc"].ToString();
  42.                 this.DDL_CreateRole.SelectedValue = dt.Rows[0]["CreateRole"].ToString();
  43.                 this.DDL_UserRole.SelectedValue = dt.Rows[0]["UserRole"].ToString();
  44.             }
  45.             this.LB_user.DataSource= notice.GetUser(roleid);
  46.             this.LB_user.DataTextField = "EmpName";
  47.             this.LB_user.DataValueField = "UserID";
  48.             this.LB_user.DataBind();
  49.             if (roleid == 2)
  50.             {
  51.                 this.LB_user.Items.Insert(0,new ListItem("系统管理员","-1"));              
  52.             }
  53.             DataTable dataTable = rm.GetPermissionList(roleid);
  54.             foreach (DataRow row in dataTable.Rows)
  55.             {
  56.                 for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
  57.                 {
  58.                     if (Convert.ToString(row["PermID"]) == this.CheckBoxList1.Items[i].Value.ToString())
  59.                     {
  60.                         this.CheckBoxList1.Items[i].Selected = true;
  61.                     }
  62.                 }
  63.             }
  64.         }
  65.     }
  66.     protected void BindDDLCreateRole()
  67.     {
  68.         this.DDL_CreateRole.DataSource = rm.GetAllRoles();
  69.         this.DDL_CreateRole.DataTextField = "RoleName";
  70.         this.DDL_CreateRole.DataValueField = "RoleID";
  71.         this.DDL_CreateRole.DataBind();
  72.     }
  73.     protected void BindDDLUserRole()
  74.     {
  75.         this.DDL_UserRole.DataSource = rm.GetAllRoles();
  76.         this.DDL_UserRole.DataTextField = "RoleName";
  77.         this.DDL_UserRole.DataValueField = "RoleID";
  78.         this.DDL_UserRole.DataBind();
  79.     }
  80.     protected void IB_Confirm_Click(object sender, EventArgs e)
  81.     {
  82.         RoleInfo roleInfo = new RoleInfo();
  83.         roleInfo.RoleName = this.TB_sRole_Name.Text.ToString().Trim();
  84.         roleInfo.RoleDesc = this.TB_sRole_Desc.Text.ToString().Trim();
  85.         roleInfo.CreateRole = Convert.ToInt32(this.DDL_CreateRole.SelectedValue.ToString());
  86.         roleInfo.UserRole = Convert.ToInt32(this.DDL_UserRole.SelectedValue.ToString());
  87.         if (rm.UpdateRole(roleInfo) == true)
  88.         {
  89.             if (rm.UpdateRole(roleInfo) == true)
  90.             {
  91.                 int roleid = Convert.ToInt32(Session["RoleID"]);
  92.                 rm.DeletePermissionInPermissionRole(roleid);
  93.                 string fromDate = "";
  94.                 string toDate = "";
  95.                 int permissionType = Convert.ToInt32(this.DDL_PermissionType.SelectedValue.ToString());
  96.                 int count = this.CheckBoxList1.Items.Count;
  97.                 foreach (ListItem list in this.CheckBoxList1.Items)
  98.                 {
  99.                     if (list.Selected == true)
  100.                     {
  101.                         rm.AddPermissionToRole(Convert.ToInt32(list.Value), roleid, permissionType, fromDate, toDate);
  102.                     }
  103.                 }
  104.                 this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色成功授权!');window.close();</script>");
  105.             }
  106.         }
  107.         else
  108.         {
  109.             this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:编辑角色失败!');window.close();</script>");
  110.         }
  111.     }
  112. }