feat: 完善 WPF 接管后的子系统选择

This commit is contained in:
2026-07-22 13:41:53 +08:00
parent a11ef73f1c
commit e4b40a32d7
2 changed files with 61 additions and 3 deletions
+3 -1
View File
@@ -18,7 +18,9 @@ Program.Main
## 外部宿主路线
`.NET Framework 4.8` 的独立启动程序通过 `LegacyApplicationHost.Run` 注入 `IExternalMainShell`。旧程序仍负责 CEF、全局异常、配置、数据库登录和子系统选择,只`RunMainForm` 位置回调外部主界面。
`.NET Framework 4.8` 的独立启动程序通过 `LegacyApplicationHost.Run` 注入 `IExternalMainShell`。旧程序仍负责 CEF、全局异常、配置、数据库登录;登录成功后自动保留当前有效子系统,或选择第一个有权限且启用的子系统,不再显示 `FrmSubSystem`,随后`RunMainForm` 位置回调外部主界面。
该跳过逻辑只在 `Manager.ExternalMainShell != null` 时生效。直接运行 `Ls_ERP.exe` 时仍保留原子系统选择页和原有循环。
`IExternalMainShell` 当前承担:
+58 -2
View File
@@ -185,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();
@@ -201,7 +207,13 @@ namespace Lskj.Main.Model
StartForm();
return;
}
if (ERPInfo.Instance.SubMenuCount > 1)
if (ExternalMainShell != null)
{
// 外部主界面关闭即结束本次 WPF 入口,不返回旧子系统选择页。
ExitSystem();
return;
}
else if (ERPInfo.Instance.SubMenuCount > 1)
{
ReStartMain();
}
@@ -684,6 +696,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>