202303241701Change
This commit is contained in:
8
CopyCode/MainFrm.Designer.cs
generated
8
CopyCode/MainFrm.Designer.cs
generated
@ -51,7 +51,7 @@ namespace XKRS.UI.Main
|
||||
//
|
||||
// menuMain
|
||||
//
|
||||
this.menuMain.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
this.menuMain.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.menuMain.AutoSize = false;
|
||||
this.menuMain.Dock = System.Windows.Forms.DockStyle.None;
|
||||
@ -64,7 +64,7 @@ namespace XKRS.UI.Main
|
||||
//
|
||||
// ststripDevices
|
||||
//
|
||||
this.ststripDevices.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
this.ststripDevices.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ststripDevices.AutoSize = false;
|
||||
this.ststripDevices.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(77)))), ((int)(((byte)(96)))), ((int)(((byte)(130)))));
|
||||
@ -173,8 +173,8 @@ namespace XKRS.UI.Main
|
||||
//
|
||||
// dockPanelMain
|
||||
//
|
||||
this.dockPanelMain.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
this.dockPanelMain.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.dockPanelMain.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World);
|
||||
this.dockPanelMain.Location = new System.Drawing.Point(0, 24);
|
||||
|
@ -14,6 +14,7 @@ using XKRS.Common.Factory;
|
||||
using XKRS.Common.Interface;
|
||||
using XKRS.Common.Model.Helper;
|
||||
using XKRS.UI.Model.Winform;
|
||||
using XKRS.UI.Model.Winform.Helper;
|
||||
|
||||
namespace XKRS.UI.Main
|
||||
{
|
||||
@ -32,13 +33,121 @@ namespace XKRS.UI.Main
|
||||
dockPanelMain.Theme = theme;
|
||||
VisualStudioToolStripExtender extender = new VisualStudioToolStripExtender();
|
||||
extender.SetStyle(menuMain, VisualStudioToolStripExtender.VsVersion.Vs2015, theme);
|
||||
InitialMenu()
|
||||
|
||||
InitialMenu(MenuFormFactory.MenuFrmTypeDict, "");
|
||||
|
||||
m_deserializeMenuFrm = new DeserializeDockContent(GetMenuFromPersistString);
|
||||
m_deserializeDeviceRunFrm = new DeserializeDockContent(GetAllFormPersistString);
|
||||
|
||||
notifyIcon.Text = SettingHelper.GetProgramDescription();
|
||||
string iconPath = SettingHelper.GetProgramIcon();
|
||||
if (!string.IsNullOrWhiteSpace(iconPath))
|
||||
{
|
||||
notifyIcon.Icon = Icon = new Icon(iconPath);
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterEvent(MenuFormBase dockFrm)
|
||||
{
|
||||
dockFrm.OnUploadProcess = DockFrm_OnUploadProcess;
|
||||
}
|
||||
|
||||
|
||||
#region Menu
|
||||
readonly ManualResetEvent _allMenuLoadDoneHandle = new ManualResetEvent(false);
|
||||
|
||||
private void InitialMenu(Dictionary<MenuNodeAttribute, Type> menuFrmTypeDict, string parentMenuCode)
|
||||
{
|
||||
menuFrmTypeDict.Keys.Where(u => u.ParentMenuCode == parentMenuCode).OrderBy(m => m.MenuOrder).ToList().ForEach(m =>
|
||||
{
|
||||
ToolStripMenuItem item = new ToolStripMenuItem(m.MenuName);
|
||||
item.Tag = m.MenuCode;
|
||||
if (m.IsActualForm)
|
||||
{
|
||||
item.Click += MenuFormItem_Click;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private async void DockFrm_OnUploadProcess(string frmId, IProcess process)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
_allMenuLoadDoneHandle.WaitOne();//阻止当前线程,直到WaitHandle接收到信号
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
_process = process;
|
||||
|
||||
|
||||
CloseAllDeviceFrm();
|
||||
try
|
||||
{
|
||||
foreach (var dock in dockPanelMain.Contents)
|
||||
{
|
||||
MenuFormBase m = dock as MenuFormBase;
|
||||
if (m != null && m.Id != frmId)
|
||||
{
|
||||
m.DownloadProcess(process);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void MenuFormItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
SuspendLayout();
|
||||
ToolStripMenuItem item = sender as ToolStripMenuItem;
|
||||
bool isExisted = false;
|
||||
foreach (var dock in dockPanelMain.Contents)
|
||||
{
|
||||
MenuFormBase menu = dock as MenuFormBase;
|
||||
if (menu != null && menu.Tag.ToString() == item.Tag.ToString())
|
||||
{
|
||||
if (menu.IsHidden)
|
||||
{
|
||||
menu.Show();
|
||||
}
|
||||
menu.BringToFront();
|
||||
isExisted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isExisted)
|
||||
{
|
||||
ResumeLayout();
|
||||
return;
|
||||
}
|
||||
MenuFormBase dockFrm = MenuFormFactory.GetMenuFrm(item.Tag.ToString());
|
||||
if (dockFrm == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
dockFrm.Text = item.Text;
|
||||
|
||||
dockFrm.DockPanel = dockPanelMain;
|
||||
dockFrm.SetLoginStatus(IsLogin);
|
||||
dockFrm.DockStateChanged += DockStateChanged;
|
||||
dockFrm.Show();
|
||||
|
||||
RegisterEvent(dockFrm);
|
||||
ResumeLayout();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
private void MainFrm_Load(object sender, EventArgs e)
|
||||
@ -136,7 +245,7 @@ namespace XKRS.UI.Main
|
||||
/// <param name="isInitialProcess">是否为初始化流程</param>
|
||||
private void LoadProcess(bool isInitialProcess = true)
|
||||
{
|
||||
if(isInitialProcess)//初次创建流程
|
||||
if (isInitialProcess)//初次创建流程
|
||||
{
|
||||
var processCodes = LoadProcessCode();
|
||||
var productionCodes = LoadProductionCode();
|
||||
@ -162,9 +271,9 @@ namespace XKRS.UI.Main
|
||||
{
|
||||
isLogin = value;
|
||||
tsslLoginStatus.Text = isLogin ? "已登录" : "未登录";
|
||||
foreach(var dock in dockPanelMain.Contents)
|
||||
foreach (var dock in dockPanelMain.Contents)
|
||||
{
|
||||
var menuFrm = dock as MenuFrmBase;
|
||||
var menuFrm = dock as MenuFormBase;
|
||||
if (menuFrm != null)
|
||||
{
|
||||
menuFrm.SetLoginStatus(isLogin);
|
||||
@ -179,42 +288,11 @@ namespace XKRS.UI.Main
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Layout布局
|
||||
|
||||
string _layoutFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{SettingHelper.GetSelectLayout()}.layout");//路径
|
||||
private DeserializeDockContent m_deserializeMenuFrm;
|
||||
private DeserializeDockContent m_deserializeDeviceRunFrm;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void LoadLayoutFromXML(DeserializeDockContent dContent)
|
||||
{
|
||||
if (!File.Exists(_layoutFile))
|
||||
return;
|
||||
dockPanelMain.SuspendLayout(true);//悬挂式布局
|
||||
|
||||
CloseAllDeviceFrm();
|
||||
while (dockPanelMain.Contents.Count > 0)
|
||||
{
|
||||
dockPanelMain.Contents[0].DockHandler.DockPanel = null;
|
||||
}
|
||||
using (FileStream stream = new FileStream(_layoutFile, FileMode.Open))
|
||||
{
|
||||
dockPanelMain.LoadFromXml(stream, dContent);
|
||||
stream.Close();
|
||||
}
|
||||
dockPanelMain.ResumeLayout(true, true);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CloseForm
|
||||
private void DeviceDisplayFrm_FormClosed(object sender,FormClosedEventArgs e)
|
||||
private void DeviceDisplayFrm_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
string id = (sender as DeviceRunFrmBase).Device.Id;
|
||||
if(showedDeviceUIDict.ContainsKey(id))
|
||||
if (showedDeviceUIDict.ContainsKey(id))
|
||||
{
|
||||
showedDeviceUIDict.Remove(id);
|
||||
}
|
||||
@ -250,6 +328,106 @@ namespace XKRS.UI.Main
|
||||
|
||||
#endregion
|
||||
|
||||
#region Layout布局
|
||||
|
||||
string _layoutFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{SettingHelper.GetSelectLayout()}.layout");//路径
|
||||
private DeserializeDockContent m_deserializeMenuFrm;
|
||||
private DeserializeDockContent m_deserializeDeviceRunFrm;
|
||||
|
||||
|
||||
private IDockContent GetMenuFromPersistString(string persistString)
|
||||
{
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
private IDockContent GetAllFormPersistString(string persistString)
|
||||
{
|
||||
if (persistString.StartsWith("MenuFrm"))
|
||||
{
|
||||
var desc = persistString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string menuCode = desc[1];
|
||||
foreach(var dock in dockPanelMain.Contents)
|
||||
{
|
||||
MenuFormBase menu = dock as MenuFormBase;
|
||||
if (menu != null && menu.Tag.ToString() == menuCode)
|
||||
{
|
||||
return dock;
|
||||
}
|
||||
}
|
||||
MenuFormBase dockFrm = MenuFormFactory.GetMenuFrm(menuCode);
|
||||
if (dockFrm == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
dockFrm.Text = desc[2];
|
||||
dockFrm.DockStateChanged += DockStateChanged;
|
||||
dockFrm.SetLoginStatus(IsLogin);
|
||||
RegisterEvent(dockFrm);
|
||||
return dockFrm;
|
||||
}
|
||||
if (persistString.StartsWith("DeviceRunFrm"))
|
||||
{
|
||||
string deviceId = persistString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[1];
|
||||
var device = _process.DeviceCollection.FirstOrDefault(u => u.Id == deviceId);
|
||||
if (null == device || null == deviceId)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (!showedDeviceUIDict.ContainsKey(deviceId))
|
||||
{
|
||||
var runCtrl = UIFactory.GetRunCtrl(device);
|
||||
DeviceRunFrmBase runFrm = new DeviceRunFrmBase(device, runCtrl);
|
||||
runFrm.Text = device.Name;
|
||||
runFrm.MdiParent = this;
|
||||
runFrm.DockPanel = dockPanelMain;
|
||||
runFrm.DockState = DockState.Document;
|
||||
runFrm.FormClosed += DeviceDisplayFrm_FormClosed;
|
||||
runFrm.DockStateChanged += DockStateChanged;
|
||||
showedDeviceUIDict[deviceId] = runFrm;
|
||||
}
|
||||
return showedDeviceUIDict[deviceId];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void DockStateChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (sender is DockContent dc)
|
||||
{
|
||||
if (dc.DockState == DockState.Float)
|
||||
{
|
||||
dc.Parent.FindForm().FormBorderStyle = FormBorderStyle.Sizable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void LoadLayoutFromXML(DeserializeDockContent dContent)
|
||||
{
|
||||
if (!File.Exists(_layoutFile))
|
||||
return;
|
||||
dockPanelMain.SuspendLayout(true);//悬挂式布局
|
||||
|
||||
CloseAllDeviceFrm();
|
||||
while (dockPanelMain.Contents.Count > 0)
|
||||
{
|
||||
dockPanelMain.Contents[0].DockHandler.DockPanel = null;
|
||||
}
|
||||
using (FileStream stream = new FileStream(_layoutFile, FileMode.Open))
|
||||
{
|
||||
dockPanelMain.LoadFromXml(stream, dContent);
|
||||
stream.Close();
|
||||
}
|
||||
dockPanelMain.ResumeLayout(true, true);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region Device Display 设备展示到底部状态栏
|
||||
readonly Dictionary<string, DeviceRunFrmBase> showedDeviceUIDict = new Dictionary<string, DeviceRunFrmBase>();
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@ -14,9 +15,34 @@ namespace XKRS.UI.Main
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
AutoStart(true);
|
||||
if(AuthorityCheck)
|
||||
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new MainFrm());
|
||||
}
|
||||
|
||||
private static void AutoStart(bool isAuto = true)
|
||||
{
|
||||
if (isAuto == true)
|
||||
{
|
||||
RegistryKey R_local = Registry.CurrentUser;//包含有关当前用户首选项的信息
|
||||
//创建一个新子项或打开一个现有子项进行写访问
|
||||
RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
|
||||
R_run.SetValue("ProjectName", Application.ExecutablePath);//获取启动应用程序的可执行文件的路径
|
||||
R_run.Close();
|
||||
R_local.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
RegistryKey R_local = Registry.CurrentUser;
|
||||
RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
|
||||
R_run.DeleteValue("ProjectName", false);
|
||||
R_run.Close();
|
||||
R_local.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user