C#实验报告(人事管理系统)_第1页
C#实验报告(人事管理系统)_第2页
C#实验报告(人事管理系统)_第3页
C#实验报告(人事管理系统)_第4页
C#实验报告(人事管理系统)_第5页
免费预览已结束,剩余26页可下载查看

下载本文档

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

文档简介

1、C蚊验报告(人事管理系统)学号149074353姓名程裕博班级物141指导教师夏敏 一安徽工业大学计算机学院2016年12月,登录时进行判断,根据不同的错误信息进行报错,如先设置一个登录界面(连接数据库)密码错误。登陆成功后,进入主界面。主界面通过树和表格来显示数据。可以对人员,班组,部门进行增删改查操作,数据保存在数据库中。二.程序源码1.数据库表结构,FMU)山工 dbom_|IB3US册保朋U* 泥* uWEE蛹同强的RiAM>RWrtflirl物*muCillGORV MJWfflEREIIMKaTOMnrant*Hr2TUQbACMiwyTMTEE3mnrrarrw)ElrFF

2、T!TribG« RrasnlD>IfflUCJRiTr '1. J) WT KLL.呼WilF电*KH啕产用ULLCAHECFS HdlEj布由ZE1E 50:9DT KLL,即而MCHJU 加JT PULLlUffl府5fK嘲-4)S一I1LLCAITXKJUBEPJJT IXLfltrniTluilKlPfTHU 1”、HT HLLfa-IB |0MH7K E G931电 笥时|»2、登录界面using System;using System.Collections.Generic;using System.ComponentModel;using Sy

3、stem.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 : CCSkinMain public Form_login() InitializeComponent();string src =博博实验一一人事管理系统实验一一人事管理

4、系统MyData.mdf;Integrated Security=True" ;private void Form1_Load( object sender, EventArgs e) private void button_login_Click( object sender, EventArgs e) string user = this .skinTextBox.Text;string password = this .skinTextBox2.Text;int sign1 = 0;int sign2 = 0;if (user ="" | password

