using Autofac;
|
using Bro.Common.Helper;
|
using Bro.Common.Interface;
|
using Bro.Common.Model.Forms;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Drawing.Design;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms.Design;
|
|
namespace Bro.Common.Model
|
{
|
public class DeviceOpBind : IComplexDisplay
|
{
|
[Category("设备名称")]
|
[Description("设备名称")]
|
[TypeConverter(typeof(DeviceSelectorConverter<IDevice>))]
|
public virtual string Device { get; set; }
|
|
[Category("操作配置")]
|
[Description("操作配置")]
|
public IOperationConfig OpConfig { get; set; } = null;
|
|
public string GetDisplayText()
|
{
|
string msg = "";
|
using (var scope = GlobalVar.Container.BeginLifetimeScope())
|
{
|
List<IDevice> deviceList = scope.Resolve<List<IDevice>>();
|
|
if (Device != null)
|
{
|
var device = deviceList.FirstOrDefault(u => u.Id == Device);
|
|
if (device != null)
|
{
|
msg += device.Name + " ";
|
}
|
}
|
}
|
|
if (OpConfig is IComplexDisplay d)
|
{
|
msg += d.GetDisplayText();
|
}
|
else
|
{
|
msg += JsonConvert.SerializeObject(OpConfig);
|
}
|
|
return msg;
|
}
|
}
|
|
public class IOperationConfigByDeviceEditor : UITypeEditor
|
{
|
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
|
{
|
return UITypeEditorEditStyle.Modal;
|
}
|
|
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
|
{
|
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
|
|
if (edSvc != null)
|
{
|
if (value == null)
|
{
|
value = new DeviceOpBind();
|
}
|
|
if (value is DeviceOpBind bind)
|
{
|
FrmDeviceOpConfigEditor frmDeviceOpEditor = new FrmDeviceOpConfigEditor(bind);
|
frmDeviceOpEditor.ShowDialog();
|
return frmDeviceOpEditor.Bind;
|
}
|
}
|
|
return base.EditValue(context, provider, value);
|
}
|
}
|
}
|