1、C#实验报告人事管理系统C#实验报告(人事管理系统)学 号149074353姓 名程裕博班 级物141指导教师夏敏工业大学计算机学院2016年12月一程序步骤先设置一个登录界面(连接数据库),登录时进行判断,根据不同的错误信息进行报错,如密码错误。登陆成功后,进入主界面。主界面通过树和表格来显示数据。可以对人员,班组,部门进行增删改查操作,数据保存在数据库中。二程序源码1.数据库表结构2、登录界面using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy
2、stem.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 = Data Source=(LocalDB)v11.0;AttachD
3、bFilename=c:users博博documentsvisual studio 2013Projects实验人事管理系统实验人事管理系统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; in
4、t sign1 = 0; int sign2 = 0; if (user = | password = ) MessageBox.Show(您输入的数据不完整!); else string sql1 = string.Format(select USERNAME from Table_login where USERNAME=N0;, user); using (SqlConnection coon = new SqlConnection(src) SqlCommand cmd = new SqlCommand(sql1, coon); coon.Open(); using (SqlDataR
5、eader dr = cmd.ExecuteReader() while (dr.Read() sign1+; if (sign1 = 0) MessageBox.Show(未查询到您的用户信息!); if (sign1 != 0) string sql2 = string.Format(select PASSWORD from Table_login where USERNAME=N0;, user); using (SqlConnection coon = new SqlConnection(src) SqlCommand cmd = new SqlCommand(sql2, coon);
6、 coon.Open(); using (SqlDataReader dr = cmd.ExecuteReader() while (dr.Read() if (password = drPASSWORD.ToString() sign2+; if (sign1 != 0 & sign2 = 0) MessageBox.Show(您的密码输入错误!); if (sign2 != 0) Form_show f1 = new Form_show(user, this); f1.Show(); this.Visible = false; 3、主界面using System;using System.
7、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 实验_人事管理系统 public partial class Form_show : Form pub
8、lic 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 List list = new List(); string name; string birth; string sex; string educati
9、on; string adminisitrator; string manegetime; / string category_name; string src = Data Source=(LocalDB)v11.0;AttachDbFilename=c:users博博documentsvisual studio 2013Projects实验人事管理系统实验人事管理系统MyData.mdf;Integrated Security=True; private void Form_show_Load(object sender, EventArgs e) toolStripStatusLabel
10、_name.Text = 管理员: + 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, FormClosedEventAr
11、gs e) fl.Close(); public void Addparent() string sql = select * from Table_tree where PR_NUMBER=-1; using (SqlConnection coon = new SqlConnection(src) SqlCommand cmd = new SqlCommand(sql, coon); coon.Open(); using (SqlDataReader dr = cmd.ExecuteReader() while (dr.Read() string name = drNAME.ToString
12、(); string number = drNUMBER.ToString(); / string category=drCATEGORY.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 AddChild(string pnumber, TreeNode pnode
13、) 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 SqlConnection(src) SqlCommand cmd = new SqlCommand(sql, conn); conn.Open(); using
14、 (SqlDataReader dr = cmd.ExecuteReader() while (dr.Read() string name = drNAME.ToString(); string number = drNUMBER.ToString(); / string category = drCATEGORY.ToString(); TreeNode tn = new TreeNode(); tn.Text = name; tn.Tag = number; tn.ImageIndex = 1; AddChild(number, tn); pnode.Nodes.Add(tn); else
15、 string sql = select * from Table_tree where PR_NUMBER= + pnumber + order by NAME desc; using (SqlConnection conn = new SqlConnection(src) SqlCommand cmd = new SqlCommand(sql, conn); conn.Open(); using (SqlDataReader dr = cmd.ExecuteReader() while (dr.Read() string name = drNAME.ToString(); string n
16、umber = drNUMBER.ToString(); / string category = drCATEGORY.ToString(); TreeNode tn = new TreeNode(); tn.Text = name; tn.Tag = number; tn.ImageIndex = 0; AddChild(number, tn); pnode.Nodes.Add(tn); private void skinButton_add_Click(object sender, EventArgs e)/无用的按钮 private void skinButton_add_Click_1
17、(object sender, EventArgs e) /MessageBox.Show(添加!); if (t.Parent.Parent!=null & t.Parent!=null) Form_Addperson fp = new Form_Addperson(t, toolStripStatusLabel_name.Text, DateTime.Now.ToString(); fp.Owner = this; fp.Show(); list.Clear(); else MessageBox.Show(请到班组添加人员!); / reshow(); private void treeV
18、iew_jiegou_AfterSelect(object sender, TreeViewEventArgs e) string sql = select * from Table_person where CATEGORY_NUMBER= + e.Node.Tag; List list = new List(); using (SqlConnection conn = new SqlConnection(src) SqlCommand cmd = new SqlCommand(sql, conn); conn.Open(); using (SqlDataReader dr = cmd.Ex
19、ecuteReader() while (dr.Read() person p = new person(); p.Person_name = drPERSON_NAME.ToString(); p.Category_name = drCATEGORY_NAME.ToString(); p.Sex = drSEX.ToString(); string dt=drBIRTH.ToString().Split( ); p.Birth = dt0; p.Education = drEDUCATION.ToString(); p.Adminisitrator = drADMINISITRATOR.To
20、String(); p.Manegetime=drMANEGETIME.ToString(); 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_Add fa = new Form_Add(t); fa.Owner
21、= this; fa.Show(); else Form_Addperson fp = new Form_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
22、= e.Node; / MessageBox.Show(t.Name); public void reshow() 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) nam
23、e = this.dataGridView1.Rowse.RowIndex.Cells0.Value.ToString(); 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.dataG
24、ridView1.Rowse.RowIndex.Cells6.Value.ToString(); sex = this.dataGridView1.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=N0 and BIRTH=N1 and ADMINISITRATOR=N2 and M
25、ANEGETIME=N3, name, birth, adminisitrator, manegetime); / MessageBox.Show(sql); using (SqlConnection coon = new SqlConnection(src) SqlCommand cmd = new SqlCommand(sql, coon); coon.Open(); using (SqlDataReader dr = cmd.ExecuteReader() while (dr.Read() ID = (int)drID; private void skinButton_delete_Cl
26、ick(object sender, EventArgs e) if (ID != -1) string sql = delete from Table_person where ID=+ID.ToString()+; using (SqlConnection coon = new SqlConnection(src) SqlCommand cmd = new SqlCommand(sql,coon); coon.Open(); int n=cmd.ExecuteNonQuery(); if(n=1) MessageBox.Show(删除成功!); reshowview(); reshow()
27、; /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; else MessageBox.Show(未选定行!); private void skinButton_rewrite_Click(object sender, EventArgs e)
28、if (ID != -1) Form_rewrite fr = new Form_rewrite(name, sex, birth, education, toolStripStatusLabel_name.Text, manegetime, ID); fr.Owner = this; fr.Show(); else MessageBox.Show(未选定行!); /list.Clear(); / this.dataGridView1.DataSource=list; private void skinButton1_search_Click(object sender, EventArgs e) string sql = select * from Table_person where 1=1; List list1 = new List(); / list1.Clear(); if (this.textBox1.Text.Trim() != ) sql = sql + and PERSON_NAME like N% + this.textBox1.Text.Trim()+ %; if (th
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1