提交
This commit is contained in:
@ -1,43 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Data;
|
||||
using AntdUI;
|
||||
using DH.Commons.Enums;
|
||||
using DH.Devices.Devices;
|
||||
using DH.Devices.Vision;
|
||||
|
||||
using DH.Commons.Helper;
|
||||
using DH.Commons.Models;
|
||||
using DHSoftware.Utils;
|
||||
using DH.Commons.Base;
|
||||
namespace DHSoftware.Views
|
||||
{
|
||||
|
||||
public partial class SettingWindow : Window
|
||||
{
|
||||
public List<CameraBase> cameras = new List<CameraBase>();
|
||||
public List<DetectionConfig> detections = new List<DetectionConfig>();
|
||||
private UserControl currControl;
|
||||
|
||||
|
||||
public SettingWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
AntdUI.TooltipComponent tooltip = new AntdUI.TooltipComponent()
|
||||
{
|
||||
Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134))),
|
||||
};
|
||||
tooltip.ArrowAlign = AntdUI.TAlign.Right;
|
||||
tooltip.SetTip(btnAdd, "新增工位");
|
||||
|
||||
|
||||
|
||||
BindEventHandler();
|
||||
InitData();
|
||||
|
||||
}
|
||||
|
||||
private void Menu_MouseDown(object sender, MouseEventArgs e)
|
||||
private void BindEventHandler()
|
||||
{
|
||||
if (e.Button == MouseButtons.Right)
|
||||
Resize += SettingWindow1_Resize;
|
||||
btnAdd.SelectedValueChanged += btnAdd_SelectedValueChanged;
|
||||
btnSave.Click += BtnSave_Click;
|
||||
|
||||
}
|
||||
private float x; //定义当前窗体的宽度
|
||||
private float y; //定义当前窗体的高度
|
||||
private void InitData()
|
||||
{
|
||||
btnAdd.Items.Clear();
|
||||
btnAdd.Items.Add("相机设置");
|
||||
btnAdd.Items.Add("工位设置");
|
||||
btnAdd.Items.Add("运控设置");
|
||||
|
||||
x = Width;
|
||||
y = Height;
|
||||
AdaptiveHelper.setTag(this);
|
||||
|
||||
|
||||
if (ConfigModel.CameraBaseList.Count > 0)
|
||||
{
|
||||
var workstationItem = FindMenuItem(menu1.Items, "相机设置");
|
||||
|
||||
if (workstationItem != null)
|
||||
{
|
||||
foreach (var item in ConfigModel.CameraBaseList)
|
||||
{
|
||||
var newItem = new MenuItem();
|
||||
newItem.Text = item.CameraName;
|
||||
newItem.IconSvg = "VideoCameraOutlined";
|
||||
workstationItem.Sub.Add(newItem);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ConfigModel.DetectionList.Count > 0)
|
||||
{
|
||||
var workstationItem = FindMenuItem(menu1.Items, "工位设置");
|
||||
|
||||
if (workstationItem != null)
|
||||
{
|
||||
foreach (var item in ConfigModel.DetectionList)
|
||||
{
|
||||
var newItem = new MenuItem();
|
||||
newItem.Text = item.Name;
|
||||
newItem.IconSvg = "AppstoreOutlined";
|
||||
workstationItem.Sub.Add(newItem);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigModel.PLCBaseList.Count > 0)
|
||||
{
|
||||
var workstationItem = FindMenuItem(menu1.Items, "运控设置");
|
||||
|
||||
if (workstationItem != null)
|
||||
{
|
||||
foreach (var item in ConfigModel.PLCBaseList)
|
||||
{
|
||||
var newItem = new MenuItem();
|
||||
newItem.Text = item.PLCName;
|
||||
newItem.IconSvg = "ControlOutlined";
|
||||
workstationItem.Sub.Add(newItem);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void BtnSave_Click(object? sender, EventArgs e)
|
||||
{
|
||||
|
||||
ConfigHelper.SaveConfig();
|
||||
AntdUI.Message.success(this, "保存成功!", autoClose: 3);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void SettingWindow1_Resize(object? sender, EventArgs e)
|
||||
{
|
||||
var newx = Width / x;
|
||||
var newy = Height / y;
|
||||
AdaptiveHelper.setControls(newx, newy, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 递归查找菜单项
|
||||
private MenuItem FindMenuItem(MenuItemCollection items, string targetText)
|
||||
{
|
||||
foreach (MenuItem item in items)
|
||||
{
|
||||
if (item.Text == targetText) return item;
|
||||
if (item.Sub != null)
|
||||
{
|
||||
var subResult = FindMenuItem(item.Sub, targetText);
|
||||
if (subResult != null) return subResult;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool isUpdatingTabs = false;
|
||||
|
||||
|
||||
private void menu1_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
// 转换坐标到控件内部坐标系(考虑滚动条)
|
||||
Point clickPoint = new Point(e.X, e.Y + menu1.ScrollBar.Value);
|
||||
@ -47,21 +149,414 @@ namespace DHSoftware.Views
|
||||
|
||||
if (clickedItem != null)
|
||||
{
|
||||
// 显示节点名称弹窗
|
||||
//MessageBox.Show($"右键点击的节点: {clickedItem.Text}");
|
||||
|
||||
var menulist = new AntdUI.IContextMenuStripItem[]
|
||||
if (clickedItem.PARENTITEM == null)
|
||||
{
|
||||
new AntdUI.ContextMenuStripItem("关联相机", "")
|
||||
{
|
||||
IconSvg = "VideoCameraAddOutlined"
|
||||
}
|
||||
};
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (clickedItem.PARENTITEM.Text)
|
||||
{
|
||||
case "相机设置":
|
||||
foreach (var tab in tabs1.Pages)
|
||||
{
|
||||
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
|
||||
{
|
||||
isUpdatingTabs = true;
|
||||
tabs1.SelectedTab = existingTab; // 直接跳转到已存在的 TabPage
|
||||
isUpdatingTabs = false;
|
||||
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//先获取是否存在该名称的配置
|
||||
//如果没有新建项
|
||||
CameraBase? CameraBase= ConfigModel.CameraBaseList.Where(c => c.CameraName == clickedItem.Text).FirstOrDefault();
|
||||
if (CameraBase == null)
|
||||
{
|
||||
CameraBase=new CameraBase();
|
||||
}
|
||||
UserControl control = null;
|
||||
control = new CameraControl(this, CameraBase);
|
||||
if (control != null)
|
||||
{
|
||||
//容器添加控件,需要调整dpi
|
||||
control.Dock = DockStyle.Fill;
|
||||
AutoDpi(control);
|
||||
AntdUI.TabPage tabPage = new AntdUI.TabPage()
|
||||
{
|
||||
Text = $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}",
|
||||
ReadOnly = false,
|
||||
|
||||
};
|
||||
tabPage.Controls.Add(control);
|
||||
tabs1.Pages.Add(tabPage);
|
||||
isUpdatingTabs = true;
|
||||
tabs1.SelectedTab = tabPage;
|
||||
isUpdatingTabs = false;
|
||||
currControl = control;
|
||||
}
|
||||
break;
|
||||
case "工位设置":
|
||||
// 检查是否已存在同名 TabPage
|
||||
foreach (var tab in tabs1.Pages)
|
||||
{
|
||||
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
|
||||
{
|
||||
isUpdatingTabs = true;
|
||||
tabs1.SelectedTab = existingTab; // 直接跳转到已存在的 TabPage
|
||||
isUpdatingTabs = false;
|
||||
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
DetectionConfig? detectionConfig = ConfigModel.DetectionList.Where(c => c.Name == clickedItem.Text).FirstOrDefault();
|
||||
if (detectionConfig == null)
|
||||
{
|
||||
detectionConfig = new DetectionConfig();
|
||||
}
|
||||
UserControl control1 = null;
|
||||
control1 = new DetectControl(this, detectionConfig);
|
||||
if (control1 != null)
|
||||
{
|
||||
//容器添加控件,需要调整dpi
|
||||
control1.Dock = DockStyle.Fill;
|
||||
AutoDpi(control1);
|
||||
AntdUI.TabPage tabPage = new AntdUI.TabPage()
|
||||
{
|
||||
Text = $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}",
|
||||
ReadOnly = false ,
|
||||
|
||||
};
|
||||
tabPage.Controls.Add(control1);
|
||||
tabs1.Pages.Add(tabPage);
|
||||
isUpdatingTabs = true;
|
||||
tabs1.SelectedTab = tabPage;
|
||||
isUpdatingTabs = false;
|
||||
currControl = control1;
|
||||
}
|
||||
break;
|
||||
|
||||
case "运控设置":
|
||||
foreach (var tab in tabs1.Pages)
|
||||
{
|
||||
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
|
||||
{
|
||||
isUpdatingTabs = true;
|
||||
tabs1.SelectedTab = existingTab; // 直接跳转到已存在的 TabPage
|
||||
isUpdatingTabs = false;
|
||||
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
//先获取是否存在该名称的配置
|
||||
//如果没有新建项
|
||||
PLCBase? pLCBase = ConfigModel.PLCBaseList.Where(c => c.PLCName == clickedItem.Text).FirstOrDefault();
|
||||
if (pLCBase == null)
|
||||
{
|
||||
pLCBase = new PLCBase();
|
||||
}
|
||||
UserControl control2 = null;
|
||||
control = new MotionControl(this, pLCBase);
|
||||
if (control != null)
|
||||
{
|
||||
//容器添加控件,需要调整dpi
|
||||
control.Dock = DockStyle.Fill;
|
||||
AutoDpi(control);
|
||||
AntdUI.TabPage tabPage = new AntdUI.TabPage()
|
||||
{
|
||||
Text = $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}",
|
||||
ReadOnly = false,
|
||||
|
||||
};
|
||||
tabPage.Controls.Add(control);
|
||||
tabs1.Pages.Add(tabPage);
|
||||
isUpdatingTabs = true;
|
||||
tabs1.SelectedTab = tabPage;
|
||||
isUpdatingTabs = false;
|
||||
currControl = control;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
|
||||
// 转换坐标到控件内部坐标系(考虑滚动条)
|
||||
Point clickPoint = new Point(e.X, e.Y + menu1.ScrollBar.Value);
|
||||
|
||||
// 递归查找命中的菜单项
|
||||
MenuItem clickedItem = FindClickedItem(menu1.Items, clickPoint);
|
||||
|
||||
if (clickedItem != null)
|
||||
{
|
||||
if (clickedItem.PARENTITEM == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (clickedItem.PARENTITEM.Text)
|
||||
{
|
||||
case "相机设置":
|
||||
var menulist = new AntdUI.IContextMenuStripItem[]
|
||||
{
|
||||
new AntdUI.ContextMenuStripItem("重命名", "")
|
||||
{
|
||||
IconSvg = "RetweetOutlined"
|
||||
},
|
||||
new AntdUI.ContextMenuStripItem("删除相机", "")
|
||||
{
|
||||
IconSvg = "DeleteOutlined"
|
||||
}
|
||||
|
||||
};
|
||||
AntdUI.ContextMenuStrip.open(menu1, it =>
|
||||
{
|
||||
switch (it.Text)
|
||||
{
|
||||
case "删除相机":
|
||||
menu1.Remove(clickedItem);
|
||||
foreach (var tab in tabs1.Pages)
|
||||
{
|
||||
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
|
||||
{
|
||||
isUpdatingTabs = true;
|
||||
tabs1.Pages.Remove(tab);
|
||||
ConfigModel.CameraBaseList.RemoveAll(c => c.CameraName == clickedItem.Text);
|
||||
isUpdatingTabs = false;
|
||||
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
ConfigModel.CameraBaseList.RemoveAll(c => c.CameraName == clickedItem.Text);
|
||||
break;
|
||||
case "重命名":
|
||||
// 保存原始名称用于查找
|
||||
string originalName = clickedItem.Text;
|
||||
|
||||
var form = new AddCameraControl(this, "重命名相机操作")
|
||||
{
|
||||
Size = new Size(300, 200),
|
||||
// 传递当前名称到表单
|
||||
CubicleName = originalName
|
||||
};
|
||||
|
||||
AntdUI.Modal.open(new AntdUI.Modal.Config(this, "", form, TType.None)
|
||||
{
|
||||
BtnHeight = 0,
|
||||
});
|
||||
|
||||
if (form.submit && !string.IsNullOrWhiteSpace(form.CubicleName))
|
||||
{
|
||||
string newName = form.CubicleName.Trim();
|
||||
|
||||
if (ConfigModel.CameraBaseList.Any(c =>
|
||||
c.CameraName.Equals(newName, StringComparison.OrdinalIgnoreCase) &&
|
||||
c.CameraName != originalName))
|
||||
{
|
||||
AntdUI.Message.warn(this, $"相机名称 '{newName}' 已存在!", autoClose: 3);
|
||||
return;
|
||||
}
|
||||
|
||||
clickedItem.Text= newName;
|
||||
var camera = ConfigModel.CameraBaseList.FirstOrDefault(c =>
|
||||
c.CameraName.Equals(originalName, StringComparison.OrdinalIgnoreCase));
|
||||
camera.CameraName = newName;
|
||||
foreach (var tab in tabs1.Pages)
|
||||
{
|
||||
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{originalName}")
|
||||
{
|
||||
isUpdatingTabs = true;
|
||||
existingTab.Text = $"{clickedItem.PARENTITEM.Text}-{newName}";
|
||||
isUpdatingTabs = false;
|
||||
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
AntdUI.Message.success(this, $"已将 '{originalName}重命名成{newName}'!", autoClose: 3);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}, menulist);
|
||||
break;
|
||||
case "工位设置":
|
||||
var menulist1 = new AntdUI.IContextMenuStripItem[]
|
||||
{ new AntdUI.ContextMenuStripItem("重命名", "")
|
||||
{
|
||||
IconSvg = "RetweetOutlined"
|
||||
},
|
||||
new AntdUI.ContextMenuStripItem("删除工位", "")
|
||||
{
|
||||
IconSvg = "DeleteOutlined"
|
||||
}
|
||||
|
||||
};
|
||||
AntdUI.ContextMenuStrip.open(menu1, it =>
|
||||
{
|
||||
switch (it.Text)
|
||||
{
|
||||
case "删除工位":
|
||||
menu1.Remove(clickedItem);
|
||||
foreach (var tab in tabs1.Pages)
|
||||
{
|
||||
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
|
||||
{
|
||||
isUpdatingTabs = true;
|
||||
tabs1.Pages.Remove(tab);
|
||||
isUpdatingTabs = false;
|
||||
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
ConfigModel.DetectionList.RemoveAll(c => c.Name == clickedItem.Text);
|
||||
break;
|
||||
case "重命名":
|
||||
// 保存原始名称用于查找
|
||||
string originalName = clickedItem.Text;
|
||||
|
||||
var form = new AddCubicleControl(this, "重命名工位操作")
|
||||
{
|
||||
Size = new Size(300, 200),
|
||||
// 传递当前名称到表单
|
||||
CubicleName = originalName
|
||||
};
|
||||
|
||||
AntdUI.Modal.open(new AntdUI.Modal.Config(this, "", form, TType.None)
|
||||
{
|
||||
BtnHeight = 0,
|
||||
});
|
||||
|
||||
if (form.submit && !string.IsNullOrWhiteSpace(form.CubicleName))
|
||||
{
|
||||
string newName = form.CubicleName.Trim();
|
||||
|
||||
if (ConfigModel.DetectionList.Any(c =>
|
||||
c.Name.Equals(newName, StringComparison.OrdinalIgnoreCase) &&
|
||||
c.Name != originalName))
|
||||
{
|
||||
AntdUI.Message.warn(this, $"工位名称 '{newName}' 已存在!", autoClose: 3);
|
||||
return;
|
||||
}
|
||||
|
||||
clickedItem.Text = newName;
|
||||
var detection = ConfigModel.DetectionList.FirstOrDefault(c =>
|
||||
c.Name.Equals(originalName, StringComparison.OrdinalIgnoreCase));
|
||||
detection.Name = newName;
|
||||
foreach (var tab in tabs1.Pages)
|
||||
{
|
||||
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{originalName}")
|
||||
{
|
||||
isUpdatingTabs = true;
|
||||
existingTab.Text = $"{clickedItem.PARENTITEM.Text}-{newName}";
|
||||
isUpdatingTabs = false;
|
||||
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
AntdUI.Message.success(this, $"已将 '{originalName}重命名成{newName}'!", autoClose: 3);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}, menulist1);
|
||||
break;
|
||||
|
||||
case "运控设置":
|
||||
var menulist2 = new AntdUI.IContextMenuStripItem[]
|
||||
{
|
||||
new AntdUI.ContextMenuStripItem("重命名", "")
|
||||
{
|
||||
IconSvg = "RetweetOutlined"
|
||||
},
|
||||
new AntdUI.ContextMenuStripItem("删除运控", "")
|
||||
{
|
||||
IconSvg = "DeleteOutlined"
|
||||
}
|
||||
|
||||
};
|
||||
AntdUI.ContextMenuStrip.open(menu1, it =>
|
||||
{
|
||||
switch (it.Text)
|
||||
{
|
||||
case "删除运控":
|
||||
menu1.Remove(clickedItem);
|
||||
foreach (var tab in tabs1.Pages)
|
||||
{
|
||||
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
|
||||
{
|
||||
isUpdatingTabs = true;
|
||||
//tabs1.SelectedTab = existingTab; // 直接跳转到已存在的 TabPage
|
||||
tabs1.Pages.Remove(tab);
|
||||
ConfigModel.PLCBaseList.RemoveAll(c => c.PLCName == clickedItem.Text);
|
||||
isUpdatingTabs = false;
|
||||
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
ConfigModel.PLCBaseList.RemoveAll(c => c.PLCName == clickedItem.Text);
|
||||
|
||||
break;
|
||||
case "重命名":
|
||||
|
||||
var form = new AddMotionControl(this, "重命名运动控制操作") { Size = new Size(300, 200) };
|
||||
AntdUI.Modal.open(new AntdUI.Modal.Config(this, "", form, TType.None)
|
||||
{
|
||||
BtnHeight = 0,
|
||||
});
|
||||
if (form.submit)
|
||||
{
|
||||
string originalName = clickedItem.Text;
|
||||
if (form.submit && !string.IsNullOrWhiteSpace(form.MotionName))
|
||||
{
|
||||
string newName = form.MotionName.Trim();
|
||||
|
||||
if (ConfigModel.PLCBaseList.Any(c =>
|
||||
c.PLCName.Equals(newName, StringComparison.OrdinalIgnoreCase) &&
|
||||
c.PLCName != originalName))
|
||||
{
|
||||
AntdUI.Message.warn(this, $"运动控制名称 '{newName}' 已存在!", autoClose: 3);
|
||||
return;
|
||||
}
|
||||
|
||||
clickedItem.Text = newName;
|
||||
var plc = ConfigModel.PLCBaseList.FirstOrDefault(c =>
|
||||
c.PLCName.Equals(originalName, StringComparison.OrdinalIgnoreCase));
|
||||
plc.PLCName = newName;
|
||||
foreach (var tab in tabs1.Pages)
|
||||
{
|
||||
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{originalName}")
|
||||
{
|
||||
isUpdatingTabs = true;
|
||||
existingTab.Text = $"{clickedItem.PARENTITEM.Text}-{newName}";
|
||||
isUpdatingTabs = false;
|
||||
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
AntdUI.Message.success(this, $"已将 '{originalName}重命名成{newName}'!", autoClose: 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}, menulist2);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private MenuItem FindClickedItem(MenuItemCollection items, Point clickPoint)
|
||||
{
|
||||
foreach (MenuItem item in items)
|
||||
@ -82,50 +577,104 @@ namespace DHSoftware.Views
|
||||
return null;
|
||||
}
|
||||
|
||||
private void btnAdd_Click(object sender, EventArgs e)
|
||||
|
||||
|
||||
private void btnAdd_SelectedValueChanged(object sender, ObjectNEventArgs e)
|
||||
{
|
||||
|
||||
var form = new AddCubicleControl(this) { Size = new Size(400, 300) };
|
||||
AntdUI.Modal.open(new AntdUI.Modal.Config(this, "", form, TType.None)
|
||||
string selectedValue = e.Value.ToString();
|
||||
switch (selectedValue)
|
||||
{
|
||||
BtnHeight = 0,
|
||||
});
|
||||
if (form.submit)
|
||||
{
|
||||
var newItem = new MenuItem(form.CubicleName);
|
||||
newItem.IconSvg = "AppstoreOutlined";
|
||||
// 防止重复添加
|
||||
if (!menu1.Items.Cast<MenuItem>().Any(m => m.Text == newItem.Text))
|
||||
{
|
||||
menu1.Items.Add(newItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
AntdUI.Notification.warn(this, "新增工位失败", $"{form.CubicleName}已存在!", autoClose: 3, align: TAlignFrom.TR);
|
||||
}
|
||||
}
|
||||
case "相机设置":
|
||||
var workstationItem = FindMenuItem(menu1.Items, "相机设置");
|
||||
|
||||
|
||||
}
|
||||
if (workstationItem != null)
|
||||
{
|
||||
|
||||
private void menu1_MouseClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
//if (e.Button == MouseButtons.Right)
|
||||
//{
|
||||
// var menu =sender as Menu;
|
||||
// if (menu?.Items.Count == 0)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
var form = new AddCameraControl(this,"新增相机操作") { Size = new Size(300, 200) };
|
||||
AntdUI.Modal.open(new AntdUI.Modal.Config(this, "", form, TType.None)
|
||||
{
|
||||
BtnHeight = 0,
|
||||
});
|
||||
if (form.submit)
|
||||
{
|
||||
var newItem = new MenuItem(form.CubicleName);
|
||||
newItem.IconSvg = "VideoCameraOutlined";
|
||||
// 防止重复添加
|
||||
if (!workstationItem.Sub.Cast<MenuItem>().Any(m => m.Text == newItem.Text))
|
||||
{
|
||||
workstationItem.Sub.Add(newItem);
|
||||
CameraBase cameraBase = new CameraBase();
|
||||
cameraBase.CameraName = form.CubicleName;
|
||||
ConfigModel.CameraBaseList.Add(cameraBase);
|
||||
}
|
||||
else
|
||||
{
|
||||
AntdUI.Message.warn(this, $"相机名称 '{form.CubicleName}' 已存在!", autoClose: 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "工位设置":
|
||||
// 查找工位设置项
|
||||
var workstationItem1= FindMenuItem(menu1.Items, "工位设置");
|
||||
|
||||
//}
|
||||
}
|
||||
if (workstationItem1 != null)
|
||||
{
|
||||
|
||||
private void btnSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
foreach(var item in menu1.Items)
|
||||
{
|
||||
var form = new AddCubicleControl(this,"新增工位操作") { Size = new Size(300, 200) };
|
||||
AntdUI.Modal.open(new AntdUI.Modal.Config(this, "", form, TType.None)
|
||||
{
|
||||
BtnHeight = 0,
|
||||
});
|
||||
if (form.submit)
|
||||
{
|
||||
var newItem = new MenuItem(form.CubicleName);
|
||||
newItem.IconSvg = "AppstoreOutlined";
|
||||
// 防止重复添加
|
||||
if (!workstationItem1.Sub.Cast<MenuItem>().Any(m => m.Text == newItem.Text))
|
||||
{
|
||||
workstationItem1.Sub.Add(newItem);
|
||||
DetectionConfig detection = new DetectionConfig();
|
||||
detection.Name = form.CubicleName;
|
||||
ConfigModel.DetectionList.Add(detection);
|
||||
}
|
||||
else
|
||||
{
|
||||
AntdUI.Message.warn(this, $"工位名称 '{form.CubicleName}' 已存在!", autoClose: 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "运控设置":
|
||||
var workstationItem2 = FindMenuItem(menu1.Items, "运控设置");
|
||||
|
||||
if (workstationItem2 != null)
|
||||
{
|
||||
|
||||
var form = new AddMotionControl(this,"新增运动控制操作") { Size = new Size(300, 200) };
|
||||
AntdUI.Modal.open(new AntdUI.Modal.Config(this, "", form, TType.None)
|
||||
{
|
||||
BtnHeight = 0,
|
||||
});
|
||||
if (form.submit)
|
||||
{
|
||||
var newItem = new MenuItem(form.MotionName);
|
||||
newItem.IconSvg = "ControlOutlined";
|
||||
// 防止重复添加
|
||||
if (!workstationItem2.Sub.Cast<MenuItem>().Any(m => m.Text == newItem.Text))
|
||||
{
|
||||
workstationItem2.Sub.Add(newItem);
|
||||
PLCBase pLCBase = new PLCBase();
|
||||
pLCBase.PLCName = form.MotionName;
|
||||
ConfigModel.PLCBaseList.Add(pLCBase);
|
||||
}
|
||||
else
|
||||
{
|
||||
AntdUI.Message.warn(this, $"运动控制名称 '{form.MotionName}' 已存在!", autoClose: 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user