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

📄 frmemployees.cs

📁 北大青鸟内部资料
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;

namespace frmEmp
{
	
	public class frmEmployees : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox txtFullName;
		private System.Windows.Forms.TextBox txtDepartment;
		private System.Windows.Forms.TextBox txtSalary;
		private System.Windows.Forms.Button btnAdd;
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.Label lblFullName;
		private System.Windows.Forms.Label lblDepartment;
		private System.Windows.Forms.Label lblSalary;
		private System.Windows.Forms.Label lblEmployeeID;
		private System.Windows.Forms.TextBox txtEmployeeID;
		private System.Windows.Forms.ListBox lstEmp;
		private System.Windows.Forms.Button btnRemove;
		
		private Hashtable hashEmployees;

		public frmEmployees()
		{
			InitializeComponent();
		}

		private void InitializeComponent()
		{
			this.lblFullName = new System.Windows.Forms.Label();
			this.txtFullName = new System.Windows.Forms.TextBox();
			this.txtDepartment = new System.Windows.Forms.TextBox();
			this.lblDepartment = new System.Windows.Forms.Label();
			this.txtSalary = new System.Windows.Forms.TextBox();
			this.lblSalary = new System.Windows.Forms.Label();
			this.btnAdd = new System.Windows.Forms.Button();
			this.btnClose = new System.Windows.Forms.Button();
			this.lblEmployeeID = new System.Windows.Forms.Label();
			this.txtEmployeeID = new System.Windows.Forms.TextBox();
			this.lstEmp = new System.Windows.Forms.ListBox();
			this.btnRemove = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// lblFullName
			// 
			this.lblFullName.Location = new System.Drawing.Point(16, 48);
			this.lblFullName.Name = "lblFullName";
			this.lblFullName.Size = new System.Drawing.Size(87, 18);
			this.lblFullName.TabIndex = 0;
			this.lblFullName.Text = "姓名:";
			// 
			// txtFullName
			// 
			this.txtFullName.Location = new System.Drawing.Point(104, 48);
			this.txtFullName.Name = "txtFullName";
			this.txtFullName.Size = new System.Drawing.Size(182, 21);
			this.txtFullName.TabIndex = 1;
			this.txtFullName.Text = "";
			// 
			// txtDepartment
			// 
			this.txtDepartment.Location = new System.Drawing.Point(104, 88);
			this.txtDepartment.Name = "txtDepartment";
			this.txtDepartment.Size = new System.Drawing.Size(182, 21);
			this.txtDepartment.TabIndex = 2;
			this.txtDepartment.Text = "";
			// 
			// lblDepartment
			// 
			this.lblDepartment.Location = new System.Drawing.Point(16, 88);
			this.lblDepartment.Name = "lblDepartment";
			this.lblDepartment.Size = new System.Drawing.Size(87, 17);
			this.lblDepartment.TabIndex = 2;
			this.lblDepartment.Text = "部门:";
			// 
			// txtSalary
			// 
			this.txtSalary.Location = new System.Drawing.Point(104, 120);
			this.txtSalary.Name = "txtSalary";
			this.txtSalary.Size = new System.Drawing.Size(182, 21);
			this.txtSalary.TabIndex = 3;
			this.txtSalary.Text = "";
			// 
			// lblSalary
			// 
			this.lblSalary.Location = new System.Drawing.Point(16, 120);
			this.lblSalary.Name = "lblSalary";
			this.lblSalary.Size = new System.Drawing.Size(87, 17);
			this.lblSalary.TabIndex = 6;
			this.lblSalary.Text = "工资:";
			// 
			// btnAdd
			// 
			this.btnAdd.Location = new System.Drawing.Point(200, 160);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.Size = new System.Drawing.Size(86, 24);
			this.btnAdd.TabIndex = 8;
			this.btnAdd.Text = "添加(&A)";
			this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
			// 
			// btnClose
			// 
			this.btnClose.Location = new System.Drawing.Point(528, 160);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new System.Drawing.Size(86, 24);
			this.btnClose.TabIndex = 13;
			this.btnClose.Text = "关闭(&C)";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// lblEmployeeID
			// 
			this.lblEmployeeID.Location = new System.Drawing.Point(16, 16);
			this.lblEmployeeID.Name = "lblEmployeeID";
			this.lblEmployeeID.Size = new System.Drawing.Size(87, 17);
			this.lblEmployeeID.TabIndex = 0;
			this.lblEmployeeID.Text = "职员编号:";
			// 
			// txtEmployeeID
			// 
			this.txtEmployeeID.Location = new System.Drawing.Point(104, 8);
			this.txtEmployeeID.Name = "txtEmployeeID";
			this.txtEmployeeID.Size = new System.Drawing.Size(182, 21);
			this.txtEmployeeID.TabIndex = 0;
			this.txtEmployeeID.Text = "";
			// 
			// lstEmp
			// 
			this.lstEmp.ItemHeight = 15;
			this.lstEmp.Location = new System.Drawing.Point(296, 8);
			this.lstEmp.Name = "lstEmp";
			this.lstEmp.Size = new System.Drawing.Size(320, 139);
			this.lstEmp.TabIndex = 14;
			// 
			// btnRemove
			// 
			this.btnRemove.Location = new System.Drawing.Point(432, 160);
			this.btnRemove.Name = "btnRemove";
			this.btnRemove.Size = new System.Drawing.Size(86, 24);
			this.btnRemove.TabIndex = 15;
			this.btnRemove.Text = "删除(&R)";
			this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
			// 
			// frmEmployees
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
			this.ClientSize = new System.Drawing.Size(624, 194);
			this.ControlBox = false;
			this.Controls.Add(this.btnRemove);
			this.Controls.Add(this.lstEmp);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.btnAdd);
			this.Controls.Add(this.txtSalary);
			this.Controls.Add(this.lblSalary);
			this.Controls.Add(this.txtDepartment);
			this.Controls.Add(this.lblDepartment);
			this.Controls.Add(this.txtFullName);
			this.Controls.Add(this.lblFullName);
			this.Controls.Add(this.lblEmployeeID);
			this.Controls.Add(this.txtEmployeeID);
			this.Font = new System.Drawing.Font("Times New Roman", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.MaximizeBox = false;
			this.Name = "frmEmployees";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "职员记录";
			this.Load += new System.EventHandler(this.frmEmployees_Load);
			this.ResumeLayout(false);

		}
		

