FrmUserEdit.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.Model.AppModels.Condition;
  3. using NXWMS.Client.Model.AppModels.Result;
  4. using NXWMS.Client.Model.AppModels.Result.SysSettings;
  5. using NXWMS.Client.Model.CoreModels;
  6. using NXWMS.Client.String.Enums;
  7. using NXWMS.Commons;
  8. using NXWMS.Services;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Windows.Forms;
  17. namespace NXWMS.Forms.SysSettings.ChildFrm
  18. {
  19. public partial class FrmUserEdit : KryptonForm
  20. {
  21. /// <summary>
  22. /// 界面最后执行操作
  23. /// </summary>
  24. private EnumOperation _LastOperation;
  25. private RolePermissionResult _selectRolePermission;
  26. private int _selectId;
  27. /// <summary>
  28. /// 客户端字段排序列表
  29. /// </summary>
  30. private List<ClientFieldOrderResult> _clientFieldOrderList;
  31. private int _selectMainMenuIndex;
  32. private int _selectMenuIndex;
  33. private int _selectFunctionIndex;
  34. /// <summary>
  35. /// 角色列表
  36. /// </summary>
  37. private List<RoleResult> _roleList;
  38. public FrmUserEdit()
  39. {
  40. InitializeComponent();
  41. }
  42. public void InitControl()
  43. {
  44. CheckForIllegalCrossThreadCalls = false;
  45. var fieldValueList = (from x in _roleList
  46. select new FieldValue
  47. {
  48. Code = x.ROLE_CODE,
  49. Name = x.ROLE_NAME
  50. }).ToList();
  51. cmbRole.DataSource = fieldValueList.Where((x, i) => fieldValueList.FindIndex(z => z.Code == x.Code) == i).ToList();
  52. cmbRole.DisplayMember = "Name";
  53. cmbRole.ValueMember = "Code";
  54. cmbRole.SelectedIndex = -1;
  55. cmbGender.DataSource = new List<FieldValue>().GetFieldValueIdList<GenderType>();
  56. cmbGender.DisplayMember = "Name";
  57. cmbGender.ValueMember = "Id";
  58. cmbGender.SelectedIndex = -1;
  59. txtUserCode.SetControlBase(50);
  60. txtUserName.SetControlBase(100);
  61. txtNickName.SetControlBase(50);
  62. txtIphoneNumber.SetControlBase(20);
  63. txtJobTitle.SetControlBase(50);
  64. txtEmail.SetControlBase(100);
  65. txtAddress.SetControlBase(200);
  66. }
  67. public EnumOperation Operation { get => _LastOperation; set => _LastOperation = value; }
  68. public int SelectId { get => _selectId; set => _selectId = value; }
  69. public List<RoleResult> RoleList { get => _roleList; set => _roleList = value; }
  70. private void btnSave_Click(object sender, EventArgs e)
  71. {
  72. if (string.IsNullOrWhiteSpace(txtUserCode.Text))
  73. {
  74. KryptonMessageBox.Show($"请输入用户编码。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  75. return;
  76. }
  77. if (string.IsNullOrWhiteSpace(txtUserName.Text))
  78. {
  79. KryptonMessageBox.Show($"请输入用户名称。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  80. return;
  81. }
  82. if (string.IsNullOrWhiteSpace(cmbGender.Text))
  83. {
  84. KryptonMessageBox.Show($"请选择性别。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  85. return;
  86. }
  87. switch (Operation)
  88. {
  89. case EnumOperation.Add:
  90. var addResult = SysSettingsServices.userService.Add(new UserCondition
  91. {
  92. JobTitle = txtJobTitle.Text,
  93. NickName = txtNickName.Text,
  94. Address = txtAddress.Text,
  95. PhoneNumber = txtIphoneNumber.Text,
  96. UserName = txtUserName.Text,
  97. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  98. Email = txtEmail.Text,
  99. Gender = cmbGender.SelectedValue.GetObjectToInt().Value,
  100. IsUsed = chkUse.Checked,
  101. RoleCode = cmbRole.SelectedValue.GetObjectToString(),
  102. UserCode = txtUserCode.Text,
  103. });
  104. if (addResult.Status == OperateStatus.Success)
  105. {
  106. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  107. groupOperation.Visible = false;
  108. }
  109. else
  110. {
  111. KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  112. }
  113. break;
  114. case EnumOperation.Edit:
  115. var editResult = SysSettingsServices.userService.Edit(new UserCondition
  116. {
  117. JobTitle = txtJobTitle.Text.Trim(),
  118. NickName = txtNickName.Text,
  119. Address = txtAddress.Text,
  120. PhoneNumber = txtIphoneNumber.Text,
  121. UserName = txtUserName.Text,
  122. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  123. Email = txtEmail.Text,
  124. Gender = cmbGender.SelectedValue.GetObjectToInt().Value,
  125. IsUsed = chkUse.Checked,
  126. RoleCode = cmbRole.SelectedValue.GetObjectToString(),
  127. UserId = SelectId,
  128. });
  129. if (editResult.Status == OperateStatus.Success)
  130. {
  131. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  132. groupOperation.Visible = false;
  133. }
  134. else
  135. {
  136. KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  137. }
  138. break;
  139. }
  140. DialogResult = DialogResult.OK;
  141. }
  142. private void btnExit_Click(object sender, EventArgs e)
  143. {
  144. this.Close();
  145. }
  146. }
  147. }