Added constructors to construct from db info

This is in no way finished. CHECK TODOs!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
This commit is contained in:
TinyAtoms
2019-06-30 00:37:18 -03:00
parent 085cd5af08
commit bf17b82c2e
10 changed files with 136 additions and 124 deletions

View File

@ -1,30 +1,23 @@
#include "headers/Customer.h"
// constructors
Customer::Customer(string name_, Verhicle_type verhicle_):
name{name_}, verhicle{verhicle_},
card_code{gen_cardcode()}
{
Customer::Customer(string name_, Verhicle_type verhicle_)
: name{name_}, verhicle{verhicle_}, card_code{gen_cardcode()} {
id = auto_increment_db() + 1;
save_db();
}
Customer::Customer(int id_, string name_, string card_code_,
Verhicle_type verhicle_, vector<Park_time> instances)
: name{name_},
card_code{card_code_},
verhicle{verhicle_},
park_instances{instances} {}
Customer::Customer(int id_, string name_, string card_code_, Verhicle_type verhicle_, vector<Park_time> instances)
: name{name_},
card_code{card_code_},
verhicle{verhicle_},
park_instances{instances}
{
Customer::~Customer() { update_db(); }
}
Customer::~Customer(){
update_db();
}
// clock in/out methods ====================================================================================
// clock in/out methods
// ====================================================================================
/*
Create a p_time object with start=now and adds to vector
*/
@ -34,22 +27,22 @@ void Customer::clock_in(int s_id) {
}
// 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
void Customer::gen_monthly() {
cout << "NAME: " << name << " card code: " << card_code << "\n";
cout << "-------------------------------------------------\n";
for (auto& i : park_instances) {
// TODO: need some logic to only include from this month. scratch that, need to remove gen monthly
// TODO: need some logic to only include from this month. scratch that,
// need to remove gen monthly
cout << i;
}
cout << "-------------------------------------------------\n\n";
}
//================================================================================================
// functions that interact with the database
@ -66,7 +59,8 @@ void Customer::save_db() {
}
void Customer::update_db() {
string statement = "UPDATE Customer SET name = '', card_code = '' where id = '';";
string statement =
"UPDATE Customer SET name = '', card_code = '' where id = '';";
statement.insert(58, to_string(id));
statement.insert(44, card_code);
statement.insert(28, name);