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

📄 employeeofdepartment.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;

namespace PMS.DesktopModules.EmployeeOfDepartment
{
	/// <summary>
	/// EmployeeOfDepartment 的摘要说明。
	/// </summary>
	public partial class EmployeeOfDepartment : System.Web.UI.Page
	{
	
		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)
				{
					///绑定控件DepartmentList,显示部门列表
					BindDepartmentList();		
		
					if(DepartmentList.Items.Count > 0)
					{
						///取DepartmentList第一项部门编号,在EmployeeGrid中显示该部门所有员工的信息
						DepartmentList.SelectedIndex = 0;
						CurrentDepartment.Text = DepartmentList.SelectedItem.Text;
						string DepartID = DepartmentList.Items[0].Value;
						///绑定控件EmployeeGrid
						BindEmployeeGrid(DepartID);		
					}
				}
			}
		}
		private void BindDepartmentList()
		{
			///定义获取数据的类
			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 BindEmployeeGrid(string DepartID)
		{
			///定义获取数据的类
			PMS.Components.Department Department = new PMS.Components.Department();
			DataTable DT = Department.GetEmployee(DepartID);

			///设定控件的数据源
			EmployeeGrid.DataSource = DT;
			///绑定控件的数据
			EmployeeGrid.DataBind();
			if(DT.Rows.Count > 0)
			{
				EmployID.Text = DT.Rows[0][0].ToString();
				BindEmployeeData(EmployID.Text.Trim());		
			}
			else
			{
				SexList.SelectedIndex = 0;
				NationalityList.SelectedIndex = 0;
				PoliticalList.SelectedIndex = 0;
				CultureList.SelectedIndex = 0;
				Maritallist.SelectedIndex = 0;
				StateList.SelectedIndex = 0;
				
				CurrentEmployeeName.Text = EmployName.Text  = "";
				EmployID.Text     = "";
				Birthday.Text     = "";
				FamilyPlace.Text  = "";
				IdentityCard.Text = "";
				Phone.Text        = "";
				Mobile.Text       = "";
				HireDate.Text     = "";
				Position.Text     = "";
				BankName.Text     = "";
				AccountNo.Text    = "";
				PubName.Text      = "";
				PubDate.Text      = "";
				Remark.Text       = "";
			}

		}
		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());
			

			///设置TextBox的相应值
			CurrentEmployeeName.Text = 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();
		}
		

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

		}
		#endregion

		protected void DepartmentList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(DepartmentList.SelectedIndex > -1)
			{
				string DepartID = DepartmentList.SelectedItem.Value;
				CurrentDepartment.Text = DepartmentList.SelectedItem.Text;
				///绑定控件EmployeeGrid
				BindEmployeeGrid(DepartID);
			}
			else
			{
				///显示操作结果信息
				Response.Write ("<script>window.alert('" + "请选择操作的数据子项!!!" + "')</script>");
			}		
		}


        protected void EmployeeGrid_RowEditing(object sender, GridViewEditEventArgs e)
        {
            string EmployeeID = EmployeeGrid.Rows[e.NewEditIndex].Cells[0].Text;
            BindEmployeeData(EmployeeID);
        }
}
}

⌨️ 快捷键说明

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