5、="")MessageBoxShow("您输入的数据不完整!");else string sql1 = string .Format( "select USERNAME from Table_login where USERNAME=N'0'", user);using ( SqlConnection coon = new SqlConnection (src)SqlCommanotmd = new SqlCommandsql1, coon);coon.Open();using ( SqlDataReader dr =

6、 cmd.ExecuteReader() while (dr.Read() sign1+; if (signl = 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 = new

7、 SqlCommandsql2, coon); coon.Open();using ( SqlDataReader dr = cmd.ExecuteReader() while (dr.Read() if (password = dr "PASSWORDToString() sign2+; if (sign1 != 0 && sign2 = 0)|MessageBoxShow("您的密码输入错误!");if (sign2 != 0) Form_showf1 = new Form_shovwuser,this );f1.Show(); this .V

8、isible = 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实验_人事

9、管理系统 public partial class Form_show: Form public Form_show()InitializeComponent();public Form_show(string name1, Form_login f)login_name=name1;fl = f;InitializeComponent(); string login_name= "xx" Form_login fl = null ;TreeNode t = new TreeNode();int ID=-1;public Listperson > list = new

10、 Listperson >(); string name;string birth;string sex;string education;string adminisitrator;string manegetime;博博/ string category_name; string src =实验一一人事管理系统实验一一人事管理系统MyData.mdf;Integrated Security=True"private void Form_show_Load(object sender, EventArgs e) toolStripStatusLabel_name.Text =

11、"管理员:"+ this .login_name;toolStripStatusLabel_time.Text ="登录时间:"+DateTime.Now.ToLongTimeString(); Addparent(); this .dataGridView1.ClearSelection(); private void toolStripStatusLabel_name_Click( object sender, EventArgs e) private void Form_show_FormClosed(object sender, FormClos

12、edEventArgs e) fl.Close(); public void Addparent()string sql = "select * from Table tree where PR NUMBER=-1"using ( SqlConnection coon = new SqlConnection (src)SqlCommanotmd = new SqlCommandsql, coon);coon.Open();using ( SqlDataReader dr = cmd.ExecuteReader() while (dr.Read() string name =

13、 dr "NAME.ToString();string number = dr "NUMBER.ToString(); |/ string category=dr"CATEGORY".ToString(); TreeNode tn = new TreeNode();tn.Text = name;tn.Tag = number;tn.ImageIndex = 1;AddChild(number, tn);treeView_jiegou.Nodes.Add(tn);/ skinTreeView1.Nodes.Add(tn);private void AddC

14、hild( string pnumber, TreeNode pnode) if ( Convert .ToInt32(pnode.Tag) = 0 | (pnode.Parent!= null &&Convert .ToInt32(pnode.Parent.Tag) = 0)string sql = "select * from Table_tree where PR_NUMBER=" + pnumber + "order by NAME desc;"using ( SqlConnection conn = new SqlConnect

15、ion (src) SqlCommanotmd = new SqlCommandsql, conn);conn.Open();using ( SqlDataReader dr = cmd.ExecuteReader() while (dr.Read() string name = dr "NAME.ToString(); |string number = dr "NUMBER.ToString();/ string category = dr"CATEGORY".ToString();TreeNode tn = new TreeNode();tn.Tex

16、t = name;tn.Tag = number;tn.ImageIndex = 1;AddChild(number, tn);pnode.Nodes.Add(tn); else string sql = "select * from Table_tree where PR_NUMBER=" + pnumber + "order by NAME desc;"using ( SqlConnection conn = new SqlConnection (src) SqlCommanotmd = new SqlCommandsql, conn);conn.O

17、pen();using ( SqlDataReader dr = cmd.ExecuteReader() while (dr.Read()string name = dr "NAME.ToString(); |string number = dr "NUMBER.ToString(); |/ string category = dr"CATEGORY".ToString(); TreeNode tn = new TreeNode();tn.Text = name;tn.Tag = number;tn.ImageIndex = 0;AddChild(num

18、ber, tn);pnode.Nodes.Add(tn);|private void skinButton add Click(object sender, EventArgs e) / 无用的按钮private void skinButton add Click 1(object sender, EventArgs e)/MessageBox.Show("添力口!");if (t.Parent.Parent!= null && t.Parent!= null ) Form_Addperson fp = newForm_Addperson(t, toolSt

19、ripStatusLabel_name.Text, DateTime.Now.ToString();fp.Owner =this ;fp.Show();list.Clear();elseMessageBoxShow("请到班组添加人员!");/ reshow();private void treeView_jiegou_AfterSelect( object sender, TreeViewEventArgs e) string sql = "select * from Table_person where CATEGORY_NUMBER=".Node.

20、Tag; List <person > list = new Listperson >();using ( SqlConnection conn = new SqlConnection (src) SqlCommandtmd = new SqlCommandsql, conn); conn.Open(); using ( SqlDataReader dr = cmd.ExecuteReader() while (dr.Read()person p = new person。; p.Person_name = dr"PERSON_NAMETbString();p.Ca

21、tegory_name = dr"CATEGORY_NAMEoString();p.Sex = dr"SEX".ToString();string 口dt=dr "BIRTH".ToString().Split( '');p.Birth = dt0;p.Education = dr"EDUCATION.ToString();p.Adminisitrator = dr"ADMINISITRATOR"ToString();p.Manegetime=dr"MANEGETIMEToString()

22、;list.Add(p);this .dataGridView1.ClearSelection();this .dataGridView1.DataSource = list;ID = -1;private void 添加部门 ToolStripMenuItem_Click( object sender, EventArgs e) if (t.Parent = null | t.Parent.Parent = null )Form_Addfa =new Form_AdQt);fa.Owner =this ;fa.Show(); else Form_Addperson fp = newForm_

23、Addperson(t, toolStripStatusLabel_name.Text, DateTime.Now.ToString();fp.Owner =this ;fp.Show();list.Clear();this .dataGridView1.DataSource = list;private void treeView_jiegou_NodeMouseClick( object sender, TreeNodeMouseClickEventArgs e) this .t = e.Node;/ MessageBox.Show(t.Name); public void reshow(

24、) treeView_jiegou.Nodes.Clear();Addparent();private void dataGridView1_CellClick( object sender, DataGridViewCellEventArgs e) /string name;/string birth; |/string education;/string adminisitrator;/string manegetime;if (e.RowIndex != -1)name =this .dataGridView1.Rowse.RowIndex.Cells0.Value.ToString()

25、;birth =this .dataGridView1.Rowse.RowIndex.Cells2.Value.ToString();education =this .dataGridView1.Rowse.RowIndex.Cells4.Value.ToString();adminisitrator =this .dataGridView1.Rowse.RowIndex.Cells5.Value.ToString();manegetime =this .dataGridView1.Rowse.RowIndex.Cells6.Value.ToString();sex =this .dataGr

26、idView1.Rowse.RowIndex.Cells3.Value.ToString();MessageBox.Show(name+birth+education+adminisitrator+manegetime+sex);string sql = string .Format( "select ID from Table_person where PERSON_NAME=N'0a nd BIRTH=N'1' and ADMINISITRATOR=N'2' and MANEGETIME=N'3'", name,

27、birth, adminisitrator, manegetime);/ MessageBox.Show(sql);using ( SqlConnection coon = new SqlConnection (src) SqlCommanotmd = new SqlCommandsql, coon);coon.Open();using ( SqlDataReader dr = cmd.ExecuteReader() while (dr.Read()int )dr "ID"ID =(private void skinButton_delete_Click( object s

28、ender, EventArgs e)if (ID != -1) string sql = "delete from Table_person where ID=" +ID.ToString()+ "" using ( SqlConnection coon = new SqlConnection (src)SqlCommanotmd = new SqlCommandsql,coon);coon.Open();int n=cmd.ExecuteNonQuery(); | if (n=1)MessageBoxShow("删除成功!");r

29、eshowview();reshow(); /foreach (person p in list) | / if (p.Adminisitrator = adminisitrator && p.Birth = birth && p.Person_name = name && p.Manegetime = manegetime)/ / list.Remove(p);/ /this.dataGridView1.DataSource = list;elseMessageBoxShow("未选定行!");private void sk

30、inButton_rewrite_Click( object sender, EventArgs e) if (ID != -1) Form_rewrite fr = new Form_rewrite (name, sex, birth, education, toolStripStatusLabel_name.Text, manegetime, ID);fr.Owner =this ;fr.Show(); else MessageBoxShow("未选定行!"); /list.Clear(); / this.dataGridView1.DataSource=list;pr

31、ivate void skinButton1 search Click(object sender, EventArgs e)string sql = "select * from Table_person where 1=1"List <person > listl = new List <person >();/list1.Clear(); if ( this .textBox1.Text.Trim() !="")sql = sql +" and PERSON_NAMke N'%" + this .

32、textBox1.Text.Trim()+ "%'"if ( this .textBox2.Text.Trim() !="")sql= sql + " and CATEGORY_NAikE N'%" + this .textBox2.Text.Trim()+ "%'"sql +=""using ( SqlConnection conn = new SqlConnection (src) SqlCommanotmd = new SqlCommandsql, conn);co

33、nn.Open(); using ( SqlDataReader dr = cmd.ExecuteReader() while (dr.Read() person p = new person ();p.Person_name = dr"PERSON_NAMETbString();p.Category_name = dr"CATEGORY_NAMEoString();p.Sex = dr"SEX".ToString();string 口 dt = dr "BIRTH".ToString().Split( ''); p.

34、Birth = dt0; p.Education = dr"EDUCATION.ToString();p.Adminisitrator = dr"ADMINISITRATOR"ToString();p.Manegetime = dr"MANEGETIMEToString();listl.Add(p);this .dataGridView1.ClearSelection();this .dataGridViewl.DataSource = listl;private void skinButton_reset_Click( object sender, E

35、ventArgs e) this .textBox1.Text =""this .textBox2.Text =""Listperson > list1 = new List person >();this .dataGridViewl.DataSource = listl;public void reshowview()List <person > listl = new List <person >();list1.Clear();this .dataGridViewl.DataSource = listl;pri

36、vate void 删除部门 ToolStripMenuItem_Click( object sender, EventArgs e) Form_delete fm_delete = new Form_delete (t);fm_delete.Owner =this ;fm_delete.Show();private void 彳修改单位 ToolStripMenuItem_Click( object sender, EventArgs e) Form_renamerename = new Form_renamet, t.Text.ToString();rename.Owner =this ;

37、rename.Show();4、人员类using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace实验_人事管理系统public class personprivate string person_name;public string Person_nameget return person_name; set person_name = value ; private string category_name;pu

38、blic string Category_nameget return category_name; set category_name = value ; private string birth;public string Birth |get return birth; set birth = value ; private string sex; |public string Sexget return sex; set sex = value ; private string education;public string Educationget return education;

39、 set education = value ; private string adminisitrator;public string Adminisitrator二 get return adminisitrator; set adminisitrator = value ; private string manegetime; public string Manegetime get return manegetime; set manegetime = value ; 5、删除界面 using System; using System.Collections.Generic; usin

40、g 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 CCWin;namespace实验_人事管理系统 public partial class Form_delete : CCSkinMain public Form_delete() InitializeCompone

41、nt();public Form_delete( TreeNode node) InitializeComponent(); this .t = node; TreeNode t = new TreeNode();string src =博博实验一一人事管理系统实验一一人事管理系统MyData.mdf;Integrated Security=True" ;private void Form_delete_Load( object sender, EventArgs e)private void skinButton_sure_Click( object sender, EventAr

42、gs e) if (t != null && t.Parent != null ) if (t.Parent.Tag.ToString() ="0")/ox.Show(t.Tag.ToString()+":"+t.Text);string sql1 = "delete from Table_person where CATEGORY_NUMBER in(select NUMBER from Table_tree where PR_NUMBER in(select NUMBER from Table_tree where NAME

43、=N'"+ t.Text +"');"/ MessageBox.Show(sql1);using ( SqlConnection coon = new SqlConnection (src) SqlCommanotmd = new SqlCommandsql1, coon);coon.Open();int n = cmd.ExecuteNonQuery();/ MessageBox.Show(" 您已经删除了 " + n.ToString() + "条数据!");string sql2 = "del

44、ete from Table_tree where PR_NUMBER in(select NUMBER from Table_tree where NAME=N'" + t.Text +"');"/ MessageBox.Show(sql2);using ( SqlConnection coon = new SqlConnection (src) SqlCommanotmd = new SqlCommandsql2, coon);coon.Open();int n = cmd.ExecuteNonQuery();/ MessageBox.Show

45、(" 您已经删除了 " + n.ToString() + "条数据!");string sql3 = "delete from Table_tree where NAME=N'" + t.Text + '";"; ;/ MessageBox.Show(sql3);using ( SqlConnection coon = new SqlConnection (src)SqlCommanacmd = new SqlCommandsql3, coon);coon.Open();int n = cmd.Ex

46、ecuteNonQuery();/ MessageBox.Show(" 您已经删除了 " + n.ToString() + "条数据!");elsestring sql4 = "delete from Table_person where CATEGORY_NUM=ER t.Tag+ ,.,. ; ;string sql5 = "delete from Table_tree where NUMBER ="+ t.Tag +""/ MessageBox.Show(sql4);using ( SqlConne

47、ction coon = new SqlConnection (src) SqlCommanotmd = new SqlCommandsql4, coon);coon.Open();int n = cmd.ExecuteNonQuery();/ MessageBox.Show(" 您已经删除了 " + n.ToString() + "条数据!");SqlCommanotmd1 = new SqlComman(sql5, coon);int n1 = cmd1.ExecuteNonQuery();/ MessageBox.Show(" 您已经删除

48、了 " + n.ToString() + "条数据!"); Form_showff = new Form_show); ff = (Form_shovw this .Owner;ff.reshow();this .Close();private void skinButton_giveup_Click( object sender, EventArgs e)this .Close();5、添加界面(部门,班组)using System;using System.Collections.Generic;using System.ComponentModel;usin

49、g 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_Add: CCSkinMainpublic Form_Add()InitializeComponent();public Form_Add( TreeNode t1)this .

50、t = t1;InitializeComponent();int ID;TreeNode t = new TreeNode();string src =博博实验一一人事管理系统实验一一人事管理系统MyData.mdf;Integrated Security=True" ;private void Form_Add_Load(object sender, EventArgs e)private void skinButton_add_Click( object sender, EventArgs e)if ( this .textBox_categoryname.Text !=&quo

51、t;")string sql = ""string sql1 = "select ID from Table_tree where ID=(select MAX(ID) from Table_tree);"using ( SqlConnection conn = new SqlConnection (src)SqlCommanotmd = new SqlCommandsql1, conn); |conn.Open();SqlDataReader dr = cmd.ExecuteReader();while (dr.Read()ID = (int

52、 )dr "ID"/ MessageBox.Show(ID.ToString();/MessageBox.Show("添加成功,数据库。"); if (t.Tag.ToString() ="0" && t.Parent = null )sql =string .Format( "insert into,ID,ID,Table_tree(NUMBER,NAME,CATEGORY,PR_NUMBER) values(0,N'1',N'部门',2);” this .textBox_c

53、ategoryname.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 .textBox_categoryname.Text.Trim(), t.Tag);/ MessageBox.Show(sql);using ( SqlConnection conn =

54、 new SqlConnection (src) SqlCommandcmd = new SqlCommandsql, conn);conn.Open();|cmd.ExecuteNonQuery(); MessageBoxShow("添力口成功,数据库。"); Form_showf1 = new Form_show();fl = (Form_shoW this .Owner;f1.reshow();this .textBox_categoryname.Text =""this .Close(); else MessageBoxShow("您输

55、入的信息不完整,请重新输入!");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;using CCWin;namespace实验_人事管理系统public

56、 partial class Form_rename: CCSkinMain public Form_rename()InitializeComponent();public Form_rename(TreeNode t1, string namel) this .t = t1;this .name = name1;InitializeComponent();TreeNode t = new TreeNode();string name;string src =博博实验一一人事管理系统实验一一人事管理系统MyData.mdf;Integrated Security=True;MultipleA

57、ctiveResultSets=true"private void Form_rename_Load(object sender, EventArgs e) this .textBox_name.Text = name; private void skinButton_rename_Click( object sender, EventArgs e) if ( this .textBox_name.Text.Trim() !="")string sql = "update Table_tree setNAME=N'+this .textBox_name.Text.Trim()+ "' where NUMBER="+t.Tag+”;"using ( SqlConnection coon= new SqlConnection (src) SqlCommanotmd = new Sql

温馨提示

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

评论

0/150

提交评论