C#实验报告(人事管理系统)_第1页
C#实验报告(人事管理系统)_第2页
C#实验报告(人事管理系统)_第3页
已阅读5页,还剩26页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、C#实验报告(人事管理系统)学号149074353姓名程裕博班级物141指导教师夏敏安徽工业大学计算机学院2016年12月先设置一个登录界面(连接数据库),登录时进行判断,根据不同的错误信息进行报错,如 密码错误。登陆成功后,进入主界面。主界面通过树和表格来显示数据。可以对人员,班组,部门进行增删改查操作,数据保存在数据库中。二.程序源码1数据库表结构3KSD 弼 恤.Rv.ii冶杞刼rv>t*w $0)* *4曙 Lift ChMlfrMfe Op 0MH7K I'M 口931 5Eg|4WTHNul佔细CHEOCn* 6 fl 41 ;nj粗樹CaaiEGORV WMBERi

2、EWKai«3*lmnrrWW?W* /CHj.TS r-Lr |昴1 (JibE* rasnlIMIfflUCiRLTr !. Jj Prr KLL伽* Will龍川價吨i网 KVT ini.CATEOiarjQaE好站ZE1E>50:< 9DT HL,却VW W *1LL创的mA.BJT ullirr wcn-iil®:| HIT RLLtC-n«l|! 4K)o.ljbk_Crw«.Bql* 10iHMKNAMECATEQOflVFR K也晅tl«】M7I:FrrWE££.l3NTIJifiJU:!黑旷 也

