-
Notifications
You must be signed in to change notification settings - Fork 0
/
staff.cpp
310 lines (301 loc) · 10.1 KB
/
staff.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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#include "staff.h"
extern Library lib;
extern Log rec;
extern string account;
extern int user_index;
void Staff::AddBook() // Add new books
{
system("cls");
Book newbook;
int category;
string money, number, price, name, isbn, author, discount, disc_num, information;
cout << "Please input the ISBN number of the book" << endl;
cin.ignore();
getline(cin, isbn); // Input ISBN number of this new book
if (lib.findBook(isbn) >= 0)
{
cout << "This ISBN number already exist!" << endl; // ISBN number already exist
Sleep(1000);
return;
}
cout << "Please input the name of the book:" << endl;
getline(cin, name); // Input bookname
cout << "Please input the author of the book:" << endl;
getline(cin, author); // Input author
cout << "Please input the copy number of the book:" << endl;
while (1) {
cin >> number; // Input copy number
if (IsAllDigit(number)) break;
cout << "Pleass input a digital number :) Try again." << endl;
}
cout << "Category List:" << endl;
cout << "1. Art" << endl;
cout << "2. Engineering" << endl;
cout << "3. Science" << endl;
cout << "Please input the number of the category of the book:" << endl;
while (1)
{
cin >> category; // Input category number
if (category == 1 || category == 2 || category == 3) break;
cout << "Pleass input a number between 1 and 3!" << endl;
}
cout << "Please input the price of the book:" << endl;
while (1) {
cin >> price; // Input price
if (IsAllDigit(price)) break;
cout << "Pleass input a digital number :) Try again." << endl;
}
cout << "Please input some information of this book:" << endl;
cin.ignore();
getline(cin, information); // Input detail information
cout << "Please input the cost of these books:" << endl;
while (1)
{
cin >> money; // Input the cost of those book
if (IsAllDigit(money)) break;
cout << "Pleass input a digital number :) Try again." << endl;
}
newbook.SetName(name);
newbook.SetIsbn(isbn);
newbook.SetAuthor(author);
newbook.SetNumber(stoi(number));
newbook.SetCategory(category);
newbook.SetPrice(stod(price));
newbook.SetInformation(information);
newbook.SetNumberOfSale(0);
lib.BookArray.push_back(newbook); // Add this newbook to lib.BookArray
cout << "Add book succsessfully!" << endl;
Sleep(1000);
cout << "Automatic quit in 2 seconds." << endl;
Sleep(2000);
rec.BookLog(account, isbn, "add", stoi(number)); // Update BookLog.txt with "add" operation
rec.CashLog(account, isbn, "add", stod(money)); // Update CashLog.txt with "add" operation
PrintBookArray(); // Output book information to Book.txt
PrintCash(); // Output cash information to Cash.txt
}
void Staff::DelBook() // Delete some books
{
system("cls");
string isbn, temp;
int bookPos; // book position in the library's BookArray
cout << "Please input the ISBN number of the book that you want to delete " << endl;
cin.ignore();
getline(cin, isbn); // Input ISBN number of the book that you want to delete
bookPos = lib.findBook(isbn);
if (bookPos >= 0)
{
cout << "There are " << lib.BookArray[bookPos].GetNumber() << " copies of this book, how many do you want to delete? " << endl;
while (1)
{
cin >> temp; // Input how many books you want to delete
if (IsAllDigit(temp)) break;
cout << "Pleass input a digital number :) Try again." << endl;
}
if (stoi(temp) > lib.BookArray[bookPos].GetNumber()) // Book number is not enough to delete
{
cout << "Book number is not that much! " << endl;
Sleep(1000);
cout << "Automatic quit after 3 seconds." << endl;
Sleep(3000);
}
else
{
lib.BookArray[bookPos].SetNumber(lib.BookArray[bookPos].GetNumber() - stoi(temp)); // Change number of this book in lib.BookArray
cout << "Delete (" << stoi(temp) << ") of this book succsessfully!~ " << endl;
Sleep(1000);
cout << "Automatic quit after 3 seconds." << endl;
Sleep(2000);
rec.BookLog(account, isbn, "del", stoi(temp)); // Update BookLog.txt with "del" operation
PrintBookArray(); // Output book information to Book.txt
}
return;
}
else
cout << "Not found this book! " << endl; // Book not exist in Book.txt
Sleep(1000);
}
void Staff::SetBook() // Change books' information
{
system("cls");
int choice;
int category;
string number, price, name, isbn, author, discount, disc_num, information;
cout << "Please input the ISBN number of the book that you want to change the information." << endl;
cin.ignore();
getline(cin, isbn); // Input ISBN number of the book that you want to change information
int bookPos = lib.findBook(isbn);
if (bookPos >= 0)
{
cout << "The book's current name is: " << lib.BookArray[bookPos].GetName() << endl;
cout << "Do you want to change it? (input 1 for YES and 0 for NO )" << endl;
cin >> choice;
if (choice == 1)
{
cout << "Please input the new name of the book" << endl;
cin.ignore();
getline(cin, name); // Input new bookname
lib.BookArray[bookPos].SetName(name);
}
cout << "The book's current ISBN number is: " << lib.BookArray[bookPos].GetIsbn() << endl;
cout << "Do you want to change it? (input 1 for YES and 0 for NO )" << endl;
cin >> choice;
if (choice == 1)
{
cout << "Please input the new ISBN number of the book" << endl;
cin.ignore();
getline(cin, isbn); // Input new ISBN number
lib.BookArray[bookPos].SetIsbn(isbn);
}
cout << "The book's current author is: " << lib.BookArray[bookPos].GetAuthor() << endl;
cout << "Do you want to change it? (input 1 for YES and 0 for NO )" << endl;
cin >> choice;
if (choice == 1)
{
cout << "Please input the new author of the book" << endl;
cin.ignore();
getline(cin, author); // Input new author
lib.BookArray[bookPos].SetAuthor(author);
}
cout << "The book's current quantity is: " << lib.BookArray[bookPos].GetNumber() << endl;
cout << "Do you want to change it? (input 1 for YES and 0 for NO )" << endl;
cin >> choice;
if (choice == 1) {
cout << "Please input the new copy number of the book" << endl;
while (1) {
cin >> number;
if (IsAllDigit(number)) break;
cout << "Pleass input a digital number :) Try again." << endl;
}
lib.BookArray[bookPos].SetNumber(stoi(number));
}
cout << "The book's current category is: " << lib.BookArray[bookPos].GetCategoryName() << endl;
cout << "Do you want to change it? (input 1 for YES and 0 for NO )" << endl;
cin >> choice;
if (choice == 1)
{
cout << "Category List:" << endl;
cout << "1. Art" << endl;
cout << "2. Engineering" << endl;
cout << "3. Science" << endl;
cout << "Please input the number of the category of the book:" << endl;
while (1)
{
cin >> category; // Input category number
if (category == 1 || category == 2 || category == 3) break;
cout << "Pleass input a number between 1 and 3!" << endl;
}
lib.BookArray[bookPos].SetCategory(category);
}
cout << "The book's current price is: " << lib.BookArray[bookPos].GetPrice() << endl;
cout << "Do you want to change it? (input 1 for YES and 0 for NO )" << endl;
cin >> choice;
if (choice == 1)
{
cout << "Please input the new price of the book" << endl;
while (1)
{
cin >> price; // Input new price
if (IsAllDigit(price)) break;
cout << "Pleass input a digital number :) Try again." << endl;
}
lib.BookArray[bookPos].SetPrice(stod(price));
}
cout << "The book's current quantity is: " << lib.BookArray[bookPos].GetInformation() << endl;
cout << "Do you want to change it? (input 1 for YES and 0 for NO )" << endl;
cin >> choice;
if (choice == 1)
{
cout << "Please input the new information of the book" << endl;
cin.ignore();
getline(cin, information); // Input new detail information
lib.BookArray[bookPos].SetInformation(information);
}
cout << "Change book information succsessfully!~ " << endl;
Sleep(1000);
cout << "Automatic quit after 3 seconds." << endl;
Sleep(2000);
rec.BookLog(account, isbn, "set", 0); // Update BookLog.txt with "set" operation
PrintBookArray(); // Output book information to Book.txt
return;
}
else
cout << "Not found this book! " << endl; // Book not exist in Book.txt
Sleep(1000);
}
void Staff::ViewProfit() // Lookup net profit
{
system("cls");
string temp;
cout << "Total income: " << lib.GetIncome() << endl;
cout << "Total outcome: " << lib.GetOutcome() << endl;
cout << "Total net profit: " << lib.GetIncome() - lib.GetOutcome() << endl;
cout << "Input 0 to exit" << endl;
cin >> temp;
while (temp != "0")
cin >> temp;
return;
}
void Staff::Interface() // Staff interface
{
LoadUser();
char command;
int stop = 0;
string str;
while (1) {
system("cls");
cout << "Welcome " << lib.UserArray[user_index].GetUsername() << "! You are in the staff mode" << endl;
cout << "Please choose what you want to do by input a number " << endl;
while (1) { // The operation list
cout << "1 ----- Add new book" << endl;
cout << "2 ----- Delete book" << endl;
cout << "3 ----- Change book information" << endl;
cout << "4 ----- List book (ALL)" << endl;
cout << "5 ----- List book (By Category)" << endl;
cout << "6 ----- List book (By Name)" << endl;
cout << "7 ----- Show more book information by ISBN number" << endl;
cout << "8 ----- Lookup net profit" << endl;
cout << "9 ----- Change my password" << endl;
cout << "0 ----- Exit;" << endl;
cin >> command;
if (command < '0' || command > '9') { // If command doesn't match input rule
cout << endl << "Please input number between 0 and 9!" << endl;
} else break;
}
switch (command)
{
case '1':
AddBook(); // Add new books
break;
case '2':
DelBook(); // Delete some books
break;
case '3':
SetBook(); // Change books' information
break;
case '4':
ListBookAll(); // List all book
break;
case '5':
ListBookByC(); // List book by category
break;
case '6':
ListBookByN(); // List book by name
break;
case '7':
BookInfor(); // See more information of one book
break;
case '8':
ViewProfit(); // Lookup profit
break;
case '9':
ChangePsw(); // Change password
break;
case '0':
stop = 1;
cout << "System will quit after 3 seconds " <<endl;
Sleep(3000);
break;
}
if (stop) break;
}
}