革博士V2程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

125 lignes
4.0 KiB

  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.Reflection;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. //using static Google.Protobuf.Collections.MapField<TKey, TValue>;
  12. using static Org.BouncyCastle.Math.EC.ECCurve;
  13. namespace GeBoShi.UI.User
  14. {
  15. public partial class NewUserFrm : Form
  16. {
  17. UserService service = new UserService();
  18. User _User = new User();
  19. User _FatherUser;
  20. bool _isNewUser = false;
  21. public NewUserFrm(User fatherUser,User m = null )
  22. {
  23. InitializeComponent();
  24. this.uiTitel1.ShowContrlBox(false, false, true);
  25. this.uiTitel1.FatherForm = this;
  26. if (m != null)
  27. {
  28. _FatherUser = fatherUser;
  29. _User = m;
  30. this.txtCode.Enabled = false;
  31. if (_User.Code == "admin")
  32. this.txtName.Enabled = cobRoleId.Enabled = false;
  33. this.tbPassword.Enabled = false;
  34. this.tbRePassword.Enabled = false;
  35. _isNewUser = false;
  36. }
  37. else
  38. {
  39. _isNewUser = true;
  40. }
  41. _FatherUser = fatherUser;
  42. }
  43. private void InitDataView()
  44. {
  45. this.cobRoleId.DisplayMember = "Name";
  46. this.cobRoleId.ValueMember = "Id";
  47. this.cobRoleId.DataSource = service.GetRoleItems();
  48. //
  49. this.txtCode.Text = _User.Code;
  50. this.txtName.Text = _User.Name;
  51. this.txtNote.Text = _User.Note;
  52. this.cobRoleId.SelectedValue = _User.RoleId;
  53. if (!_isNewUser)
  54. this.tbPassword.Text = _User.Password;
  55. else
  56. this.tbPassword.Text = "";
  57. this.tbRePassword.Text = "";
  58. }
  59. private void NewUserFrm_Load(object sender, EventArgs e)
  60. {
  61. InitDataView();
  62. }
  63. private void btnCancel_Click(object sender, EventArgs e)
  64. {
  65. this.Close();
  66. }
  67. private void btnSave_Click(object sender, EventArgs e)
  68. {
  69. try
  70. {
  71. if((_isNewUser)&&(this.tbRePassword.Text != this.tbPassword.Text))
  72. {
  73. throw new Exception("密码和重复密码不同!");
  74. }
  75. string szCode = this.txtCode.Text.Trim();
  76. string szName = this.txtName.Text.Trim();
  77. string szNote = this.txtNote.Text.Trim();
  78. string szPw = this.tbPassword.Text.Trim();
  79. int roleId = (int)this.cobRoleId.SelectedValue;
  80. if (szCode == "" || szName == "")
  81. throw new Exception("请填写帐号和名称!");
  82. _User.Code = szCode;
  83. _User.Name = szName;
  84. _User.RoleId = roleId;
  85. _User.Note = szNote;
  86. _User.ModifyUserCode = _FatherUser.Code;
  87. bool result;
  88. if (_User.Id == 0)
  89. {
  90. _User.Password = szPw;
  91. _User.CreateUserCode = _FatherUser.Code;
  92. result = service.Insert(_User);
  93. }
  94. else
  95. result = service.Update(_User);
  96. if (!result)
  97. throw new Exception("保存失败!");
  98. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  99. this.DialogResult = DialogResult.OK;
  100. this.Close();
  101. }
  102. catch (Exception ex)
  103. {
  104. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  105. }
  106. }
  107. }
  108. }