LoginScreen.xaml.cs 2.0 KB

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