SysManageRole.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:10k
- using System;
- using System.Data;
- using System.Data.SqlClient;
- 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;
- public partial class SysManage_SysManageRole : System.Web.UI.Page
- {
- RoleManage rm = new RoleManage();
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!this.Page.IsPostBack)
- {
- try
- {
- this.GridView1.PageSize = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["MorePageNum"]);
- }
- catch
- {
- this.GridView1.PageSize = 10;
- }
- BindToGridView();
- }
- }
- protected void BindToGridView()
- {
- this.GridView1.DataSource = rm.GetAllRoles();
- this.GridView1.DataBind();
- }
- //protected void BindToFormViewDDLCreateRole()
- //{
- // ((DropDownList)FormView1.FindControl("DDL_CreateRole")).DataSource = rm.GetAllRoles();
- // ((DropDownList)FormView1.FindControl("DDL_CreateRole")).DataTextField ="RoleName";
- // ((DropDownList)FormView1.FindControl("DDL_CreateRole")).DataValueField ="RoleID";
- // ((DropDownList)FormView1.FindControl("DDL_CreateRole")).DataBind();
- //}
- //protected void BindToFormViewDDLUserRole()
- //{
- // ((DropDownList)FormView1.FindControl("DDL_UserRole")).DataSource = rm.GetAllRoles();
- // ((DropDownList)FormView1.FindControl("DDL_UserRole")).DataTextField = "RoleName";
- // ((DropDownList)FormView1.FindControl("DDL_UserRole")).DataValueField = "RoleID";
- // ((DropDownList)FormView1.FindControl("DDL_UserRole")).DataBind();
- // ((DropDownList)FormView1.FindControl("DDL_UserRole")).Items.Insert(0, new ListItem("未选择", "-1"));
- //}
- protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
- {
- if (this.TB_Condition.Text.ToString().Trim() == "")
- {
- this.GridView1.DataSource = rm.GetAllRoles();
- this.GridView1.DataBind();
- }
- else
- {
- string searchContent = TB_Condition.Text.ToString().Trim();
- int roleType = Convert.ToInt32(DDL_Condition.SelectedValue.ToString());
- this.GridView1.DataSource = rm.GetRoleByConditions(roleType, searchContent, this.CB_Blur.Checked);
- this.GridView1.DataBind();
- }
- }
- protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
- {
- //this.FormView1.ChangeMode(FormViewMode.Edit);
- int roleid = Convert.ToInt32(this.GridView1.DataKeys[e.NewEditIndex].Value.ToString());
- Session["RoleID"] = roleid;
- DataTable dt = rm.GetRoleByID(roleid);
- //this.FormView1.DataSource = dt;
- //this.FormView1.DataBind();
- //BindToFormViewDDLCreateRole();
- //BindToFormViewDDLUserRole();
- //if (dt.Rows.Count > 0)
- //{
- // //((TextBox)FormView1.FindControl("TB_sRole_Name")).Text = dt.Rows[0]["RoleName"].ToString();
- // //((TextBox)FormView1.FindControl("TB_sRole_Desc")).Text = dt.Rows[0]["RoleDesc"].ToString();
- // if (dt.Rows[0]["CreateRole"].ToString() != "")
- // {
- // ((DropDownList)FormView1.FindControl("DDL_CreateRole")).SelectedValue = dt.Rows[0]["CreateRole"].ToString();
- // }
- // if (dt.Rows[0]["UserRole"].ToString() != "")
- // {
- // ((DropDownList)FormView1.FindControl("DDL_UserRole")).SelectedValue = dt.Rows[0]["UserRole"].ToString();
- // }
- //}
- Session["RoleName"] = dt.Rows[0]["RoleName"].ToString();
- //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>");
- 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>");
- }
- //protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
- //{
- // RoleInfo roleInfo = new RoleInfo();
- // roleInfo.RoleID = Convert.ToInt32(this.FormView1.DataKey.Value);
- // roleInfo.RoleName = ((TextBox)FormView1.FindControl("TB_sRole_Name")).Text.ToString();
- // roleInfo.RoleDesc = ((TextBox)FormView1.FindControl("TB_sRole_Desc")).Text.ToString();
- // if (((DropDownList)FormView1.FindControl("DDL_CreateRole")).Items.Count > 0)
- // {
- // roleInfo.CreateRole = Convert.ToInt32(((DropDownList)FormView1.FindControl("DDL_CreateRole")).SelectedValue.ToString());
- // }
- // if (((DropDownList)FormView1.FindControl("DDL_UserRole")).Items.Count > 0)
- // {
- // roleInfo.UserRole = Convert.ToInt32(((DropDownList)FormView1.FindControl("DDL_UserRole")).SelectedValue.ToString());
- // }
- // if (rm.UpdateRole(roleInfo) == true)
- // {
- // this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色记录更新成功!');window.close();document.getElementById(TB_Decs).innerText='';document.getElementById(TB_Account).innerText='';</script>");
- // BindToGridView();
- // ClearAllText();
- // }
- // else
- // {
- // this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色记录更新失败!');window.close();</script>");
- // ClearAllText();
- // }
- // //this.FormView1.ChangeMode(FormViewMode.Insert);
- //}
- //protected void ClearAllText()
- //{
- // ((TextBox)FormView1.FindControl("TB_sRole_Name")).Text = "";
- // ((TextBox)FormView1.FindControl("TB_sRole_Desc")).Text = "";
- //}
- protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
- {
- int RoleID = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
- if (rm.DeleteRole(RoleID) == true)
- {
- 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>");
- }
- BindToGridView();
- //ClearAllText();
- }
- /*protected void btn_authorize_Click(object sender, EventArgs e)
- {
- if (this.FormView1.CurrentMode == FormViewMode.Insert)
- {
- this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:请在角色列表选择角色!');window.close();</script>");
- return;
- }
- if (Session["RoleID"] == null)
- {
- this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色信息丢失,请重新选择角色!');window.close();</script>");
- return;
- }
- int roleid = Convert.ToInt32(Session["RoleID"]);
- int perminssiontype = Convert.ToInt32(this.DDL_PermissionType.SelectedValue.ToString());
- string fromDate = this.TB_FromDate.Text.ToString().Trim();
- string toDate = this.TB_ToDate.Text.ToString().Trim();
- rm.DeletePermissionInPermissionRole(roleid);
- for (int i = 0; i < this.LB_AuthorizedList.Items.Count; i++)
- {
- int permid = Convert.ToInt32(this.LB_AuthorizedList.Items[i].Value.ToString());
- rm.AddPermissionToRole(permid, roleid, perminssiontype, fromDate, toDate);
- }
- this.Page.ClientScript.RegisterStartupScript(this.GetType(), "0", "<script>alert('系统提示:角色成功授权!');window.close();</script>");
- this.TB_FromDate.Text = "";
- this.TB_ToDate.Text = "";
- }*/
- protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
- {
- int currentpageindex;
- currentpageindex = Convert.ToInt32(e.NewPageIndex);
- if (currentpageindex == -2)
- {
- TextBox txtNewPageIndex;
- txtNewPageIndex = GridView1.BottomPagerRow.FindControl("LinkTextBoxNewPage") as TextBox;
- if (txtNewPageIndex != null)
- {
- try
- {
- currentpageindex = Convert.ToInt32(txtNewPageIndex.Text) - 1;
- }
- catch
- {
- currentpageindex = 0;
- }
- }
- }
- currentpageindex = currentpageindex < 0 ? 0 : currentpageindex;
- currentpageindex = currentpageindex >= GridView1.PageCount ? GridView1.PageCount - 1 : currentpageindex;
- GridView1.PageIndex = currentpageindex;
- this.GridView1.DataSource = rm.GetAllRoles();
- GridView1.DataBind();
- }
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- int iRow;
- iRow = e.Row.DataItemIndex;
- iRow = iRow % 2;
- if (iRow > 0)
- e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='#f0f0f0';");
- else
- e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';");
- e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#E8F2FA';");
- }
- }
- }