using ComponentFactory.Krypton.Toolkit; using NXWMS.Client.Model.AppModels.Condition.Monitor; using NXWMS.Client.Model.AppModels.Result.Base; using NXWMS.Client.Model.AppModels.Result.Monitor; using NXWMS.Services; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Threading; using System.Windows.Forms; namespace NXWMS.Forms.Monitor { public partial class frmWmsAllLineStatus : Form { public frmWmsAllLineStatus() { InitializeComponent(); } public List opcItemCrnLst = new List(); public List resultLst = new List(); public List basFaultLst = new List(); private void frmWmsAllLineStatus_Load(object sender, EventArgs e) { try { Thread th = new Thread(ShowAllLineTranMonitorMsg) { IsBackground = true }; th.Start(); basFaultLst = WcsMonitorService.wcsMotManageService.GetBasFaultMsg().Data; } catch (Exception ex) { KryptonMessageBox.Show(ex.Message); } } private void ShowAllLineTranMonitorMsg() { while (true) { try { resultLst = WcsMonitorService.wcsMotManageService.GetBasDevData(new WcsMotBasDevSearchMd()).Data; opcItemCrnLst = resultLst.FirstOrDefault(x => x.DEV_TYPE_CODE == "CrnType").PlcItemList; SetCrnPicLocation(); List tranDevLst = resultLst.FindAll(x => x.DEV_TYPE_CODE == "TranType"); if (tranDevLst.Count > 0) { foreach (WcsMotBasDevResult item in tranDevLst) { WcsMotOpcItemStatusResult WorkModel = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "WorkModel" && x.DEV_CODE == item.DEV_CODE); WcsMotOpcItemStatusResult FrontHaveGoodsFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "FrontHaveGoodsFlag" && x.DEV_CODE == item.DEV_CODE); WcsMotOpcItemStatusResult BackEndHaveGoodsFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "BackEndHaveGoodsFlag" && x.DEV_CODE == item.DEV_CODE); WcsMotOpcItemStatusResult AlarmNo = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "AlarmNo" && x.DEV_CODE == item.DEV_CODE); TranDevWorkModeEnum WorkModelEnum = GetEnumObj(WorkModel.PLC_ITEM_VALUE); string picName = "picb_" + item.DEV_CODE; if (Convert.ToInt32(AlarmNo.PLC_ITEM_VALUE) > 0) { Invoke(new Action(() => { Control picControl = this.Controls.Find(picName, true)[0]; if (picControl is PictureBox) { PictureBox ptb = picControl as PictureBox; ptb.BackColor = Color.Red; } })); } else { Invoke(new Action(() => { Control picControl = this.Controls.Find(picName, true)[0]; if (picControl is PictureBox) { if (Convert.ToBoolean(FrontHaveGoodsFlag.PLC_ITEM_VALUE) || Convert.ToBoolean(BackEndHaveGoodsFlag.PLC_ITEM_VALUE)) { PictureBox ptb = picControl as PictureBox; ptb.BackColor = Color.Lime; } else { if (WorkModelEnum == TranDevWorkModeEnum.联机执行任务) { PictureBox ptb = picControl as PictureBox; ptb.BackColor = Color.FromArgb(80, 160, 255); } else { PictureBox ptb = picControl as PictureBox; ptb.BackColor = Color.White; } } } })); } } } } catch { } Thread.Sleep(500); } } private void SetCrnPicLocation() { try { WcsMotOpcItemStatusResult RunPosColumn = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "RunPosColumn"); Invoke(new Action(() => { int crnPic_Y = 358; if (RunPosColumn.PLC_ITEM_VALUE == "0") { picb_Crn001.Location = new Point(picb_Tran1004.Location.X, crnPic_Y); } else { decimal numInterval = Math.Round(((decimal)(pictureBox31.Location.X - pictureBox13.Location.X) / 48), 2); decimal colPicXIndex = pictureBox13.Location.X + (Convert.ToInt32(RunPosColumn.PLC_ITEM_VALUE) - 1) * numInterval; picb_Crn001.Location = new Point(Convert.ToInt32(Math.Round(colPicXIndex, 0)), crnPic_Y); } })); } catch { } } private void Picb_Crn001_MouseHover(object sender, EventArgs e) { try { WcsMotOpcItemStatusResult WorkModel = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "WorkModel"); WcsMotOpcItemStatusResult WorkStatus = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "WorkStatus"); WcsMotOpcItemStatusResult TaskNo = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "TaskNo"); WcsMotOpcItemStatusResult AlarmNo = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "AlarmNo"); WcsMotOpcItemStatusResult WorkRow = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "WorkRow"); WcsMotOpcItemStatusResult RunPosColumn = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "RunPosColumn"); WcsMotOpcItemStatusResult PlatformPosLayer = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "PlatformPosLayer"); WcsMotOpcItemStatusResult PlatformHaveGoodsSignal = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "PlatformHaveGoodsSignal"); WcsMotOpcItemStatusResult ForkOriginSignal = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "ForkOriginSignal"); WcsMotOpcItemStatusResult ForkScanLeftSignal = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "ForkScanLeftSignal"); WcsMotOpcItemStatusResult ForkScanRightSignal = opcItemCrnLst.FirstOrDefault(x => x.OPC_ITEM_CODE == "ForkScanRightSignal"); CrnDevWorkModeEnum WorkModelEnum = GetEnumObj(WorkModel.PLC_ITEM_VALUE); CrnDevWorkStatusEnum WorkStatusEnum = GetEnumObj(WorkStatus.PLC_ITEM_VALUE); ToolTip ttp = new ToolTip { InitialDelay = 200, AutoPopDelay = 3000, ReshowDelay = 200, ShowAlways = true, IsBalloon = true }; BasFaultMd basFaultMd = basFaultLst.FirstOrDefault(x => x.DEV_TYPE_CODE == WorkModel.DEV_TYPE_CODE && x.FAULT_CODE == AlarmNo.PLC_ITEM_VALUE); string alarmStr = AlarmNo.PLC_ITEM_VALUE + "--" + basFaultMd == null ? "未知报警信息" : basFaultMd.FAULT_NAME; 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"; ttp.SetToolTip(picb_Crn001, tipShowMsg); } catch (Exception ex) { KryptonMessageBox.Show(ex.Message); } } private void Picb_Tran1011_MouseHover(object sender, EventArgs e) { try { PictureBox ptb = sender as PictureBox; WcsMotBasDevResult item = resultLst.FirstOrDefault(x => x.DEV_CODE == ptb.Name.Replace("picb_", "")); WcsMotOpcItemStatusResult WorkModel = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "WorkModel" && x.DEV_CODE == item.DEV_CODE); WcsMotOpcItemStatusResult FrontHaveGoodsFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "FrontHaveGoodsFlag" && x.DEV_CODE == item.DEV_CODE); WcsMotOpcItemStatusResult BackEndHaveGoodsFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "BackEndHaveGoodsFlag" && x.DEV_CODE == item.DEV_CODE); WcsMotOpcItemStatusResult AlarmNo = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "AlarmNo" && x.DEV_CODE == item.DEV_CODE); TranDevWorkModeEnum WorkModelEnum = GetEnumObj(WorkModel.PLC_ITEM_VALUE); WcsMotOpcItemStatusResult LowPosStopFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "LowPosStopFlag" && x.DEV_CODE == item.DEV_CODE); WcsMotOpcItemStatusResult HighPosStopFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "HighPosStopFlag" && x.DEV_CODE == item.DEV_CODE); WcsMotOpcItemStatusResult ApplyInStock = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "ApplyInStock" && x.DEV_CODE == item.DEV_CODE); WcsMotOpcItemStatusResult UltrahighFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "UltrahighFlag" && x.DEV_CODE == item.DEV_CODE); WcsMotOpcItemStatusResult OverWeightFlag = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "OverWeightFlag" && x.DEV_CODE == item.DEV_CODE); WcsMotOpcItemStatusResult TaskNo = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "TaskNo" && x.DEV_CODE == item.DEV_CODE); WcsMotOpcItemStatusResult TargetLocNo = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "TargetLocNo" && x.DEV_CODE == item.DEV_CODE); WcsMotOpcItemStatusResult PalletCode = item.PlcItemList.FirstOrDefault(x => x.OPC_ITEM_CODE == "PalletCode" && x.DEV_CODE == item.DEV_CODE); ToolTip ttp = new ToolTip { InitialDelay = 200, AutoPopDelay = 3000, ReshowDelay = 200, ShowAlways = true, IsBalloon = true }; BasFaultMd basFaultMd = basFaultLst.FirstOrDefault(x => x.DEV_TYPE_CODE == WorkModel.DEV_TYPE_CODE && x.FAULT_CODE == AlarmNo.PLC_ITEM_VALUE); string alarmStr = AlarmNo.PLC_ITEM_VALUE + "--" + basFaultMd == null ? "未知报警信息" : basFaultMd.FAULT_NAME; 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"; ttp.SetToolTip(ptb, tipShowMsg); } catch (Exception ex) { KryptonMessageBox.Show(ex.Message); } } public T GetEnumObj(object val) where T : Enum { FieldInfo[] fields = typeof(T).GetFields(BindingFlags.Static | BindingFlags.Public); bool isGet = false; foreach (var fi in fields) { int enumVal = ((int)fi.GetValue(null)); int tmpVal = Convert.ToInt32(val); if (enumVal == tmpVal) { isGet = true; break; } } if (isGet) { val = Convert.ToInt32(val); return (T)val; } else { return (T)fields[0].GetValue(null); } } } /// /// 输送线设备工作状态枚举 /// public enum TranDevWorkModeEnum { 脱机待机, 脱机执行任务, 联机待机, 联机执行任务, } /// /// 堆垛机工作模式枚举 /// public enum CrnDevWorkModeEnum { 维修 = 0, 手动 = 1, 单机自动 = 2, 联机自动 = 3, 不明 = 4, } /// /// 堆垛机作业状态枚举 /// public enum CrnDevWorkStatusEnum { 待机 = 0, 运行中 = 1, 故障 = 2, 放货完成 = 3, } }