领胜LDS 键盘AOI检测项目
wells.liu
2020-07-08 ee940e0f7c7f00471976bc151319e2e2baf1062b
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
using Bro.Common.Helper;
using Bro.Common.Interface;
using System;
using System.Reflection;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
 
namespace Bro.UI.Model.Winform
{
    public partial class MenuFrmBase : DockContent, IMenuNode, IProcessObserver, ILogOutput
    {
        public Action<string, IProcess> OnUploadProcess { get; set; }
        public event Action<LogMsg> OnLogMsgOutput;
        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
 
        protected override string GetPersistString()
        {
            var attr = this.GetType().GetCustomAttribute<MenuNodeAttribute>();
 
            if (attr == null)
            {
                return base.GetPersistString();
            }
 
            return $"MenuFrm,{attr.MenuCode},{attr.MenuName}";
        }
    }
}