most features are implemented #4
@ -5,4 +5,8 @@ IndentWidth: 4
|
|||||||
Language: Cpp
|
Language: Cpp
|
||||||
|
|
||||||
PointerAlignment: Left
|
PointerAlignment: Left
|
||||||
ColumnLimit: 160
|
ColumnLimit: 120
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
BreakConstructorInitializersStyle : BCIS_AfterColon
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
64
Customer.cpp
64
Customer.cpp
@ -1,9 +1,27 @@
|
|||||||
#include "headers/Customer.h"
|
#include "headers/Customer.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// moet aangepast worden om een verhicle_type toe te voegen
|
// constructors
|
||||||
Customer::Customer(int id_, string name_, Verhicle_type verhicle_) : id{id_}, name{name_}, verhicle{verhicle_}, card_code{gen_cardcode()} {}
|
Customer::Customer(string name_, Verhicle_type verhicle_, SQLite::Database& db):
|
||||||
|
name{name_}, verhicle{verhicle_},
|
||||||
|
card_code{gen_cardcode()}
|
||||||
|
{
|
||||||
|
id = auto_increment_db(db) + 1;
|
||||||
|
save_db(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}
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// clock methods ====================================================================================
|
||||||
/*
|
/*
|
||||||
creert een park_time object met start time= nu, en voegt t toe aan een vector.
|
creert een park_time object met start time= nu, en voegt t toe aan een vector.
|
||||||
*/
|
*/
|
||||||
@ -15,7 +33,7 @@ void Customer::clock_in(int s_id) {
|
|||||||
// edit de laatste park_time obj in de vector zodat de end_time = now.
|
// 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.
|
// 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";
|
||||||
std::cout << "-------------------------------------------------\n";
|
std::cout << "-------------------------------------------------\n";
|
||||||
@ -26,23 +44,49 @@ void Customer::gen_monthly() {
|
|||||||
std::cout << "-------------------------------------------------\n\n";
|
std::cout << "-------------------------------------------------\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Customer::update_db(SQLite::Database& database) {
|
//================================================================================================
|
||||||
string statement{"insert into Customer values (, '', '', )"};
|
// functions that interact with the database
|
||||||
|
|
||||||
|
void Customer::save_db(SQLite::Database& database) {
|
||||||
|
string statement{"insert into Customer values (, '', '', );"};
|
||||||
// after ( = 28)
|
// after ( = 28)
|
||||||
statement.insert(38, std::to_string(int(verhicle)));
|
statement.insert(38, std::to_string(int(verhicle)));
|
||||||
statement.insert(36, card_code);
|
statement.insert(36, card_code);
|
||||||
statement.insert(32, name);
|
statement.insert(32, name);
|
||||||
statement.insert(29, std::to_string(id));
|
statement.insert(29, "null");
|
||||||
std::cout << statement;
|
|
||||||
SQLite::Transaction transaction(database);
|
SQLite::Transaction transaction(database);
|
||||||
database.exec(statement);
|
database.exec(statement);
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
void Customer::update_db(SQLite::Database& database) {
|
||||||
|
string statement = "UPDATE Customer SET name = \"\", card_code = \"\" where id = '';";
|
||||||
|
statement.insert(58, std::to_string(id));
|
||||||
|
statement.insert(44, card_code);
|
||||||
|
statement.insert(28, name);
|
||||||
|
// std::cout << statement; TODO: set some logging here
|
||||||
|
database.exec(statement);
|
||||||
|
}
|
||||||
|
|
||||||
// used to generate random card codes that will be used to authenticate users.
|
void Customer::delete_db(SQLite::Database& database) {
|
||||||
// they represent contactless rf cards that users will use to authenticate
|
string statement = "delete from Customer where id= ;";
|
||||||
|
statement.insert(statement.length() - 2, std::to_string(id));
|
||||||
|
// std::cout << statement;
|
||||||
|
SQLite::Transaction transaction(database);
|
||||||
|
database.exec(statement);
|
||||||
|
transaction.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Customer::auto_increment_db(SQLite::Database& database) {
|
||||||
|
SQLite::Statement max_id(database, "select max(id) from Customer;");
|
||||||
|
int id = 0;
|
||||||
|
max_id.executeStep();
|
||||||
|
id = max_id.getColumn(0);
|
||||||
|
max_id.reset();
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// random helpers=============================================================
|
||||||
std::mt19937 mt(time(0));
|
std::mt19937 mt(time(0));
|
||||||
std::uniform_int_distribution<int> dist(65, 127);
|
std::uniform_int_distribution<int> dist(65, 127);
|
||||||
|
|
||||||
|
@ -20,13 +20,7 @@ enum class Verhicle_type {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
db repr of Customer
|
card code is een randomly generated string moeten zijn, die je bv. op een nfc card zou opslaan en zo zou
|
||||||
int id (not null, auto increment)
|
|
||||||
string name (not nulll)
|
|
||||||
string card_code (not null)
|
|
||||||
Dit moet nog verandert worden.
|
|
||||||
|
|
||||||
card code zou eigenlijk een randomly generated string moeten zijn, die je bv. op een ndf card zou opslaan en zo zou
|
|
||||||
authenticaten bij je parking spot. We kunnen dit ipv of samen met een password gebruiken.
|
authenticaten bij je parking spot. We kunnen dit ipv of samen met een password gebruiken.
|
||||||
clock in en out creeert en compleet een park_time object. Voegt het toe aan een vector.
|
clock in en out creeert en compleet een park_time object. Voegt het toe aan een vector.
|
||||||
|
|
||||||
@ -34,20 +28,31 @@ clock in en out creeert en compleet een park_time object. Voegt het toe aan een
|
|||||||
|
|
||||||
class Customer {
|
class Customer {
|
||||||
public:
|
public:
|
||||||
|
Customer(string name_, Verhicle_type verhicle_, SQLite::Database& db);
|
||||||
|
Customer(int id_, string name_, string card_code_, Verhicle_type verhicle_,
|
||||||
|
vector<Park_time> instances); // needed to construct from db
|
||||||
|
// potentially: add a destructor that calls update_db() before being destroyed
|
||||||
int id;
|
int id;
|
||||||
string name;
|
string name;
|
||||||
string card_code;
|
string card_code;
|
||||||
|
|
||||||
void clock_in(int s_id);
|
void clock_in(int s_id);
|
||||||
void clock_out(int s_id);
|
void clock_out(int s_id);
|
||||||
|
|
||||||
|
void update_db(SQLite::Database& database);
|
||||||
|
void delete_db(SQLite::Database& database);
|
||||||
|
|
||||||
// void gen_weekly(); TODO: this
|
// void gen_weekly(); TODO: this
|
||||||
void gen_monthly();
|
void gen_monthly();
|
||||||
Customer(int id_, string name_, Verhicle_type verhicle_);
|
|
||||||
void update_db(SQLite::Database& database);
|
|
||||||
|
|
||||||
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(SQLite::Database& database);
|
||||||
|
int auto_increment_db(SQLite::Database& database);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CUSTOMER_H
|
#endif // CUSTOMER_H
|
15
main.cpp
15
main.cpp
@ -32,17 +32,8 @@ using std::cout;
|
|||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
SQLite::Database db = data::start_db();
|
SQLite::Database db = data::start_db();
|
||||||
|
// see implementation of update_db, save_db and delete_db of customer to see how queries and statements work
|
||||||
// search example
|
Customer sagar{"Ramsaransing", Verhicle_type::medium, db};
|
||||||
SQLite::Statement get_sagar(db, "select * from Customer where name like '%sagar%' ");
|
|
||||||
while (get_sagar.executeStep()) {
|
|
||||||
int id = get_sagar.getColumn(0);
|
|
||||||
string name = get_sagar.getColumn(1);
|
|
||||||
string code = get_sagar.getColumn(2);
|
|
||||||
int car = get_sagar.getColumn(3);
|
|
||||||
cout << id << "," << name << "," << code << "," << car << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Customer sagar{15, "Ramsaransing", Verhicle_type::medium};
|
|
||||||
sagar.update_db(db);
|
sagar.update_db(db);
|
||||||
|
sagar.delete_db(db);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user