Нет описания

LoginWindow.xaml.cs 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Shapes;
  13. using Newtonsoft.Json.Linq;
  14. namespace WpfApplication19
  15. {
  16. /// <summary>
  17. /// Interaction logic for LoginWindow.xaml
  18. /// </summary>
  19. public partial class LoginWindow : Window
  20. {
  21. bool _isSkip = true;
  22. public LoginWindow()
  23. {
  24. InitializeComponent();
  25. userIDTextInput.Focus();
  26. }
  27. private void button2_Click(object sender, RoutedEventArgs e)
  28. {
  29. //this.Close();
  30. this.DialogResult = false;
  31. Application.Current.MainWindow.Close();
  32. }
  33. private void loginButton_Click(object sender, RoutedEventArgs e)
  34. {
  35. string data = string.Format("empid={0}&password={1}", userIDTextInput.Text, passwordBox.Password);
  36. string passwd = passwordBox.Password;
  37. WebAppConnector wp = new WebAppConnector()
  38. {
  39. Uri = Utils.getSetting("webServerURL")+"/sessions.json",
  40. Method = "POST",
  41. PostData = data
  42. };
  43. Response r = null;
  44. try {
  45. r = wp.sendRequest();
  46. }catch{
  47. if(_isSkip == false)
  48. MessageBox.Show("Cannot Send Data to Server, Please Try Again or Get Help from System Administrator");
  49. //for skip block
  50. else {
  51. this.DialogResult = true;
  52. User u = new User();
  53. u.email = "1234";
  54. u.empid = "root";
  55. u.password = "1234";
  56. u.roles.Add("admin");
  57. GlobalVars.user = u;
  58. Application.Current.MainWindow.Show();
  59. var w = (MainWindow)Application.Current.MainWindow;
  60. Close();
  61. return;
  62. }
  63. }
  64. string ans = (string)r.jsonBody["msg"];
  65. //Console.WriteLine((JArray)r.jsonBody["roles"]);
  66. if (r.status == "OK" && ans == "Y")
  67. {
  68. this.DialogResult = true;
  69. User u = new User();
  70. u.password = passwd;
  71. u.email = (string)r.jsonBody["email"];
  72. u.empid = (string)r.jsonBody["empid"];
  73. foreach (var role in r.jsonBody["roles"])
  74. {
  75. u.roles.Add((string)role);
  76. }
  77. GlobalVars.user = u;
  78. Close();
  79. Application.Current.MainWindow.Show();
  80. var w = (MainWindow)Application.Current.MainWindow;
  81. //w.UpdateStatus(u);
  82. }
  83. else
  84. {
  85. alertText.Text = "Your UserID and Password invalid!!";
  86. }
  87. }
  88. }
  89. }