DebugExceptionTaskUI.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. using DbCommon.BusinessCore.BaseCore;
  2. using Pms.DataLibrary.Models;
  3. using Pms.DataLibrary.Order;
  4. using ProjectManagementSystem.Common.Extenions;
  5. using ProjectManagementSystem.Common.Models;
  6. using ProjectManagementSystem.Common.Service;
  7. using ProjectManagementSystem.Common.WebApi;
  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.Threading.Tasks;
  16. using System.Windows.Forms;
  17. namespace ProjectManagementSystem.UI
  18. {
  19. public partial class DebugExceptionTaskUI : UserControl, IDisplayUI
  20. {
  21. private MaterialBindingManager materialBindingManager;
  22. public DebugExceptionTaskUI()
  23. {
  24. InitializeComponent();
  25. }
  26. public bool Init()
  27. {
  28. materialBindingManager = new MaterialBindingManager();
  29. dataGridUI1.dataGridView1.CellClick += DataGridView1_CellClick;
  30. return true;
  31. }
  32. private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
  33. {
  34. string taskId = dataGridUI1.GetCurrentColValue("TaskID");
  35. if (string.IsNullOrEmpty(taskId)) return;
  36. var stepInfoList = PmsApi.GetHistoryStepList(taskId);
  37. if (stepInfoList == null) return;
  38. var posArray = stepInfoList
  39. .Where(d => !string.IsNullOrEmpty(d.WareHouseID))
  40. .OrderBy(d => d.StepID)
  41. .Select(d => d.WareHouseID)
  42. .ToArray();
  43. //comboBox2.Items.AddRange(posArray);
  44. comboBox1.Text = taskId;
  45. comboBox2.Text = posArray.First();
  46. comboBox3.Text = posArray.Last();
  47. }
  48. public void UpdateDisplay()
  49. {
  50. if (!this.Visible) return;
  51. string taskId = dataGridUI1.GetCurrentColValue("TaskID");
  52. string taskId_StepList = dataGridUI2.GetCurrentColValue("TaskID");
  53. if(!string.IsNullOrEmpty(taskId_StepList)
  54. && taskId == taskId_StepList)
  55. {
  56. return;
  57. }
  58. if (string.IsNullOrEmpty(taskId))
  59. {
  60. dataGridUI2.ShowDataGrid<StepData>(null);
  61. return;
  62. }
  63. var stepInfoList = PmsApi.GetHistoryStepList(taskId);
  64. if (stepInfoList == null) return;
  65. dataGridUI2.ShowDataGrid(stepInfoList.OrderBy(d => d.StepID).ToList());
  66. }
  67. private async void button1_Click(object sender, EventArgs e)
  68. {
  69. try
  70. {
  71. var startTime = DateTime.Now.AddDays(-1).Date;
  72. var endTime = DateTime.Now.AddDays(1).Date;
  73. if (endTime <= startTime)
  74. {
  75. MessageBox.Show("结束时间必须晚于开始时间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  76. return;
  77. }
  78. (sender as Control).Enabled = false;
  79. var lists = await Task.Run(() =>
  80. {
  81. var taskDataList = PmsApi.GetHistoryTaskList(startTime, endTime);
  82. if (taskDataList == null) return taskDataList;
  83. taskDataList = taskDataList.Where(d => d.TaskState != ETaskState.Finished).ToList();
  84. foreach (var item in taskDataList)
  85. {
  86. item.AllWarehouse = item.AllWarehouse.ToShortPosString();
  87. }
  88. return taskDataList;
  89. });
  90. if (lists == null) return;
  91. dataGridUI1.ShowDataGrid(lists);
  92. }
  93. catch (Exception ex)
  94. {
  95. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  96. }
  97. (sender as Control).Enabled = true;
  98. }
  99. private void button2_Click(object sender, EventArgs e)
  100. {
  101. using (SaveFileDialog dialog = new SaveFileDialog())
  102. {
  103. dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  104. dialog.FileName = string.Format("历史数据_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss"));
  105. dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|所有文件(*.*)|*.*";
  106. dialog.ValidateNames = true;
  107. dialog.CheckPathExists = true;
  108. dialog.AddExtension = true;
  109. DialogResult dialogResult = dialog.ShowDialog();
  110. if (dialogResult == DialogResult.OK)
  111. {
  112. try
  113. {
  114. var dataList = dataGridUI1.GetDataTable();
  115. Common.Config.ExcelConfig.Instance.SaveExcel(dialog.FileName, dataList);
  116. MessageBox.Show("导出成功!");
  117. }
  118. catch (Exception ex)
  119. {
  120. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  121. }
  122. }
  123. }
  124. }
  125. private async void button5_Click(object sender, EventArgs e)
  126. {
  127. try
  128. {
  129. string taskId = comboBox1.Text;
  130. string currentPos = comboBox2.Text;
  131. if (string.IsNullOrEmpty(taskId) || string.IsNullOrEmpty(currentPos)) return;
  132. string allWarehouse = dataGridUI1.GetCurrentColValue("AllWarehouse");
  133. string text = $"确定要{(sender as Control).Text} {taskId}?({currentPos})";
  134. var dialogResult = MessageBox.Show(text, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  135. if (dialogResult != DialogResult.OK)
  136. {
  137. return;
  138. }
  139. (sender as Control).Enabled = false;
  140. var ret = await Task.Run(() =>
  141. {
  142. return AgvCallback(taskId, currentPos, "outbin");
  143. });
  144. MessageBox.Show($"{ret.Item2}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  145. }
  146. catch (Exception ex)
  147. {
  148. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  149. }
  150. (sender as Control).Enabled = true;
  151. }
  152. private async void button3_Click(object sender, EventArgs e)
  153. {
  154. try
  155. {
  156. string taskId = comboBox1.Text;
  157. string endPos = comboBox3.Text;
  158. if (string.IsNullOrEmpty(taskId) || string.IsNullOrEmpty(endPos)) return;
  159. string allWarehouse = dataGridUI1.GetCurrentColValue("AllWarehouse");
  160. string text = $"确定要{(sender as Control).Text} {taskId}?({allWarehouse})";
  161. var dialogResult = MessageBox.Show(text, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  162. if (dialogResult != DialogResult.OK)
  163. {
  164. return;
  165. }
  166. (sender as Control).Enabled = false;
  167. var ret = await Task.Run(() =>
  168. {
  169. return AgvCallback(taskId, endPos, "end");
  170. });
  171. MessageBox.Show($"{ret.Item2}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  172. }
  173. catch (Exception ex)
  174. {
  175. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  176. }
  177. (sender as Control).Enabled = true;
  178. }
  179. private (bool, string) AgvCallback(string taskId, string currentPosition, string method)
  180. {
  181. var t = PmsTaskService.Instance.GetTaskState(taskId);
  182. if (t == null)
  183. {
  184. return (false, "获取任务状态失败");
  185. }
  186. t.currentPositionCode = currentPosition;
  187. t.method = method;
  188. bool result = CustomerApi.AgvCallback(t, out string content);
  189. return (true, $"任务状态上报{result.ToChineseString()} {content}");
  190. }
  191. private async void button4_Click(object sender, EventArgs e)
  192. {
  193. try
  194. {
  195. string taskId = comboBox1.Text;
  196. string startPos = comboBox2.Text;
  197. string endPos = comboBox3.Text;
  198. if (string.IsNullOrEmpty(taskId) || string.IsNullOrEmpty(startPos) || string.IsNullOrEmpty(endPos)) return;
  199. string allWarehouse = dataGridUI1.GetCurrentColValue("AllWarehouse");
  200. string text = $"确定要{(sender as Control).Text} {taskId}?({allWarehouse})";
  201. var dialogResult = MessageBox.Show(text, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  202. if (dialogResult != DialogResult.OK)
  203. {
  204. return;
  205. }
  206. (sender as Control).Enabled = false;
  207. var ret = await Task.Run(() =>
  208. {
  209. return ReTask(taskId, startPos, endPos);
  210. });
  211. MessageBox.Show($"{ret.Item2}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  212. }
  213. catch (Exception ex)
  214. {
  215. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  216. }
  217. (sender as Control).Enabled = true;
  218. }
  219. private (bool, string) ReTask(string taskId, string startPos, string endPos)
  220. {
  221. var mData = materialBindingManager.GetById(taskId);
  222. if (mData == null)
  223. {
  224. return (false, "获取物料信息失败");
  225. }
  226. PmsTaskInfoDto data = new PmsTaskInfoDto();
  227. data.TaskID = $"{taskId};{DateTime.Now.ToString("yyyyMMddHHmmssfffffff")}";
  228. data.LocationCode = startPos;
  229. data.TargetLocationCode = endPos;
  230. mData.TaskID = data.TaskID;
  231. var result = materialBindingManager.Save(mData);
  232. if (!result)
  233. {
  234. return (false, "保存物料信息失败");
  235. }
  236. var result2 = PmsTaskService.Instance.TaskAddNoCheck(data);
  237. return (true, result2.message);
  238. }
  239. }
  240. }