Compare commits
8 commits
dd23da5f72
...
f0ec980e8d
Author | SHA1 | Date | |
---|---|---|---|
f0ec980e8d | |||
4f9151d85b | |||
df972f68fc | |||
57bfe3af62 | |||
a33b9896b3 | |||
63f9822f34 | |||
69982fc931 | |||
46d6468e5c |
27 changed files with 204 additions and 160 deletions
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required(VERSION 3.8)
|
cmake_minimum_required(VERSION 3.8)
|
||||||
|
|
||||||
project(kima2 VERSION 1.4.2)
|
project(kima2 VERSION 1.5.0)
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH "${CMAKE_HOME_DIRECTORY}/cmake")
|
set(CMAKE_MODULE_PATH "${CMAKE_HOME_DIRECTORY}/cmake")
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
add_compile_options(/W4 /WX)
|
add_compile_options(/W4 /WX)
|
||||||
else()
|
else()
|
||||||
add_compile_options(-Wall -Wextra -pedantic -Woverloaded-virtual -Wredundant-decls -Wshadow)
|
#add_compile_options(-Wall -Wextra -pedantic -Woverloaded-virtual -Wredundant-decls -Wshadow)
|
||||||
|
add_compile_options(-Wall -Wextra)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
configure_file(config.h.in ${PROJECT_BINARY_DIR}/config.h)
|
configure_file(config.h.in ${PROJECT_BINARY_DIR}/config.h)
|
||||||
|
@ -30,11 +31,11 @@ endif()
|
||||||
add_subdirectory(3rdparty)
|
add_subdirectory(3rdparty)
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES Debug)
|
#if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES Debug)
|
||||||
include(CTest)
|
# include(CTest)
|
||||||
enable_testing()
|
# enable_testing()
|
||||||
add_subdirectory(test)
|
# add_subdirectory(test)
|
||||||
endif()
|
#endif()
|
||||||
|
|
||||||
|
|
||||||
# CPack
|
# CPack
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -13,6 +13,8 @@ endif (MINGW)
|
||||||
set(CORE_SOURCES
|
set(CORE_SOURCES
|
||||||
database.cpp
|
database.cpp
|
||||||
entity.cpp
|
entity.cpp
|
||||||
|
entityint.cpp
|
||||||
|
entityuuid.cpp
|
||||||
seller.cpp
|
seller.cpp
|
||||||
article.cpp
|
article.cpp
|
||||||
sale.cpp
|
sale.cpp
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef ARTICLE_H
|
#ifndef ARTICLE_H
|
||||||
#define ARTICLE_H
|
#define ARTICLE_H
|
||||||
|
|
||||||
#include "entity.h"
|
#include "entityuuid.h"
|
||||||
//#include "sale.h"
|
//#include "sale.h"
|
||||||
//#include "seller.h"
|
//#include "seller.h"
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
class Seller;
|
class Seller;
|
||||||
class Sale;
|
class Sale;
|
||||||
|
|
||||||
class Article : public Entity
|
class Article : public EntityUuid
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Article() = default;
|
Article() = default;
|
||||||
|
|
|
@ -40,7 +40,6 @@ std::size_t CsvReader::readSellersFromFile(const fs::path& filePath, Marketplace
|
||||||
}
|
}
|
||||||
|
|
||||||
auto seller = std::make_unique<Seller>();
|
auto seller = std::make_unique<Seller>();
|
||||||
seller->createUuid();
|
|
||||||
seller->setSellerNo(row[0].get<int>());
|
seller->setSellerNo(row[0].get<int>());
|
||||||
if (row[1].is_int()) {
|
if (row[1].is_int()) {
|
||||||
seller->setNumArticlesOffered(row[1].get<int>());
|
seller->setNumArticlesOffered(row[1].get<int>());
|
||||||
|
@ -56,10 +55,9 @@ std::size_t CsvReader::readSellersFromFile(const fs::path& filePath, Marketplace
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there was no special seller "Sonderkonto" in import data, then create one
|
// If there was no special seller "Sonderkonto" in import data, then create one
|
||||||
auto specialSeller = market->findSellerWithUuid("11111111-1111-1111-1111-111111111111");
|
auto specialSeller = market->findSellerWithSellerNo(0);
|
||||||
if (!specialSeller) {
|
if (!specialSeller) {
|
||||||
auto seller = std::make_unique<Seller>();
|
auto seller = std::make_unique<Seller>();
|
||||||
seller->setUuidFromString("11111111-1111-1111-1111-111111111111");
|
|
||||||
seller->setSellerNo(0);
|
seller->setSellerNo(0);
|
||||||
seller->setLastName("Sonderkonto");
|
seller->setLastName("Sonderkonto");
|
||||||
seller->setFirstName("Sonderkonto");
|
seller->setFirstName("Sonderkonto");
|
||||||
|
|
|
@ -75,11 +75,10 @@ void Database::createNew()
|
||||||
|
|
||||||
std::string sqlCreateKima2{"CREATE TABLE IF NOT EXISTS kima2 ("
|
std::string sqlCreateKima2{"CREATE TABLE IF NOT EXISTS kima2 ("
|
||||||
"version INTEGER NOT NULL);"
|
"version INTEGER NOT NULL);"
|
||||||
"INSERT INTO kima2 (version) VALUES (2);"};
|
"INSERT INTO kima2 (version) VALUES (3);"};
|
||||||
sqlStrings.push_back(sqlCreateKima2);
|
sqlStrings.push_back(sqlCreateKima2);
|
||||||
std::string sqlCreateSellers{"CREATE TABLE IF NOT EXISTS sellers ("
|
std::string sqlCreateSellers{"CREATE TABLE IF NOT EXISTS sellers ("
|
||||||
"id TEXT PRIMARY KEY NOT NULL, "
|
"seller_no INTEGER PRIMARY KEY NOT NULL, "
|
||||||
"seller_no INTEGER, "
|
|
||||||
"first_name TEXT, "
|
"first_name TEXT, "
|
||||||
"last_name TEXT, "
|
"last_name TEXT, "
|
||||||
"num_offered_articles INTEGER, "
|
"num_offered_articles INTEGER, "
|
||||||
|
@ -89,13 +88,13 @@ void Database::createNew()
|
||||||
std::string sqlCreateArticles{
|
std::string sqlCreateArticles{
|
||||||
"CREATE TABLE IF NOT EXISTS articles ("
|
"CREATE TABLE IF NOT EXISTS articles ("
|
||||||
"id TEXT PRIMARY KEY NOT NULL, "
|
"id TEXT PRIMARY KEY NOT NULL, "
|
||||||
"seller_id TEXT NOT NULL, "
|
"seller_no TEXT NOT NULL, "
|
||||||
"source_no INTEGER NOT NULL, "
|
"source_no INTEGER NOT NULL, "
|
||||||
"article_no INTEGER NOT NULL, "
|
"article_no INTEGER NOT NULL, "
|
||||||
"description TEXT, "
|
"description TEXT, "
|
||||||
"price INTEGER NOT NULL, "
|
"price INTEGER NOT NULL, "
|
||||||
"UNIQUE (source_no, article_no), "
|
"UNIQUE (source_no, article_no), "
|
||||||
"FOREIGN KEY (seller_id) REFERENCES sellers(id) ON DELETE CASCADE, "
|
"FOREIGN KEY (seller_no) REFERENCES sellers(seller_no) ON DELETE CASCADE, "
|
||||||
"CHECK (article_no BETWEEN 0 AND 99999)"
|
"CHECK (article_no BETWEEN 0 AND 99999)"
|
||||||
");"};
|
");"};
|
||||||
sqlStrings.push_back(sqlCreateArticles);
|
sqlStrings.push_back(sqlCreateArticles);
|
||||||
|
@ -115,9 +114,9 @@ void Database::createNew()
|
||||||
sqlStrings.push_back(sqlCreateSalesItems);
|
sqlStrings.push_back(sqlCreateSalesItems);
|
||||||
|
|
||||||
std::string sqlInitialEntries{
|
std::string sqlInitialEntries{
|
||||||
"INSERT OR IGNORE INTO sellers (id, seller_no, first_name, last_name, "
|
"INSERT OR IGNORE INTO sellers (seller_no, first_name, last_name, "
|
||||||
"num_offered_articles) VALUES "
|
"num_offered_articles) VALUES "
|
||||||
"('11111111-1111-1111-1111-111111111111', 0, 'Sonderkonto', 'Sonderkonto', 0)"};
|
"(0, 'Sonderkonto', 'Sonderkonto', 0)"};
|
||||||
sqlStrings.push_back(sqlInitialEntries);
|
sqlStrings.push_back(sqlInitialEntries);
|
||||||
|
|
||||||
beginTransaction();
|
beginTransaction();
|
||||||
|
@ -130,13 +129,18 @@ void Database::createNew()
|
||||||
void Database::updateDbToVer2()
|
void Database::updateDbToVer2()
|
||||||
{
|
{
|
||||||
beginTransaction();
|
beginTransaction();
|
||||||
exec("INSERT OR IGNORE INTO sellers (id, seller_no, first_name, last_name, "
|
exec("INSERT OR IGNORE INTO sellers (seller_no, first_name, last_name, "
|
||||||
"num_offered_articles) VALUES "
|
"num_offered_articles) VALUES "
|
||||||
"('11111111-1111-1111-1111-111111111111', 0, 'Sonderkonto', 'Sonderkonto', 0)");
|
"(0, 'Sonderkonto', 'Sonderkonto', 0)");
|
||||||
exec("UPDATE kima2 SET version = 2");
|
exec("UPDATE kima2 SET version = 3");
|
||||||
endTransaction();
|
endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Database::updateDbToVer3()
|
||||||
|
{
|
||||||
|
newDb();
|
||||||
|
}
|
||||||
|
|
||||||
void Database::init()
|
void Database::init()
|
||||||
{
|
{
|
||||||
const int errCode = sqlite3_open(dbname_.c_str(), &db_);
|
const int errCode = sqlite3_open(dbname_.c_str(), &db_);
|
||||||
|
@ -152,12 +156,19 @@ void Database::init()
|
||||||
switch (version) {
|
switch (version) {
|
||||||
case 0:
|
case 0:
|
||||||
createNew();
|
createNew();
|
||||||
|
initResult_ = InitResult::OK;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
updateDbToVer2();
|
updateDbToVer3();
|
||||||
|
initResult_ = InitResult::OUTDATED_REPLACED;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
updateDbToVer3();
|
||||||
|
initResult_ = InitResult::OUTDATED_REPLACED;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Do nothing because we are up-to-date.
|
// Do nothing because we are up-to-date.
|
||||||
|
initResult_ = InitResult::OK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,16 +236,13 @@ unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& seller
|
||||||
retCode = sqlite3_prepare_v2(
|
retCode = sqlite3_prepare_v2(
|
||||||
db_,
|
db_,
|
||||||
"INSERT INTO sellers"
|
"INSERT INTO sellers"
|
||||||
" (id, seller_no, first_name, last_name, num_offered_articles)"
|
" (seller_no, first_name, last_name, num_offered_articles)"
|
||||||
" VALUES (:uuid, :seller_no, :first_name, :last_name, :num_offered_articles)",
|
" VALUES (:seller_no, :first_name, :last_name, :num_offered_articles)",
|
||||||
-1, &stmt, nullptr);
|
-1, &stmt, nullptr);
|
||||||
|
|
||||||
if (retCode != SQLITE_OK)
|
if (retCode != SQLITE_OK)
|
||||||
throw std::runtime_error(sqlite3_errmsg(db_));
|
throw std::runtime_error(sqlite3_errmsg(db_));
|
||||||
|
|
||||||
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":uuid"),
|
|
||||||
boost::uuids::to_string(seller->getUuid()).c_str(), -1,
|
|
||||||
SQLITE_TRANSIENT);
|
|
||||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_no"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_no"),
|
||||||
seller->getSellerNo());
|
seller->getSellerNo());
|
||||||
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":first_name"),
|
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":first_name"),
|
||||||
|
@ -260,15 +268,14 @@ unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& seller
|
||||||
"UPDATE sellers SET"
|
"UPDATE sellers SET"
|
||||||
" seller_no = :seller_no, first_name = :first_name,"
|
" seller_no = :seller_no, first_name = :first_name,"
|
||||||
" last_name = :last_name, num_offered_articles = :num_offered_articles"
|
" last_name = :last_name, num_offered_articles = :num_offered_articles"
|
||||||
" WHERE id = :uuid",
|
" WHERE seller_no = :id",
|
||||||
-1, &stmt, nullptr);
|
-1, &stmt, nullptr);
|
||||||
|
|
||||||
if (retCode != SQLITE_OK)
|
if (retCode != SQLITE_OK)
|
||||||
throw std::runtime_error(sqlite3_errmsg(db_));
|
throw std::runtime_error(sqlite3_errmsg(db_));
|
||||||
|
|
||||||
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":uuid"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":id"),
|
||||||
boost::uuids::to_string(seller->getUuid()).c_str(), -1,
|
seller->getId());
|
||||||
SQLITE_TRANSIENT);
|
|
||||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_no"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_no"),
|
||||||
seller->getSellerNo());
|
seller->getSellerNo());
|
||||||
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":first_name"),
|
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":first_name"),
|
||||||
|
@ -292,14 +299,13 @@ unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& seller
|
||||||
count += static_cast<int>(seller->getArticles(false).size());
|
count += static_cast<int>(seller->getArticles(false).size());
|
||||||
|
|
||||||
retCode =
|
retCode =
|
||||||
sqlite3_prepare_v2(db_, "DELETE FROM sellers WHERE id = :uuid", -1, &stmt, nullptr);
|
sqlite3_prepare_v2(db_, "DELETE FROM sellers WHERE seller_no = :id", -1, &stmt, nullptr);
|
||||||
|
|
||||||
if (retCode != SQLITE_OK)
|
if (retCode != SQLITE_OK)
|
||||||
throw std::runtime_error(sqlite3_errmsg(db_));
|
throw std::runtime_error(sqlite3_errmsg(db_));
|
||||||
|
|
||||||
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":uuid"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":id"),
|
||||||
boost::uuids::to_string(seller->getUuid()).c_str(), -1,
|
seller->getId());
|
||||||
SQLITE_TRANSIENT);
|
|
||||||
|
|
||||||
retCode = sqlite3_step(stmt);
|
retCode = sqlite3_step(stmt);
|
||||||
|
|
||||||
|
@ -346,7 +352,7 @@ unsigned int Database::storeArticles(std::vector<Article*> articles)
|
||||||
retCode = sqlite3_prepare_v2(
|
retCode = sqlite3_prepare_v2(
|
||||||
db_,
|
db_,
|
||||||
"INSERT INTO articles"
|
"INSERT INTO articles"
|
||||||
" (id, seller_id, source_no, article_no, description, price)"
|
" (id, seller_no, source_no, article_no, description, price)"
|
||||||
" VALUES (:uuid, :seller_id, :source_no, :article_no, :desc, :price)",
|
" VALUES (:uuid, :seller_id, :source_no, :article_no, :desc, :price)",
|
||||||
-1, &stmt, nullptr);
|
-1, &stmt, nullptr);
|
||||||
|
|
||||||
|
@ -356,9 +362,8 @@ unsigned int Database::storeArticles(std::vector<Article*> articles)
|
||||||
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":uuid"),
|
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":uuid"),
|
||||||
boost::uuids::to_string(article->getUuid()).c_str(), -1,
|
boost::uuids::to_string(article->getUuid()).c_str(), -1,
|
||||||
SQLITE_TRANSIENT);
|
SQLITE_TRANSIENT);
|
||||||
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"),
|
||||||
boost::uuids::to_string(article->getSeller()->getUuid()).c_str(), -1,
|
article->getSeller()->getId());
|
||||||
SQLITE_TRANSIENT);
|
|
||||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":source_no"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":source_no"),
|
||||||
article->getSourceNo());
|
article->getSourceNo());
|
||||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":article_no"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":article_no"),
|
||||||
|
@ -382,7 +387,7 @@ unsigned int Database::storeArticles(std::vector<Article*> articles)
|
||||||
retCode = sqlite3_prepare_v2(
|
retCode = sqlite3_prepare_v2(
|
||||||
db_,
|
db_,
|
||||||
"UPDATE articles SET"
|
"UPDATE articles SET"
|
||||||
" seller_id = seller_id, source_no = :source_no, article_no = :article_no,"
|
" seller_no = :seller_id, source_no = :source_no, article_no = :article_no,"
|
||||||
" description = :desc, price = :price"
|
" description = :desc, price = :price"
|
||||||
" WHERE id = :uuid",
|
" WHERE id = :uuid",
|
||||||
-1, &stmt, nullptr);
|
-1, &stmt, nullptr);
|
||||||
|
@ -393,9 +398,8 @@ unsigned int Database::storeArticles(std::vector<Article*> articles)
|
||||||
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":uuid"),
|
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":uuid"),
|
||||||
boost::uuids::to_string(article->getUuid()).c_str(), -1,
|
boost::uuids::to_string(article->getUuid()).c_str(), -1,
|
||||||
SQLITE_TRANSIENT);
|
SQLITE_TRANSIENT);
|
||||||
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"),
|
||||||
boost::uuids::to_string(article->getSeller()->getUuid()).c_str(), -1,
|
article->getSeller()->getId());
|
||||||
SQLITE_TRANSIENT);
|
|
||||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":source_no"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":source_no"),
|
||||||
article->getSourceNo());
|
article->getSourceNo());
|
||||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":article_no"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":article_no"),
|
||||||
|
@ -553,7 +557,7 @@ unsigned int Database::loadSellers(std::vector<std::unique_ptr<Seller>>& sellers
|
||||||
sqlite3_stmt* stmt;
|
sqlite3_stmt* stmt;
|
||||||
|
|
||||||
retCode = sqlite3_prepare_v2(db_,
|
retCode = sqlite3_prepare_v2(db_,
|
||||||
"SELECT id, seller_no, first_name, last_name, "
|
"SELECT seller_no, first_name, last_name, "
|
||||||
"num_offered_articles FROM sellers ORDER BY seller_no",
|
"num_offered_articles FROM sellers ORDER BY seller_no",
|
||||||
-1, &stmt, nullptr);
|
-1, &stmt, nullptr);
|
||||||
if (retCode != SQLITE_OK)
|
if (retCode != SQLITE_OK)
|
||||||
|
@ -566,11 +570,10 @@ unsigned int Database::loadSellers(std::vector<std::unique_ptr<Seller>>& sellers
|
||||||
while (retCode != SQLITE_DONE) {
|
while (retCode != SQLITE_DONE) {
|
||||||
++count;
|
++count;
|
||||||
auto seller = std::make_unique<Seller>();
|
auto seller = std::make_unique<Seller>();
|
||||||
seller->setUuidFromString(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)));
|
seller->setSellerNo(sqlite3_column_int(stmt, 0));
|
||||||
seller->setSellerNo(sqlite3_column_int(stmt, 1));
|
seller->setFirstName(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 1)));
|
||||||
seller->setFirstName(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2)));
|
seller->setLastName(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2)));
|
||||||
seller->setLastName(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3)));
|
seller->setNumArticlesOffered(sqlite3_column_int(stmt, 3));
|
||||||
seller->setNumArticlesOffered(sqlite3_column_int(stmt, 4));
|
|
||||||
seller->setState(Seller::State::OK);
|
seller->setState(Seller::State::OK);
|
||||||
sellers.push_back(std::move(seller));
|
sellers.push_back(std::move(seller));
|
||||||
|
|
||||||
|
@ -583,14 +586,14 @@ unsigned int Database::loadSellers(std::vector<std::unique_ptr<Seller>>& sellers
|
||||||
retCode = sqlite3_prepare_v2(db_,
|
retCode = sqlite3_prepare_v2(db_,
|
||||||
"SELECT id, source_no, article_no, description, price"
|
"SELECT id, source_no, article_no, description, price"
|
||||||
" FROM articles"
|
" FROM articles"
|
||||||
" WHERE seller_id = :seller_uuid"
|
" WHERE seller_no = :seller_id"
|
||||||
" ORDER BY article_no",
|
" ORDER BY article_no",
|
||||||
-1, &stmt, nullptr);
|
-1, &stmt, nullptr);
|
||||||
if (retCode != SQLITE_OK)
|
if (retCode != SQLITE_OK)
|
||||||
throw std::runtime_error(sqlite3_errmsg(db_));
|
throw std::runtime_error(sqlite3_errmsg(db_));
|
||||||
|
|
||||||
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":seller_uuid"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"),
|
||||||
boost::uuids::to_string(seller->getUuid()).c_str(), -1, SQLITE_TRANSIENT);
|
seller->getId());
|
||||||
|
|
||||||
retCode = sqlite3_step(stmt);
|
retCode = sqlite3_step(stmt);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
class Database
|
class Database
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum class InitResult {OK, OUTDATED_REPLACED};
|
||||||
explicit Database(const std::string& dbname);
|
explicit Database(const std::string& dbname);
|
||||||
Database();
|
Database();
|
||||||
~Database();
|
~Database();
|
||||||
|
@ -25,6 +26,7 @@ class Database
|
||||||
std::vector<std::unique_ptr<Seller>>& sellers);
|
std::vector<std::unique_ptr<Seller>>& sellers);
|
||||||
void updateCashPointNo(int oldCashPointNo, int newCashPointNo);
|
void updateCashPointNo(int oldCashPointNo, int newCashPointNo);
|
||||||
void newDb();
|
void newDb();
|
||||||
|
InitResult getInitResult() {return initResult_;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sqlite3* db_{nullptr};
|
sqlite3* db_{nullptr};
|
||||||
|
@ -36,6 +38,8 @@ class Database
|
||||||
int getVersion();
|
int getVersion();
|
||||||
unsigned int storeArticles(std::vector<Article*> articles);
|
unsigned int storeArticles(std::vector<Article*> articles);
|
||||||
void updateDbToVer2();
|
void updateDbToVer2();
|
||||||
|
void updateDbToVer3();
|
||||||
|
InitResult initResult_{InitResult::OK};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DATABASE_H
|
#endif // DATABASE_H
|
|
@ -1,33 +1,6 @@
|
||||||
#include "entity.h"
|
#include "entity.h"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <boost/uuid/uuid_generators.hpp>
|
|
||||||
#include <boost/uuid/uuid_io.hpp>
|
|
||||||
|
|
||||||
Entity::~Entity() = default;
|
|
||||||
|
|
||||||
void Entity::createUuid()
|
|
||||||
{
|
|
||||||
static boost::uuids::random_generator generator{};
|
|
||||||
uuid_ = generator();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Entity::setUuidFromString(const std::string& uuidString)
|
|
||||||
{
|
|
||||||
boost::uuids::string_generator generator{};
|
|
||||||
uuid_ = generator(uuidString);
|
|
||||||
}
|
|
||||||
|
|
||||||
Entity::State Entity::getState() const
|
Entity::State Entity::getState() const
|
||||||
{
|
{
|
||||||
return state_;
|
return state_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::setSourceNo(int sourceNo) {
|
|
||||||
sourceNo_ = sourceNo;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Entity::getSourceNo() const {
|
|
||||||
return sourceNo_;
|
|
||||||
}
|
|
|
@ -1,34 +1,15 @@
|
||||||
#ifndef ENTITY_H
|
#ifndef ENTITY_H
|
||||||
#define ENTITY_H
|
#define ENTITY_H
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <boost/uuid/uuid.hpp>
|
|
||||||
#include <boost/uuid/uuid_io.hpp>
|
|
||||||
|
|
||||||
class Entity
|
class Entity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class State { NEW, UPDATE, DELETE, OK };
|
enum class State { NEW, UPDATE, DELETE, OK };
|
||||||
|
//virtual ~Entity() = 0;
|
||||||
// Entity() = default;
|
|
||||||
virtual ~Entity() = 0;
|
|
||||||
|
|
||||||
void createUuid();
|
|
||||||
void setUuidFromString(const std::string& uuidString);
|
|
||||||
void setState(State state) { state_ = state; }
|
void setState(State state) { state_ = state; }
|
||||||
void setSourceNo(int sourceNo);
|
|
||||||
|
|
||||||
const boost::uuids::uuid& getUuid() const { return uuid_; };
|
|
||||||
std::string getUuidAsString() const { return boost::uuids::to_string(uuid_); }
|
|
||||||
virtual State getState() const;
|
virtual State getState() const;
|
||||||
virtual int getSourceNo() const;
|
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
int sourceNo_{};
|
|
||||||
|
|
||||||
private:
|
|
||||||
boost::uuids::uuid uuid_{};
|
|
||||||
State state_{State::NEW};
|
State state_{State::NEW};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
9
src/core/entityint.cpp
Normal file
9
src/core/entityint.cpp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#include "entityint.h"
|
||||||
|
|
||||||
|
EntityInt::EntityInt(int id) {
|
||||||
|
id_ = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityInt::setId(int id) {
|
||||||
|
id_ = id;
|
||||||
|
}
|
18
src/core/entityint.h
Normal file
18
src/core/entityint.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef ENTITY_INT_H
|
||||||
|
#define ENTITY_INT_H
|
||||||
|
|
||||||
|
#include "entity.h"
|
||||||
|
|
||||||
|
class EntityInt : public Entity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EntityInt() = default;
|
||||||
|
EntityInt(int id);
|
||||||
|
void setId(int id);
|
||||||
|
int getId() const { return id_; };
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int id_{};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ENTITY_INT_H
|
29
src/core/entityuuid.cpp
Normal file
29
src/core/entityuuid.cpp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include "entityuuid.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <boost/uuid/uuid_generators.hpp>
|
||||||
|
#include <boost/uuid/uuid_io.hpp>
|
||||||
|
|
||||||
|
EntityUuid::~EntityUuid() = default;
|
||||||
|
|
||||||
|
void EntityUuid::createUuid()
|
||||||
|
{
|
||||||
|
static boost::uuids::random_generator generator{};
|
||||||
|
uuid_ = generator();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityUuid::setUuidFromString(const std::string& uuidString)
|
||||||
|
{
|
||||||
|
boost::uuids::string_generator generator{};
|
||||||
|
uuid_ = generator(uuidString);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void EntityUuid::setSourceNo(int sourceNo) {
|
||||||
|
sourceNo_ = sourceNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
int EntityUuid::getSourceNo() const {
|
||||||
|
return sourceNo_;
|
||||||
|
}
|
32
src/core/entityuuid.h
Normal file
32
src/core/entityuuid.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#ifndef ENTITY_UUID_H
|
||||||
|
#define ENTITY_UUID_H
|
||||||
|
|
||||||
|
#include "entity.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <boost/uuid/uuid.hpp>
|
||||||
|
#include <boost/uuid/uuid_io.hpp>
|
||||||
|
|
||||||
|
class EntityUuid : public Entity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Entity() = default;
|
||||||
|
virtual ~EntityUuid() = 0;
|
||||||
|
|
||||||
|
void createUuid();
|
||||||
|
void setUuidFromString(const std::string& uuidString);
|
||||||
|
void setSourceNo(int sourceNo);
|
||||||
|
|
||||||
|
const boost::uuids::uuid& getUuid() const { return uuid_; };
|
||||||
|
std::string getUuidAsString() const { return boost::uuids::to_string(uuid_); }
|
||||||
|
virtual int getSourceNo() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int sourceNo_{};
|
||||||
|
|
||||||
|
private:
|
||||||
|
boost::uuids::uuid uuid_{};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ENTITY_UUID_H
|
|
@ -39,7 +39,6 @@ std::size_t ExcelReader::readSellersFromFile(const fs::path& filePath, Marketpla
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto seller = std::make_unique<Seller>();
|
auto seller = std::make_unique<Seller>();
|
||||||
seller->createUuid();
|
|
||||||
seller->setSellerNo(row[0].value<int>());
|
seller->setSellerNo(row[0].value<int>());
|
||||||
seller->setNumArticlesOffered(row[1].value<int>());
|
seller->setNumArticlesOffered(row[1].value<int>());
|
||||||
std::string firstName = row[2].value<std::string>();
|
std::string firstName = row[2].value<std::string>();
|
||||||
|
@ -51,10 +50,9 @@ std::size_t ExcelReader::readSellersFromFile(const fs::path& filePath, Marketpla
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there was no special seller "Sonderkonto" in import data, then create one
|
// If there was no special seller "Sonderkonto" in import data, then create one
|
||||||
auto specialSeller = market->findSellerWithUuid("11111111-1111-1111-1111-111111111111");
|
auto specialSeller = market->findSellerWithSellerNo(0);
|
||||||
if (!specialSeller) {
|
if (!specialSeller) {
|
||||||
auto seller = std::make_unique<Seller>();
|
auto seller = std::make_unique<Seller>();
|
||||||
seller->setUuidFromString("11111111-1111-1111-1111-111111111111");
|
|
||||||
seller->setSellerNo(0);
|
seller->setSellerNo(0);
|
||||||
seller->setLastName("Sonderkonto");
|
seller->setLastName("Sonderkonto");
|
||||||
seller->setFirstName("Sonderkonto");
|
seller->setFirstName("Sonderkonto");
|
||||||
|
|
|
@ -15,7 +15,6 @@ void JsonUtil::exportSellers(const std::filesystem::path& filePath, Marketplace*
|
||||||
|
|
||||||
for (const auto& seller : market->getSellers()) {
|
for (const auto& seller : market->getSellers()) {
|
||||||
json newEntry;
|
json newEntry;
|
||||||
newEntry["uuid"] = seller->getUuidAsString();
|
|
||||||
newEntry["seller_no"] = seller->getSellerNo();
|
newEntry["seller_no"] = seller->getSellerNo();
|
||||||
newEntry["last_name"] = seller->getLastName();
|
newEntry["last_name"] = seller->getLastName();
|
||||||
newEntry["first_name"] = seller->getFirstName();
|
newEntry["first_name"] = seller->getFirstName();
|
||||||
|
@ -38,7 +37,6 @@ void JsonUtil::importSellers(const std::filesystem::path& filePath, Marketplace*
|
||||||
|
|
||||||
for (auto val : jsonValues["sellers"]) {
|
for (auto val : jsonValues["sellers"]) {
|
||||||
auto seller = std::make_unique<Seller>();
|
auto seller = std::make_unique<Seller>();
|
||||||
seller->setUuidFromString(val["uuid"]);
|
|
||||||
seller->setSellerNo(val["seller_no"]);
|
seller->setSellerNo(val["seller_no"]);
|
||||||
seller->setLastName(val["last_name"]);
|
seller->setLastName(val["last_name"]);
|
||||||
seller->setFirstName(val["first_name"]);
|
seller->setFirstName(val["first_name"]);
|
||||||
|
@ -47,10 +45,9 @@ void JsonUtil::importSellers(const std::filesystem::path& filePath, Marketplace*
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there was no special seller "Sonderkonto" in import data, then create one
|
// If there was no special seller "Sonderkonto" in import data, then create one
|
||||||
auto specialSeller = market->findSellerWithUuid("11111111-1111-1111-1111-111111111111");
|
auto specialSeller = market->findSellerWithSellerNo(0);
|
||||||
if (!specialSeller) {
|
if (!specialSeller) {
|
||||||
auto seller = std::make_unique<Seller>();
|
auto seller = std::make_unique<Seller>();
|
||||||
seller->setUuidFromString("11111111-1111-1111-1111-111111111111");
|
|
||||||
seller->setSellerNo(0);
|
seller->setSellerNo(0);
|
||||||
seller->setLastName("Sonderkonto");
|
seller->setLastName("Sonderkonto");
|
||||||
seller->setFirstName("Sonderkonto");
|
seller->setFirstName("Sonderkonto");
|
||||||
|
@ -81,7 +78,7 @@ void JsonUtil::exportSales(const std::filesystem::path& filePath, Marketplace* m
|
||||||
for (const auto& article : sale->getArticles()) {
|
for (const auto& article : sale->getArticles()) {
|
||||||
json newArticle;
|
json newArticle;
|
||||||
newArticle["uuid"] = article->getUuidAsString();
|
newArticle["uuid"] = article->getUuidAsString();
|
||||||
newArticle["seller_uuid"] = article->getSeller()->getUuidAsString();
|
newArticle["seller_no"] = article->getSeller()->getSellerNo();
|
||||||
newArticle["desc"] = article->getDescription();
|
newArticle["desc"] = article->getDescription();
|
||||||
newArticle["price"] = article->getPrice();
|
newArticle["price"] = article->getPrice();
|
||||||
// newArticle["source_no"] = article->getSourceNo();
|
// newArticle["source_no"] = article->getSourceNo();
|
||||||
|
@ -122,7 +119,7 @@ void JsonUtil::importSales(const std::filesystem::path& filePath, Marketplace* m
|
||||||
article->setArticleNo(valArticle["article_no"]);
|
article->setArticleNo(valArticle["article_no"]);
|
||||||
article->setDescription(valArticle["desc"]);
|
article->setDescription(valArticle["desc"]);
|
||||||
article->setPrice(valArticle["price"]);
|
article->setPrice(valArticle["price"]);
|
||||||
auto seller = market->findSellerWithUuid(valArticle["seller_uuid"]);
|
auto seller = market->findSellerWithSellerNo(valArticle["seller_no"]);
|
||||||
if (seller == nullptr) {
|
if (seller == nullptr) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"Die zu importierenden Daten verweisen auf einen nicht vorhandenen Verkäufer. "
|
"Die zu importierenden Daten verweisen auf einen nicht vorhandenen Verkäufer. "
|
||||||
|
|
|
@ -13,9 +13,9 @@ namespace fs = std::filesystem;
|
||||||
|
|
||||||
Marketplace::Marketplace()
|
Marketplace::Marketplace()
|
||||||
{
|
{
|
||||||
auto seller = std::make_unique<Seller>("Max", "Mustermann");
|
/*auto seller = std::make_unique<Seller>("Max", "Mustermann");
|
||||||
seller->createUuid();
|
seller->createUuid();
|
||||||
sellers_.push_back(std::move(seller));
|
sellers_.push_back(std::move(seller)); */
|
||||||
}
|
}
|
||||||
|
|
||||||
void Marketplace::storeToDb(bool onlyDelete)
|
void Marketplace::storeToDb(bool onlyDelete)
|
||||||
|
@ -25,11 +25,12 @@ void Marketplace::storeToDb(bool onlyDelete)
|
||||||
db.storeSales(sales_);
|
db.storeSales(sales_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Marketplace::loadFromDb()
|
Database::InitResult Marketplace::loadFromDb()
|
||||||
{
|
{
|
||||||
Database db;
|
Database db;
|
||||||
db.loadSellers(sellers_);
|
db.loadSellers(sellers_);
|
||||||
db.loadSales(sales_, sellers_);
|
db.loadSales(sales_, sellers_);
|
||||||
|
return db.getInitResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
SellersVec& Marketplace::getSellers() { return sellers_; }
|
SellersVec& Marketplace::getSellers() { return sellers_; }
|
||||||
|
@ -103,6 +104,7 @@ Seller* Marketplace::findSellerWithSellerNo(int sellerNo)
|
||||||
return (*iter).get();
|
return (*iter).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
Seller* Marketplace::findSellerWithUuid(const std::string& uuid)
|
Seller* Marketplace::findSellerWithUuid(const std::string& uuid)
|
||||||
{
|
{
|
||||||
auto iter = std::find_if(sellers_.begin(), sellers_.end(),
|
auto iter = std::find_if(sellers_.begin(), sellers_.end(),
|
||||||
|
@ -111,6 +113,7 @@ Seller* Marketplace::findSellerWithUuid(const std::string& uuid)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return (*iter).get();
|
return (*iter).get();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
|
void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef MARKETPLACE_H
|
#ifndef MARKETPLACE_H
|
||||||
#define MARKETPLACE_H
|
#define MARKETPLACE_H
|
||||||
|
|
||||||
|
#include "database.h"
|
||||||
#include "article.h"
|
#include "article.h"
|
||||||
#include "sale.h"
|
#include "sale.h"
|
||||||
#include "seller.h"
|
#include "seller.h"
|
||||||
|
@ -23,7 +24,7 @@ class Marketplace
|
||||||
Marketplace();
|
Marketplace();
|
||||||
|
|
||||||
void storeToDb(bool onlyDelete = false);
|
void storeToDb(bool onlyDelete = false);
|
||||||
void loadFromDb();
|
Database::InitResult loadFromDb();
|
||||||
|
|
||||||
SellersVec& getSellers();
|
SellersVec& getSellers();
|
||||||
SalesVec& getSales();
|
SalesVec& getSales();
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace
|
||||||
using ArticlesVec = std::vector<Article*>;
|
using ArticlesVec = std::vector<Article*>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sale : public Entity
|
class Sale : public EntityUuid
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void addArticle(Article* articlePtr);
|
void addArticle(Article* articlePtr);
|
||||||
|
|
|
@ -7,15 +7,14 @@
|
||||||
|
|
||||||
Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo,
|
Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo,
|
||||||
int numArticlesOffered)
|
int numArticlesOffered)
|
||||||
: Entity()
|
: EntityInt(sellerNo)
|
||||||
{
|
{
|
||||||
firstName_ = firstName;
|
firstName_ = firstName;
|
||||||
lastName_ = lastName;
|
lastName_ = lastName;
|
||||||
sellerNo_ = sellerNo;
|
|
||||||
numArticlesOffered_ = numArticlesOffered;
|
numArticlesOffered_ = numArticlesOffered;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Seller::setSellerNo(int seller_no) { sellerNo_ = seller_no; }
|
void Seller::setSellerNo(int seller_no) { setId(seller_no); }
|
||||||
|
|
||||||
void Seller::setFirstName(const std::string& firstName) { firstName_ = firstName; }
|
void Seller::setFirstName(const std::string& firstName) { firstName_ = firstName; }
|
||||||
|
|
||||||
|
@ -33,13 +32,13 @@ std::string Seller::getFirstName() const { return firstName_; }
|
||||||
|
|
||||||
std::string Seller::getLastName() const { return lastName_; }
|
std::string Seller::getLastName() const { return lastName_; }
|
||||||
|
|
||||||
int Seller::getSellerNo() const { return sellerNo_; }
|
int Seller::getSellerNo() const { return getId(); }
|
||||||
|
|
||||||
std::string Seller::getSellerNoAsString() const
|
std::string Seller::getSellerNoAsString() const
|
||||||
{
|
{
|
||||||
std::stringstream selNoStr;
|
std::stringstream selNoStr;
|
||||||
|
|
||||||
selNoStr << std::setfill('0') << std::setw(3) << sellerNo_;
|
selNoStr << std::setfill('0') << std::setw(3) << id_;
|
||||||
|
|
||||||
return selNoStr.str();
|
return selNoStr.str();
|
||||||
;
|
;
|
||||||
|
@ -104,8 +103,8 @@ int Seller::sumInCents()
|
||||||
|
|
||||||
std::string Seller::sumAsString() { return formatCentAsEuroString(sumInCents()); }
|
std::string Seller::sumAsString() { return formatCentAsEuroString(sumInCents()); }
|
||||||
|
|
||||||
bool operator<(const Seller& li, const Seller& re) { return li.sellerNo_ < re.sellerNo_; }
|
bool operator<(const Seller& li, const Seller& re) { return li.id_ < re.id_; }
|
||||||
bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re)
|
bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re)
|
||||||
{
|
{
|
||||||
return li->sellerNo_ < re->sellerNo_;
|
return li->id_ < re->id_;
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
#define SELLER_H
|
#define SELLER_H
|
||||||
|
|
||||||
#include "article.h"
|
#include "article.h"
|
||||||
#include "entity.h"
|
#include "entityint.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -10,11 +10,11 @@
|
||||||
|
|
||||||
// class Article;
|
// class Article;
|
||||||
|
|
||||||
class Seller : public Entity
|
class Seller : public EntityInt
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Seller() = default;
|
Seller() = default;
|
||||||
// virtual ~Seller() = default;
|
~Seller() = default;
|
||||||
Seller(const std::string& firstName, const std::string& lastName, int sellerNo = 0,
|
Seller(const std::string& firstName, const std::string& lastName, int sellerNo = 0,
|
||||||
int numArticlesOffered = 0);
|
int numArticlesOffered = 0);
|
||||||
|
|
||||||
|
@ -42,7 +42,6 @@ class Seller : public Entity
|
||||||
friend bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re);
|
friend bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int sellerNo_{-1};
|
|
||||||
int numArticlesOffered_{};
|
int numArticlesOffered_{};
|
||||||
std::string firstName_{};
|
std::string firstName_{};
|
||||||
std::string lastName_{};
|
std::string lastName_{};
|
||||||
|
|
|
@ -35,7 +35,13 @@ MainWindow::MainWindow()
|
||||||
ui_.setupUi(this);
|
ui_.setupUi(this);
|
||||||
|
|
||||||
marketplace_ = std::make_unique<Marketplace>();
|
marketplace_ = std::make_unique<Marketplace>();
|
||||||
marketplace_->loadFromDb();
|
Database::InitResult res = marketplace_->loadFromDb();
|
||||||
|
if (res == Database::InitResult::OUTDATED_REPLACED) {
|
||||||
|
QMessageBox(QMessageBox::Icon::Information, "Datenbankinformation",
|
||||||
|
"Es wurde eine <b>veraltete</b> Datenbankdatei erkannt.<br />Diese wurde "
|
||||||
|
"umbenannt und eine <b>neue</b> Datei wurde erstellt.")
|
||||||
|
.exec();
|
||||||
|
}
|
||||||
statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT);
|
statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT);
|
||||||
|
|
||||||
BasketModel* model = new BasketModel(getMarketplace(), ui_.basketView);
|
BasketModel* model = new BasketModel(getMarketplace(), ui_.basketView);
|
||||||
|
@ -449,14 +455,6 @@ void MainWindow::onImportSellerExcelActionTriggered()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMessageBox(
|
|
||||||
QMessageBox::Icon::Information, "Bitte beachten",
|
|
||||||
"<b>Achtung:</b> Importieren Sie die Verkäuferdaten nur auf <b>einer (!)</b> "
|
|
||||||
"KIMA2-Installation.<br /> "
|
|
||||||
"Verteilen Sie die Daten auf die anderen Installationen unbedingt über eine JSON-Datei!",
|
|
||||||
QMessageBox::StandardButton::Ok, this)
|
|
||||||
.exec();
|
|
||||||
|
|
||||||
auto filename = QFileDialog::getOpenFileName(
|
auto filename = QFileDialog::getOpenFileName(
|
||||||
this, "Verkäufer importieren", QString(),
|
this, "Verkäufer importieren", QString(),
|
||||||
"Alle unterstützte Dateien (*.xlsx *.csv);;Excel Dateien (*.xlsx);;CSV Dateien (*.csv)");
|
"Alle unterstützte Dateien (*.xlsx *.csv);;Excel Dateien (*.xlsx);;CSV Dateien (*.csv)");
|
||||||
|
|
|
@ -102,7 +102,7 @@ void ReportDialog::onPrintReportButtonClicked()
|
||||||
for (unsigned int j = 0;
|
for (unsigned int j = 0;
|
||||||
j < ENTRIES_PER_PAGE && (i - 1) * ENTRIES_PER_PAGE + j < sellers.size(); ++j) {
|
j < ENTRIES_PER_PAGE && (i - 1) * ENTRIES_PER_PAGE + j < sellers.size(); ++j) {
|
||||||
int idx = (i - 1) * ENTRIES_PER_PAGE + j;
|
int idx = (i - 1) * ENTRIES_PER_PAGE + j;
|
||||||
if (sellers.at(idx)->getUuidAsString() == "11111111-1111-1111-1111-111111111111") {
|
if (sellers.at(idx)->getId() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
content += QString("%1 %2 %3 %4 %5 %6 %7\n")
|
content += QString("%1 %2 %3 %4 %5 %6 %7\n")
|
||||||
|
@ -121,7 +121,7 @@ void ReportDialog::onPrintReportButtonClicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
// pieces booked on the special account "Sonderkonto"
|
// pieces booked on the special account "Sonderkonto"
|
||||||
const auto specialSeller = market_->findSellerWithUuid("11111111-1111-1111-1111-111111111111");
|
const auto specialSeller = market_->findSellerWithSellerNo(0);
|
||||||
if (specialSeller && specialSeller->numArticlesSold() > 0) {
|
if (specialSeller && specialSeller->numArticlesSold() > 0) {
|
||||||
printer.newPage();
|
printer.newPage();
|
||||||
painter.setFont(QFont("Arial", 16, QFont::Bold));
|
painter.setFont(QFont("Arial", 16, QFont::Bold));
|
||||||
|
|
|
@ -59,7 +59,7 @@ QVariant ReportModel::data(const QModelIndex& index, int role) const
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
return seller->getUuidAsString().c_str();
|
return seller->getId();
|
||||||
case 1:
|
case 1:
|
||||||
return seller->getSellerNo();
|
return seller->getSellerNo();
|
||||||
case 2:
|
case 2:
|
||||||
|
|
|
@ -44,7 +44,7 @@ QModelIndex SaleModel::parent(const QModelIndex& index) const
|
||||||
Sale* sale{};
|
Sale* sale{};
|
||||||
Article* article{};
|
Article* article{};
|
||||||
|
|
||||||
Entity* ent = static_cast<Entity*>(index.internalPointer());
|
EntityUuid* ent = static_cast<EntityUuid*>(index.internalPointer());
|
||||||
|
|
||||||
sale = dynamic_cast<Sale*>(ent);
|
sale = dynamic_cast<Sale*>(ent);
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ QVariant SellerModel::data(const QModelIndex& index, int role) const
|
||||||
*/
|
*/
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
return seller->getUuidAsString().c_str();
|
return seller->getId();
|
||||||
case 1:
|
case 1:
|
||||||
return seller->getSellerNo();
|
return seller->getSellerNo();
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -85,7 +85,7 @@ bool SellerModel::setData(const QModelIndex& index, const QVariant& value, int r
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
seller->setUuidFromString(value.toString().toStdString());
|
seller->setId(value.toInt());
|
||||||
break;
|
break;
|
||||||
case 1: {
|
case 1: {
|
||||||
if (value.toInt() < 0)
|
if (value.toInt() < 0)
|
||||||
|
@ -126,7 +126,6 @@ bool SellerModel::insertRows(int row, int count, const QModelIndex& parent)
|
||||||
{
|
{
|
||||||
emit beginInsertRows(parent, row, row + count - 1);
|
emit beginInsertRows(parent, row, row + count - 1);
|
||||||
auto seller = std::make_unique<Seller>();
|
auto seller = std::make_unique<Seller>();
|
||||||
seller->createUuid();
|
|
||||||
seller->setSellerNo(marketplace_->getNextSellerNo());
|
seller->setSellerNo(marketplace_->getNextSellerNo());
|
||||||
marketplace_->getSellers().push_back(std::move(seller));
|
marketplace_->getSellers().push_back(std::move(seller));
|
||||||
emit endInsertRows();
|
emit endInsertRows();
|
||||||
|
@ -142,7 +141,7 @@ bool SellerModel::removeRows(int row, int count, const QModelIndex& parent)
|
||||||
marketplace_->getSellers().erase(
|
marketplace_->getSellers().erase(
|
||||||
std::remove_if(marketplace_->getSellers().begin(), marketplace_->getSellers().end(),
|
std::remove_if(marketplace_->getSellers().begin(), marketplace_->getSellers().end(),
|
||||||
[&seller](const std::unique_ptr<Seller>& a) {
|
[&seller](const std::unique_ptr<Seller>& a) {
|
||||||
return a->getUuid() == seller->getUuid();
|
return a->getId() == seller->getId();
|
||||||
}),
|
}),
|
||||||
marketplace_->getSellers().end());
|
marketplace_->getSellers().end());
|
||||||
emit endRemoveRows();
|
emit endRemoveRows();
|
||||||
|
|
|
@ -9,14 +9,14 @@
|
||||||
BOOST_AUTO_TEST_CASE(create_uuid_nil)
|
BOOST_AUTO_TEST_CASE(create_uuid_nil)
|
||||||
{
|
{
|
||||||
Seller seller{};
|
Seller seller{};
|
||||||
BOOST_TEST(seller.getUuid().is_nil() == true);
|
BOOST_TEST(seller.getId().is_nil() == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(create_uuid)
|
BOOST_AUTO_TEST_CASE(create_uuid)
|
||||||
{
|
{
|
||||||
Seller seller{};
|
Seller seller{};
|
||||||
seller.createUuid();
|
seller.createUuid();
|
||||||
BOOST_TEST(seller.getUuid().is_nil() == false);
|
BOOST_TEST(seller.getId().is_nil() == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(create_many)
|
BOOST_AUTO_TEST_CASE(create_many)
|
||||||
|
@ -25,7 +25,7 @@ BOOST_AUTO_TEST_CASE(create_many)
|
||||||
std::array<Seller, QUANTITY> sellers;
|
std::array<Seller, QUANTITY> sellers;
|
||||||
for (unsigned i = 0; i < sellers.size(); i++) {
|
for (unsigned i = 0; i < sellers.size(); i++) {
|
||||||
sellers[i] = Seller();
|
sellers[i] = Seller();
|
||||||
sellers[i].createUuid();
|
//sellers[i].createUuid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue