📄 formqueryemployee.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data ;
using System.Data .SqlClient ;
namespace BlueHill.BlueHillWindows.EmployeeManagement
{
/// <summary>
/// FormQueryEmployee 的摘要说明。
/// </summary>
public class FormQueryEmployee : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
public System.Windows.Forms.TextBox txtName;
public System.Windows.Forms.TextBox txtEmail;
public System.Windows .Forms .ComboBox cbDepartment;
private System.Windows.Forms.Button btnQuery;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.PictureBox pictureBox3;
public DataTable datat;
//
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public FormQueryEmployee()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormQueryEmployee));
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.txtEmail = new System.Windows.Forms.TextBox();
this.cbDepartment = new System.Windows.Forms.ComboBox();
this.btnQuery = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox3 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(48, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 23);
this.label1.TabIndex = 0;
this.label1.Text = "姓名";
//
// label2
//
this.label2.Location = new System.Drawing.Point(48, 80);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 23);
this.label2.TabIndex = 1;
this.label2.Text = "电子邮件";
//
// label3
//
this.label3.Location = new System.Drawing.Point(48, 128);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 23);
this.label3.TabIndex = 2;
this.label3.Text = "所属部门";
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(144, 32);
this.txtName.Name = "txtName";
this.txtName.TabIndex = 3;
this.txtName.Text = "";
this.txtName.TextChanged += new System.EventHandler(this.txtName_TextChanged);
//
// txtEmail
//
this.txtEmail.Location = new System.Drawing.Point(144, 80);
this.txtEmail.Name = "txtEmail";
this.txtEmail.TabIndex = 4;
this.txtEmail.Text = "";
//
// cbDepartment
//
this.cbDepartment.Location = new System.Drawing.Point(144, 128);
this.cbDepartment.Name = "cbDepartment";
this.cbDepartment.Size = new System.Drawing.Size(121, 20);
this.cbDepartment.TabIndex = 5;
//
// btnQuery
//
this.btnQuery.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnQuery.Location = new System.Drawing.Point(80, 224);
this.btnQuery.Name = "btnQuery";
this.btnQuery.TabIndex = 6;
this.btnQuery.Text = "查询";
this.btnQuery.Click += new System.EventHandler(this.btnQuery_Click);
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(208, 224);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 7;
this.btnCancel.Text = "取消";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// label4
//
this.label4.Location = new System.Drawing.Point(48, 176);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(272, 23);
this.label4.TabIndex = 8;
this.label4.Text = "_________________________________________________________________________________" +
"____________________________________________________________________";
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(8, 24);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(24, 32);
this.pictureBox1.TabIndex = 9;
this.pictureBox1.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
this.pictureBox2.Location = new System.Drawing.Point(8, 72);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(24, 32);
this.pictureBox2.TabIndex = 10;
this.pictureBox2.TabStop = false;
//
// pictureBox3
//
this.pictureBox3.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox3.Image")));
this.pictureBox3.Location = new System.Drawing.Point(8, 112);
this.pictureBox3.Name = "pictureBox3";
this.pictureBox3.Size = new System.Drawing.Size(24, 32);
this.pictureBox3.TabIndex = 11;
this.pictureBox3.TabStop = false;
//
// FormQueryEmployee
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.ControlLight;
this.ClientSize = new System.Drawing.Size(384, 273);
this.ControlBox = false;
this.Controls.Add(this.pictureBox3);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.label4);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnQuery);
this.Controls.Add(this.cbDepartment);
this.Controls.Add(this.txtEmail);
this.Controls.Add(this.txtName);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FormQueryEmployee";
this.Text = "员工查询";
this.Load += new System.EventHandler(this.FormQueryEmployee_Load);
this.ResumeLayout(false);
}
#endregion
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.Close ();
}
private void btnQuery_Click(object sender, System.EventArgs e)
{
try
{
SqlConnection conn=new SqlConnection("Initial Catalog=BlueHill;Data Source=(local);Trusted_Connection=Yes");
SqlDataAdapter adp;
string s1="select * from tblemployee where Name like'%"+ this.txtName.Text +"%' and Email like'%"+ this.txtEmail.Text +"%' and DeptID like'%"+ this.cbDepartment.SelectedValue.ToString() +"%'";
string s2="select * from tblemployee where Name like'%"+ this.txtName.Text +"%' and Email like'%"+ this.txtEmail.Text +"%'";
if(cbDepartment.SelectedIndex <= -1)
{
adp=new SqlDataAdapter(s2,conn);
}
else
{
adp=new SqlDataAdapter(s1,conn);
}
DataSet datas = new DataSet();
datat = new DataTable();
adp.Fill(datas,"tblemployeeMap");
datat=datas.Tables[0];
}
catch(Exception)
{
MessageBox.Show("查询结果不合理!");
}
}
private void FormQueryEmployee_Load(object sender, System.EventArgs e)
{
}
private void txtName_TextChanged(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -