コード例 #1
0
        private void button1_Click(object sender, EventArgs e)//密码修改 “确定”
        {
            if (this.textBox1.Text == "")
            {
                MessageBox.Show("请输入原密码!");
                return;
            }
            if (this.textBox2.Text == "")
            {
                MessageBox.Show("请输入新密码!");
                return;
            }
            if (this.textBox3.Text == "")
            {
                MessageBox.Show("请再次输入新密码!");
                return;
            }
            if (this.textBox2.Text != this.textBox3.Text)
            {
                MessageBox.Show("密码错误!请重新确认新密码!");
                this.textBox3.Text = "";
                return;
            }
            if (this.textBox1.Text == this.textBox2.Text)
            {
                MessageBox.Show("新旧密码相同!请重置");
                this.textBox2.Text = "";
                this.textBox3.Text = "";
                return;
            }
            string sqlforUpdate = string.Format("UPDATE " + ConfigurationManager.AppSettings["Table"] + " SET password ='******'where password='******'");

            if (MysqlHelper.ExecuteNonQuery(sqlforUpdate) == 1)
            {
                MessageBox.Show("修改成功!");
                ShowAllUsers();//显示当前最新所有用户
            }
        }
コード例 #2
0
        private void button2_Click(object sender, EventArgs e)// 新建用户 保存
        {
            if (this.textBox4.Text == "")
            {
                MessageBox.Show("用户名不能为空!");
                return;
            }
            if (this.textBox5.Text == "")
            {
                MessageBox.Show("密码不能为空!");
                return;
            }
            if (this.textBox6.Text == "")
            {
                MessageBox.Show("请再次输入密码!");
                return;
            }
            if (this.textBox5.Text != this.textBox6.Text)
            {
                MessageBox.Show("密码错误!请重新确认新密码!");
                this.textBox6.Text = "";
                return;
            }
            int userRole = -1;

            if (this.radioButton1.Checked)
            {
                userRole = 0;
            }
            else
            {
                if (radioButton2.Checked)
                {
                    userRole = 1;
                }
                else
                {
                    if (radioButton3.Checked)
                    {
                        userRole = 2;
                    }
                    else
                    {
                        MessageBox.Show("请选择用户角色!");
                        return;
                    }
                }
            }
            string sqlforCheck = string.Format("SELECT * FROM " + ConfigurationManager.AppSettings["Table"] + " WHERE name='" + this.textBox4.Text + "'");
            string sqlforAdd   = string.Format("INSERT INTO " + ConfigurationManager.AppSettings["Table"] + "(name,password,role) VALUES('" + this.textBox4.Text + "','" + this.textBox5.Text + "'," + userRole + ")");

            if (MysqlHelper.ExecuteScalar(sqlforCheck) != null)
            {
                MessageBox.Show("用户名已存在!");
                this.textBox4.Text = "";
                this.textBox5.Text = "";
                this.textBox6.Text = "";
                return;
            }
            else
            {
                if (MysqlHelper.ExecuteNonQuery(sqlforAdd) == 1)
                {
                    MessageBox.Show("保存成功!");
                    ShowAllUsers();//显示当前最新所有用户
                }
            }
        }