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