SignUpForm.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Model;
  2. using Permission;
  3. using PlcUiForm;
  4. using Sunny.UI;
  5. using Sunny.UI.Win32;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  16. using User = Model.User;
  17. namespace YangjieTester.用户管理
  18. {
  19. [FormDescriptionAttribute("用户注册")]
  20. public partial class SignUpForm : PlcBaseForm
  21. {
  22. public SignUpForm()
  23. {
  24. InitializeComponent();
  25. }
  26. private void FormSignIn_Load(object sender, EventArgs e)
  27. {
  28. cobLevel.Items.Clear();
  29. cobLevel.DataSource=new List<PermissionLevel>() { PermissionLevel.操作工, PermissionLevel.工程师, PermissionLevel.技术员, PermissionLevel.管理员};
  30. if (cobLevel.Items.Count > 0)
  31. cobLevel.SelectedIndex = 0;
  32. }
  33. bool GetInputUser(out User user)
  34. {
  35. string name = txtUsername.Text.Trim();
  36. string password1 = txtPassword1.Text.Trim();
  37. string password2 = txtPassword2.Text.Trim();
  38. var level = (PermissionLevel)cobLevel.SelectedItem;
  39. if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(password1) && !string.IsNullOrEmpty(password2))
  40. {
  41. if (password1.Equals(password2))
  42. {
  43. user = new Model.User(name, password1, level);
  44. return true;
  45. }
  46. }
  47. user = null;
  48. return false;
  49. }
  50. private void btnSignUp_Click(object sender, EventArgs e)
  51. {
  52. if (GetInputUser(out User user))
  53. {
  54. if(user.PermissionLevel>= AppSession.CurrentUser.PermissionLevel)
  55. {
  56. MessageBox.Show($"新注册的用户权限必须低于当前用户权限等级:{AppSession.CurrentUser.PermissionLevel}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  57. return;
  58. }
  59. if(UserService.RegisterUser(user,out string err))
  60. {
  61. MessageBox.Show("注册成功","",MessageBoxButtons.OK,MessageBoxIcon.Information);
  62. }
  63. else
  64. {
  65. MessageBox.Show($"注册失败:{err}","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
  66. }
  67. }
  68. else
  69. {
  70. MessageBox.Show($"输入信息错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  71. }
  72. }
  73. private void btnCancel_Click(object sender, EventArgs e)
  74. {
  75. Close();
  76. }
  77. }
  78. }