LoginScreen.xaml.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Automation.Peers;
  4. using System.Windows.Automation.Provider;
  5. using System.Windows.Controls;
  6. using System.Windows.Input;
  7. using InABox.Clients;
  8. using InABox.Wpf;
  9. using InABox.WPF;
  10. using ValidationResult = InABox.Clients.ValidationResult;
  11. namespace PRSDesktop
  12. {
  13. /// <summary>
  14. /// Interaction logic for LoginScreen.xaml
  15. /// </summary>
  16. public partial class LoginScreen : ThemableWindow
  17. {
  18. public LoginScreen()
  19. {
  20. InitializeComponent();
  21. }
  22. public string UserID
  23. {
  24. get => editUser.Text;
  25. set => editUser.Text = value;
  26. }
  27. public string Password
  28. {
  29. get => editPassword.Password;
  30. set => editPassword.Password = value;
  31. }
  32. private void editUser_TextChanged(object sender, TextChangedEventArgs e)
  33. {
  34. }
  35. private void btnOK_Click(object sender, RoutedEventArgs e)
  36. {
  37. Progress.Show("Logging In");
  38. try
  39. {
  40. var valid = ClientFactory.Validate(editUser.Text, editPassword.Password);
  41. Progress.Close();
  42. if (valid == ValidationResult.VALID)
  43. {
  44. DialogResult = true;
  45. Close();
  46. }
  47. }
  48. catch (Exception err)
  49. {
  50. Progress.Close();
  51. MessageBox.Show(err.Message);
  52. }
  53. }
  54. private void btnCancel_Click(object sender, RoutedEventArgs e)
  55. {
  56. DialogResult = false;
  57. Close();
  58. }
  59. private void EditPassword_KeyUp(object sender, KeyEventArgs e)
  60. {
  61. e.Handled = true;
  62. if (e.Key == Key.Enter || e.Key == Key.Return)
  63. {
  64. var peer = new ButtonAutomationPeer(btnOK);
  65. var invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
  66. invokeProv.Invoke();
  67. }
  68. }
  69. }
  70. }