private void DoFocus() { if (string.IsNullOrEmpty(TbLoginName.Text)) { TbLoginName.Focus(); } else if (string.IsNullOrEmpty(PbPassword.Password)) { PbPassword.Focus(); } }
public InputWindow( string title, string text, string tail, Func <string, string> check, Action <string> onOk, bool isPassword) { _isPassword = isPassword; this.Title = title; InitializeComponent(); this.TbUcName.Text = nameof(InputWindow); TbTitle.Text = title; if (isPassword) { TbText.Visibility = Visibility.Collapsed; PbPassword.Visibility = Visibility.Visible; PbPassword.Password = text; } else { TbText.Text = text; } TbTail.Text = tail; var owner = WpfUtil.GetTopWindow(); if (this != owner) { this.Owner = owner; } _check = check; _onOk = onOk ?? throw new ArgumentNullException(nameof(onOk)); TimeSpan.FromMilliseconds(100).Delay().ContinueWith(t => { UIThread.Execute(() => () => { if (isPassword) { PbPassword.Focus(); } else { if (!string.IsNullOrEmpty(TbText.Text)) { TbText.SelectionStart = TbText.Text.Length; } TbText.Focus(); } }); }); }
private void SignIn(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(TbLogin.Text)) { MB.MessageBoxInfo("Введите логин"); TbLogin.Focus(); } else if (string.IsNullOrWhiteSpace(PbPassword.Password)) { MB.MessageBoxInfo("Введите пароль"); PbPassword.Focus(); } else { var employee = DataService.GetContext().Employee.FirstOrDefault(u => u.User.Login == TbLogin.Text); if (employee == null) { MB.MessageBoxInfo("Введен неверно логин/пароль"); TbLogin.Focus(); count++; } else { if (employee.User.Password != PbPassword.Password) { MB.MessageBoxInfo("Введен неверно логин/пароль"); TbLogin.Clear(); PbPassword.Clear(); count++; } else { Entity.CurrentEmployee = employee; switch (employee.User.IdRole) { case 1: new WinManager().Show(); this.Close(); break; case 2: new WinEmployee().Show(); this.Close(); break; case 3: new WinAdmin().Show(); this.Close(); break; } count = 0; } } if (count >= 3) { TbLogin.Text = string.Empty; PbPassword.Password = string.Empty; GridSignIn.Visibility = Visibility.Hidden; GridCaptcha.Visibility = Visibility.Visible; TbCaptcha.Text = Captcha.GenerateString(5); return; } } }