⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rolesfuncusers.aspx.cs

📁 asp.net办公自动化实例导航——非常经典的OA源代码
💻 CS
字号:
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 System.Windows.Forms;

//引用数据库访问层。
using qminoa.DA;
using qminoa.Common;

namespace qminoa.Webs.sysSecurity
{
	public class RolesFuncUsers  : qminoa.Webs.PageBase
	{
		protected System.Web.UI.WebControls.TextBox txbRoleName;
		protected System.Web.UI.WebControls.DropDownList RoleFuncDrop;
		protected System.Web.UI.WebControls.DataList RoleFuncList;
		protected System.Web.UI.WebControls.DropDownList RoleUnitDrop;
		protected System.Web.UI.WebControls.DropDownList RoleBranchDrop;
		protected System.Web.UI.WebControls.ListBox RoleUserListbox;
		protected System.Web.UI.WebControls.DataList RoleUserList;
		protected System.Web.UI.WebControls.LinkButton AddRoleBtn;
		protected System.Web.UI.WebControls.LinkButton AddAllRoleBtn;
		protected System.Web.UI.WebControls.LinkButton UpdateRole;
		protected System.Web.UI.WebControls.LinkButton AddFunc;
		protected System.Web.UI.WebControls.LinkButton FuncRightOK;
		protected System.Web.UI.WebControls.LinkButton LinkOK;
		protected System.Web.UI.WebControls.LinkButton linkCanncel;

        public int RoleID;
		protected System.Web.UI.WebControls.TextBox txbRoleDes;
	    
		private void Page_Load(object sender, System.EventArgs e)
		{
			this.PageBegin("模块管理",true);
			RoleID=Int32.Parse(Request.QueryString["roleid"]);
			if (Page.IsPostBack == false) 
			{  
				AdminDB admin = new AdminDB();
				SqlDataReader dr=admin.GetRoleInfo(RoleID) ;
				dr.Read();
				txbRoleName.Text=dr["RoleName"].ToString();
				txbRoleDes.Text=dr["Description"].ToString();
				BindFuncData();
				BindUserData();
			}
			else 
				ReSetCheckListInfo();
		}

		private void BindFuncData() 
		{
			AdminDB admin = new AdminDB();
		    RoleFuncList.DataSource=admin.GetRoleFunc(RoleID);	
			RoleFuncList.DataBind();
			SetCheckListInfo();
			RoleFuncDrop.DataSource=admin.GetAllFuncs();
			RoleFuncDrop.DataBind(); 
			
		}

		private void BindUserData() 
		{
			AdminDB admin = new AdminDB();
			RoleUnitDrop.DataSource=admin.GetAllBranch();
			RoleUnitDrop.DataBind();
			RoleUnitDrop.SelectedIndex=0;
			RoleBranchDrop.DataSource=admin.GetDepByBranch(Int32.Parse(RoleUnitDrop.SelectedItem.Value));
			RoleBranchDrop.DataBind();
			RoleBranchDrop.SelectedIndex=0;
			RoleUserListbox.DataSource=admin.GetEmpInfo(Int32.Parse(RoleBranchDrop.SelectedItem.Value),"dep");
			RoleUserListbox.DataBind(); 
			RoleUserList.DataSource=admin.GetRoleUser(RoleID);	
			RoleUserList.DataBind();
		}

		public void SetCheckListInfo()
		{		
			for (int FuncNum=0; FuncNum<RoleFuncList.Items.Count;FuncNum++)
			{
				int lastindex=Int32.Parse(((System.Web.UI.WebControls.Label)RoleFuncList.Items[FuncNum].FindControl("LastSelectIndex")).Text);
				for(int i=0;i<((CheckBoxList)RoleFuncList.Items[FuncNum].FindControl("FcheckRightSet")).Items.Count;i++)
					if(i<=lastindex)
						((CheckBoxList)RoleFuncList.Items[FuncNum].FindControl("FcheckRightSet")).Items[i].Selected=true;
					else    
						((CheckBoxList)RoleFuncList.Items[FuncNum].FindControl("FcheckRightSet")).Items[i].Selected=false;
			}
		}
		
