2018-07-02

1.识别实体

实体:职员
属性:编号、姓名、性别、部门、权限

实体:打卡机
属性:编号、位置

实体关系:打卡
属性:流水号、打卡日期、打卡时间、职员编号、打卡机编号

2.E-R图

image.png

3.数据表图

1图1.png

4.数据库图

职员表

![
捕获222.PNG

打卡机表
捕获333.PNG

数据库表

9999999获.PNG

5登录注册界面

捕获1.PNG

点击“登录”按钮则登录系统

   private void bt_Login_Click(object sender, EventArgs e)
        {
            String connStr = ConfigurationManager.ConnectionStrings["Attendance"].ConnectionString;
            SqlConnection sqlConn = new SqlConnection(connStr);
            try
            {
                // 连接数据库
                sqlConn.Open();

                // 构造命令发送给数据库
                String sqlStr = "select * from EMPLOYEE where ID=@id and PASSWORD=@pwd";
                SqlCommand cmd = new SqlCommand(sqlStr, sqlConn);

                // 注意是用用户ID登录,而不是用户名,用户名可能会重复
                cmd.Parameters.Add(new SqlParameter("@id", this.tb_User.Text.Trim()));
                cmd.Parameters.Add(new SqlParameter("@pwd", this.tb_Password.Text.Trim()));

                SqlDataReader dr = cmd.ExecuteReader();

                // 如果从数据库中查询到记录,则表示可以登录
                if (dr.HasRows)
                {
                    dr.Read();
                    UserInfo.userId = int.Parse(dr["ID"].ToString());
                    UserInfo.userName = dr["NAME"].ToString();
                    UserInfo.userPwd = dr["PASSWORD"].ToString();
                    UserInfo.userRole = dr["ROLE"].ToString();
                    UserInfo.userDepartment = dr["DEPARTMENT"].ToString();
                    UserInfo.userGender = dr["GENDER"].ToString();

                    MessageBox.Show(UserInfo.userRole + "登录成功");

                    if (UserInfo.userRole == "职员")
                    {
                        Form3 Form = new Form3();
                        Form.Show();
                        //// 显示收银员主界面
                        //MainFormUser formUser = new MainFormUser();
                        //formUser.Show();

                        //// 隐藏登录界面
                        this.Hide();
                    }

                    if (UserInfo.userRole == "管理员")
                    {
                        Form4 Form = new Form4();
                        Form.Show();
                        //// 显示库管员主界面
                        //MainFormAdmin formAdmin = new MainFormAdmin();
                        //formAdmin.Show();

                        //// 隐藏登录界面
                        this.Hide();
                    }
                }
                else
                {
                    MessageBox.Show("用户名或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show("访问数据库错误:" + exp.Message);
            }
            finally
            {
                sqlConn.Close();
            }
        }

        // 点击“退出”按钮则退出应用程序
捕获2.PNG

捕获3.PNG

点击录入职员按钮进入Form2

Form2 Form = new Form2();
          Form.Show();
捕获4.PNG

点击注册按钮注册

 String id = this.textBox1.Text.Trim();
            String name = this.textBox2.Text.Trim();
            String password = this.textBox3.Text.Trim();
            String gender = this.comboBox1.Text.ToString();
            String department = this.comboBox2.Text.ToString();
            String role = this.comboBox3.Text.ToString();

            // 连接字符串,注意与实际环境保持一致
            String connStr = ConfigurationManager.ConnectionStrings["Attendance"].ConnectionString;
            SqlConnection sqlConn = new SqlConnection(connStr);
            try
            {
                // 连接数据库
                sqlConn.Open();
                

                // 构造命令
                String sqlStr = "insert into employee(ID, NAME, GENDER, DEPARTMENT, ROLE, PASSWORD) values(@id, @name, @gender, @department, @role, @password)";
                SqlCommand cmd = new SqlCommand(sqlStr, sqlConn);
                String sqlSt = "select MAX(id+1) as id from employee";

                // SQL字符串参数赋值
                cmd.Parameters.Add(new SqlParameter("@id", id));
                cmd.Parameters.Add(new SqlParameter("@name", name));
                cmd.Parameters.Add(new SqlParameter("@gender", gender));
                cmd.Parameters.Add(new SqlParameter("@department", department));
                cmd.Parameters.Add(new SqlParameter("@role", role));
                cmd.Parameters.Add(new SqlParameter("@password", password));

                // 将命令发送给数据库
                int res = cmd.ExecuteNonQuery();

                // 根据返回值判断是否插入成功
                if (res != 0)
                {
                    MessageBox.Show("职员信息录入成功");
                }
                else
                {
                    MessageBox.Show("职员信息录入失败");
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show("访问数据库错误:" + exp.Message);
            }
            finally
            {
                sqlConn.Close();
            }
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

6职员打卡

捕获9.PNG

点击打开串口按钮

 // 串口已打开,此时需要关闭
            if (serialPort1.IsOpen)
            {
                serialPort1.Close();
                this.toolStripStatusLabel1.Text = "已关闭串口" + serialPort1.PortName.ToString();
                buttonOpenCOM.Text = "打开";
                return;
            }
            // 否则打开串口
            else
            {
                serialPort1.PortName = comboBoxCOMList.Text;
                InitSerialPort();

                try
                {
                    serialPort1.Open();
                    this.toolStripStatusLabel1.Text = "已打开串口" + serialPort1.PortName.ToString();
                    buttonOpenCOM.Text = "关闭";
                }
                catch (Exception ex)
                {
                    this.toolStripStatusLabel1.Text = "打开串口失败,原因:" + ex.Message;
                    return;
                }
            }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 考勤系统数据库建立 1、识别实体 职员:编号、姓名、性别、部门、权限打卡机:编号、位置打卡:编号、员工编号、日期、...
    要上天的鱼阅读 200评论 0 0
  • 考勤系统需求分析 需求概述 背景 考勤系统是指一套管理公司的员工的上下班考勤记录等相关情况的物联网应用系统,是考勤...
    hww123阅读 318评论 0 0
  • # XML复习 ## 第一章 ## 思考题 **什么是XML?** XML是可扩展性标记语言,XML是标准通用标记...
    冷漠铁锤丁富贵阅读 841评论 0 0
  • 考勤系统需求分析 1、需求概述 背景 考勤系统是指一套管理公司的员工的上下班考勤记录等相关情况的物联网应用系统,是...
    要上天的鱼阅读 190评论 0 0
  • 对山林野趣的第一印象是王维的辋川,中国人似乎真的很厌倦车马之喧,所以只要一谈到理想的乡野,就一定是清幽少人迹...
    于小航阅读 559评论 0 0