⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pspasscontrol.cs

📁 飞信的收发使用csharp进行开发
💻 CS
字号:
namespace Imps.Client.Pc.Options
{
    using Imps.Client.Core;
    using Imps.Client.Pc;
    using Imps.Client.Pc.Controls;
    using Imps.Client.Pc.Utils;
    using Imps.Client.Resource;
    using Imps.Client.Utils;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class PsPassControl : OptionsControlBase
    {
        private IFrameworkWindow _frameworkWindow;
        private XButton btnChangePassword;
        private IContainer components;
        private XLabel lbConfirmNewPassword;
        private XLabel lbNewPassword;
        private XLabel lbOldPassword;
        private XLabel lbPassword;
        private XLabel lbRule;
        private XTextBox tbNewPwd;
        private XTextBox tbNewPwdConfirm;
        private XTextBox tbOldPwd;

        public PsPassControl(IFrameworkWindow iFrameworkWindow)
        {
            this._frameworkWindow = iFrameworkWindow;
            this.InitializeComponent();
            this.SetLimitation();
        }

        private void btnChangePassword_Click(object sender, EventArgs e)
        {
            this.DoChangePassword();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void DoChangePassword()
        {
            UiErrorHelper.HandEventSafely(this._frameworkWindow, delegate {
                if (this.InnerCheckUserInput())
                {
                    this.btnChangePassword.Enabled = false;
                    AsyncBizOperation op = new AsyncBizOperation();
                    op.ImpsError += new EventHandler<ImpsErrorEventArgs>(this.op_ImpsError);
                    op.Successed += new EventHandler(this.op_Successed);
                    if (!this.CurrentUser.AsyncChangePassword(this.tbOldPwd.Text, this.tbNewPwd.Text, op))
                    {
                        this._frameworkWindow.UnifiedMessageBox.ShowError(StringTable.PersonalInfo.MsgChangePassword_Failed);
                    }
                }
            });
        }

        private void InitializeComponent()
        {
            this.lbPassword = new XLabel();
            this.lbOldPassword = new XLabel();
            this.tbOldPwd = new XTextBox();
            this.tbNewPwd = new XTextBox();
            this.lbNewPassword = new XLabel();
            this.tbNewPwdConfirm = new XTextBox();
            this.lbConfirmNewPassword = new XLabel();
            this.btnChangePassword = new XButton();
            this.lbRule = new XLabel();
            XLabel label = new XLabel();
            base.SuspendLayout();
            label.BorderStyle = BorderStyle.Fixed3D;
            label.Location = new Point(0x36, 15);
            label.Name = "lbLine";
            label.Size = new Size(300, 2);
            label.TabIndex = 1;
            this.lbPassword.AutoSize = true;
            this.lbPassword.Location = new Point(5, 9);
            this.lbPassword.Name = "lbPassword";
            this.lbPassword.Size = new Size(0x3d, 13);
            this.lbPassword.TabIndex = 0;
            this.lbPassword.Text = "lbPassword";
            this.lbOldPassword.AutoSize = true;
            this.lbOldPassword.Location = new Point(0x13, 0x22);
            this.lbOldPassword.Name = "lbOldPassword";
            this.lbOldPassword.Size = new Size(0x4d, 13);
            this.lbOldPassword.TabIndex = 2;
            this.lbOldPassword.Text = "lbOldPassword";
            this.tbOldPwd.BackColor = Color.White;
            this.tbOldPwd.BorderStyle = BorderStyle.FixedSingle;
            this.tbOldPwd.Location = new Point(0x15, 0x37);
            this.tbOldPwd.Name = "tbOldPwd";
            this.tbOldPwd.Size = new Size(0x11c, 20);
            this.tbOldPwd.TabIndex = 3;
            this.tbOldPwd.UseSystemPasswordChar = true;
            this.tbNewPwd.BackColor = Color.White;
            this.tbNewPwd.BorderStyle = BorderStyle.FixedSingle;
            this.tbNewPwd.Location = new Point(0x15, 0x6c);
            this.tbNewPwd.Name = "tbNewPwd";
            this.tbNewPwd.Size = new Size(0x11c, 20);
            this.tbNewPwd.TabIndex = 5;
            this.tbNewPwd.UseSystemPasswordChar = true;
            this.lbNewPassword.AutoSize = true;
            this.lbNewPassword.Location = new Point(0x13, 0x57);
            this.lbNewPassword.Name = "lbNewPassword";
            this.lbNewPassword.Size = new Size(0x53, 13);
            this.lbNewPassword.TabIndex = 4;
            this.lbNewPassword.Text = "lbNewPassword";
            this.tbNewPwdConfirm.BackColor = Color.White;
            this.tbNewPwdConfirm.BorderStyle = BorderStyle.FixedSingle;
            this.tbNewPwdConfirm.Location = new Point(0x15, 0xa1);
            this.tbNewPwdConfirm.Name = "tbNewPwdConfirm";
            this.tbNewPwdConfirm.Size = new Size(0x11c, 20);
            this.tbNewPwdConfirm.TabIndex = 7;
            this.tbNewPwdConfirm.UseSystemPasswordChar = true;
            this.lbConfirmNewPassword.AutoSize = true;
            this.lbConfirmNewPassword.Location = new Point(0x13, 140);
            this.lbConfirmNewPassword.Name = "lbConfirmNewPassword";
            this.lbConfirmNewPassword.Size = new Size(0x76, 13);
            this.lbConfirmNewPassword.TabIndex = 6;
            this.lbConfirmNewPassword.Text = "lbConfirmNewPassword";
            this.btnChangePassword.Location = new Point(230, 0xcb);
            this.btnChangePassword.Name = "btnChangePassword";
            this.btnChangePassword.Size = new Size(0x4b, 0x19);
            this.btnChangePassword.TabIndex = 8;
            this.btnChangePassword.UseVisualStyleBackColor = true;
            this.btnChangePassword.Click += new EventHandler(this.btnChangePassword_Click);
            this.lbRule.Location = new Point(0x15, 250);
            this.lbRule.Name = "lbRule";
            this.lbRule.Size = new Size(330, 90);
            this.lbRule.AutoSize = false;
            this.lbRule.TabIndex = 9;
            this.lbRule.Text = "lbRule";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.lbRule);
            base.Controls.Add(this.btnChangePassword);
            base.Controls.Add(this.tbNewPwdConfirm);
            base.Controls.Add(this.lbConfirmNewPassword);
            base.Controls.Add(this.tbNewPwd);
            base.Controls.Add(this.lbNewPassword);
            base.Controls.Add(this.tbOldPwd);
            base.Controls.Add(this.lbOldPassword);
            base.Controls.Add(this.lbPassword);
            base.Controls.Add(label);
            base.Name = "PsPassControl";
            base.Size = new Size(0x16b, 0x1b1);
            base.Load += new EventHandler(this.PsPassControl_Load);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private bool InnerCheckUserInput()
        {
            string text = this.tbOldPwd.Text;
            string pass = this.tbNewPwd.Text;
            if (text.Length <= 0)
            {
                BalloonHelper.ShowInputErrorBallon(this.tbOldPwd, StringTable.PersonalInfo.OldPasswordNotEmpty, StringTable.Options.TitleInvalidInput);
                return false;
            }
            if (text != this.CurrentUser.Password)
            {
                BalloonHelper.ShowInputErrorBallon(this.tbOldPwd, StringTable.PersonalInfo.OldPasswordNotCorrect, StringTable.Options.TitleInvalidInput);
                return false;
            }
            if (pass.Length <= 0)
            {
                BalloonHelper.ShowInputErrorBallon(this.tbNewPwd, StringTable.PersonalInfo.NewPasswordNotEmpty, StringTable.Options.TitleInvalidInput);
                return false;
            }
            if (text == pass)
            {
                BalloonHelper.ShowInputErrorBallon(this.tbNewPwd, StringTable.PersonalInfo.NewPasswordSameAsOld, StringTable.Options.TitleInvalidInput);
                return false;
            }
            if ((pass.Length < 6) || (pass.Length > 0x10))
            {
                BalloonHelper.ShowInputErrorBallon(this.tbNewPwd, StringTable.PersonalInfo.NewPasswordLengthInvalid, StringTable.Options.TitleInvalidInput);
                return false;
            }
            if (!ControlHelper.IsValidPassword(pass))
            {
                BalloonHelper.ShowInputErrorBallon(this.tbNewPwd, StringTable.PersonalInfo.NewPasswordInvalid, StringTable.Options.TitleInvalidInput);
                return false;
            }
            if (this.tbNewPwdConfirm.Text.Length <= 0)
            {
                BalloonHelper.ShowInputErrorBallon(this.tbNewPwdConfirm, StringTable.PersonalInfo.NewPasswordConfirmNotEmpty, StringTable.Options.TitleInvalidInput);
                return false;
            }
            if (pass != this.tbNewPwdConfirm.Text)
            {
                BalloonHelper.ShowInputErrorBallon(this.tbNewPwdConfirm, StringTable.PersonalInfo.NewPasswordDiff, StringTable.Options.TitleInvalidInput);
                return false;
            }
            return true;
        }

        private void op_ImpsError(object sender, ImpsErrorEventArgs e)
        {
            this.btnChangePassword.Enabled = true;
            this._frameworkWindow.UnifiedMessageBox.ShowError(this, StringTable.PersonalInfo.MsgChangePassword_Failed, e.ToString());
        }

        private void op_Successed(object sender, EventArgs e)
        {
            try
            {
                UserAccounts.LaststAccountNewPassword = this.tbNewPwd.Text;
                UserAccounts.SaveToLocal();
                ((EntryPointControl) this._frameworkWindow.AccountManager.EntryPointControl).LoadUserAccounts();
            }
            catch (Exception exception)
            {
                ClientLogger.WriteGeneral("Save new password failed.", exception.ToString(), 10);
            }
            this.btnChangePassword.Enabled = true;
            this.UpdateData(false);
            this._frameworkWindow.UnifiedMessageBox.ShowInfo(this, StringTable.PersonalInfo.MsgChangePassword_200);
        }

        private void PsPassControl_Load(object sender, EventArgs e)
        {
            this.lbPassword.Text = StringTable.Password.GbPasswordSecurity;
            this.lbOldPassword.Text = StringTable.Password.OldPassword;
            this.lbNewPassword.Text = StringTable.Password.NewPassword;
            this.lbConfirmNewPassword.Text = StringTable.Password.ReNewPassword;
            this.btnChangePassword.Text = StringTable.Password.BtnChangePassword;
            this.lbRule.Text = StringTable.Password.PasswordRules;
        }

        private void SetLimitation()
        {
            this.tbOldPwd.MaxLength = 0x20;
            this.tbNewPwd.MaxLength = 0x10;
            this.tbNewPwdConfirm.MaxLength = 0x10;
            ControlHelper.SetAcceptPasswordChar(this.tbNewPwd, true);
            ControlHelper.SetAcceptPasswordChar(this.tbNewPwdConfirm, true);
            ControlHelper.SetAcceptPasswordChar(this.tbOldPwd, true);
        }

        public override bool UpdateData(bool update)
        {
            if (!update)
            {
                this.tbOldPwd.Text = string.Empty;
                this.tbNewPwd.Text = string.Empty;
                this.tbNewPwdConfirm.Text = string.Empty;
            }
            base.Modified = false;
            return true;
        }

        private Imps.Client.Core.User CurrentUser
        {
            get
            {
                return this._frameworkWindow.AccountManager.CurrentUser;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -