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 plcItemList; public bool submit; public MotionProcessEdit(AntdUI.Window _window, string TitleName, PLCItem _plcItem, BindingList _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; sltDataType.SelectedIndexChanged += SltDataType_SelectedIndexChanged; } private void SltDataType_SelectedIndexChanged(object sender, IntEventArgs e) { iptValue.Visible = e.Value != 3; sltValue.Visible = e.Value == 3; } 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; if (sltDataType.SelectedIndex != 3) { plcItem.Value = iptValue.Text; } else { plcItem.Value = sltValue.Text; } plcItem.StartExecute = sltEnable.SelectedIndex != 0; submit = true; this.Dispose(); } private void InitData() { foreach (var item in plcItemList) { sltName.Items.Add(item.Name); } var PLCDataTypes = Enum.GetNames(typeof(EnumPLCDataType)); foreach (var name in PLCDataTypes) { sltDataType.Items.Add(name); } var boolNames = Enum.GetNames(typeof(EnumBool)); foreach (var name in boolNames) { sltEnable.Items.Add(name); } var bool1Names = Enum.GetNames(typeof(EnumBool1)); foreach (var name in bool1Names) { sltValue.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; if (sltDataType.SelectedIndex != 3) { iptValue.Text = plcItem.Value; } else { sltValue.SelectedIndex=plcItem.Value=="True"?1:0; } } } private void panel1_Click(object sender, EventArgs e) { } } }