using CleanMachineHMI.Domain.Enums; using CleanMachineHMI.Utils; using Krypton.Toolkit; using LeadDataBaseUtility; using NX_LogUtility; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace CleanMachineHMI { public partial class frmIOMonitor_Old : KryptonForm { public frmIOMonitor_Old() { InitializeComponent(); _InfoLanguageTextList = this.GetInfoLanguageText(GlobalHelper.LanguageCode, "Label"); //InitControl(); } /// /// 页面信息语言文本列表 /// private DataTable _InfoLanguageTextList; bool isThRun = false; List lstMoitor_X = new List(); List lstMoitor_Y = new List(); Stopwatch sw = new Stopwatch(); public class BtnPlcItemMonitor { public CircleButton ctn { get; set; } public BasPlcItemMd plcItemMd { get; set; } } private void frmIOMonitor_Load(object sender, EventArgs e) { try { InitControl(); Thread th1 = new Thread(ReFreshControl_Y); th1.IsBackground = true; th1.Start(); } catch (Exception) { } } private void ReFreshControl_Y() { while (GlobalHelper.SysThIsRunFlag) { try { if (lstMoitor_X.Count > 0) { //LogHelper.WriteLog("~~~~~~~~~~~~~~I/O监控界面,X 类型PLC变量的圆形展示控件渲染开始~~~~~~~~~~~~~~", LogTypeEum.Run); //sw.Start(); foreach (BtnPlcItemMonitor item in lstMoitor_X) { Invoke(new Action(() => { if (string.IsNullOrEmpty(item.plcItemMd.PlcItemValue)) { if (isThRun) { item.ctn.BackColor = Color.FromArgb(191, 219, 255); } } else if (bool.Parse(item.plcItemMd.PlcItemValue.ToString())) { if (isThRun) { item.ctn.BackColor = Color.Lime; } } else { if (isThRun) { item.ctn.BackColor = Color.Red; } } })); } //sw.Stop(); //LogHelper.WriteLog($"~~~~~~~~~~~~~~I/O监控界面,X 类型PLC变量的圆形展示控件渲染结束,总花费时间为:【{sw.ElapsedMilliseconds}】。~~~~~~~~~~~~~~", LogTypeEum.Run); //sw.Reset(); } if (lstMoitor_Y.Count > 0) { //LogHelper.WriteLog("~~~~~~~~~~~~~~I/O监控界面,Y 类型PLC变量的圆形展示控件渲染开始~~~~~~~~~~~~~~", LogTypeEum.Run); //sw.Start(); foreach (BtnPlcItemMonitor item in lstMoitor_Y) { Invoke(new Action(() => { if (string.IsNullOrEmpty(item.plcItemMd.PlcItemValue)) { if (isThRun) { item.ctn.BackColor = Color.FromArgb(191, 219, 255); } } else if (bool.Parse(item.plcItemMd.PlcItemValue.ToString())) { if (isThRun) { item.ctn.BackColor = Color.Lime; } } else { if (isThRun) { item.ctn.BackColor = Color.Red; } } })); } //sw.Stop(); //LogHelper.WriteLog($"~~~~~~~~~~~~~~I/O监控界面,Y 类型PLC变量的圆形展示控件渲染结束,总花费时间为:【{sw.ElapsedMilliseconds}】。~~~~~~~~~~~~~~", LogTypeEum.Run); //sw.Reset(); } } catch { } Thread.Sleep(5); } } private void InitControl() { try { lstMoitor_X.Clear(); lstMoitor_Y.Clear(); #region PLC X数据类型变量 if (GlobalHelper.PlcItemMd_X_List != null && GlobalHelper.PlcItemMd_X_List.Count > 0) { //List tempLst = AppConfig.PlcItemMd_X_List.FindAll(x => x.PlcItemName != "备用").OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList(); List tempLst = GlobalHelper.PlcItemMd_X_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList(); int dataSum = tempLst.Count; int rowNum; if (dataSum % 2 == 0) { rowNum = dataSum / 2; } else { rowNum = dataSum / 2 + 1; } int tmpNum = 1; //int colFirstLocX = 35; int colFirstLocY = 8; int colSecondLocX = 325; int colSecondLocY = 8; int panalTemplateWidth = 245; if (GlobalHelper.LanguageCode == "English") { panalTemplateWidth = 245; } else { panalTemplateWidth = 175; } int panalTemplateHeight = 30; int wdNum = kryptonPanel2.Width / 2; int tmpSpace = (wdNum - panalTemplateWidth) / 2 == 0 ? 1 : (wdNum - panalTemplateWidth) / 2; colSecondLocX = wdNum + tmpSpace + 1; int rowSpace = 7; foreach (BasPlcItemMd item in tempLst) { if (tmpNum <= rowNum) { Panel panel = new Panel(); panel.Location = new Point(tmpSpace, colFirstLocY + panalTemplateHeight * (tmpNum - 1) + rowSpace * (tmpNum - 1)); panel.Size = new Size(panalTemplateWidth, panalTemplateHeight); panel.BackColor = Color.White; panel.BorderStyle = BorderStyle.FixedSingle; KryptonLabel label = new KryptonLabel(); label.StateCommon.ShortText.Font = new Font("宋体", (float)10, FontStyle.Bold); label.Location = new Point(-1, 6); int a = Convert.ToInt32(item.PlcItemPriAddress); label.Text = "X" + Convert.ToString(a, 8).PadLeft(2, '0'); CircleButton button = new CircleButton(); button.Name = "cbtn_" + item.PlcItemCode; button.Size = new Size(23, 23); button.Location = new Point(28, 3); button.BackColor = Color.FromArgb(191, 219, 255); KryptonLabel label1 = new KryptonLabel(); label1.StateCommon.ShortText.Font = new Font("宋体", (float)8.5, FontStyle.Regular); label1.Location = new Point(44, 6); label1.Text = _InfoLanguageTextList.GetInfoText_1(item.PlcItemName.Replace("(I/O监控)", ""), item.PlcItemCode, "Label"); panel.Controls.Add(label); panel.Controls.Add(button); panel.Controls.Add(label1); kryptonPanel2.Controls.Add(panel); lstMoitor_X.Add(new BtnPlcItemMonitor { ctn = button, plcItemMd = item, }); } else { Panel panel = new Panel(); panel.Location = new Point(colSecondLocX, colSecondLocY + panalTemplateHeight * (tmpNum - rowNum - 1) + rowSpace * (tmpNum - rowNum - 1)); panel.Size = new Size(panalTemplateWidth, panalTemplateHeight); panel.BackColor = Color.White; panel.BorderStyle = BorderStyle.FixedSingle; KryptonLabel label = new KryptonLabel(); label.StateCommon.ShortText.Font = new Font("宋体", (float)10, FontStyle.Bold); label.Location = new Point(-1, 6); int a = Convert.ToInt32(item.PlcItemPriAddress); label.Text = "X" + Convert.ToString(a, 8).PadLeft(2, '0'); CircleButton button = new CircleButton(); button.Name = "cbtn_" + item.PlcItemCode; button.Size = new Size(23, 23); button.Location = new Point(28, 3); button.BackColor = Color.FromArgb(191, 219, 255); KryptonLabel label1 = new KryptonLabel(); label1.StateCommon.ShortText.Font = new Font("宋体", (float)8.5, FontStyle.Regular); label1.Location = new Point(44, 6); //label1.Text = item.PlcItemName.Replace("(I/O监控)", ""); label1.Text = _InfoLanguageTextList.GetInfoText_1(item.PlcItemName.Replace("(I/O监控)", ""), item.PlcItemCode, "Label"); panel.Controls.Add(label); panel.Controls.Add(button); panel.Controls.Add(label1); kryptonPanel2.Controls.Add(panel); lstMoitor_X.Add(new BtnPlcItemMonitor { ctn = button, plcItemMd = item, }); } tmpNum++; } Label label2 = new Label(); label2.BackColor = Color.FromArgb(160, 160, 160); label2.Text = ""; label2.Location = new Point(wdNum, 0); label2.Size = new Size(1, kryptonPanel2.Height); kryptonPanel2.Controls.Add(label2); } #endregion #region PLC Y数据类型变量 if (GlobalHelper.PlcItemMd_Y_List != null && GlobalHelper.PlcItemMd_Y_List.Count > 0) { //List tempLst = AppConfig.PlcItemMd_Y_List.FindAll(x => x.PlcItemName != "备用").OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList(); List tempLst = GlobalHelper.PlcItemMd_Y_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList(); int dataSum = tempLst.Count; //int dataSum = AppConfig.PlcItemMd_Y_List.Count; int rowNum; if (dataSum % 2 == 0) { rowNum = dataSum / 2; } else { rowNum = dataSum / 2 + 1; } int tmpNum = 1; int colFirstLocX = 35; int colFirstLocY = 8; int colSecondLocX = 325; int colSecondLocY = 8; int panalTemplateWidth = 245; if (GlobalHelper.LanguageCode == "English") { panalTemplateWidth = 245; } else { panalTemplateWidth = 175; } int panalTemplateHeight = 30; int wdNum = kryptonPanel3.Width / 2; int tmpSpace = (wdNum - panalTemplateWidth) / 2; colFirstLocX = tmpSpace; colSecondLocX = wdNum + tmpSpace + 1; int rowSpace = 7; foreach (BasPlcItemMd item in tempLst) { if (tmpNum <= rowNum) { Panel panel = new Panel(); panel.Location = new Point(colFirstLocX, colFirstLocY + panalTemplateHeight * (tmpNum - 1) + rowSpace * (tmpNum - 1)); panel.Size = new Size(panalTemplateWidth, panalTemplateHeight); panel.BackColor = Color.White; panel.BorderStyle = BorderStyle.FixedSingle; KryptonLabel label = new KryptonLabel(); label.StateCommon.ShortText.Font = new Font("宋体", (float)10, FontStyle.Bold); label.Location = new Point(-1, 6); int a = Convert.ToInt32(item.PlcItemPriAddress); label.Text = "Y" + Convert.ToString(a, 8).PadLeft(2, '0'); CircleButton button = new CircleButton(); button.Name = "cbtn_" + item.PlcItemCode; button.Size = new Size(23, 23); button.Location = new Point(28, 3); button.BackColor = Color.FromArgb(191, 219, 255); KryptonLabel label1 = new KryptonLabel(); label1.StateCommon.ShortText.Font = new Font("宋体", (float)8.5, FontStyle.Regular); label1.Location = new Point(44, 6); label1.Text = _InfoLanguageTextList.GetInfoText_1(item.PlcItemName.Replace("(I/O监控)", ""), item.PlcItemCode, "Label"); panel.Controls.Add(label); panel.Controls.Add(button); panel.Controls.Add(label1); kryptonPanel3.Controls.Add(panel); lstMoitor_Y.Add(new BtnPlcItemMonitor { ctn = button, plcItemMd = item, }); } else { Panel panel = new Panel(); panel.Location = new Point(colSecondLocX, colSecondLocY + panalTemplateHeight * (tmpNum - rowNum - 1) + rowSpace * (tmpNum - rowNum - 1)); panel.Size = new Size(panalTemplateWidth, panalTemplateHeight); panel.BackColor = Color.White; panel.BorderStyle = BorderStyle.FixedSingle; KryptonLabel label = new KryptonLabel(); label.StateCommon.ShortText.Font = new Font("宋体", (float)10, FontStyle.Bold); label.Location = new Point(-1, 6); int a = Convert.ToInt32(item.PlcItemPriAddress); label.Text = "Y" + Convert.ToString(a, 8).PadLeft(2, '0'); CircleButton button = new CircleButton(); button.Name = "cbtn_" + item.PlcItemCode; button.Size = new Size(23, 23); button.Location = new Point(28, 3); button.BackColor = Color.FromArgb(191, 219, 255); KryptonLabel label1 = new KryptonLabel(); label1.StateCommon.ShortText.Font = new Font("宋体", (float)8.5, FontStyle.Regular); label1.Location = new Point(44, 6); label1.Text = _InfoLanguageTextList.GetInfoText_1(item.PlcItemName.Replace("(I/O监控)", ""), item.PlcItemCode, "Label"); panel.Controls.Add(label); panel.Controls.Add(button); panel.Controls.Add(label1); kryptonPanel3.Controls.Add(panel); lstMoitor_Y.Add(new BtnPlcItemMonitor { ctn = button, plcItemMd = item, }); } tmpNum++; } Label label2 = new Label(); label2.BackColor = Color.FromArgb(160, 160, 160); label2.Text = ""; label2.Location = new Point(wdNum, 0); label2.Size = new Size(1, kryptonPanel3.Height); kryptonPanel3.Controls.Add(label2); } #endregion } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void frmIOMonitor_SizeChanged(object sender, EventArgs e) { //isThRun = false; //kryptonPanel2.Controls.Clear(); //kryptonPanel3.Controls.Clear(); //InitControl(); //isThRun = true; } private void frmIOMonitor_FormClosing(object sender, FormClosingEventArgs e) { } } }