3、-駅FtCiLTlfiOKT刑慣員M|FE WJI2HF:ir肝hut 血rii:LwlOF-Rfi匙Nui wa 如UUlVlAMlPUfWQHD0*flKLhdf(&c(i住戳h网御I勒Mm ir|im/itJr.hAJyW:mlmIIOTCTT 也 HITLUJJJaIL >.|*1- i 屮 J.I h IIPlSTQSfi sTiAFCHKf! 韌 HHT l(TL.FKE1AET EET HirTtRU 他 曲2、登录界面using System;using System.Collections.Generic;using System.ComponentModel;

4、using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using CCWin;using System.Data.SqlClient;namespace实验_人事管理系统public partial class Form login : CCSkinMainpublic Form_login()In itializeComp onen t();stri ng src =博博实验一一人事管理

5、系统实验一一人事管理系统MyData.mdf;l ntegrated Security=True" ;private void Form1_Load( object sender,EventArgs e)private void butt on _log in _Click(object sen der,Eve ntArgs e)string user = this .skinTextBox.Text;string password = this .skinTextBox2.Text;int sign1 = 0;int sign2 = 0;if (user =""

6、 | password ="“)MessageBoxShow("您输入的数据不完整!");elsestring sql1 = string .Format( "select USERNAME from Table_login where USERNAME=N'0'", user);using ( SqlConnection coon = new SqlConnection (src)SqlCommanobmd = new SqlComman(tql1, coon);coon. Ope n();using ( SqlDataRea

7、der dr = cmd.ExecuteReader()while (dr.Read()sig n1+;if (sign1 = 0)|MessageBoxShow("未查询到您的用户信息!");if (sign1 != 0)string sql2 = string .Format( "select PASSWORD from Table_login where USERNAME=N'0'", user);using ( SqlConnection coon = new SqlConnection (src)SqlCommanotmd =

8、new SqlCommandsql2, coon);coon. Ope n();using ( SqlDataReader dr = cmd.ExecuteReader()while (dr.Read()if (password = dr"PASSWORDToString()sig n2+;if (sign1 != 0 && sign2 = 0)|MessageBoxShow(“您的密码输入错误!");if (sign2 != 0)Form_showf1 = new Form_shov(user, this );f1.Show();this .Visible

9、 = false ;3、主界面using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Timers;using System.Data.SqlClient;using CCWin;namespace实验_人事管理系统pu

10、blic partial class Form_show: Formpublic Form_show()In itializeComp onen t();public Form_show(string name1, Form_login f)login _n ame=n ame1;fl = f;In itializeComp onen t();string login_name= "xx"Form_login fl = null ;TreeNode t = new TreeNode();int ID=-1;public List <person > list =

11、 new List <person >();stri ng n ame;stri ng birth;stri ng sex;stri ng educati on;stri ng adm ini sitrator;stri ng man egetime;/ stri ng category_ name;博博实验一一人事管理系统stri ng src =实验一一人事管理系统MyData.mdf;l ntegrated Security=True" ;private void Form_show_Load(object sender. EventArgs e)toolStrip

12、StatusLabel_name.Text ="管理员:"+ thisogin_name;toolStripStatusLabel_time.Text ="登录时间:"+DateTime.Now.ToL on gTimeStri ng();Addpare nt();this .dataGridView1.ClearSelection();private void toolStripStatusLabel_name_Click(object sender, EventArgs e)private void Form_show_FormClosed(obje

13、ct sender, FormClosedEventArgs e)fl.Close();public void Addparent()stri ng sql = "select * from Table tree where PR NUMBER=-1"using ( SqlConnection coon = new SqlConnection (src)SqlCommanotmd = new SqlCommandsql, coon);coon. Ope n();using ( SqlDataReader dr = cmd.ExecuteReader()while (dr.R

14、ead()string name = dr "NAME".ToString();stri ng number = dr "NUMBER.ToStri ng();/ stri ng category=dr"CATEGORY".ToStri ng();TreeNode tn = new TreeNode();tn. Text = n ame;tn. Tag = n umber;tn.lm age In dex = 1;AddChild(number, tn);treeView_jiegou.Nodes.Add(t n);/ ski nTreeVie

15、w1.Nodes.Add(t n);private void AddChild( string pnumber, TreeNode pnode)if ( Convert .ToInt32(pnode.Tag) = 0 | (pnode.Parent!=null &&Convert .ToInt32(pnode.Parent.Tag) = 0)stri ng sql = "select * from Table_tree where PR_NUMBER=" + pn umber + "order by NAME desc;"using (

16、SqlConnection conn = new SqlConnection (src)SqlCommanobmd = new SqlComman(tql, conn);conn. Ope n();using ( SqlDataReader dr = cmd.ExecuteReader()while (dr.Read()_|string name = dr "NAME".ToString();stri ng number = dr "NUMBER.ToStri ng();/ stri ng category = dr"CATEGORY".ToS

17、tri ng(); TreeNode tn = new TreeNode();tn. Text = n ame;tn. Tag = n umber;tn.lm age In dex = 1;AddChild(number, tn);pno de.Nodes.Add(t n);else+ pn umber +stri ng sql = "select * from Table_tree where PR_NUMBER=" "order by NAME desc;"using ( SqlConnection conn = new SqlConnection

18、(src)SqlCommanobmd = new SqlComman(tql, conn);conn. Ope n();using ( SqlDataReader dr = cmd.ExecuteReader()while (dr.Read()string name = dr "NAME".ToString();stri ng number = dr "NUMBEFR.ToStri ng();/ stri ng category = dr"CATEGORY".ToStri ng(); TreeNode tn = new TreeNode();t

19、n. Text = n ame;tn. Tag = n umber;tn.lm age In dex = 0;AddChild( number, tn);pno de.Nodes.Add(t n);private void skin Butt on _add_Click(object sen der, Eve ntArgs e) / 无用的按钮 private void skin Butt on add Click 1(object sen der,Eve ntArgs e)MessageBox.Show("添加!");if (t.Parent.Parent!=null &

20、amp;& t.Parent!=null )Form_Addpers onfp = n ewForm_Addpers on (t, toolStripStatusLabel_ name.Text, DateTime.Now.ToStri ng();fp.Owner =this ;fp.Show();list.Clear();elseMessageBoxShow("请到班组添加人员!");/ reshow();private void treeView_jiegou_AfterSelect( object sender,TreeViewEventArgs e)stri

21、ng sql = "select * from Table_person where CATEGORY_NUMBER="Node.Tag;List <person > list = new List <person >();using ( SqlConnection conn = new SqlConnection (src) SqlCommandtmd = new SqlCommandsql, conn);conn. Ope n();using ( SqlDataReader dr = cmd.ExecuteReader()while (dr.Re

22、ad()3person p = new person();p.Person _n ame = dr"PERSON_NAMETbStri ng();p.Category _n ame = drp.Sex = dr"CATEGORY_NAMEoStri ng();"SEX".ToStri ng();str ingdt=dr "BIRTH".ToString().Split('');p.Birth = dt0;p.Educati on = dr"EDUCATION"ToStri ng();p.Adm in

23、i sitrator = dr"ADMINISITRATORJ'.ToStri ng();p.Ma negetime=dr"MANEGETIMEToStri ng();list.Add(p);this .dataGridView1.ClearSelection();this .dataGridView1.DataSource = list;ID = -1;private void 添加部门 ToolStripMenultem_Click(object sender,EventArgs e)if (t.Parent = null | t.Parent.Parent =

24、null )Form_Addfa = new Form_Adc(t);fa.Owner =this ;fa.Show();elseForm_Addpers onfp = n ewForm_Addpers on (t, toolStripStatusLabel_ name.Text, DateTime.Now.ToStri ng();fp.Owner =this ;fp.Show();list.Clear();this .dataGridView1.DataSource = list;private void treeView_jiegou_NodeMouseClick( object send

25、er,TreeNodeMouseClickEventArgs e)this .t = e.Node;/ MessageBox.Show(t.Name);public void reshow()treeView_jiegou.Nodes.Clear();Addpare nt();private void dataGridView1_CellClick( object sender,DataGridViewCellEventArgse)/string n ame;/string birth;/string education;/stri ng adm ini sitrator;/stri ng m

26、an egetime;if (e.RowIndex != -1)name =this .dataGridView1.Rowse.Rowlndex.CellsO.Value.ToString();birth =this .dataGridView1.Rowse.Rowlndex.Cells2.Value.ToString();educati on =this .dataGridView1.Rowse.Rowlndex.Cells4.Value.ToString();admi nisitrator =this .dataGridView1.Rowse.Rowlndex.Cells5.Value.T

27、oString();man egetime =this .dataGridView1.Rowse.Rowlndex.Cells6.Value.ToString();sex =this .dataGridView1.Rowse.Rowlndex.Cells3.Value.ToString();/MessageBox.Show( name+birth+educatio n+admi nisitrat oilman egetime+sex);string sql = string .Format( "select lD from Table_person where PERSON_NAME

28、=N'Oa nd BIRTH=N'1' and ADMINISITRATOR=N'2' and MANEGETIME=N'3"; name, birth, adm ini sitrator, man egetime);/ MessageBox.Show(sql);using ( SqlConnection coon = new SqlConnection (src) "ISqlCommanobmd = new SqlComman(tql, coon);coon. Ope n();using ( SqlDataReader dr

29、 = cmd.ExecuteReader()while (dr.Read()private void skin Butt on _delete_Click(object sen der. Eve ntArgs e)二-if (ID != -1)stri ng sql = "delete from Table_pers on where ID=" +ID.ToStri ng()+""using ( SqlConnection coon = new SqlConnection (src)_|SqlCommanobmd = new SqlComman(tql,

30、coon);coon. Ope n();int n=cmd.ExecuteNonQuery();if (n=1) MessageBoxShow("删除成功!");reshowview();reshow();/foreach (pers on p in list)/ if (p.Admi nisitrator = admi nisitrator && p.Birth = birth &&p.Pers on_n ame = n ame && p.Ma negetime = man egetime)/ / list.Remove(p

31、);/ this.dataGridView1.DataSource = list;else nMessageBoxShow("未选定行!");private void skinButton_rewrite_Click( object sender. EventArgs e) -if (ID != -1)Form_rewrite fr = new Form_rewrite (name, sex, birth, education, toolStripStatusLabel_ name.Text, man egetime, ID);fr.Owner =this ;fr.Show

32、();elseMessageBoxShow("未选定行!");list.Clear();/ this.dataGridView1.DataSource=list;private void skinButton1 search Click(object sender, EventArgs e)stri ng sql = "select * from Table_pers on where 1=1"List <person > listl = new List <person >();/ list1.Clear();if ( this

33、 .textBox1.Text.Trim() !="")sql = sql +" and PERSON_NAMEs N'%"+ this .textBox1.Text.Trim()+ "%'"if ( this .textBox2.Text.Trim() !="")sql= sql + " and CATEGORY_NAME N'%" + this .textBox2.Text.Trim()+ "%'"sql +=""usi

34、ng ( SqlConnection conn = new SqlConnection (src)SqlCommanotmd = new SqlCommandsql, conn);conn. Ope n();using ( SqlDataReader dr = cmd.ExecuteReader()while (dr.Read()person p = new person();p.Person _n ame = dr"PERSON_NAMETbStri ng();p.Category_ name = dr"CATEGORY_NAMEoStri ng();p.Sex = dr

35、"SEX".ToStri ng();string dt = dr "BIRTH".ToString().Split( '');p.Birth = dt0;p.Education = dr"EDUCATION.ToStri ng();p.Admi ni sitrator = dr"ADMINISITRATORJ'.ToStri ng();p.Ma negetime = dr"MANEGETIMEToStri ng();listl.Add(p);this .dataGridViewl.ClearSelec

36、tion();this .dataGridViewl.DataSource = listl;private void skin Butt on _reset_Click(object sen der,Eve ntArgs e)this .textBox1.Text ="”;this .textBox2.Text =""List <person > list1 = new List <person >();this .dataGridView1.DataSource = list1;public void reshowview()List &

37、lt;person > list1 = new List <person >();list1.Clear();this .dataGridView1.DataSource = list1;private void 删除部门 ToolStripMenultem_Click( object sender,EventArgs e)Form_delete fm_delete = new Form_delete (t);fm_delete.Owner =this ;fm_delete.Show();private void 修改单位 ToolStripMenultem_Click( o

38、bject sender,EventArgs e)Form_renamerename = new Form_renamet, t.Text.ToString();rename.Owner =this ;ren ame.Show();4、人员类using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace实验_人事管理系统public class personprivate stri ng pers on_n ame;p

39、ublic str ing Pers on_n ameget retur n pers on_n ame; set person_name =value ; private stri ng category_ name;public stri ng Category_ nameget return category_name; set category_name = value ; privatestri ngbirth;public stri ng Birthget return birth; set birth =value ; privatestri ngsex;public str i

40、ng Sexget return sex; set sex =value; privatestri ngeducati on;public str ingEducati onget return education; set education = value ; private stri ng adm ini sitrator; public str ing Admini sitrator二get return adminisitrator; set adminisitrator = value ; privatestri ng man egetime;public str ing Man

41、egetimeget return manegetime; set manegetime = value ; 5、删除界面using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;using

42、CCWin;namespace实验_人事管理系统public partial class Form_delete : CCSkinMainpublic Form_delete()In itializeComp onen t();public Form_delete( TreeNode no de)In itializeComp onen t();this .t = no de;TreeNode t = new TreeNode();stri ng src =博博实验一一人事管理系统实验一一人事管理系统MyData.mdf;l ntegrated Security=True" ;pri

43、vate void Form_delete_Load( object sender, EventArgs e)private void skin Butt on _sure_Click(object sen der. Eve ntArgs e)if (t != null && t.Parent !=null )if (t.Parent.Tag.ToString() ="0")/ /ox.Show(t.Tag.ToStri ng()+":"+t.Text);stri ng sql1 = "delete from Table_per

44、son where CATEGORY_NUMBERin( select NUMBER from Table_tree where PR_NUMBER in( select NUMBER from Table_tree where NAME=N'"+ t.Text +"');"/ MessageBox.Show(sql1);using ( SqlConnection coon = new SqlConnection (src)_|SqlCommanotmd = new SqlComman(fcql1, coon);coon. Ope n();int

45、n = cmd.ExecuteNonQuery();/ MessageBox.Show(“ 您已经删除了 “ + n.ToString() + "条数据!");stri ng sql2 = "delete from Table_tree where PR_NUMBER in (selectNUMBER from Table_tree where NAME=N'" + t.Text +"');"/ MessageBox.Show(sql2);using ( SqlConnection coon = new SqlConn

46、ection (src)SqlCommanotmd = new SqlCommandsql2, coon);coon. Ope n();int n = cmd.ExecuteNonQuery();/ MessageBox.Show(" 您已经删除了 “ + n.ToString() + "条数据!");stri ng sql3 = "delete from Table_tree where NAME=N'" + t.Text +III.I! ./ MessageBox.Show(sql3);using ( SqlConnection c

47、oon = new SqlConnection (src)SqlCommanafcmd = new SqlCommandsql3, coon);coon. Ope n();int n = cmd.ExecuteNonQuery();/ MessageBox.Show(" 您已经删除了 “ + n.ToString() + "条数据!");elsestring sql4 = "delete from Table_person where CATEGORY_NUM=ER t.Tag+ ""stri ng sql5 = "dele

48、te from Table_tree where NUMBER =" / MessageBox.Show(sql4);+ t.Tag +""using ( SqlConnection coon = new SqlConnection (src)SqlCommanotmd = new SqlComman(fcql4, coon);coon. Ope n();int n = cmd.ExecuteNonQuery();/ MessageBox.Show(“ 您已经删除了 “ + n.ToString() + "SqlCommanotmd1 = new Sql

49、Comman(iql5, coon);条数据! “);int n1 = cmd1.ExecuteNonQuery();/ MessageBox.Show(“ 您已经删除了 “ + n.ToString() + "条数据! “); _lForm_showff = new Form_show();ff = (Form_shoWthis .Owner;ff.reshow();this .Close();private void skin Butt on _giveup_Click(object sen der, Eve ntArgs e)this .Close();5、添加界面(部门,班组

50、)using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;namespace实验_人事管理系统public partial class Form_Add: CCSk inM ainpubli

51、c Form_Add()In itializeComp onen t();public Form_Add( TreeNode t1) 一this .t = t1;In itializeComp onen t();int ID;TreeNode t = new TreeNode();stri ng src =博博实验一一人事管理系统实验一一人事管理系统MyData.mdf;l ntegrated Security=True" ;private void Form_Add_Load(object sender,EventArgs e)private void skin Butt on _

52、add_Click(object sen der,Eve ntArgs e)if ( this .textBox_categoryname.Text !="")string sql =""stri ng sql1 = "select ID from Table_tree where ID=(select MAX(ID) from Table_tree);"using ( SqlConnection conn = new SqlConnection (src)SqlCommanobmd = new SqlComman(tql1, con

53、n);conn. Ope n();SqlDataReader dr = cmd.ExecuteReader();while (dr.Read() ID = (int )dr "ID"/ MessageBox.Show(ID.ToStr in g();MessageBox.Show("添加成功,数据库。"); 1if (t.Tag.ToString() ="0" && t.Parent = null )sql =string .Format( "insert into,ID,ID,Table_tree(NUMB

54、ER,NAME,CATEGORY,PR_NUMBER) values(0,N'1',N'部门',2);" this .textBox_categoryname.Text.Trim(), t.Tag);else if (t.Parent.Tag.ToString() ="0")sql =string .Format( "insert intoTable_tree(NUMBER,NAME,CATEGORY,PR_NUMBER) values(0,N'1',N'班组',2);" this

55、 .textBox_categoryname.Text.Trim(), t.Tag);/ MessageBox.Show(sql);using ( SqlConnection conn = new SqlConnection (src)SqlCommanobmd = new SqlComman(tql, conn);conn. Ope n();|cmd.ExecuteN on Query();MessageBoxShow("添加成功,数据库。");Form_showf1 = new Form_show();f1 = (Form_show this .Owner;f1.res

56、how();this .textBox_categoryname.Text =""this .Close();elseMessageBoxShow("您输入的信息不完整,请重新输入!");6、部门、班组修改using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.SqlClient;namespace实验_人事管理系统public partial class Form_re name: CCSki nM ainpublic Form_rename()In itializeComp onen t();public Form_rename(TreeNode t1, string name1) 一this .t = t1;this .name = name1;In itializeComp onen t();Tr

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论