AppData --> lấy trạng thái gán thời gian

APIModels--> Bỏ gán thời gian
DepositSMUCv2--> Báo đang trong giao dịch chỉ khi đăng nhập thành công
This commit is contained in:
Nguyen Dinh Thuan
2024-09-16 23:33:30 +07:00
parent 2e94ba03ac
commit 33214ad7fa
4 changed files with 85 additions and 20 deletions
+2 -2
View File
@@ -64,7 +64,7 @@ namespace SafeBagDE70.API
{ {
var json = JsonConvert.SerializeObject(deviceStatus); var json = JsonConvert.SerializeObject(deviceStatus);
var _deviceStatus = JsonConvert.DeserializeObject<DeviceStatus>(json); var _deviceStatus = JsonConvert.DeserializeObject<DeviceStatus>(json);
_deviceStatus.DeviceTime=DateTime.Now; //_deviceStatus.DeviceTime=DateTime.Now;
HttpClientHandler clientHandler = new HttpClientHandler(); HttpClientHandler clientHandler = new HttpClientHandler();
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; }; clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
@@ -97,7 +97,7 @@ namespace SafeBagDE70.API
{ {
if (deviceStatus == null) return; if (deviceStatus == null) return;
DeviceEvent deviceEvent = InsertEventToDB(deviceStatus); DeviceEvent deviceEvent = InsertEventToDB(deviceStatus);
deviceStatus.DeviceTime = DateTime.Now; //deviceStatus.DeviceTime = DateTime.Now;
deviceStatus.TransactionCode = AppData.GetTransactionCode(); deviceStatus.TransactionCode = AppData.GetTransactionCode();
TaskSendEvent(deviceStatus).ContinueWith(t => TaskSendEvent(deviceStatus).ContinueWith(t =>
{ {
+38 -13
View File
@@ -36,24 +36,33 @@ namespace SafeBagDE70
public static int MaxNotes = 300; public static int MaxNotes = 300;
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 DeviceStatus? DeviceStatus
{
set { _DeviceStatus = value; }
get
{
if (_DeviceStatus == null)
{
InitDeviceStatus();
}
else
{
_DeviceStatus.DeviceTime = DateTime.Now;
}
return _DeviceStatus;
}
}
public static bool bInitUser = false; public static bool bInitUser = false;
static AppData()
{
CDMSTATE = new CDMSTATE();
//InitDeviceStatus();
}
public static void Init() public static void Init()
{ {
try try
{ {
CDMSTATE = new CDMSTATE();
DeviceStatus = new DeviceStatus
{
Device = Environment.MachineName,
TenantId = AppData.TenantId,
Status = 0,
CDMStatus = 0,
PrinterStatus = 0,
SensorStatus = 0,
Notes = "",
OtherError = 0,
};
bInitUser = InitUsers(); bInitUser = InitUsers();
} }
catch (Exception ex) catch (Exception ex)
@@ -68,6 +77,21 @@ namespace SafeBagDE70
} }
public static void InitDeviceStatus()
{
DeviceStatus = new DeviceStatus
{
Device = Environment.MachineName,
TenantId = AppData.TenantId,
Status = 0,
CDMStatus = 0,
PrinterStatus = 0,
SensorStatus = 0,
Notes = "",
OtherError = 0,
};
}
public static bool InitUsers() public static bool InitUsers()
{ {
int retryCount = 0; int retryCount = 0;
@@ -101,6 +125,7 @@ namespace SafeBagDE70
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Information($"Retry InitUser: {retryCount}/{maxRetries}");
retryCount++; retryCount++;
if (retryCount >= maxRetries) if (retryCount >= maxRetries)
+44 -3
View File
@@ -100,8 +100,8 @@ namespace SafeBagDE70
{ {
transactionCode = AppData.GetTransactionCode(); transactionCode = AppData.GetTransactionCode();
lblUser.Content = $"Xin chào khách hàng: {AppData.CurrentCustomerAccount.Name} (Gian hàng {AppData.CurrentCustomerAccount.CustomerId})"; lblUser.Content = $"Xin chào khách hàng: {AppData.CurrentCustomerAccount.Name} (Gian hàng {AppData.CurrentCustomerAccount.CustomerId})";
lblTransactionCode.Content = $"Mã GD: {transactionCode}"; lblTransactionCode.Content = $"Mã GD: {transactionCode}";
AppData.IsInTransaction = true;
} }
cCmdRsp = new CCmdRsp(serialPortDE70); cCmdRsp = new CCmdRsp(serialPortDE70);
AppData.cCmdRsp = cCmdRsp; AppData.cCmdRsp = cCmdRsp;
@@ -114,7 +114,7 @@ namespace SafeBagDE70
notesInSession = new NotesInSession(); notesInSession = new NotesInSession();
spNotesInSession.DataContext = notesInSession; spNotesInSession.DataContext = notesInSession;
AppData.IsInTransaction = true;
ResetButtons(); ResetButtons();
btnStart.IsEnabled = true; btnStart.IsEnabled = true;
btnLogout.IsEnabled = true; btnLogout.IsEnabled = true;
@@ -359,7 +359,7 @@ namespace SafeBagDE70
sensorTimer.IsEnabled = false; sensorTimer.IsEnabled = false;
try try
{ {
countSensorTimer++;
if (countSensorTimer % 10 == 0) if (countSensorTimer % 10 == 0)
{ {
@@ -392,7 +392,48 @@ namespace SafeBagDE70
AppData.DeviceStatus.DeviceTime = DateTime.Now; AppData.DeviceStatus.DeviceTime = DateTime.Now;
APIModels.SendHealthCheck(AppData.DeviceStatus); APIModels.SendHealthCheck(AppData.DeviceStatus);
} }
if (countSensorTimer % 1800 == 0)
{
if (!AppData.IsInTransaction)
{
Task.Run(async () =>
{
try
{
using (var context = new CDMDbContext())
{
var startTime = DateTime.Now.Date.AddDays(-2).Date;
var unsentHist = context.Histories
.Where(x => x.DepositTime >= startTime)
.Where(x => ((x.IsSent == null || x.IsSent == false)))
.ToList();
foreach(var item in unsentHist)
{
var data2Send = JsonConvert.DeserializeObject<CountingData2Send>(item.Data);
var bResult = await APIModels.SendCountingData(data2Send);
if (bResult)
{
item.IsSent = true;
context.Update(item);
context.SaveChanges();
Log.Information("Resend: " + data2Send + " successfully");
}
else
{
Log.Error("Resend: " + data2Send + " failed");
}
}
}
}
catch (Exception ex)
{
Log.Fatal(ex,"Resend failed");
}
});
}
}
countSensorTimer++;
sensorTimer.IsEnabled = false; sensorTimer.IsEnabled = false;
GetSensorValue(); GetSensorValue();
sensorTimer.IsEnabled = true; sensorTimer.IsEnabled = true;
-1
View File
@@ -69,7 +69,6 @@
<PackageReference Include="System.Drawing.Common" Version="8.0.3" /> <PackageReference Include="System.Drawing.Common" Version="8.0.3" />
<PackageReference Include="System.IO.Ports" Version="8.0.0" /> <PackageReference Include="System.IO.Ports" Version="8.0.0" />
<PackageReference Include="System.Management" Version="8.0.0" /> <PackageReference Include="System.Management" Version="8.0.0" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="8.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>