		static void Main() 
		{
			 Application.Run(new frmEmployees());
		}

		private void frmEmployees_Load(object sender, System.EventArgs e)
		{
			hashEmployees = new Hashtable();
		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
				Employee objEmployee = new Employee();
				try 
				{
					objEmployee._employeeID = this.txtEmployeeID.Text;
					objEmployee._employeeFullName = this.txtFullName.Text;
					objEmployee._employeeDepartment = this.txtDepartment.Text;
					objEmployee._employeeSalary     = double.Parse(this.txtSalary.Text);
					hashEmployees.Add(this.txtEmployeeID.Text,objEmployee);

					lstEmp.Items.Add(txtFullName.Text);  
				}
				catch(NotSupportedException)
				{
					MessageBox.Show("不能添加项目");
				}
				catch(Exception ex)
				{
					MessageBox.Show("不能添加项目至列表\n" +
						ex.Message);
				}

				this.txtEmployeeID.Text="";
				this.txtFullName.Text    = "";
				this.txtDepartment.Text  = "";
				this.txtSalary.Text      = "";

			}

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			this.Close();
			Application.Exit(); 
		}

		private void btnRemove_Click(object sender, System.EventArgs e)
		{
			IDictionaryEnumerator myEnumerator = hashEmployees.GetEnumerator();
			while ( myEnumerator.MoveNext())
			{
				Employee A = (Employee)hashEmployees[myEnumerator.Key];
				if ((String)(lstEmp.SelectedItem) == A._employeeFullName)
				{
					hashEmployees.Remove(myEnumerator.Key); 
					lstEmp.Items.RemoveAt(lstEmp.SelectedIndex);  
					lstEmp.Refresh(); 
					break;
				}
			
			}
		}
	}
}

⌨️ 快捷键说明

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