3 Commits

Author SHA1 Message Date
ec089c66e7 id fix 2019-07-22 10:28:44 -03:00
ef607e7ffc cosmetic merge 2019-07-22 10:19:52 -03:00
aa52f96beb fixed customer role 2019-07-22 10:16:07 -03:00
5 changed files with 405 additions and 401 deletions

View File

@ -13,13 +13,14 @@ Customer::Customer(string name_, string password_, Vehicle_type vehicle_, string
} }
Customer::Customer(int id_, string name_, string password_, Vehicle_type vehicle_, Customer::Customer(int id_, string name_, string password_, Vehicle_type vehicle_,
vector<Park_time> instances, string telephone_) vector<Park_time> instances, string telephone_, int role_)
: id{id_}, : id{id_},
name{name_}, name{name_},
password{password_}, password{password_},
vehicle{vehicle_}, vehicle{vehicle_},
park_instances{instances}, park_instances{instances},
telephone{telephone_} {} telephone{telephone_},
role{role_} {}
// clock in/out methods // clock in/out methods
// ==================================================================================== // ====================================================================================

View File

@ -1,12 +1,12 @@
#include "headers/Interface.h" #include "headers/Interface.h"
// I added it to pass spots, because the parking options need it to check where // 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 // is free parking_spots is declared in main, and if i declare it
// liberal use of // liberal use of
// cin.ignore(10000, '\n'); // cin.ignore(10000, '\n');
// so it skips to the next newline, in essence clearing the cin buffer // 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 string introduction = "P A R K M A N N E"; //logo animation, disable during testing
text_animation(introduction, 50); text_animation(introduction, 50);
@ -36,14 +36,14 @@ void interface(vector<Park_spot>& spots) {
} else { } else {
cout << "ERROR ROLE_INVALID!"; 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; __label__ begin, exit;
cout << "\nLogged in succesfully!\n"; cout << "\nLogged in succesfully!\n";
begin: begin:
system("CLS"); system("CLS");
cout << "Hello! " << c.name cout << "Hello! " << c.name
<< ", please select an option:\n[1]Parking\n[2]Monthly report\n" << ", please select an option:\n[1]Parking\n[2]Monthly report\n"
@ -80,12 +80,12 @@ begin:
break; break;
} }
goto begin; goto begin;
exit:; exit:;
} }
void interface_admin(vector<Park_spot>& spots) { void interface_admin(vector<Park_spot>& spots) {
__label__ begin, exit; __label__ begin, exit;
begin: begin:
system("CLS"); system("CLS");
cout << "\nWelcome to the admin interface\n"; cout << "\nWelcome to the admin interface\n";
cout << "\n[1] Reports & analytics"; cout << "\n[1] Reports & analytics";
@ -213,13 +213,13 @@ begin:
break; break;
} }
goto begin; goto begin;
exit:; exit:;
} }
// --------- individual things. // --------- individual things.
void park(Customer& c, vector<Park_spot>& spots) { void park(Customer& c, vector<Park_spot>& spots) {
__label__ exit; __label__ exit;
cout << "You have selected parking option.\n"; cout << "You have selected parking option.\n";
if (!(c.parked())) { if (!(c.parked())) {
@ -258,10 +258,10 @@ void park(Customer& c, vector<Park_spot>& spots) {
cout << "OK, have a nice day."; cout << "OK, have a nice day.";
} }
} }
exit:; exit:;
} }
void new_customer() { void new_customer() {
int vtype; int vtype;
string name; string name;
string password; string password;
@ -277,12 +277,12 @@ void new_customer() {
cout << "\nWhat's the password? "; cout << "\nWhat's the password? ";
std::getline(cin, password); std::getline(cin, password);
Customer newcustomer{name, password, Vehicle_type(vtype), telephone, role}; Customer newcustomer{name, password, Vehicle_type(vtype), telephone, role};
cout << "\nNew customer sucessfully created\n"; cout << "\nNew customer sucessfully created with ID:" << newcustomer.id << "\n";
if (confirm()) if (confirm())
newcustomer.update_db(); newcustomer.update_db();
} }
void new_admin() { void new_admin() {
int vtype = 2; // revision required! Needs to be set to NULL int vtype = 2; // revision required! Needs to be set to NULL
string name; string name;
string password; string password;
@ -294,13 +294,13 @@ void new_admin() {
std::getline(cin, telephone); std::getline(cin, telephone);
cout << "\nWhat's the password?"; cout << "\nWhat's the password?";
std::getline(cin, password); std::getline(cin, password);
Customer newcustomer{name, password, Vehicle_type(vtype), telephone, role}; Customer newadmin{name, password, Vehicle_type(vtype), telephone, role};
cout << "\nNew customer sucessfully created\n"; cout << "\nNew customer sucessfully created with ID=" << newadmin.id << "\n";
if (confirm()) if (confirm())
newcustomer.update_db(); newadmin.update_db();
} }
void new_parkspot(vector<Park_spot>& spots) { void new_parkspot(vector<Park_spot>& spots) {
cout << "What type of parking spot? \n[1] Two-wheeler\n[2] Four-wheeler\n"; cout << "What type of parking spot? \n[1] Two-wheeler\n[2] Four-wheeler\n";
int vtype; int vtype;
cin >> vtype; cin >> vtype;
@ -310,10 +310,10 @@ void new_parkspot(vector<Park_spot>& spots) {
spots.push_back(newspot); spots.push_back(newspot);
cout << "New parking spot sucessfully created.\n"; cout << "New parking spot sucessfully created.\n";
} }
} }
void edit_information(Customer& c) void edit_information(Customer& c)
{ {
string string0; int int0; string string0; int int0;
/*std::cout<<"\nInput to update name or press [0] to keep name:\n"; /*std::cout<<"\nInput to update name or press [0] to keep name:\n";
std::getline(cin,string0); std::getline(cin,string0);
@ -337,11 +337,11 @@ void edit_information(Customer& c)
else c.telephone=string0; else c.telephone=string0;
c.role=0; c.role=0;
if(confirm()){c.update_db();} if(confirm()){c.update_db();}
} }
// time stuff----------------------------------------------------- // time stuff-----------------------------------------------------
pair<int, int> create_month_period() { pair<int, int> create_month_period() {
std::time_t t = std::time(0); std::time_t t = std::time(0);
std::tm* date = std::localtime(&t); std::tm* date = std::localtime(&t);
int month, year = 0; int month, year = 0;
@ -355,9 +355,9 @@ pair<int, int> create_month_period() {
date->tm_mon = month; date->tm_mon = month;
period.second = mktime(date); period.second = mktime(date);
return period; return period;
} }
pair<int, int> create_week_period() { pair<int, int> create_week_period() {
std::time_t t = std::time(0); std::time_t t = std::time(0);
std::tm* date = std::localtime(&t); std::tm* date = std::localtime(&t);
int day, month, year = 0; int day, month, year = 0;
@ -372,9 +372,9 @@ pair<int, int> create_week_period() {
period.first = mktime(date); period.first = mktime(date);
period.second = period.first + 604800; // plus 7 days in seconds. period.second = period.first + 604800; // plus 7 days in seconds.
return period; return period;
} }
bool confirm(void) { bool confirm(void) {
string ver; string ver;
std::cout << "\nAre you sure you want to commit these actions?" std::cout << "\nAre you sure you want to commit these actions?"
"\n[No] Revert." "\n[No] Revert."
@ -392,11 +392,11 @@ bool confirm(void) {
Sleep(1000); Sleep(1000);
return false; return false;
} }
} }
// ------------------------------ report stuff // ------------------------------ report stuff
void report_all_spots(bool weekly) { void report_all_spots(bool weekly) {
pair<int, int> period; pair<int, int> period;
if (weekly) { if (weekly) {
period = create_week_period(); // remove the pair<int, int> period = create_week_period(); // remove the pair<int, int>
@ -407,9 +407,9 @@ void report_all_spots(bool weekly) {
cout << "working timeperiods: " << period.first << ", " << period.second; // DEBUG cout << "working timeperiods: " << period.first << ", " << period.second; // DEBUG
reports_from_allparkspots(period); // TODO: namechange of reports_from_allparkspots in query? 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 << "Which parking spot would you like a report on?\n";
cout << "Parking spot ID: "; cout << "Parking spot ID: ";
int spotID; int spotID;
@ -422,9 +422,9 @@ void report_single_spot(bool weekly) {
period = create_month_period(); period = create_month_period();
} }
reports_from_parkspot(spotID, 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 // use report_customer(0) to make interactive
// so admin can call the interactive version, but customer can only call // so admin can call the interactive version, but customer can only call
// report_customer(own_cid) // report_customer(own_cid)
@ -439,4 +439,4 @@ void report_customer(int customerID, bool weekly) {
period = create_month_period(); period = create_month_period();
} }
reports_from_customer(customerID, period); reports_from_customer(customerID, period);
} }

View File

@ -41,9 +41,10 @@ vector<Customer> query_customer_with_name(string name) {
string password = query.getColumn(2); string password = query.getColumn(2);
int vehicle = query.getColumn(3); // cast to vehicle int vehicle = query.getColumn(3); // cast to vehicle
string telephone = query.getColumn(4); string telephone = query.getColumn(4);
int role = query.getColumn(5);
vector<Park_time> park_instances = query_parktimes_for_customer(id); vector<Park_time> park_instances = query_parktimes_for_customer(id);
result.push_back( result.push_back(
Customer{id, name_, password, Vehicle_type(vehicle), park_instances, telephone}); Customer{id, name_, password, Vehicle_type(vehicle), park_instances, telephone, role});
} }
return result; return result;
} }
@ -63,8 +64,10 @@ Customer query_customer_with_id(int id) {
string password = query.getColumn(2); string password = query.getColumn(2);
int vehicle = query.getColumn(3); // cast to vehicle int vehicle = query.getColumn(3); // cast to vehicle
string telephone = query.getColumn(4); string telephone = query.getColumn(4);
int role = query.getColumn(5);
vector<Park_time> park_instances = query_parktimes_for_customer(id); vector<Park_time> park_instances = query_parktimes_for_customer(id);
Customer result{id, name, password, Vehicle_type(vehicle), park_instances, telephone}; Customer result{id, name, password, Vehicle_type(vehicle), park_instances, telephone, role};
return result; return result;
} }
} }

View File

@ -41,9 +41,9 @@ class Customer {
Vehicle_type vehicle; Vehicle_type vehicle;
string telephone; string telephone;
int role; int role;
Customer(string name_, string password_, Vehicle_type vehicle_, string telephone_, int role); Customer(string name_, string password_, Vehicle_type vehicle_, string telephone_, int role_);
Customer(int id_, string name_, string password_, Vehicle_type vehicle_, Customer(int id_, string name_, string password_, Vehicle_type vehicle_,
vector<Park_time> instances, string telephone_); vector<Park_time> instances, string telephone_, int role_);
void clock_in(int s_id); void clock_in(int s_id);
void clock_out(int s_id); void clock_out(int s_id);
bool parked(); bool parked();

BIN
test.db3

Binary file not shown.