Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

84 righe
2.3 KiB

  1. using System;
  2. using System.Windows.Forms;
  3. namespace StuMgmClient
  4. {
  5. public partial class LoginForm : Form
  6. {
  7. const string deaultIp = "10.10.0.44";
  8. const int deaultPort = 502;
  9. public LoginForm()
  10. {
  11. InitializeComponent();
  12. SystemComm.Init(deaultIp, deaultPort);
  13. if(SystemData.InitSystemData()!= ErrCode.Success)
  14. throw new Exception("初始化异常,请重新启动");
  15. }
  16. ////账号密码正则校验
  17. //public bool RegexUser(string u, string p)
  18. //{
  19. // var regex = new Regex("^(?![0-9]+$)(?![a-zA-Z]+$)(?![a-z!@#$]+$)(?![A-Z!@#$]+$)(?![\\d!@#$]+$)^[a-zA-Z\\d!@#$]{5,20}$");
  20. // //校验密码是否符合
  21. // bool resultU = regex.IsMatch(u);
  22. // bool resultP = regex.IsMatch(p);
  23. // if (resultU == true && resultP == true)
  24. // {
  25. // return true;
  26. // }
  27. // else
  28. // {
  29. // return false;
  30. // }
  31. //}
  32. private void chkPassWord_CheckedChanged(object sender, EventArgs e)
  33. {
  34. }
  35. private void labForgetPassword_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  36. {
  37. }
  38. private void btnSubmit_Click(object sender, EventArgs e)
  39. {
  40. Roles userRole;
  41. string token;
  42. if (VerifLogin(out userRole, out token) != ErrCode.Success)
  43. return;
  44. switch (userRole)
  45. {
  46. case Roles.Student:
  47. ShowStudentForm(token);
  48. break;
  49. default:
  50. MessageBox.Show(userRole.ToString());
  51. break;
  52. }
  53. }
  54. ErrCode VerifLogin(out Roles userRole, out string token)
  55. {
  56. ErrCode errcode = SystemCtrl.VerifLogin(txtUserName.Text, txtPassWord.Text, out userRole, out token);
  57. if (errcode != ErrCode.Success)
  58. MessageBox.Show(errcode.ToString());
  59. return errcode;
  60. }
  61. void ShowStudentForm(string token)
  62. {
  63. this.Hide();
  64. StudentForm stu = new StudentForm(token);
  65. stu.ShowDialog();
  66. this.Show();
  67. }
  68. }
  69. }