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

📄 usersmodule.ascx.cs

📁 asp.net办公自动化实例导航——非常经典的OA源代码
💻 CS
字号:
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Windows.Forms;
//引用数据库访问层。
using qminoa.DA;
using qminoa.Common;

namespace qminoa.Webs.sysSecurity.module
{
	/// <summary>
	///		UsersModule1 的摘要说明。
	///		本页面为一个用户控件,作为SecurityRoles.aspx页面的一部分来显示。
	///		本模块主要用来显示系统管理中的所有用户信息,可以查看用户的详细信息,添加和删除用户信息。
	///		模块主要由一个DataList控件、一个LinkButton和两个DropDownList组成。
	/// </summary>
	public abstract class UsersModule : System.Web.UI.UserControl
	{   
		//定义一个DropDownList控件 UnitDrop用来显示单位信息。
		protected System.Web.UI.WebControls.DropDownList UnitDrop;
		//定义一个DropDownList控件 BranchDrop用来显示部门信息。
		protected System.Web.UI.WebControls.DropDownList BranchDrop;
		//定义一个DataList控件 UserList用来显示用户信息,包括查看和删除按钮。
		protected System.Web.UI.WebControls.DataList UserList;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if (Page.IsPostBack == false) 
			{   //当第一次调用页面时绑定数据库数据。
				BindData();
			}
		}

		//从数据库中取得所有的模块信息数据,并显示在页面上。
		private void BindData() 
		{   
			//引用数据库访问层中的系统管理类。
			AdminDB admin = new AdminDB();
			//用数据库信息填充UnitDrop单位信息。
            UnitDrop.DataSource=admin.GetAllBranch();
			UnitDrop.DataBind();
			//设置UnitDrop的默认选项为第一项。
			UnitDrop.SelectedIndex=0;
			//根据单位信息用数据库信息填充BranchDrop部门信息。
			BranchDrop.DataSource=admin.GetDepByBranch(Int32.Parse(UnitDrop.SelectedItem.Value));
            BranchDrop.DataBind();
			BranchDrop.SelectedIndex=0;
			//根据单位信息用数据库信息填充UserList用户信息。
			UserList.DataSource=admin.GetEmpInfo(Int32.Parse(BranchDrop.SelectedItem.Value),"dep");
			UserList.DataBind(); 
		}
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		///		设计器支持所需的方法 - 不要使用
		///		代码编辑器修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.UnitDrop.SelectedIndexChanged += new System.EventHandler(this.UnitDrop_SelectedIndexChanged);
			this.BranchDrop.SelectedIndexChanged += new System.EventHandler(this.BranchDrop_SelectedIndexChanged);
			this.UserList.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.UserList_ItemCommand);
			this.UserList.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.OnAttachScript);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void OnAttachScript (object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
		{
			if (e.Item.ItemType == ListItemType.Item ||
				e.Item.ItemType == ListItemType.AlternatingItem) 
			{
				ImageButton button = (ImageButton) e.Item.FindControl("Imagebutton4");
				button.Attributes.Add ("onclick",
					"return confirm (\"确定要删除此项记录吗?\");");
			}
		}

		//单位信息列表选择项改变事件函数。
		private void UnitDrop_SelectedIndexChanged(object sender, System.EventArgs e)
		{     //引用数据库访问层中的系统管理类。
			  AdminDB admin = new AdminDB();
              //根据单位信息用数据库信息填充BranchDrop部门信息。
			  BranchDrop.DataSource=admin.GetDepByBranch(Int32.Parse(UnitDrop.SelectedItem.Value));
			  BranchDrop.DataBind();
			  //根据单位信息用数据库信息填充UserList用户信息。
			  UserList.DataSource=admin.GetEmpInfo(Int32.Parse(BranchDrop.SelectedItem.Value),"dep");
		      UserList.DataBind();   
		}

		//部门信息列表选择项改变事件函数。
		private void BranchDrop_SelectedIndexChanged(object sender, System.EventArgs e)
		{    //引用数据库访问层中的系统管理类。
			AdminDB admin = new AdminDB();	
			//根据部门信息用数据库信息填充UserList用户信息。
			UserList.DataSource=admin.GetEmpInfo(Int32.Parse(BranchDrop.SelectedItem.Value),"dep");
			UserList.DataBind();   
		}

         //UserList中的ItemCommand事件函数,用来完成各元素中的按钮事件。
		private void UserList_ItemCommand(object sender, DataListCommandEventArgs e) 
		{
             //引用数据库访问层中的系统管理类。
			AdminDB admin = new AdminDB();
			//取得单击按钮在UserList控件中的主键值,取得用户号。
			int UserID = (int) UserList.DataKeys[e.Item.ItemIndex];
             //判断事件的命令类型。
			if (e.CommandName == "edit") 
			{    
				//转到查看用户详细信息页面。
				Response.Redirect("UserRoles.aspx?userid=" + UserID,false);
		
			}
			
			else if (e.CommandName == "delete") 
			{	
				if(admin.DeleteFuncRoleUser(UserID,"emp"))
				{
					JScript.Alert("删除成功!");
					BindData();
				}
				else
					JScript.Alert("删除失败!");
			}
			
		}

		//添加用户信息按钮事件函数。
		private void AddUserBtn_Click(object sender, System.EventArgs e)
		{      //转到添加用户信息页面。
		      Response.Redirect("UserRoles.aspx",false);
		}
	}
}

⌨️ 快捷键说明

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