using System;
using System.Windows.Forms;
using CRVM.Entity;
using CRVM.CIDExcuter;

namespace CRVM
{
    public partial class SetPasswordForm : Form
    {

        public SetPasswordForm()
        {
            InitializeComponent();
        }

        private void cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //20151101 jxp  
        private void Setpassword_Load(object sender, EventArgs e)
        {
            this.old_pswd.PasswordChar = '*';
            this.new_pswd.PasswordChar = '*';
            this.again_pswd.PasswordChar = '*';
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (DbHelper.GetInstance("").IsUser(old_pswd.Text.Trim()))
            {
                if (SysParam.Instance.DataIsMatch(old_pswd.Text.Trim(), "^[a-zA-Z0-9]{6,16}$") == false)
                {
                    MessageBox.Show("您输入的新密码格式不对，需为6~16字母与数字的组合！");
                    this.new_pswd.Text = "";
                    again_pswd.Text = "";
                }
                else
                {
                    if (new_pswd.Text.Trim() != again_pswd.Text.Trim())
                    {
                        MessageBox.Show("您两次输入的密码不一致，请重新输入！");
                        again_pswd.Text = "";
                    }
                    else
                    {
                        DbHelper.GetInstance("").ChangePassWord(new_pswd.Text.Trim());
                        MessageBox.Show("密码修改成功！");
                    }
                }
            }
            else
            {
                MessageBox.Show("原始密码错误！");
            }
        }
    }
}
