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
|
{
|
/// <summary>
|
/// IO点编号
|
/// </summary>
|
[Category("IO配置")]
|
[Description("IO点编号")]
|
public virtual int IONum { get; set; }
|
|
/// <summary>
|
/// IO点的值
|
/// </summary>
|
[Category("IO配置")]
|
[Description("IO数值")]
|
public virtual int Value { get; set; }
|
|
/// <summary>
|
/// IO点是in还是out
|
/// </summary>
|
[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<IODefinition> IOItemSource { get; set; } = new List<IODefinition>();
|
}
|
|
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;
|
}
|
}
|
}
|