Compare commits
No commits in common. "b377ca043d647a09dced27d77bdb498a71ba57d5" and "f133cd7f219615eb23fab2fe0e9893090b34e22a" have entirely different histories.
b377ca043d
...
f133cd7f21
@ -9,7 +9,7 @@ include_directories(
|
||||
)
|
||||
|
||||
|
||||
add_executable(park main.cpp data.cpp headers/data.h Customer.cpp headers/Customer.h Park_spot.cpp headers/Park_spot.h Park_time.cpp headers/Park_time.h)
|
||||
add_executable(park main.cpp Customer.cpp headers/Customer.h Park_spot.cpp headers/Park_spot.h Park_time.cpp headers/Park_time.h)
|
||||
|
||||
target_link_libraries(park
|
||||
SQLiteCpp
|
||||
|
47
Customer.cpp
47
Customer.cpp
@ -2,21 +2,29 @@
|
||||
#include <iostream>
|
||||
|
||||
// moet aangepast worden om een verhicle_type toe te voegen
|
||||
Customer::Customer(int id_, string name_, Verhicle_type verhicle_) : id{id_}, name{name_}, verhicle{verhicle_}, card_code{gen_cardcode()} {}
|
||||
Customer::Customer(int id_, string name_)
|
||||
: id { id_ }
|
||||
, name { name_ }
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
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) {
|
||||
@ -24,33 +32,4 @@ 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;
|
||||
}
|
||||
}
|
14
data.cpp
14
data.cpp
@ -1,14 +0,0 @@
|
||||
#include "headers/data.h"
|
||||
|
||||
namespace data {
|
||||
|
||||
SQLite::Database start_db() {
|
||||
SQLite::Database db("test.db3", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
|
||||
|
||||
db.exec("create table if not exists Customer (id integer primary key, name text, card_code varchar(20), verhicle int)");
|
||||
db.exec("create table if not exists Park_spot (id integer primary key, taken boolean, customer_id int)");
|
||||
db.exec("create table if not exists Park_time (id integer primary key, customer_id int, spot_id int, start real, end real, duration real)");
|
||||
|
||||
return db;
|
||||
}
|
||||
} // namespace data
|
@ -1,17 +1,15 @@
|
||||
#ifndef CUSTOMER_H
|
||||
#define CUSTOMER_H
|
||||
#pragma once
|
||||
#include "../thirdparty/SQLiteCpp/include/SQLiteCpp/SQLiteCpp.h"
|
||||
#include "Park_time.h"
|
||||
#include <ctime>
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Park_time.h"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
// enum type is basically een manier om categories te representen als een integer in the background, maar om t in code
|
||||
// enum type is basically een manier om categories te representen als een integer in the background, maar om t in code
|
||||
// aan te geven als de actual category.
|
||||
enum class Verhicle_type {
|
||||
small = 1,
|
||||
@ -24,16 +22,16 @@ db repr of Customer
|
||||
int id (not null, auto increment)
|
||||
string name (not nulll)
|
||||
string card_code (not null)
|
||||
Dit moet nog verandert worden.
|
||||
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
|
||||
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.
|
||||
clock in en out creeert en compleet een park_time object. Voegt het toe aan een vector.
|
||||
|
||||
*/
|
||||
|
||||
class Customer {
|
||||
public:
|
||||
public:
|
||||
int id;
|
||||
string name;
|
||||
string card_code;
|
||||
@ -41,13 +39,13 @@ class Customer {
|
||||
void clock_out(int s_id);
|
||||
// void gen_weekly(); TODO: this
|
||||
void gen_monthly();
|
||||
Customer(int id_, string name_, Verhicle_type verhicle_);
|
||||
void update_db(SQLite::Database& database);
|
||||
Customer(int id_, string name_);
|
||||
|
||||
private:
|
||||
private:
|
||||
Verhicle_type verhicle;
|
||||
vector<Park_time> park_instances;
|
||||
string gen_cardcode();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // CUSTOMER_H
|
@ -1,6 +0,0 @@
|
||||
#include "../thirdparty/SQLiteCpp/include/SQLiteCpp/SQLiteCpp.h"
|
||||
#include "Customer.h"
|
||||
namespace data {
|
||||
SQLite::Database start_db();
|
||||
|
||||
}
|
16
main.cpp
16
main.cpp
@ -1,5 +1,5 @@
|
||||
#include "headers/Park_spot.h"
|
||||
#include "headers/data.h"
|
||||
#include "thirdparty/SQLiteCpp/include/SQLiteCpp/SQLiteCpp.h"
|
||||
#include <iostream>
|
||||
#include <thread> // to make pausing work, not sure if i need chrono, or this, or both
|
||||
#include <vector>
|
||||
@ -30,11 +30,18 @@ a wait function where 1 sec represents 1 hour irl.
|
||||
using std::cout;
|
||||
|
||||
int main() {
|
||||
SQLite::Database db("test.db3", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
|
||||
|
||||
SQLite::Database db = data::start_db();
|
||||
db.exec("create table if not exists Customer (id integer primary key, name text, card_code varchar(20), verhicle int)");
|
||||
db.exec("create table if not exists Park_spot (id integer primary key, taken boolean, customer_id int)");
|
||||
db.exec("create table if not exists Park_time (id integer primary key, customer_id int, spot_id int, start real, end real, duration real)");
|
||||
|
||||
SQLite::Transaction transaction(db);
|
||||
db.exec("insert into Customer values (NULL, 'sagar ram', 'aqwsderfgtaqwsderfgt', 2)");
|
||||
transaction.commit();
|
||||
|
||||
// search example
|
||||
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);
|
||||
@ -42,7 +49,4 @@ int main() {
|
||||
int car = get_sagar.getColumn(3);
|
||||
cout << id << "," << name << "," << code << "," << car << std::endl;
|
||||
}
|
||||
|
||||
Customer sagar{15, "Ramsaransing", Verhicle_type::medium};
|
||||
sagar.update_db(db);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user