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 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
+1 -1
View File
@@ -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;
+35 -18
View File
@@ -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();
}
+48 -42
View File
@@ -8,53 +8,59 @@
x:Name="ucWelcome"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="4*"/>
<RowDefinition Height="4*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Top Section -->
<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"/>
<TextBlock Text="Xin chào! Hãy lựa chọn hình thức đăng nhập để tiếp tục" FontSize="24" FontWeight="Bold" TextAlignment="Center"/>
</StackPanel>
<!-- Middle Section -->
<Grid Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid x:Name="gridMain" Visibility="Collapsed">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="4*"/>
<RowDefinition Height="4*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button hc:IconElement.Geometry="{StaticResource FullScreenGeometry}" Grid.Column="0" Grid.Row="0" x:Name="btnQRCodeLogin" Content="QR CODE" Width="200" Height="100" Margin="0,0,10,0" FontSize="20" FontWeight="Bold" Click="btnQRCodeLogin_Click"/>
<Button Grid.Column="2" Grid.Row="0" x:Name="btnPinCodeLogin" Content="PIN CODE" Width="200" Height="100" Margin="10,0,0,0" Click="PinCodeButton_Click" FontSize="20" FontWeight="Bold"/>
<StackPanel Grid.ColumnSpan="3" Grid.Row="1" HorizontalAlignment="Center" Visibility="Collapsed" x:Name="PinCodePanel">
<TextBox x:Name="PinCodeBox" Width="300" Height="60" FontSize="20" HorizontalContentAlignment="Center" Margin="0,10,0,0"/>
<!--<TextBlock Text="Quên mã PIN?" Foreground="Blue" TextDecorations="Underline" Cursor="Hand" Margin="0,5,0,0" MouseLeftButtonUp="ForgotPin_Click"/>-->
<Button Content="Đăng nhập" Width="200" Height="40" Margin="0,10,0,0" Click="LoginButton_Click"/>
<Label x:Name="lblPincodeError" Background="Transparent" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Red" />
</StackPanel>
<StackPanel Grid.ColumnSpan="3" Grid.Row="1" HorizontalAlignment="Center" Visibility="Collapsed" x:Name="QrCodePanel">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Đưa QR Code của bạn vào đầu đọc" FontSize="20"/>
<hc:LoadingCircle Background="Transparent" VerticalAlignment="Bottom" Width="50" Height="50" Margin="10"/>
<Label x:Name="lblQRcodeError" Background="Transparent" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Red" />
<!-- Top Section -->
<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"/>
<TextBlock Text="Xin chào! Hãy lựa chọn hình thức đăng nhập để tiếp tục" FontSize="24" FontWeight="Bold" TextAlignment="Center"/>
</StackPanel>
<!-- Middle Section -->
<Grid Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button hc:IconElement.Geometry="{StaticResource FullScreenGeometry}" Grid.Column="0" Grid.Row="0" x:Name="btnQRCodeLogin" Content="QR CODE" Width="200" Height="100" Margin="0,0,10,0" FontSize="20" FontWeight="Bold" Click="btnQRCodeLogin_Click"/>
<Button Grid.Column="2" Grid.Row="0" x:Name="btnPinCodeLogin" Content="PIN CODE" Width="200" Height="100" Margin="10,0,0,0" Click="PinCodeButton_Click" FontSize="20" FontWeight="Bold"/>
<StackPanel Grid.ColumnSpan="3" Grid.Row="1" HorizontalAlignment="Center" Visibility="Collapsed" x:Name="PinCodePanel">
<TextBox x:Name="PinCodeBox" Width="300" Height="60" FontSize="20" HorizontalContentAlignment="Center" Margin="0,10,0,0"/>
<!--<TextBlock Text="Quên mã PIN?" Foreground="Blue" TextDecorations="Underline" Cursor="Hand" Margin="0,5,0,0" MouseLeftButtonUp="ForgotPin_Click"/>-->
<Button Content="Đăng nhập" Width="200" Height="40" Margin="0,10,0,0" Click="LoginButton_Click"/>
<Label x:Name="lblPincodeError" Background="Transparent" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Red" />
</StackPanel>
<StackPanel Grid.ColumnSpan="3" Grid.Row="1" HorizontalAlignment="Center" Visibility="Collapsed" x:Name="QrCodePanel">
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="Đưa QR Code của bạn vào đầu đọc" FontSize="20"/>
<hc:LoadingCircle Background="Transparent" VerticalAlignment="Bottom" Width="50" Height="50" Margin="10"/>
<Label x:Name="lblQRcodeError" Background="Transparent" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Red" />
</StackPanel>
</Grid>
<!-- Bottom Section -->
<StackPanel Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock x:Name="txtVersion" Text="TRỢ GIÚP" Foreground="Blue" TextDecorations="Underline" Cursor="Hand" MouseLeftButtonUp="Help_Click"/>
</StackPanel>
</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>
<!-- Bottom Section -->
<StackPanel Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock x:Name="txtVersion" Text="TRỢ GIÚP" Foreground="Blue" TextDecorations="Underline" Cursor="Hand" MouseLeftButtonUp="Help_Click"/>
</StackPanel>
</Grid>
</UserControl>
+13 -1
View File
@@ -4,6 +4,7 @@ using Serilog;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
@@ -50,7 +51,18 @@ namespace SafeBagDE70
PinCodeBox.Text = "";
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)
{
+2 -2
View File
@@ -4,7 +4,7 @@
{
"Name": "File",
"Args": {
"path": "logs\\log_.txt",
"path": "D:\\logs\\log_.txt",
"rollingInterval": "Day"
}
}
@@ -15,7 +15,7 @@
"SensorPort": "COM3"
},
"CDM": {
"MaxNotes": 300
"MaxNotes": 9999
},
"Device": {
"BaseURL": "http://203.171.20.94:9103/Safebag/",