using DE70_CMDv2; using Newtonsoft.Json.Linq; using SafeBagDE70.Model; using Serilog; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; namespace SafeBagDE70 { public static class AppData { public static string CDMPort = "COM4"; public static string SensorPort = "COM3"; public static Version? CurrentVersion = null; public static List? customerAccounts = null; public static CustomerAccount? CurrentCustomerAccount{get;set;} public static CCmdRsp? cCmdRsp=null; public static bool IsAuthenticated = false; public static bool IsInTransaction = false; public static int WDTCount = 0; public static ObservableCollection logCollection = new ObservableCollection(); public static ListView logListView = null; public static int MaxLogCount = 500; public static void Init() { customerAccounts = new List{ new CustomerAccount{Name="NGUYỄN ĐÌNH THUẬN",CustomerId="HUE_0000000001",QRCode="HUE_0000000001",PINCode="H0001" }, new CustomerAccount{Name="HOÀNG VĂN HIỆP",CustomerId="HUE_0000000002",QRCode="HUE_0000000002",PINCode="H0002" }, new CustomerAccount{Name="PHẠM NGỌC HƯNG",CustomerId="HUE_0000000003",QRCode="HUE_0000000003",PINCode="H0003" }, new CustomerAccount{Name="AMHUE-ESTELLETEST",CustomerId="00DZAMHUE0004",QRCode="00DZAMHUE0004",PINCode="H0004" }, new CustomerAccount{Name="AMHUE-ECCOTEST",CustomerId="00DZAMHUE0005",QRCode="00DZAMHUE0005",PINCode="H0005" }, new CustomerAccount{Name="AMHUE-ALDOTEST",CustomerId="00DZAMHUE0006",QRCode="00DZAMHUE0006",PINCode="H0006" }, new CustomerAccount{Name="AMHUE-MLBTEST",CustomerId="00DZAMHUE0007",QRCode="00DZAMHUE0007",PINCode="H0007" }, new CustomerAccount{Name="AMHUE-PEDROTEST",CustomerId="00DZAMHUE0008",QRCode="00DZAMHUE0008",PINCode="H0008" } }; CurrentCustomerAccount = customerAccounts[0]; CDMSTATE=new CDMSTATE(); } public static CDMSTATE? CDMSTATE = null; private static DateTime CutOffTime = new DateTime(1, 1, 1, 12, 0, 0); // 12:00 noon as cut-off time public static void GetNewTransactionCode() { DateTime transactionDateTime = DateTime.Now; string merchantCode = CurrentCustomerAccount.CustomerId; // Adjust transaction date if it's past cut-off time (12:00 noon) DateTime prevadjustedDate = CurrentCustomerAccount.TransactionTime.Hour >= CutOffTime.Hour ? transactionDateTime.Date : transactionDateTime.Date.AddDays(-1); DateTime adjustedDate = transactionDateTime.Hour >= CutOffTime.Hour ? transactionDateTime.Date : transactionDateTime.Date.AddDays(-1); if ((adjustedDate - prevadjustedDate).Days > 0) { CurrentCustomerAccount.TransactionCount =1; } else { CurrentCustomerAccount.TransactionCount++; } var transactionCount = CurrentCustomerAccount.TransactionCount; string datePart = adjustedDate.ToString("yyyyMMdd"); string timePart = transactionDateTime.ToString("HHmmss"); string transactionCountPart = transactionCount.ToString("D2"); // Ensure 2 digits // Combine all parts to form the transaction ID string transactionId = $"{datePart}{timePart}{merchantCode}{transactionCountPart}"; CurrentCustomerAccount.TransactionCode = transactionId; CurrentCustomerAccount.TransactionTime = transactionDateTime; } } public class CustomerAccount { public string? Name { get; set; } public string? CustomerId { get; set; } public string? QRCode { get; set; } public string? PINCode { get; set; } public int TransactionCount { get; set; } = 1; public DateTime TransactionTime { get; set; } public string TransactionCode { get; set; } } public class CountSession { public CountSession() { for (int i = 0; i < QuantityDenomi.Count(); i++) { QuantityDenomi[i] = 0; } for (int i = 0; i < SumDenomi.Count(); i++) { SumDenomi[i] = 0; } for (int i = 0; i < TempNotes.Count(); i++) { TempNotes[i] = 0; } } public int[] QuantityDenomi { get; set; } = new int[10]; public int[] SumDenomi { get; set; } = new int[10]; public bool IsStored = false; public int[] TempNotes { get; set; } = new int[5]; } public class CountingData2Send { public string? TransactionCode { get; set; } public List? Sessions { get; set; } public string? UserId { get; set; } public string? MachineId { get; set; } public string? MachineTime { get; set; } public int RejectNotes { get; set; } public int GenuineNotes { get; set; } public int UnfitNotes { get; set; } public int CounterfeitNotes { get; set; } public int SuspendNotes { get; set; } } public class CDMSTATE : INotifyPropertyChanged { public int IsCassetteFull = 0; public int IsNotesInEscrow = 0; public int IsRejectPocketFull = 0; public int IsNotesInRejectPocket = 0; public int IsNotesInHopper = 0; private byte _SR1; public byte SR1 { get { return _SR1; } set { if (_SR1 != value) { _SR1 = value; UpdateCDMStatus(); OnPropertyChanged(nameof(SR1)); } } } private byte _SR2; public byte SR2 { get { return _SR2; } set { if (_SR2 != value) { _SR2 = value; UpdateCDMStatus(); OnPropertyChanged(nameof(SR2)); } } } private byte _SR3; public byte SR3 { get { return _SR3; } set { if (_SR3 != value) { _SR3 = value; UpdateCDMStatus(); OnPropertyChanged(nameof(SR3)); } } } private void UpdateCDMStatus() { if (AppData.cCmdRsp != null) { CDMStatus = "SR1: " + AppData.cCmdRsp.GetSR1Summary(SR1) + " SR2: " + AppData.cCmdRsp.GetSR2Summary(SR2); } } private string? _CDMStatus; public string? CDMStatus { get { return _CDMStatus; } set { if (_CDMStatus != value) { _CDMStatus = value; OnPropertyChanged(nameof(CDMStatus)); } } } public DateTime RequestTime = DateTime.Now; public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } }