版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、(1) 向解决方案资源管理器中添加一个新的窗体,将其名称改为“AmendStafferInfo.cs”,在窗体中放置如下图2.32所示的控件。图2.32 职员信息维护窗体(2) 放置一个sqlDataAdapter控件,在sqlDataAdapter设置的第四步【生成SQL语句】窗口中的编辑框中输入:select * from 职员基本信息表各控件的属性设置如表2.7所示。表2.7 职员信息维护窗体控件属性设置控件类型对 象 名属 性取值(说明)FormAmendStafferInfoNameAmendStafferInfoText职员信息维护StartPositionCenterScreen
2、Icon实例目录下的hrm.ico文件ImageListimageList1Images依次添加icon目录下的首记录.bmp等10个图标 续表控件类型对 象 名属 性取值(说明)ToolBarToolBar1ImageListimageList1Buttons在弹出的对话框中单击【添加】按钮添加成员,并将各个按钮的Text和ToolTipText设置为如图2.32中所示的文字DataGriddataGrid1CaptionVisibleFalseLabel共21个Text如图2.32中所示TextBoxtxt1txt17 共17个TextTextBoxtxt17ReadOnlyTrueCom
3、boBoxcmb1cmb4 共4个Textcmb1Items男、女cmb2Items汉族、壮族、满族、苗族、其他cmb3Items安徽、北京、河南、河北、其他(3) 为本窗体添加事件处理代码如下所示。using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Data.SqlClient;namespace 人力资源管理系统public class AmendStaf
4、ferInfo : System.Windows.Forms.Form private DataTable tempTable = new DataTable(); private CurrencyManager cmAmend; private string strSQL = ; private SqlConnection tempConnection = new SqlConnection( server=localhost;database=hrmbook;Connect Timeout=30; Trusted_Connection=yes) ; private SqlDataAdapt
5、er da; private DataTable tblDataSource = new DataTable();/*此处省略由程序自动生成的代码*/-初始化窗体,读入数据-private void AmendStafferInfo_Load(object sender, System.EventArgs e) this.sqlDataAdapter1.Fill(tempTable); this.dataGrid1.DataSource = tempTable.DefaultView; InputComboBox();/填充【单位编号】下拉列表框的下拉列表 DataGridStateContr
6、ol(); DataBindingsFunction(); cmAmend = (CurrencyManager) BindingContexttempTable; /-将数据显示在表格中,并设置表格参数- private void DataGridStateControl() DataGridTableStyle ts = new DataGridTableStyle(); DataGridNoActiveCellColumn aColumnTextColumn; ts.AlternatingBackColor = Color.LightGray; ts.MappingName = temp
7、Table.TableName; ts.AllowSorting = false;/不允许进行排序 int numCols = tempTable.Columns.Count; for (int i = 1;i numCols;i+) /从第二列开始,不显示第一列的“职员编号” aColumnTextColumn = new DataGridNoActiveCellColumn(); aColumnTextColumn.MappingName = tempTable.Columnsi.ColumnName; aColumnTextColumn.HeaderText = tempTable.Co
8、lumnsi.ColumnName; aColumnTextColumn.NullText = ; aColumnTextColumn.Format = D; ts.GridColumnStyles.Add(aColumnTextColumn); this.dataGrid1.TableStyles.Add(ts); this.dataGrid1.Select(0);/选定第一列 /-为面板中的文本框绑定数据集中的相应字段- private void DataBindingsFunction() this.txt1.DataBindings.Add(Text,tempTable,职员编号);
9、this.txt2.DataBindings.Add(Text,tempTable,姓名); this.txt3.DataBindings.Add(Text,tempTable,姓名简码); this.txt4.DataBindings.Add(Text,tempTable,出生日期); this.txt5.DataBindings.Add(Text,tempTable,年龄); this.txt6.DataBindings.Add(Text,tempTable,文化程度); this.txt7.DataBindings.Add(Text,tempTable,毕业学校); this.txt8.
10、DataBindings.Add(Text,tempTable,健康状况); this.txt9.DataBindings.Add(Text,tempTable,婚姻状况); this.txt10.DataBindings.Add(Text,tempTable,身份证号码); this.txt11.DataBindings.Add(Text,tempTable,家庭电话); this.txt12.DataBindings.Add(Text,tempTable,办公电话); this.txt13.DataBindings.Add(Text,tempTable,手机); this.txt14.Da
11、taBindings.Add(Text,tempTable,电子邮件地址); this.txt15.DataBindings.Add(Text,tempTable,职工帐号); this.txt16.DataBindings.Add(Text,tempTable,备注); this.cmb1.DataBindings.Add(Text,tempTable,性别); this.cmb2.DataBindings.Add(Text,tempTable,民族); this.cmb3.DataBindings.Add(Text,tempTable,籍贯); this.cmb4.DataBindings
12、.Add(Text,tempTable,单位编号); /-为【单位编号】下拉列表框设置下拉数据辞典- private void InputComboBox() this.strSQL = select 单位编号 from 组织机构编码表 order by 单位编号; this.da = new SqlDataAdapter(this.strSQL,this.tempConnection); this.da.Fill(tblDataSource); for (int i=0;i 0) this.dataGrid1.UnSelect(cmAmend.Position); cmAmend.Posit
13、ion-; this.dataGrid1.Select(cmAmend.Position); this.dataGrid1.CurrentRowIndex = cmAmend.Position; return; if (e.Button.ToolTipText = 下一记录) if (cmAmend.Position 0) cmAmend.RemoveAt(cmAmend.Position); else MessageBox.Show(没有可以删除的数据,提示, MessageBoxButtons.OK,MessageBoxIcon.Error); catch(Exception expres
14、s) MessageBox.Show(express.ToString(),提示,MessageBoxButtons.OK, MessageBoxIcon.Error); return; if (e.Button.ToolTipText = 提交修改) if (this.txt1.Text.Trim() = )/检查不能为空的字段 MessageBox.Show(职员编号不能为空!,提示,MessageBoxButtons.OK, MessageBoxIcon.Error); return; if (this.txt2.Text.Trim()=) MessageBox.Show(职员姓名不能为
15、空!,提示,MessageBoxButtons.OK, MessageBoxIcon.Error); return; cmAmend.EndCurrentEdit();/结束当前编辑操作并提交修改 if (tempTable.GetChanges() != null) try this.sqlDataAdapter1.Update(tempTable); catch(Exception express) MessageBox.Show(express.ToString(),提示, MessageBoxButtons.OK,MessageBoxIcon.Error); this.tempTabl
16、e.RejectChanges(); return; if (e.Button.ToolTipText = 取消修改) try cmAmend.CancelCurrentEdit(); /取消编辑 catch(Exception express) MessageBox.Show(express.ToString(),提示, MessageBoxButtons.OK,MessageBoxIcon.Error); return; if (e.Button.ToolTipText = 退出) this.Close(); /-在【机构编码】下拉列表框右边的文本框中显示与之对应的机构名称- privat
17、e void cmb4_SelectedIndexChanged(object sender, System.EventArgs e) DataTable tempTable = new DataTable(); string strSearchWord = this.cmb4.Text.Trim(); this.strSQL=select 单位名称 from 组织机构编码表where单位编号=+strSearchWord+; this.da = new SqlDataAdapter(this.strSQL,this.tempConnection); this.da.Fill(tempTable);/查询获得机构的单位名称,并填写到文本框中 if (tempTable.Rows.Count0) this.txt17.Text = tempTable.Rows00.ToString().Trim(); this.cmb4.SelectAll(); /-选择表格中的任何一个单元
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026四川内江隆昌市宝峰幼儿园见习岗位招聘2人考试备考试题及答案详解
- 2026年中医骨伤科学考试题解附答案
- 2026湖南邵阳市邵阳县审计局专业技术人员招聘10人笔试题库含答案详解【夺分金卷】
- 2026年福建三明市城市建设发展集团有限公司关于招聘应届毕业生5人的考前冲刺密卷及完整答案详解(网校专用)
- 2026广东广州医科大学附属第五医院人才招聘3人(十四)考前冲刺密卷附参考答案详解(研优卷)
- 2026四川绵阳市三台县医疗卫生辅助岗招募52人考前冲刺密卷附答案详解【综合卷】
- 2026年滇西应用技术大学招聘专任教师(博士)和“双师型”教师(25人)考前冲刺试卷附完整答案详解(夺冠)
- 2026浙江衢州市龙游县龙北水利枢纽综合开发有限公司招聘合同制员工1人(二)模拟试卷含完整答案详解【名校卷】
- 2026云南玉溪美年大健康体检中心就业见习岗位招募7人备考题库(综合卷)附答案详解
- 2026广西桂林旅游学院酒店管理学院国际酒店管理学院协议工资制人员招聘6人备考题库往年题考附答案详解
- 全国一级学会、协会目录
- 徐氏调查研究报告
- 龙虎山正一日诵早晚课
- 2022年阜阳市界首市选调中小学教师考试真题
- 2022高级经济师《知识产权实务》预测试卷2
- YY/T 0471.3-2004接触性创面敷料试验方法 第3部分:阻水性
- GB/T 11348.3-2011机械振动在旋转轴上测量评价机器的振动第3部分:耦合的工业机器
- GB 2711-2003非发酵性豆制品及面筋卫生标准
- GA/T 1163-2014人类DNA荧光标记STR分型结果的分析及应用
- 煤矿用防爆电气设备防爆检查标准培训课件
- 地铁是怎样建成的少儿科普版课件
评论
0/150
提交评论