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:
+2
-2
@@ -64,7 +64,7 @@ namespace SafeBagDE70.API
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(deviceStatus);
|
||||
var _deviceStatus = JsonConvert.DeserializeObject<DeviceStatus>(json);
|
||||
_deviceStatus.DeviceTime=DateTime.Now;
|
||||
//_deviceStatus.DeviceTime=DateTime.Now;
|
||||
|
||||
HttpClientHandler clientHandler = new HttpClientHandler();
|
||||
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
|
||||
@@ -97,7 +97,7 @@ namespace SafeBagDE70.API
|
||||
{
|
||||
if (deviceStatus == null) return;
|
||||
DeviceEvent deviceEvent = InsertEventToDB(deviceStatus);
|
||||
deviceStatus.DeviceTime = DateTime.Now;
|
||||
//deviceStatus.DeviceTime = DateTime.Now;
|
||||
deviceStatus.TransactionCode = AppData.GetTransactionCode();
|
||||
TaskSendEvent(deviceStatus).ContinueWith(t =>
|
||||
{
|
||||
|
||||
+38
-13
@@ -36,24 +36,33 @@ namespace SafeBagDE70
|
||||
public static int MaxNotes = 300;
|
||||
public static string BaseURL = "";
|
||||
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;
|
||||
static AppData()
|
||||
{
|
||||
CDMSTATE = new CDMSTATE();
|
||||
//InitDeviceStatus();
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
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();
|
||||
}
|
||||
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()
|
||||
{
|
||||
int retryCount = 0;
|
||||
@@ -101,6 +125,7 @@ namespace SafeBagDE70
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Information($"Retry InitUser: {retryCount}/{maxRetries}");
|
||||
retryCount++;
|
||||
|
||||
if (retryCount >= maxRetries)
|
||||
|
||||
+44
-3
@@ -100,8 +100,8 @@ namespace SafeBagDE70
|
||||
{
|
||||
transactionCode = AppData.GetTransactionCode();
|
||||
lblUser.Content = $"Xin chào khách hàng: {AppData.CurrentCustomerAccount.Name} (Gian hàng {AppData.CurrentCustomerAccount.CustomerId})";
|
||||
|
||||
lblTransactionCode.Content = $"Mã GD: {transactionCode}";
|
||||
AppData.IsInTransaction = true;
|
||||
}
|
||||
cCmdRsp = new CCmdRsp(serialPortDE70);
|
||||
AppData.cCmdRsp = cCmdRsp;
|
||||
@@ -114,7 +114,7 @@ namespace SafeBagDE70
|
||||
notesInSession = new NotesInSession();
|
||||
spNotesInSession.DataContext = notesInSession;
|
||||
|
||||
AppData.IsInTransaction = true;
|
||||
|
||||
ResetButtons();
|
||||
btnStart.IsEnabled = true;
|
||||
btnLogout.IsEnabled = true;
|
||||
@@ -359,7 +359,7 @@ namespace SafeBagDE70
|
||||
sensorTimer.IsEnabled = false;
|
||||
try
|
||||
{
|
||||
countSensorTimer++;
|
||||
|
||||
|
||||
if (countSensorTimer % 10 == 0)
|
||||
{
|
||||
@@ -392,7 +392,48 @@ namespace SafeBagDE70
|
||||
AppData.DeviceStatus.DeviceTime = DateTime.Now;
|
||||
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;
|
||||
GetSensorValue();
|
||||
sensorTimer.IsEnabled = true;
|
||||
|
||||
@@ -69,7 +69,6 @@
|
||||
<PackageReference Include="System.Drawing.Common" Version="8.0.3" />
|
||||
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
|
||||
<PackageReference Include="System.Management" Version="8.0.0" />
|
||||
<PackageReference Include="System.ServiceProcess.ServiceController" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user