コード例 #1
0
 private void ButReject_Click(object sender, EventArgs e)
 {
     try
     {
         if (RegistName.Text.Trim().Equals(""))
         {
             MessageBox.Show("用户名不能为空!", "提示");
             RegistName.Focus();
         }
         else if (PassWord.Text.Trim().Equals(""))
         {
             MessageBox.Show("密码不能为空!", "提示");
             PassWord.Focus();
         }
         else if (UserName(RegistName.Text.Trim()))
         {
             MessageBox.Show("用户名已经存在!", "提示");
             ClearAll();
         }
         else
         {
             string sqlStr = "insert user_info (userName, userPwd, roles) values('" + RegistName.Text.Trim() + "','" + PassWord.Text.Trim() + "','" + RolesBox.Text.Trim() + "')";
             if (DBconn.PDData(sqlStr))
             {
                 MessageBox.Show("用户" + RegistName.Text.Trim() + "注册成功!");
             }
             this.Close();
         }
     }catch (Exception ex)            {
         DBconn.conn.Close();
         MessageBox.Show(ex.Message);
         ClearAll();
     }
 }
コード例 #2
0
        // 判断注册用户是否已经存在
        bool UserName(string userName)
        {
            string  sqlStr = "select userName from user_info where userName='******'";
            DataSet ds     = DBconn.getData(sqlStr);

            if (ds.Tables[0].Rows.Count == 0)
            {
                return(false);
            }
            return(true);
        }
コード例 #3
0
        // 加载数据到列表方法
        public void AddData(string sql)
        {
            try
            {
                // 首先清空页面
                while (this.dataGridView1.Rows.Count != 0)
                {
                    this.dataGridView1.Rows.RemoveAt(0);
                }

                DataSet ds = DBconn.getData(sql);

                int count = ds.Tables[0].Rows.Count;
                // 逐行加载数据到列表
                for (int i = 0; i < count; i++)
                {
                    string id       = ds.Tables[0].Rows[i][0].ToString().Trim();
                    string userid   = ds.Tables[0].Rows[i][1].ToString().Trim();
                    string content  = ds.Tables[0].Rows[i][2].ToString().Trim();
                    string dateTime = ds.Tables[0].Rows[i][3].ToString().Trim();
                    string status   = ds.Tables[0].Rows[i][4].ToString().Trim();
                    string address  = ds.Tables[0].Rows[i][5].ToString().Trim();
                    string type     = ds.Tables[0].Rows[i][6].ToString().Trim();

                    // 获取用户名
                    string  sqlName = "select userName from user_info where userId = '" + int.Parse(userid) + "'";
                    DataSet dataSet = DBconn.getData(sqlName);

                    // 加载数据到列表
                    this.dataGridView1.Rows.Add(id, dataSet.Tables[0].Rows[0][0], content, dateTime, address, type, status);

                    // 设置按键背景色
                    if (status.Equals("待维修"))
                    {
                        dataGridView1.Rows[i].Cells[6].Style.BackColor = Color.Pink;
                    }
                    else
                    {
                        dataGridView1.Rows[i].Cells[6].Style.BackColor = Color.Aqua;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("获取数据失败" + ex.Message);
            }
            finally
            {
                // 关闭数据库
                DBconn.conn.Close();
            }
        }
コード例 #4
0
        // 修改按钮
        private void userGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                // 验证选择行
                if (userGridView.Columns[e.ColumnIndex].Name == "Modify" && e.ColumnIndex >= 0)
                {
                    // 获取需要修改的用户信息
                    string userId    = userGridView.CurrentRow.Cells[0].Value.ToString().Trim();
                    string userName  = userGridView.CurrentRow.Cells[1].Value.ToString().Trim();
                    string userPwd   = userGridView.CurrentRow.Cells[2].Value.ToString().Trim();
                    string userRoles = userGridView[3, e.RowIndex].EditedFormattedValue.ToString();

                    if (userName.Equals(""))
                    {
                        MessageBox.Show("用户名不能为空!");
                        return;
                    }
                    else if (userPwd.Equals(""))
                    {
                        MessageBox.Show("用户密码不能为空!");
                        return;
                    }
                    else if (userRoles.Equals(""))
                    {
                        MessageBox.Show("用户角色不能为空!");
                        return;
                    }
                    else
                    {
                        // 在数据库中修改
                        string sql = "update user_info set userName = '******', userPwd = '" + userPwd + "', roles = '" + userRoles + "' where userId = '" + int.Parse(userId) + "'";

                        //DataSet dataSet = DBconn.upData(sql);

                        if (DBconn.PDData(sql))
                        {
                            MessageBox.Show("用户:" + userName + " 修改成功");
                        }
                    }
                }
            }catch (Exception ex)
            {
                MessageBox.Show("修改失败:" + ex.Message);
            }
            finally
            {
                // 关闭数据库连接
                DBconn.conn.Close();
            }
        }
