87 lines
4.1 KiB
Plaintext
87 lines
4.1 KiB
Plaintext
using DE70_CMDv2;
|
|
using SafeBagDE70.Model;
|
|
using Serilog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
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<CustomerAccount>? 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<string> logCollection = new ObservableCollection<string>();
|
|
public static ListView logListView = null;
|
|
public static int MaxLogCount = 500;
|
|
public static void Init()
|
|
{
|
|
|
|
customerAccounts = new List<CustomerAccount>{
|
|
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];
|
|
}
|
|
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; }
|
|
}
|
|
}
|