feat: 支持外部 WPF 主界面接管
This commit is contained in:
@@ -15,6 +15,7 @@ using Lskj.Control;
|
||||
using Lskj.Control.Model;
|
||||
using Lskj.Core;
|
||||
using Lskj.Data;
|
||||
using Lskj.Main.Hosting;
|
||||
using Lskj.Model;
|
||||
using Lskj.Util;
|
||||
using Lskj.Web.Core.Util;
|
||||
@@ -55,6 +56,10 @@ namespace Lskj.Main.Model
|
||||
public static int isAwaitTime = 10;
|
||||
public static int RefreshTime = 0;
|
||||
/// <summary>
|
||||
/// 由外部启动程序提供的可选主界面。默认为 null,旧 Ls_ERP.exe 仍打开 FrmMain。
|
||||
/// </summary>
|
||||
public static IExternalMainShell ExternalMainShell { get; internal set; }
|
||||
/// <summary>
|
||||
/// 默认下载地址
|
||||
/// </summary>
|
||||
private static string filePath = string.Empty;
|
||||
@@ -190,7 +195,12 @@ namespace Lskj.Main.Model
|
||||
if (isStart)
|
||||
{
|
||||
// 直接进入主界面
|
||||
RunMainForm();
|
||||
result = RunMainForm();
|
||||
if (result == DialogResult.Retry)
|
||||
{
|
||||
StartForm();
|
||||
return;
|
||||
}
|
||||
if (ERPInfo.Instance.SubMenuCount > 1)
|
||||
{
|
||||
ReStartMain();
|
||||
@@ -686,6 +696,10 @@ namespace Lskj.Main.Model
|
||||
/// <returns>DialogResult.</returns>
|
||||
private static DialogResult RunMainForm()
|
||||
{
|
||||
IExternalMainShell externalMainShell = ExternalMainShell;
|
||||
if (externalMainShell != null)
|
||||
return externalMainShell.ShowDialog();
|
||||
|
||||
_frmMain = new FrmMain();
|
||||
return _frmMain.ShowDialog();
|
||||
}
|
||||
@@ -909,6 +923,11 @@ namespace Lskj.Main.Model
|
||||
}
|
||||
}));
|
||||
}
|
||||
else if (ExternalMainShell != null && ExternalMainShell.IsOpen)
|
||||
{
|
||||
ExternalMainShell.RequestExit($"当前用户在另一电脑登录\r\nClientIp:{clientip}\r\nMacAdress:{loginMacAdress}\r\n当前系统即将关闭");
|
||||
isClose = true;
|
||||
}
|
||||
else if (_frmMain != null && _frmMain.Visible == true)
|
||||
{
|
||||
_frmMain.Invoke(new Action(() =>
|
||||
@@ -953,7 +972,7 @@ namespace Lskj.Main.Model
|
||||
}
|
||||
//记录登出日志
|
||||
LogUtil.WriteDebug("", "退出软件", "软件退出", "系统登录");
|
||||
Process[] p = Process.GetProcessesByName("Ls_ERP");
|
||||
Process[] p = GetApplicationProcesses();
|
||||
foreach (Process item in p)
|
||||
{
|
||||
try
|
||||
@@ -1107,6 +1126,12 @@ namespace Lskj.Main.Model
|
||||
/// </summary>
|
||||
public static void ReLogin()
|
||||
{
|
||||
IExternalMainShell externalMainShell = ExternalMainShell;
|
||||
if (externalMainShell != null && externalMainShell.IsOpen)
|
||||
{
|
||||
externalMainShell.RequestRelogin();
|
||||
return;
|
||||
}
|
||||
if (_frmMain != null)
|
||||
{
|
||||
if (ERPInfo.Instance.WatermarkForm != null)
|
||||
@@ -1121,5 +1146,16 @@ namespace Lskj.Main.Model
|
||||
StartForm();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回当前启动路线需要退出的主进程。
|
||||
/// 旧入口保持原有 Ls_ERP 进程名语义,外部宿主只退出当前 WPF 进程。
|
||||
/// </summary>
|
||||
internal static Process[] GetApplicationProcesses()
|
||||
{
|
||||
return ExternalMainShell == null
|
||||
? Process.GetProcessesByName("Ls_ERP")
|
||||
: new[] { Process.GetCurrentProcess() };
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user