almost all internals done after i fix segfault
This commit is contained in:
29
Customer.cpp
29
Customer.cpp
@ -1,20 +1,20 @@
|
||||
#include "headers/Customer.h"
|
||||
|
||||
// constructors
|
||||
Customer::Customer(string name_, Verhicle_type verhicle_)
|
||||
: name{name_}, verhicle{verhicle_}, card_code{gen_cardcode()} {
|
||||
Customer::Customer(string name_, string password_, Verhicle_type verhicle_)
|
||||
: name{name_}, verhicle{verhicle_}, password{hash_password(password)} {
|
||||
id = auto_increment_db() + 1;
|
||||
save_db();
|
||||
}
|
||||
|
||||
Customer::Customer(int id_, string name_, string card_code_,
|
||||
Customer::Customer(int id_, string name_, string password_,
|
||||
Verhicle_type verhicle_, vector<Park_time> instances)
|
||||
: name{name_},
|
||||
card_code{card_code_},
|
||||
:id{id_},
|
||||
name{name_},
|
||||
password{password_},
|
||||
verhicle{verhicle_},
|
||||
park_instances{instances} {}
|
||||
|
||||
Customer::~Customer() { update_db(); }
|
||||
|
||||
// clock in/out methods
|
||||
// ====================================================================================
|
||||
@ -33,7 +33,7 @@ void Customer::clock_out(int s_id) {
|
||||
|
||||
// report gen
|
||||
void Customer::gen_monthly() {
|
||||
cout << "NAME: " << name << " card code: " << card_code << "\n";
|
||||
cout << "NAME: " << name << "\n";
|
||||
cout << "-------------------------------------------------\n";
|
||||
for (auto& i : park_instances) {
|
||||
// TODO: need some logic to only include from this month. scratch that,
|
||||
@ -50,7 +50,7 @@ void Customer::save_db() {
|
||||
string statement{"insert into Customer values (, '', '', );"};
|
||||
// after ( = 28)
|
||||
statement.insert(38, to_string(int(verhicle)));
|
||||
statement.insert(36, card_code);
|
||||
statement.insert(36, password);
|
||||
statement.insert(32, name);
|
||||
statement.insert(29, to_string(id));
|
||||
SQLite::Transaction transaction(data::db);
|
||||
@ -62,7 +62,7 @@ void Customer::update_db() {
|
||||
string statement =
|
||||
"UPDATE Customer SET name = '', card_code = '' where id = '';";
|
||||
statement.insert(58, to_string(id));
|
||||
statement.insert(44, card_code);
|
||||
statement.insert(44, password);
|
||||
statement.insert(28, name);
|
||||
data::db.exec(statement);
|
||||
}
|
||||
@ -84,15 +84,4 @@ int Customer::auto_increment_db() {
|
||||
return id;
|
||||
}
|
||||
|
||||
// random helpers=============================================================
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user