wait sql init successfully

This commit is contained in:
thuannd88
2024-09-16 19:19:00 +07:00
parent 87896e8def
commit 26ba949d1f
6 changed files with 105 additions and 68 deletions
+6 -4
View File
@@ -37,12 +37,11 @@ namespace SafeBagDE70
public static string BaseURL = ""; public static string BaseURL = "";
public static int TenantId = 0; public static int TenantId = 0;
public static DeviceStatus? DeviceStatus = null; public static DeviceStatus? DeviceStatus = null;
public static bool bInitUser = false;
public static void Init() public static void Init()
{ {
try try
{ {
CDMSTATE = new CDMSTATE(); CDMSTATE = new CDMSTATE();
DeviceStatus = new DeviceStatus DeviceStatus = new DeviceStatus
{ {
@@ -55,7 +54,7 @@ namespace SafeBagDE70
Notes = "", Notes = "",
OtherError = 0, OtherError = 0,
}; };
InitUsers(); bInitUser=InitUsers();
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -69,7 +68,7 @@ namespace SafeBagDE70
} }
private static void InitUsers() private static bool InitUsers()
{ {
int retryCount = 0; int retryCount = 0;
int maxRetries = 20; // Max retries before giving up int maxRetries = 20; // Max retries before giving up
@@ -97,6 +96,8 @@ namespace SafeBagDE70
} }
CurrentCustomerAccount = customerAccounts[0]; CurrentCustomerAccount = customerAccounts[0];
Log.Information("InitUsers thành công"); Log.Information("InitUsers thành công");
bInitUser = true;
break;
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -116,6 +117,7 @@ namespace SafeBagDE70
Thread.Sleep(delay); Thread.Sleep(delay);
} }
} }
return bInitUser;
} }
public static CDMSTATE? CDMSTATE = null; public static CDMSTATE? CDMSTATE = null;
private static DateTime CutOffTime = new DateTime(1, 1, 1, 12, 0, 0); // 12:00 noon as cut-off time private static DateTime CutOffTime = new DateTime(1, 1, 1, 12, 0, 0); // 12:00 noon as cut-off time
+1 -1
View File
@@ -75,7 +75,7 @@ namespace SafeBagDE70
int countTimer = 0; int countTimer = 0;
CCmdRsp cCmdRsp = null; CCmdRsp cCmdRsp = null;
bool bInitialized = false; bool bInitialized = false;
bool bOpenPort = false; bool bOpenPort = true;
bool bIsMaintain = false; bool bIsMaintain = false;
MainWindow mainWindow = null; MainWindow mainWindow = null;
Thread thread = null; Thread thread = null;
+19 -2
View File
@@ -47,8 +47,17 @@ namespace SafeBagDE70
private void MainWindow_Loaded(object sender, RoutedEventArgs e) private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{ {
AppData.Init();
if (_welcomeUC == null) _welcomeUC = new WelcomeUC(); if (_welcomeUC == null) _welcomeUC = new WelcomeUC();
gridMain.Children.Add(_welcomeUC);
Task.Run(() =>
{
AppData.Init();
Dispatcher.Invoke(() =>
{
if (AppData.bInitUser)
{
_welcomeUC.ShowLogin();
if (_collectionUC == null) _collectionUC = new CollectionUC(); if (_collectionUC == null) _collectionUC = new CollectionUC();
if (_informationUC == null) _informationUC = new InformationUC(); if (_informationUC == null) _informationUC = new InformationUC();
if (_errorUC == null) _errorUC = new ErrorUC(); if (_errorUC == null) _errorUC = new ErrorUC();
@@ -58,7 +67,7 @@ namespace SafeBagDE70
if (_endSessionUC == null) _endSessionUC = new EndSessionUC(); if (_endSessionUC == null) _endSessionUC = new EndSessionUC();
gridMain.Children.Add(_welcomeUC);
gridMain.Children.Add(_depositUC); gridMain.Children.Add(_depositUC);
gridMain.Children.Add(_collectionUC); gridMain.Children.Add(_collectionUC);
gridMain.Children.Add(_informationUC); gridMain.Children.Add(_informationUC);
@@ -68,6 +77,14 @@ namespace SafeBagDE70
gridMain.Children.Add(_endSessionUC); gridMain.Children.Add(_endSessionUC);
ShowWelcomeScreen(); ShowWelcomeScreen();
}
else
{
_welcomeUC.ShowInfor("KHÔNG TẢI ĐƯỢC DANH SÁCH CỬA HÀNG");
}
});
});
//ShowDepositScreen(); //ShowDepositScreen();
} }
+7 -1
View File
@@ -8,12 +8,12 @@
x:Name="ucWelcome" x:Name="ucWelcome"
mc:Ignorable="d"> mc:Ignorable="d">
<Grid> <Grid>
<Grid x:Name="gridMain" Visibility="Collapsed">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="4*"/> <RowDefinition Height="4*"/>
<RowDefinition Height="4*"/> <RowDefinition Height="4*"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!-- Top Section --> <!-- Top Section -->
<StackPanel Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0"> <StackPanel Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0">
<Image Source="icon/logo.ico" Width="200" Height="200" Margin="0,10,0,10" Stretch="UniformToFill"/> <Image Source="icon/logo.ico" Width="200" Height="200" Margin="0,10,0,10" Stretch="UniformToFill"/>
@@ -56,5 +56,11 @@
<TextBlock x:Name="txtVersion" Text="TRỢ GIÚP" Foreground="Blue" TextDecorations="Underline" Cursor="Hand" MouseLeftButtonUp="Help_Click"/> <TextBlock x:Name="txtVersion" Text="TRỢ GIÚP" Foreground="Blue" TextDecorations="Underline" Cursor="Hand" MouseLeftButtonUp="Help_Click"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
<Grid x:Name="gridInfor">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock x:Name="txtInfor" Text="ĐANG KHỞI TẠO, VUI LÒNG ĐỢI" Foreground="Blue" FontSize="24" />
</StackPanel>
</Grid>
</Grid>
</UserControl> </UserControl>
+13 -1
View File
@@ -4,6 +4,7 @@ using Serilog;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@@ -50,7 +51,18 @@ namespace SafeBagDE70
PinCodeBox.Text = ""; PinCodeBox.Text = "";
QrCodePanel.Visibility = Visibility.Collapsed; QrCodePanel.Visibility = Visibility.Collapsed;
} }
public void ShowLogin()
{
gridInfor.Visibility = Visibility.Collapsed;
gridMain.Visibility = Visibility.Visible;
}
public void ShowInfor(string strMessage)
{
gridInfor.Visibility = Visibility.Visible;
gridMain.Visibility = Visibility.Collapsed;
txtInfor.Text = strMessage;
txtInfor.Foreground = new SolidColorBrush(Colors.DarkRed);
}
private void LoginButton_Click(object sender, RoutedEventArgs e) private void LoginButton_Click(object sender, RoutedEventArgs e)
{ {
+2 -2
View File
@@ -4,7 +4,7 @@
{ {
"Name": "File", "Name": "File",
"Args": { "Args": {
"path": "logs\\log_.txt", "path": "D:\\logs\\log_.txt",
"rollingInterval": "Day" "rollingInterval": "Day"
} }
} }
@@ -15,7 +15,7 @@
"SensorPort": "COM3" "SensorPort": "COM3"
}, },
"CDM": { "CDM": {
"MaxNotes": 300 "MaxNotes": 9999
}, },
"Device": { "Device": {
"BaseURL": "http://203.171.20.94:9103/Safebag/", "BaseURL": "http://203.171.20.94:9103/Safebag/",