2022年C#实验报告 .pdf
《2022年C#实验报告 .pdf》由会员分享,可在线阅读,更多相关《2022年C#实验报告 .pdf(29页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、C#实验报告(人事管理系统)学号149074353 姓名程裕博班级物 141 指导教师夏敏安徽工业大学计算机学院2016 年 12 月名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 29 页 - - - - - - - - - 一程序步骤先设置一个登录界面(连接数据库),登录时进行判断,根据不同的错误信息进行报错,如密码错误。 登陆成功后, 进入主界面。 主界面通过树和表格来显示数据。可以对人员, 班组,部门进行增删改查操作,数据保存在数据库中。二程序源码1.数据库表结构
2、名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 29 页 - - - - - - - - - 2、登录界面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;
3、 using System.Windows.Forms; using CCWin; using System.Data.SqlClient; namespace 实验_人事管理系统 publicpartialclassForm_login : CCSkinMain public Form_login() InitializeComponent(); string src = 博博实验人事管理系统实验人事管理系统MyData.mdf;Integrated Security=True; privatevoid Form1_Load( object sender, EventArgs e) priv
4、atevoid 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 = ) MessageBox .Show( 您输入的数据不完整! ); else string sql1 = string.Format( select USERNAME from Table_login where USE
5、RNAME=N0;, user); using ( SqlConnection coon = newSqlConnection (src) SqlCommand cmd = newSqlCommand (sql1, coon); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 29 页 - - - - - - - - - coon.Open(); using ( SqlDataReader dr = cmd.ExecuteReader() while (dr.Read()
6、 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 = newSqlConnection (src) SqlCommand cmd = newSqlCommand (sql2, coon); coon.Open(); using ( SqlDataReader dr = cm
7、d.ExecuteReader() while (dr.Read() if (password = drPASSWORD.ToString() sign2+; if (sign1 != 0 & sign2 = 0) MessageBox .Show( 您的密码输入错误! ); if (sign2 != 0) Form_show f1 = newForm_show (user, this ); f1.Show(); this .Visible = false ; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - -
8、 - - - - - 第 4 页,共 29 页 - - - - - - - - - 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.
9、SqlClient; using CCWin; namespace 实验_人事管理系统 publicpartialclassForm_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 = newTreeNode(); int ID=-1;
10、 public List list = new List (); string name; string birth; string sex; string education; string adminisitrator; string manegetime; / string category_name;string src = 博博实验人事管理系统实验人事管理系统MyData.mdf;Integrated Security=True; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - -
11、 第 5 页,共 29 页 - - - - - - - - - privatevoid Form_show_Load(object sender, EventArgs e) toolStripStatusLabel_name.Text = 管理员: + this .login_name; toolStripStatusLabel_time.Text = 登录时间: + DateTime.Now.ToLongTimeString(); Addparent(); this .dataGridView1.ClearSelection(); privatevoid toolStripStatusLab
12、el_name_Click(object sender, EventArgs e) privatevoid Form_show_FormClosed(object sender, FormClosedEventArgs e) fl.Close(); publicvoid Addparent() string sql = select * from Table_tree where PR_NUMBER=-1; using ( SqlConnection coon = newSqlConnection (src) SqlCommand cmd = newSqlCommand (sql, coon)
13、; coon.Open(); using ( SqlDataReader dr = cmd.ExecuteReader() while (dr.Read() string name = drNAME .ToString(); string number = drNUMBER .ToString(); / string category=drCATEGORY.ToString();TreeNode tn = newTreeNode(); tn.Text = name; tn.Tag = number; tn.ImageIndex = 1; AddChild(number, tn); treeVi
14、ew_jiegou.Nodes.Add(tn); / skinTreeView1.Nodes.Add(tn); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 29 页 - - - - - - - - - privatevoid AddChild( string pnumber, TreeNode pnode) if ( Convert .ToInt32(pnode.Tag) = 0 | (pnode.Parent!=null & Convert .ToInt32(pno
15、de.Parent.Tag) = 0) stringsql = select * from Table_tree where PR_NUMBER= + pnumber + order by NAME desc; ; using ( SqlConnection conn = newSqlConnection (src) SqlCommand cmd = newSqlCommand (sql, conn); conn.Open(); using ( SqlDataReader dr = cmd.ExecuteReader() while (dr.Read() string name = drNAM
16、E .ToString(); string number = drNUMBER .ToString(); / string category = drCATEGORY.ToString();TreeNode tn = newTreeNode(); tn.Text = name; tn.Tag = number; tn.ImageIndex = 1; AddChild(number, tn); pnode.Nodes.Add(tn); else stringsql = select * from Table_tree where PR_NUMBER= + pnumber + order by N
17、AME desc; ; using ( SqlConnection conn = newSqlConnection (src) SqlCommand cmd = newSqlCommand (sql, conn); conn.Open(); using ( SqlDataReader dr = cmd.ExecuteReader() while (dr.Read() string name = drNAME .ToString(); string number = drNUMBER .ToString(); / string category = drCATEGORY.ToString();名
18、师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 29 页 - - - - - - - - - TreeNode tn = newTreeNode(); tn.Text = name; tn.Tag = number; tn.ImageIndex = 0; AddChild(number, tn); pnode.Nodes.Add(tn); privatevoid skinButton_add_Click(object sender, EventArgs e) / 无用的按钮
19、 privatevoid skinButton_add_Click_1(object sender, EventArgs e) /MessageBox.Show( 添加! );if (t.Parent.Parent!=null & t.Parent!=null ) Form_Addperson fp = newForm_Addperson(t, toolStripStatusLabel_name.Text, DateTime.Now.ToString(); fp.Owner = this ; fp.Show(); list.Clear(); elseMessageBox .Show( 请到班组
20、添加人员! ); / reshow(); privatevoid treeView_jiegou_AfterSelect(object sender, TreeViewEventArgs e) string sql = select * from Table_person where CATEGORY_NUMBER= + e.Node.Tag; List list = newList (); using ( SqlConnection conn = newSqlConnection (src) SqlCommand cmd = newSqlCommand (sql, conn); conn.O
21、pen(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 29 页 - - - - - - - - - using ( SqlDataReader dr = cmd.ExecuteReader() while (dr.Read() person p = newperson (); p.Person_name = drPERSON_NAME.ToString(); p.Category_name = drCATEGORY_NAME.ToString(); p.Sex =
22、 drSEX.ToString(); string dt=drBIRTH.ToString().Split( ); p.Birth = dt0; p.Education = drEDUCATION .ToString(); p.Adminisitrator = drADMINISITRATOR .ToString(); p.Manegetime=drMANEGETIME.ToString(); list.Add(p); this .dataGridView1.ClearSelection(); this .dataGridView1.DataSource = list; ID = -1; pr
23、ivatevoid添加部门 ToolStripMenuItem_Click(object sender, EventArgs e) if (t.Parent = null | t.Parent.Parent = null ) Form_Add fa = newForm_Add (t); fa.Owner = this ; fa.Show(); else Form_Addperson fp = newForm_Addperson(t, toolStripStatusLabel_name.Text, DateTime.Now.ToString(); fp.Owner = this ; fp.Sho
24、w(); list.Clear(); this .dataGridView1.DataSource = list; privatevoid treeView_jiegou_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 29 页 - - - - - - - - - this .t = e.Node; / MessageBox.Show(t.Name);
25、 publicvoid reshow() treeView_jiegou.Nodes.Clear(); Addparent(); privatevoid 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.Cel
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年C#实验报告 2022 C# 实验 报告
限制150内