105 lines
3.1 KiB
C#
105 lines
3.1 KiB
C#
using System.ComponentModel;
|
|
using AntdUI;
|
|
using DH.Commons.Base;
|
|
using DH.Commons.Enums;
|
|
using DH.Devices.PLC;
|
|
|
|
namespace DHSoftware.Views
|
|
{
|
|
public partial class MotionProcessEdit : UserControl
|
|
{
|
|
private AntdUI.Window window;
|
|
private PLCItem plcItem;
|
|
private BindingList<PLCItem> plcItemList;
|
|
public bool submit;
|
|
public MotionProcessEdit(AntdUI.Window _window, string TitleName, PLCItem _plcItem, BindingList<PLCItem> _plcItemList)
|
|
{
|
|
InitializeComponent();
|
|
lbTitleName.Text = TitleName;
|
|
plcItem = _plcItem;
|
|
plcItemList= _plcItemList;
|
|
// 绑定事件
|
|
BindEventHandler();
|
|
//设置默认值
|
|
InitData();
|
|
|
|
}
|
|
private void BindEventHandler()
|
|
{
|
|
sltName.SelectedIndexChanged += SltName_SelectedIndexChanged;
|
|
button_ok.Click += Button_ok_Click;
|
|
button_cancel.Click += Button_cancel_Click;
|
|
|
|
|
|
|
|
}
|
|
|
|
private void SltName_SelectedIndexChanged(object sender, IntEventArgs e)
|
|
{
|
|
Select select = (Select)sender;
|
|
var pLCItems=plcItemList.Where(it=>it.Name==select.Text).FirstOrDefault();
|
|
if (pLCItems != null)
|
|
{
|
|
sltDataType.SelectedIndex =(int)pLCItems.Type;
|
|
iptAddress.Text= pLCItems.Address;
|
|
}
|
|
}
|
|
|
|
private void Button_cancel_Click(object sender, EventArgs e)
|
|
{
|
|
submit = false;
|
|
this.Dispose();
|
|
}
|
|
|
|
private void Button_ok_Click(object sender, EventArgs e)
|
|
{
|
|
sltName.Status = AntdUI.TType.None;
|
|
//检查输入内容
|
|
if (String.IsNullOrEmpty(sltName.Text))
|
|
{
|
|
sltName.Status = AntdUI.TType.Error;
|
|
AntdUI.Message.warn(window, "参数名称不能为空!", autoClose: 3);
|
|
return;
|
|
}
|
|
plcItem.Name = sltName.Text;
|
|
plcItem.Address = iptAddress.Text;
|
|
plcItem.Type = (EnumPLCDataType)sltDataType.SelectedIndex;
|
|
plcItem.Value=iptValue.Text;
|
|
plcItem.StartExecute = sltEnable.SelectedIndex != 0;
|
|
submit = true;
|
|
this.Dispose();
|
|
}
|
|
|
|
private void InitData()
|
|
{
|
|
|
|
foreach (var item in plcItemList)
|
|
{
|
|
sltName.Items.Add(item.Name);
|
|
sltDataType.Items.Add(item.Type);
|
|
}
|
|
|
|
var boolNames = Enum.GetNames(typeof(EnumBool));
|
|
foreach (var name in boolNames)
|
|
{
|
|
sltEnable.Items.Add(name);
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(plcItem.Name))
|
|
{
|
|
sltName.Text = plcItem.Name;
|
|
iptAddress.Text = plcItem.Address;
|
|
sltDataType.SelectedIndex = (int)plcItem.Type;
|
|
sltEnable.SelectedIndex = plcItem.StartExecute ? 1 : 0;
|
|
iptValue.Text = plcItem.Value;
|
|
}
|
|
}
|
|
|
|
private void panel1_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|