202303241701Change
This commit is contained in:
23
XKRS.UI.Model.Winform/Helper/AttributeHelper.cs
Normal file
23
XKRS.UI.Model.Winform/Helper/AttributeHelper.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace XKRS.UI.Model.Winform
|
||||
{
|
||||
/// <summary>
|
||||
/// 菜单节点属性
|
||||
/// </summary>
|
||||
public class MenuNodeAttribute:Attribute
|
||||
{
|
||||
public string MenuCode { get; set; }
|
||||
public string MenuName { get; set; }
|
||||
public int MenuOrder { get; set; }
|
||||
public string ParentMenuCode { get; set; }
|
||||
/// <summary>
|
||||
/// 表示该窗体是实际显示窗体还是只是父节点
|
||||
/// </summary>
|
||||
public bool IsActualForm { get; set; }
|
||||
}
|
||||
}
|
106
XKRS.UI.Model.Winform/Helper/MenuFormFactory.cs
Normal file
106
XKRS.UI.Model.Winform/Helper/MenuFormFactory.cs
Normal file
@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using XKRS.Common.Interface;
|
||||
|
||||
namespace XKRS.UI.Model.Winform.Helper
|
||||
{
|
||||
public static class MenuFormFactory
|
||||
{
|
||||
|
||||
public static Dictionary<MenuNodeAttribute, Type> menuFrmTypeDict = null;
|
||||
public static Dictionary<MenuNodeAttribute,Type> MenuFrmTypeDict
|
||||
{
|
||||
get
|
||||
{
|
||||
if (menuFrmTypeDict == null)
|
||||
{
|
||||
var assm = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory)
|
||||
.GetFiles("*.dll")
|
||||
.Where(fi =>
|
||||
{
|
||||
return fi.Name.StartsWith("XKRS");
|
||||
})
|
||||
.Select(u =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return Assembly.LoadFrom(u.FullName);
|
||||
}
|
||||
catch { }
|
||||
return null;
|
||||
})
|
||||
.Where(a => a != null)
|
||||
.ToList();
|
||||
assm.AddRange(AppDomain.CurrentDomain.GetAssemblies());
|
||||
assm = assm.Distinct().ToList();
|
||||
|
||||
try
|
||||
{
|
||||
menuFrmTypeDict = assm.SelectMany(a => a.GetTypes())
|
||||
.Where(t =>
|
||||
{
|
||||
if (t.GetInterfaces().Contains(typeof(IMenuNode)))
|
||||
{
|
||||
var attr = t.GetCustomAttribute<MenuNodeAttribute>();
|
||||
return attr != null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}).ToDictionary(t => t.GetCustomAttribute<MenuNodeAttribute>(), t => t);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return menuFrmTypeDict;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 从Menu配置项转为窗口
|
||||
/// </summary>
|
||||
/// <param name="frmCode"></param>
|
||||
/// <returns></returns>
|
||||
public static MenuFormBase GetMenuFrm(string frmCode)
|
||||
{
|
||||
Type frmType = GetMenuFrmType(frmCode);
|
||||
if (frmType == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var menuItem = Activator.CreateInstance(frmType);
|
||||
if (menuItem == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var menu = menuItem as MenuFormBase;
|
||||
if (menu == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
menu.Tag = frmCode;
|
||||
return menu;
|
||||
}
|
||||
|
||||
public static Type GetMenuFrmType(string frmCode)
|
||||
{
|
||||
Type frmType = null;
|
||||
foreach (KeyValuePair<MenuNodeAttribute,Type> pair in MenuFrmTypeDict)
|
||||
{
|
||||
if (pair.Key.MenuCode == frmCode)
|
||||
{
|
||||
frmType = pair.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return frmType;
|
||||
}
|
||||
}
|
||||
}
|
@ -15,10 +15,21 @@ namespace XKRS.UI.Model.Winform
|
||||
public partial class DeviceRunFrmBase : DockContent
|
||||
{
|
||||
public IDevice Device { get; set; }
|
||||
public IRunCtrl RunCtrl { get; set; }
|
||||
|
||||
public DeviceRunFrmBase()
|
||||
public DeviceRunFrmBase() : base()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public DeviceRunFrmBase(IDevice device,IRunCtrl runCtrl) : base()
|
||||
{
|
||||
Device = device;
|
||||
RunCtrl = runCtrl;
|
||||
UserControl uc = RunCtrl as UserControl;
|
||||
uc.Dock = DockStyle.Fill;
|
||||
this.Controls.Add(uc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
namespace XKRS.UI.Model.Winform
|
||||
{
|
||||
partial class MenuFrmBase
|
||||
partial class MenuFormBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@ -31,13 +31,13 @@ namespace XKRS.UI.Model.Winform
|
||||
{
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// MenuFrmBase
|
||||
// MenuFormBase
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
|
||||
this.ClientSize = new System.Drawing.Size(474, 344);
|
||||
this.DoubleBuffered = true;
|
||||
this.Font = new System.Drawing.Font("Tahoma", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World);
|
||||
this.Name = "MenuFrmBase";
|
||||
this.Name = "MenuFormBase";
|
||||
this.Text = "MenuFrmBase";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
|
@ -12,24 +12,52 @@ using XKRS.Common.Interface;
|
||||
|
||||
namespace XKRS.UI.Model.Winform
|
||||
{
|
||||
public partial class MenuFrmBase : DockContent
|
||||
public partial class MenuFormBase : DockContent
|
||||
{
|
||||
public Action<string,IProcess> OnUploadProcess { get; set; }
|
||||
public event Action<bool> OnIsLoginChanged;
|
||||
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
|
||||
public MenuFrmBase()
|
||||
private IProcess process = null;
|
||||
public IProcess Process
|
||||
{
|
||||
get => process;
|
||||
set
|
||||
{
|
||||
if (process != value)
|
||||
{
|
||||
process = value;
|
||||
OnProcessUpdated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MenuFormBase()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
#region IProcessObserver
|
||||
public virtual void OnProcessUpdated() { }
|
||||
|
||||
public virtual void DownloadProcess(IProcess process)
|
||||
{
|
||||
Process = process;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region Login
|
||||
protected virtual bool IsLogin { get; set; }
|
||||
public virtual void SetLoginStatus(bool isLogin)
|
||||
{
|
||||
IsLogin = isLogin;
|
||||
OnIsLoginChanged?.Invoke(IsLogin);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
@ -60,6 +60,8 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Helper\AttributeHelper.cs" />
|
||||
<Compile Include="Helper\MenuFormFactory.cs" />
|
||||
<Compile Include="UI\DockContent\DeviceRunFrmBase.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
Reference in New Issue
Block a user