84 lines
2.2 KiB
C#
84 lines
2.2 KiB
C#
using AntdUI;
|
|
using DH.Commons.Base;
|
|
using DH.Commons.Enums;
|
|
using DH.Devices.PLC;
|
|
|
|
namespace DHSoftware.Views
|
|
{
|
|
public partial class MotionEdit : UserControl
|
|
{
|
|
private AntdUI.Window window;
|
|
private PLCItem plcItem;
|
|
public bool submit;
|
|
public MotionEdit(AntdUI.Window _window,string TitleName, PLCItem _plcItem)
|
|
{
|
|
InitializeComponent();
|
|
lbTitleName.Text = TitleName;
|
|
plcItem = _plcItem;
|
|
// 绑定事件
|
|
BindEventHandler();
|
|
//设置默认值
|
|
InitData();
|
|
|
|
}
|
|
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)
|
|
{
|
|
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;
|
|
submit = true;
|
|
this.Dispose();
|
|
}
|
|
|
|
private void InitData()
|
|
{
|
|
var PLCItemNames = Enum.GetNames(typeof(EnumPLCOutputIO));
|
|
foreach (var name in PLCItemNames)
|
|
{
|
|
sltName.Items.Add(name);
|
|
}
|
|
var PLCDataTypes = Enum.GetNames(typeof(EnumPLCDataType));
|
|
foreach (var name in PLCDataTypes)
|
|
{
|
|
sltDataType.Items.Add(name);
|
|
}
|
|
sltDataType.SelectedIndex = 0;
|
|
|
|
|
|
if (!string.IsNullOrEmpty(plcItem.Name))
|
|
{
|
|
sltName.Text = plcItem.Name;
|
|
iptAddress.Text = plcItem.Address;
|
|
sltDataType.SelectedIndex =(int)plcItem.Type;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|