-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
138 lines (122 loc) · 3.6 KB
/
Copy pathMenu.cpp
File metadata and controls
138 lines (122 loc) · 3.6 KB
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
#include <iostream>
#include "ClearScreen.h"
#include "Menu.h"
#include <limits>
#include "PasswordManager.h"
using namespace std;
void Menu::displayMenu() {
cout << "\tMAIN MENU" << endl
<< "__________________________" << endl
<< "ADD STOCK [1]" << endl
<< "VIEW STOCK [2]" << endl
<< "DELETE STOCK [3]" << endl
<< "EDIT PASSWORD [4]" << endl
<< "EXIT [5]" << endl;
}
int Menu::getUserChoice() {
int choice;
while (true) {
cout << "Please enter a number between 1 and 6: "<< endl;
cin >> choice;
if (cin.fail()) {
cin.clear();
cin.ignore(numeric_limits<ptrdiff_t>::max(), '\n');
cout << "Invalid. Please enter a number between 1 and 6." << endl;
} else if (choice < 1 || choice > 6) {
cout << "Invalid. Please enter a number between 1 and 6." << endl;
} else {
return choice;
}
}
}
bool Menu::handleUserChoice() {
int choice = getUserChoice();
Node* input = nullptr;
string error;
bool exit = false;
switch (choice) {
case 1:
input = new Node;
cout << "Enter the ID: ";
cin >> input->id;
cout << "Enter the name: ";
cin.ignore();
getline(cin, input->name);
cout << "Enter the category: ";
getline(cin, input->category);
cout << "Enter the quantity: ";
cin >> input->quantity;
cout << "Enter the price: ";
cin >> input->price;
cout << "Enter the date in: ";
cin.ignore();
getline(cin, input->dateIn);
cout << "Enter the date out: ";
getline(cin, input->dateOut);
addStock(input);
break;
case 2:
displayQueue();
cin.ignore();
cout << "Press any key to continue" << endl;
getchar();
break;
case 3:
removeStock();
cout << "\nItem first in stock has been removed.\nPlease press any key to continue" << endl;
cin.ignore();
getchar();
break;
case 4:
passwordManager.setPassword();
break;
case 5:
fileHandler.saveToFile(&stockQueue);
return true;
default:
error = "Invalid, Please try again\n";
break;
}
system(CLEAR);
if(!error.empty())
cout << error;
return exit;
}
void Menu::displayQueue() {
stockQueue.display();
//soon we will
}
void Menu::addStock(Node* input) {
if (input == nullptr) {
cout << "Invalid, Please try again" << endl;
return;
}
stockQueue.enqueue(input);
cout << "Item added to stock successfully" << endl;
}
void Menu::removeStock() {
if (stockQueue.isEmpty()) {
cout << "The stock queue is empty" << endl;
return;
}
stockQueue.dequeue();
cout << "Item removed successfully: " << endl;
}
bool Menu::authentication() {
string enterPass;
if (!passwordManager.checkPasswordAvailability()) {
cout << "There is no stored password. Please set a new password." << endl;
passwordManager.setPassword();
return true;
}
cout << "Please enter your password:" << endl;
// cin.ignore(); heya bent el lazina de
getline(cin, enterPass);
if (passwordManager.getPassword(enterPass)) {
cout << "Success!" << endl;
return true;
} else {
cout << "Failed. Please try again." << endl;
return false;
}
}