cosmetic merge

This commit is contained in:
MassiveAtoms 2019-07-22 10:19:52 -03:00
parent aa52f96beb
commit ef607e7ffc

View File

@ -1,17 +1,18 @@
#include "headers/Interface.h"
#include "headers/Interface.h"
// I added it to pass spots, because the parking options need it to check where
// is free parking_spots is declared in main, and if i declare it
// liberal use of
// cin.ignore(10000, '\n');
// so it skips to the next newline, in essence clearing the cin buffer
// I added it to pass spots, because the parking options need it to check where
// is free parking_spots is declared in main, and if i declare it
// liberal use of
// cin.ignore(10000, '\n');
// so it skips to the next newline, in essence clearing the cin buffer
void interface(vector<Park_spot>& spots) {
void interface(vector<Park_spot>& spots) {
/*
string introduction = "P A R K M A N N E"; //logo animation, disable during testing
text_animation(introduction, 50);
*/
__label__ exit;
system("CLS");
cout << "\nWelcome to the parking system. Please login...";
int id;
string password;
@ -35,14 +36,15 @@ void interface(vector<Park_spot>& spots) {
} else {
cout << "ERROR ROLE_INVALID!";
}
exit:;
}
exit:;
}
void interface_member(vector<Park_spot>& spots, Customer& c) {
void interface_member(vector<Park_spot>& spots, Customer& c) {
__label__ begin, exit;
cout << "\nLogged in succesfully!\n";
begin:
begin:
system("CLS");
cout << "Hello! " << c.name
<< ", please select an option:\n[1]Parking\n[2]Monthly report\n"
"[3]Edit information\n[4]Exit\n";
@ -55,17 +57,21 @@ begin:
break;
}
case 2: {
cout << "Has not been implemented yet\n";
report_customer(c.id);
string lol;
std::cout<<"Enter any character to continue...";
std::cin>>lol;
break;
}
case 3: {
cout << "Has not been implemented yet\n";
edit_information(c);
break;
}
case 4: {
cout << "Exiting...\n";
Sleep(2000);
goto exit;
break;
}
@ -74,12 +80,13 @@ begin:
break;
}
goto begin;
exit:;
}
exit:;
}
void interface_admin(vector<Park_spot>& spots) {
void interface_admin(vector<Park_spot>& spots) {
__label__ begin, exit;
begin:
begin:
system("CLS");
cout << "\nWelcome to the admin interface\n";
cout << "\n[1] Reports & analytics";
cout << "\n[2] Parking spots";
@ -97,6 +104,7 @@ begin:
cout << "[4] See weekly report of a specific parking spot\n";
cout << "[5] See monthly report of a specific customer\n";
cout << "[6] See weekly report of a specific customer\n";
cout << "[7] Return\n";
cout << "Enter option number: ";
int option_1;
cin >> option_1;
@ -126,9 +134,17 @@ begin:
report_customer(0, true);
break;
}
case 7: {
goto begin;
break;
}
default:
break;
}
string lol;
std::cout<<"Enter any character to continue...";
std::cin>>lol;
break;
}
case 2: {
cout << "[1] See current status of parking spots\n";
@ -141,6 +157,9 @@ begin:
switch (option_2) {
case 1: {
current_status_parkspots(spots);
string lol;
std::cout<<"Enter any character to continue...";
std::cin>>lol;
break;
}
case 2: {
@ -154,9 +173,11 @@ begin:
default:
break;
}
break;
}
case 3: {
system("CLS");
cout << "[1] Make new customer\n";
cout << "[2] Make new admin\n";
cout << "[3] Return\n";
@ -181,6 +202,8 @@ begin:
break;
}
case 4: {
std::cout<<"Exiting...";
Sleep(2000);
goto exit;
break;
} break;
@ -190,12 +213,13 @@ begin:
break;
}
goto begin;
exit:;
}
exit:;
// --------- individual things.
}
void park(Customer& c, vector<Park_spot>& spots) {
// --------- individual things.
void park(Customer& c, vector<Park_spot>& spots) {
__label__ exit;
cout << "You have selected parking option.\n";
if (!(c.parked())) {
@ -231,13 +255,13 @@ void park(Customer& c, vector<Park_spot>& spots) {
query_parkspot_with_id(c.parked_at(), spots).clock(c);
cout << "You have sucessfully clocked out.";
} else {
cout << "OK, have a nice day."; // exit to customer login
cout << "OK, have a nice day.";
}
}
exit:;
}
exit:;
}
void new_customer() {
void new_customer() {
int vtype;
string name;
string password;
@ -256,9 +280,9 @@ void new_customer() {
cout << "\nNew customer sucessfully created\n";
if (confirm())
newcustomer.update_db();
}
}
void new_admin() {
void new_admin() {
int vtype = 2; // revision required! Needs to be set to NULL
string name;
string password;
@ -274,10 +298,10 @@ void new_admin() {
cout << "\nNew customer sucessfully created\n";
if (confirm())
newcustomer.update_db();
}
}
void new_parkspot(vector<Park_spot>& spots) {
cout << "What type of parking spot? \n[1] Twowheeler\n[2] Fourwheeler\n";
void new_parkspot(vector<Park_spot>& spots) {
cout << "What type of parking spot? \n[1] Two-wheeler\n[2] Four-wheeler\n";
int vtype;
cin >> vtype;
cin.ignore(10000, '\n');
@ -286,11 +310,38 @@ void new_parkspot(vector<Park_spot>& spots) {
spots.push_back(newspot);
cout << "New parking spot sucessfully created.\n";
}
}
}
// time stuff-----------------------------------------------------
void edit_information(Customer& c)
{
string string0; int int0;
/*std::cout<<"\nInput to update name or press [0] to keep name:\n";
std::getline(cin,string0);
if (string0=="0");
else c.name=string0;*/
pair<int, int> create_month_period() {
std::cout<<"\n Input to update vehicle to [1]Two-Wheeler,"
"[2]Four-Wheeler or press [0] to keep vehicle type:\n";
std::cin>>int0;
if (!int0);
else c.vehicle=Vehicle_type(int0);
cin.ignore();
std::cout<<"\n Input to update password or press [0] to keep current password:\n";
std::getline(cin,string0);
if (string0=="0");
else c.password=hash_password(string0);
std::cout<<"\n Input to update phone number or press [0] to keep current number:\n";
std::getline(cin,string0);
if (string0=="0");
else c.telephone=string0;
c.role=0;
if(confirm()){c.update_db();}
}
// time stuff-----------------------------------------------------
pair<int, int> create_month_period() {
std::time_t t = std::time(0);
std::tm* date = std::localtime(&t);
int month, year = 0;
@ -304,9 +355,9 @@ pair<int, int> create_month_period() {
date->tm_mon = month;
period.second = mktime(date);
return period;
}
}
pair<int, int> create_week_period() {
pair<int, int> create_week_period() {
std::time_t t = std::time(0);
std::tm* date = std::localtime(&t);
int day, month, year = 0;
@ -321,23 +372,31 @@ pair<int, int> create_week_period() {
period.first = mktime(date);
period.second = period.first + 604800; // plus 7 days in seconds.
return period;
}
}
bool confirm(void) {
bool confirm(void) {
string ver;
std::cout << "\nAre you sure you want to commit these actions?"
"\n[No] Revert."
"\n[Yes] Commit.";
std::cin >> ver;
if (ver == "YES" | ver == "Yes" | ver == "yes")
{
std::cout<<"Succes! Changes Saved.";
Sleep(1000);
return true;
}
else
{
std::cout<<"No changes committed.";
Sleep(1000);
return false;
}
}
}
// ------------------------------ report stuff
// ------------------------------ report stuff
void report_all_spots(bool weekly) {
void report_all_spots(bool weekly) {
pair<int, int> period;
if (weekly) {
period = create_week_period(); // remove the pair<int, int>
@ -348,9 +407,9 @@ void report_all_spots(bool weekly) {
cout << "working timeperiods: " << period.first << ", " << period.second; // DEBUG
reports_from_allparkspots(period); // TODO: namechange of reports_from_allparkspots in query?
}
}
void report_single_spot(bool weekly) {
void report_single_spot(bool weekly) {
cout << "Which parking spot would you like a report on?\n";
cout << "Parking spot ID: ";
int spotID;
@ -363,9 +422,9 @@ void report_single_spot(bool weekly) {
period = create_month_period();
}
reports_from_parkspot(spotID, period);
}
}
void report_customer(int customerID, bool weekly) {
void report_customer(int customerID, bool weekly) {
// use report_customer(0) to make interactive
// so admin can call the interactive version, but customer can only call
// report_customer(own_cid)
@ -380,4 +439,4 @@ void report_customer(int customerID, bool weekly) {
period = create_month_period();
}
reports_from_customer(customerID, period);
}
}