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

.net编程

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Configuration;
  5. using System.Collections;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. using com.etong.DAL;
  13. using com.etong.Model;
  14. using com.etong.DBUtility;
  15. public partial class SysManage_SysManageRole : System.Web.UI.Page
  16. {
  17.     RoleManage rm = new RoleManage();
  18.     protected void Page_Load(object sender, EventArgs e)
  19.     {
  20.         if (!this.Page.IsPostBack)
  21.         {
  22.             try
  23.             {
  24.                 this.GridView1.PageSize = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["MorePageNum"]);
  25.             }
  26.             catch
  27.             {
  28.                 this.GridView1.PageSize = 10;
  29.             }
  30.             BindToGridView();
  31.         }
  32.     }
  33.     protected void BindToGridView()
  34.     {
  35.         this.GridView1.DataSource = rm.GetAllRoles();
  36.         this.GridView1.DataBind();
  37.     }
  38.     //protected void BindToFormViewDDLCreateRole()
  39.     //{
  40.     //    ((DropDownList)FormView1.FindControl("DDL_CreateRole")).DataSource = rm.GetAllRoles();
  41.     //    ((DropDownList)FormView1.FindControl("DDL_CreateRole")).DataTextField ="RoleName";
  42.     //    ((DropDownList)FormView1.FindControl("DDL_CreateRole")).DataValueField ="RoleID";
  43.     //    ((DropDownList)FormView1.FindControl("DDL_CreateRole")).DataBind();
  44.     //}
  45.     //protected void BindToFormViewDDLUserRole()
  46.     //{
  47.     //    ((DropDownList)FormView1.FindControl("DDL_UserRole")).DataSource = rm.GetAllRoles();
  48.     //    ((DropDownList)FormView1.FindControl("DDL_UserRole")).DataTextField = "RoleName";
  49.     //    ((DropDownList)FormView1.FindControl("DDL_UserRole")).DataValueField = "RoleID";
  50.     //    ((DropDownList)FormView1.FindControl("DDL_UserRole")).DataBind();
  51.     //    ((DropDownList)FormView1.FindControl("DDL_UserRole")).Items.Insert(0, new ListItem("未选择", "-1"));
  52.     //}
  53.     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  54.     {
  55.         if (this.TB_Condition.Text.ToString().Trim() == "")
  56.         {
  57.             this.GridView1.DataSource = rm.GetAllRoles();
  58.             this.GridView1.DataBind();
  59.         }
  60.         else
  61.         {
  62.             string searchContent = TB_Condition.Text.ToString().Trim();
  63.             int roleType = Convert.ToInt32(DDL_Condition.SelectedValue.ToString());
  64.             this.GridView1.DataSource = rm.GetRoleByConditions(roleType, searchContent, this.CB_Blur.Checked);
  65.             this.GridView1.DataBind();
  66.         }
  67.     }
  68.     protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  69.     {
  70.         //this.FormView1.ChangeMode(FormViewMode.Edit);
  71.         int roleid = Convert.ToInt32(this.GridView1.DataKeys[e.NewEditIndex].Value.ToString());
  72.         Session["RoleID"] = roleid;
  73.         DataTable dt = rm.GetRoleByID(roleid);
  74.         //this.FormView1.DataSource = dt;
  75.         //this.FormView1.DataBind();
  76.         //BindToFormViewDDLCreateRole();
  77.         //BindToFormViewDDLUserRole();
  78.         //if (dt.Rows.Count > 0)
  79.         //{
  80.         //   //((TextBox)FormView1.FindControl("TB_sRole_Name")).Text = dt.Rows[0]["RoleName"].ToString();
  81.         //   //((TextBox)FormView1.FindControl("TB_sRole_Desc")).Text = dt.Rows[0]["RoleDesc"].ToString();
  82.         //    if (dt.Rows[0]["CreateRole"].ToString() != "")
  83.         //    {
  84.         //        ((DropDownList)FormView1.FindControl("DDL_CreateRole")).SelectedValue = dt.Rows[0]["CreateRole"].ToString();
  85.         //    }
  86.         //    if (dt.Rows[0]["UserRole"].ToString() != "")
  87.         //    {
  88.         //        ((DropDownList)FormView1.FindControl("DDL_UserRole")).SelectedValue = dt.Rows[0]["UserRole"].ToString();
  89.         //    }
  90.         //}
  91.         Session["RoleName"] = dt.Rows[0]["RoleName"].ToString();
  92.         //this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script> if (document.all&&window.print) window.showModalDialog('authorize.aspx','','help:0;dialogWidth:500px;dialogHeight:450px,location=no, status=no;');</script>");
  93.         this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script> window.open('authorize.aspx','角色授权','height=500,width=550,top=159,left=262,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');</script>");
  94.     }
  95.     //protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
  96.     //{
  97.     //    RoleInfo roleInfo = new RoleInfo();
  98.     //    roleInfo.RoleID = Convert.ToInt32(this.FormView1.DataKey.Value);
  99.     //    roleInfo.RoleName = ((TextBox)FormView1.FindControl("TB_sRole_Name")).Text.ToString();
  100.     //    roleInfo.RoleDesc = ((TextBox)FormView1.FindControl("TB_sRole_Desc")).Text.ToString();
  101.     //    if (((DropDownList)FormView1.FindControl("DDL_CreateRole")).Items.Count > 0)
  102.     //    {
  103.     //        roleInfo.CreateRole = Convert.ToInt32(((DropDownList)FormView1.FindControl("DDL_CreateRole")).SelectedValue.ToString());
  104.     //    }
  105.     //    if (((DropDownList)FormView1.FindControl("DDL_UserRole")).Items.Count > 0)
  106.     //    {
  107.     //        roleInfo.UserRole = Convert.ToInt32(((DropDownList)FormView1.FindControl("DDL_UserRole")).SelectedValue.ToString());
  108.     //    }
  109.     //    if (rm.UpdateRole(roleInfo) == true)
  110.     //    {
  111.     //        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色记录更新成功!');window.close();document.getElementById(TB_Decs).innerText='';document.getElementById(TB_Account).innerText='';</script>");
  112.     //        BindToGridView();
  113.     //        ClearAllText();
  114.     //    }
  115.     //    else
  116.     //    {
  117.     //        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色记录更新失败!');window.close();</script>");
  118.     //        ClearAllText();
  119.     //    }
  120.     //    //this.FormView1.ChangeMode(FormViewMode.Insert);
  121.     //}
  122.     //protected void ClearAllText()
  123.     //{
  124.     //    ((TextBox)FormView1.FindControl("TB_sRole_Name")).Text = "";
  125.     //    ((TextBox)FormView1.FindControl("TB_sRole_Desc")).Text = "";
  126.     //}
  127.     protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
  128.     {
  129.         int RoleID = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
  130.         if (rm.DeleteRole(RoleID) == true)
  131.         {
  132.             this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色记录删除成功!');window.close();</script>");      
  133.         }
  134.         else
  135.         {
  136.             this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色记录删除失败!');window.close();</script>");
  137.         }
  138.         BindToGridView();
  139.         //ClearAllText();
  140.     }
  141.     /*protected void btn_authorize_Click(object sender, EventArgs e)
  142.     {
  143.         if (this.FormView1.CurrentMode == FormViewMode.Insert)
  144.         {
  145.             this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:请在角色列表选择角色!');window.close();</script>");
  146.             return;
  147.         }
  148.         if (Session["RoleID"] == null)
  149.         {
  150.             this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色信息丢失,请重新选择角色!');window.close();</script>");
  151.             return;
  152.         }
  153.         int roleid = Convert.ToInt32(Session["RoleID"]);
  154.         int perminssiontype = Convert.ToInt32(this.DDL_PermissionType.SelectedValue.ToString());
  155.         string fromDate = this.TB_FromDate.Text.ToString().Trim();
  156.         string toDate = this.TB_ToDate.Text.ToString().Trim();
  157.         rm.DeletePermissionInPermissionRole(roleid);
  158.         for (int i = 0; i < this.LB_AuthorizedList.Items.Count; i++)
  159.         {
  160.             int permid = Convert.ToInt32(this.LB_AuthorizedList.Items[i].Value.ToString());
  161.             rm.AddPermissionToRole(permid, roleid, perminssiontype, fromDate, toDate);
  162.         }
  163.         this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色成功授权!');window.close();</script>");
  164.         this.TB_FromDate.Text = "";
  165.         this.TB_ToDate.Text = "";
  166.     }*/
  167.     protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
  168.     {
  169.         int currentpageindex;
  170.         currentpageindex = Convert.ToInt32(e.NewPageIndex);
  171.         if (currentpageindex == -2)
  172.         {
  173.             TextBox txtNewPageIndex;
  174.             txtNewPageIndex = GridView1.BottomPagerRow.FindControl("LinkTextBoxNewPage") as TextBox;
  175.             if (txtNewPageIndex != null)
  176.             {
  177.                 try
  178.                 {
  179.                     currentpageindex = Convert.ToInt32(txtNewPageIndex.Text) - 1;
  180.                 }
  181.                 catch
  182.                 {
  183.                     currentpageindex = 0;
  184.                 }
  185.             }
  186.         }
  187.         currentpageindex = currentpageindex < 0 ? 0 : currentpageindex;
  188.         currentpageindex = currentpageindex >= GridView1.PageCount ? GridView1.PageCount - 1 : currentpageindex;
  189.         GridView1.PageIndex = currentpageindex;
  190.         this.GridView1.DataSource = rm.GetAllRoles();
  191.         GridView1.DataBind();
  192.    }
  193.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  194.     {
  195.         if (e.Row.RowType == DataControlRowType.DataRow)
  196.         {
  197.             int iRow;
  198.             iRow = e.Row.DataItemIndex;
  199.             iRow = iRow % 2;
  200.             if (iRow > 0)
  201.                 e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='#f0f0f0';");
  202.             else
  203.                 e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';");
  204.             e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#E8F2FA';");
  205.         }
  206.     }
  207. }