using Bro.Common.Helper; using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using static Bro.Common.Helper.EnumHelper; namespace Bro.Common.Model { public class IOItem : IComplexDisplay { /// /// IO点编号 /// [Category("IO配置")] [Description("IO点编号")] public virtual int IONum { get; set; } /// /// IO点的值 /// [Category("IO配置")] [Description("IO数值")] public virtual int Value { get; set; } /// /// IO点是in还是out /// [Category("IO配置")] [Description("IO类型")] public virtual IOType IOType { get; set; } public string GetDisplayText() { return $"{IOType.GetEnumDescription()},编号{IONum},IO点的值{Value}"; } } public class IODefinition : IOItem { [Category("IO配置")] [Description("IO用途描述")] public string IODesc { get; set; } [Category("IO配置")] [Description("备注说明")] public string Remark { get; set; } [Browsable(false)] [JsonIgnore] public override int Value { get; set; } public new string GetDisplayText() { return $"{IODesc} {IOType.GetEnumDescription()} {IONum}"; } } public class IORefrenceItem { [Category("IO操作配置")] [Description("需要操作的IO")] [TypeConverter(typeof(IORefrenceItemSourceConverter))] public IOItem IOItem { get; set; } = new IOItem(); [Category("IO操作配置")] [Description("需要操作的IO的数值")] public int CheckValue { get => IOItem.Value; set => IOItem.Value = value; } [Browsable(false)] [JsonIgnore] public List IOItemSource { get; set; } = new List(); } public class IORefrenceItemSourceConverter : ComboBoxItemTypeConvert { public override Hashtable GetConvertHash(ITypeDescriptorContext context) { Hashtable table = new Hashtable(); if (context.Instance is IORefrenceItem item) { item.IOItemSource.ForEach(i => { table[i.IODesc + i.IOType.GetEnumDescription() + i.IONum] = i as IOItem; }); } return table; } } }