		public void ReSetCheckListInfo()
		{		
			for (int FuncNum=0; FuncNum<RoleFuncList.Items.Count;FuncNum++)
			{
				int lastindex=Int32.Parse(((System.Web.UI.WebControls.Label)RoleFuncList.Items[FuncNum].FindControl("LastSelectIndex")).Text);
				int newindex=GetCheckListInfo(FuncNum,lastindex);
				((System.Web.UI.WebControls.Label)RoleFuncList.Items[FuncNum].FindControl("LastSelectIndex")).Text=newindex.ToString();
				for(int i=0;i<((CheckBoxList)RoleFuncList.Items[FuncNum].FindControl("FcheckRightSet")).Items.Count;i++)
					if(i<=newindex)
						((CheckBoxList)RoleFuncList.Items[FuncNum].FindControl("FcheckRightSet")).Items[i].Selected=true;
					else    
						((CheckBoxList)RoleFuncList.Items[FuncNum].FindControl("FcheckRightSet")).Items[i].Selected=false;
			}
		}

		public int GetCheckListInfo(int index,int LastSelectIndex)
		{   
			int NewSelectIndex=-2;  
			for(int ChBox=0;ChBox<((CheckBoxList)RoleFuncList.Items[index].FindControl("FcheckRightSet")).Items.Count;ChBox++)
				if( ((CheckBoxList)RoleFuncList.Items[index].FindControl("FcheckRightSet")).Items[ChBox].Selected==true&&ChBox> LastSelectIndex)
					NewSelectIndex=ChBox;
				else if( ((CheckBoxList)RoleFuncList.Items[index].FindControl("FcheckRightSet")).Items[ChBox].Selected==false&&ChBox<=LastSelectIndex)
					NewSelectIndex=ChBox-1; 
			if (NewSelectIndex==-2)
				NewSelectIndex=LastSelectIndex;
			return   NewSelectIndex;
		}

