Interface > Master #6
@@ -1,5 +1,6 @@
 | 
			
		||||
#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
 | 
			
		||||
 | 
			
		||||
@@ -11,10 +12,14 @@ void interface(vector<Park_spot>& spots) {
 | 
			
		||||
    cout << "\n[2]Log in as administrator";
 | 
			
		||||
    cin >> selector;
 | 
			
		||||
    switch (selector) {
 | 
			
		||||
    case 1:
 | 
			
		||||
    case 1: {
 | 
			
		||||
        interface_member(spots);
 | 
			
		||||
    case 2:
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    case 2: {
 | 
			
		||||
        interface_admin(spots);
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -33,15 +38,16 @@ void interface_member(vector<Park_spot>& spots) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    cout << "Logged in succesfully\n";
 | 
			
		||||
    cout << "select an option\n [1] Parking options\n[2]other";
 | 
			
		||||
    cout << "select an option\n [1] Parking options\n[2]monthy report";
 | 
			
		||||
    int option;
 | 
			
		||||
    cin >> option;
 | 
			
		||||
    switch (option) {
 | 
			
		||||
    case 1: {
 | 
			
		||||
        park(c, spots);
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    case 2: {
 | 
			
		||||
        // other thing you want to add
 | 
			
		||||
        c.gen_monthly();
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -50,7 +56,47 @@ void interface_member(vector<Park_spot>& spots) {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void interface_admin(vector<Park_spot>& spots) {}
 | 
			
		||||
void interface_admin(vector<Park_spot>& spots) {
 | 
			
		||||
    cout << "Welcome to the admin interface. It is not completely ready yet.\n";
 | 
			
		||||
    cout << "[1] See monthly report of ALL parking spots\n";
 | 
			
		||||
    cout << "[2] See weekly report of ALL parking spots\n";
 | 
			
		||||
    cout << "[3] See monthly 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 << "option[1-5]:";
 | 
			
		||||
    int option;
 | 
			
		||||
    cin >> option;
 | 
			
		||||
    switch (option) {
 | 
			
		||||
    case 1: {
 | 
			
		||||
        reports_from_allparkspots();
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    case 2: {
 | 
			
		||||
        reports_from_allparkspots(true);
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    case 3: {
 | 
			
		||||
        cout << "Which parking spot would you like a report on?ID:";
 | 
			
		||||
        int spotid;
 | 
			
		||||
        cin >> spotid;
 | 
			
		||||
        reports_from_parkspot(spotid);
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    case 4: {
 | 
			
		||||
        cout << "Which parking spot would you like a report on?ID:";
 | 
			
		||||
        int spotid;
 | 
			
		||||
        cin >> spotid;
 | 
			
		||||
        reports_from_parkspot(spotid, true);
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    case 5: {
 | 
			
		||||
        current_status_parkspots(spots);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// --------- individual things.
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -61,6 +61,7 @@ std::ostream& operator<<(std::ostream& os, const Park_time& pt) {
 | 
			
		||||
    std::time_t start_ = system_clock::to_time_t(pt.start);
 | 
			
		||||
    std::time_t end_ = system_clock::to_time_t(pt.end);
 | 
			
		||||
    os << "- - - - - - - - - - - - - - - - - - - -\n";
 | 
			
		||||
    os << "Customer # " << pt.customer_id << "at parking spot " << pt.spot_id << "\n";
 | 
			
		||||
    os << "Clocked in :" << std::ctime(&start_);
 | 
			
		||||
    os << "clocked out : " << std::ctime(&end_);
 | 
			
		||||
    os << "duration : " << pt.duration << "\n";
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										92
									
								
								Query.cpp
									
									
									
									
									
								
							
							
						
						
									
										92
									
								
								Query.cpp
									
									
									
									
									
								
							@@ -1,6 +1,5 @@
 | 
			
		||||
#include "headers/Query.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
vector<Park_time> query_parktimes_for_customer(int cid) {
 | 
			
		||||
    /*
 | 
			
		||||
    This is needed to initialize the park_instances for the customer constructor
 | 
			
		||||
@@ -25,10 +24,8 @@ vector<Park_time> query_parktimes_for_customer(int cid) {
 | 
			
		||||
    return park_times;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------- customers
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
vector<Customer> query_customer_with_name(string name) {
 | 
			
		||||
    /*
 | 
			
		||||
    We use this instead of plain customers because:
 | 
			
		||||
@@ -70,29 +67,102 @@ Customer query_customer_with_id(int id) {
 | 
			
		||||
        Customer result{
 | 
			
		||||
            id, name, password, Vehicle_type(vehicle), park_instances};
 | 
			
		||||
        // DEBUG
 | 
			
		||||
        // cout << "{" << result.id << "," <<result.password <<"," << int(vehicle) << "}\n";
 | 
			
		||||
        // cout << "{" << result.id << "," <<result.password <<"," <<
 | 
			
		||||
        // int(vehicle) << "}\n";
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//------------------------------- 
 | 
			
		||||
//------------------------------- parkspot info
 | 
			
		||||
 | 
			
		||||
Park_spot query_parkspot_with_id(int id, vector<Park_spot>& parkspots){
 | 
			
		||||
    for (Park_spot& i : parkspots){
 | 
			
		||||
        if (i.id == id){
 | 
			
		||||
Park_spot query_parkspot_with_id(int id, vector<Park_spot>& parkspots) {
 | 
			
		||||
    for (Park_spot& i : parkspots) {
 | 
			
		||||
        if (i.id == id) {
 | 
			
		||||
            return i;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void reports_from_parkspot(int spotid, bool weekly) {
 | 
			
		||||
    std::time_t t = std::time(0); // get time now
 | 
			
		||||
    std::tm* now = std::localtime(&t);
 | 
			
		||||
    int s_since_epoch = ((now->tm_year - 70) * 365.2425 * 24 * 3600) +
 | 
			
		||||
                        (now->tm_mon * 30.436875 * 24 * 3600);
 | 
			
		||||
 | 
			
		||||
    if (weekly){
 | 
			
		||||
        s_since_epoch += ((now->tm_mday/ 7) * 24 * 3600);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    vector<Park_time> park_times;
 | 
			
		||||
    SQLite::Statement query(
 | 
			
		||||
        data::db, "SELECT * FROM Park_time WHERE spot_id = ? AND start > ?;");
 | 
			
		||||
    query.bind(1, spotid);
 | 
			
		||||
    query.bind(2, s_since_epoch);
 | 
			
		||||
    while (query.executeStep()) {
 | 
			
		||||
        int id = query.getColumn(0);
 | 
			
		||||
        int cid = query.getColumn(1);
 | 
			
		||||
        int start = query.getColumn(3);
 | 
			
		||||
        int duration = query.getColumn(5);
 | 
			
		||||
        Park_time result{id, cid, spotid, start, duration};
 | 
			
		||||
        park_times.push_back(result);
 | 
			
		||||
    }
 | 
			
		||||
    query.reset();
 | 
			
		||||
 | 
			
		||||
    for (auto i : park_times) {
 | 
			
		||||
        cout << i;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void reports_from_allparkspots(bool weekly) {
 | 
			
		||||
    std::time_t t = std::time(0); // get time now
 | 
			
		||||
    std::tm* now = std::localtime(&t);
 | 
			
		||||
    int s_since_epoch = ((now->tm_year - 70) * 365.2425 * 24 * 3600) +
 | 
			
		||||
                        (now->tm_mon * 30.436875 * 24 * 3600);
 | 
			
		||||
    if (weekly){
 | 
			
		||||
        s_since_epoch += ((now->tm_mday/ 7) * 24 * 3600);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    vector<Park_time> park_times;
 | 
			
		||||
    SQLite::Statement query(
 | 
			
		||||
        data::db, "SELECT * FROM Park_time WHERE start > ?;");
 | 
			
		||||
    query.bind(1, s_since_epoch);
 | 
			
		||||
    while (query.executeStep()) {
 | 
			
		||||
        int id = query.getColumn(0);
 | 
			
		||||
        int cid = query.getColumn(1);
 | 
			
		||||
        int spotid = query.getColumn(2);
 | 
			
		||||
        int start = query.getColumn(3);
 | 
			
		||||
        int duration = query.getColumn(5);
 | 
			
		||||
        Park_time result{id, cid, spotid, start, duration};
 | 
			
		||||
        park_times.push_back(result);
 | 
			
		||||
    }
 | 
			
		||||
    query.reset();
 | 
			
		||||
 | 
			
		||||
    for (auto i : park_times) {
 | 
			
		||||
        cout << i;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void current_status_parkspots(vector<Park_spot>& spots){
 | 
			
		||||
    for(auto& i : spots){
 | 
			
		||||
        cout << "---------------------------\n";
 | 
			
		||||
        cout << "PS #" << i.id << "\n";
 | 
			
		||||
        cout << "Taken: " << ((i.taken) ? "true" : "false") << "\n";
 | 
			
		||||
        if (i.taken){
 | 
			
		||||
            cout << "Customer#" << i.parked_customer << "  parked there\n";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// -------------- paroking spots
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// vector<Park_spot> populate_spots(){
 | 
			
		||||
//         vector<Park_spot> spots;
 | 
			
		||||
//     SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id > 0;");
 | 
			
		||||
//     SQLite::Statement query(data::db, "SELECT * FROM Park_spot WHERE id >
 | 
			
		||||
//     0;");
 | 
			
		||||
//     // query.bind(1, 2);
 | 
			
		||||
//     while (query.executeStep()) {
 | 
			
		||||
//         int id = query.getColumn(0);
 | 
			
		||||
 
 | 
			
		||||
@@ -59,5 +59,8 @@ vector<Park_spot> populate_spots();
 | 
			
		||||
 | 
			
		||||
Park_spot query_parkspot_with_id(int id, vector<Park_spot>& parkspots);
 | 
			
		||||
 | 
			
		||||
void reports_from_parkspot(int spotid, bool weekly=false);
 | 
			
		||||
void reports_from_allparkspots(bool weekly=false);
 | 
			
		||||
 | 
			
		||||
#endif // CUSTOMER_H
 | 
			
		||||
void current_status_parkspots(vector<Park_spot>& spots);
 | 
			
		||||
#endif // CUSTOMER_H
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user