-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclsTransfer.h
151 lines (125 loc) · 4.96 KB
/
clsTransfer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#pragma once
#include "clsScreen.h"
#include "Global.h"
class clsTransfer : public clsScreen {
static string _PrepareTransferLogRecord(clsClient& SourceClient,clsClient& DestinationClient, float Amount, string separator = "#//#") {
return clsDate::GetTodayAndTime() + separator
+ SourceClient.account_number + separator // from
+ DestinationClient.account_number + separator // to
+ to_string(Amount) + separator // amount
+ UserSession::getCurrentUser().UserName; // user
}
static void _AddTransferLogLineToFile(clsClient& SourceClient, clsClient& DestinationClient, float Amount, string separator = "#//#") {
string LogLine = "";
fstream LogTransferFile;
LogTransferFile.open(LogTransferFilePath, ios::app);
if (LogTransferFile.is_open())
{
LogLine = _PrepareTransferLogRecord(SourceClient, DestinationClient, Amount, separator);
LogTransferFile << LogLine << endl;
LogTransferFile.close();
}
}
struct stLog;
static stLog _ConvertLogLineToRecord(string LogLine) {
vector<string> vlog = clsString::Split(LogLine,"#//#");
return stLog(vlog[0], vlog[1], vlog[2], vlog[3], vlog[4]);
}
static vector<stLog> _LoadTransfersDataFromFile() {
vector<stLog> vLogs;
stLog Log;
fstream TransferLogs;
TransferLogs.open(LogTransferFilePath, ios::in);
string Line;
if (TransferLogs.is_open())
{
while (getline(TransferLogs,Line))
{
Log = _ConvertLogLineToRecord(Line);
vLogs.push_back(Log);
}
TransferLogs.close();
}
return vLogs;
}
static void _PrintTransferLogRecordLine(stLog Log)
{
cout << "| " << setw(35) << left << Log.DateAndTime;
cout << "| " << setw(13) << left << Log.AccFrom;
cout << "| " << setw(13) << left << Log.AccTo;
cout << "| " << setw(13) << left << Log.Amounttransferred;
cout << "| " << setw(13) << left << Log.UserPerformedTransfer;
}
public:
struct stLog
{
string DateAndTime, AccFrom, AccTo, Amounttransferred , UserPerformedTransfer;
stLog(){};
stLog(string dateAndTime,string accFrom,string accTo,string amountTransferred,string userPerformedTransfer) {
DateAndTime = dateAndTime;
AccFrom = accFrom;
AccTo = accTo;
Amounttransferred = amountTransferred;
UserPerformedTransfer = userPerformedTransfer;
}
};
static void Transfer() {
float AmountToTransfer = 0;
_DrawScreenHeader("Transfer Screen");
string AccNumFrom = clsInputValidate::ReadString("\nEnter Account Number To Transfer From : ");
while (!clsClient::IsClientExisits(AccNumFrom))
{
AccNumFrom = clsInputValidate::ReadString("\nClient does not exist!\nEnter Account Number To Transfer From :\n");
}
string AccNumTo = clsInputValidate::ReadString("\nEnter Account Number To Transfer To : \n");
while (!clsClient::IsClientExisits(AccNumTo))
{
AccNumTo = clsInputValidate::ReadString("\nClient dows not exist!\nEnter Account Number To Transfer To : \n");
}
clsClient TransferFromClient = clsClient::Find(AccNumFrom);
clsClient TransferToClient = clsClient::Find(AccNumTo);
system("cls");
_DrawScreenHeader("Transfer Screen");
cout << "\nClient To Transfer From Data: ";
clsScreen::PrintShortlistedClient(TransferFromClient);
cout << "\nClient To Transfer To Data: ";
clsScreen::PrintShortlistedClient(TransferToClient);
cout << "-------------------------------\n";
cout << "\nBalance is "<<TransferFromClient.balance<<" Enter Amount To Transfer : \n";
AmountToTransfer = clsInputValidate::ReadFloatNumberBetween(1, TransferFromClient.balance);
TransferFromClient.Transfer(AmountToTransfer, TransferToClient);
system("cls");
_DrawScreenHeader("Transfer Screen");
cout << "\nAmount Transfered Successfully\n";
cout << "Client Transfered From Data\n";
clsScreen::PrintShortlistedClient(TransferFromClient);
cout << "Client Transfered To Data\n";
clsScreen::PrintShortlistedClient(TransferToClient);
cout << "\nThank You!\n";
_AddTransferLogLineToFile(TransferFromClient, TransferToClient, AmountToTransfer);
}
static void _TransferLogScreen() {
_DrawScreenHeader("Trasnfer Logs Screen");
vector<stLog> vLogs = _LoadTransfersDataFromFile();
cout << "\n\t\t\t\t\Transfer Logs List (" << vLogs.size() << ") Client(s).";
cout << "\n_______________________________________________________";
cout << "_________________________________________\n" << endl;
cout << "| " << left << setw(35) << "Date And Time";
cout << "| " << left << setw(13) << "Client From";
cout << "| " << left << setw(13) << "Client To";
cout << "| " << left << setw(13) << "Amount";
cout << "| " << left << setw(13) << "User";
cout << "\n_______________________________________________________";
cout << "_________________________________________\n" << endl;
if (vLogs.size() == 0)
cout << "\t\t\t\tNo Clients Available In the System!";
else
for (stLog& Log : vLogs)
{
_PrintTransferLogRecordLine(Log);
cout << endl;
}
cout << "\n_______________________________________________________";
cout << "_________________________________________\n" << endl;
}
};