コード例 #5
0
        private void SuperAdminForm_Load(object sender, EventArgs e)
        {
            // 右下角时间控制
            this.toolStripStatusLabel1.Alignment = ToolStripItemAlignment.Right;
            this.toolStripStatusLabel1.Text      = "当前日期为:" + DateTime.Now.ToShortDateString();

            // 设置下拉列表
            this.RolesColumn.Items.Add("后勤老师");
            this.RolesColumn.Items.Add("维修工程师");
            this.RolesColumn.Items.Add("学生");

            // 设置id无法修改
            userGridView.Columns[0].ReadOnly = true;

            // 从数据库中取数据,加载到列表控件上
            try
            {
                // SQL语句
                string sql = "select * from user_info";
                // 1.连接数据库,并执行SQL语句
                DataSet dataSet = DBconn.getData(sql);

                // 2.通过for循环加载数据
                for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                {
                    // 定义字符串接收对应数据
                    string userId    = dataSet.Tables[0].Rows[i][0].ToString();
                    string userName  = dataSet.Tables[0].Rows[i][1].ToString();
                    string userPwd   = dataSet.Tables[0].Rows[i][2].ToString();
                    string userRoles = dataSet.Tables[0].Rows[i][3].ToString();


                    this.userGridView.Rows.Add(userId, userName, userPwd);

                    //MessageBox.Show( this.RolesColumn.Items[i].ToString());

                    this.userGridView.Rows[i].Cells[3].Style.NullValue = userRoles;
                    // this.userGridView.DataSource = dataSet.Tables[0];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("加载出错:" + ex.Message);
            }
            finally
            {
                // 关闭数据库连接
                DBconn.conn.Close();
            }
        }
コード例 #6
0
 // 修改按钮
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try {
         if (dataGridView1.Columns[e.ColumnIndex].Name == "ColumnRe" && e.ColumnIndex >= 0)
         {
             //说明点击的列是DataGridViewButtonColumn列
             DataGridViewColumn column = dataGridView1.Columns[e.ColumnIndex];
             // MessageBox.Show(dataGridView1.CurrentRow.Cells[0].Value.ToString());
             // 获取需要修改的状态
             string strStatus = Convert.ToString(dataGridView1.CurrentRow.Cells[6].Value);
             if (strStatus.Equals("待维修"))
             {
                 // 弹出消息框,并获取消息框的返回值
                 DialogResult dr = MessageBox.Show("是否已经维修?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                 if (dr == DialogResult.Yes)
                 {
                     // 修改状态数据库语句
                     string sql = "update repairtable set repairStatus = '" + "已维修" + "' where repairId = '" + int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()) + "'";
                     DBconn.upData(sql);
                     // 修改窗体状态语句
                     dataGridView1.CurrentRow.Cells[6].Value = "已维修";
                     dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[6].Style.BackColor = Color.Aqua;
                 }
             }
             else
             {
                 // 弹出消息框,并获取消息框的返回值
                 DialogResult dr = MessageBox.Show("是否未维修?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                 if (dr == DialogResult.Yes)
                 {
                     // 修改状态数据库语句
                     string sql = "update repairtable set repairStatus = '" + "待维修" + "'where repairId = '" + int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString()) + "'";
                     DBconn.upData(sql);
                     // 修改窗体状态语句
                     dataGridView1.CurrentRow.Cells[6].Value = "待维修";
                     dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[6].Style.BackColor = Color.Pink;
                 }
             }
         }
     }catch (Exception ex)
     {
         MessageBox.Show("修改失败" + ex.Message);
     }
     finally
     {
         // 最后关闭数据库
         DBconn.conn.Close();
     }
 }
