Exemplo n.º 1
0
        /// <summary>
        /// 确认按钮按下
        /// </summary>
        private void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            string oldPwd = txtOldPwd.Password;

            // 如果是第一次设置密码的情况
            if (btnConfirm.Content.ToString() == "下一步")
            {
                // 加载自定义窗口
                UserDefined win = new UserDefined();
                win.IsFirstFlg = true;
                win.Show();
                // 关闭该窗口
                this.Close();
            }

            // 检查是否是首次使用
            bool isFirst = service.IsFirst();

            if (isFirst || service.CheckPwdOK(oldPwd))
            {
                if (txtNewPwd.Password == txtNewPwdConfirm.Password)
                {
                    string pwd = txtNewPwd.Password;
                    if (Regex.IsMatch(pwd, @"^[A-Za-z0-9]{4,20}$"))
                    {
                        if (service.SetPwd(txtNewPwd.Password))
                        {
                            if (isFirst)
                            {
                                lblMessage.Content = "密码设置成功";
                                btnConfirm.Content = "下一步";
                            }
                            else
                            {
                                this.Close();
                                Message.ShowMessage("密码重置成功,请重新登录", this, shutdownFlg: true);
                                // 回到登录界面
                                ReLogin();
                            }
                        }
                    }
                    else
                    {
                        lblMessage.Content    = "密码仅限4-20位大小写字母及数字";
                        lblMessage.Foreground = Brushes.Red;
                    }
                }
                else
                {
                    lblMessage.Content    = "两次输入不一致,请重新输入";
                    lblMessage.Foreground = Brushes.Red;
                }
            }
            else
            {
                lblMessage.Content    = "原密码错误,请重新输入";
                lblMessage.Foreground = Brushes.Red;
            }
        }