LookupStafferInfo.cs
上传用户:hjieqiu
上传日期:2013-05-11
资源大小:16494k
文件大小:13k
源码类别:

企业管理

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. namespace 人力资源管理系统
  8. {
  9. /// <summary>
  10. /// LookupStafferInfo 的摘要说明。
  11. /// </summary>
  12. public class LookupStafferInfo : System.Windows.Forms.Form
  13. {
  14. private DataTable tempTable = new DataTable();
  15. private System.Windows.Forms.ComboBox cmb1;
  16. private System.Windows.Forms.TextBox txt1;
  17. private System.Windows.Forms.TextBox txt2;
  18. private System.Windows.Forms.ComboBox cmb3;
  19. private System.Windows.Forms.ComboBox cmb2;
  20. private System.Windows.Forms.Label label6;
  21. private System.Windows.Forms.Label label8;
  22. private System.Windows.Forms.Label label14;
  23. private System.Windows.Forms.Label label15;
  24. private System.Windows.Forms.Label label16;
  25. private System.Windows.Forms.GroupBox groupBox1;
  26. private System.Windows.Forms.DataGrid dataGrid1;
  27. private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
  28. private System.Windows.Forms.Button btn_Research;
  29. private System.Windows.Forms.Button btnQuit;
  30. private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
  31. private System.Data.SqlClient.SqlConnection sqlConnection1;
  32. /// <summary>
  33. /// 必需的设计器变量。
  34. /// </summary>
  35. private System.ComponentModel.Container components = null;
  36. public LookupStafferInfo()
  37. {
  38. //
  39. // Windows 窗体设计器支持所必需的
  40. //
  41. InitializeComponent();
  42. //
  43. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  44. //
  45. }
  46. /// <summary>
  47. /// 清理所有正在使用的资源。
  48. /// </summary>
  49. protected override void Dispose( bool disposing )
  50. {
  51. if( disposing )
  52. {
  53. if(components != null)
  54. {
  55. components.Dispose();
  56. }
  57. }
  58. base.Dispose( disposing );
  59. }
  60. #region Windows 窗体设计器生成的代码
  61. /// <summary>
  62. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  63. /// 此方法的内容。
  64. /// </summary>
  65. private void InitializeComponent()
  66. {
  67. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(LookupStafferInfo));
  68. this.cmb1 = new System.Windows.Forms.ComboBox();
  69. this.txt1 = new System.Windows.Forms.TextBox();
  70. this.txt2 = new System.Windows.Forms.TextBox();
  71. this.cmb3 = new System.Windows.Forms.ComboBox();
  72. this.cmb2 = new System.Windows.Forms.ComboBox();
  73. this.label6 = new System.Windows.Forms.Label();
  74. this.label8 = new System.Windows.Forms.Label();
  75. this.label14 = new System.Windows.Forms.Label();
  76. this.label15 = new System.Windows.Forms.Label();
  77. this.label16 = new System.Windows.Forms.Label();
  78. this.groupBox1 = new System.Windows.Forms.GroupBox();
  79. this.btn_Research = new System.Windows.Forms.Button();
  80. this.btnQuit = new System.Windows.Forms.Button();
  81. this.dataGrid1 = new System.Windows.Forms.DataGrid();
  82. this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
  83. this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
  84. this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
  85. this.groupBox1.SuspendLayout();
  86. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
  87. this.SuspendLayout();
  88. // 
  89. // cmb1
  90. // 
  91. this.cmb1.Items.AddRange(new object[] {
  92.   "男",
  93.   "女"});
  94. this.cmb1.Location = new System.Drawing.Point(200, 40);
  95. this.cmb1.Name = "cmb1";
  96. this.cmb1.Size = new System.Drawing.Size(56, 20);
  97. this.cmb1.TabIndex = 2;
  98. // 
  99. // txt1
  100. // 
  101. this.txt1.Location = new System.Drawing.Point(12, 40);
  102. this.txt1.Name = "txt1";
  103. this.txt1.Size = new System.Drawing.Size(76, 21);
  104. this.txt1.TabIndex = 0;
  105. this.txt1.Text = "";
  106. // 
  107. // txt2
  108. // 
  109. this.txt2.Location = new System.Drawing.Point(104, 40);
  110. this.txt2.Name = "txt2";
  111. this.txt2.Size = new System.Drawing.Size(76, 21);
  112. this.txt2.TabIndex = 1;
  113. this.txt2.Text = "";
  114. // 
  115. // cmb3
  116. // 
  117. this.cmb3.Items.AddRange(new object[] {
  118.   "安徽",
  119.   "北京",
  120.   "河南",
  121.   "河北",
  122.   "其他"});
  123. this.cmb3.Location = new System.Drawing.Point(360, 40);
  124. this.cmb3.Name = "cmb3";
  125. this.cmb3.Size = new System.Drawing.Size(96, 20);
  126. this.cmb3.TabIndex = 4;
  127. // 
  128. // cmb2
  129. // 
  130. this.cmb2.Items.AddRange(new object[] {
  131.   "汉族",
  132.   "壮族",
  133.   "满族",
  134.   "苗族",
  135.   "其他"});
  136. this.cmb2.Location = new System.Drawing.Point(272, 40);
  137. this.cmb2.Name = "cmb2";
  138. this.cmb2.Size = new System.Drawing.Size(72, 20);
  139. this.cmb2.TabIndex = 3;
  140. // 
  141. // label6
  142. // 
  143. this.label6.Location = new System.Drawing.Point(112, 16);
  144. this.label6.Name = "label6";
  145. this.label6.Size = new System.Drawing.Size(48, 16);
  146. this.label6.TabIndex = 28;
  147. this.label6.Text = "姓名";
  148. // 
  149. // label8
  150. // 
  151. this.label8.Location = new System.Drawing.Point(16, 16);
  152. this.label8.Name = "label8";
  153. this.label8.Size = new System.Drawing.Size(64, 16);
  154. this.label8.TabIndex = 29;
  155. this.label8.Text = "姓名简码";
  156. // 
  157. // label14
  158. // 
  159. this.label14.Location = new System.Drawing.Point(280, 16);
  160. this.label14.Name = "label14";
  161. this.label14.Size = new System.Drawing.Size(48, 16);
  162. this.label14.TabIndex = 27;
  163. this.label14.Text = "民族";
  164. // 
  165. // label15
  166. // 
  167. this.label15.Location = new System.Drawing.Point(360, 16);
  168. this.label15.Name = "label15";
  169. this.label15.Size = new System.Drawing.Size(48, 16);
  170. this.label15.TabIndex = 25;
  171. this.label15.Text = "籍贯";
  172. // 
  173. // label16
  174. // 
  175. this.label16.Location = new System.Drawing.Point(200, 16);
  176. this.label16.Name = "label16";
  177. this.label16.Size = new System.Drawing.Size(48, 16);
  178. this.label16.TabIndex = 26;
  179. this.label16.Text = "性别";
  180. // 
  181. // groupBox1
  182. // 
  183. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
  184. | System.Windows.Forms.AnchorStyles.Right)));
  185. this.groupBox1.Controls.Add(this.btn_Research);
  186. this.groupBox1.Controls.Add(this.txt1);
  187. this.groupBox1.Controls.Add(this.txt2);
  188. this.groupBox1.Controls.Add(this.label15);
  189. this.groupBox1.Controls.Add(this.cmb3);
  190. this.groupBox1.Controls.Add(this.cmb2);
  191. this.groupBox1.Controls.Add(this.label16);
  192. this.groupBox1.Controls.Add(this.label6);
  193. this.groupBox1.Controls.Add(this.label8);
  194. this.groupBox1.Controls.Add(this.cmb1);
  195. this.groupBox1.Controls.Add(this.label14);
  196. this.groupBox1.Controls.Add(this.btnQuit);
  197. this.groupBox1.Location = new System.Drawing.Point(0, 0);
  198. this.groupBox1.Name = "groupBox1";
  199. this.groupBox1.Size = new System.Drawing.Size(592, 80);
  200. this.groupBox1.TabIndex = 30;
  201. this.groupBox1.TabStop = false;
  202. // 
  203. // btn_Research
  204. // 
  205. this.btn_Research.Location = new System.Drawing.Point(480, 34);
  206. this.btn_Research.Name = "btn_Research";
  207. this.btn_Research.Size = new System.Drawing.Size(68, 24);
  208. this.btn_Research.TabIndex = 5;
  209. this.btn_Research.Text = "查询";
  210. this.btn_Research.Click += new System.EventHandler(this.btn_Research_Click);
  211. // 
  212. // btnQuit
  213. // 
  214. this.btnQuit.Location = new System.Drawing.Point(634, 36);
  215. this.btnQuit.Name = "btnQuit";
  216. this.btnQuit.Size = new System.Drawing.Size(68, 24);
  217. this.btnQuit.TabIndex = 31;
  218. this.btnQuit.Text = "退出";
  219. this.btnQuit.Click += new System.EventHandler(this.btnQuit_Click);
  220. // 
  221. // dataGrid1
  222. // 
  223. this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
  224. | System.Windows.Forms.AnchorStyles.Left) 
  225. | System.Windows.Forms.AnchorStyles.Right)));
  226. this.dataGrid1.CaptionVisible = false;
  227. this.dataGrid1.DataMember = "";
  228. this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  229. this.dataGrid1.Location = new System.Drawing.Point(0, 72);
  230. this.dataGrid1.Name = "dataGrid1";
  231. this.dataGrid1.ReadOnly = true;
  232. this.dataGrid1.Size = new System.Drawing.Size(592, 338);
  233. this.dataGrid1.TabIndex = 6;
  234. // 
  235. // sqlDataAdapter1
  236. // 
  237. this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
  238. this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
  239.   new System.Data.Common.DataTableMapping("Table", "职员基本信息表", new System.Data.Common.DataColumnMapping[] {
  240.  new System.Data.Common.DataColumnMapping("姓名", "姓名"),
  241.  new System.Data.Common.DataColumnMapping("姓名简码", "姓名简码"),
  242.  new System.Data.Common.DataColumnMapping("性别", "性别"),
  243.  new System.Data.Common.DataColumnMapping("出生日期", "出生日期"),
  244.  new System.Data.Common.DataColumnMapping("籍贯", "籍贯"),
  245.  new System.Data.Common.DataColumnMapping("民族", "民族"),
  246.  new System.Data.Common.DataColumnMapping("办公电话", "办公电话"),
  247.  new System.Data.Common.DataColumnMapping("婚姻状况", "婚姻状况"),
  248.  new System.Data.Common.DataColumnMapping("单位名称", "单位名称"),
  249.  new System.Data.Common.DataColumnMapping("文化程度", "文化程度"),
  250.  new System.Data.Common.DataColumnMapping("职员编号", "职员编号"),
  251.  new System.Data.Common.DataColumnMapping("单位编号", "单位编号")})});
  252. // 
  253. // sqlSelectCommand1
  254. // 
  255. this.sqlSelectCommand1.CommandText = "SELECT a.姓名, a.姓名简码, a.性别, a.出生日期, a.籍贯, a.民族, a.办公电话, a.婚姻状况, b.单位名称, a.文化程度, a." +
  256. "职员编号, b.单位编号 FROM 职员基本信息表 a INNER JOIN 组织机构编码表 b ON a.单位编号 = b.单位编号";
  257. this.sqlSelectCommand1.Connection = this.sqlConnection1;
  258. // 
  259. // sqlConnection1
  260. // 
  261. this.sqlConnection1.ConnectionString = "workstation id=localhost;Integrated Security=SSPI;Database=hrmbook;";
  262. // 
  263. // LookupStafferInfo
  264. // 
  265. this.AcceptButton = this.btn_Research;
  266. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  267. this.ClientSize = new System.Drawing.Size(592, 423);
  268. this.Controls.Add(this.dataGrid1);
  269. this.Controls.Add(this.groupBox1);
  270. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  271. this.Name = "LookupStafferInfo";
  272. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  273. this.Text = "【职员信息查询】";
  274. this.Load += new System.EventHandler(this.LookupStafferInfo_Load);
  275. this.groupBox1.ResumeLayout(false);
  276. ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
  277. this.ResumeLayout(false);
  278. }
  279. #endregion
  280. //--------------------初始化窗体,读入数据------------------
  281. private void LookupStafferInfo_Load(object sender, System.EventArgs e)
  282. {
  283. this.sqlDataAdapter1.Fill(tempTable);
  284. this.dataGrid1.DataSource = tempTable.DefaultView;
  285. DataGridStateControl();
  286. }
  287. //--------------将数据显示在表格中,并设置表格参数------------------
  288. private void DataGridStateControl()
  289. {
  290. DataGridTableStyle ts = new DataGridTableStyle();
  291. DataGridNoActiveCellColumn aColumnTextColumn;
  292. ts.AlternatingBackColor = Color.LightGray;
  293. ts.MappingName = tempTable.TableName;
  294. ts.AllowSorting = false;//不允许进行排序
  295. int numCols = tempTable.Columns.Count;
  296. for (int i = 0;i< numCols-2;i++)//将数据填充到表格中
  297. {
  298. aColumnTextColumn = new DataGridNoActiveCellColumn();
  299. aColumnTextColumn.MappingName = tempTable.Columns[i].ColumnName;
  300. aColumnTextColumn.HeaderText = tempTable.Columns[i].ColumnName;
  301. aColumnTextColumn.NullText = "";
  302. aColumnTextColumn.Format = "D";
  303. ts.GridColumnStyles.Add(aColumnTextColumn);
  304. }
  305. this.dataGrid1.TableStyles.Add(ts);
  306. this.dataGrid1.Select(0);
  307. }
  308. //--------------将符合查询条件的数据查询并显示在表中------------------
  309. private void btn_Research_Click(object sender, System.EventArgs e)
  310. {
  311. string strRowFilter = "";
  312. string strCmb1 = this.cmb1.Text.Trim();
  313. string strCmb2 = this.cmb2.Text.Trim();
  314. string strCmb3 = this.cmb3.Text.Trim();
  315. if(this.txt1.Text.Trim() != "")//设置表的过滤条件
  316. strRowFilter += "姓名简码 like '%" + txt1.Text.Trim() + "%' and ";
  317. if(this.txt2.Text.Trim() != "")
  318. strRowFilter += "姓名 like '%" + txt2.Text.Trim() + "%' and ";
  319. if(strCmb1 != "")
  320. strRowFilter += "性别 like '%" + strCmb1 + "%' and ";
  321. if(strCmb2 != "")
  322. strRowFilter += "民族 like '%" + strCmb2 + "%' and ";
  323. if(strCmb3 != "")
  324. strRowFilter += "籍贯 like '%" + strCmb3 + "%' and ";
  325. if(strRowFilter != "")    // 存在查询条件
  326. strRowFilter = strRowFilter.Substring(0,strRowFilter.Length-5);
  327. tempTable.DefaultView.RowFilter = strRowFilter;
  328. }
  329. //--------------退出窗体-----------------
  330. private void btnQuit_Click(object sender, System.EventArgs e)
  331. {
  332. this.Close();
  333. }
  334. }
  335. }