This commit is contained in:
thuannd88
2024-09-05 13:54:06 +07:00
parent f4f433b838
commit acfa22a83a
3 changed files with 167 additions and 97 deletions
+10 -8
View File
@@ -68,12 +68,13 @@ namespace SafeBagDE70.Admin
((MainWindow)Application.Current.MainWindow).ShowWelcomeScreen();
Task.Run(() =>
{
Thread.Sleep(2000);
Thread.Sleep(5000);
Dispatcher.Invoke(() =>
{
lblCounterStatus.Text = "";
});
});
AppData.GetCassetteData();
}
else
{
@@ -116,12 +117,14 @@ namespace SafeBagDE70.Admin
{
cCmdRsp.SendEventFix(recvData.dat[16]);
}
if (cCmdRsp.recv_dat.dat[0] != 0x40)
{
bSuccess = false;
}
if (bSuccess)
{
//if (cCmdRsp.recv_dat.dat[0] != 0x40)
//{
// bSuccess = false;
//}
//if (bSuccess)
//{
//}
Thread.Sleep(1000);
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_RESET);
Thread.Sleep(2000);
@@ -141,7 +144,6 @@ namespace SafeBagDE70.Admin
}
}
}
}
catch (Exception ex) {
Log.Fatal(ex, "SoftReset");
}
+38 -2
View File
@@ -53,7 +53,7 @@ namespace SafeBagDE70
CDMStatus = 0,
PrinterStatus = 0,
SensorStatus = 0,
Notes = 0,
Notes = "",
OtherError = 0,
};
}
@@ -121,6 +121,36 @@ namespace SafeBagDE70
}
}
public static byte[] GetCassetteData()
{
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_READ_CASSETTE);
var data = cCmdRsp.recv_dat.dat;
StringBuilder str = new StringBuilder();
var recv_dat = cCmdRsp.recv_dat;
AppData.DeviceStatus.Notes = GetNotesString(recv_dat.dat);
str.Append("DATA:");
for (int i = 0; i < recv_dat.leng - 1; i++)
{
var dat = string.Format("{0:X2} ", recv_dat.dat[i]);
str.Append(dat);
}
Log.Information("[CASSETTE]" + str.ToString());
return (byte[])data.Clone();
}
public static string GetNotesString(byte[] cassetData)
{
int notes = 0;
int offset = 14;
string str = "";
for (int i = 0; i < 10; i++)
{
notes = cassetData[2 * i + offset] * 256 + cassetData[2 * i + 1 + offset];
str += notes + ",";
}
return str.Trim(',');
}
}
public class CustomerAccount
@@ -215,6 +245,12 @@ namespace SafeBagDE70
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public enum COUNTINGSTATE
{
NORMAL=0,
AUTOEND=1,
FULLIFSTORE=2
}
public class CDMSTATE : INotifyPropertyChanged
{
public int IsCassetteFull = 0;
@@ -336,7 +372,7 @@ namespace SafeBagDE70
public int PrinterStatus { get; set; }
public int SensorStatus { get; set; }
public int OtherError { get; set; }
public int? Notes { get; set; }
public string? Notes { get; set; }
public string Description { get; set; }
}
public enum DeviceStatusCode {
+56 -24
View File
@@ -120,7 +120,7 @@ namespace SafeBagDE70
StopTimers();
ShowError(state.CDMStatus);
}
GetCassetteData();
AppData.GetCassetteData();
}
catch (Exception ex)
{
@@ -231,7 +231,7 @@ namespace SafeBagDE70
DoStoreStart();
Dispatcher.Invoke(() =>
{
EndSession(1);
EndSession(COUNTINGSTATE.AUTOEND,"Tự động kết thúc");
});
Log.Information("7. Timout completed");
});
@@ -631,24 +631,7 @@ namespace SafeBagDE70
}
return bSuccess;
}
private byte[] GetCassetteData()
{
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_READ_CASSETTE);
var data=cCmdRsp.recv_dat.dat;
StringBuilder str=new StringBuilder();
var recv_dat = cCmdRsp.recv_dat;
AppData.DeviceStatus.Notes = GetNotes(recv_dat.dat);
str.Append("DATA:");
for (int i = 0; i < recv_dat.leng - 1; i++)
{
var dat = string.Format("{0:X2} ", recv_dat.dat[i]);
str.Append(dat);
}
Log.Information("[CASSETTE]" + str.ToString());
return (byte[])data.Clone();
}
private int GetNotes(byte[] cassetData)
{
int notes = 0;
@@ -659,6 +642,7 @@ namespace SafeBagDE70
}
return notes;
}
private bool CheckStoreValid(byte[] previousCassetData, byte[] newCassetData,List<CountSession> countSessions)
{
var quantFromSession = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };//500.000->500
@@ -686,9 +670,33 @@ namespace SafeBagDE70
return bValid;
}
private bool CheckPreStoreValid(byte[] previousCassetData, int maxNotes, List<CountSession> countSessions)
{
var quantFromSession = 0;//500.000->500
var quantFromCasset = 0;
bool bValid = true;
foreach (var session in countSessions)
{
if ((session.IsStored == false))
{
for (int i = 0; i < 10; i++)
quantFromSession += session.QuantityDenomi[i];
}
}
int offset = 14;
for (int i=0;i<10; i++)
{
quantFromCasset += previousCassetData[2 * i + offset] * 256 + previousCassetData[2 * i + 1 + offset];
}
if (quantFromCasset + quantFromSession > maxNotes)
bValid = false;
return bValid;
}
private void UpdateListViewCountItems()
{
Dispatcher.Invoke(DispatcherPriority.Normal, () =>
{
if (lvCountItems != null && lvCountItems.Count > 0)
{
double sum = 0;
if (sessions != null && sessions.Count > 0)
@@ -734,6 +742,8 @@ namespace SafeBagDE70
lvCountItems[i].Value = "0";
}
}
}
});
}
@@ -824,10 +834,12 @@ namespace SafeBagDE70
//Debug.WriteLine(quantityStored);
var previousCassetData = GetCassetteData();
var previousCassetData = AppData.GetCassetteData();
if(CheckPreStoreValid(previousCassetData,300,sessions))
{
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_STORESTART);
bSuccess = WaitUntilCountReady(10);
var newCasstData = GetCassetteData();
var newCasstData = AppData.GetCassetteData();
bool bValid = CheckStoreValid(previousCassetData, newCasstData, sessions);
if (bValid)
{
@@ -852,7 +864,16 @@ namespace SafeBagDE70
ShowError(str);
}
Thread.Sleep(2000);
Thread.Sleep(1000);
}
else
{
string str = "KÉT ĐÃ ĐẦY ĐỀ NGHỊ LẤY LẠI TIỀN VÀ KẾT THÚC GIAO DỊCH, VUI LÒNG BÁO CÁO LẠI CHI NHÁNH";
Log.Information(str);
DoCheck();
EndSession(COUNTINGSTATE.FULLIFSTORE,str);
}
}
catch (Exception ex)
{
@@ -959,7 +980,7 @@ namespace SafeBagDE70
return bSuccess;
}
private void EndSession(int _CountingState=0)
private void EndSession(COUNTINGSTATE _CountingState =0, string? strMessage=null)
{
string currentMethod = MethodBase.GetCurrentMethod().Name;
@@ -986,7 +1007,7 @@ namespace SafeBagDE70
UserId = AppData.CurrentCustomerAccount.CustomerId,
MachineTime = DateTime.Now.ToString("yyyyMMddHHmmss"),
GenuineNotes = quantityStored,
CountingState= _CountingState
CountingState= (int)_CountingState
};
SyncData(data2Send);
@@ -1000,9 +1021,20 @@ namespace SafeBagDE70
}
String strNotify = $"BẠN VỪA THỰC HIỆN NỘP TIỀN VÀO MÁY CDM:\r\n"
+ $"SỐ LƯỢNG TỜ: {totalQuantity}\r\n"
+ $"SỐ TIỀN: {totalValue} VND\r\n";
if (AppData.CurrentCustomerAccount != null)
{
var strTransactionCode = AppData.CurrentCustomerAccount.TransactionCode;
strNotify = strTransactionCode + "\r\n" + strNotify;
}
if(strMessage!=null)
{
strNotify += strMessage;
}
mainWindow.ShowInformationScreen(strNotify, false, false);
ResetSessions();
StartWelcomeTimer();