FuncRightSet.aspx.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:7k
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Web;
- using System.Web.SessionState;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- //引用数据库访问层。
- using qminoa.DA;
- using qminoa.Common;
- namespace qminoa.Webs.sysSecurity
- {
- public class FuncRightSet : qminoa.Webs.PageBase
- {
- protected System.Web.UI.WebControls.TextBox txbFuncName;
- protected System.Web.UI.WebControls.TextBox txbFuncDes;
- protected System.Web.UI.WebControls.DropDownList FuncRoleDrop;
- protected System.Web.UI.WebControls.DataList FuncRoleList;
- protected System.Web.UI.WebControls.LinkButton lbnOK;
- protected System.Web.UI.WebControls.LinkButton lbncannel;
- protected System.Web.UI.WebControls.LinkButton lbnFuncUpdate;
- protected System.Web.UI.WebControls.LinkButton AddFunc;
-
- public int FuncID;
- private void Page_Load(object sender, System.EventArgs e)
- {
- this.PageBegin("模块管理",true);
- FuncID=Int32.Parse(Request.QueryString["funcid"]);
- if (Page.IsPostBack == false)
- {
- BindData();
- }
- else
- ReSetCheckListInfo();
- }
- private void BindData()
- {
- AdminDB admin = new AdminDB();
- SqlDataReader dr=admin.GetFuncInfo(FuncID) ;
- dr.Read();
- txbFuncName.Text=dr["FuncName"].ToString();
- txbFuncDes.Text=dr["Description"].ToString();
- FuncRoleList.DataSource=admin.GetFuncRole(FuncID);
- FuncRoleList.DataBind();
- SetCheckListInfo();
- FuncRoleDrop.DataSource=admin.GetAllRoles();
- FuncRoleDrop.DataBind();
- }
-
- public void SetCheckListInfo()
- {
- for (int FuncNum=0; FuncNum<FuncRoleList.Items.Count;FuncNum++)
- {
- int lastindex=Int32.Parse(((System.Web.UI.WebControls.Label)FuncRoleList.Items[FuncNum].FindControl("LastSelectIndex")).Text);
- for(int i=0;i<((CheckBoxList)FuncRoleList.Items[FuncNum].FindControl("checkRightSet")).Items.Count;i++)
- if(i<=lastindex)
- ((CheckBoxList)FuncRoleList.Items[FuncNum].FindControl("checkRightSet")).Items[i].Selected=true;
- else
- ((CheckBoxList)FuncRoleList.Items[FuncNum].FindControl("checkRightSet")).Items[i].Selected=false;
- }
- }
- public void ReSetCheckListInfo()
- {
- for (int FuncNum=0; FuncNum<FuncRoleList.Items.Count;FuncNum++)
- {
- int lastindex=Int32.Parse(((System.Web.UI.WebControls.Label)FuncRoleList.Items[FuncNum].FindControl("LastSelectIndex")).Text);
- int newindex=GetCheckListInfo(FuncNum,lastindex);
- ((System.Web.UI.WebControls.Label)FuncRoleList.Items[FuncNum].FindControl("LastSelectIndex")).Text=newindex.ToString();
- for(int i=0;i<((CheckBoxList)FuncRoleList.Items[FuncNum].FindControl("checkRightSet")).Items.Count;i++)
- if(i<=newindex)
- ((CheckBoxList)FuncRoleList.Items[FuncNum].FindControl("checkRightSet")).Items[i].Selected=true;
- else
- ((CheckBoxList)FuncRoleList.Items[FuncNum].FindControl("checkRightSet")).Items[i].Selected=false;
- }
- }
- public int GetCheckListInfo(int index,int LastSelectIndex)
- {
- int NewSelectIndex=-2;
- for(int ChBox=0;ChBox<((CheckBoxList)FuncRoleList.Items[index].FindControl("checkRightSet")).Items.Count;ChBox++)
- if( ((CheckBoxList)FuncRoleList.Items[index].FindControl("checkRightSet")).Items[ChBox].Selected==true&&ChBox> LastSelectIndex)
- NewSelectIndex=ChBox;
- else if( ((CheckBoxList)FuncRoleList.Items[index].FindControl("checkRightSet")).Items[ChBox].Selected==false&&ChBox<=LastSelectIndex)
- NewSelectIndex=ChBox-1;
- if (NewSelectIndex==-2)
- NewSelectIndex=LastSelectIndex;
- return NewSelectIndex;
- }
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
- InitializeComponent();
- base.OnInit(e);
- }
-
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.lbnFuncUpdate.Click += new System.EventHandler(this.lbnFuncUpdate_Click);
- this.AddFunc.Click += new System.EventHandler(this.AddFunc_Click);
- this.FuncRoleList.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.FuncRoleList_ItemCommand);
- this.lbnOK.Click += new System.EventHandler(this.lbnOK_Click);
- this.lbncannel.Click += new System.EventHandler(this.lbncannel_Click);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- private void FuncRoleList_ItemCommand(object sender, DataListCommandEventArgs e)
- {
- AdminDB admin = new AdminDB();
- int RoleID = (int) FuncRoleList.DataKeys[e.Item.ItemIndex];
- String RoleName=((System.Web.UI.WebControls.Label)e.Item.FindControl("lbRoleName")).Text;
- if (e.CommandName == "edit")
- {
- if(this.CheckAuth("角色管理") >= 3)
- Response.Redirect("RolesFuncUsers.aspx?roleid=" +RoleID,false);
- else
- JScript.Alert("您没有权限进行此操作!");
- }
- else if (e.CommandName == "delete")
- {
- if(this.EmpRightCode == 4)
- {
- if(admin.DeleteFuncRole(FuncID,RoleID))
- {
- this.WriteOptLog("删除模块角色关联信息(模块ID:"+FuncID.ToString()+",角色ID:"+RoleID.ToString()+")");
- JScript.Alert("删除成功!");
- BindData();
- }
- else
- JScript.Alert("删除失败!");
- }
- else
- {
- JScript.Alert("您没有权限进行此操作!");
- }
- }
-
- }
- private void lbnFuncUpdate_Click(object sender, System.EventArgs e)
- {
- if(this.EmpRightCode >= 3)
- {
- AdminDB admin = new AdminDB();
- admin.UpdateFuncInfo(FuncID,txbFuncName.Text,txbFuncDes.Text);
- BindData();
- }
- else
- {
- JScript.Alert("您没有权限进行此操作!");
- }
- }
- private void lbnOK_Click(object sender, System.EventArgs e)
- {
- if(this.EmpRightCode >= 3)
- {
- for(int i=0;i<FuncRoleList.Items.Count;i++)
- {
- AdminDB admin = new AdminDB();
- int roleid=(int)FuncRoleList.DataKeys[i];
- int rightfalg=Int32.Parse(((System.Web.UI.WebControls.Label)FuncRoleList.Items[i].FindControl("LastSelectIndex")).Text);
- admin.UpdateFuncRoleRight(FuncID,roleid,rightfalg);
- }
- Response.Redirect("moduleadmin.aspx",false);
- }
- else
- {
- JScript.Alert("您没有权限进行此操作!");
- }
- }
- private void AddFunc_Click(object sender, System.EventArgs e)
- {
- if(this.EmpRightCode >= 3)
- {
- AdminDB admin = new AdminDB();
- admin.AddFuncRole(FuncID,Int32.Parse(FuncRoleDrop.SelectedItem.Value));
- this.WriteOptLog("添加模块角色关联信息(模块ID:"+FuncID.ToString()+",角色ID:"+FuncRoleDrop.SelectedItem.Value.ToString()+")");
- BindData();
- }
- else
- {
- JScript.Alert("您没有权限进行此操作!");
- }
- }
- private void lbncannel_Click(object sender, System.EventArgs e)
- {
- Response.Redirect("moduleadmin.aspx",false);
- }
-
- }
- }