heavily simplified imports and using directives

This commit is contained in:
TinyAtoms 2019-06-29 23:22:58 -03:00
parent 97ed3150ec
commit 085cd5af08
8 changed files with 44 additions and 43 deletions

View File

@ -1,5 +1,4 @@
#include "headers/Customer.h"
#include <iostream>
// constructors
Customer::Customer(string name_, Verhicle_type verhicle_):
@ -20,6 +19,10 @@ Customer::Customer(int id_, string name_, string card_code_, Verhicle_type verhi
}
Customer::~Customer(){
update_db();
}
// clock in/out methods ====================================================================================
/*
@ -37,13 +40,13 @@ void Customer::clock_out(int s_id) { park_instances[park_instances.size() - 1].c
// report gen
void Customer::gen_monthly() {
std::cout << "NAME: " << name << " card code: " << card_code << "\n";
std::cout << "-------------------------------------------------\n";
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
std::cout << i;
// TODO: need some logic to only include from this month. scratch that, need to remove gen monthly
cout << i;
}
std::cout << "-------------------------------------------------\n\n";
cout << "-------------------------------------------------\n\n";
}
@ -53,7 +56,7 @@ void Customer::gen_monthly() {
void Customer::save_db() {
string statement{"insert into Customer values (, '', '', );"};
// after ( = 28)
statement.insert(38, std::to_string(int(verhicle)));
statement.insert(38, to_string(int(verhicle)));
statement.insert(36, card_code);
statement.insert(32, name);
statement.insert(29, to_string(id));
@ -64,17 +67,15 @@ void Customer::save_db() {
void Customer::update_db() {
string statement = "UPDATE Customer SET name = '', card_code = '' where id = '';";
statement.insert(58, std::to_string(id));
statement.insert(58, to_string(id));
statement.insert(44, card_code);
statement.insert(28, name);
// std::cout << statement; TODO: set some logging here
data::db.exec(statement);
}
void Customer::delete_db() {
string statement = "delete from Customer where id= ;";
statement.insert(statement.length() - 2, std::to_string(id));
// std::cout << statement;
statement.insert(statement.length() - 2, to_string(id));
SQLite::Transaction transaction(data::db);
data::db.exec(statement);
transaction.commit();

View File

@ -4,13 +4,17 @@
// constructors
Park_spot::Park_spot(){
parked = nullptr;
id = auto_increment_db() + 1;
taken = false;
Park_spot::Park_spot()
: parked{nullptr},
id{auto_increment_db()+1},
taken{false} {
save_db();
}
Park_spot::~Park_spot(){
update_db();
}
// clock in en out, calls de juist(in/out) van de customer aan de hand van internal state van taken
@ -62,8 +66,7 @@ void Park_spot::save_db() {
void Park_spot::delete_db() {
string statement = "delete from Park_spot where id= ;";
statement.insert(statement.length() - 2, std::to_string(id));
// std::cout << statement;
statement.insert(statement.length() - 2, to_string(id));
SQLite::Transaction transaction(data::db);
data::db.exec(statement);
transaction.commit();

View File

@ -1,6 +1,4 @@
#include"headers/Park_time.h"
#include <iostream>
#include <ctime>
Park_time::Park_time(int c_id, int s_id)
@ -13,15 +11,19 @@ Park_time::Park_time(int c_id, int s_id)
save_db();
}
Park_time::~Park_time(){
update_db();
}
void Park_time::clock_out(int c_id, int s_id)
{
if (c_id != customer_id) {
std::cout << "wrong customer id, you are at the wrong location";
cout << "wrong customer id, you are at the wrong location";
return;
}
if (s_id != spot_id) {
std::cout << "Wrong spot id, you're at the wrong location";
cout << "Wrong spot id, you're at the wrong location";
return;
}
@ -31,7 +33,7 @@ void Park_time::clock_out(int c_id, int s_id)
update_db();
} else {
std::cout << "Already clocked out. Something is wrong \n";
cout << "Already clocked out. Something is wrong \n";
}
}
@ -50,7 +52,7 @@ std::ostream& operator<<(std::ostream& os, const Park_time & pt){
int Park_time::start_to_int(){
auto start_to_epoch = start.time_since_epoch();
auto start_value = std::chrono::duration_cast<std::chrono::seconds>(start_to_epoch);
auto start_value = duration_cast<seconds>(start_to_epoch);
int start_seconds = start_value.count();
return start_seconds;
}
@ -74,7 +76,7 @@ void Park_time::save_db() {
void Park_time::update_db() {
string statement = "UPDATE Park_time SET end = , duration = where id = '';";
statement.insert(53, std::to_string(id));
statement.insert(53, to_string(id));
statement.insert(40, to_string(duration));
statement.insert(27, to_string(start_to_int() + duration));
data::db.exec(statement);

View File

@ -1,15 +1,14 @@
#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 "data.h"
using std::string;
#include "Park_time.h"
#include "data.h"
#include <random>
#include <vector>
using std::vector;
// will make it easy to represent it in the database while making it easy to use while programming
@ -32,7 +31,7 @@ class Customer {
Customer(string name_, Verhicle_type verhicle_);
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
~Customer();
int id;
string name;
string card_code;

View File

@ -14,8 +14,9 @@ class Park_spot {
public:
int id;
bool taken;
Customer* parked; //TODO: think about memory management
Customer* parked;
Park_spot();
~Park_spot();
void clock(Customer* c_customer);
private:
void save_db();

View File

@ -5,12 +5,14 @@
#include <chrono>
#include <iostream>
#include <string>
#include <ctime>
#include "data.h"
using namespace std::chrono;
using std::string;
using std::to_string;
using std::cout;
/*
@ -21,6 +23,7 @@ class Park_time {
public:
Park_time(int c_id, int s_id);
// Park_time(int c_id, int s_id );
~Park_time();
int id;
int customer_id;
int spot_id;

View File

@ -1,9 +1,4 @@
#include "thirdparty/SQLiteCpp/include/SQLiteCpp/SQLiteCpp.h"
#include "headers/data.h"
#include "headers/Park_spot.h"
#include <iostream>
#include <vector>
#include <string>
#include <thread>
@ -31,16 +26,13 @@ a wait function where 1 sec represents 1 hour irl.
}
using std::cout;
int main() {
class Customer sagar{"Sagar Ramsaransing", Verhicle_type::bike};
sagar.update_db();
Park_spot p1;
p1.clock(&sagar);
Wait(2);
p1.clock(&sagar);
// p1.clock(&sagar);
}

BIN
test.db3

Binary file not shown.