コード例 #7
0
        /// <summary>
        /// 登录按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            try
            {
                // 1. 验证输入数据是否合法
                // 获取文本框的值
                string name = this.userName.Text.Trim();
                string pwd  = this.passWord.Text.Trim();
                string role = this.Roles.Text.Trim();

                // 验证输入的值
                if (name.Equals(""))
                {
                    MessageBox.Show("用户名不能为空!", "提示");
                    // 获取焦点
                    userName.Focus();
                    return;
                }
                else if (pwd.Equals(""))
                {
                    MessageBox.Show("密码不能为空", "提示");
                    // 获取焦点
                    passWord.Focus();
                    return;
                }
                else if (Roles.Equals(""))
                {
                    MessageBox.Show("身份不能为空", "提示");
                    // 获取焦点
                    Roles.Focus();

                    return;
                }
                // 数据库查询用户信息
                string  sqlStr = "select userName, userPwd, roles from user_info where userName = '******'";
                DataSet ds     = DBconn.getData(sqlStr);
                // 一个大坑,数据库取出来的数据的字符串中有空字符,需要使用trim()去掉

                // string roles = ds.Tables[0].Rows[0][2].ToString().Trim();
                int count = ds.Tables[0].Rows.Count;
                if (count == 0)
                {
                    MessageBox.Show("用户名不存在,请重新输入", "提示");
                    // 文本框置空
                    userName.Text = "";
                    passWord.Text = "";
                    Roles.Text    = "";
                    userName.Focus();
                }
                else if (ds.Tables[0].Rows[0][1].ToString().Trim() == pwd)
                {
                    string roles = ds.Tables[0].Rows[0][2].ToString().Trim();
                    // 验证身份
                    if (roles.Equals("后勤老师") && roles.Equals(role))
                    {
                        MessageBox.Show("恭喜您登录成功!", "提示");
                        // 验证通过,页面跳转
                        SuperAdminForm superAdminForm = new SuperAdminForm();
                        this.Hide();
                        superAdminForm.Show();
                    }
                    else if (roles.Equals("维修工程师") && roles.Equals(role))
                    {
                        MessageBox.Show("恭喜您登录成功!", "提示");
                        // 验证通过,页面跳转
                        AdminForm adminForm = new AdminForm();
                        this.Hide();
                        adminForm.Show();
                    }
                    else if (roles.Equals("学生") && roles.Equals(role))
                    {
                        // 验证通过,页面跳转
                        MessageBox.Show("恭喜您登录成功!", "提示");

                        MainForm mainForm = new MainForm();
                        mainForm.LabUser.Text = name;
                        this.Hide();
                        mainForm.Show();
                    }
                    else
                    {
                        MessageBox.Show("请正确选择您的身份!");
                        Roles.Text = "";
                        userName.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("密码错误!请重新输入!");
                    userName.Text = "";
                    passWord.Text = "";
                    Roles.Text    = "";
                    userName.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("登录异常:" + ex.Message);
                userName.Text = "";
                passWord.Text = "";
                Roles.Text    = "";
                userName.Focus();
            }
            finally
            {
                // 最后关闭数据库
                DBconn.conn.Close();
            }
        }
コード例 #8
0
ファイル: MainForm.cs プロジェクト: lijian20/RepairSystemOfC-
        private void ButRepair_Click(object sender, EventArgs e)
        {
            try
            {
                // 1.验证输入内容是否有效
                if (TextAddress.Text.Trim().Equals(""))
                {
                    MessageBox.Show("报修地点不能为空", "提示");
                    TextAddress.Focus();
                    return;
                }
                else if (TextContent.Text.Trim().Equals(""))
                {
                    MessageBox.Show("报修内容不能为空", "提示");
                    TextContent.Focus();
                    return;
                }
                else if (ComType.SelectedIndex == -1)
                {
                    MessageBox.Show("请选择报修类型", "提示");
                    ComType.Focus();
                    return;
                }
                // 验证数据库中是否已经有相同的报修
                string  id     = "select userId from user_info where userName = '******'";
                DataSet user   = DBconn.getData(id);
                string  sqlStr = "select repairId,repairCount from repairtable where userId = '" + user.Tables[0].Rows[0][0] + "'";


                DataSet ds = DBconn.getData(sqlStr);
                //如果ds里面不存在数据,说明这个用户第一次报修,直接插入新的记录
                if (ds.Tables[0].Rows.Count == 0)
                {
                    string sqlInsert = "insert into repairtable(userId,repairContent,repairDate," +
                                       "repairStatus,repairAddress,repairType,repairCount)values('" + user.Tables[0].Rows[0][0] + "','" + TextContent.Text + "','" + DateRepair.Value + "','" + "待维修" + "','" + TextAddress.Text + "','" + ComType.Text + "','" + 1 + "')";
                    DBconn.upData(sqlInsert);
                    MessageBox.Show("报修成功!");
                    ClearAll();
                }
                else
                {
                    //否则的话就是repairtable表里已经有了LanUser里的这个用户。目的就是更新这个用户的报修次数,并插入新的记录
                    int    count     = ds.Tables[0].Rows.Count;
                    string sqlInsert = "insert into repairtable(userId,repairContent,repairDate," +
                                       "repairStatus,repairAddress,repairType,repairCount)values('" + user.Tables[0].Rows[0][0] + "','" + TextContent.Text + "','" + DateRepair.Value + "','" + "待维修" + "','" + TextAddress.Text + "','" + ComType.Text + "','" + (count + 1) + "')";
                    DBconn.upData(sqlInsert);
                    MessageBox.Show("报修成功!");
                    ClearAll();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("报修出错:" + ex.Message);
                TextContent.Focus();
            }
            finally
            {
                // 最后关闭数据库
                DBconn.conn.Close();
            }
        }