Esempio n. 1
0
        /// <summary>
        /// 点击确定按钮
        /// </summary>
        private void button3_Click(object sender, EventArgs e)
        {
            string id         = textBox1.Text;  //账号
            string name       = textBox2.Text;  //姓名
            string password   = textBox4.Text;  //用户密码
            string rePassword = textBox5.Text;  //确认密码
            string sex        = "";             //性别

            if (radioButton1.Checked)
            {
                sex = "男";
            }
            else
            {
                sex = "女";
            }
            if (id != "" && name != "" && password != "" && rePassword != "" && sex != "")
            {
                if (textBox1.Text.Length > 6)
                {
                    MessageBox.Show("账号名称过长,请重新输入!", "错误提示框", MessageBoxButtons.OK);
                    textBox1.Text = "";
                    textBox1.Focus();
                }
                else if (textBox1.Text.Length < 4)
                {
                    MessageBox.Show("账号名称过短,请重新输入!", "错误提示框", MessageBoxButtons.OK);
                    textBox1.Text = "";
                    textBox1.Focus();
                }
                else if (textBox4.Text.Length > 10)
                {
                    MessageBox.Show("密码过长,请重新输入!", "错误提示框", MessageBoxButtons.OK);
                    textBox4.Text = "";
                    textBox5.Text = "";
                    textBox4.Focus();
                }
                else if (textBox4.Text.Length < 6)
                {
                    MessageBox.Show("密码过短,请重新输入!", "错误提示框", MessageBoxButtons.OK);
                    textBox4.Text = "";
                    textBox5.Text = "";
                    textBox4.Focus();
                }
                else if (password != rePassword)
                {
                    MessageBox.Show("两次输入的密码不一致,请重新输入!", "错误提示框", MessageBoxButtons.OK);
                    textBox5.Text = "";
                    textBox5.Focus();
                }
                else
                {
                    string date = DateTime.Now.ToShortDateString().ToString();
                    //新建SQL语句
                    string mySQL = "Insert into UserInfo values('" + id + "','" + password + "','" + name + "','" + sex + "','" + date + "')";
                    //操作数据库
                    try
                    {
                        Administrator.OperateDBbyCom(mySQL);
                        MessageBox.Show("恭喜,注册成功!", "注册提示框", MessageBoxButtons.OK);
                    }
                    catch
                    {
                        MessageBox.Show("账户已存在,请重新输入!", "错误提示框", MessageBoxButtons.OK);
                        textBox1.Text = "";
                        textBox1.Focus();
                    }
                }
            }
            else
            {
                MessageBox.Show("请完整填写注册信息!", "错误提示框", MessageBoxButtons.OK);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 点击重置密码按钮
        /// </summary>
        private void button1_Click(object sender, EventArgs e)
        {
            //获取更改的账户信息
            string userName    = textBox1.Text;
            string passWord    = textBox2.Text;
            string newPasWrd   = textBox3.Text;
            string reNewPasWrd = textBox4.Text;
            //SQL语句,账户查询
            string mySQL1 = "select UserId from UserInfo where UserId = '" + userName + "'";
            //SQL语句,账户密码查询
            string mySQL2 = "select UserPwd from UserInfo where UserId = '" + userName + "'";

            if (userName != "" && passWord != "" && newPasWrd != "" && reNewPasWrd != "")
            {
                //获取查询后的数据
                operateResult = Administrator.OperateDB(mySQL1);
                daSe          = (DataSet)operateResult[1];

                if (daSe.Tables["information"].Rows.Count == 0)
                {
                    MessageBox.Show("用户不存在!", "错误提示", MessageBoxButtons.OK);
                    //重置窗体
                    textBox1.Text = "";
                    textBox2.Text = "";
                    textBox3.Text = "";
                    textBox4.Text = "";
                    textBox1.Focus();
                }
                else if (textBox3.Text.Length > 10)
                {
                    MessageBox.Show("密码长度超过10位,请重新输入!", "错误提示框", MessageBoxButtons.OK);
                    textBox3.Text = "";
                    textBox4.Text = "";
                    textBox3.Focus();
                }
                else if (textBox3.Text.Length < 6)
                {
                    MessageBox.Show("密码长度不足6位,请重新输入!", "错误提示框", MessageBoxButtons.OK);
                    textBox3.Text = "";
                    textBox4.Text = "";
                    textBox3.Focus();
                }
                else if (newPasWrd != reNewPasWrd)
                {
                    MessageBox.Show("两次输入的重设密码不一致!", "错误提示", MessageBoxButtons.OK);
                    //初始化窗体
                    textBox3.Text = "";
                    textBox4.Text = "";
                    textBox3.Focus();
                }
                else
                {
                    operateResult = Administrator.OperateDB(mySQL2);
                    daSe          = (DataSet)operateResult[1];
                    if (daSe.Tables["information"].Rows[0][0].ToString() != passWord)
                    {
                        MessageBox.Show("原始密码错误,请重新输入!", "错误提示", MessageBoxButtons.OK);
                        //初始化窗体
                        textBox2.Text = "";
                        textBox2.Focus();
                    }
                    else
                    {
                        //SQL语句,更新密码
                        string mySQL3 = "update UserInfo set UserPwd = '" + textBox3.Text + "' where UserId = '" + userName + "'";
                        Administrator.OperateDBbyCom(mySQL3);
                        MessageBox.Show("密码更改成功!", "提示", MessageBoxButtons.OK);
                        //重置窗体
                        textBox1.Text = "";
                        textBox2.Text = "";
                        textBox3.Text = "";
                        textBox4.Text = "";
                        textBox1.Focus();
                    }
                }
            }
            else
            {
                MessageBox.Show("请填写完整的信息!", "错误提示", MessageBoxButtons.OK);
            }
        }