refactor(session): expose WPF-compatible legacy state
This commit is contained in:
@@ -92,16 +92,58 @@ namespace Lskj.Main.Hosting
|
||||
|
||||
try
|
||||
{
|
||||
Program.ShutdownMainProcess();
|
||||
Manager.EndExternalSessionServices();
|
||||
Manager.ExitSystem();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_mainProcessInitialized = false;
|
||||
_mainProcessShutdown = true;
|
||||
Manager.ExternalMainShell = null;
|
||||
try
|
||||
{
|
||||
Program.ShutdownMainProcess();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_mainProcessInitialized = false;
|
||||
_mainProcessShutdown = true;
|
||||
Manager.ExternalMainShell = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static object CreateLoginRuntime()
|
||||
{
|
||||
return new LegacyLoginRuntime();
|
||||
}
|
||||
|
||||
public static string PrepareAuthenticatedSession()
|
||||
{
|
||||
if (!ERPInfo.Instance.LoginResult)
|
||||
return ResourceKeys.LoginFault;
|
||||
|
||||
DataTable enabled = MainImpl.EnableSubSystem();
|
||||
ERPInfo.Instance.SubMenuCount = enabled == null
|
||||
? 0
|
||||
: enabled.Rows.Count;
|
||||
if (!Manager.TrySelectExternalMainShellSubSystem())
|
||||
return ResourceKeys.SubSystemUnEnabled;
|
||||
|
||||
LegacyLoginRuntime.RefreshDelphiParameters();
|
||||
Manager.BeginExternalSessionServices();
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static void CompleteAuthenticatedSession()
|
||||
{
|
||||
Manager.EndExternalSessionServices();
|
||||
}
|
||||
|
||||
public static void ActivateSubSystem(string id, string caption)
|
||||
{
|
||||
ERPInfo.Instance.SubSysId = id ?? string.Empty;
|
||||
ERPInfo.Instance.SubSysName = caption ?? string.Empty;
|
||||
LegacyLoginRuntime.RefreshDelphiParameters();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -111,6 +153,7 @@ namespace Lskj.Main.Hosting
|
||||
public sealed partial class LegacyLoginRuntime
|
||||
{
|
||||
private DataTable _ledgerTable;
|
||||
private bool _connectionInitialized;
|
||||
|
||||
public LegacyLoginRuntime()
|
||||
{
|
||||
@@ -175,11 +218,69 @@ namespace Lskj.Main.Hosting
|
||||
|
||||
public DataTable LoadLedgers()
|
||||
{
|
||||
EnsureInitialConnection();
|
||||
_ledgerTable = MainImpl.GetLedgerList() ?? new DataTable("Ledgers");
|
||||
SelectedLedgerName = ResolveSelectedLedgerName(_ledgerTable);
|
||||
return _ledgerTable;
|
||||
}
|
||||
|
||||
private void EnsureInitialConnection()
|
||||
{
|
||||
if (_connectionInitialized)
|
||||
return;
|
||||
|
||||
if (string.Equals(
|
||||
IniHelper.Read(SystemResourcesIniName, ConnectionModeKey),
|
||||
"1",
|
||||
StringComparison.Ordinal))
|
||||
{
|
||||
int port;
|
||||
string host = IniHelper.Read(
|
||||
SystemResourcesIniName,
|
||||
DirectLastHostKey);
|
||||
string name = IniHelper.Read(
|
||||
SystemResourcesIniName,
|
||||
DirectLastNameKey);
|
||||
if (!int.TryParse(
|
||||
IniHelper.Read(
|
||||
SystemResourcesIniName,
|
||||
DirectLastPortKey),
|
||||
out port))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"保存的直连端口无效,请重新设置连接。");
|
||||
}
|
||||
|
||||
string error = ApplyDirectConnection(host, port, name);
|
||||
if (!string.IsNullOrWhiteSpace(error))
|
||||
throw new InvalidOperationException(error);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!DBConfig.Instance.CreateConnection(
|
||||
DBConfig.Instance.Connection))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
ResourceKeys.UnConnectServer);
|
||||
}
|
||||
if (!string.Equals(
|
||||
DBConfig.Instance.ServerType,
|
||||
"达梦数据库",
|
||||
StringComparison.Ordinal) &&
|
||||
DelphiHelper.Delphi_Init(new StringBuilder(
|
||||
DBConfig.Instance.GetDelphiConnection(
|
||||
DBConfig.Instance.dephiConnection))) == 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
ResourceKeys.UnConnectServer + "[By Delphi]");
|
||||
}
|
||||
SystemInfo.RefreshSystemParam();
|
||||
}
|
||||
|
||||
BaseResources.Localization(LocalizationType.CHS);
|
||||
_connectionInitialized = true;
|
||||
}
|
||||
|
||||
public DataTable LoadUsers()
|
||||
{
|
||||
DataTable users = SystemInfo.Instance.DisplayUserCode
|
||||
@@ -220,6 +321,7 @@ namespace Lskj.Main.Hosting
|
||||
string oldDataBook = DBConfig.Instance.DataBook;
|
||||
string oldSelectedLedgerName = SelectedLedgerName;
|
||||
string oldAccountBook = ERPInfo.Instance.AccountBook;
|
||||
bool oldConnectionInitialized = _connectionInitialized;
|
||||
try
|
||||
{
|
||||
DBConfig.Instance.ServerName = serverName;
|
||||
@@ -238,10 +340,12 @@ namespace Lskj.Main.Hosting
|
||||
}
|
||||
|
||||
SystemInfo.RefreshSystemParam();
|
||||
BaseResources.Localization(LocalizationType.CHS);
|
||||
DataTable users = LoadUsers();
|
||||
|
||||
SelectedLedgerName = dataBook;
|
||||
ERPInfo.Instance.AccountBook = dataBook;
|
||||
_connectionInitialized = true;
|
||||
return users;
|
||||
}
|
||||
catch (Exception switchException)
|
||||
@@ -251,6 +355,7 @@ namespace Lskj.Main.Hosting
|
||||
DBConfig.Instance.DataBook = oldDataBook;
|
||||
SelectedLedgerName = oldSelectedLedgerName;
|
||||
ERPInfo.Instance.AccountBook = oldAccountBook;
|
||||
_connectionInitialized = oldConnectionInitialized;
|
||||
try
|
||||
{
|
||||
DBConfig.Instance.CreateConnection(DBConfig.Instance.Connection);
|
||||
@@ -488,11 +593,11 @@ namespace Lskj.Main.Hosting
|
||||
|
||||
ERPInfo.Instance.LanguageName = "中文";
|
||||
LanguageTranslation.GetLanguageComparisonTable();
|
||||
TrySetDelphiParameters();
|
||||
RefreshDelphiParameters();
|
||||
PubUtil.ClearFilesInDirectory(PubUtil.ImageDownloadPath);
|
||||
}
|
||||
|
||||
private static void TrySetDelphiParameters()
|
||||
internal static void RefreshDelphiParameters()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user