📄 frmsearch.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Example_2
{
/// <summary>
/// Summary description for frmSearch.
/// </summary>
public class frmSearch : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtEmployeeID;
private System.Windows.Forms.Label lblEmployeeID;
private System.Windows.Forms.Button btnSearch;
private Hashtable objHashEmployees;
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public frmSearch(Hashtable hashTable)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
objHashEmployees = hashTable;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSearch = new System.Windows.Forms.Button();
this.txtEmployeeID = new System.Windows.Forms.TextBox();
this.lblEmployeeID = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnSearch
//
this.btnSearch.Location = new System.Drawing.Point(216, 16);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(56, 24);
this.btnSearch.TabIndex = 0;
this.btnSearch.Text = "搜索(&S)";
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// txtEmployeeID
//
this.txtEmployeeID.Location = new System.Drawing.Point(80, 16);
this.txtEmployeeID.Name = "txtEmployeeID";
this.txtEmployeeID.Size = new System.Drawing.Size(120, 21);
this.txtEmployeeID.TabIndex = 0;
this.txtEmployeeID.Text = "";
//
// lblEmployeeID
//
this.lblEmployeeID.Location = new System.Drawing.Point(8, 24);
this.lblEmployeeID.Name = "lblEmployeeID";
this.lblEmployeeID.Size = new System.Drawing.Size(70, 15);
this.lblEmployeeID.TabIndex = 2;
this.lblEmployeeID.Text = "职员编号:";
//
// button1
//
this.button1.Location = new System.Drawing.Point(280, 16);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 24);
this.button1.TabIndex = 3;
this.button1.Text = "取消(&C)";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// frmSearch
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(344, 53);
this.ControlBox = false;
this.Controls.Add(this.button1);
this.Controls.Add(this.lblEmployeeID);
this.Controls.Add(this.txtEmployeeID);
this.Controls.Add(this.btnSearch);
this.Name = "frmSearch";
this.Text = "搜索";
this.ResumeLayout(false);
}
#endregion
private void btnSearch_Click(object sender, System.EventArgs e)
{
try
{
//Finding the employee id
object objEmployeeFind = objHashEmployees[this.txtEmployeeID.Text];
//Casting to Employee type
Employee objEmployee = (Employee)objEmployeeFind;
//Adding values to static fields
frmEmployees.employeeID = objEmployee._employeeID;
frmEmployees.employeeName = objEmployee._employeeFullName;
frmEmployees.employeeDepartment = objEmployee._employeeDepartment;
frmEmployees.employeeSalary = objEmployee._employeeSalary.ToString();
this.Close();
}
//catching Exceptions
catch(ArgumentOutOfRangeException)
{
MessageBox.Show("不能检索项目");
}
catch(Exception)
{
MessageBox.Show("检索项目时出现问题");
}
}
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -