Add project files.
This commit is contained in:
@@ -0,0 +1,311 @@
|
||||
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<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];
|
||||
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 static CDMSTATE? GetCDMState()
|
||||
{
|
||||
if(cCmdRsp!=null)
|
||||
{
|
||||
cCmdRsp.SendDeSense();
|
||||
string strSend = cCmdRsp.GetSendDat(false);
|
||||
string strRecv = cCmdRsp.GetRecvDat();
|
||||
Log.Information($"[SEND] {strSend}");
|
||||
Log.Information($"[RECV] {strRecv}");
|
||||
var data = cCmdRsp.recv_dat.dat;
|
||||
if(AppData.CDMSTATE!=null)
|
||||
{
|
||||
AppData.CDMSTATE.IsCassetteFull = data[17] & 0x08;
|
||||
AppData.CDMSTATE.IsNotesInEscrow = data[4] & 0x01;
|
||||
AppData.CDMSTATE.IsRejectPocketFull = data[3] & 0x40;
|
||||
AppData.CDMSTATE.IsNotesInRejectPocket = data[3] & 0x10;
|
||||
AppData.CDMSTATE.IsNotesInHopper = data[3] & 0x01;
|
||||
AppData.CDMSTATE.RequestTime = DateTime.Now;
|
||||
AppData.CDMSTATE.SR1 = data[0];
|
||||
AppData.CDMSTATE.SR2 = data[1];
|
||||
AppData.CDMSTATE.SR3 = data[2];
|
||||
}
|
||||
|
||||
}
|
||||
return AppData.CDMSTATE;
|
||||
}
|
||||
|
||||
}
|
||||
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<CountSession>? 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 int CountingState { get; set; }//0-Normal End, 1-Timeout End
|
||||
}
|
||||
|
||||
public class NotesInSession : INotifyPropertyChanged
|
||||
{
|
||||
|
||||
private int _GenuineNotes;
|
||||
public int GenuineNotes
|
||||
{
|
||||
get
|
||||
{
|
||||
return _GenuineNotes;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_GenuineNotes != value)
|
||||
{
|
||||
_GenuineNotes = value;
|
||||
OnPropertyChanged(nameof(GenuineNotes));
|
||||
}
|
||||
}
|
||||
}
|
||||
private int _RejectNotes;
|
||||
public int RejectNotes
|
||||
{
|
||||
get
|
||||
{
|
||||
return _RejectNotes;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_RejectNotes != value)
|
||||
{
|
||||
_RejectNotes = value;
|
||||
OnPropertyChanged(nameof(RejectNotes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
public void UpdateCDMStatus()
|
||||
{
|
||||
if (AppData.cCmdRsp != null) {
|
||||
CDMStatus = RequestTime.ToString("yyyyMMdd HHmmss")+ " 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));
|
||||
}
|
||||
}
|
||||
public class DeviceStatus
|
||||
{
|
||||
public int TenantId { get; set; }
|
||||
public string Device { get; set; }
|
||||
public int Status { get; set; }
|
||||
public DateTime DeviceTime { get; set; }
|
||||
public int CDMStatus { get; set; }
|
||||
public int PrinterStatus { get; set; }
|
||||
public int SensorStatus { get; set; }
|
||||
public int OtherError { get; set; }
|
||||
public string Description { get; set; }
|
||||
}
|
||||
public enum DeviceStatusCode {
|
||||
NORMAL=0,
|
||||
ERROR=1
|
||||
}
|
||||
public enum PrinterStatusCode
|
||||
{
|
||||
NORMAL = 0,
|
||||
NEARPAPEROUT = 1,
|
||||
PAPEROUT=2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using SafeBagDE70.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace SafeBagDE70
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for QRCodeWindow.xaml
|
||||
/// </summary>
|
||||
public partial class QRCodeWindow : HandyControl.Controls.Window
|
||||
{
|
||||
private DispatcherTimer timer;
|
||||
int countTimer = 0;
|
||||
public string QRCodeContent = null;
|
||||
public QRCodeWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.KeyDown += QRCodeWindow_KeyDown;
|
||||
this.Loaded += QRCodeWindow_Loaded;
|
||||
}
|
||||
private void QRCodeWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Keyboard.Focus(this);
|
||||
timer = new DispatcherTimer();
|
||||
|
||||
// Set the timer interval to 1 second
|
||||
timer.Interval = TimeSpan.FromMilliseconds(100);
|
||||
|
||||
// Define the event handler that's called each time the timer elapses
|
||||
timer.Tick += Timer_Tick;
|
||||
|
||||
// Start the timer
|
||||
timer.Start();
|
||||
}
|
||||
private void Timer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
countTimer++;
|
||||
if (QRCodeContent!=null && countTimer == 5)
|
||||
{
|
||||
DialogResult = true;
|
||||
this.Close();
|
||||
//finish
|
||||
}
|
||||
}
|
||||
|
||||
private void QRCodeWindow_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
QRCodeContent += KeyModel.GetCharFromKey(e.Key);
|
||||
countTimer = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user