领胜LDS 键盘AOI检测项目
wells.liu
2020-07-04 642cd31f0d1586a2a5ca6f9a3b3364725f4f1ecd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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);
        }
    }
}