📄 lookupstafferinfo.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 人力资源管理系统
{
/// <summary>
/// LookupStafferInfo 的摘要说明。
/// </summary>
public class LookupStafferInfo : System.Windows.Forms.Form
{
private DataTable tempTable = new DataTable();
private System.Windows.Forms.ComboBox cmb1;
private System.Windows.Forms.TextBox txt1;
private System.Windows.Forms.TextBox txt2;
private System.Windows.Forms.ComboBox cmb3;
private System.Windows.Forms.ComboBox cmb2;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.Label label15;
private System.Windows.Forms.Label label16;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Windows.Forms.Button btn_Research;
private System.Windows.Forms.Button btnQuit;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public LookupStafferInfo()
{
//
// 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(LookupStafferInfo));
this.cmb1 = new System.Windows.Forms.ComboBox();
this.txt1 = new System.Windows.Forms.TextBox();
this.txt2 = new System.Windows.Forms.TextBox();
this.cmb3 = new System.Windows.Forms.ComboBox();
this.cmb2 = new System.Windows.Forms.ComboBox();
this.label6 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label14 = new System.Windows.Forms.Label();
this.label15 = new System.Windows.Forms.Label();
this.label16 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btn_Research = new System.Windows.Forms.Button();
this.btnQuit = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// cmb1
//
this.cmb1.Items.AddRange(new object[] {
"男",
"女"});
this.cmb1.Location = new System.Drawing.Point(200, 40);
this.cmb1.Name = "cmb1";
this.cmb1.Size = new System.Drawing.Size(56, 20);
this.cmb1.TabIndex = 2;
//
// txt1
//
this.txt1.Location = new System.Drawing.Point(12, 40);
this.txt1.Name = "txt1";
this.txt1.Size = new System.Drawing.Size(76, 21);
this.txt1.TabIndex = 0;
this.txt1.Text = "";
//
// txt2
//
this.txt2.Location = new System.Drawing.Point(104, 40);
this.txt2.Name = "txt2";
this.txt2.Size = new System.Drawing.Size(76, 21);
this.txt2.TabIndex = 1;
this.txt2.Text = "";
//
// cmb3
//
this.cmb3.Items.AddRange(new object[] {
"安徽",
"北京",
"河南",
"河北",
"其他"});
this.cmb3.Location = new System.Drawing.Point(360, 40);
this.cmb3.Name = "cmb3";
this.cmb3.Size = new System.Drawing.Size(96, 20);
this.cmb3.TabIndex = 4;
//
// cmb2
//
this.cmb2.Items.AddRange(new object[] {
"汉族",
"壮族",
"满族",
"苗族",
"其他"});
this.cmb2.Location = new System.Drawing.Point(272, 40);
this.cmb2.Name = "cmb2";
this.cmb2.Size = new System.Drawing.Size(72, 20);
this.cmb2.TabIndex = 3;
//
// label6
//
this.label6.Location = new System.Drawing.Point(112, 16);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(48, 16);
this.label6.TabIndex = 28;
this.label6.Text = "姓名";
//
// label8
//
this.label8.Location = new System.Drawing.Point(16, 16);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(64, 16);
this.label8.TabIndex = 29;
this.label8.Text = "姓名简码";
//
// label14
//
this.label14.Location = new System.Drawing.Point(280, 16);
this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(48, 16);
this.label14.TabIndex = 27;
this.label14.Text = "民族";
//
// label15
//
this.label15.Location = new System.Drawing.Point(360, 16);
this.label15.Name = "label15";
this.label15.Size = new System.Drawing.Size(48, 16);
this.label15.TabIndex = 25;
this.label15.Text = "籍贯";
//
// label16
//
this.label16.Location = new System.Drawing.Point(200, 16);
this.label16.Name = "label16";
this.label16.Size = new System.Drawing.Size(48, 16);
this.label16.TabIndex = 26;
this.label16.Text = "性别";
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.btn_Research);
this.groupBox1.Controls.Add(this.txt1);
this.groupBox1.Controls.Add(this.txt2);
this.groupBox1.Controls.Add(this.label15);
this.groupBox1.Controls.Add(this.cmb3);
this.groupBox1.Controls.Add(this.cmb2);
this.groupBox1.Controls.Add(this.label16);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.label8);
this.groupBox1.Controls.Add(this.cmb1);
this.groupBox1.Controls.Add(this.label14);
this.groupBox1.Controls.Add(this.btnQuit);
this.groupBox1.Location = new System.Drawing.Point(0, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(592, 80);
this.groupBox1.TabIndex = 30;
this.groupBox1.TabStop = false;
//
// btn_Research
//
this.btn_Research.Location = new System.Drawing.Point(480, 34);
this.btn_Research.Name = "btn_Research";
this.btn_Research.Size = new System.Drawing.Size(68, 24);
this.btn_Research.TabIndex = 5;
this.btn_Research.Text = "查询";
this.btn_Research.Click += new System.EventHandler(this.btn_Research_Click);
//
// btnQuit
//
this.btnQuit.Location = new System.Drawing.Point(634, 36);
this.btnQuit.Name = "btnQuit";
this.btnQuit.Size = new System.Drawing.Size(68, 24);
this.btnQuit.TabIndex = 31;
this.btnQuit.Text = "退出";
this.btnQuit.Click += new System.EventHandler(this.btnQuit_Click);
//
// dataGrid1
//
this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 72);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(592, 338);
this.dataGrid1.TabIndex = 6;
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "职员基本信息表", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("姓名", "姓名"),
new System.Data.Common.DataColumnMapping("姓名简码", "姓名简码"),
new System.Data.Common.DataColumnMapping("性别", "性别"),
new System.Data.Common.DataColumnMapping("出生日期", "出生日期"),
new System.Data.Common.DataColumnMapping("籍贯", "籍贯"),
new System.Data.Common.DataColumnMapping("民族", "民族"),
new System.Data.Common.DataColumnMapping("办公电话", "办公电话"),
new System.Data.Common.DataColumnMapping("婚姻状况", "婚姻状况"),
new System.Data.Common.DataColumnMapping("单位名称", "单位名称"),
new System.Data.Common.DataColumnMapping("文化程度", "文化程度"),
new System.Data.Common.DataColumnMapping("职员编号", "职员编号"),
new System.Data.Common.DataColumnMapping("单位编号", "单位编号")})});
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT a.姓名, a.姓名简码, a.性别, a.出生日期, a.籍贯, a.民族, a.办公电话, a.婚姻状况, b.单位名称, a.文化程度, a." +
"职员编号, b.单位编号 FROM 职员基本信息表 a INNER JOIN 组织机构编码表 b ON a.单位编号 = b.单位编号";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=localhost;Integrated Security=SSPI;Database=hrmbook;";
//
// LookupStafferInfo
//
this.AcceptButton = this.btn_Research;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(592, 423);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.groupBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "LookupStafferInfo";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "【职员信息查询】";
this.Load += new System.EventHandler(this.LookupStafferInfo_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
//--------------------初始化窗体,读入数据------------------
private void LookupStafferInfo_Load(object sender, System.EventArgs e)
{
this.sqlDataAdapter1.Fill(tempTable);
this.dataGrid1.DataSource = tempTable.DefaultView;
DataGridStateControl();
}
//--------------将数据显示在表格中,并设置表格参数------------------
private void DataGridStateControl()
{
DataGridTableStyle ts = new DataGridTableStyle();
DataGridNoActiveCellColumn aColumnTextColumn;
ts.AlternatingBackColor = Color.LightGray;
ts.MappingName = tempTable.TableName;
ts.AllowSorting = false;//不允许进行排序
int numCols = tempTable.Columns.Count;
for (int i = 0;i< numCols-2;i++)//将数据填充到表格中
{
aColumnTextColumn = new DataGridNoActiveCellColumn();
aColumnTextColumn.MappingName = tempTable.Columns[i].ColumnName;
aColumnTextColumn.HeaderText = tempTable.Columns[i].ColumnName;
aColumnTextColumn.NullText = "";
aColumnTextColumn.Format = "D";
ts.GridColumnStyles.Add(aColumnTextColumn);
}
this.dataGrid1.TableStyles.Add(ts);
this.dataGrid1.Select(0);
}
//--------------将符合查询条件的数据查询并显示在表中------------------
private void btn_Research_Click(object sender, System.EventArgs e)
{
string strRowFilter = "";
string strCmb1 = this.cmb1.Text.Trim();
string strCmb2 = this.cmb2.Text.Trim();
string strCmb3 = this.cmb3.Text.Trim();
if(this.txt1.Text.Trim() != "")//设置表的过滤条件
strRowFilter += "姓名简码 like '%" + txt1.Text.Trim() + "%' and ";
if(this.txt2.Text.Trim() != "")
strRowFilter += "姓名 like '%" + txt2.Text.Trim() + "%' and ";
if(strCmb1 != "")
strRowFilter += "性别 like '%" + strCmb1 + "%' and ";
if(strCmb2 != "")
strRowFilter += "民族 like '%" + strCmb2 + "%' and ";
if(strCmb3 != "")
strRowFilter += "籍贯 like '%" + strCmb3 + "%' and ";
if(strRowFilter != "") // 存在查询条件
strRowFilter = strRowFilter.Substring(0,strRowFilter.Length-5);
tempTable.DefaultView.RowFilter = strRowFilter;
}
//--------------退出窗体-----------------
private void btnQuit_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -