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

📄 employeemng.aspx.cs

📁 人事管理系统源码 主要功能有: 员工管理:员工信息管理 员工调动管理 部门管理:部门信息管理 部门人员管理 用户管理:用户管理 修改密码
💻 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;
//该源码下载自www.51aspx.com(51aspx.com)


namespace PMS.DesktopModules.EmployeeInfo
{
	/// <summary>
	/// EmployeeMng 的摘要说明。
	/// </summary>
	public partial class EmployeeMng : System.Web.UI.Page
	{
        //51aspx.com


	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			///判断用户是否登陆
			if(Session["UserID"] == null)
			{
				Response.Redirect("~/Default.aspx");
			}
			///判断用户是否是超级管理员或普通管理员
			if(Components.User.IsAuthority(Session["UserID"].ToString()) != Components.User.USERTYPESUPERADMIN && Components.User.IsAuthority(Session["UserID"].ToString()) != Components.User.USERTYPEADMIN)
			{
				Response.Write("<script>alert(\"你没有权限,请与管理员联系!\")</script>");
				Response.Write("<script>history.back();</script>");
			}
			else
			{
				if(!Page.IsPostBack)
				{
					///绑定控件的数据
					BindEmployeeList();		
		
					if(EmployeeList.Items.Count > 0)
					{
						///显示第一项的信息
						BindEmployeeData(EmployeeList.Items[0].Value);
						CurrentEmployeeName.Text = EmployeeList.Items[0].Text;
						EmployeeList.SelectedIndex = 0;
					}
					
				}
		
				///设置按钮的可用性
				UpdateBtn.Enabled = DeleteBtn.Enabled = (EmployeeList.Items.Count <= 0) ? false : true;
	
				///添加删除确认对话框
				DeleteBtn.Attributes.Add("onclick","return confirm('" + "你确定要删除所选择的数据子项吗?" + "');");
			}
		}

		private void BindEmployeeList()
		{
			///定义获取数据的类
			PMS.Components.Employee employee = new PMS.Components.Employee();
			DataTable DT = employee.GetEmployee();

			///设定控件的数据源
			EmployeeList.DataSource = DT;
			
			///设定控件的Text属性和Value属性
			EmployeeList.DataTextField = "EmployeeName";
			EmployeeList.DataValueField = "EmployeeID";

			///绑定控件的数据
			EmployeeList.DataBind();

		}

		private void BindDepartList()
		{
			///定义获取数据的类
			PMS.Components.Department depart = new PMS.Components.Department();
			DataTable DT = depart.GetDepartment();

			///设定控件的数据源
			DepartmentList.DataSource = DT;
			
			///设定控件的Text属性和Value属性
			DepartmentList.DataTextField = "DepartName";
			DepartmentList.DataValueField = "DepartID";

			///绑定控件的数据
			DepartmentList.DataBind();

		}

		private void BindEmployeeData(string EmployeeID)
		{
			///绑定所属部门的信息
			BindDepartList();

			///定义获取数据的类
			PMS.Components.Employee employ = new PMS.Components.Employee();
			DataTable DT = employ.GetEmployee(EmployeeID);

			///设置列表控件的选择值
			PMS.Common.Common.SetListBoxItem(SexList,DT.Rows[0]["Sex"].ToString());
			PMS.Common.Common.SetListBoxItem(NationalityList,DT.Rows[0]["Nationality"].ToString());
			PMS.Common.Common.SetListBoxItem(PoliticalList,DT.Rows[0]["Political"].ToString());
			PMS.Common.Common.SetListBoxItem(CultureList,DT.Rows[0]["Culture"].ToString());
			PMS.Common.Common.SetListBoxItem(Maritallist,DT.Rows[0]["Marital"].ToString());
			PMS.Common.Common.SetListBoxItem(StateList,DT.Rows[0]["State"].ToString());
			PMS.Common.Common.SetListBoxItem(DepartmentList,DT.Rows[0]["DepartID"].ToString());

			///设置TextBox的相应值
			EmployName.Text   = DT.Rows[0]["EmployeeName"].ToString();
			EmployID.Text     = DT.Rows[0]["EmployeeID"].ToString();
			Birthday.Text     = (Convert.ToDateTime(DT.Rows[0]["Birthday"].ToString())).ToShortDateString();
			FamilyPlace.Text  = DT.Rows[0]["FamilyPlace"].ToString();
			IdentityCard.Text = DT.Rows[0]["IdentityCard"].ToString();
			Phone.Text        = DT.Rows[0]["Phone"].ToString();
			Mobile.Text       = DT.Rows[0]["Mobile"].ToString();
			HireDate.Text     = (Convert.ToDateTime(DT.Rows[0]["HireDate"].ToString())).ToShortDateString();
			Position.Text     = DT.Rows[0]["Position"].ToString();
			BankName.Text     = DT.Rows[0]["BankName"].ToString();
			AccountNo.Text    = DT.Rows[0]["AccountNo"].ToString();
			PubName.Text      = DT.Rows[0]["PubName"].ToString();
			PubDate.Text      = DT.Rows[0]["PubDate"].ToString();
			Remark.Text       = DT.Rows[0]["Remark"].ToString();
		}

		

		protected void EmployeeList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(EmployeeList.SelectedIndex > -1)
			{
				///显示员工的信息
				BindEmployeeData(EmployeeList.SelectedValue);
				CurrentEmployeeName.Text = EmployeeList.SelectedItem.Text;

				///设置按钮的可用性
				UpdateBtn.Enabled = DeleteBtn.Enabled = true;
			}
			else
			{
				///显示操作结果信息
				Response.Write ("<script>window.alert('" + "请选择操作的数据子项!!!" + "')</script>");
			}		
		}
		

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void AddBtn_Click(object sender, System.EventArgs e)
		{
			///跳转到添加页面
			Response.Redirect("AddEmployee.aspx");
		}

		protected void DeleteBtn_Click(object sender, System.EventArgs e)
		{
			if(EmployeeList.SelectedIndex > -1)
			{
				///定义类
				PMS.Components.Employee employ = new PMS.Components.Employee();
				
				try
				{   
					///删除操作
					if(employ.DeleteEmployee(EmployeeList.SelectedValue))
					{
						///重新显示员工的信息
						BindEmployeeList();
						if(EmployeeList.Items.Count > 0)
						{						
							BindEmployeeData(EmployeeList.Items[0].Value);
							EmployeeList.SelectedIndex = 0;
							CurrentEmployeeName.Text = EmployeeList.SelectedItem.Text;

						}
					
						///显示操作结果信息
						Response.Write ("<script>window.alert('" + "删除数据子项成功!!!" + "')</script>");
					
					}
					
				}
				catch(Exception ex)
				{			
					///显示添加操作中的失败、错误信息
					PMS.Common.SystemError.SystemLog(ex.Message) ;
				    Response.Redirect(ex.Message) ;
				}
			}
			else
			{
				///显示操作结果信息
				Response.Write ("<script>window.alert('" + "请选择操作的数据子项!!!" + "')</script>");
			}		
		}

		protected void UpdateBtn_Click(object sender, System.EventArgs e)
		{
			if(Page.IsValid == true)
			{
				if(EmployeeList.SelectedIndex > -1)
				{
					///定义类
					PMS.Components.Employee employ = new PMS.Components.Employee();
				
					try
					{  
						
						string CurrentEmployeeID = EmployeeList.SelectedValue;
						int CurrentIndex      = EmployeeList.SelectedIndex;
						string str = "update [Employee] set EmployeeName='"+EmployName.Text.ToString()+"',Sex=" + Int32.Parse(SexList.SelectedValue)+ ",Nationality = " 
					+ Int32.Parse(NationalityList.SelectedValue)+",Birthday='" + Convert.ToDateTime(Birthday.Text.Trim()) + "',Political=" + Int32.Parse(PoliticalList.SelectedValue)
					+ ",Culture=" + Int32.Parse(CultureList.SelectedValue) + ",Marital=" + Int32.Parse(Maritallist.SelectedValue)+",FamilyPlace='" + FamilyPlace.Text.Trim()
					+ "',IdentityCard='"+ IdentityCard.Text.Trim() + "',Phone='" + Phone.Text.Trim() + "',Mobile='" + Mobile.Text.Trim() + "',HireDate='" + Convert.ToDateTime(HireDate.Text.Trim()) 
					+ "',Position='"+ Position.Text.Trim() + "',StateList=" + Int32.Parse(StateList.SelectedValue) +",BankName='" + BankName.Text.Trim() + "',AccountNo='" + AccountNo.Text.Trim() 
					+ "',PubName='"+ PubName.Text.Trim() + "',PubDate='" + Convert.ToDateTime(PubDate.Text.Trim()) + "',DepartID='" + DepartmentList.SelectedValue + "',Remark='" + Remark.Text.Trim()
					+"' where  EmployeeID='" +CurrentEmployeeID+"'";
						if(employ.UpdateEmployee(str))
						{
							///重新显示员工的信息
							BindEmployeeList();
							BindEmployeeData(CurrentEmployeeID);
							EmployeeList.SelectedIndex = CurrentIndex;
							CurrentEmployeeName.Text = EmployeeList.SelectedItem.Text;
					
							///显示操作结果信息
							Response.Write ("<script>window.alert('" + "修改数据子项成功!!!" + "')</script>");
						}
						
					}
					catch(Exception ex)
					{			
						///显示添加操作中的失败、错误信息
						PMS.Common.SystemError.SystemLog(ex.Message) ;
						Response.Redirect(ex.Message) ;

					}
				}
				else
				{
					///显示操作结果信息
					Response.Write ("<script>window.alert('" + "请选择操作的数据子项!!!" + "')</script>");
				}	
			}
		}

		
	
	}
}

⌨️ 快捷键说明

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