SignInForm.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using Model;
  11. using Sunny.UI;
  12. using Sunny.UI.Win32;
  13. using Permission;
  14. using User = Model.User;
  15. using PlcUiForm;
  16. namespace YangjieTester.用户管理
  17. {
  18. [FormDescriptionAttribute("登录")]
  19. public partial class SignInForm : PlcBaseForm
  20. {
  21. public SignInForm()
  22. {
  23. InitializeComponent();
  24. }
  25. string UserName,Password;
  26. public SignInForm(string userName,string password)
  27. {
  28. UserName = userName;
  29. Password = password;
  30. InitializeComponent();
  31. }
  32. private void FormSignIn_Load(object sender, EventArgs e)
  33. {
  34. txtUsername.Text = UserName;
  35. txtPassword.Text = Password;
  36. }
  37. bool GetInputUser(out User user)
  38. {
  39. string name = txtUsername.Text.Trim();
  40. string password = txtPassword.Text.Trim();
  41. if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(password))
  42. {
  43. user = new Model.User(name, password);
  44. return true;
  45. }
  46. user = null;
  47. return false;
  48. }
  49. private void btnSignIn_Click(object sender, EventArgs e)
  50. {
  51. if(GetInputUser(out User user))
  52. {
  53. if (UserService.ValidateUser(user, out string err))
  54. {
  55. PermissionManager.SignIn(user);
  56. MessageBox.Show($"登录成功,权限:{Enum.GetName(typeof(PermissionLevel), user.PermissionLevel)}", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
  57. DialogResult = DialogResult.OK;
  58. Close();
  59. }
  60. else
  61. {
  62. MessageBox.Show($"登录失败:{err}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  63. }
  64. }
  65. }
  66. private void btnSignOut_Click(object sender, EventArgs e)
  67. {
  68. txtUsername.Text = null;
  69. txtPassword.Text = null;
  70. PermissionManager.SignOut();
  71. }
  72. private void btnSignUp_Click(object sender, EventArgs e)
  73. {
  74. new SignUpForm().ShowDialog();
  75. }
  76. }
  77. }