Thiết lập gần hết giấy cho in tối đa 20 lần
This commit is contained in:
+119
-1
@@ -19,6 +19,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace SafeBagDE70
|
||||
@@ -44,7 +45,8 @@ namespace SafeBagDE70
|
||||
static Task? resendTaskHistories = null;
|
||||
static Task? resendTaskEvents = null;
|
||||
static Task? commandTask = null;
|
||||
public static DeviceStatus? _DeviceStatus = null;
|
||||
private static DeviceStatus? _DeviceStatus = null;
|
||||
public static DeviceStatusFile? DeviceStatusFile = null;
|
||||
public static DeviceStatus? DeviceStatus
|
||||
{
|
||||
set { _DeviceStatus = value; }
|
||||
@@ -67,6 +69,7 @@ namespace SafeBagDE70
|
||||
CDMSTATE = new CDMSTATE();
|
||||
ADMINDEVICESTATUS = new ADMINDEVICESTATUS();
|
||||
customerAccounts = new ObservableCollection<CustomerAccount>();
|
||||
GetDeviceStatusFromFile();
|
||||
//InitDeviceStatus();
|
||||
}
|
||||
public static void Init()
|
||||
@@ -474,6 +477,108 @@ namespace SafeBagDE70
|
||||
Log.Error("GetandExecuteCommands error: "+str);
|
||||
}
|
||||
}
|
||||
static string deviceStatusFileName = "device_status.txt";
|
||||
public static void GetDeviceStatusFromFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
lock(deviceStatusFileName)
|
||||
{
|
||||
if (File.Exists(deviceStatusFileName))
|
||||
{
|
||||
var fileContent = File.ReadAllText(deviceStatusFileName);
|
||||
DeviceStatusFile = JsonConvert.DeserializeObject<DeviceStatusFile>(fileContent);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeviceStatusFile = new DeviceStatusFile();
|
||||
UpdateDeviceStatusToFile();
|
||||
}
|
||||
}
|
||||
Log.Information("GetPrinterStatusFromFile success");
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "GetPrinterStatusFromFile");
|
||||
}
|
||||
}
|
||||
public static void UpdatePrinterStatus(bool IsPrinterPaperOut)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (DeviceStatusFile!=null)
|
||||
{
|
||||
DeviceStatusFile.IsPrinterNearPaperOut = IsPrinterPaperOut;
|
||||
if (!IsPrinterPaperOut)
|
||||
{
|
||||
DeviceStatusFile.PrintingCountFromNPO = 0;
|
||||
}
|
||||
}
|
||||
}catch(Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "UpdatePrinterStatus");
|
||||
}
|
||||
}
|
||||
public static void UpdatePrintingCountToStatusFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.Information("UpdateTransactionCountToStatusFile");
|
||||
|
||||
if (DeviceStatusFile!=null)
|
||||
{
|
||||
if (DeviceStatusFile.IsPrinterNearPaperOut)
|
||||
{
|
||||
DeviceStatusFile.PrintingCountFromNPO++;
|
||||
}
|
||||
else
|
||||
{
|
||||
DeviceStatusFile.PrintingCountFromNPO = 0;
|
||||
}
|
||||
UpdateDeviceStatusToFile();
|
||||
|
||||
Log.Information("UpdateTransactionCountToStatusFile success");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "UpdateTransactionCountToStatusFile");
|
||||
}
|
||||
}
|
||||
public static void UpdateDeviceStatusToFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (deviceStatusFileName)
|
||||
{
|
||||
if (File.Exists(deviceStatusFileName))
|
||||
{
|
||||
var fileContent = JsonConvert.SerializeObject(DeviceStatusFile);
|
||||
File.WriteAllText(deviceStatusFileName, fileContent);
|
||||
}
|
||||
}
|
||||
Log.Information("UpdatePrinterStatusFromFile success");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "UpdatePrinterStatusFromFile");
|
||||
}
|
||||
}
|
||||
public static bool IsStopPrinting()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (DeviceStatusFile != null)
|
||||
return DeviceStatusFile.IsStopPrinting();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<int> UpdateCustomers()
|
||||
{
|
||||
try
|
||||
@@ -867,6 +972,19 @@ namespace SafeBagDE70
|
||||
public string? TransactionCode { get; set; }
|
||||
public string Description { get; set; }
|
||||
}
|
||||
public class DeviceStatusFile
|
||||
{
|
||||
public bool IsPrinterNearPaperOut = false;
|
||||
public int PrintingCountFromNPO = 0;//Transaction Count From Near Paper Out
|
||||
public bool IsStopPrinting()
|
||||
{
|
||||
if (IsPrinterNearPaperOut && PrintingCountFromNPO >= 20)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public enum DeviceStatusCode {
|
||||
NORMAL=0,
|
||||
ERROR=1
|
||||
|
||||
Reference in New Issue
Block a user