UserLoginView.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Security.Cryptography;
  10. using Aitex.Core.Utilities;
  11. using Aitex.Core.RT.Log;
  12. namespace Aitex.Core.Backend
  13. {
  14. public partial class UserLoginView : Form
  15. {
  16. private UserLoginView()
  17. {
  18. InitializeComponent();
  19. AcceptButton = this.buttonLogin;
  20. CancelButton = this.buttonCancel;
  21. Load += new EventHandler(UserLoginView_Load);
  22. }
  23. void UserLoginView_Load(object sender, EventArgs e)
  24. {
  25. this.Text = "Login";
  26. }
  27. MainView _mainView;
  28. /// <summary>
  29. /// create only one instance
  30. /// </summary>
  31. static UserLoginView _instance;
  32. /// <summary>
  33. /// clear passowrd input
  34. /// </summary>
  35. private void ResetInput()
  36. {
  37. this.textBoxPassword.Clear();
  38. }
  39. protected override void OnClosing(CancelEventArgs e)
  40. {
  41. buttonCancel_Click(null, null);
  42. e.Cancel = true;
  43. base.OnClosing(e);
  44. }
  45. /// <summary>
  46. /// display this dialog
  47. /// </summary>
  48. public static void Display(bool ignorePassword)
  49. {
  50. if (_instance == null)
  51. _instance = new UserLoginView();
  52. _instance.ResetInput();
  53. if (ignorePassword)
  54. {
  55. if (_instance._mainView == null)
  56. {
  57. _instance._mainView = new MainView();
  58. }
  59. _instance._mainView.Show();
  60. return;
  61. }
  62. if (_instance._mainView != null && _instance._mainView.Visible)
  63. {
  64. _instance._mainView.Show();
  65. }
  66. else
  67. {
  68. _instance.Show();
  69. }
  70. }
  71. public static void AddCustomView(string name, UserControl uc)
  72. {
  73. if (_instance == null)
  74. _instance = new UserLoginView();
  75. if (_instance._mainView == null)
  76. _instance._mainView = new MainView();
  77. _instance._mainView.AddCustomView(name, uc);
  78. }
  79. /// <summary>
  80. /// when user click to login
  81. /// </summary>
  82. /// <param name="sender"></param>
  83. /// <param name="e"></param>
  84. private void buttonLogin_Click(object sender, EventArgs e)
  85. {
  86. var superPwd = System.Configuration.ConfigurationManager.AppSettings["Su"];
  87. var user = textBoxAccountId.Text;
  88. var pwd = textBoxPassword.Text;
  89. if (String.Compare(user, "admin", true) == 0 && Md5Helper.VerifyMd5Hash(pwd, superPwd))
  90. {
  91. LOG.Write("用户登入后台界面");
  92. if (_mainView == null) _mainView = new MainView();
  93. _mainView.Show();
  94. Hide();
  95. }
  96. else
  97. {
  98. LOG.Write("用户密码错误,登入后台界面失败");
  99. MessageBox.Show("Account name or password is error, login failed.", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  100. }
  101. }
  102. /// <summary>
  103. /// when user click to cancel
  104. /// </summary>
  105. /// <param name="sender"></param>
  106. /// <param name="e"></param>
  107. private void buttonCancel_Click(object sender, EventArgs e)
  108. {
  109. this.Hide();
  110. DialogResult = DialogResult.Cancel;
  111. }
  112. }
  113. }