From 26ba949d1f8e613dfe7680497d91d718691d1c3f Mon Sep 17 00:00:00 2001 From: thuannd88 Date: Mon, 16 Sep 2024 19:19:00 +0700 Subject: [PATCH] wait sql init successfully --- AppData.cs | 10 +++-- DepositSMUCv2.xaml.cs | 2 +- MainWindow.xaml.cs | 53 ++++++++++++++++--------- WelcomeUC.xaml | 90 +++++++++++++++++++++++-------------------- WelcomeUC.xaml.cs | 14 ++++++- appsettings.json | 4 +- 6 files changed, 105 insertions(+), 68 deletions(-) diff --git a/AppData.cs b/AppData.cs index 6bfaaa3..b36fa23 100644 --- a/AppData.cs +++ b/AppData.cs @@ -37,12 +37,11 @@ namespace SafeBagDE70 public static string BaseURL = ""; public static int TenantId = 0; public static DeviceStatus? DeviceStatus = null; - + public static bool bInitUser = false; public static void Init() { try { - CDMSTATE = new CDMSTATE(); DeviceStatus = new DeviceStatus { @@ -55,7 +54,7 @@ namespace SafeBagDE70 Notes = "", OtherError = 0, }; - InitUsers(); + bInitUser=InitUsers(); } catch (Exception ex) { @@ -69,7 +68,7 @@ namespace SafeBagDE70 } - private static void InitUsers() + private static bool InitUsers() { int retryCount = 0; int maxRetries = 20; // Max retries before giving up @@ -97,6 +96,8 @@ namespace SafeBagDE70 } CurrentCustomerAccount = customerAccounts[0]; Log.Information("InitUsers thành công"); + bInitUser = true; + break; } catch (Exception ex) { @@ -116,6 +117,7 @@ namespace SafeBagDE70 Thread.Sleep(delay); } } + return bInitUser; } public static CDMSTATE? CDMSTATE = null; private static DateTime CutOffTime = new DateTime(1, 1, 1, 12, 0, 0); // 12:00 noon as cut-off time diff --git a/DepositSMUCv2.xaml.cs b/DepositSMUCv2.xaml.cs index 10b032f..3b5c4c9 100644 --- a/DepositSMUCv2.xaml.cs +++ b/DepositSMUCv2.xaml.cs @@ -75,7 +75,7 @@ namespace SafeBagDE70 int countTimer = 0; CCmdRsp cCmdRsp = null; bool bInitialized = false; - bool bOpenPort = false; + bool bOpenPort = true; bool bIsMaintain = false; MainWindow mainWindow = null; Thread thread = null; diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 60da5ed..54ae041 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -47,27 +47,44 @@ namespace SafeBagDE70 private void MainWindow_Loaded(object sender, RoutedEventArgs e) { - AppData.Init(); + if (_welcomeUC == null) _welcomeUC = new WelcomeUC(); - if (_collectionUC == null) _collectionUC = new CollectionUC(); - if (_informationUC == null) _informationUC = new InformationUC(); - if (_errorUC == null) _errorUC = new ErrorUC(); - if (_depositUC == null) _depositUC = new DepositSMUCv2(); - if (_timeoutUC == null) _timeoutUC = new TimeoutUC(); - if (_maintainanceUC == null) _maintainanceUC = new MaintainanceUC(); - if (_endSessionUC == null) _endSessionUC = new EndSessionUC(); - - gridMain.Children.Add(_welcomeUC); - gridMain.Children.Add(_depositUC); - gridMain.Children.Add(_collectionUC); - gridMain.Children.Add(_informationUC); - gridMain.Children.Add(_errorUC); - gridMain.Children.Add(_timeoutUC); - gridMain.Children.Add(_maintainanceUC); - gridMain.Children.Add(_endSessionUC); + Task.Run(() => + { + AppData.Init(); + Dispatcher.Invoke(() => + { + if (AppData.bInitUser) + { + _welcomeUC.ShowLogin(); + if (_collectionUC == null) _collectionUC = new CollectionUC(); + if (_informationUC == null) _informationUC = new InformationUC(); + if (_errorUC == null) _errorUC = new ErrorUC(); + if (_depositUC == null) _depositUC = new DepositSMUCv2(); + if (_timeoutUC == null) _timeoutUC = new TimeoutUC(); + if (_maintainanceUC == null) _maintainanceUC = new MaintainanceUC(); + if (_endSessionUC == null) _endSessionUC = new EndSessionUC(); - ShowWelcomeScreen(); + + + gridMain.Children.Add(_depositUC); + gridMain.Children.Add(_collectionUC); + gridMain.Children.Add(_informationUC); + gridMain.Children.Add(_errorUC); + gridMain.Children.Add(_timeoutUC); + gridMain.Children.Add(_maintainanceUC); + gridMain.Children.Add(_endSessionUC); + + ShowWelcomeScreen(); + } + else + { + _welcomeUC.ShowInfor("KHÔNG TẢI ĐƯỢC DANH SÁCH CỬA HÀNG"); + } + }); + + }); //ShowDepositScreen(); } diff --git a/WelcomeUC.xaml b/WelcomeUC.xaml index a9ffa8c..d478b40 100644 --- a/WelcomeUC.xaml +++ b/WelcomeUC.xaml @@ -8,53 +8,59 @@ x:Name="ucWelcome" mc:Ignorable="d"> - - - - - - - - - - - - - - + - - - - + + + - - - - - - -