DebugUI.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using DbCommon.BusinessCore.BaseCore;
  11. using DbCommon.Enties.DbModels;
  12. using ProjectManagementSystem.Common.Logger;
  13. using ProjectManagementSystem.Common.WebApi;
  14. using Pms.DataLibrary.Models;
  15. using ProjectManagementSystem.Common.Models;
  16. using Pms.DataLibrary.Order;
  17. using ProjectManagementSystem.Common.Extenions;
  18. namespace ProjectManagementSystem.UI
  19. {
  20. public partial class DebugUI : UserControl, IDisplayUI
  21. {
  22. private WareHouseManager wareHouseManager = new WareHouseManager();
  23. private LocationPropertyManager locationManager = new LocationPropertyManager();
  24. public DebugUI()
  25. {
  26. InitializeComponent();
  27. }
  28. public bool Init()
  29. {
  30. return true;
  31. }
  32. private bool InitUI()
  33. {
  34. var taskBookInfoList = PmsApi.GetTaskBookList();
  35. if (taskBookInfoList == null)
  36. {
  37. CLog.Instance.SystemLog.WriteWarn("获取任务模板失败,请检查AGVS系统是否启动!!!");
  38. }
  39. cmbTaskTemplate.DataSource = taskBookInfoList?.Select(d => d.Name).ToList();
  40. var wareHouseInfoList = PmsApi.GetWarehouseListInfo(string.Empty);
  41. if (wareHouseInfoList != null)
  42. {
  43. cmbLocationCode1.DataSource = wareHouseInfoList.Select(d => d.WareHouseID).ToList();
  44. cmbLocationCode2.DataSource = wareHouseInfoList.Select(d => d.WareHouseID).ToList();
  45. }
  46. var taskDataList = PmsApi.GetTaskList();
  47. if (taskDataList != null)
  48. {
  49. cmbParentTaskId.DataSource = taskDataList.Select(d => d.TaskID).ToList();
  50. }
  51. DataTable dt = wareHouseManager.QueryWareHouse();
  52. if (dt != null
  53. && dt.Rows.Count > 0)
  54. {
  55. this.cmbWareHouseCode.ValueMember = "WareHouseCode";
  56. this.cmbWareHouseCode.DisplayMember = "WareHouseName";
  57. this.cmbWareHouseCode.DataSource = dt;
  58. }
  59. dt = wareHouseManager.QueryWareHouse();
  60. if (dt != null
  61. && dt.Rows.Count > 0)
  62. {
  63. this.cmbTargetWareHouseCode.ValueMember = "WareHouseCode";
  64. this.cmbTargetWareHouseCode.DisplayMember = "WareHouseName";
  65. this.cmbTargetWareHouseCode.DataSource = dt;
  66. }
  67. return true;
  68. }
  69. private void button1_Click(object sender, EventArgs e)
  70. {
  71. string upLocation = cmbLocationCode1.Text.Trim();
  72. string downLocation = cmbLocationCode2.Text.Trim();
  73. string taskTemplate = cmbTaskTemplate.Text.Trim();
  74. string parentTaskId = cmbParentTaskId.Text.Trim();
  75. if (string.IsNullOrEmpty(upLocation)
  76. || string.IsNullOrEmpty(downLocation)
  77. || string.IsNullOrEmpty(taskTemplate))
  78. {
  79. ShowErrMsg("任务点或任务模板检查异常");
  80. return;
  81. }
  82. if (upLocation.Contains(" ")
  83. || downLocation.Contains(" "))
  84. {
  85. ShowErrMsg("任务点不能包含空格");
  86. return;
  87. }
  88. if (upLocation.Contains(",")
  89. || downLocation.Contains(","))
  90. {
  91. ShowErrMsg("任务点不能包含中文状态的逗号");
  92. return;
  93. }
  94. string[] posArr = ($"{upLocation},{downLocation}").ToValueArray<string>();
  95. if (posArr == null
  96. || posArr.Length == 0)
  97. {
  98. ShowErrMsg("任务点转换失败");
  99. return;
  100. }
  101. foreach (var item in posArr)
  102. {
  103. var wareHouseInfoList = PmsApi.GetWarehouseListInfo(item);
  104. if (wareHouseInfoList == null
  105. || wareHouseInfoList.Count == 0)
  106. {
  107. ShowErrMsg($"PMS中没有库位配置:{item}");
  108. return;
  109. }
  110. }
  111. var taskDataList = PmsApi.GetTaskList();
  112. if (taskDataList == null)
  113. {
  114. ShowErrMsg("获取当前任务列表失败");
  115. return;
  116. }
  117. ;
  118. int count = taskDataList
  119. .Where(d =>
  120. {
  121. foreach (var item in posArr)
  122. {
  123. if (d.AllWarehouse.Contains(item))
  124. {
  125. return true;
  126. }
  127. }
  128. return false;
  129. })
  130. .Count();
  131. if (count > 0)
  132. {
  133. ShowErrMsg("有正在执行的任务");
  134. return;
  135. }
  136. string text = $"确定要生成此任务?任务点:{string.Join(",", posArr)},任务簿:{taskTemplate},父任务ID:{parentTaskId}";
  137. var dialogResult = MessageBox.Show(text, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  138. if (dialogResult != DialogResult.OK)
  139. {
  140. return;
  141. }
  142. try
  143. {
  144. MidTaskInfoEx data = new MidTaskInfoEx();
  145. data.TemplateName = taskTemplate;
  146. data.AgvId = 0;
  147. data.AgvType = "0";
  148. for (int i = 0; i < posArr.Length; i++)
  149. {
  150. data.ParametersDic.Add($"U{i + 1}", posArr[i]);
  151. }
  152. data.Priority = 0;
  153. data.ParentTaskId = parentTaskId;
  154. bool result = PmsApi.TaskAdd(data);
  155. if (result)
  156. {
  157. ShowMsg("添加任务成功");
  158. }
  159. else
  160. {
  161. ShowErrMsg("添加任务失败");
  162. }
  163. }
  164. catch (Exception ex)
  165. {
  166. ShowErrMsg($"添加任务发生异常:{ex.Message}");
  167. }
  168. }
  169. private void ShowMsg(string text)
  170. {
  171. MessageBox.Show(text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  172. }
  173. private void ShowErrMsg(string text)
  174. {
  175. MessageBox.Show(text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  176. }
  177. public void UpdateDisplay()
  178. {
  179. }
  180. private void 更新数据ToolStripMenuItem_Click(object sender, EventArgs e)
  181. {
  182. InitUI();
  183. }
  184. private void cmbWareHouseCode_SelectedIndexChanged(object sender, EventArgs e)
  185. {
  186. ComboBox cmb = sender as ComboBox;
  187. if (cmb == null)
  188. {
  189. return;
  190. }
  191. string wHouse = cmb.SelectedValue.ToString();
  192. var nameList = locationManager.QueryDataList(wHouse)?.Select(d => d.LocationCode).ToList();
  193. nameList.Add(string.Empty);
  194. cmbLocationCode.DataSource = nameList;
  195. cmbLocationCode.SelectedIndex = cmbLocationCode.Items.Count - 1;
  196. }
  197. private void cmbTargetWareHouseCode_SelectedIndexChanged(object sender, EventArgs e)
  198. {
  199. ComboBox cmb = sender as ComboBox;
  200. if (cmb == null)
  201. {
  202. return;
  203. }
  204. string wHouse = cmb.SelectedValue.ToString();
  205. var nameList = locationManager.QueryDataList(wHouse)?.Select(d => d.LocationCode).ToList();
  206. nameList.Add(string.Empty);
  207. cmbTargetLocationCode.DataSource = nameList;
  208. cmbTargetLocationCode.SelectedIndex = cmbTargetLocationCode.Items.Count - 1;
  209. }
  210. private void button2_Click(object sender, EventArgs e)
  211. {
  212. try
  213. {
  214. PmsTaskInfo data = new PmsTaskInfo();
  215. data.WareHouseCode = cmbWareHouseCode.SelectedValue.ToString();
  216. data.LocationCode = cmbLocationCode.Text;
  217. data.TargetWareHouseCode = cmbTargetWareHouseCode.SelectedValue.ToString();
  218. data.TargetLocationCode = cmbTargetLocationCode.Text;
  219. data.MaterialId = textBoxMaterialID.Text;
  220. var result = PmsApi.CustomApiPost("TaskAdd", null, data);
  221. if (result?.code == 20000)
  222. {
  223. ShowMsg("添加任务成功");
  224. }
  225. else
  226. {
  227. ShowErrMsg($"添加任务失败,{result?.message}");
  228. }
  229. }
  230. catch (Exception ex)
  231. {
  232. ShowErrMsg($"添加任务发生异常:{ex.Message}");
  233. }
  234. }
  235. private void button3_Click(object sender, EventArgs e)
  236. {
  237. }
  238. }
  239. }