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 414 additions and 396 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_,
vector<Park_time> instances, string telephone_)
vector<Park_time> instances, string telephone_, int role_)
: id{id_},
name{name_},
password{password_},
vehicle{vehicle_},
park_instances{instances},
telephone{telephone_} {}
telephone{telephone_},
role{role_} {}
// 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
// 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);
@ -36,14 +36,14 @@ 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"
@ -57,8 +57,8 @@ begin:
break;
}
case 2: {
string lol;
report_customer(c.id);
string lol;
std::cout<<"Enter any character to continue...";
std::cin>>lol;
break;
@ -80,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";
@ -103,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;
@ -132,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";
@ -147,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: {
@ -160,6 +173,7 @@ begin:
default:
break;
}
break;
}
case 3: {
@ -199,13 +213,13 @@ begin:
break;
}
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;
cout << "You have selected parking option.\n";
if (!(c.parked())) {
@ -244,10 +258,10 @@ void park(Customer& c, vector<Park_spot>& spots) {
cout << "OK, have a nice day.";
}
}
exit:;
}
exit:;
}
void new_customer() {
void new_customer() {
int vtype;
string name;
string password;
@ -263,12 +277,12 @@ void new_customer() {
cout << "\nWhat's the password? ";
std::getline(cin, password);
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())
newcustomer.update_db();
}
}
void new_admin() {
void new_admin() {
int vtype = 2; // revision required! Needs to be set to NULL
string name;
string password;
@ -280,13 +294,13 @@ void new_admin() {
std::getline(cin, telephone);
cout << "\nWhat's the password?";
std::getline(cin, password);
Customer newcustomer{name, password, Vehicle_type(vtype), telephone, role};
cout << "\nNew customer sucessfully created\n";
Customer newadmin{name, password, Vehicle_type(vtype), telephone, role};
cout << "\nNew customer sucessfully created with ID=" << newadmin.id << "\n";
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";
int vtype;
cin >> vtype;
@ -296,10 +310,10 @@ void new_parkspot(vector<Park_spot>& spots) {
spots.push_back(newspot);
cout << "New parking spot sucessfully created.\n";
}
}
}
void edit_information(Customer& c)
{
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);
@ -323,11 +337,11 @@ void edit_information(Customer& c)
else c.telephone=string0;
c.role=0;
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::tm* date = std::localtime(&t);
int month, year = 0;
@ -341,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;
@ -358,9 +372,9 @@ 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."
@ -378,11 +392,11 @@ bool confirm(void) {
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>
@ -393,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;
@ -408,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)
@ -425,4 +439,4 @@ void report_customer(int customerID, bool weekly) {
period = create_month_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);
int vehicle = query.getColumn(3); // cast to vehicle
string telephone = query.getColumn(4);
int role = query.getColumn(5);
vector<Park_time> park_instances = query_parktimes_for_customer(id);
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;
}
@ -63,8 +64,10 @@ Customer query_customer_with_id(int id) {
string password = query.getColumn(2);
int vehicle = query.getColumn(3); // cast to vehicle
string telephone = query.getColumn(4);
int role = query.getColumn(5);
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;
}
}

View File

@ -41,9 +41,9 @@ class Customer {
Vehicle_type vehicle;
string telephone;
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_,
vector<Park_time> instances, string telephone_);
vector<Park_time> instances, string telephone_, int role_);
void clock_in(int s_id);
void clock_out(int s_id);
bool parked();

BIN
test.db3

Binary file not shown.