private void txtUserName_Validating(object sender, CancelEventArgs e) { InfoTextBox txt = (InfoTextBox)sender; if (this.canAcceptUserName(txt.Text)) { this.errorProvider.Clear(); #region 自动填写登录信息 // 如果设置文件中当前用户的状态为记住密码 var dic = CommandLine.Console.AccountDictionary; CommandLine.Console._accounts._account account = null; if (dic.ContainsKey(txt.Text)) { account = dic[txt.Text]; } if (txt == this.loginInfo_txtUserName) { if (account != null) { this.txtUserPwd.Text = account.userpwd; this.cbRememberMe.Checked = account.rememberme; this.cbAutoLogin.Checked = account.autologin; } } else if (txt == this.logoutInfo_txtUserName) { if (account != null && account.autologin) { this.logoutInfo_cbCancelAutoLogin.Enabled = true; } else { this.logoutInfo_cbCancelAutoLogin.Enabled = false; this.logoutInfo_cbCancelAutoLogin.Checked = false; } } #endregion } else { if (string.IsNullOrEmpty(txt.Text)) { this.errorProvider.SetError(txt, "请输入您的用户名。"); } else { this.errorProvider.SetError(txt, "请输入您的11位手机号码。"); } } }
private void MainForm_CurrentPagePanelChanged(object sender, ManagerPagePanelChangedEventArgs e) { if (e.NewValue != null) { if (e.NewValue == this.loginSucceededPagePanel) { this.cmsNotifyIcon_tsmiLogin.Enabled = false; this.cmsNotifyIcon_tsmiLogout.Enabled = false; this.cmsNotifyIcon_tsmiLogin.Checked = false; this.cmsNotifyIcon_tsmiLogout.Checked = false; // 在登录成功时更新用户信息。 #region 更新用户信息 var dic = CommandLine.Console.AccountDictionary; CommandLine.Console._accounts._account account; if (dic.ContainsKey(this.loginInfoPagePanel.UserName)) { account = dic[this.loginInfoPagePanel.UserName]; if (this.loginInfoPagePanel.RememberMe) { if (this.loginInfoPagePanel.AutoLogin) { foreach (var _account in CommandLine.Console.Accounts.accounts) { if (_account.autologin) { _account.autologin = false; } } } } else { dic.Remove(this.loginInfoPagePanel.UserName); } } else { account = new CommandLine.Console._accounts._account(); } account.username = this.loginInfoPagePanel.UserName; account.userpwd = this.loginInfoPagePanel.UserPwd; account.rememberme = this.loginInfoPagePanel.RememberMe; account.autologin = this.loginInfoPagePanel.AutoLogin; if (this.loginInfoPagePanel.RememberMe && !dic.ContainsKey(this.loginInfoPagePanel.UserName)) { dic.Add(this.loginInfoPagePanel.UserName, account); } CommandLine.Console.SaveConfig(); #endregion this.loginSucceededPagePanel.userName = this.loginInfoPagePanel.UserName; if (this.loginInfoPagePanel.AutoLogin) { this.loginSucceeded_cbCancelAutoLogin.Enabled = true; } else { this.loginSucceeded_cbCancelAutoLogin.Enabled = false; this.loginSucceeded_cbCancelAutoLogin.Checked = false; } this.statusBar.ShowStatus(5000, $"用户 {this.loginSucceededPagePanel.UserName} 成功登录。", this.Invoke); this.timer.Start(); var wlanInfoLines = ((ILoginSucceededPage)Program.manager.CurrentPage).WlanInfos .Select(pair => $"{pair.Key}:{pair.Value}"); this.lblWlanInfos.Text = string.Join(Environment.NewLine, wlanInfoLines.ToArray()); } else { this.cmsNotifyIcon_tsmiLogin.Enabled = true; this.cmsNotifyIcon_tsmiLogout.Enabled = true; if (e.NewValue == this.loginInfoPagePanel) { this.cmsNotifyIcon_tsmiLogout.Checked = false; this.cmsNotifyIcon_tsmiLogin.Checked = true; this.notifyIcon.Text = "Wlan-edu 登录"; } else if (e.NewValue == this.logoutInfoPagePanel) { this.cmsNotifyIcon_tsmiLogin.Checked = false; this.cmsNotifyIcon_tsmiLogout.Checked = true; this.notifyIcon.Text = "Wlan-edu 下线"; } this.statusBar.StatusBarState = StatusBarState.None; } } }