- Chỉnh update users
- Đưa phần gọi lệnh đếm vào Task
This commit is contained in:
@@ -50,29 +50,9 @@ namespace SafeBagDE70.Admin
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var amCustomers = await APIModels.GetAeonMallCustomers(AppData.TenantId);
|
int nUpdatedCustomers=await AppData.UpdateCustomers();
|
||||||
using (var context = new CDMDbContext())
|
|
||||||
{
|
|
||||||
var customers = context.Customers;
|
|
||||||
context.Customers.RemoveRange(customers);
|
|
||||||
context.SaveChanges();
|
|
||||||
foreach (var amCustomer in amCustomers)
|
|
||||||
{
|
|
||||||
var customer = new Customer
|
|
||||||
{
|
|
||||||
AccountNumber = amCustomer.TenantCode,
|
|
||||||
AccountHolder = amCustomer.TenantName,
|
|
||||||
TenantName = amCustomer.TenantShortName,
|
|
||||||
TenantCode = amCustomer.TenantCode,
|
|
||||||
PinCode = amCustomer.TenantCode,
|
|
||||||
UpdatedTime = DateTime.Now,
|
|
||||||
};
|
|
||||||
customers.Add(customer);
|
|
||||||
}
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
lblStatus.Foreground = new SolidColorBrush(Colors.Green);
|
lblStatus.Foreground = new SolidColorBrush(Colors.Green);
|
||||||
lblStatus.Content = "Updated customers: " + amCustomers.Count;
|
lblStatus.Content = "Updated customers: " + nUpdatedCustomers;
|
||||||
}
|
}
|
||||||
AppData.InitUsers();
|
AppData.InitUsers();
|
||||||
}
|
}
|
||||||
|
|||||||
+45
-1
@@ -347,9 +347,20 @@ namespace SafeBagDE70
|
|||||||
bResult = ResetCDMCounter();
|
bResult = ResetCDMCounter();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 3:
|
||||||
|
if(IsInternetOk && !IsInTransaction)
|
||||||
|
{
|
||||||
|
Log.Information("Request update Customers");
|
||||||
|
int nCount = await UpdateCustomers();
|
||||||
|
Log.Information($"Updated {nCount} users");
|
||||||
|
InitUsers();
|
||||||
|
if (nCount > 0) bResult = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
await APIModels.UpdateDeviceCommand(command.Id, bResult?1:-1);
|
if(bResult)
|
||||||
|
await APIModels.UpdateDeviceCommand(command.Id, bResult?1:0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -369,6 +380,39 @@ namespace SafeBagDE70
|
|||||||
Log.Error("GetandExecuteCommands error: "+str);
|
Log.Error("GetandExecuteCommands error: "+str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static async Task<int> UpdateCustomers()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var amCustomers = await APIModels.GetAeonMallCustomers(AppData.TenantId);
|
||||||
|
using (var context = new CDMDbContext())
|
||||||
|
{
|
||||||
|
var customers = context.Customers;
|
||||||
|
context.Customers.RemoveRange(customers);
|
||||||
|
context.SaveChanges();
|
||||||
|
foreach (var amCustomer in amCustomers)
|
||||||
|
{
|
||||||
|
var customer = new Customer
|
||||||
|
{
|
||||||
|
AccountNumber = amCustomer.TenantCode,
|
||||||
|
AccountHolder = amCustomer.TenantName,
|
||||||
|
TenantName = amCustomer.TenantShortName,
|
||||||
|
TenantCode = amCustomer.TenantCode,
|
||||||
|
PinCode = amCustomer.TenantCode,
|
||||||
|
UpdatedTime = DateTime.Now,
|
||||||
|
};
|
||||||
|
customers.Add(customer);
|
||||||
|
}
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
return amCustomers.Count();
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
public static bool ResetCDMCounter()
|
public static bool ResetCDMCounter()
|
||||||
{
|
{
|
||||||
bool bResetOk = false;
|
bool bResetOk = false;
|
||||||
|
|||||||
+25
-15
@@ -659,7 +659,19 @@ namespace SafeBagDE70
|
|||||||
//TempNote[1] ++;
|
//TempNote[1] ++;
|
||||||
noteVal = cCmdRsp.recv_dat.dat[17];
|
noteVal = cCmdRsp.recv_dat.dat[17];
|
||||||
Log.Information($"Serial Value: {noteVal}");
|
Log.Information($"Serial Value: {noteVal}");
|
||||||
UpdateCountSession(countSession, noteVal);
|
switch (noteVal)
|
||||||
|
{
|
||||||
|
case 0x00: countSession.QuantityDenomi[0]++; break;
|
||||||
|
case 0x01: countSession.QuantityDenomi[1]++; break;
|
||||||
|
case 0x02: countSession.QuantityDenomi[2]++; break;
|
||||||
|
case 0x03: countSession.QuantityDenomi[3]++; break;
|
||||||
|
case 0x04: countSession.QuantityDenomi[4]++; break;
|
||||||
|
case 0x05: countSession.QuantityDenomi[5]++; break;
|
||||||
|
case 0x06: countSession.QuantityDenomi[6]++; break;
|
||||||
|
case 0x07: countSession.QuantityDenomi[7]++; break;
|
||||||
|
case 0x08: countSession.QuantityDenomi[8]++; break;
|
||||||
|
case 0x09: countSession.QuantityDenomi[9]++; break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 0x03: countSession.TempNotes[2]++; break;
|
case 0x03: countSession.TempNotes[2]++; break;
|
||||||
case 0x0b: countSession.TempNotes[3]++; break;
|
case 0x0b: countSession.TempNotes[3]++; break;
|
||||||
@@ -749,6 +761,8 @@ namespace SafeBagDE70
|
|||||||
|
|
||||||
string currentMethod = MethodBase.GetCurrentMethod().Name;
|
string currentMethod = MethodBase.GetCurrentMethod().Name;
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
taskCounting = Task.Run(() =>
|
||||||
{
|
{
|
||||||
if (bOpenPort)
|
if (bOpenPort)
|
||||||
{
|
{
|
||||||
@@ -756,21 +770,19 @@ namespace SafeBagDE70
|
|||||||
serialPortDE70.DiscardOutBuffer();
|
serialPortDE70.DiscardOutBuffer();
|
||||||
|
|
||||||
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_CNTSTART);
|
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_CNTSTART);
|
||||||
//if (cCmdRsp.recv_dat != null && cCmdRsp.recv_dat.dat[2] != 43) {
|
if (cCmdRsp.recv_dat != null && cCmdRsp.recv_dat.dat[2] != 43)
|
||||||
//}
|
{
|
||||||
|
|
||||||
//do
|
|
||||||
//{
|
|
||||||
// serialPortDE70.DiscardInBuffer();
|
|
||||||
// serialPortDE70.DiscardOutBuffer();
|
|
||||||
// cCmdRsp.SendXXCmd((byte)Command.CMD_SENSE);
|
|
||||||
//}
|
|
||||||
//while (cCmdRsp.recv_dat != null && cCmdRsp.recv_dat.dat[1] == 0x09); //SR2 = 0x09 : Counting Status
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do
|
||||||
taskCounting = Task.Run(() =>
|
|
||||||
{
|
{
|
||||||
|
serialPortDE70.DiscardInBuffer();
|
||||||
|
serialPortDE70.DiscardOutBuffer();
|
||||||
|
cCmdRsp.SendXXCmd((byte)Command.CMD_SENSE);
|
||||||
|
}
|
||||||
|
while (cCmdRsp.recv_dat != null && cCmdRsp.recv_dat.dat[1] == 0x09); //SR2 = 0x09 : Counting Status
|
||||||
|
}
|
||||||
|
|
||||||
var str = "BEFORE COUNT";
|
var str = "BEFORE COUNT";
|
||||||
str+="\r\nSTORED: "+ GetQuantityFromSessions(sessions,true);
|
str+="\r\nSTORED: "+ GetQuantityFromSessions(sessions,true);
|
||||||
str += "\r\nSTACKER: " + GetQuantityFromSessions(sessions, false);
|
str += "\r\nSTACKER: " + GetQuantityFromSessions(sessions, false);
|
||||||
@@ -790,8 +802,6 @@ namespace SafeBagDE70
|
|||||||
APIModels.SendEvent(AppData.DeviceStatus);
|
APIModels.SendEvent(AppData.DeviceStatus);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user