FrmMaterielEdit.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.Model.AppModels.Condition.Base;
  3. using NXWMS.Client.Model.AppModels.Result.Base;
  4. using NXWMS.Client.Model.CoreModels;
  5. using NXWMS.Client.String.Enums;
  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.Windows.Forms;
  15. namespace NXWMS.Forms.Base.ChildFrm
  16. {
  17. public partial class FrmMaterielEdit : KryptonForm
  18. {
  19. private List<MaterielTypeResult> _materielTypeList;
  20. private int _id;
  21. public EnumOperation operation { get; set; }
  22. public FrmMaterielEdit()
  23. {
  24. InitializeComponent();
  25. }
  26. public List<MaterielTypeResult> MaterielTypeList { get => _materielTypeList; set => _materielTypeList = value; }
  27. public int Id { get => _id; set => _id = value; }
  28. public void InitControl()
  29. {
  30. cmbMaterielType.DataSource = _materielTypeList;
  31. cmbMaterielType.DisplayMember = "MATERIEL_TYPE_Name";
  32. cmbMaterielType.ValueMember = "MATERIEL_TYPE_CODE";
  33. cmbMaterielType.SelectedIndex = -1;
  34. }
  35. private void FrmMaterielEdit_Shown(object sender, EventArgs e)
  36. {
  37. }
  38. private void btnSave_Click(object sender, EventArgs e)
  39. {
  40. if (string.IsNullOrWhiteSpace(txtMaterielCode.Text))
  41. {
  42. KryptonMessageBox.Show($"请输入物品编码!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  43. return;
  44. }
  45. if (string.IsNullOrWhiteSpace(cmbMaterielType.Text))
  46. {
  47. KryptonMessageBox.Show($"请选择物品类型!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  48. return;
  49. }
  50. switch (operation)
  51. {
  52. case EnumOperation.Add:
  53. var addResult = BaseServices.materielService.Add(new MaterielCondition
  54. {
  55. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  56. IsUsed = chkUse.Checked,
  57. Describe = richDescibe.Text,
  58. DelayEffectiveTime = Convert.ToInt32(numDelayEffectiveTime.Value),
  59. EffectiveTime = dtEffectiveTime.Value,
  60. Height = Convert.ToInt32(numHeight.Value),
  61. Length = Convert.ToInt32(numLength.Value),
  62. MaterielCode = txtMaterielCode.Text,
  63. MaterielName = txtMaterielName.Text,
  64. MaterielType = cmbMaterielType.SelectedValue == null ? "" :
  65. cmbMaterielType.SelectedValue.ToString(),
  66. MaxStock = numMaxStock.Value,
  67. MinStock = numMinStock.Value,
  68. OutboundEffectiveTime = dtOutboundEffectiveTime.Value,
  69. SpecsModel = txtSpecsModel.Text,
  70. UnitCode = cmbUnit.SelectedValue == null ? "" :
  71. cmbUnit.SelectedValue.ToString(),
  72. UnitPrice = numUnitPrice.Value,
  73. Volume = Convert.ToInt32(numVolume.Value),
  74. Weight = numWeight.Value,
  75. Wide = Convert.ToInt32(numWide.Value),
  76. });
  77. if (addResult.Status == OperateStatus.Success)
  78. {
  79. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  80. this.DialogResult = DialogResult.OK;
  81. }
  82. else
  83. {
  84. KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  85. }
  86. break;
  87. case EnumOperation.Edit:
  88. var editResult = BaseServices.materielService.Edit(new MaterielCondition
  89. {
  90. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  91. IsUsed = chkUse.Checked,
  92. Describe = richDescibe.Text,
  93. DelayEffectiveTime = Convert.ToInt32(numDelayEffectiveTime.Value),
  94. EffectiveTime = dtEffectiveTime.Value,
  95. Height = Convert.ToInt32(numHeight.Value),
  96. Length = Convert.ToInt32(numLength.Value),
  97. MaterielCode = txtMaterielCode.Text,
  98. MaterielName = txtMaterielName.Text,
  99. MaterielType = cmbMaterielType.SelectedValue == null ? "" :
  100. cmbMaterielType.SelectedValue.ToString(),
  101. MaxStock = numMaxStock.Value,
  102. MinStock = numMinStock.Value,
  103. OutboundEffectiveTime = dtOutboundEffectiveTime.Value,
  104. SpecsModel = txtSpecsModel.Text,
  105. UnitCode = cmbUnit.SelectedValue == null ? "" :
  106. cmbUnit.SelectedValue.ToString(),
  107. UnitPrice = numUnitPrice.Value,
  108. Volume = Convert.ToInt32(numVolume.Value),
  109. Weight = numWeight.Value,
  110. Wide = Convert.ToInt32(numWeight.Value),
  111. Id = Id,
  112. });
  113. if (editResult.Status == OperateStatus.Success)
  114. {
  115. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  116. InitControl();
  117. this.DialogResult = DialogResult.OK;
  118. }
  119. else
  120. {
  121. KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  122. }
  123. break;
  124. }
  125. }
  126. private void btnExit_Click(object sender, EventArgs e)
  127. {
  128. DialogResult = DialogResult.Cancel;
  129. this.Close();
  130. }
  131. }
  132. }