1111
This commit is contained in:
116
DHSoftware/Views/SavePositionControl.cs
Normal file
116
DHSoftware/Views/SavePositionControl.cs
Normal file
@ -0,0 +1,116 @@
|
||||
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using DH.Commons.Base;
|
||||
using DH.Commons.Enums;
|
||||
using DH.Commons.Helper;
|
||||
using DH.Commons.Models;
|
||||
|
||||
namespace DHSoftware.Views
|
||||
{
|
||||
public partial class SavePositionControl : UserControl
|
||||
{
|
||||
private AntdUI.Window window;
|
||||
public bool submit;
|
||||
public int Position;
|
||||
|
||||
|
||||
public SavePositionControl(AntdUI.Window _window,int _position)
|
||||
{
|
||||
this.window = _window;
|
||||
InitializeComponent();
|
||||
Position=_position;
|
||||
sltName.Items.Clear();
|
||||
var targetFields = GetSpecificIOFields();
|
||||
foreach(var item in targetFields)
|
||||
{
|
||||
sltName.Items.Add(item);
|
||||
}
|
||||
iptPosition.Text= Position.ToString();
|
||||
// 绑定事件
|
||||
BindEventHandler();
|
||||
}
|
||||
|
||||
private void BindEventHandler()
|
||||
{
|
||||
button_ok.Click += Button_ok_Click;
|
||||
button_cancel.Click += Button_cancel_Click;
|
||||
}
|
||||
|
||||
private void Button_cancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
submit = false;
|
||||
this.Dispose();
|
||||
}
|
||||
|
||||
private void Button_ok_Click(object sender, EventArgs e)
|
||||
{
|
||||
iptPosition.Status = AntdUI.TType.None;
|
||||
|
||||
if (String.IsNullOrEmpty(sltName.Text))
|
||||
{
|
||||
sltName.Status = AntdUI.TType.Error;
|
||||
AntdUI.Message.warn(window, "请选择工位!", autoClose: 3);
|
||||
return;
|
||||
}
|
||||
|
||||
//根据工位查找点位
|
||||
PLCItem? pLCItem = ConfigModel.PLCBaseList?
|
||||
.FirstOrDefault()?
|
||||
.PLCItemList?
|
||||
.Where(it=>it.Name==sltName.Text).FirstOrDefault();
|
||||
if (pLCItem == null)
|
||||
{
|
||||
AntdUI.Message.warn(window, $"未找到{sltName.Text}地址,请检查该地址是否存在于点位表!", autoClose: 3);
|
||||
return;
|
||||
}
|
||||
|
||||
PLCItem? pLCItem1 = ConfigModel.GlobalList?
|
||||
.FirstOrDefault()?
|
||||
.StartProcessList?
|
||||
.Where(it=>it.Name ==sltName.Text).FirstOrDefault();
|
||||
|
||||
if (pLCItem1 == null)
|
||||
{
|
||||
pLCItem1=new PLCItem();
|
||||
pLCItem1.Name = pLCItem.Name;
|
||||
pLCItem1.Address = pLCItem.Address;
|
||||
pLCItem1.Value = iptPosition.Text;
|
||||
pLCItem1.Type = pLCItem.Type;
|
||||
pLCItem1.StartExecute = true;
|
||||
ConfigModel.GlobalList?
|
||||
.FirstOrDefault()?
|
||||
.StartProcessList?.Add(pLCItem1);
|
||||
}
|
||||
else
|
||||
{
|
||||
pLCItem1.Value = iptPosition.Text;
|
||||
}
|
||||
|
||||
ConfigHelper.SaveConfig();
|
||||
AntdUI.Message.success(window, "保存成功!", autoClose: 3);
|
||||
submit = true;
|
||||
this.Dispose();
|
||||
}
|
||||
|
||||
public static List<string> GetSpecificIOFields()
|
||||
{
|
||||
return Enum.GetNames(typeof(EnumPLCOutputIO))
|
||||
.Where(name =>
|
||||
Regex.IsMatch(name, @"^工位[1-9]|10$") || // 匹配工位1-10
|
||||
name == "OK脉冲" ||
|
||||
name == "NG脉冲")
|
||||
.OrderBy(name =>
|
||||
{
|
||||
// 对工位进行数字排序
|
||||
if (name.StartsWith("工位"))
|
||||
{
|
||||
return int.Parse(name.Substring(2));
|
||||
}
|
||||
return 99; // OK/NG放在最后
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user