Ejemplo n.º 1
0
        //用户管理按钮事件
        private void btn_UserPage_Click(object sender, EventArgs e)
        {
            admin_userPage admin_UserPage = new admin_userPage(); //实例化用户管理窗体对象

            admin_UserPage.ShowDialog();                          //显示用户管理界面
        }
Ejemplo n.º 2
0
        //添加按钮
        private void btn_add_Click(object sender, EventArgs e)
        {
            //判断输入文本是否为空
            if (text_name.Text == "" || mtext_card.Text.Trim().Length < 18)
            {
                MessageBox.Show("请填写添加正确信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                string[] card_temp = mtext_card.Text.Split('-');                                      //去掉-符号
                string   card      = card_temp[0].Trim() + card_temp[1].Trim() + card_temp[2].Trim(); //组合身份证
                string   pwd       = card.Substring(card.Length - 6, 6);                              //取身份证后6位数做密码

                if (cmb_user.Text == "学生")
                {
                    //添加用户的sql语句
                    string sql = "insert into [user] (u_password,u_name,u_sex,u_card,c_id,u_position,u_number) values ('" + pwd + "','" + text_name.Text.Trim() + "','" + cmb_sex.Text + "','" + card + "','" + cmb_college.SelectedIndex + "','" + cmb_user.Text + "','5')";
                    con = dButil.SqlOpen();                                      //打开数据库
                    cmd = new SqlCommand(sql, con);                              //储存sql语句
                    int n = cmd.ExecuteNonQuery();                               //执行语句,返回成功记录进行判断
                    sql = "select u_id from [user] where u_card='" + card + "'"; //查询账号
                    cmd = new SqlCommand(sql, con);                              //储存sql语句
                    int m = Convert.ToInt32(cmd.ExecuteScalar());                //执行sql语句,获得账号
                    con.Close();                                                 //关闭数据量
                    if (n > 0)
                    {
                        SqlDbHelper dbHelper = new SqlDbHelper();              //实例化SqlDbHelper类
                        dbHelper.Operation("成功添加用户:" + text_name.Text.Trim()); //插入操作记录

                        DialogResult dialog = MessageBox.Show("添加用户:" + text_name.Text.Trim() + "成功!\n账号为" + m + "\n密码为身份证后六位\n点击确认返回用户管理界面", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        //失败提示
                        MessageBox.Show("添加失败,请检查资料!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    con.Close();//关闭数据库
                }
                else
                {
                    //添加用户的sql语句
                    string sql = "insert into [user] (u_password,u_name,u_sex,u_card,c_id,u_position,u_number) values ('" + pwd + "','" + text_name.Text.Trim() + "','" + cmb_sex.Text + "','" + cmb_college.SelectedIndex + "','" + card + "','" + cmb_user.Text + "','8')";
                    con = dButil.SqlOpen();                                      //打开数据库
                    cmd = new SqlCommand(sql, con);                              //储存sql语句
                    int n = cmd.ExecuteNonQuery();                               //执行sql语句,返回成功记录进行判断
                    sql = "select u_id from [user] where u_card='" + card + "'"; //查询账号
                    cmd = new SqlCommand(sql, con);                              //储存sql语句
                    int m = Convert.ToInt16(cmd.ExecuteScalar());                //执行sql语句,获得账号
                    con.Close();                                                 //关闭数据库
                    if (n > 0)
                    {
                        SqlDbHelper dbHelper = new SqlDbHelper();              //实例化SqlDbHelper类
                        dbHelper.Operation("成功添加用户:" + text_name.Text.Trim()); //插入操作记录

                        //成功提示
                        DialogResult dialog = MessageBox.Show("添加用户:" + text_name.Text.Trim() + "成功!\n账号为" + m + "\n密码为身份证后六位\n点击确认返回用户管理界面", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                        if (DialogResult.OK == dialog) //确认判断
                        {
                            this.Close();              //关闭窗体
                            admin_userPage admin_User = new admin_userPage();
                            admin_User.Activate();
                        }
                    }
                    else
                    {
                        //失败提示
                        MessageBox.Show("添加失败,请检查资料!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    con.Close();//关闭数据库
                }
            }
        }
Ejemplo n.º 3
0
        //确认修改按钮事件
        private void btn_edit_Click(object sender, EventArgs e)
        {
            string[] tel_temp = mtext_tel.Text.Split('-');                                        //去掉-,分成3个值储存在数组中
            string   str_tel  = tel_temp[0].Trim() + tel_temp[1].Trim() + tel_temp[2].Trim();     //进行组合成手机号

            string[] card_temp = mtext_card.Text.Split('-');                                      //去掉-,分成3个值储存在数组中
            string   str_card  = card_temp[0].Trim() + card_temp[1].Trim() + card_temp[2].Trim(); //进行组合成身份证

            if (str_tel.Trim().Length < 11 && str_tel != "")
            {
                MessageBox.Show("手机号错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (str_card.Trim().Length < 18)
            {
                MessageBox.Show("身份证错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                if (text_name.Text != "" || mtext_tel.Text != "" || mtext_card.Text != "")
                {
                    string sql = "";
                    //sql更新语句
                    if (cmb_position.Text.Equals("学生"))
                    {
                        sql = "update [user] set u_name='" + text_name.Text.Trim() + "',u_sex='" + cmb_sex.Text + "',u_tel='" + str_tel + "',u_card='" + str_card + "',u_position='" + cmb_position.Text + "',c_id='" + cmb_college.SelectedIndex + "',u_number='5' where u_id='" + text_id.Text + "'";
                    }
                    else
                    {
                        sql = "update [user] set u_name='" + text_name.Text.Trim() + "',u_sex='" + cmb_sex.Text + "',u_tel='" + str_tel + "',u_card='" + str_card + "',u_position='" + cmb_position.Text + "',c_id='" + cmb_college.SelectedIndex + "',u_number='8' where u_id='" + text_id.Text + "'";
                    }

                    con = dButil.SqlOpen();
                    cmd = new SqlCommand(sql, con); //储存sql语句
                    int n = cmd.ExecuteNonQuery();  //执行sql语句,返回影响行数判断是否修改成功
                    con.Close();                    //关闭数据库
                    if (n > 0)
                    {
                        SqlDbHelper dbHelper = new SqlDbHelper();                        //实例化SqlDbHelper类
                        dbHelper.Operation("成功修改学号/工号为:" + text_id.Text.Trim() + "的用户"); //插入操作记录

                        //修改成功进行提示
                        DialogResult dialog = MessageBox.Show("修改成功!点击确认返回用户管理界面", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        if (DialogResult.OK == dialog)
                        {
                            this.Close();
                            admin_userPage admin_User = new admin_userPage();
                            admin_User.Activate();
                        }
                    }
                    else
                    {
                        //修改失败弹出提示
                        MessageBox.Show("修改失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    //文本框内容为空弹出提示
                    MessageBox.Show("修改内容不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }