can save to db
This commit is contained in:
		
							
								
								
									
										11
									
								
								Customer.cpp
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								Customer.cpp
									
									
									
									
									
								
							@@ -10,6 +10,7 @@ Customer::Customer(string name_, Verhicle_type verhicle_):
 | 
				
			|||||||
    save_db();
 | 
					    save_db();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Customer::Customer(int id_, string name_, string card_code_, Verhicle_type verhicle_, vector<Park_time> instances)
 | 
					Customer::Customer(int id_, string name_, string card_code_, Verhicle_type verhicle_, vector<Park_time> instances)
 | 
				
			||||||
    : name{name_}, 
 | 
					    : name{name_}, 
 | 
				
			||||||
     card_code{card_code_},
 | 
					     card_code{card_code_},
 | 
				
			||||||
@@ -20,19 +21,20 @@ Customer::Customer(int id_, string name_, string card_code_, Verhicle_type verhi
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// clock in/out methods ====================================================================================
 | 
				
			||||||
// clock methods ====================================================================================
 | 
					 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
creert een park_time object met start time= nu, en voegt t toe aan een vector.
 | 
					Create a p_time object with start=now and adds to vector
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void Customer::clock_in(int s_id) {
 | 
					void Customer::clock_in(int s_id) {
 | 
				
			||||||
    Park_time pt{id, s_id};
 | 
					    Park_time pt{id, s_id};
 | 
				
			||||||
    park_instances.push_back(pt);
 | 
					    park_instances.push_back(pt);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// edit de laatste park_time obj in de vector zodat de end_time = now.
 | 
					// edit last p_time object so end=now
 | 
				
			||||||
void Customer::clock_out(int s_id) { park_instances[park_instances.size() - 1].clock_out(id, s_id); }
 | 
					void Customer::clock_out(int s_id) { park_instances[park_instances.size() - 1].clock_out(id, s_id); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// report gen
 | 
					// report gen
 | 
				
			||||||
void Customer::gen_monthly() {
 | 
					void Customer::gen_monthly() {
 | 
				
			||||||
    std::cout << "NAME: " << name << " card code: " << card_code << "\n";
 | 
					    std::cout << "NAME: " << name << " card code: " << card_code << "\n";
 | 
				
			||||||
@@ -44,6 +46,7 @@ void Customer::gen_monthly() {
 | 
				
			|||||||
    std::cout << "-------------------------------------------------\n\n";
 | 
					    std::cout << "-------------------------------------------------\n\n";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//================================================================================================
 | 
					//================================================================================================
 | 
				
			||||||
// functions that interact with the database
 | 
					// functions that interact with the database
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,9 @@
 | 
				
			|||||||
#include "headers/Park_spot.h"
 | 
					#include "headers/Park_spot.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// constructors
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Park_spot::Park_spot(){
 | 
					Park_spot::Park_spot(){
 | 
				
			||||||
    parked = nullptr;
 | 
					    parked = nullptr;
 | 
				
			||||||
    id = auto_increment_db() + 1;
 | 
					    id = auto_increment_db() + 1;
 | 
				
			||||||
@@ -7,6 +11,8 @@ Park_spot::Park_spot(){
 | 
				
			|||||||
    save_db();
 | 
					    save_db();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// clock in en out, calls de juist(in/out) van de customer aan de hand van internal state van taken
 | 
					// clock in en out, calls de juist(in/out) van de customer aan de hand van internal state van taken
 | 
				
			||||||
void Park_spot::clock(Customer* c_customer){
 | 
					void Park_spot::clock(Customer* c_customer){
 | 
				
			||||||
    if (!taken){
 | 
					    if (!taken){
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,12 +12,12 @@
 | 
				
			|||||||
using std::string;
 | 
					using std::string;
 | 
				
			||||||
using std::vector;
 | 
					using std::vector;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// enum type is basically een manier om categories te representen als een integer in the background, maar om t in code
 | 
					// will make it easy to represent it in the database while making it easy to use while programming
 | 
				
			||||||
// aan te geven als de actual category.
 | 
					 | 
				
			||||||
enum class Verhicle_type {
 | 
					enum class Verhicle_type {
 | 
				
			||||||
    small = 1,
 | 
					    bike = 1,
 | 
				
			||||||
    medium = 2,
 | 
					    small_car = 2,
 | 
				
			||||||
    large = 3,
 | 
					    suv = 3,
 | 
				
			||||||
 | 
					    pickup = 4
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -43,15 +43,13 @@ class Customer {
 | 
				
			|||||||
    void update_db();
 | 
					    void update_db();
 | 
				
			||||||
    void delete_db();
 | 
					    void delete_db();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // void gen_weekly(); TODO: this
 | 
					    void gen_monthly(); // remove, make it a function in data
 | 
				
			||||||
    void gen_monthly();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private:
 | 
					  private:
 | 
				
			||||||
    Verhicle_type verhicle;
 | 
					    Verhicle_type verhicle;
 | 
				
			||||||
    vector<Park_time> park_instances;
 | 
					    vector<Park_time> park_instances;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    string gen_cardcode();
 | 
					    string gen_cardcode();
 | 
				
			||||||
 | 
					 | 
				
			||||||
    void save_db();
 | 
					    void save_db();
 | 
				
			||||||
    int auto_increment_db();
 | 
					    int auto_increment_db();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,26 +12,20 @@ using namespace std::chrono;
 | 
				
			|||||||
using std::string;
 | 
					using std::string;
 | 
				
			||||||
using std::to_string;
 | 
					using std::to_string;
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
db repr of Park_time
 | 
					 | 
				
			||||||
int id (not null, auto increment)
 | 
					 | 
				
			||||||
int customer_id (not null) (many to one or something like that)
 | 
					 | 
				
			||||||
int spot_id (not null, many to one or something like that)
 | 
					 | 
				
			||||||
int duration 
 | 
					 | 
				
			||||||
datetime start (not null)
 | 
					 | 
				
			||||||
datetime end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
Dit is gewoon een record van hoe lang, wie en waar iemand parkeert. Basically, een component van 
 | 
					
 | 
				
			||||||
de internal state van customer.
 | 
					Record of who parked at what park_spot and at what time.
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Park_time {
 | 
					class Park_time {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
 | 
					    Park_time(int c_id, int s_id);
 | 
				
			||||||
 | 
					    // Park_time(int c_id, int s_id );
 | 
				
			||||||
    int id;
 | 
					    int id;
 | 
				
			||||||
    int customer_id;
 | 
					    int customer_id;
 | 
				
			||||||
    int spot_id;
 | 
					    int spot_id;
 | 
				
			||||||
    int duration;
 | 
					    int duration;
 | 
				
			||||||
    Park_time(int c_id, int s_id);
 | 
					
 | 
				
			||||||
    // Park_time(int c_id, int s_id );
 | 
					 | 
				
			||||||
    void clock_out(int c_id, int s_id);
 | 
					    void clock_out(int c_id, int s_id);
 | 
				
			||||||
    friend std::ostream& operator<<(std::ostream& os, const  Park_time & pt);
 | 
					    friend std::ostream& operator<<(std::ostream& os, const  Park_time & pt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.cpp
									
									
									
									
									
								
							@@ -35,7 +35,7 @@ a wait function where 1 sec represents 1 hour irl.
 | 
				
			|||||||
using std::cout;
 | 
					using std::cout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main() {
 | 
					int main() {
 | 
				
			||||||
    class Customer sagar{"Sagar Ramsaransing", Verhicle_type::medium};
 | 
					    class Customer sagar{"Sagar Ramsaransing", Verhicle_type::bike};
 | 
				
			||||||
    sagar.update_db();
 | 
					    sagar.update_db();
 | 
				
			||||||
    Park_spot p1;
 | 
					    Park_spot p1;
 | 
				
			||||||
    p1.clock(&sagar);
 | 
					    p1.clock(&sagar);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user