FormPmsTaskInfo.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using DbCommon.BusinessCore.BaseCore;
  2. using DbCommon.Enties.DbModels;
  3. using ProjectManagementSystem.Common.Extenions;
  4. using ProjectManagementSystem.Common.WebApi;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace ProjectManagementSystem.Forms
  15. {
  16. public partial class FormPmsTaskInfo : Form
  17. {
  18. public PmsTaskInfo PmsTask { get; set; }
  19. public bool IsAppointment { get; set; }
  20. public string CurrentButtonText { get; set; }
  21. private WareHouseManager wareHouseManager = new WareHouseManager();
  22. private LocationPropertyManager locationManager = new LocationPropertyManager();
  23. private MaterialDetailManager materialDetailManager = new MaterialDetailManager();
  24. public FormPmsTaskInfo()
  25. {
  26. InitializeComponent();
  27. }
  28. public void Init(object sender, LocationProperty locationData)
  29. {
  30. CurrentButtonText = (sender as Control).Text;
  31. if(CurrentButtonText.Contains("预约"))
  32. {
  33. IsAppointment = true;
  34. }
  35. if(CurrentButtonText.Contains("叫料"))
  36. {
  37. InitCallMaterial(sender, locationData);
  38. }
  39. else if(CurrentButtonText.Contains("转运"))
  40. {
  41. InitTransferMaterial(sender, locationData);
  42. }
  43. }
  44. private void InitWareHouse(ComboBox cmb, string[] wareHouseCodes = null)
  45. {
  46. var dt = wareHouseCodes == null ?
  47. wareHouseManager.GetList() : wareHouseManager.QueryWareHouseList(wareHouseCodes);
  48. if (dt != null
  49. && dt.Count > 0)
  50. {
  51. cmb.ValueMember = "WareHouseCode";
  52. cmb.DisplayMember = "WareHouseName";
  53. cmb.DataSource = dt;
  54. }
  55. button1.Text = CurrentButtonText;
  56. }
  57. private bool InitCallMaterial(object sender, LocationProperty locationData)
  58. {
  59. PmsTask = new PmsTaskInfo();
  60. PmsTask.TargetWareHouseCode = locationData.WareHouseCode;
  61. PmsTask.TargetLocationCode = locationData.LocationCode;
  62. InitWareHouse(cmbTargetWareHouseCode);
  63. this.cmbTargetWareHouseCode.SelectedValue = PmsTask.TargetWareHouseCode;
  64. this.cmbTargetLocationCode.SelectedItem = PmsTask.TargetLocationCode;
  65. var data = wareHouseManager.GetById(PmsTask.TargetWareHouseCode);
  66. string[] wareHouseCodes = data.SourceWareHouseCode.ToValueArray<string>();
  67. InitWareHouse(cmbWareHouseCode, wareHouseCodes);
  68. this.label8.Enabled = false;
  69. this.label9.Enabled = false;
  70. this.cmbTargetWareHouseCode.Enabled = false;
  71. this.cmbTargetLocationCode.Enabled = false;
  72. return true;
  73. }
  74. private bool InitTransferMaterial(object sender, LocationProperty locationData)
  75. {
  76. PmsTask = new PmsTaskInfo();
  77. PmsTask.WareHouseCode = locationData.WareHouseCode;
  78. PmsTask.LocationCode = locationData.LocationCode;
  79. InitWareHouse(cmbWareHouseCode);
  80. this.cmbWareHouseCode.SelectedValue = PmsTask.WareHouseCode;
  81. this.cmbLocationCode.SelectedItem = PmsTask.LocationCode;
  82. var data = wareHouseManager.GetById(PmsTask.WareHouseCode);
  83. string[] wareHouseCodes = data.TargetWareHouseCode.ToValueArray<string>();
  84. InitWareHouse(cmbTargetWareHouseCode, wareHouseCodes);
  85. this.label5.Enabled = false;
  86. this.label7.Enabled = false;
  87. this.cmbWareHouseCode.Enabled = false;
  88. this.cmbLocationCode.Enabled = false;
  89. this.label6.Enabled = false;
  90. this.cmbMaterialId.Enabled = false;
  91. return true;
  92. }
  93. private void button1_Click(object sender, EventArgs e)
  94. {
  95. try
  96. {
  97. string text = $"确定要{button1.Text}?";
  98. var dialogResult = MessageBox.Show(text, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  99. if (dialogResult != DialogResult.OK)
  100. {
  101. return;
  102. }
  103. string apiName = IsAppointment ? "TaskAppointment" : "TaskAdd";
  104. PmsTaskInfo data = new PmsTaskInfo();
  105. data.WareHouseCode = cmbWareHouseCode.SelectedValue?.ToString();
  106. data.LocationCode = cmbLocationCode.Text;
  107. data.TargetWareHouseCode = cmbTargetWareHouseCode.SelectedValue?.ToString();
  108. data.TargetLocationCode = cmbTargetLocationCode.Text;
  109. data.MaterialId = cmbMaterialId.Text;
  110. var result = PmsApi.CustomApiPost(apiName, null, data);
  111. if (result?.code == 20000)
  112. {
  113. ShowMsg($"{button1.Text}成功,{result?.message}");
  114. this.Close();
  115. }
  116. else
  117. {
  118. ShowErrMsg($"{button1.Text}失败,{result?.message}");
  119. }
  120. }
  121. catch (Exception ex)
  122. {
  123. ShowErrMsg($"{CurrentButtonText}过程发生异常:{ex.Message}");
  124. }
  125. }
  126. private void ShowMsg(string text)
  127. {
  128. MessageBox.Show(text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  129. }
  130. private void ShowErrMsg(string text)
  131. {
  132. MessageBox.Show(text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  133. }
  134. private void cmbWareHouseCode_SelectedIndexChanged(object sender, EventArgs e)
  135. {
  136. string wHouse = cmbWareHouseCode.SelectedValue.ToString();
  137. var nameList = locationManager.QueryDataList(wHouse)?.Select(d => d.LocationCode).ToList();
  138. nameList.Add(string.Empty);
  139. cmbLocationCode.DataSource = nameList;
  140. cmbLocationCode.SelectedIndex = cmbLocationCode.Items.Count - 1;
  141. //获取取货仓库所有的物料
  142. var materialList = locationManager.GetList(d => d.WareHouseCode == wHouse && !string.IsNullOrEmpty(d.MaterialId))?
  143. .Select(d => d.MaterialId)
  144. .Distinct()
  145. .ToList();
  146. var materialList2 = materialDetailManager.GetList()
  147. .Select(d => d.MaterialId)
  148. .Distinct()
  149. .ToList();
  150. materialList.AddRange(materialList2);
  151. materialList = materialList.Distinct().ToList();
  152. materialList.Add(string.Empty);
  153. cmbMaterialId.DataSource = materialList;
  154. cmbMaterialId.SelectedIndex = cmbMaterialId.Items.Count - 1;
  155. }
  156. private void cmbTargetWareHouseCode_SelectedIndexChanged(object sender, EventArgs e)
  157. {
  158. string wHouse = cmbTargetWareHouseCode.SelectedValue.ToString();
  159. var nameList = locationManager.QueryDataList(wHouse)?.Select(d => d.LocationCode).ToList();
  160. nameList.Add(string.Empty);
  161. cmbTargetLocationCode.DataSource = nameList;
  162. cmbTargetLocationCode.SelectedIndex = cmbTargetLocationCode.Items.Count - 1;
  163. }
  164. private void cmbLocationCode_SelectedIndexChanged(object sender, EventArgs e)
  165. {
  166. if (!string.IsNullOrEmpty(cmbLocationCode.Text))
  167. {
  168. cmbMaterialId.Text = locationManager.GetById(cmbLocationCode.Text)?.MaterialId;
  169. }
  170. }
  171. }
  172. }