c#之简单人力资源管理系统

目录


人力资源管理系统
一. 概述
1.绪论
2.背景
3.开发环境
二.需求功能分析
1.功能分析
2.数据库设计
三.系统模块描述
1.登录注册
2.管理员功能
3.员工功能
4.退出登录
5.数据库类
四.系统调试
1.测试时出现的问题
2.使用说明
五.总结



一. 概述
1.绪论
人力资源管理是一个企事业单位不可缺少的部分,它的内容对于单位决策者和管理者至关重要。 一直以来人们使用传统人工的方式管理文件档案,这种管理方式存在着许多缺点,如:效率低、保密性差,而且时间一长,将产生大量的文件和数据,这对于查找、更新和维护都带来了不少的困难。随着计算机应用的普及,我们可以使用计算机对人力资源信息进行管理,具有手工管理所无法比拟的优点.例如:检索迅速、查找方便、可靠性高、存储量大、保密性好、寿命长、成本低等。这些优点能够极大地提高人力资源管理的效率,也是企业的科学化、正规化管理的重要条件。因此,开发人力资源管理系统是很有必要的事情。
2.背景
在企业管理信息系统建设中,人力资源作为一个单独的模块进行开发。目前我们对人力资源管理仍停留在纸介质的基础上,浪费了许多人力和物力 。作为岗位信息,员工信息以及员工档案等信息过多时,不便于信息查看且管理繁琐,影响及时查看信息,因此需要对上述资料进行集中管理,及时了解本公司的人力资源信息,有利于决策层和管理者调配人力资源的管理效率。
3.开发环境
采用C#进行人力资源管理系统界面的设计;
数据库管理系统采用SQL SERVER2014。
二.需求功能分析
1.功能分析
(1).注册、登录;
(2).管理员身份:人事管理(对部门,人员的增删改查)、招聘管理(发布招聘信息,处理招聘招聘信息)、考勤管理(制定考勤规则,审核考勤数据)、薪酬管理;
(3).员工身份:查看招聘信息、投递简历、考勤签到、修改密码;
(4).退出登录。
2.数据库设计
(当时做这个的时候没有学过表的设计,主键以及表之间的联系统统没有考虑到)
(1)管理员登录信息表(manager)
属性:姓名,密码
这里写图片描述

(2)员工登录信息表(role)
属性:姓名,密码

这里写图片描述

(3)公司员工表(staff)
属性:员工号、姓名、性别、年龄

这里写图片描述

(4)公司部门表(department)
属性:部门号、名称、部门人数

这里写图片描述

(5)部门-员工表(departmentAndStaff)
属性:部门号、部门名称、员工号、员工姓名

这里写图片描述

(6)考勤规则表(time)
属性:小时、分钟

这里写图片描述

(7)考勤记录表(absense)
属性:姓名、签到时间、出勤信息
这里写图片描述

(8)招聘信息表(information)
属性:招聘内容、薪酬
这里写图片描述

(9)应聘人员表(employee)
属性:姓名、性别、年龄、学位

这里写图片描述

(10)面试人员表(employee_ing)
属性:姓名、性别、年龄
这里写图片描述

(11)薪资表(salary)
属性:姓名、出勤次数、迟到次数、薪资
这里写图片描述

