?? 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 + -