-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_manager.cpp
149 lines (137 loc) · 4.74 KB
/
account_manager.cpp
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
#include "account_manager.h"
account_manager::account_manager() : current_account(new account) {
}
void account_manager::Login() {
while (true) {
SQLiteDB db("../bank.db");
int id;
std::string pass;
std::cout << "Enter id (no spaces): ";
std::cin >> id;
std::cout << "Enter password (no spaces): ";
std::cin >> pass;
std::vector<std::vector<std::string>> result = db.selectData("account", id);
if (result[0][2] != pass) {
std::cout << "\nInvalid user id number or password. Try again\n\n";
continue;
}
current_account->Set_id(std::stoi(result[0][0]));
current_account->Set_user_name(result[0][1]);
current_account->Set_password(result[0][2]);
current_account->Set_balance(std::stoi(result[0][3]));
break;
}
}
account_manager::~account_manager() {
current_account = nullptr;
}
void account_manager::SignUp() {
SQLiteDB db("../bank.db");
std::string name,password;
std::cout << "Enter user name (No spaces): ";
std::cin >> name;
current_account->Set_user_name(name);
std::cout << "Enter password (no spaces): ";
std::cin >> password;
current_account->Set_password(password);
db.insertData("account", {name, password, "0"});
current_account->Set_id(db.getMaxID("account"));
std::cout << "your ID : " << current_account->Get_id() << '\n';
}
void account_manager::AccessSystem() {
// system("CLS");
std::cout << "\n";
std::cout << "\t1: Login\n";
std::cout << "\t2: SignUP\n";
std::cout << "\nEnter number in range " << "1 - 2: ";
int choice;
std::cin >> choice;
if (choice == 1) {
Login();
View();
if (current_account == nullptr) {
delete current_account;
current_account = nullptr;
}
} else {
SignUp();
}
}
void account_manager::Withdraw() {
std::cout << "Enter Amount of money : ";
int amount;
std::cin >> amount;
if (current_account->available_to_use(amount)) {
current_account->Reduse_balance(amount);
std::cout << "Withdraw Done Successfully\n";
} else {
std::cout << "You don't have enough money to Withdraw.\n";
}
std::cout << "Your current balance is "
<< current_account->Get_balance() << '\n';
SQLiteDB db("../bank.db");
std::string b = std::to_string(current_account->Get_balance());
db.updateData("account", "balance", b.c_str(), current_account->Get_id());
}
void account_manager::Deposit_money() {
std::cout << "Enter Amount of money : ";
int amount;
std::cin >> amount;
current_account->Add_balance(amount);
std::cout << "Deposit Done Successfully\n"
<< "Your current balance is "
<< current_account->Get_balance() << '\n';
SQLiteDB db("../bank.db");
std::string b = std::to_string(current_account->Get_balance());
db.updateData("account", "balance", b.c_str(), current_account->Get_id());
}
void account_manager::Send() {
SQLiteDB db("../bank.db");
int id;
account rec;
std::cout << "Enter the recipient ID : ";
std::cin >> id;
std::cout << "Enter Amount of money : ";
int amount;
std::cin >> amount;
std::vector<std::vector<std::string>> result = db.selectData("account", id);
rec.Set_id(std::stoi(result[0][0]));
rec.Set_user_name(result[0][1]);
rec.Set_password(result[0][2]);
rec.Set_balance(std::stoi(result[0][3]));
if (current_account->available_to_use(amount)) {
rec.Add_balance(amount);
current_account->Reduse_balance(amount);
std::cout << current_account->Get_user_name() << " Send " << amount << " to " << rec.Get_user_name()
<< '\n';
std::string b = std::to_string(current_account->Get_balance());
db.updateData("account", "balance", b.c_str(), current_account->Get_id());
b = std::to_string(rec.Get_balance());
db.updateData("account", "balance", b.c_str(), rec.Get_id());
} else {
std::cout << "You don't have enough money to Transfer \n";
}
}
void account_manager::View() {
std::cout << "\n\nHello " << current_account->Get_user_name() << '\n';
while (true) {
int choice;
std::cout << "\t1: View Profile\n";
std::cout << "\t2: Withdraw\n";
std::cout << "\t3: Deposit money\n";
std::cout << "\t4: Transfer To\n";
std::cout << "\t5: Logout\n";
std::cin >> choice;
if (choice == 1) {
current_account->PrintInfo();
} else if (choice == 2) {
Withdraw();
} else if (choice == 3) {
Deposit_money();
} else if (choice == 4) {
Send();
} else {
break;
}
}
}