修改
This commit is contained in:
@@ -19,63 +19,114 @@ namespace CleanMachineHMI.FrmUserControl
|
||||
[FormType(EnumFormType.IoMonitor)]
|
||||
public partial class frmIOMonitor : UserControl
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public frmIOMonitor()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
private void frmIOMonitorNew_Load(object sender, EventArgs e)
|
||||
{
|
||||
initControl();
|
||||
Global.OnShowX_Y_Status += Show_X_Y_Status;
|
||||
PlcOperationHelper.Instance.OnShowX_Y_Status += Show_X_Y_Status;
|
||||
}
|
||||
private void Show_X_Y_Status(object sender, EventArgs e)
|
||||
|
||||
public Dictionary<PlcItem, CircleButton> buttons = new Dictionary<PlcItem, CircleButton>();
|
||||
|
||||
|
||||
private CircleButton findeControl(PlcItem item)
|
||||
{
|
||||
PlcItem item = sender as PlcItem;
|
||||
BeginInvoke(new Action(() =>
|
||||
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)
|
||||
{
|
||||
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item.PlcItemDataType == 2)
|
||||
if (!buttons.TryGetValue(item, out var btn))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
btn.BackColor = Color.Red;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//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;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }));
|
||||
//}
|
||||
private void initControl()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
if (PlcOperationHelper.Instance.PlcItemMd_X_List != null && PlcOperationHelper.Instance.PlcItemMd_X_List.Count > 0)
|
||||
@@ -83,15 +134,14 @@ namespace CleanMachineHMI.FrmUserControl
|
||||
List<PlcItem> tempLst = PlcOperationHelper.Instance.PlcItemMd_X_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
||||
foreach (PlcItem item in tempLst)
|
||||
{
|
||||
BeginInvoke(new Action(() =>
|
||||
{
|
||||
if (this.Controls.Find("klb_X" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true).Length > 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}));
|
||||
if (this.Controls.Find("klb_X" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true).Length > 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,17 +150,21 @@ namespace CleanMachineHMI.FrmUserControl
|
||||
List<PlcItem> tempLst = PlcOperationHelper.Instance.PlcItemMd_Y_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
||||
foreach (PlcItem item in tempLst)
|
||||
{
|
||||
BeginInvoke(new Action(() =>
|
||||
{
|
||||
if (this.Controls.Find("klb_Y" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true).Length > 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}));
|
||||
if (this.Controls.Find("klb_Y" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true).Length > 0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Show_X_Y_Status(PlcOperationHelper.Instance.PlcItemMd_X_List);
|
||||
|
||||
Show_X_Y_Status(PlcOperationHelper.Instance.PlcItemMd_Y_List);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user