feat: expose legacy login runtime for WPF host

This commit is contained in:
2026-07-28 14:19:28 +08:00
parent 6be6607a40
commit fa48419bd8
4 changed files with 562 additions and 5 deletions
+100 -5
View File
@@ -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;
@@ -180,7 +185,13 @@ namespace Lskj.Main.Model
bool isOpenBs = false;
DialogResult result;
if (ERPInfo.Instance.SubMenuCount > 1 && !skipMenu)
if (ExternalMainShell != null)
{
// WPF 主框架已经提供顶部子系统导航,不再打开旧 FrmSubSystem。
// 优先保留当前仍有权限的子系统,否则选择第一个可用子系统。
isStart = SelectExternalMainShellSubSystem();
}
else if (ERPInfo.Instance.SubMenuCount > 1 && !skipMenu)
{
// 进入子系统界面
result = RunSubSystemForm();
@@ -190,8 +201,19 @@ namespace Lskj.Main.Model
if (isStart)
{
// 直接进入主界面
RunMainForm();
if (ERPInfo.Instance.SubMenuCount > 1)
result = RunMainForm();
if (result == DialogResult.Retry)
{
StartForm();
return;
}
if (ExternalMainShell != null)
{
// 外部主界面关闭即结束本次 WPF 入口,不返回旧子系统选择页。
ExitSystem();
return;
}
else if (ERPInfo.Instance.SubMenuCount > 1)
{
ReStartMain();
}
@@ -653,6 +675,9 @@ namespace Lskj.Main.Model
/// <returns>DialogResult.</returns>
private static DialogResult RunLoginForm()
{
if (ExternalMainShell != null)
return ExternalMainShell.ShowLoginDialog(new LegacyLoginRuntime());
FrmLogin frmLogin = new FrmLogin();
return frmLogin.ShowDialog();
}
@@ -674,6 +699,50 @@ namespace Lskj.Main.Model
BsUrl = _frmSubSystem.BsUrl;
return dialogResult;
}
/// <summary>
/// 为外部 WPF 主框架选择登录后的初始子系统。
/// 旧 WinForms 入口仍由 FrmSubSystem 完成人工选择。
/// </summary>
private static bool SelectExternalMainShellSubSystem()
{
string where = string.IsNullOrEmpty(ERPInfo.Instance.SeriesId)
? string.Empty
: string.Format("and SeriesId={0}", ERPInfo.Instance.SeriesId);
DataTable subSystems = MainImpl.GetSubSystems(where);
if (subSystems == null || subSystems.Rows.Count == 0)
{
MessageUtil.Show(ResourceKeys.SubSystemUnEnabled);
return false;
}
DataRow selectedRow = subSystems.AsEnumerable().FirstOrDefault(row =>
IsEnabledSubSystem(row) &&
string.Equals(
row["SubSysId"] + string.Empty,
ERPInfo.Instance.SubSysId,
StringComparison.OrdinalIgnoreCase));
if (selectedRow == null)
selectedRow = subSystems.AsEnumerable().FirstOrDefault(IsEnabledSubSystem);
if (selectedRow == null)
{
MessageUtil.Show(ResourceKeys.SubSystemUnEnabled);
return false;
}
ERPInfo.Instance.SubMenuCount = subSystems.AsEnumerable().Count(IsEnabledSubSystem);
ERPInfo.Instance.SubSysId = selectedRow["SubSysId"] + string.Empty;
ERPInfo.Instance.SubSysName = selectedRow["SubSysName"] + string.Empty;
return true;
}
private static bool IsEnabledSubSystem(DataRow row)
{
return row != null &&
row.Table.Columns.Contains("UseEd") &&
row["UseEd"] != DBNull.Value &&
Convert.ToBoolean(row["UseEd"]);
}
/// <summary>
/// <para>说明:打开主程序</para>
/// <para>创建人:龚宇超</para>
@@ -686,6 +755,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 +982,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 +1031,7 @@ namespace Lskj.Main.Model
}
//记录登出日志
LogUtil.WriteDebug("", "退出软件", "软件退出", "系统登录");
Process[] p = Process.GetProcessesByName("Ls_ERP");
Process[] p = GetApplicationProcesses();
foreach (Process item in p)
{
try
@@ -1107,6 +1185,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 +1205,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() };
}
}
}
}