FrmUitEdit.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.Model.AppModels.Condition.Base;
  3. using NXWMS.Client.Model.CoreModels;
  4. using NXWMS.Client.String.Enums;
  5. using NXWMS.Commons;
  6. using NXWMS.Services;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Web.UI.WebControls;
  15. using System.Windows.Forms;
  16. namespace NXWMS.Forms.Base.ChildFrm
  17. {
  18. public partial class FrmUitEdit : KryptonForm
  19. {
  20. public FrmUitEdit()
  21. {
  22. InitializeComponent();
  23. }
  24. private int _id;
  25. public EnumOperation operation { get; set; }
  26. public int Id { get => _id; set => _id = value; }
  27. private void btnExit_Click(object sender, EventArgs e)
  28. {
  29. this.DialogResult = DialogResult.Cancel;
  30. }
  31. public void InitControl()
  32. {
  33. var fieldList = new List<FieldValue>().GetFieldValueCodeList<Client.String.Enums.UnitType>();
  34. cmbUnitType.DataSource = fieldList;
  35. cmbUnitType.DisplayMember = "Name";
  36. cmbUnitType.ValueMember = "Code";
  37. cmbUnitType.SelectedIndex = -1;
  38. }
  39. private void FrmUitEdit_Shown(object sender, EventArgs e)
  40. {
  41. }
  42. private void btnSave_Click(object sender, EventArgs e)
  43. {
  44. if (string.IsNullOrWhiteSpace(txtUnitCode.Text))
  45. {
  46. KryptonMessageBox.Show($"请输入单位编码!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  47. return;
  48. }
  49. if (string.IsNullOrWhiteSpace(cmbUnitType.Text))
  50. {
  51. KryptonMessageBox.Show($"请选择单位类型!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  52. return;
  53. }
  54. switch (operation)
  55. {
  56. case EnumOperation.Add:
  57. var addResult = BaseServices.unitService.Add(new UnitCondition
  58. {
  59. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  60. IsUsed = chkUse.Checked,
  61. Describe = richDescibe.Text,
  62. UnitCode = txtUnitCode.Text,
  63. UnitName = txtUnitName.Text,
  64. UnitType = cmbUnitType.SelectedValue == null ? "" :
  65. cmbUnitType.SelectedValue.ToString(),
  66. }); ;
  67. if (addResult.Status == OperateStatus.Success)
  68. {
  69. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  70. InitControl();
  71. groupOperation.Visible = false;
  72. this.DialogResult = DialogResult.OK;
  73. }
  74. else
  75. {
  76. KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  77. }
  78. break;
  79. case EnumOperation.Edit:
  80. var editResult = BaseServices.unitService.Edit(new UnitCondition
  81. {
  82. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  83. IsUsed = chkUse.Checked,
  84. Describe = richDescibe.Text,
  85. UnitCode = txtUnitCode.Text,
  86. UnitName = txtUnitName.Text,
  87. UnitType = cmbUnitType.SelectedValue == null ? "" :
  88. cmbUnitType.SelectedValue.ToString(),
  89. Id = Id,
  90. });
  91. if (editResult.Status == OperateStatus.Success)
  92. {
  93. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  94. InitControl();
  95. groupOperation.Visible = false;
  96. this.DialogResult = DialogResult.OK;
  97. }
  98. else
  99. {
  100. KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  101. }
  102. break;
  103. }
  104. }
  105. }
  106. }