2021-06-05 14:17:30 +08:00
|
|
|
|
using CleanMachineHMI.Domain.Enums;
|
|
|
|
|
|
using CleanMachineHMI.Utils;
|
2021-12-26 21:30:02 +08:00
|
|
|
|
using Krypton.Toolkit;
|
2021-06-05 14:17:30 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows.Forms;
|
2021-12-31 19:53:53 +08:00
|
|
|
|
using CleanMachine.Model;
|
2022-05-05 20:42:02 +08:00
|
|
|
|
using CleanMachine.Model.BAS;
|
|
|
|
|
|
|
2021-06-05 14:17:30 +08:00
|
|
|
|
namespace CleanMachineHMI.FrmUserControl
|
|
|
|
|
|
{
|
2022-01-18 15:57:46 +08:00
|
|
|
|
[FormType(EnumFormType.IoMonitor)]
|
2021-06-05 14:17:30 +08:00
|
|
|
|
public partial class frmIOMonitor : UserControl
|
|
|
|
|
|
{
|
2022-05-10 15:21:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-05 14:17:30 +08:00
|
|
|
|
public frmIOMonitor()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
2022-05-10 15:21:13 +08:00
|
|
|
|
|
2021-06-05 14:17:30 +08:00
|
|
|
|
private void frmIOMonitorNew_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
initControl();
|
2022-05-10 15:21:13 +08:00
|
|
|
|
PlcOperationHelper.Instance.OnShowX_Y_Status += Show_X_Y_Status;
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
2022-05-10 15:21:13 +08:00
|
|
|
|
|
|
|
|
|
|
public Dictionary<PlcItem, CircleButton> buttons = new Dictionary<PlcItem, CircleButton>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private CircleButton findeControl(PlcItem item)
|
|
|
|
|
|
{
|
|
|
|
|
|
var controlname = item.PlcItemDataType == PlcItemTypeDesc.X ? "cbt_X" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0') :
|
|
|
|
|
|
"cbt_Y" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0');
|
|
|
|
|
|
var controls = this.Controls.Find(controlname, true);
|
|
|
|
|
|
return controls.Count() > 0 ? controls[0] as CircleButton : null;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Show_X_Y_Status(IEnumerable<PlcItem> items)
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
2022-05-10 15:21:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in items)
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
2022-05-10 15:21:13 +08:00
|
|
|
|
if (!buttons.TryGetValue(item, out var btn))
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
2022-05-10 15:21:13 +08:00
|
|
|
|
btn = findeControl(item);
|
|
|
|
|
|
buttons.Add(item, btn);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(item.PlcItemValue))
|
|
|
|
|
|
{
|
|
|
|
|
|
btn.BackColor = Color.FromArgb(191, 219, 255);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (bool.Parse(item.PlcItemValue.ToString()))
|
|
|
|
|
|
{
|
|
|
|
|
|
btn.BackColor = Color.Lime;
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-05-10 15:21:13 +08:00
|
|
|
|
btn.BackColor = Color.Red;
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
2022-05-10 15:21:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
2022-05-10 15:21:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//private void Show_X_Y_Status(IEnumerable<PlcItem> items)
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
|
|
// BeginInvoke(new Action(() =>
|
|
|
|
|
|
// {
|
|
|
|
|
|
// foreach (var item in items)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (item.PlcItemDataType == 2)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (this.Controls.Find("cbt_X" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true).Length > 0)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// CircleButton ctn = this.Controls.Find("cbt_X" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true)[0] as CircleButton;
|
|
|
|
|
|
// if (string.IsNullOrEmpty(item.PlcItemValue))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ctn.BackColor = Color.FromArgb(191, 219, 255);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else if (bool.Parse(item.PlcItemValue.ToString()))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ctn.BackColor = Color.Lime;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ctn.BackColor = Color.Red;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (this.Controls.Find("cbt_Y" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true).Length > 0)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// CircleButton ctn = this.Controls.Find("cbt_Y" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true)[0] as CircleButton;
|
|
|
|
|
|
// if (string.IsNullOrEmpty(item.PlcItemValue))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ctn.BackColor = Color.FromArgb(191, 219, 255);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else if (bool.Parse(item.PlcItemValue.ToString()))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ctn.BackColor = Color.Lime;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ctn.BackColor = Color.Red;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }));
|
|
|
|
|
|
//}
|
2021-06-05 14:17:30 +08:00
|
|
|
|
private void initControl()
|
|
|
|
|
|
{
|
2022-05-10 15:21:13 +08:00
|
|
|
|
|
2021-06-05 14:17:30 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2022-05-06 15:23:30 +08:00
|
|
|
|
if (PlcOperationHelper.Instance.PlcItemMd_X_List != null && PlcOperationHelper.Instance.PlcItemMd_X_List.Count > 0)
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
2022-05-06 15:23:30 +08:00
|
|
|
|
List<PlcItem> tempLst = PlcOperationHelper.Instance.PlcItemMd_X_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
2021-12-31 19:53:53 +08:00
|
|
|
|
foreach (PlcItem item in tempLst)
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
2022-05-10 15:21:13 +08:00
|
|
|
|
|
|
|
|
|
|
if (this.Controls.Find("klb_X" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true).Length > 0)
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
2022-05-10 15:21:13 +08:00
|
|
|
|
KryptonLabel label1 = this.Controls.Find("klb_X" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true)[0] as KryptonLabel;
|
|
|
|
|
|
|
|
|
|
|
|
label1.Text = this.T(item.PlcItemName.Replace("(I/O监控)", ""), item.PlcItemCode);
|
|
|
|
|
|
}
|
2021-06-05 14:17:30 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-06 15:23:30 +08:00
|
|
|
|
if (PlcOperationHelper.Instance.PlcItemMd_Y_List != null && PlcOperationHelper.Instance.PlcItemMd_Y_List.Count > 0)
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
2022-05-06 15:23:30 +08:00
|
|
|
|
List<PlcItem> tempLst = PlcOperationHelper.Instance.PlcItemMd_Y_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
2021-12-31 19:53:53 +08:00
|
|
|
|
foreach (PlcItem item in tempLst)
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
2022-05-10 15:21:13 +08:00
|
|
|
|
|
|
|
|
|
|
if (this.Controls.Find("klb_Y" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true).Length > 0)
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
2022-05-10 15:21:13 +08:00
|
|
|
|
KryptonLabel label1 = this.Controls.Find("klb_Y" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true)[0] as KryptonLabel;
|
|
|
|
|
|
|
|
|
|
|
|
label1.Text = this.T(item.PlcItemName.Replace("(I/O监控)", ""), item.PlcItemCode);
|
|
|
|
|
|
}
|
2021-06-05 14:17:30 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-10 15:21:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Show_X_Y_Status(PlcOperationHelper.Instance.PlcItemMd_X_List);
|
|
|
|
|
|
|
|
|
|
|
|
Show_X_Y_Status(PlcOperationHelper.Instance.PlcItemMd_Y_List);
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
KryptonMessageBox.Show(ex.Message);
|
|
|
|
|
|
}
|
2022-01-18 15:57:46 +08:00
|
|
|
|
}
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|