C#实验报告人事管理系统.docx
《C#实验报告人事管理系统.docx》由会员分享,可在线阅读,更多相关《C#实验报告人事管理系统.docx(40页珍藏版)》请在冰豆网上搜索。
![C#实验报告人事管理系统.docx](https://file1.bdocx.com/fileroot1/2023-4/21/c63cd895-7f5e-4b8c-a310-e4dab9b907b0/c63cd895-7f5e-4b8c-a310-e4dab9b907b01.gif)
C#实验报告人事管理系统
C#实验报告
(人事管理系统)
学号
149074353
姓名
程裕博
班级
物141
指导教师
夏敏
工业大学计算机学院
2016年12月
一.程序步骤
先设置一个登录界面(连接数据库),登录时进行判断,根据不同的错误信息进行报错,如密码错误。
登陆成功后,进入主界面。
主界面通过树和表格来显示数据。
可以对人员,班组,部门进行增删改查操作,数据保存在数据库中。
二.程序源码
1.数据库表结构
2、登录界面
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Windows.Forms;
usingCCWin;
usingSystem.Data.SqlClient;
namespace实验__人事管理系统
{
publicpartialclassForm_login:
CCSkinMain
{
publicForm_login()
{
InitializeComponent();
}
stringsrc=@"DataSource=(LocalDB)\v11.0;AttachDbFilename=c:
\users\博博\documents\visualstudio2013\Projects\实验——人事管理系统\实验——人事管理系统\MyData.mdf;IntegratedSecurity=True";
privatevoidForm1_Load(objectsender,EventArgse)
{
}
privatevoidbutton_login_Click(objectsender,EventArgse)
{
stringuser=this.skinTextBox.Text;
stringpassword=this.skinTextBox2.Text;
intsign1=0;
intsign2=0;
if(user==""||password=="")
MessageBox.Show("您输入的数据不完整!
");
else
{
stringsql1=string.Format("selectUSERNAMEfrom[Table_login]whereUSERNAME=N'{0}';",user);
using(SqlConnectioncoon=newSqlConnection(src))
{
SqlCommandcmd=newSqlCommand(sql1,coon);
coon.Open();
using(SqlDataReaderdr=cmd.ExecuteReader())
{
while(dr.Read())
{
sign1++;
}
}
}
if(sign1==0)
MessageBox.Show("未查询到您的用户信息!
");
if(sign1!
=0)
{
stringsql2=string.Format("selectPASSWORDfrom[Table_login]whereUSERNAME=N'{0}';",user);
using(SqlConnectioncoon=newSqlConnection(src))
{
SqlCommandcmd=newSqlCommand(sql2,coon);
coon.Open();
using(SqlDataReaderdr=cmd.ExecuteReader())
{
while(dr.Read())
{
if(password==dr["PASSWORD"].ToString())
sign2++;
}
}
}
}
if(sign1!
=0&&sign2==0)
MessageBox.Show("您的密码输入错误!
");
if(sign2!
=0)
{
Form_showf1=newForm_show(user,this);
f1.Show();
this.Visible=false;
}
}
}
}
}
3、主界面
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Windows.Forms;
usingSystem.Timers;
usingSystem.Data.SqlClient;
usingCCWin;
namespace实验__人事管理系统
{
publicpartialclassForm_show:
Form
{
publicForm_show()
{
InitializeComponent();
}
publicForm_show(stringname1,Form_loginf)
{
login_name=name1;
fl=f;
InitializeComponent();
}
stringlogin_name="xx";
Form_loginfl=null;
TreeNodet=newTreeNode();
intID=-1;
publicListlist=newList();
stringname;
stringbirth;
stringsex;
stringeducation;
stringadminisitrator;
stringmanegetime;
//stringcategory_name;
stringsrc=@"DataSource=(LocalDB)\v11.0;AttachDbFilename=c:
\users\博博\documents\visualstudio2013\Projects\实验——人事管理系统\实验——人事管理系统\MyData.mdf;IntegratedSecurity=True";
privatevoidForm_show_Load(objectsender,EventArgse)
{
toolStripStatusLabel_name.Text="管理员:
"+this.login_name;
toolStripStatusLabel_time.Text="登录时间:
"+DateTime.Now.ToLongTimeString();
Addparent();
this.dataGridView1.ClearSelection();
}
privatevoidtoolStripStatusLabel_name_Click(objectsender,EventArgse)
{
}
privatevoidForm_show_FormClosed(objectsender,FormClosedEventArgse)
{
fl.Close();
}
publicvoidAddparent()
{
stringsql="select*from[Table_tree]wherePR_NUMBER=-1";
using(SqlConnectioncoon=newSqlConnection(src))
{
SqlCommandcmd=newSqlCommand(sql,coon);
coon.Open();
using(SqlDataReaderdr=cmd.ExecuteReader())
{
while(dr.Read())
{
stringname=dr["NAME"].ToString();
stringnumber=dr["NUMBER"].ToString();
//stringcategory=dr["CATEGORY"].ToString();
TreeNodetn=newTreeNode();
tn.Text=name;
tn.Tag=number;
tn.ImageIndex=1;
AddChild(number,tn);
treeView_jiegou.Nodes.Add(tn);
//skinTreeView1.Nodes.Add(tn);
}
}
}
}
privatevoidAddChild(stringpnumber,TreeNodepnode)
{
if(Convert.ToInt32(pnode.Tag)==0||(pnode.Parent!
=null&&Convert.ToInt32(pnode.Parent.Tag)==0))
{
stringsql="select*from[Table_tree]wherePR_NUMBER="+pnumber+"orderbyNAMEdesc;";
using(SqlConnectionconn=newSqlConnection(src))
{
SqlCommandcmd=newSqlCommand(sql,conn);
conn.Open();
using(SqlDataReaderdr=cmd.ExecuteReader())
{
while(dr.Read())
{
stringname=dr["NAME"].ToString();
stringnumber=dr["NUMBER"].ToString();
//stringcategory=dr["CATEGORY"].ToString();
TreeNodetn=newTreeNode();
tn.Text=name;
tn.Tag=number;
tn.ImageIndex=1;
AddChild(number,tn);
pnode.Nodes.Add(tn);
}
}
}
}
else
{
stringsql="select*from[Table_tree]wherePR_NUMBER="+pnumber+"orderbyNAMEdesc;";
using(SqlConnectionconn=newSqlConnection(src))
{
SqlCommandcmd=newSqlCommand(sql,conn);
conn.Open();
using(SqlDataReaderdr=cmd.ExecuteReader())
{
while(dr.Read())
{
stringname=dr["NAME"].ToString();
stringnumber=dr["NUMBER"].ToString();
//stringcategory=dr["CATEGORY"].ToString();
TreeNodetn=newTreeNode();
tn.Text=name;
tn.Tag=number;
tn.ImageIndex=0;
AddChild(number,tn);
pnode.Nodes.Add(tn);
}
}
}
}
}
privatevoidskinButton_add_Click(objectsender,EventArgse)//无用的按钮
{
}
privatevoidskinButton_add_Click_1(objectsender,EventArgse)
{
//MessageBox.Show("添加!
");
if(t.Parent.Parent!
=null&&t.Parent!
=null)
{
Form_Addpersonfp=newForm_Addperson(t,toolStripStatusLabel_name.Text,DateTime.Now.ToString());
fp.Owner=this;
fp.Show();
list.Clear();
}
else
MessageBox.Show("请到班组添加人员!
");
//reshow();
}
privatevoidtreeView_jiegou_AfterSelect(objectsender,TreeViewEventArgse)
{
stringsql="select*fromTable_personwhereCATEGORY_NUMBER="+e.Node.Tag;
Listlist=newList();
using(SqlConnectionconn=newSqlConnection(src))
{
SqlCommandcmd=newSqlCommand(sql,conn);
conn.Open();
using(SqlDataReaderdr=cmd.ExecuteReader())
{
while(dr.Read())
{
personp=newperson();
p.Person_name=dr["PERSON_NAME"].ToString();
p.Category_name=dr["CATEGORY_NAME"].ToString();
p.Sex=dr["SEX"].ToString();
string[]dt=dr["BIRTH"].ToString().Split('');
p.Birth=dt[0];
p.Education=dr["EDUCATION"].ToString();
p.Adminisitrator=dr["ADMINISITRATOR"].ToString();
p.Manegetime=dr["MANEGETIME"].ToString();
list.Add(p);
}
}
this.dataGridView1.ClearSelection();
this.dataGridView1.DataSource=list;
ID=-1;
}
}
privatevoid添加部门ToolStripMenuItem_Click(objectsender,EventArgse)
{
if(t.Parent==null||t.Parent.Parent==null)
{
Form_Addfa=newForm_Add(t);
fa.Owner=this;
fa.Show();
}
else
{
Form_Addpersonfp=newForm_Addperson(t,toolStripStatusLabel_name.Text,DateTime.Now.ToString());
fp.Owner=this;
fp.Show();
list.Clear();
this.dataGridView1.DataSource=list;
}
}
privatevoidtreeView_jiegou_NodeMouseClick(objectsender,TreeNodeMouseClickEventArgse)
{
this.t=e.Node;
//MessageBox.Show(t.Name);
}
publicvoidreshow()
{
treeView_jiegou.Nodes.Clear();
Addparent();
}
privatevoiddataGridView1_CellClick(objectsender,DataGridViewCellEventArgse)
{
//stringname;
//stringbirth;
////stringeducation;
//stringadminisitrator;
//stringmanegetime;
if(e.RowIndex!
=-1)
{
name=this.dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
birth=this.dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
education=this.dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
adminisitrator=this.dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
manegetime=this.dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
sex=this.dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
//MessageBox.Show(name+birth+education+adminisitrator+manegetime+sex);
stringsql=string.Format("selectIDfromTable_personwherePERSON_NAME=N'{0}'andBIRTH=N'{1}'andADMINISITRATOR=N'{2}'andMANEGETIME=N'{3}'",name,birth,adminisitrator,manegetime);
//MessageBox.Show(sql);
using(SqlConnectioncoon=newSqlConnection(src))
{
SqlCommandcmd=newSqlCommand(sql,coon);
coon.Open();
using(SqlDataReaderdr=cmd.ExecuteReader())
{
while(dr.Read())
{
ID=(int)dr["ID"];
}
}
}
}
}
privatevoidskinButton_delete_Click(objectsender,EventArgse)
{
if(ID!
=-1)
{
stringsql="deletefromTable_personwhereID="+ID.ToString()+";";
using(SqlConnectioncoon=newSqlConnection(src))
{
SqlCommandcmd=newSqlCommand(sql,coon);
coon.Open();
intn=cmd.ExecuteNonQuery();
if(n==1)
{
MessageBox.Show("删除成功!
");
reshowview();
reshow();
}
//foreach(personpinlist)
//{
//if(p.Adminisitrator==adminisitrator&&p.Birth==birth&&p.Person_name==name&&p.Manegetime==manegetime)
//{
//list.Remove(p);
//}
//}
//this.dataGridView1.DataSource=list;
}
}
else
{
MessageBox.Show("未选定行!
");
}
}
privatevoidskinButton_rewrite_Click(objectsender,EventArgse)
{
if(ID!
=-1)
{
Form_rewritefr=newForm_rewrite(name,sex,birth,education,toolStripStatusLabel_name.Text,manegetime,ID);
fr.Owner=this;
fr.Show();
}
else
MessageBox.Show("未选定行!
");
//list.Clear();
//this.dataGridView1.DataSource=list;
}
privatevoidskinButton1_search_Click(objectsender,EventArgse)
{
stringsql="select*fromTable_personwhere1=1";
Listlist1=newList();
//list1.Clear();
if(this.textBox1.Text.Trim()!
="")
sql=sql+"andPERSON_NAMElikeN'%"+this.textBox1.Text.Trim()+"%'";
if(th