FrmParameterEdit.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.Model.AppModels.Condition.SysSettings;
  3. using NXWMS.Client.Model.AppModels.Result;
  4. using NXWMS.Client.Model.CoreModels;
  5. using NXWMS.Client.String.Enums;
  6. using NXWMS.Commons;
  7. using NXWMS.Services;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Windows.Forms;
  16. namespace NXWMS.Forms.SysSettings.ChildFrm
  17. {
  18. public partial class FrmParameterEdit : KryptonForm
  19. {
  20. private int id;
  21. private EnumOperation _operation;
  22. public FrmParameterEdit()
  23. {
  24. InitializeComponent();
  25. }
  26. public int Id { get => id; set => id = value; }
  27. public EnumOperation Operation { get => _operation; set => _operation = value; }
  28. /// <summary>
  29. /// 控件初始化
  30. /// </summary>
  31. public void InitControl()
  32. {
  33. CheckForIllegalCrossThreadCalls = false;
  34. var fieldList = new List<FieldValue>().GetFieldValueCodeList<ParameterType>();
  35. cmbParameterType.DataSource = fieldList;
  36. cmbParameterType.DisplayMember = "Name";
  37. cmbParameterType.ValueMember = "Code";
  38. cmbParameterType.SelectedIndex = -1;
  39. fieldList = new List<FieldValue>().GetFieldValueIdList<AllowEditFlagType>();
  40. chkAllowEditFlag.DataSource = fieldList;
  41. chkAllowEditFlag.DisplayMember = "Name";
  42. chkAllowEditFlag.ValueMember = "Id";
  43. chkAllowEditFlag.SelectedIndex = -1;
  44. }
  45. private void btnSave_Click(object sender, EventArgs e)
  46. {
  47. if (string.IsNullOrWhiteSpace(txtParameterCode.Text))
  48. {
  49. KryptonMessageBox.Show($"请输入参数编码。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  50. return;
  51. }
  52. if (string.IsNullOrWhiteSpace(txtParameterName.Text))
  53. {
  54. KryptonMessageBox.Show($"请输入参数名称。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  55. return;
  56. }
  57. if (string.IsNullOrWhiteSpace(txtParameterValue.Text))
  58. {
  59. KryptonMessageBox.Show($"请输入参数值。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  60. return;
  61. }
  62. if (string.IsNullOrWhiteSpace(cmbParameterType.Text))
  63. {
  64. KryptonMessageBox.Show($"请选择参数类型。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  65. return;
  66. }
  67. if (string.IsNullOrWhiteSpace(chkAllowEditFlag.Text))
  68. {
  69. KryptonMessageBox.Show($"请选择是否允许修改。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  70. return;
  71. }
  72. if (KryptonMessageBox.Show("是否保存", "提示信息", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
  73. {
  74. return;
  75. }
  76. switch (Operation)
  77. {
  78. case EnumOperation.Add:
  79. var addResult = SysSettingsServices.parameterService.Add(new ParameterCondition
  80. {
  81. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  82. IsUsed = chkUse.Checked ? false : true,
  83. ParameterCode = txtParameterCode.Text,
  84. ParameterName = txtParameterName.Text,
  85. ParameterType = cmbParameterType.SelectedValue.ToString(),
  86. AllowEditFlag = Convert.ToInt32(chkAllowEditFlag.SelectedValue.ToString()),
  87. ParameterValue = txtParameterValue.Text,
  88. Describe = richDescibe.Text,
  89. IsShow = chkShow.Checked ? false : true
  90. });
  91. if (addResult.Status == OperateStatus.Success)
  92. {
  93. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  94. this.DialogResult = DialogResult.OK;
  95. }
  96. else
  97. {
  98. KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  99. }
  100. break;
  101. case EnumOperation.Edit:
  102. var editResult = SysSettingsServices.parameterService.Edit(new ParameterCondition
  103. {
  104. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  105. IsUsed = chkUse.Checked,
  106. ParameterCode = txtParameterCode.Text,
  107. ParameterName = txtParameterName.Text,
  108. ParameterType = cmbParameterType.SelectedValue.ToString(),
  109. AllowEditFlag = Convert.ToInt32(chkAllowEditFlag.SelectedValue.ToString()),
  110. ParameterValue = txtParameterValue.Text,
  111. Describe = richDescibe.Text,
  112. IsShow = chkShow.Checked,
  113. ParameterId = Id,
  114. });
  115. if (editResult.Status == OperateStatus.Success)
  116. {
  117. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  118. this.DialogResult = DialogResult.OK;
  119. }
  120. else
  121. {
  122. KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  123. }
  124. break;
  125. }
  126. }
  127. private void btnExit_Click(object sender, EventArgs e)
  128. {
  129. this.DialogResult = DialogResult.Cancel;
  130. this.Close();
  131. }
  132. }
  133. }