领胜LDS 键盘AOI检测项目
xcd
2020-07-04 753b5add58defa5c09015308efb81bcaea0ebe91
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using Bro.Common.Helper;
using Bro.Common.Interface;
//using Bro.UI.Config.Helper;
using System;
using System.Reflection;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
 
namespace Bro.UI.Config.MenuForms
{
    public interface IMenuNode
    {
        //IProcess Process { get; set; }
 
        //void DownloadProcess(IProcess process);
        //Action<IProcess> OnUploadProcess { get; set; }
    }
 
    public interface IProcessObserver
    {
        IProcess Process { get; set; }
 
        void OnProcessUpdated();
        void DownloadProcess(IProcess process);
    }
 
    public interface ILogOutput
    {
        Action<LogMsg> OnLogMsgOutput { get; set; }
        void LogDisplay(LogMsg msg);
    }
 
    public partial class MenuFrmBase : DockContent, IMenuNode, IProcessObserver, ILogOutput
    {
        public Action<string, IProcess> OnUploadProcess { get; set; }
        public Action<LogMsg> OnLogMsgOutput { get; set; }
        public string Id { get; set; } = Guid.NewGuid().ToString();
 
        private IProcess process = null;
 
        public IProcess Process
        {
            get => process;
            set
            {
                //if (process != value)
                {
                    process = value;
                    OnProcessUpdated();
                }
            }
        }
 
        public MenuFrmBase()
        {
            InitializeComponent();
 
            var dockAttr = GetType().GetCustomAttribute<DockOptionAttribute>();
            if (dockAttr != null)
            {
                FormClosing += MenuFrmBase_FormClosing;
            }
        }
 
        protected virtual void MenuFrmBase_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason != CloseReason.MdiFormClosing)
            {
                e.Cancel = true;
 
                if (DockHandler.DockPanel != null)
                    Hide();
            }
        }
 
        #region IProcessObserver
        public virtual void OnProcessUpdated()
        {
        }
 
        public virtual void DownloadProcess(IProcess process)
        {
            Process = process;
        }
        #endregion
 
        #region ILogOutput
        public virtual void LogDisplay(LogMsg msg)
        {
        }
 
        protected virtual void LogAsync(LogMsg msg)
        {
            OnLogMsgOutput?.Invoke(msg);
        }
 
        protected virtual void LogAsync(DateTime dt, string prefix, string msg = "")
        {
            OnLogMsgOutput?.Invoke(new LogMsg(dt, prefix, msg));
        }
        #endregion
 
        #region Login
        protected bool IsLogin { get; set; }
 
        public virtual void SetLoginStatus(bool isLogin)
        {
            IsLogin = isLogin;
        }
        #endregion
    }
}