From acfa22a83a228b3b0e70717c8da1a2c1ca5605bc Mon Sep 17 00:00:00 2001 From: thuannd88 Date: Thu, 5 Sep 2024 13:54:06 +0700 Subject: [PATCH] fix --- Admin/AdminConfigurationUC.xaml.cs | 42 +++---- AppData.cs | 40 ++++++- DepositSMUCv2.xaml.cs | 182 +++++++++++++++++------------ 3 files changed, 167 insertions(+), 97 deletions(-) diff --git a/Admin/AdminConfigurationUC.xaml.cs b/Admin/AdminConfigurationUC.xaml.cs index eb2a1c5..c62e895 100644 --- a/Admin/AdminConfigurationUC.xaml.cs +++ b/Admin/AdminConfigurationUC.xaml.cs @@ -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,29 +117,30 @@ namespace SafeBagDE70.Admin { cCmdRsp.SendEventFix(recvData.dat[16]); } - if (cCmdRsp.recv_dat.dat[0] != 0x40) + //if (cCmdRsp.recv_dat.dat[0] != 0x40) + //{ + // bSuccess = false; + //} + //if (bSuccess) + //{ + + //} + Thread.Sleep(1000); + cCmdRsp.SendXXCmd((byte)Command.CMD_DE_RESET); + Thread.Sleep(2000); + cCmdRsp.SendXXCmd((byte)Command.CMD_DE_SENSE); + if (cCmdRsp.recv_dat.dat[1] == 0x04 && cCmdRsp.recv_dat.dat[2] == 0x41) { - bSuccess = false; - } - if (bSuccess) - { - Thread.Sleep(1000); - cCmdRsp.SendXXCmd((byte)Command.CMD_DE_RESET); - Thread.Sleep(2000); - cCmdRsp.SendXXCmd((byte)Command.CMD_DE_SENSE); - if (cCmdRsp.recv_dat.dat[1] == 0x04 && cCmdRsp.recv_dat.dat[2] == 0x41) + lblCounterStatus.Text = "Reset lỗi thành công"; + ((MainWindow)Application.Current.MainWindow).ShowWelcomeScreen(); + Task.Run(() => { - lblCounterStatus.Text = "Reset lỗi thành công"; - ((MainWindow)Application.Current.MainWindow).ShowWelcomeScreen(); - Task.Run(() => + Thread.Sleep(2000); + Dispatcher.Invoke(() => { - Thread.Sleep(2000); - Dispatcher.Invoke(() => - { - lblCounterStatus.Text = ""; - }); + lblCounterStatus.Text = ""; }); - } + }); } } } diff --git a/AppData.cs b/AppData.cs index 1ad7a67..a333f60 100644 --- a/AppData.cs +++ b/AppData.cs @@ -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 { diff --git a/DepositSMUCv2.xaml.cs b/DepositSMUCv2.xaml.cs index 3db7982..0ed3fb2 100644 --- a/DepositSMUCv2.xaml.cs +++ b/DepositSMUCv2.xaml.cs @@ -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 countSessions) { var quantFromSession = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };//500.000->500 @@ -686,54 +670,80 @@ namespace SafeBagDE70 return bValid; } + private bool CheckPreStoreValid(byte[] previousCassetData, int maxNotes, List 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, () => { - double sum = 0; - if (sessions != null && sessions.Count > 0) + if (lvCountItems != null && lvCountItems.Count > 0) { - for (int i = 0; i < 10; i++) + double sum = 0; + if (sessions != null && sessions.Count > 0) { - int quantity = 0; + for (int i = 0; i < 10; i++) + { + int quantity = 0; + for (int j = 0; j < sessions.Count; j++) + { + + quantity += sessions[j].QuantityDenomi[9 - i]; + + } + lvCountItems[i].Quantity = quantity.ToString(); + sum += lvCountItems[i].getValue(); + + } + //Update amount of money + lvCountItems[10].Quantity = UpdateTotalQuantity().ToString(); + lvCountItems[10].Value = sum.ToString(); + + //Update Notes In Sesion + notesInSession.GenuineNotes = 0; + notesInSession.RejectNotes = 0; + for (int j = 0; j < sessions.Count; j++) { - - quantity += sessions[j].QuantityDenomi[9 - i]; - - } - lvCountItems[i].Quantity = quantity.ToString(); - sum += lvCountItems[i].getValue(); - - } - //Update amount of money - lvCountItems[10].Quantity = UpdateTotalQuantity().ToString(); - lvCountItems[10].Value = sum.ToString(); - - //Update Notes In Sesion - notesInSession.GenuineNotes = 0; - notesInSession.RejectNotes = 0; - - for (int j = 0; j < sessions.Count; j++) - { - if (sessions[j].IsStored == false) - { - for (int i = 0; i < 10; i++) + if (sessions[j].IsStored == false) { - notesInSession.GenuineNotes += sessions[j].QuantityDenomi[9 - i]; + for (int i = 0; i < 10; i++) + { + notesInSession.GenuineNotes += sessions[j].QuantityDenomi[9 - i]; + } + notesInSession.RejectNotes += sessions[j].TempNotes.Sum(); } - notesInSession.RejectNotes += sessions[j].TempNotes.Sum(); + } + } + else + { + for (int i = 0; i < 11; i++) + { + lvCountItems[i].Quantity = "0"; + lvCountItems[i].Value = "0"; } } } - else - { - for (int i = 0; i < 11; i++) - { - lvCountItems[i].Quantity = "0"; - lvCountItems[i].Value = "0"; - } - } + }); } @@ -824,35 +834,46 @@ namespace SafeBagDE70 //Debug.WriteLine(quantityStored); - var previousCassetData = GetCassetteData(); - cCmdRsp.SendXXCmd((byte)Command.CMD_DE_STORESTART); - bSuccess=WaitUntilCountReady(10); - var newCasstData = GetCassetteData(); - bool bValid= CheckStoreValid(previousCassetData,newCasstData,sessions); - if(bValid) + var previousCassetData = AppData.GetCassetteData(); + if(CheckPreStoreValid(previousCassetData,300,sessions)) { - if (bSuccess) + cCmdRsp.SendXXCmd((byte)Command.CMD_DE_STORESTART); + bSuccess = WaitUntilCountReady(10); + var newCasstData = AppData.GetCassetteData(); + bool bValid = CheckStoreValid(previousCassetData, newCasstData, sessions); + if (bValid) { - foreach (var item in sessions) + if (bSuccess) { - item.IsStored = true; + foreach (var item in sessions) + { + item.IsStored = true; + } + quantityStored = UpdateTotalQuantity(); + Log.Information("Stored " + GetShortInforFromCountItems()); + } + else + { + Log.Error("Store FAIL " + GetShortInforFromCountItems()); } - quantityStored = UpdateTotalQuantity(); - Log.Information("Stored " + GetShortInforFromCountItems()); } else { - Log.Error("Store FAIL " + GetShortInforFromCountItems()); + string str = "PHIÊN GIAO DỊCH KHÔNG HỢP LỆ (SỐ TIỀN GIAO DỊCH KHÔNG KHỚP), VUI LÒNG BÁO CÁO LẠI CHI NHÁNH"; + Log.Information(str); + ShowError(str); } - } + + Thread.Sleep(1000); + } else { - string str = "PHIÊN GIAO DỊCH KHÔNG HỢP LỆ (SỐ TIỀN GIAO DỊCH KHÔNG KHỚP), VUI LÒNG BÁO CÁO LẠI CHI NHÁNH"; + 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); - ShowError(str); - } - - Thread.Sleep(2000); + 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();