        public void SaveTheRoleFuncRightInfo()
        {
	        for(int i=0;i<RoleFuncList.Items.Count;i++)
 	          {
		        AdminDB admin = new AdminDB();
		        int funcid=(int)RoleFuncList.DataKeys[i];
		        int lastindex=Int32.Parse(((System.Web.UI.WebControls.Label)RoleFuncList.Items[i].FindControl("LastSelectIndex")).Text);
		        admin.UpdateFuncRoleRight(funcid,RoleID,lastindex);	
	          }	
	   }
		#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.UpdateRole.Click += new System.EventHandler(this.UpdateRole_Click);
			this.AddFunc.Click += new System.EventHandler(this.AddFunc_Click);
			this.RoleFuncList.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.RoleFuncList_ItemCommand);
			this.FuncRightOK.Click += new System.EventHandler(this.FuncRightOK_Click);
			this.RoleUnitDrop.SelectedIndexChanged += new System.EventHandler(this.RoleUnitDrop_SelectedIndexChanged);
			this.RoleBranchDrop.SelectedIndexChanged += new System.EventHandler(this.RoleBranchDrop_SelectedIndexChanged);
			this.AddRoleBtn.Click += new System.EventHandler(this.AddRoleBtn_Click);
			this.AddAllRoleBtn.Click += new System.EventHandler(this.AddAllRoleBtn_Click);
			this.RoleUserList.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.RoleUserList_ItemCommand);
			this.LinkOK.Click += new System.EventHandler(this.LinkOK_Click);
			this.linkCanncel.Click += new System.EventHandler(this.linkCanncel_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void AddFunc_Click(object sender, System.EventArgs e)
		{	
			if(this.CheckAuth("用户管理") >= 3)
			{
				AdminDB admin = new AdminDB();
				admin.AddFuncRole(Int32.Parse(RoleFuncDrop.SelectedItem.Value),RoleID);
				BindFuncData();
			}
			else
			{
				JScript.Alert("您没有权限进行此操作!");
			}
		}

		private void AddRoleBtn_Click(object sender, System.EventArgs e)
		{   
			if(this.CheckAuth("用户管理") >= 3)
			{
				if(RoleUserListbox.SelectedIndex<0)				
					JScript.Alert("请选择一个用户!");
				else 
				{
					AdminDB admin = new AdminDB();
					admin.AddUserRole(Int32.Parse(RoleUserListbox.SelectedItem.Value),RoleID);
					BindUserData();
				}
			}
			else
			{
				JScript.Alert("您没有权限进行此操作!");
			}
		}

		private void AddAllRoleBtn_Click(object sender, System.EventArgs e)
		{
			if(this.CheckAuth("用户管理") >= 3)
			{
				for(int i=0;i<RoleUserListbox.Items.Count;i++)
				{  
					AdminDB admin = new AdminDB();
					admin.AddUserRole(Int32.Parse(RoleUserListbox.Items[i].Value),RoleID);
				}
				BindUserData();
			}
			else
			{
				JScript.Alert("您没有权限进行此操作!");
			}
		}

		private void RoleUnitDrop_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			AdminDB admin = new AdminDB();
			RoleBranchDrop.DataSource=admin.GetDepByBranch(Int32.Parse(RoleUnitDrop.SelectedItem.Value));
			RoleBranchDrop.DataBind();
			RoleUserListbox.DataSource=admin.GetEmpInfo(Int32.Parse(RoleBranchDrop.SelectedItem.Value),"dep");
			RoleUserListbox.DataBind();   
		}
		
		private void RoleBranchDrop_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			AdminDB admin = new AdminDB();	
			RoleUserListbox.DataSource=admin.GetEmpInfo(Int32.Parse(RoleBranchDrop.SelectedItem.Value),"dep");
			RoleUserListbox.DataBind();   
		}

		private void RoleUserList_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
		{
			AdminDB admin = new AdminDB();
			int UserID = (int) RoleUserList.DataKeys[e.Item.ItemIndex];
			if (e.CommandName == "edit") 
			{
				if(this.CheckAuth("用户管理") >= 3)
				{
					Response.Redirect("UserRoles.aspx?userid=" +UserID,false);
				}
				else
				{
					JScript.Alert("您没有权限进行此操作!");
				}
		
			}		
			else if (e.CommandName == "delete") 
			{   
				if(this.EmpRightCode == 4)
				{
					if(admin.DeleteRoleUser(UserID,RoleID))
					{
						JScript.Alert("删除成功!");
						BindUserData();
					}
					else
						JScript.Alert("删除失败!");
				}
				else
					JScript.Alert("您没有权限进行此操作!");
			} 
		}

		private void RoleFuncList_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
		{
			AdminDB admin = new AdminDB();
			int FuncID = (int) RoleFuncList.DataKeys[e.Item.ItemIndex];
			if (e.CommandName == "edit") 
			{
				if(this.CheckAuth("模块管理") >= 3)
				Response.Redirect("FuncRightSet.aspx?funcid=" +FuncID,false);
				else
					JScript.Alert("您没有权限进行此操作!");
			}
			
			else if (e.CommandName == "delete") 
			{  
				if(this.EmpRightCode == 4)
				{
					if(admin.DeleteFuncRole(FuncID,RoleID))
					{
						JScript.Alert("删除成功!");
						BindFuncData();
					}
					else
						JScript.Alert("删除失败!");
				}
			}
		}

		private void FuncRightOK_Click(object sender, System.EventArgs e)
		{
			if(this.EmpRightCode >= 3)
				SaveTheRoleFuncRightInfo();
			else
				JScript.Alert("您没有权限进行此操作!");
		}

		private void LinkOK_Click(object sender, System.EventArgs e)
		{
			if(this.EmpRightCode >= 3)
			{
				SaveTheRoleFuncRightInfo();
				Response.Redirect("roleadmin.aspx",false);
			}
			else
			{
				JScript.Alert("您没有权限进行此操作!");
			}
		}

		private void UpdateRole_Click(object sender, System.EventArgs e)
		{
			if(this.EmpRightCode >= 3)
			{
				AdminDB admin = new AdminDB();
				if(admin.UpdateRoleInfo(RoleID,txbRoleName.Text,txbRoleDes.Text))
				{
					JScript.Alert("保存角角信息成功!");
				}
				else
				{
					JScript.Alert("保存角角信息失败!");
				}
			}
			else
			{
				JScript.Alert("您没有权限进行此操作!");
			}
		}

		private void linkCanncel_Click(object sender, System.EventArgs e)
		{
		      Response.Redirect("roleadmin.aspx",false);
		}

			
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -