Ejemplo n.º 1
0
        private bool OkClick = false;//定义给bool值,进行判断是否点击了返回按钮

        //重置密码的按钮事件
        private void btn_NetStep_Click(object sender, EventArgs e)
        {
            SqlDbHelper sqlDbHelper = new SqlDbHelper();     //类的实例创建
            string      name_id     = text_name.Text.Trim(); //获得学号
            string      name_card   = text_card.Text.Trim(); //获得身份证

            //判断
            if (name_id == "" || name_card == "")
            {
                //错误提示
                MessageBox.Show("请输入账号、身份证", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (name_card.Length < 18)//判断身份证是否有18位
            {
                //错误提示
                MessageBox.Show("身份证号码未达到18位", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //sql查询语句
                String sql = "select u_card from [user] where u_id=" + name_id;
                int    n   = sqlDbHelper.Checkcard(sql, name_card);//传递参数进行判断
                if (n == 2)
                {
                    string card = name_card.Substring(name_card.Length - 6);//取得身份证后六位
                    sql = "update [user] set u_password='******' where u_id='" + name_id + "'";
                    bool b_card = sqlDbHelper.EditPwd(sql);
                    if (b_card == true)
                    {
                        //弹窗提示
                        MessageBox.Show("密码重置成功,为身份证后六位", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        //弹窗提示
                        MessageBox.Show("密码重置失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else if (n == 1)
                {
                    //身份证错误提示
                    MessageBox.Show("身份证错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    text_card.Text = ""; //清空身份证
                    text_card.Focus();   //获得身份证输入焦点
                }
                else
                {
                    //账号不存在提示
                    MessageBox.Show("账号不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    text_name.Text = ""; //清空账号
                    text_card.Text = ""; //清空身份证
                    text_name.Focus();   //获得账号输入焦点
                }
            }
        }