三.系统模块描述
1.登录注册
1)界面设置
这里写图片描述
2)介绍:
a.使用者注册(管理员注册或者普通人员注册)
这里写图片描述
b.使用注册的账号登录
这里写图片描述
3)核心代码:
注册:

        private void button1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text;
            string password1 = textBox2.Text;
            string password2 = textBox3.Text;
            if (radioButton1.Checked)
            {
                if (name.Equals("") || password1.Equals("") || password2.Equals(""))//用户名或密码为空
                {
                    MessageBox.Show("用户名或密码不能为空");
                }
                else if (password1 != password2)
                {
                    MessageBox.Show("两次密码不相同!");

                }
                else {
                    try
                    {
                        DBconn.connection.ConnectionString = DBconn.connString;

                        string sql = "insert into manager values('" + name + "','" + password1 + "') ";

                        SqlCommand command = new SqlCommand(sql, DBconn.connection);
                        DBconn.connection.Open();
                        command.ExecuteNonQuery();
                        MessageBox.Show("注册成功!");
                        DBconn.connection.Close();
                        this.Hide();
                        login f = new login();
                        f.ShowDialog();

                    }
                    catch(Exception ex) //创建检查Exception对象
                    {
                        Console.WriteLine(ex.Message.ToString());//输出错误信息 
                        MessageBox.Show("系统错误!");
                    }
                }


            }
            else if (radioButton2.Checked)
            {
                if (name.Equals("") || password1.Equals("") || password2.Equals(""))//用户名或密码为空
                {
                    MessageBox.Show("用户名或密码不能为空");
                }
                else if (password1 != password2)
                {
                    MessageBox.Show("两次密码不相同!");

                }
                else
                {
                    try
                    {
                        DBconn.connection.ConnectionString = DBconn.connString;

                        string sql = "insert into role values('" + name + "','" + password1 + "') ";

                        SqlCommand command = new SqlCommand(sql, DBconn.connection);
                        DBconn.connection.Open();
                        command.ExecuteNonQuery();
                        MessageBox.Show("注册成功!");
                        DBconn.connection.Close();
                        this.Hide();
                        login f = new login();
                        f.ShowDialog();


                    }
                    catch (Exception ex) //创建检查Exception对象
                    {
                        Console.WriteLine(ex.Message.ToString());//输出错误信息 
                        MessageBox.Show("系统错误!");
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择角色!");
            }
        }

登录时:

        private void enter_Click(object sender, EventArgs e)
        {
            string username = user.Text;
            string userpassword = password.Text;
            try
            {
                if (radioButton1.Checked)
                {


                    if (username.Equals("") || password.Equals(""))//用户名或密码为空
                    {
                        MessageBox.Show("用户名或密码不能为空");
                    }
                    else//用户名或密码不为空
                    {

                        string sql1 = "select name,password from manager where name='" + username + "' and password='" + userpassword + "'";

                        DBconn.connection.ConnectionString = DBconn.connString;
                        DBconn.connection.Open();
                        SqlCommand command = new SqlCommand(sql1, DBconn.connection);
                        SqlDataAdapter sda = new SqlDataAdapter();
                        sda.SelectCommand = command;
                        DataSet ds = new DataSet();
                        int n = sda.Fill(ds, "验证");
                        if (n > 0)
                        {
                            loginInformation.login_user_name = username;
                            loginInformation.login_user_password = userpassword;
                            MessageBox.Show("欢迎进入人力资源管理系统!", "登录成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            newForm f2 = new newForm();

                            DBconn.connection.Close();

                            this.Hide();
                            f2.ShowDialog();
                        }
                        else {
                            MessageBox.Show("未找到信息!");
                            DBconn.connection.Close();

                        }
                    }
                }
                else if (radioButton2.Checked)
                {
                    if (username.Equals("") || password.Equals(""))//用户名或密码为空
                    {
                        MessageBox.Show("用户名或密码不能为空");
                    }
                    else//用户名或密码不为空
                    {

                        string sql = "select name,password from role where name='" + username + "' and password='" + userpassword + "'";
                        DBconn.connection.ConnectionString = DBconn.connString;
                        DBconn.connection.Open();
                        SqlCommand command = new SqlCommand(sql, DBconn.connection);
                        SqlDataAdapter sda = new SqlDataAdapter();
                        sda.SelectCommand = command;
                        DataSet ds = new DataSet();
                        int n = sda.Fill(ds, "验证");
                        if (n > 0)
                        {
                            loginInformation.login_user_name = user.Text;
                            loginInformation.login_user_password = password.Text;
                            MessageBox.Show("欢迎进入人力资源管理系统!", "登录成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            DBconn.connection.Close();
                            用户界面 f2 = new 用户界面();
                            this.Hide();
                            f2.ShowDialog();
                        }
                        else {
                            MessageBox.Show("未找到信息!");
                            DBconn.connection.Close();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("请选择角色!");
                    DBconn.connection.Close();
                }
            }
            catch (Exception ex)//创建检查Exception对象  
            {
                Console.WriteLine(ex.Message.ToString());//输出错误信息  
                MessageBox.Show("系统错误!");
                DBconn.connection.Close();

            }

        }

2.管理员功能
管理员界面:
这里写图片描述
1) 人事管理
介绍:通过人事管理实现公司部门、人员的添加、修改、删除,以及将已经添加到公司的员工添加到相应的部门中去。
①人员管理
添加人员
界面:
这里写图片描述
代码:

            try
            {
                Int32 no = Convert.ToInt32(textBox3.Text);
                string name = textBox1.Text;
                string sex = textBox4.Text;
                Int32 age = Convert.ToInt32(textBox2.Text);
                string sql = "insert into staff(sNo,sName,sSex,sAge) values (" + no + ",'" + name + "','" + sex + "'," + age + ")";

                DBconn.connection.ConnectionString = DBconn.connString;
                DBconn.connection.Open();

                SqlCommand command = new SqlCommand(sql, DBconn.connection);
                command.ExecuteNonQuery();

                string message = "添加成功";
                MessageBox.Show(message, "添加成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                MessageBox.Show("系统错误!");
            }

删除人员
界面:
这里写图片描述
按工号查找按钮代码:

            if (textBox1.Text == "")
            {
                MessageBox.Show("填入工号!");
            }
            else
            {
                try
                {
                    Int32 no = Convert.ToInt32(textBox3.Text);
                    string sql = "select * from staff where sNo = " + no + " ";
                    DBconn.connection.ConnectionString = DBconn.connString;
                    DBconn.connection.Open();

                    SqlCommand command = new SqlCommand(sql, DBconn.connection);
                    SqlDataReader dataReader = command.ExecuteReader();
                    if (dataReader.Read())
                    {
                        listBox1.Items.Clear();
                        sNo = dataReader[0].ToString();
                        listBox1.Items.Add("员工号:" + sNo);
                        sName = dataReader[1].ToString();
                        listBox1.Items.Add("员工名:" + sName);
                        sSex = dataReader[2].ToString();
                        listBox1.Items.Add("员工性别:" + sSex);
                        sAge = dataReader[3].ToString();
                        listBox1.Items.Add("员工年龄:" + sAge);

                    }
                    else
                    {
                        listBox1.Items.Clear();
                        listBox1.Items.Add("没有该项!");
                    }

                    dataReader.Close();
                    DBconn.connection.Close();
                }

删除按钮代码:

                string sql = "delete from staff where sNo = " + sNo + " ";
                DBconn.connection.ConnectionString = DBconn.connString;
                DBconn.connection.Open();

                SqlCommand command = new SqlCommand(sql, DBconn.connection);
                command.ExecuteNonQuery();
                MessageBox.Show("删除成功!");
                DBconn.connection.Close();

修改人员信息
界面:
这里写图片描述
修改代码:

            string name = textBox6.Text;
            string sex = textBox4.Text;
            Int32 age = Convert.ToInt32(textBox5.Text);

            string sql = "update staff set  sName = '" + name + " ',sSex = '" + sex + " ',sAge = " + age + " where sNo = "+sNo+"";
            DBconn.connection.ConnectionString = DBconn.connString;
            DBconn.connection.Open();

            SqlCommand command = new SqlCommand(sql, DBconn.connection);
            command.ExecuteNonQuery();
            MessageBox.Show("修改成功!");

②部门管理
界面:
这里写图片描述

这里写图片描述
这里写图片描述
代码参照人员管理即可。
③人员部门管理
界面:
这里写图片描述
这里写图片描述
代码参照人员管理即可。
2) 招聘管理
介绍:管理人员通过招聘管理 发布公司招聘信息,游客登录之后通过查看招聘信息、投递简历之后,管理员处理招聘人员信息,决定是否告知应聘者参加面试。
① 发布招聘
界面:
这里写图片描述
代码:

            string a = textBox1.Text;
            double  b =Convert.ToDouble(textBox2.Text);
            try
            {

                string sql1 = "delete from information";
                string sql2 = "insert into information values ('"+a+"',"+b+")";

                DBconn.connection.ConnectionString = DBconn.connString;
                DBconn.connection.Open();

                SqlCommand command1 = new SqlCommand(sql1, DBconn.connection);
                command1.ExecuteNonQuery();
                SqlCommand command2 = new SqlCommand(sql2, DBconn.connection);
                command2.ExecuteNonQuery();

                string message = "发布成功!";
                MessageBox.Show(message, "发布成功!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                DBconn.connection.Close();

② 处理招聘
界面:
这里写图片描述
查看按钮代码:

                string sql = "select * from employee ";
                DBconn.connection.ConnectionString = DBconn.connString;
                DBconn.connection.Open();
                SqlCommand command = new SqlCommand(sql, DBconn.connection);
                SqlDataAdapter da = new SqlDataAdapter(command);
                DataSet ds = new DataSet();
                da.Fill(ds, "employee");
                dataGridView1.DataSource = ds;
                dataGridView1.DataMember = "employee";

                dataGridView1.Columns[0].HeaderText = "姓名";
               // dataGridView1.Columns[0].DataPropertyName = ds.Tables[0].Columns[0].ToString();
                dataGridView1.Columns[0].Width = 106;

                dataGridView1.Columns[1].HeaderText = "性别";
               // dataGridView1.Columns[1].DataPropertyName = ds.Tables[0].Columns[1].ToString();
                dataGridView1.Columns[1].Width = 106;

                dataGridView1.Columns[2].HeaderText = "年龄";
                dataGridView1.Columns[2].Width = 106;

                dataGridView1.Columns[3].HeaderText = "学历";
                dataGridView1.Columns[3].Width = 106;
                DBconn.connection.Close();

面试按钮代码:

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (dataGridView1.Rows[i].Selected == true)
                {

                    string name = dataGridView1.Rows[i].Cells[0].Value.ToString();
                    string sex = dataGridView1.Rows[i].Cells[1].Value.ToString();
                    string age = dataGridView1.Rows[i].Cells[2].Value.ToString();

                    string sql = "insert into employee_ing values('" + name + "','" + sex + "','" + age + "')";
                    DBconn.connection.ConnectionString = DBconn.connString;
                    DBconn.connection.Open();
                    SqlCommand command = new SqlCommand(sql,DBconn.connection);
                    command.ExecuteNonQuery();
                    DBconn.connection.Close();
                }
            }
            MessageBox.Show("已经添加到面试表!");

③ 面试人员表
界面:
这里写图片描述
删除代码:

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Rows[i].Selected == true)
                    {

                        string name = dataGridView1.Rows[i].Cells[0].Value.ToString();
                        string sex = dataGridView1.Rows[i].Cells[1].Value.ToString();
                        string age = dataGridView1.Rows[i].Cells[2].Value.ToString();
                        string sql = "delete from employee_ing where name = '" + name + "'and sex = '" + sex + "'and age = '" + age + "'";
                        DBconn.connection.ConnectionString = DBconn.connString;
                        DBconn.connection.Open();
                        SqlCommand command = new SqlCommand(sql, DBconn.connection);
                        command.ExecuteNonQuery();

                        DBconn.connection.Close();
                    }
                }

                MessageBox.Show("删除成功!");


                string sql2 = "select * from employee_ing ";
                DBconn.connection.ConnectionString = DBconn.connString;
                DBconn.connection.Open();
                SqlCommand command2 = new SqlCommand(sql2, DBconn.connection);
                SqlDataAdapter da = new SqlDataAdapter(command2);
                DataSet ds = new DataSet();
                da.Fill(ds, "employee_ing");
                dataGridView1.DataSource = ds;
                dataGridView1.DataMember = "employee_ing";

                dataGridView1.Columns[0].HeaderText = "姓名";
                // dataGridView1.Columns[0].DataPropertyName = ds.Tables[0].Columns[0].ToString();
                dataGridView1.Columns[0].Width = 143;

                dataGridView1.Columns[1].HeaderText = "性别";
                // dataGridView1.Columns[1].DataPropertyName = ds.Tables[0].Columns[1].ToString();
                dataGridView1.Columns[1].Width = 143;

                dataGridView1.Columns[2].HeaderText = "年龄";
                dataGridView1.Columns[2].Width = 143;

                DBconn.connection.Close();

3) 考勤管理
介绍:管理员制定每天上班的时间,员工上班的时候在系统上签到,系统判断为迟到或者正常出勤,管理员审核考勤数据,可以查看员工的签到情况。
① 制定考核规则
界面:
这里写图片描述
代码:

            string hour = textBox1.Text;
            string minute = textBox2.Text;
            string sql = "insert into time values('" + hour + "','" + minute + "')";
            string sql2 = "delete from time";
            try
            {
                DBconn.connection.ConnectionString = DBconn.connString;
                DBconn.connection.Open();
                SqlCommand command = new SqlCommand(sql, DBconn.connection);
                SqlCommand command2 = new SqlCommand(sql2, DBconn.connection);
                command2.ExecuteNonQuery();
                command.ExecuteNonQuery();

                string message = "成功";
                MessageBox.Show(message, "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                DBconn.connection.Close();

② 审核考勤数据
界面:
这里写图片描述
初始化代码:

                string sql = "select distinct name from absense ";
                DBconn.connection.ConnectionString = DBconn.connString;
                DBconn.connection.Open();
                SqlCommand command = new SqlCommand(sql, DBconn.connection);
                SqlDataAdapter da = new SqlDataAdapter(command);
                DataSet ds = new DataSet();
                da.Fill(ds, "name");
                dataGridView1.DataSource = ds;
                dataGridView1.DataMember = "name";

                dataGridView1.Columns[0].HeaderText = "姓名";

                dataGridView1.Columns[0].Width = 106;

                DBconn.connection.Close();

查看代码:

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (dataGridView1.Rows[i].Selected == true)
                {

                    string name = dataGridView1.Rows[i].Cells[0].Value.ToString();//得到选中的名字
                    string sql = "select* from absense where  name = '" + name + "' and time  between '" + textBox1.Text + "' and '" + textBox2.Text + "'order by time";
                    string sql1 = "select* from absense where  name = '" + name + "'order by time";
                    string sql2 = "select count(*) from absense where  name = '" + name + "' and time  between '" + textBox1.Text + "' and '" + textBox2.Text + "'and absense = '迟到'";
                    string sql3 = "select count(*) from absense where  name = '" + name + "'and absense = '迟到'";
                    if (textBox1.Text == "" || textBox2.Text == "")
                    {

                        DBconn.connection.ConnectionString = DBconn.connString;
                        DBconn.connection.Open();
                        SqlCommand command1 = new SqlCommand(sql1, DBconn.connection);
                        SqlCommand command3 = new SqlCommand(sql3, DBconn.connection);
                        SqlDataAdapter da1 = new SqlDataAdapter(command1);
                        DataSet ds1 = new DataSet();
                        da1.Fill(ds1, "absense");
                        dataGridView2.DataSource = ds1;
                        dataGridView2.DataMember = "absense";

                        dataGridView2.Columns[0].HeaderText = "姓名";
                        // dataGridView1.Columns[0].DataPropertyName = ds.Tables[0].Columns[0].ToString();
                        dataGridView2.Columns[0].Width = 106;

                        dataGridView2.Columns[1].HeaderText = "签到时间";
                        // dataGridView1.Columns[1].DataPropertyName = ds.Tables[0].Columns[1].ToString();
                        dataGridView2.Columns[1].Width = 106;

                        dataGridView2.Columns[2].HeaderText = "状态";
                        dataGridView2.Columns[2].Width = 106;

                        string count = command3.ExecuteScalar().ToString();//数据库数据行数

                        textBox3.Text = count;
                        DBconn.connection.Close();



                    }
                    else if (!(Program.IsDate(textBox1.Text) && Program.IsDate(textBox2.Text)))
                    {
                        MessageBox.Show("时间格式不正确!");
                    }
                    else
                    {
                        DBconn.connection.ConnectionString = DBconn.connString;
                        DBconn.connection.Open();
                        SqlCommand command1 = new SqlCommand(sql, DBconn.connection);
                        SqlCommand command2 = new SqlCommand(sql2, DBconn.connection);
                        SqlDataAdapter da1 = new SqlDataAdapter(command1);


                        DataSet ds1 = new DataSet();
                        da1.Fill(ds1, "absense");
                        dataGridView2.DataSource = ds1;
                        dataGridView2.DataMember = "absense";

                        dataGridView2.Columns[0].HeaderText = "姓名";
                        // dataGridView1.Columns[0].DataPropertyName = ds.Tables[0].Columns[0].ToString();
                        dataGridView2.Columns[0].Width = 106;

                        dataGridView2.Columns[1].HeaderText = "签到时间";
                        // dataGridView1.Columns[1].DataPropertyName = ds.Tables[0].Columns[1].ToString();
                        dataGridView2.Columns[1].Width = 106;

                        dataGridView2.Columns[2].HeaderText = "状态";
                        dataGridView2.Columns[2].Width = 106;

                        string count = command2.ExecuteScalar().ToString();//数据库数据行数
                        textBox3.Text = count;
                        DBconn.connection.Close();
                    }
                }
            }

4) 薪酬管理
介绍: 管理员通过员工的低薪和考勤的情况,根据公式得出薪酬,点击人员名单填入时间段之后显示该员工的薪酬。

界面;
这里写图片描述
代码;

            //清空表中之前的数据
            string sql6 = "delete from salary";
            DBconn.connection.Open();
            SqlCommand command5 = new SqlCommand(sql6, DBconn.connection);
            command5.ExecuteNonQuery();
            DBconn.connection.Close();

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (dataGridView1.Rows[i].Selected == true)
                {
                    string name = dataGridView1.Rows[i].Cells[0].Value.ToString();//得到选中的名字
                    int count1;//出勤
                    int count2;
                    float salary;
                    string beginTime = textBox1.Text;
                    string endTime = textBox2.Text;
                    string sql = "select count(*) from absense where name = '" + name + "'and time between '" + beginTime + "'and'" + endTime + "'and absense = '正常出勤'";
                    string sql1 = "select count(*) from absense where name = '" + name + "'and time between '" + beginTime + "'and'" + endTime + "'and absense = '迟到'";
                    string sql2 = "select count(*) from absense where name = '" + name + "'and absense = '正常出勤'";
                    string sql3 = "select count(*) from absense where name = '" + name + "'and absense = '迟到'";
                    //  string sql4 = "insert into salary values('"+name + "','"+count1+"','" + salary + "')";
                    string sql5 = "select * from salary";


                    if (beginTime == "" || endTime == "")
                    {
                        try
                        {
                            DBconn.connection.ConnectionString = DBconn.connString;
                            DBconn.connection.Open();
                            SqlCommand command1 = new SqlCommand(sql2, DBconn.connection);
                            count1 = Convert.ToInt16(command1.ExecuteScalar().ToString());//出勤的次数

                            SqlCommand command2 = new SqlCommand(sql3, DBconn.connection);
                            count2 = Convert.ToInt16(command2.ExecuteScalar().ToString());//迟到的次数
                            salary = count1 * 200 + count2 * 150;


                            string sql4 = "insert into salary values('" + name + "','" + count1 + "','"+count2+"','" + salary + "')";
                            SqlCommand command3 = new SqlCommand(sql4, DBconn.connection);//插入一条记录到工资表
                            command3.ExecuteNonQuery();

                            //将工资表的记录显示在datagridview中
                            SqlCommand command4 = new SqlCommand(sql5, DBconn.connection);
                            SqlDataAdapter da1 = new SqlDataAdapter(command4);
                            DataSet ds1 = new DataSet();
                            da1.Fill(ds1, "salary");
                            dataGridView2.DataSource = ds1;
                            dataGridView2.DataMember = "salary";
                            dataGridView2.Columns[0].HeaderText = "姓名";
                            // dataGridView1.Columns[0].DataPropertyName = ds.Tables[0].Columns[0].ToString();
                            dataGridView2.Columns[0].Width = 86;

                            dataGridView2.Columns[1].HeaderText = "出勤次数";
                            // dataGridView1.Columns[1].DataPropertyName = ds.Tables[0].Columns[1].ToString();
                            dataGridView2.Columns[1].Width = 70;

                            dataGridView2.Columns[2].HeaderText = "迟到次数";
                            // dataGridView1.Columns[1].DataPropertyName = ds.Tables[0].Columns[1].ToString();
                            dataGridView2.Columns[2].Width = 70;

                            dataGridView2.Columns[3].HeaderText = "工资";
                            dataGridView2.Columns[3].Width = 86;

                            DBconn.connection.Close();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                            MessageBox.Show("系统错误!");
                            DBconn.connection.Close();
                        }
                    }
                    else if (!(Program.IsDate(textBox1.Text) && Program.IsDate(textBox2.Text)))
                    {
                        MessageBox.Show("时间格式不正确!");
                    }
                    else
                    {//当时间不为空的时候
                        try
                        {
                            DBconn.connection.ConnectionString = DBconn.connString;
                            DBconn.connection.Open();
                            SqlCommand command1 = new SqlCommand(sql, DBconn.connection);
                            count1 = Convert.ToInt16(command1.ExecuteScalar().ToString());//出勤的次数

                            SqlCommand command2 = new SqlCommand(sql, DBconn.connection);
                            count2 = Convert.ToInt16(command2.ExecuteScalar().ToString());//迟到的次数
                            salary = count1 * 200 + count2 * 150;


                            string sql4 = "insert into salary values('" + name + "','" + count1 + "','" + count2 + "','" + salary + "')";
                            SqlCommand command3 = new SqlCommand(sql4, DBconn.connection);//插入一条记录到工资表
                            command3.ExecuteNonQuery();

                            //将工资表的记录显示在datagridview中
                            SqlCommand command4 = new SqlCommand(sql5, DBconn.connection);
                            SqlDataAdapter da1 = new SqlDataAdapter(command4);
                            DataSet ds1 = new DataSet();
                            da1.Fill(ds1, "salary");
                            dataGridView2.DataSource = ds1;
                            dataGridView2.DataMember = "salary";
                            dataGridView2.Columns[0].HeaderText = "姓名";
                            // dataGridView1.Columns[0].DataPropertyName = ds.Tables[0].Columns[0].ToString();
                            dataGridView2.Columns[0].Width = 86;

                            dataGridView2.Columns[1].HeaderText = "出勤次数";
                            // dataGridView1.Columns[1].DataPropertyName = ds.Tables[0].Columns[1].ToString();
                            dataGridView2.Columns[1].Width = 70;

                            dataGridView2.Columns[2].HeaderText = "迟到次数";
                            // dataGridView1.Columns[1].DataPropertyName = ds.Tables[0].Columns[1].ToString();
                            dataGridView2.Columns[2].Width = 70;

                            dataGridView2.Columns[3].HeaderText = "工资";
                            dataGridView2.Columns[3].Width = 86;

                            DBconn.connection.Close();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                            MessageBox.Show("系统错误!");
                            DBconn.connection.Close();
                        }
                    }
                }

3.员工功能
员工界面:
这里写图片描述
1) 招聘信息
介绍:员工或游客查看公司招聘信息,然后投递简历给管理员。
界面:
这里写图片描述

投递简历界面:
这里写图片描述
提交按钮代码:

            string name = textBox1.Text;
            string sex = textBox2.Text;
            string age = textBox3.Text;
            string degree = textBox4.Text;
            try {
                DBconn.connection.ConnectionString = DBconn.connString;
                DBconn.connection.Open();
                string sql = "insert into employee values('" + name + "','" + sex + "','" + age + "','" + degree + "')";
                SqlCommand command1 = new SqlCommand(sql, DBconn.connection);
                command1.ExecuteNonQuery();
                string message = "提交成功!";
                MessageBox.Show(message, "提交成功!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                DBconn.connection.Close();

2) 考勤
介绍:如果你是本公司员工,则可以签到打卡成功,如果不是本公司员工,则不能进行签到操作。

点击签到即判断是否是本公司员工
这里写图片描述

如果是本公司员工,则进行签到。

签到界面:(如果你今天已经签过到,则系统提示不能重复签到)

这里写图片描述
这里写图片描述
代码:

            try
            {
                DBconn.connection.Close();
                string sql = "select name, time from absense where name='" + loginInformation.login_user_name + "' and time='" + DateTime.Now.Date + "'";
                DBconn.connection.ConnectionString = DBconn.connString;
                DBconn.connection.Open();
                SqlCommand command1 = new SqlCommand(sql, DBconn.connection);
                SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = command1;
                DataSet ds = new DataSet();
                int n = sda.Fill(ds, "验证");
                if (n > 0)
                {
                    MessageBox.Show("你今天已经签过到了!");
                    DBconn.connection.Close();
                }
                else
                {

                    string sql4 = "select * from time ";
                    string sql2 = "insert into absense values('" + loginInformation.login_user_name + "', '" + DateTime.Now.ToString() + "','迟到')";
                    string sql3 = "insert into absense values('" + loginInformation.login_user_name + "', '" + DateTime.Now.ToString() + "','正常出勤')";

                    DBconn.connection.Close();
                    DBconn.connection.ConnectionString = DBconn.connString;
                    DBconn.connection.Open();
                    SqlDataAdapter sda1 = new SqlDataAdapter(sql4, DBconn.connection);
                    DataSet ds1 = new DataSet();
                    sda1.Fill(ds1);
                    string b1 = ds1.Tables[0].Rows[0][0].ToString();
                    string b2 = ds1.Tables[0].Rows[0][1].ToString();
                    DBconn.connection.Close();
                    Int32 b3 = Convert.ToInt32(b1);//hour
                    Int32 b4 = Convert.ToInt32(b2);//minute
                    DateTime now = DateTime.Now;
                    string a1 = now.Hour.ToString();
                    string a2 = now.Minute.ToString();
                    Int32 a3 = Convert.ToInt32(a1);//当前hour
                    Int32 a4 = Convert.ToInt32(a2);//当前minute


                    if (a3 == b3)
                    {
                        if (a4 == b4)
                        {
                            textBox2.Text = "真准时!签到成功!";
                        }
                        else if (a4 < b4)
                        {
                            textBox2.Text = "真勤快!签到成功!";

                        }
                        else if (a4 > b4)
                        {
                            textBox2.Text = "迟到了!签到成功!";

                        }

                    }
                    else if (a3 > b3)
                    {
                        textBox2.Text = "迟到了!签到成功!";

                    }
                    else if (a3 < b3)
                    {
                        textBox2.Text = "真勤快!签到成功!";

                    }
                    DBconn.connection.Close();



                    if (textBox2.Text == "迟到了!签到成功!")
                    {
                        DBconn.connection.ConnectionString = DBconn.connString;
                        DBconn.connection.Open();
                        SqlCommand command = new SqlCommand(sql2, DBconn.connection);
                        command.ExecuteNonQuery();
                        DBconn.connection.Close();
                    }
                    else
                    {

                        DBconn.connection.ConnectionString = DBconn.connString;
                        DBconn.connection.Open();
                        SqlCommand command = new SqlCommand(sql3, DBconn.connection);
                        command.ExecuteNonQuery();
                        DBconn.connection.Close();
                    }

                }

3)修改密码
界面:
这里写图片描述
确定按钮代码:

            if (textBox1.Text == loginInformation.login_user_password)
            {
                if (textBox2.Text == textBox3.Text)
                {
                    try
                    {

                        string sql = "update role set  password = '" + textBox2.Text + " 'where name = '" + loginInformation.login_user_name + "'";
                        DBconn.connection.ConnectionString = DBconn.connString;
                        DBconn.connection.Open();

                        SqlCommand command = new SqlCommand(sql, DBconn.connection);
                        command.ExecuteNonQuery();
                        MessageBox.Show("修改成功!");
                        DBconn.connection.Close();
                    }
                    catch (Exception ex)
                    {
                        DBconn.connection.Close();
                        Console.WriteLine(ex);
                        MessageBox.Show("系统错误!");
                    }

                }
                else {
                    MessageBox.Show("两次密码输入不一致!");
                    DBconn.connection.Close();
                }
            }
            else {
                MessageBox.Show("当前密码错误!");
                DBconn.connection.Close();
            }

4.退出登录
介绍:用户或管理员可以通过这个选项切换用户或直接退出登录。

            MessageBox.Show("退出成功!");
            this.Close();
            DBconn.connection.Close();
            login f = new login();
            f.Show();

5.数据库类

    class DBconn
    {
        public static string connString = "Server=DESKTOP-LBSS781\\SQLEXPRESS;Database=hr;Integrated Security=True";
        public static SqlConnection connection = new SqlConnection(connString);
    }

四.系统调试
1.测试时出现的问题
1)登录时使用tab键出现屏幕刷新卡顿现象。
2)单击首页界面刷新跳转,需要得到改进。
3)人员添加到部门以及从部门移除的时候需要一个一个添加,比较麻烦。这个是刚开始做的功能,没有考虑周全。
4)数据库的设计还存在很大的问题,但是在最后才意识到数据库的不标准,就没有去做改动,但是不影响工功能的实现。
2.使用说明
1)请先注册再行登录
2)添加部门成员的时候需要一个一个操作,不适合较大型公司使用,请慎重选择。
3)可能会出诸多异常,请退出重新操作。
五.总结
我认为,在这学期的课程设计中,不仅培养了独立思考、动手操作的能力,在各种其它能力上也都有了提高。更重要的是,在实验课上,我们学会了很多学习的方法。而这是日后最实用的,真的是受益匪浅。要面对社会的挑战,只有不断的学习、实践,再学习、再实践。这对于我们的将来也有很大的帮助。以后,不管有多苦,我想我们都能变苦为乐,找寻有趣的事情,发现其中珍贵的事情。就像中国提倡的艰苦奋斗一样,我们都可以在实验结束之后变的更加成熟,会面对需要面对的事情。
回顾起此课程设计,至今我仍感慨颇多,从理论到实践,在这段日子里,可以说得是苦多于甜,但是可以学到很多很多的东西,同时不仅可以巩固了以前所学过的知识,而且学到了很多在书本上所没有学到过的知识。通过这次课程设计使我懂得了理论与实际相结合是很重要的,只有理论知识是远远不够的,只有把所学的理论知识与实践相结合起来,从理论中得出结论,才能真正为社会服务,从而提高自己的实际动手能力和独立思考的能力。在设计的过程中遇到问题,可以说得是困难重重,但可喜的是最终都得到了解决。

  • 64
    点赞
  • 296
    收藏
    觉得还不错? 一键收藏
  • 24
    评论
评论 24
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值