Interface > Master #6
@ -54,13 +54,14 @@ int Customer::parked_at() { return park_instances[park_instances.size() - 1].spo
|
|||||||
// functions that interact with the database
|
// functions that interact with the database
|
||||||
|
|
||||||
void Customer::save_db() {
|
void Customer::save_db() {
|
||||||
string statement{"insert into Customer values (, '', '', , );"};
|
string statement{"insert into Customer values (, '', '', ,'');"};
|
||||||
// after ( = 28)
|
// after ( = 28)
|
||||||
statement.insert(40, telephone);
|
statement.insert(41, telephone);
|
||||||
statement.insert(38, to_string(int(vehicle)));
|
statement.insert(38, to_string(int(vehicle)));
|
||||||
statement.insert(36, password);
|
statement.insert(36, password);
|
||||||
statement.insert(32, name);
|
statement.insert(32, name);
|
||||||
statement.insert(29, to_string(id));
|
statement.insert(29, to_string(id));
|
||||||
|
// cout << statement;
|
||||||
SQLite::Transaction transaction(data::db);
|
SQLite::Transaction transaction(data::db);
|
||||||
data::db.exec(statement);
|
data::db.exec(statement);
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
@ -75,8 +76,8 @@ void Customer::update_db() {
|
|||||||
statement.insert(57, to_string(int(vehicle)));
|
statement.insert(57, to_string(int(vehicle)));
|
||||||
statement.insert(43, password);
|
statement.insert(43, password);
|
||||||
statement.insert(28, name);
|
statement.insert(28, name);
|
||||||
cout << statement;
|
// cout << statement;
|
||||||
// data::db.exec(statement);
|
data::db.exec(statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Customer::delete_db() {
|
void Customer::delete_db() {
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
#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
|
||||||
|
// 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) {
|
||||||
int selector;
|
int selector;
|
||||||
@ -11,6 +13,7 @@ void interface(vector<Park_spot>& spots) {
|
|||||||
cout << "\n[1]Log in as member";
|
cout << "\n[1]Log in as member";
|
||||||
cout << "\n[2]Log in as administrator";
|
cout << "\n[2]Log in as administrator";
|
||||||
cin >> selector;
|
cin >> selector;
|
||||||
|
cin.ignore(10000, '\n');
|
||||||
switch (selector) {
|
switch (selector) {
|
||||||
case 1: {
|
case 1: {
|
||||||
interface_member(spots);
|
interface_member(spots);
|
||||||
@ -28,19 +31,20 @@ void interface_member(vector<Park_spot>& spots) {
|
|||||||
string password;
|
string password;
|
||||||
cout << "\nPlease input id:";
|
cout << "\nPlease input id:";
|
||||||
cin >> id;
|
cin >> id;
|
||||||
|
cin.ignore(10000, '\n');
|
||||||
Customer c = query_customer_with_id(id);
|
Customer c = query_customer_with_id(id);
|
||||||
cout << "\nPlease input password:";
|
cout << "\nPlease input password:";
|
||||||
cin >> password;
|
std::getline(cin, password);
|
||||||
|
|
||||||
while (!(verify_password(c.password, password))) {
|
while (!(verify_password(c.password, password))) {
|
||||||
cout << "ERROR: wrong password. Please retype your password \n";
|
cout << "ERROR: wrong password. Please retype your password:\n";
|
||||||
cin >> password;
|
std::getline(cin, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Logged in succesfully\n";
|
cout << "Logged in succesfully\n";
|
||||||
cout << "select an option\n [1] Parking options\n[2]monthy report";
|
cout << "select an option\n [1] Parking options\n[2]monthy report\n";
|
||||||
int option;
|
int option;
|
||||||
cin >> option;
|
cin >> option;
|
||||||
|
cin.ignore(10000, '\n');
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case 1: {
|
case 1: {
|
||||||
park(c, spots);
|
park(c, spots);
|
||||||
@ -64,9 +68,11 @@ void interface_admin(vector<Park_spot>& spots) {
|
|||||||
cout << "[4] See weekly report of a specific parking spot\n";
|
cout << "[4] See weekly report of a specific parking spot\n";
|
||||||
cout << "[5] See current status of parking spots\n";
|
cout << "[5] See current status of parking spots\n";
|
||||||
cout << "[6] Make new customer\n";
|
cout << "[6] Make new customer\n";
|
||||||
cout << "option[1-6]:";
|
cout << "[7] Make new parking spot\n";
|
||||||
|
cout << "option[1-7]:";
|
||||||
int option;
|
int option;
|
||||||
cin >> option;
|
cin >> option;
|
||||||
|
cin.ignore(10000, '\n');
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case 1: {
|
case 1: {
|
||||||
reports_from_allparkspots();
|
reports_from_allparkspots();
|
||||||
@ -80,6 +86,7 @@ void interface_admin(vector<Park_spot>& spots) {
|
|||||||
cout << "Which parking spot would you like a report on?ID:";
|
cout << "Which parking spot would you like a report on?ID:";
|
||||||
int spotid;
|
int spotid;
|
||||||
cin >> spotid;
|
cin >> spotid;
|
||||||
|
cin.ignore(10000, '\n');
|
||||||
reports_from_parkspot(spotid);
|
reports_from_parkspot(spotid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -87,17 +94,21 @@ void interface_admin(vector<Park_spot>& spots) {
|
|||||||
cout << "Which parking spot would you like a report on?ID:";
|
cout << "Which parking spot would you like a report on?ID:";
|
||||||
int spotid;
|
int spotid;
|
||||||
cin >> spotid;
|
cin >> spotid;
|
||||||
|
cin.ignore(10000, '\n');
|
||||||
reports_from_parkspot(spotid, true);
|
reports_from_parkspot(spotid, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 5: {
|
case 5: {
|
||||||
current_status_parkspots(spots);
|
current_status_parkspots(spots);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case 6: {
|
case 6: {
|
||||||
new_customer();
|
new_customer();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case 7: {
|
case 7: {
|
||||||
new_parkspot(spots);
|
new_parkspot(spots);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -121,6 +132,7 @@ void park(Customer& c, vector<Park_spot>& spots) {
|
|||||||
cout << "where do you want to park?";
|
cout << "where do you want to park?";
|
||||||
int parkid;
|
int parkid;
|
||||||
cin >> parkid;
|
cin >> parkid;
|
||||||
|
cin.ignore(10000, '\n');
|
||||||
for (Park_spot& i : spots) {
|
for (Park_spot& i : spots) {
|
||||||
if (i.id == parkid) {
|
if (i.id == parkid) {
|
||||||
i.clock(c);
|
i.clock(c);
|
||||||
@ -133,6 +145,7 @@ void park(Customer& c, vector<Park_spot>& spots) {
|
|||||||
<< ", do you want to clock out?\n enter [1] for yes and [0] for no";
|
<< ", do you want to clock out?\n enter [1] for yes and [0] for no";
|
||||||
int answer = 0;
|
int answer = 0;
|
||||||
cin >> answer;
|
cin >> answer;
|
||||||
|
cin.ignore(10000, '\n');
|
||||||
if (answer) {
|
if (answer) {
|
||||||
query_parkspot_with_id(c.parked_at(), spots).clock(c);
|
query_parkspot_with_id(c.parked_at(), spots).clock(c);
|
||||||
cout << "You have sucessfully clocked out.";
|
cout << "You have sucessfully clocked out.";
|
||||||
@ -148,20 +161,24 @@ void new_customer() {
|
|||||||
string password;
|
string password;
|
||||||
string telephone;
|
string telephone;
|
||||||
cout << "What's the name of the customer? ";
|
cout << "What's the name of the customer? ";
|
||||||
cin >> name;
|
std::getline(cin, name);
|
||||||
cout << "What's the vehicle type? [1]twoweeler, [2] fourweeler: ";
|
cout << "What's the vehicle type? [1]twoweeler, [2] fourweeler: ";
|
||||||
cin >> vtype;
|
cin >> vtype;
|
||||||
|
cin.ignore(10000, '\n');
|
||||||
cout << "What's the telephone number? ";
|
cout << "What's the telephone number? ";
|
||||||
cin >> telephone;
|
std::getline(cin, telephone);
|
||||||
cout << "What's the password? ";
|
cout << "What's the password?";
|
||||||
cin >> password;
|
std::getline(cin, password);
|
||||||
Customer newcustomer{name, password, Vehicle_type(vtype), telephone};
|
Customer newcustomer{name, password, Vehicle_type(vtype), telephone};
|
||||||
cout << "New customer sucessfully created\n";
|
cout << "New customer sucessfully created\n";
|
||||||
|
newcustomer.update_db();
|
||||||
}
|
}
|
||||||
|
|
||||||
void new_parkspot(vector<Park_spot>& spots) {
|
void new_parkspot(vector<Park_spot>& spots) {
|
||||||
cout << "What type of parking spot? [1] twoweeler, [2] fourweeler: ";
|
cout << "What type of parking spot? [1] twoweeler, [2] fourweeler: ";
|
||||||
int vtype;
|
int vtype;
|
||||||
|
cin >> vtype;
|
||||||
|
cin.ignore(10000, '\n');
|
||||||
Park_spot newspot{Vehicle_type(vtype)};
|
Park_spot newspot{Vehicle_type(vtype)};
|
||||||
spots.push_back(newspot);
|
spots.push_back(newspot);
|
||||||
cout << "new parking spot sucessfully created.\n";
|
cout << "new parking spot sucessfully created.\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user