customer can be saved into db

This commit is contained in:
MassiveAtoms
2019-06-26 15:12:23 -03:00
parent 2e22008040
commit f11ebc6a9c
7 changed files with 75 additions and 36 deletions

View File

@ -2,29 +2,21 @@
#include <iostream>
// moet aangepast worden om een verhicle_type toe te voegen
Customer::Customer(int id_, string name_)
: id { id_ }
, name { name_ }
{
}
Customer::Customer(int id_, string name_, Verhicle_type verhicle_) : id{id_}, name{name_}, verhicle{verhicle_}, card_code{gen_cardcode()} {}
/*
creert een park_time object met start time= nu, en voegt t toe aan een vector.
*/
void Customer::clock_in( int s_id)
{
void Customer::clock_in(int s_id) {
Park_time pt{id, s_id};
park_instances.push_back(pt);
}
// edit de laatste park_time obj in de vector zodat de end_time = 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); }
// monthly report generation. moet nog een manier vinden om af te bakenen.
void Customer::gen_monthly(){
void Customer::gen_monthly() {
std::cout << "NAME: " << name << " card code: " << card_code << "\n";
std::cout << "-------------------------------------------------\n";
for (auto& i : park_instances) {
@ -32,4 +24,33 @@ void Customer::gen_monthly(){
std::cout << i;
}
std::cout << "-------------------------------------------------\n\n";
}
}
void Customer::update_db(SQLite::Database& database) {
string statement{"insert into Customer values (, '', '', )"};
// after ( = 28)
statement.insert(38, std::to_string(int(verhicle)));
statement.insert(36, card_code);
statement.insert(32, name);
statement.insert(29, std::to_string(id));
std::cout << statement;
SQLite::Transaction transaction(database);
database.exec(statement);
transaction.commit();
}
//
// used to generate random card codes that will be used to authenticate users.
// they represent contactless rf cards that users will use to authenticate
std::mt19937 mt(time(0));
std::uniform_int_distribution<int> dist(65, 127);
string Customer::gen_cardcode() {
string code;
for (int i = 0; i < 20; i++) {
char letter = char(dist(mt));
code += letter;
}
return code;
}