forked from jacobjhicks/BuildingClassCIT241
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIImp.cpp
533 lines (489 loc) · 14.2 KB
/
UIImp.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
#include "Ui.h"
#include "Date.h"
#include "Order.h"
#include <iostream>
#include <string>
UI::UI()
{
// invlist.load stocks into inventory
}
UI::~UI()
{
// write stocks from inventory into file
}
void UI::mainMenu()
{
bool continueUi = true;
do
{
int option;
string customername, customeremail, customerID;
bool emailCheck,remCustomerCheck;
CustomerType *tempCustomer;
bool verifyInput = false;
cout << string(3, '\n');
do
{
if (verifyInput)
{
// This locks up if cin has never been used. Skip on first iteration
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
cout << "Main Menu \n\n1) Add customer \n2) Remove coustomer \n3) Find customer" <<
"\n4) List customer information \n5) Order menu \n6) Inventory menu \n7) Exit" << endl;
cin >> option;
// Set to verify cin after first read
verifyInput = true;
if (!cin)
{
cout << endl;
cout << "Invalid option entered. Please try again." << endl;
cout << endl;
}
} while (!cin);
switch (option)
{
case 1: // add customer
do
{
// Need to get potential new customerID
cout << "Enter Customer ID: ";
cin >> customerID;
// after reading in customerID - see if it already exists
if (totalCustomers.findCustomer(customerID))
{
// if it already exists, warn user and go back to customer menu
cout << endl << "Custeromer ID already exists.\nPlease Re-";
}
} while (totalCustomers.findCustomer(customerID));
// collect rest of customer information
cout << "Enter customer name: ";
// names are notorious for having spaces in them - must use getline
cin.ignore();
getline(cin, customername);
do
{
// Need to get potential new customeremail
cout << "Enter customer email: ";
cin.clear();
cin >> customeremail;
// After reading in customeremail - check if it is valid
// Establish a general email pattern
// regex emailMatch("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$");
// Check the input for the regex pattern
// if (regex_match(customeremail, emailMatch))
int i = customeremail.find('@', 1);
if (//customeremail.find('@', 1) == true && // this line produced a Warning
customeremail.find('@', 1) != string::npos && // If no matches were found, the function returns string::npos.
customeremail.find('.', i + 1) != string::npos &&
customeremail.back() != '.') //Making sure there is an "@" and a "." afterwards. Characters must follow.
{
emailCheck = false;
}
else
{
cout << "ERROR: Incorrect email address entered. \nPlease Re-";
emailCheck = true;
}
} while (emailCheck);
// build customer and add to customer
// customerlist.addCustomer(Customer(----,-----,-----));
tempCustomer = new CustomerType(customerID, customername, customeremail);
totalCustomers.addCustomer(*tempCustomer);
break;
case 2: // remove customer
// you may want to display list of customerIDs so user can choose one
cout << "Current customers:" << endl;
cout << totalCustomers << endl;
do
{
cout << "Enter customer ID you want to delete: ";
cin >> customerID;
if (totalCustomers.findCustomer(customerID)) {
remCustomerCheck = false;
totalCustomers.removeCustomer(totalCustomers.getCustomer(customerID));
}
else
{
cout << "ERROR: Invalid customer ID entered. \nPlease Re-";
remCustomerCheck = true;
}
} while (remCustomerCheck);
// find customer object in customerlist returning iterator pointing to the customer object
// if found
// use customer list remove method passing iterator
// else
// message to user not found
break;
case 3: // find customer returning iterator pointing to the customer
// you may want to display list of customerIDs so user can choose one
cout << "enter customer ID" << endl;
cin >> customerID;
// CustomerType& cust = custlist.getcustomer(customerID)
break;
case 4: // list customer information
cout << "Current customers:" << endl;
cout << totalCustomers << endl;
break;
case 5: //order menu
orderMenu();
break;
case 6: //inv menu
invMenu();
break;
case 7: //exit
continueUi = false;
break;
default:
cout << "Invalid option try again";
break;
}
} while (continueUi);
}
void UI::orderMenu()
{
int option;
string custID;
bool notValidCustomer;
Order *tempOrder;
bool stayInMenu = true;
do
{
do
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Order Menu" <<
"\n1) List Orders for Customer \n2) Over all orders for all customers \n3) Add order to customer" <<
"\n4) Cancel order for a customer \n5) Update order for a customer \n6) Go Back \n";
cin >> option;
if (!cin)
{
cout << endl;
cout << "Invalid option entered. Please try again." << endl;
cout << endl;
}
} while (!cin);
switch (option)
{
case 1: // list orders for a customer
cout << "Current customers:" << endl;
cout << totalCustomers << endl;//customerListprint;
do
{
cout << "Enter customer ID: ";
cin >> custID;
if (totalCustomers.findCustomer(custID)) { // iterator = find customer
notValidCustomer = false;
cout << totalCustomers.getOrders(totalCustomers.getCustomer(custID)) << endl;
}
else {
notValidCustomer = true;
cout << "ERROR: Invalid customer ID entered. \nPlease Re-";
}
} while (notValidCustomer);
break;
case 2: // list all orders for all customers
// use for range loop to retrieve each customer
for (CustomerType customer : totalCustomers)
{
// for current customer invoke printOrders() method
cout << customer.printOrders();
}
break;
case 3: // add an order for a customer
//customerListprint;
cout << "Current customers:" << endl;
cout << totalCustomers << endl;
do
{
cout << "Enter customer ID: ";
cin >> custID;
if (totalCustomers.findCustomer(custID)) { // iterator = find customer
notValidCustomer = false;
tempOrder = new Order();
addOrderData(*tempOrder);
totalCustomers.addOrder(totalCustomers.getCustomer(custID), *tempOrder);// - Get oder to pass in
}
else {
notValidCustomer = true;
cout << "ERROR: Invalid customer ID entered. \nPlease Re-";
}
} while (notValidCustomer);
break;
case 4: // cancel order
//customerListprint;
cout << "Current customers:" << endl;
cout << totalCustomers << endl;
do
{
cout << "Enter customer ID: ";
cin >> custID;
if (totalCustomers.findCustomer(custID)) { // iterator = find customer
notValidCustomer = false;
CustomerType customer = totalCustomers.getCustomer(custID);
cout << "Orders for customer " << customer.getId() << " : "<< customer.getName() << endl;
cout << customer.printOrders() << endl;
bool invalidOrder = true;
string orderID;
do
{
cout << "Enter order number to cancel: ";
cin >> orderID;
if (customer.findOrder(orderID))
{
invalidOrder = false;
customer.removeOrder(orderID);
cout << "Order " << orderID << " removed from customers order list." << endl;
}
else
{
invalidOrder = true;
cout << "ERROR: Invalid order ID entered." << endl;
cout << "Please Re-";
}
} while (invalidOrder);
}
else {
notValidCustomer = true;
cout << "ERROR: Invalid customer ID entered. \nPlease Re-";
}
} while (notValidCustomer);
break;
case 5: // update order
// updateOrderMenu()
break;
case 6:
stayInMenu = false;
break;
default:
cout << "Invalid Option \"" << option << "\"" << endl;
break;
}
} while (stayInMenu);
}
void UI::invMenu()
{
int option, custID;
bool stayInMenu = true;
do
{
do
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << endl << "Inventory Menu" << endl;
cout << "1) List all items in inventory" << endl;
cout << "2) Display an item in inventory" << endl;
cout << "3) Process order from supplier" << endl;
cout << "4) Generate orders to the suppliers for a given month" << endl;
cout << "5) Find the high demand items for a period of time - month, qtr, yr" << endl;
cout << "6) Exit" << endl;
cin >> option;
if (!cin)
{
cout << endl;
cout << "Invalid option entered. Please try again." << endl;
cout << endl;
}
} while (!cin);
switch (option)
{
case 1: // list all items in inventory
{
// totalInventory.print();
break;
}
case 2: // display an item in inventory
{
bool invalidItem;
string itemID;
do
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
// ask user for itemid
cout << "Enter the id of the item you would to display: ";
cin >> itemID;
if (totalInventory.itemExists(itemID))
{
invalidItem = false;
Stock& itemStock = totalInventory.findItem(itemID);
// cout << itemStock << endl; // Can't print item information yet.
}
else
{
invalidItem = true;
cout << "ERROR: Invalid item ID entered." << endl;
cout << "Please Re-";
}
} while (!invalidItem);
break;
}
case 3: //process an order from a supplier
{
bool cancelOpenFile = false;
ofstream orderFile;
do
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
string fileName;
// prompt user for filename of order from a supplier
cout << "Enter the name of the order file (or EXIT to go back): ";
cin >> fileName;
stringstream exitCheck;
for (char c : fileName)
exitCheck << toupper(c);
// Exit open file
if (exitCheck.str() == "EXIT")
{
cancelOpenFile = true;
break;
}
// establish an input file using filename from user
orderFile.open(fileName); // or maybe have a directory for it: orderFile.open($ordersDirectoryNameVariable + "\\" + fileName );
// check if file was unable to open
if (orderFile.fail())
{
cout << "File not found. Please Re-";
}
} while (orderFile.fail());
// if user wants to EXIT...
if (cancelOpenFile)
{
orderFile.close();
break;
}
/* FILE ASSUMPTIONS
[customer id]
[order id]
[item id] [quantitiy]
[item id] [quantitiy]
...
*/
// while more records
// read new item information - itemid, qty
// Stock& stk = invlist.findItem(itemid)
// if stk not emptystock
// stk.incrementQuantity(qty)
// else
// error message
// endif
// end while
// close file
orderFile.close();
break;
}
case 4: // Generate orders to the suppliers for a given month
{
// get month and year for order header
// vector<SupplierItem> supplist;
// for each stock in invlist
// if stock.getInStock() < stock.getReorderPoint()
// supplist.push_back(SupplierItem(stock.getSupplierID(),
// stock.getID(), stock.reorderAmount())
// endif
// next
// supplist.sort
// generate report with breaks at supplierID change
break;
}
case 5: //Find the high demand items for a period of time - month, qtr, yr
{
// vector<pair<string, int>> usage;
// get startdate and enddate
// for each cust in custlist
// for each ord in cust.ordlist
// verify that orderdate is between startdate and enddate
// if so,
// for each orditem in orditemlist
// string itdata = orditem.getItemID()
// auto& itemiter = find(usage.begin(), usage.end(),
// [itdata](pair<string, int> listel)
// {return (listel.first() == itdata); }
// if itemiter != usage.end()
// itemiter->second += orditem.getQuant();
// else
// usage.push_back(make_pair(orditem.getItemID(), orditem.getQuant())
// endif
// next
// endif
// next
// next
break;
}
case 6:
{
stayInMenu = false;
break;
}
default:
{
cout << "Invalid Option \"" << option << "\"" << endl;
break;
}
}
} while (stayInMenu);
}
void UI::addOrderData(Order &newOrder)
{
string ordId, ordDateString, delDateString, itemID, option;
Date ordDate,delDate;
int quantity;
bool moreItems = true;
orderItem *tempItem;
cout << "\nEnter Order Id: ";
// Validate Order ID here ???
// It would not hurt to...
cin >> ordId;
cout << "\nEnter Order Date Ex: 1/1/1990: ";
cin >> ordDateString;
ordDate = { ordDateString };
cout << "\nEnter Delivery Date Ex: 1/1/1990: ";
cin >> delDateString;
delDate = { delDateString };
Order tempOrder(ordId, ordDate, delDate);
do
{
cout << "\nEnter Item Id: ";
cin >> itemID;
cout << "\nEnter quantity: ";
cin >> quantity;
tempItem = new orderItem(itemID, quantity);
tempOrder.addOrderItem(*tempItem);
cout << "\nEnter 'Finish' to finish adding items otherwise any charter to continue entering items: ";
cin >> option;
std::transform(option.begin(), option.end(), option.begin(), ::toupper);
if (option == "FINISH")
moreItems = false;
} while (moreItems);
newOrder = tempOrder;
}
//void UI::custMenu(int ID)
//{
// string itemID, qnty;
// Listinvertory;
// cin >> itemID
// if ()
// {
//
// }
//}
// addOrderData routine
//void UI::addOrderData(CustomerType& cust)
// collect orderid, orderdate, deliverydate
// create order object
// while more orderitems
// collect orderitem data - itemid, quantity
// orderitem reference = ord.findOrderItem(itemid)
// if orderitem refence != emptyorderitem,
// orderitem reference.incrementQuantity(quantity)
// else
// orderitem neworditem = invlist.checkIfInStock(itemid, quantity)
// ord.addOrderItem(neworderitem)
// endif
// ask if more orderitems
// end while when no more order items
// cust.addOrder(order object)