-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.cpp
More file actions
255 lines (240 loc) · 8.88 KB
/
admin.cpp
File metadata and controls
255 lines (240 loc) · 8.88 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#include "admin.h"
#include "stock.h"
#include "onlineorder.h"
#include <iostream>
#include <fstream>
#include <cstring>
#include <limits>
#include "color.h"
// void stockshow();
// definition ha constructor ki
admin::admin()
{
stockobject = new stock;
if (!stockobject)
{
markRed();
cerr << "Failed to allocate memory for stockobject." << endl;
resetColor();
exit(-1);
}
login();
}
/*here ---- idar fucntion ha login ke liye -----------*/
void admin ::login()
{
const int MAX_LENGTH = 20; // Maximum length for username and password
char check_username[MAX_LENGTH];
char check_passcode[MAX_LENGTH];
// Open the file to read credentials
ifstream loginFile("credential.txt");
if (loginFile.fail()) // error dekhne ke liye
{
markRed();
cout << "File is not opened" << endl;
resetColor();
exit(-1);
}
else
{
// ye file se read karain gain
loginFile.getline(check_username, MAX_LENGTH, '\n');
loginFile.getline(check_passcode, MAX_LENGTH);
loginFile.close();
// size ko find karne ke liye aesa kia
size = strlen(check_username) + 1;
size1 = strlen(check_passcode) + 1;
username = new char[size + 1];
passcode = new char[size1];
// now check if it is match or not so
int choice;
bool loggedIn = false;
do
{
loggedIn = false;
// Prompt for username ke nam enter kare
markCyan();
cout << "\nEnter username: ";
cin >> username;
resetColor();
cin.ignore();
// Prompt for password
markMagenta();
cout << "\nEnter password: ";
cin >> passcode;
resetColor();
cout << endl;
// now check ke sahi be ha ke nahi ha
if (strncmp(username, check_username, MAX_LENGTH) == 0 && strncmp(passcode, check_passcode, MAX_LENGTH) == 0)
{
loggedIn = true;
showadmin();
cout << endl
<< endl;
display();
}
else
{
markRed();
cout << "Sorry! Invalid username or password." << endl;
cout << "Do you want to try again?" << endl;
cout << "Press 0 for exit or any other key to re-enter credentials: ";
resetColor();
cin >> choice;
if (choice == 0)
exit(0);
// Clear karna zarori ha cin.ignore jo ye wala ha proper aik \n ko ignore karta ha
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
} while (!loggedIn && choice != 0);
}
}
// display ka fucntion jis me sare function hain aage
void admin::display()
{
int choice;
do
{
markCyan(); // Applying cyan color
cout << "\t \t*************************************************\n";
cout << "\t \t* Admin Menu *\n";
cout << "\t \t*************************************************\n\n";
resetColor(); // Resetting color
markGreen();
cout << "----------------------------------------------------------" << endl;
cout << "| 1--> Stock display |" << endl;
cout << "----------------------------------------------------------" << endl;
cout << "| 2--> Remove stock OR New items order |" << endl;
cout << "----------------------------------------------------------" << endl;
cout << "| 3--> Delete credential of employees/students |" << endl;
cout << "----------------------------------------------------------" << endl;
cout << "| 4--> Display Best Seller Employee |" << endl;
cout << "----------------------------------------------------------" << endl;
cout << "| 5--> Notifications |" << endl;
cout << "----------------------------------------------------------" << endl;
cout << "| 6--> online orders |" << endl;
cout << "----------------------------------------------------------" << endl;
cout << "| 7--> Complaints |" << endl;
cout << "----------------------------------------------------------" << endl;
cout << "| 8--> Stats |" << endl;
cout << "----------------------------------------------------------" << endl;
cout << "| 9--> Reservation |" << endl;
cout << "----------------------------------------------------------" << endl;
cout << "| 10--> Tip managment |" << endl;
cout << "----------------------------------------------------------" << endl;
cout << "| 11--> Exit |" << endl;
cout << "----------------------------------------------------------" << endl;
resetColor();
markYellow();
cout << "Enter your choice: ";
cin >> choice;
resetColor();
switch (choice)
{
case 1:
markYellow(); // yellow color kia hoa
cout << "\nStock display : " << endl;
resetColor(); // Resetting color
stockobject->loadstock_from_file();
break;
case 2:
markYellow(); // Applying yellow color
cout << "\n Remove stock or order new items" << endl;
resetColor(); // Resetting color
powers = new StockHandleByAdmin;
break;
case 3:
markYellow(); // Applying yellow color
cout << "\nDelete credential of employees/students" << endl;
resetColor(); // Resetting color
deal = new adminotherdealing;
deal->reademployees();
break;
case 4:
markYellow(); // Applying yellow color
cout << "\nDisplay Best Seller Employee" << endl;
resetColor(); // Resetting color
deal = new adminotherdealing;
deal->bestseller();
break;
case 5:
markYellow(); // Applying yellow color
cout << "\nNotifications" << endl;
resetColor(); // Resetting color
deal = new adminotherdealing;
deal->writenotification();
break;
case 6:
markYellow(); // Applying yellow color
cout << "\nonline orders " << endl;
resetColor(); // Resetting color
online = new onlineOrder;
if (!online)
{
cerr << "Failed to allocate memory for online." << endl;
exit(-1);
}
online->viewAndRespondToOrders();
break;
case 7:
markYellow(); // Applying yellow color
cout << "\ncomplaints: \n";
resetColor(); // Resetting color
deal = new adminotherdealing;
deal->seecomplaint();
break;
case 8:
markYellow(); // Applying yellow color
cout << "\nstats :" << endl;
resetColor(); // Resetting color
stockobject->stats();
break;
case 9:
deal = new adminotherdealing;
deal->confirmreservation();
break;
case 10:
deal= new adminotherdealing;
deal->tipemployee();
break;
case 11:
markRed(); // Applying yellow color
cout << "\nExiting admin menu." << endl;
resetColor(); // Resetting color
exit(-1);
break;
default:
markRed(); // Applying red color to error message
cout << "\nInvalid choice. Please try again." << endl;
resetColor(); // Resetting color
break;
}
} while (true);
}
bool admin::operator!()
{
if (username == NULL)
{
return false;
}
else
return true;
}
admin::~admin()
{
// ye distrcutor ha jo sab ko delete kar rha..to save memeory leakage also
if (username != NULL)
{
delete[] username;
username = NULL;
}
if (passcode != NULL)
{
delete[] passcode;
passcode = NULL;
}
delete[] powers;
delete[] deal;
delete[] stockobject;
delete[] online;
}