frmWmsAllLineStatus.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.Model.AppModels.Condition.Monitor;
  3. using NXWMS.Client.Model.AppModels.Result.Base;
  4. using NXWMS.Client.Model.AppModels.Result.Monitor;
  5. using NXWMS.Services;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Windows.Forms;
  16. namespace NXWMS.Forms.Monitor
  17. {
  18. public partial class frmWmsAllLineStatus : Form
  19. {
  20. public frmWmsAllLineStatus()
  21. {
  22. InitializeComponent();
  23. }
  24. public List<WcsMotOpcItemStatusResult> opcItemCrnLst = new List<WcsMotOpcItemStatusResult>();
  25. public List<WcsMotBasDevResult> resultLst = new List<WcsMotBasDevResult>();
  26. public List<BasFaultMd> basFaultLst = new List<BasFaultMd>();
  27. private void frmWmsAllLineStatus_Load(object sender, EventArgs e)
  28. {
  29. try
  30. {
  31. Thread th = new Thread(ShowAllLineTranMonitorMsg)
  32. {
  33. IsBackground = true
  34. };
  35. th.Start();
  36. basFaultLst = WcsMonitorService.wcsMotManageService.GetBasFaultMsg().Data;
  37. }
  38. catch (Exception ex)
  39. {
  40. KryptonMessageBox.Show(ex.Message);
  41. }
  42. }
  43. private void ShowAllLineTranMonitorMsg()
  44. {
  45. while (true)
  46. {
  47. try
  48. {
  49. resultLst = WcsMonitorService.wcsMotManageService.GetBasDevData(new WcsMotBasDevSearchMd()).Data;
  50. opcItemCrnLst = resultLst.FirstOrDefault(x => x.DEV_TYPE_CODE == "CrnType").PlcItemList;
  51. SetCrnPicLocation();
  52. List<WcsMotBasDevResult> tranDevLst = resultLst.FindAll(x => x.DEV_TYPE_CODE == "TranType");
  53. if (tranDevLst.Count > 0)
  54. {
  55. foreach (WcsMotBasDevResult item in tranDevLst)
  56. {
  57. WcsMotOpcItemStatusResult WorkModel = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "WorkModel" && x.DEV_CODE == item.DEV_CODE);
  58. WcsMotOpcItemStatusResult FrontHaveGoodsFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "FrontHaveGoodsFlag" && x.DEV_CODE == item.DEV_CODE);
  59. WcsMotOpcItemStatusResult BackEndHaveGoodsFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "BackEndHaveGoodsFlag" && x.DEV_CODE == item.DEV_CODE);
  60. WcsMotOpcItemStatusResult AlarmNo = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "AlarmNo" && x.DEV_CODE == item.DEV_CODE);
  61. TranDevWorkModeEnum WorkModelEnum = GetEnumObj<TranDevWorkModeEnum>(WorkModel.PLC_ITEM_VALUE);
  62. string picName = "picb_" + item.DEV_CODE;
  63. if (Convert.ToInt32(AlarmNo.PLC_ITEM_VALUE) > 0)
  64. {
  65. Invoke(new Action(() => {
  66. Control picControl = this.Controls.Find(picName, true)[0];
  67. if (picControl is PictureBox)
  68. {
  69. PictureBox ptb = picControl as PictureBox;
  70. ptb.BackColor = Color.Red;
  71. }
  72. }));
  73. }
  74. else
  75. {
  76. Invoke(new Action(() => {
  77. Control picControl = this.Controls.Find(picName, true)[0];
  78. if (picControl is PictureBox)
  79. {
  80. if (Convert.ToBoolean(FrontHaveGoodsFlag.PLC_ITEM_VALUE) || Convert.ToBoolean(BackEndHaveGoodsFlag.PLC_ITEM_VALUE))
  81. {
  82. PictureBox ptb = picControl as PictureBox;
  83. ptb.BackColor = Color.Lime;
  84. }
  85. else
  86. {
  87. if (WorkModelEnum == TranDevWorkModeEnum.联机执行任务)
  88. {
  89. PictureBox ptb = picControl as PictureBox;
  90. ptb.BackColor = Color.FromArgb(80, 160, 255);
  91. }
  92. else
  93. {
  94. PictureBox ptb = picControl as PictureBox;
  95. ptb.BackColor = Color.White;
  96. }
  97. }
  98. }
  99. }));
  100. }
  101. }
  102. }
  103. }
  104. catch
  105. {
  106. }
  107. Thread.Sleep(500);
  108. }
  109. }
  110. private void SetCrnPicLocation()
  111. {
  112. try
  113. {
  114. WcsMotOpcItemStatusResult RunPosColumn = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "RunPosColumn");
  115. Invoke(new Action(() => {
  116. int crnPic_Y = 358;
  117. if (RunPosColumn.PLC_ITEM_VALUE == "0")
  118. {
  119. picb_Crn001.Location = new Point(picb_Tran1004.Location.X, crnPic_Y);
  120. }
  121. else
  122. {
  123. decimal numInterval = Math.Round(((decimal)(pictureBox31.Location.X - pictureBox13.Location.X) / 48), 2);
  124. decimal colPicXIndex = pictureBox13.Location.X + (Convert.ToInt32(RunPosColumn.PLC_ITEM_VALUE) - 1) * numInterval;
  125. picb_Crn001.Location = new Point(Convert.ToInt32(Math.Round(colPicXIndex, 0)), crnPic_Y);
  126. }
  127. }));
  128. }
  129. catch
  130. {
  131. }
  132. }
  133. private void Picb_Crn001_MouseHover(object sender, EventArgs e)
  134. {
  135. try
  136. {
  137. WcsMotOpcItemStatusResult WorkModel = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "WorkModel");
  138. WcsMotOpcItemStatusResult WorkStatus = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "WorkStatus");
  139. WcsMotOpcItemStatusResult TaskNo = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "TaskNo");
  140. WcsMotOpcItemStatusResult AlarmNo = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "AlarmNo");
  141. WcsMotOpcItemStatusResult WorkRow = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "WorkRow");
  142. WcsMotOpcItemStatusResult RunPosColumn = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "RunPosColumn");
  143. WcsMotOpcItemStatusResult PlatformPosLayer = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "PlatformPosLayer");
  144. WcsMotOpcItemStatusResult PlatformHaveGoodsSignal = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "PlatformHaveGoodsSignal");
  145. WcsMotOpcItemStatusResult ForkOriginSignal = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "ForkOriginSignal");
  146. WcsMotOpcItemStatusResult ForkScanLeftSignal = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "ForkScanLeftSignal");
  147. WcsMotOpcItemStatusResult ForkScanRightSignal = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "ForkScanRightSignal");
  148. CrnDevWorkModeEnum WorkModelEnum = GetEnumObj<CrnDevWorkModeEnum>(WorkModel.PLC_ITEM_VALUE);
  149. CrnDevWorkStatusEnum WorkStatusEnum = GetEnumObj<CrnDevWorkStatusEnum>(WorkStatus.PLC_ITEM_VALUE);
  150. ToolTip ttp = new ToolTip
  151. {
  152. InitialDelay = 200,
  153. AutoPopDelay = 3000,
  154. ReshowDelay = 200,
  155. ShowAlways = true,
  156. IsBalloon = true
  157. };
  158. BasFaultMd basFaultMd = basFaultLst.FirstOrDefault(x => x.DEV_TYPE_CODE == WorkModel.DEV_TYPE_CODE && x.FAULT_CODE == AlarmNo.PLC_ITEM_VALUE);
  159. string alarmStr = AlarmNo.PLC_ITEM_VALUE + "--" + basFaultMd == null ? "未知报警信息" : basFaultMd.FAULT_NAME;
  160. string tipShowMsg = $"堆垛机号:【{WorkModel.DEV_CODE}】\r\n堆垛机名称:【{WorkModel.DEV_NAME}】\r\n工作模式:【{WorkModelEnum}】\r\n作业状态:【{WorkStatusEnum}】\r\n指令号:【{TaskNo.PLC_ITEM_VALUE}】\r\n作业排:【{WorkRow.PLC_ITEM_VALUE}】\r\n行走位置:【{RunPosColumn.PLC_ITEM_VALUE}】\r\n载货台位置:【{PlatformPosLayer.PLC_ITEM_VALUE}】\r\n载货台有货信号:【{PlatformHaveGoodsSignal.PLC_ITEM_VALUE}】\r\n货叉原点信号:【{ForkOriginSignal.PLC_ITEM_VALUE}】\r\n货叉左探有货信号:【{ForkScanLeftSignal.PLC_ITEM_VALUE}】\r\n货叉右探有货信号:【{ForkScanRightSignal.PLC_ITEM_VALUE}】\r\n报警码:【{alarmStr}】\r\n";
  161. ttp.SetToolTip(picb_Crn001, tipShowMsg);
  162. }
  163. catch (Exception ex)
  164. {
  165. KryptonMessageBox.Show(ex.Message);
  166. }
  167. }
  168. private void Picb_Tran1011_MouseHover(object sender, EventArgs e)
  169. {
  170. try
  171. {
  172. PictureBox ptb = sender as PictureBox;
  173. WcsMotBasDevResult item = resultLst.FirstOrDefault(x => x.DEV_CODE == ptb.Name.Replace("picb_", ""));
  174. WcsMotOpcItemStatusResult WorkModel = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "WorkModel" && x.DEV_CODE == item.DEV_CODE);
  175. WcsMotOpcItemStatusResult FrontHaveGoodsFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "FrontHaveGoodsFlag" && x.DEV_CODE == item.DEV_CODE);
  176. WcsMotOpcItemStatusResult BackEndHaveGoodsFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "BackEndHaveGoodsFlag" && x.DEV_CODE == item.DEV_CODE);
  177. WcsMotOpcItemStatusResult AlarmNo = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "AlarmNo" && x.DEV_CODE == item.DEV_CODE);
  178. TranDevWorkModeEnum WorkModelEnum = GetEnumObj<TranDevWorkModeEnum>(WorkModel.PLC_ITEM_VALUE);
  179. WcsMotOpcItemStatusResult LowPosStopFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "LowPosStopFlag" && x.DEV_CODE == item.DEV_CODE);
  180. WcsMotOpcItemStatusResult HighPosStopFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "HighPosStopFlag" && x.DEV_CODE == item.DEV_CODE);
  181. WcsMotOpcItemStatusResult ApplyInStock = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "ApplyInStock" && x.DEV_CODE == item.DEV_CODE);
  182. WcsMotOpcItemStatusResult UltrahighFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "UltrahighFlag" && x.DEV_CODE == item.DEV_CODE);
  183. WcsMotOpcItemStatusResult OverWeightFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "OverWeightFlag" && x.DEV_CODE == item.DEV_CODE);
  184. WcsMotOpcItemStatusResult TaskNo = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "TaskNo" && x.DEV_CODE == item.DEV_CODE);
  185. WcsMotOpcItemStatusResult TargetLocNo = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "TargetLocNo" && x.DEV_CODE == item.DEV_CODE);
  186. WcsMotOpcItemStatusResult PalletCode = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "PalletCode" && x.DEV_CODE == item.DEV_CODE);
  187. ToolTip ttp = new ToolTip
  188. {
  189. InitialDelay = 200,
  190. AutoPopDelay = 3000,
  191. ReshowDelay = 200,
  192. ShowAlways = true,
  193. IsBalloon = true
  194. };
  195. BasFaultMd basFaultMd = basFaultLst.FirstOrDefault(x => x.DEV_TYPE_CODE == WorkModel.DEV_TYPE_CODE && x.FAULT_CODE == AlarmNo.PLC_ITEM_VALUE);
  196. string alarmStr = AlarmNo.PLC_ITEM_VALUE + "--" + basFaultMd == null ? "未知报警信息" : basFaultMd.FAULT_NAME;
  197. string tipShowMsg = $"输送线号:【{WorkModel.DEV_CODE}】\r\n输送线名称:【{WorkModel.DEV_NAME}】\r\n工作模式:【{WorkModelEnum}】\r\n指令号:【{TaskNo.PLC_ITEM_VALUE}】\r\n目标站台:【{TargetLocNo.PLC_ITEM_VALUE}】\r\n托盘号:【{PalletCode.PLC_ITEM_VALUE.Replace('\0', ' ').Replace(" ", "")}】\r\n前端有货信号:【{FrontHaveGoodsFlag.PLC_ITEM_VALUE}】\r\n后端有货信号:【{BackEndHaveGoodsFlag.PLC_ITEM_VALUE}】\r\n低位停准信号:【{LowPosStopFlag.PLC_ITEM_VALUE}】\r\n高位停准信号:【{HighPosStopFlag.PLC_ITEM_VALUE}】\r\n入库申请信号:【{ApplyInStock.PLC_ITEM_VALUE}】\r\n超高信号:【{UltrahighFlag.PLC_ITEM_VALUE}】\r\n超重信号:【{OverWeightFlag.PLC_ITEM_VALUE}】\r\n报警码:【{alarmStr}】\r\n";
  198. ttp.SetToolTip(ptb, tipShowMsg);
  199. }
  200. catch (Exception ex)
  201. {
  202. KryptonMessageBox.Show(ex.Message);
  203. }
  204. }
  205. public T GetEnumObj<T>(object val) where T : Enum
  206. {
  207. FieldInfo[] fields = typeof(T).GetFields(BindingFlags.Static | BindingFlags.Public);
  208. bool isGet = false;
  209. foreach (var fi in fields)
  210. {
  211. int enumVal = ((int)fi.GetValue(null));
  212. int tmpVal = Convert.ToInt32(val);
  213. if (enumVal == tmpVal)
  214. {
  215. isGet = true;
  216. break;
  217. }
  218. }
  219. if (isGet)
  220. {
  221. val = Convert.ToInt32(val);
  222. return (T)val;
  223. }
  224. else
  225. {
  226. return (T)fields[0].GetValue(null);
  227. }
  228. }
  229. }
  230. /// <summary>
  231. /// 输送线设备工作状态枚举
  232. /// </summary>
  233. public enum TranDevWorkModeEnum
  234. {
  235. 脱机待机,
  236. 脱机执行任务,
  237. 联机待机,
  238. 联机执行任务,
  239. }
  240. /// <summary>
  241. /// 堆垛机工作模式枚举
  242. /// </summary>
  243. public enum CrnDevWorkModeEnum
  244. {
  245. 维修 = 0,
  246. 手动 = 1,
  247. 单机自动 = 2,
  248. 联机自动 = 3,
  249. 不明 = 4,
  250. }
  251. /// <summary>
  252. /// 堆垛机作业状态枚举
  253. /// </summary>
  254. public enum CrnDevWorkStatusEnum
  255. {
  256. 待机 = 0,
  257. 运行中 = 1,
  258. 故障 = 2,
  259. 放货完成 = 3,
  260. }
  261. }