diff --git a/CMakeLists.txt b/CMakeLists.txt index 5aa0bb0..aab6d76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.8) -project(kima2 VERSION 1.5.0) +project(kima2 VERSION 1.4.2) set(CMAKE_MODULE_PATH "${CMAKE_HOME_DIRECTORY}/cmake") @@ -12,8 +12,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) if(MSVC) add_compile_options(/W4 /WX) else() - #add_compile_options(-Wall -Wextra -pedantic -Woverloaded-virtual -Wredundant-decls -Wshadow) - add_compile_options(-Wall -Wextra) + add_compile_options(-Wall -Wextra -pedantic -Woverloaded-virtual -Wredundant-decls -Wshadow) endif() configure_file(config.h.in ${PROJECT_BINARY_DIR}/config.h) @@ -31,11 +30,11 @@ endif() add_subdirectory(3rdparty) add_subdirectory(src) -#if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES Debug) -# include(CTest) -# enable_testing() -# add_subdirectory(test) -#endif() +if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES Debug) + include(CTest) + enable_testing() + add_subdirectory(test) +endif() # CPack diff --git a/manual/Benutzerhandbuch.odt b/manual/Benutzerhandbuch.odt index cb1354e..ab245ce 100644 Binary files a/manual/Benutzerhandbuch.odt and b/manual/Benutzerhandbuch.odt differ diff --git a/manual/Benutzerhandbuch.pdf b/manual/Benutzerhandbuch.pdf index 86442af..e4966fc 100644 Binary files a/manual/Benutzerhandbuch.pdf and b/manual/Benutzerhandbuch.pdf differ diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 504d0c3..3d9fa92 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -13,8 +13,6 @@ endif (MINGW) set(CORE_SOURCES database.cpp entity.cpp - entityint.cpp - entityuuid.cpp seller.cpp article.cpp sale.cpp diff --git a/src/core/article.h b/src/core/article.h index 50c0a9d..a497242 100644 --- a/src/core/article.h +++ b/src/core/article.h @@ -1,7 +1,7 @@ #ifndef ARTICLE_H #define ARTICLE_H -#include "entityuuid.h" +#include "entity.h" //#include "sale.h" //#include "seller.h" @@ -11,7 +11,7 @@ class Seller; class Sale; -class Article : public EntityUuid +class Article : public Entity { public: Article() = default; @@ -41,4 +41,4 @@ class Article : public EntityUuid std::string description_{}; }; -#endif +#endif \ No newline at end of file diff --git a/src/core/csvreader.cpp b/src/core/csvreader.cpp index 73f95e1..ea0eea4 100644 --- a/src/core/csvreader.cpp +++ b/src/core/csvreader.cpp @@ -40,6 +40,7 @@ std::size_t CsvReader::readSellersFromFile(const fs::path& filePath, Marketplace } auto seller = std::make_unique(); + seller->createUuid(); seller->setSellerNo(row[0].get()); if (row[1].is_int()) { seller->setNumArticlesOffered(row[1].get()); @@ -55,9 +56,10 @@ std::size_t CsvReader::readSellersFromFile(const fs::path& filePath, Marketplace } // If there was no special seller "Sonderkonto" in import data, then create one - auto specialSeller = market->findSellerWithSellerNo(0); + auto specialSeller = market->findSellerWithUuid("11111111-1111-1111-1111-111111111111"); if (!specialSeller) { auto seller = std::make_unique(); + seller->setUuidFromString("11111111-1111-1111-1111-111111111111"); seller->setSellerNo(0); seller->setLastName("Sonderkonto"); seller->setFirstName("Sonderkonto"); diff --git a/src/core/database.cpp b/src/core/database.cpp index f95deae..123c467 100644 --- a/src/core/database.cpp +++ b/src/core/database.cpp @@ -75,10 +75,11 @@ void Database::createNew() std::string sqlCreateKima2{"CREATE TABLE IF NOT EXISTS kima2 (" "version INTEGER NOT NULL);" - "INSERT INTO kima2 (version) VALUES (3);"}; + "INSERT INTO kima2 (version) VALUES (2);"}; sqlStrings.push_back(sqlCreateKima2); std::string sqlCreateSellers{"CREATE TABLE IF NOT EXISTS sellers (" - "seller_no INTEGER PRIMARY KEY NOT NULL, " + "id TEXT PRIMARY KEY NOT NULL, " + "seller_no INTEGER, " "first_name TEXT, " "last_name TEXT, " "num_offered_articles INTEGER, " @@ -88,13 +89,13 @@ void Database::createNew() std::string sqlCreateArticles{ "CREATE TABLE IF NOT EXISTS articles (" "id TEXT PRIMARY KEY NOT NULL, " - "seller_no TEXT NOT NULL, " + "seller_id TEXT NOT NULL, " "source_no INTEGER NOT NULL, " "article_no INTEGER NOT NULL, " "description TEXT, " "price INTEGER NOT NULL, " "UNIQUE (source_no, article_no), " - "FOREIGN KEY (seller_no) REFERENCES sellers(seller_no) ON DELETE CASCADE, " + "FOREIGN KEY (seller_id) REFERENCES sellers(id) ON DELETE CASCADE, " "CHECK (article_no BETWEEN 0 AND 99999)" ");"}; sqlStrings.push_back(sqlCreateArticles); @@ -114,9 +115,9 @@ void Database::createNew() sqlStrings.push_back(sqlCreateSalesItems); std::string sqlInitialEntries{ - "INSERT OR IGNORE INTO sellers (seller_no, first_name, last_name, " + "INSERT OR IGNORE INTO sellers (id, seller_no, first_name, last_name, " "num_offered_articles) VALUES " - "(0, 'Sonderkonto', 'Sonderkonto', 0)"}; + "('11111111-1111-1111-1111-111111111111', 0, 'Sonderkonto', 'Sonderkonto', 0)"}; sqlStrings.push_back(sqlInitialEntries); beginTransaction(); @@ -129,18 +130,13 @@ void Database::createNew() void Database::updateDbToVer2() { beginTransaction(); - exec("INSERT OR IGNORE INTO sellers (seller_no, first_name, last_name, " + exec("INSERT OR IGNORE INTO sellers (id, seller_no, first_name, last_name, " "num_offered_articles) VALUES " - "(0, 'Sonderkonto', 'Sonderkonto', 0)"); - exec("UPDATE kima2 SET version = 3"); + "('11111111-1111-1111-1111-111111111111', 0, 'Sonderkonto', 'Sonderkonto', 0)"); + exec("UPDATE kima2 SET version = 2"); endTransaction(); } -void Database::updateDbToVer3() -{ - newDb(); -} - void Database::init() { const int errCode = sqlite3_open(dbname_.c_str(), &db_); @@ -156,19 +152,12 @@ void Database::init() switch (version) { case 0: createNew(); - initResult_ = InitResult::OK; break; case 1: - updateDbToVer3(); - initResult_ = InitResult::OUTDATED_REPLACED; - break; - case 2: - updateDbToVer3(); - initResult_ = InitResult::OUTDATED_REPLACED; + updateDbToVer2(); break; default: // Do nothing because we are up-to-date. - initResult_ = InitResult::OK; break; } } @@ -236,13 +225,16 @@ unsigned int Database::storeSellers(std::vector>& seller retCode = sqlite3_prepare_v2( db_, "INSERT INTO sellers" - " (seller_no, first_name, last_name, num_offered_articles)" - " VALUES (:seller_no, :first_name, :last_name, :num_offered_articles)", + " (id, seller_no, first_name, last_name, num_offered_articles)" + " VALUES (:uuid, :seller_no, :first_name, :last_name, :num_offered_articles)", -1, &stmt, nullptr); if (retCode != SQLITE_OK) 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"), seller->getSellerNo()); sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":first_name"), @@ -268,14 +260,15 @@ unsigned int Database::storeSellers(std::vector>& seller "UPDATE sellers SET" " seller_no = :seller_no, first_name = :first_name," " last_name = :last_name, num_offered_articles = :num_offered_articles" - " WHERE seller_no = :id", + " WHERE id = :uuid", -1, &stmt, nullptr); if (retCode != SQLITE_OK) throw std::runtime_error(sqlite3_errmsg(db_)); - sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":id"), - seller->getId()); + 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"), seller->getSellerNo()); sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":first_name"), @@ -299,13 +292,14 @@ unsigned int Database::storeSellers(std::vector>& seller count += static_cast(seller->getArticles(false).size()); retCode = - sqlite3_prepare_v2(db_, "DELETE FROM sellers WHERE seller_no = :id", -1, &stmt, nullptr); + sqlite3_prepare_v2(db_, "DELETE FROM sellers WHERE id = :uuid", -1, &stmt, nullptr); if (retCode != SQLITE_OK) throw std::runtime_error(sqlite3_errmsg(db_)); - sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":id"), - seller->getId()); + sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":uuid"), + boost::uuids::to_string(seller->getUuid()).c_str(), -1, + SQLITE_TRANSIENT); retCode = sqlite3_step(stmt); @@ -352,7 +346,7 @@ unsigned int Database::storeArticles(std::vector articles) retCode = sqlite3_prepare_v2( db_, "INSERT INTO articles" - " (id, seller_no, source_no, article_no, description, price)" + " (id, seller_id, source_no, article_no, description, price)" " VALUES (:uuid, :seller_id, :source_no, :article_no, :desc, :price)", -1, &stmt, nullptr); @@ -362,8 +356,9 @@ unsigned int Database::storeArticles(std::vector articles) sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":uuid"), boost::uuids::to_string(article->getUuid()).c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"), - article->getSeller()->getId()); + sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"), + boost::uuids::to_string(article->getSeller()->getUuid()).c_str(), -1, + SQLITE_TRANSIENT); sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":source_no"), article->getSourceNo()); sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":article_no"), @@ -387,7 +382,7 @@ unsigned int Database::storeArticles(std::vector articles) retCode = sqlite3_prepare_v2( db_, "UPDATE articles SET" - " seller_no = :seller_id, source_no = :source_no, article_no = :article_no," + " seller_id = seller_id, source_no = :source_no, article_no = :article_no," " description = :desc, price = :price" " WHERE id = :uuid", -1, &stmt, nullptr); @@ -398,8 +393,9 @@ unsigned int Database::storeArticles(std::vector articles) sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":uuid"), boost::uuids::to_string(article->getUuid()).c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"), - article->getSeller()->getId()); + sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"), + boost::uuids::to_string(article->getSeller()->getUuid()).c_str(), -1, + SQLITE_TRANSIENT); sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":source_no"), article->getSourceNo()); sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":article_no"), @@ -557,7 +553,7 @@ unsigned int Database::loadSellers(std::vector>& sellers sqlite3_stmt* stmt; retCode = sqlite3_prepare_v2(db_, - "SELECT seller_no, first_name, last_name, " + "SELECT id, seller_no, first_name, last_name, " "num_offered_articles FROM sellers ORDER BY seller_no", -1, &stmt, nullptr); if (retCode != SQLITE_OK) @@ -570,10 +566,11 @@ unsigned int Database::loadSellers(std::vector>& sellers while (retCode != SQLITE_DONE) { ++count; auto seller = std::make_unique(); - seller->setSellerNo(sqlite3_column_int(stmt, 0)); - seller->setFirstName(reinterpret_cast(sqlite3_column_text(stmt, 1))); - seller->setLastName(reinterpret_cast(sqlite3_column_text(stmt, 2))); - seller->setNumArticlesOffered(sqlite3_column_int(stmt, 3)); + seller->setUuidFromString(reinterpret_cast(sqlite3_column_text(stmt, 0))); + seller->setSellerNo(sqlite3_column_int(stmt, 1)); + seller->setFirstName(reinterpret_cast(sqlite3_column_text(stmt, 2))); + seller->setLastName(reinterpret_cast(sqlite3_column_text(stmt, 3))); + seller->setNumArticlesOffered(sqlite3_column_int(stmt, 4)); seller->setState(Seller::State::OK); sellers.push_back(std::move(seller)); @@ -586,14 +583,14 @@ unsigned int Database::loadSellers(std::vector>& sellers retCode = sqlite3_prepare_v2(db_, "SELECT id, source_no, article_no, description, price" " FROM articles" - " WHERE seller_no = :seller_id" + " WHERE seller_id = :seller_uuid" " ORDER BY article_no", -1, &stmt, nullptr); if (retCode != SQLITE_OK) throw std::runtime_error(sqlite3_errmsg(db_)); - sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"), - seller->getId()); + sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":seller_uuid"), + boost::uuids::to_string(seller->getUuid()).c_str(), -1, SQLITE_TRANSIENT); retCode = sqlite3_step(stmt); @@ -749,4 +746,4 @@ void Database::updateCashPointNo(int oldCashPointNo, int newCashPointNo) sqlite3_finalize(stmt); endTransaction(); -} +} \ No newline at end of file diff --git a/src/core/database.h b/src/core/database.h index 2cf1b63..661d433 100644 --- a/src/core/database.h +++ b/src/core/database.h @@ -11,7 +11,6 @@ class Database { public: - enum class InitResult {OK, OUTDATED_REPLACED}; explicit Database(const std::string& dbname); Database(); ~Database(); @@ -26,7 +25,6 @@ class Database std::vector>& sellers); void updateCashPointNo(int oldCashPointNo, int newCashPointNo); void newDb(); - InitResult getInitResult() {return initResult_;} private: sqlite3* db_{nullptr}; @@ -38,8 +36,6 @@ class Database int getVersion(); unsigned int storeArticles(std::vector articles); void updateDbToVer2(); - void updateDbToVer3(); - InitResult initResult_{InitResult::OK}; }; -#endif // DATABASE_H +#endif // DATABASE_H \ No newline at end of file diff --git a/src/core/entity.cpp b/src/core/entity.cpp index 4a8cfb4..8caa834 100644 --- a/src/core/entity.cpp +++ b/src/core/entity.cpp @@ -1,6 +1,33 @@ #include "entity.h" +#include + +#include +#include + +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 { return state_; } + +void Entity::setSourceNo(int sourceNo) { + sourceNo_ = sourceNo; +} + +int Entity::getSourceNo() const { + return sourceNo_; +} \ No newline at end of file diff --git a/src/core/entity.h b/src/core/entity.h index 68b3ba7..017b6e0 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -1,16 +1,35 @@ #ifndef ENTITY_H #define ENTITY_H +#include + +#include +#include + class Entity { -public: + public: enum class State { NEW, UPDATE, DELETE, OK }; - //virtual ~Entity() = 0; - void setState(State state) { state_ = state; } - virtual State getState() const; -private: + // Entity() = default; + virtual ~Entity() = 0; + + void createUuid(); + void setUuidFromString(const std::string& uuidString); + 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 int getSourceNo() const; + + protected: + int sourceNo_{}; + + private: + boost::uuids::uuid uuid_{}; State state_{State::NEW}; }; -#endif // ENTITY_H +#endif // ENTITY_H \ No newline at end of file diff --git a/src/core/entityint.cpp b/src/core/entityint.cpp deleted file mode 100644 index 835c5ff..0000000 --- a/src/core/entityint.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "entityint.h" - -EntityInt::EntityInt(int id) { - id_ = id; -} - -void EntityInt::setId(int id) { - id_ = id; -} diff --git a/src/core/entityint.h b/src/core/entityint.h deleted file mode 100644 index 9430a70..0000000 --- a/src/core/entityint.h +++ /dev/null @@ -1,18 +0,0 @@ -#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 diff --git a/src/core/entityuuid.cpp b/src/core/entityuuid.cpp deleted file mode 100644 index 4ec15ab..0000000 --- a/src/core/entityuuid.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "entityuuid.h" - -#include - -#include -#include - -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_; -} diff --git a/src/core/entityuuid.h b/src/core/entityuuid.h deleted file mode 100644 index 9b99ba7..0000000 --- a/src/core/entityuuid.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef ENTITY_UUID_H -#define ENTITY_UUID_H - -#include "entity.h" - -#include - -#include -#include - -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 diff --git a/src/core/excelreader.cpp b/src/core/excelreader.cpp index 7ef401d..cd0a8d7 100644 --- a/src/core/excelreader.cpp +++ b/src/core/excelreader.cpp @@ -39,6 +39,7 @@ std::size_t ExcelReader::readSellersFromFile(const fs::path& filePath, Marketpla continue; } auto seller = std::make_unique(); + seller->createUuid(); seller->setSellerNo(row[0].value()); seller->setNumArticlesOffered(row[1].value()); std::string firstName = row[2].value(); @@ -50,9 +51,10 @@ std::size_t ExcelReader::readSellersFromFile(const fs::path& filePath, Marketpla } // If there was no special seller "Sonderkonto" in import data, then create one - auto specialSeller = market->findSellerWithSellerNo(0); + auto specialSeller = market->findSellerWithUuid("11111111-1111-1111-1111-111111111111"); if (!specialSeller) { auto seller = std::make_unique(); + seller->setUuidFromString("11111111-1111-1111-1111-111111111111"); seller->setSellerNo(0); seller->setLastName("Sonderkonto"); seller->setFirstName("Sonderkonto"); diff --git a/src/core/jsonutil.cpp b/src/core/jsonutil.cpp index 873bb7b..dddf79a 100644 --- a/src/core/jsonutil.cpp +++ b/src/core/jsonutil.cpp @@ -15,6 +15,7 @@ void JsonUtil::exportSellers(const std::filesystem::path& filePath, Marketplace* for (const auto& seller : market->getSellers()) { json newEntry; + newEntry["uuid"] = seller->getUuidAsString(); newEntry["seller_no"] = seller->getSellerNo(); newEntry["last_name"] = seller->getLastName(); newEntry["first_name"] = seller->getFirstName(); @@ -37,6 +38,7 @@ void JsonUtil::importSellers(const std::filesystem::path& filePath, Marketplace* for (auto val : jsonValues["sellers"]) { auto seller = std::make_unique(); + seller->setUuidFromString(val["uuid"]); seller->setSellerNo(val["seller_no"]); seller->setLastName(val["last_name"]); seller->setFirstName(val["first_name"]); @@ -45,9 +47,10 @@ void JsonUtil::importSellers(const std::filesystem::path& filePath, Marketplace* } // If there was no special seller "Sonderkonto" in import data, then create one - auto specialSeller = market->findSellerWithSellerNo(0); + auto specialSeller = market->findSellerWithUuid("11111111-1111-1111-1111-111111111111"); if (!specialSeller) { auto seller = std::make_unique(); + seller->setUuidFromString("11111111-1111-1111-1111-111111111111"); seller->setSellerNo(0); seller->setLastName("Sonderkonto"); seller->setFirstName("Sonderkonto"); @@ -78,7 +81,7 @@ void JsonUtil::exportSales(const std::filesystem::path& filePath, Marketplace* m for (const auto& article : sale->getArticles()) { json newArticle; newArticle["uuid"] = article->getUuidAsString(); - newArticle["seller_no"] = article->getSeller()->getSellerNo(); + newArticle["seller_uuid"] = article->getSeller()->getUuidAsString(); newArticle["desc"] = article->getDescription(); newArticle["price"] = article->getPrice(); // newArticle["source_no"] = article->getSourceNo(); @@ -119,7 +122,7 @@ void JsonUtil::importSales(const std::filesystem::path& filePath, Marketplace* m article->setArticleNo(valArticle["article_no"]); article->setDescription(valArticle["desc"]); article->setPrice(valArticle["price"]); - auto seller = market->findSellerWithSellerNo(valArticle["seller_no"]); + auto seller = market->findSellerWithUuid(valArticle["seller_uuid"]); if (seller == nullptr) { throw std::runtime_error( "Die zu importierenden Daten verweisen auf einen nicht vorhandenen Verkäufer. " @@ -133,4 +136,4 @@ void JsonUtil::importSales(const std::filesystem::path& filePath, Marketplace* m } market->storeToDb(); -} +} \ No newline at end of file diff --git a/src/core/marketplace.cpp b/src/core/marketplace.cpp index c9f4b7a..8f666fe 100644 --- a/src/core/marketplace.cpp +++ b/src/core/marketplace.cpp @@ -13,9 +13,9 @@ namespace fs = std::filesystem; Marketplace::Marketplace() { - /*auto seller = std::make_unique("Max", "Mustermann"); + auto seller = std::make_unique("Max", "Mustermann"); seller->createUuid(); - sellers_.push_back(std::move(seller)); */ + sellers_.push_back(std::move(seller)); } void Marketplace::storeToDb(bool onlyDelete) @@ -25,12 +25,11 @@ void Marketplace::storeToDb(bool onlyDelete) db.storeSales(sales_); } -Database::InitResult Marketplace::loadFromDb() +void Marketplace::loadFromDb() { Database db; db.loadSellers(sellers_); db.loadSales(sales_, sellers_); - return db.getInitResult(); } SellersVec& Marketplace::getSellers() { return sellers_; } @@ -104,7 +103,6 @@ Seller* Marketplace::findSellerWithSellerNo(int sellerNo) return (*iter).get(); } -/* Seller* Marketplace::findSellerWithUuid(const std::string& uuid) { auto iter = std::find_if(sellers_.begin(), sellers_.end(), @@ -113,7 +111,6 @@ Seller* Marketplace::findSellerWithUuid(const std::string& uuid) return nullptr; return (*iter).get(); } -*/ void Marketplace::addArticleToBasket(std::unique_ptr
article) { @@ -292,4 +289,4 @@ void Marketplace::clear() Database db; db.newDb(); loadFromDb(); -} +} \ No newline at end of file diff --git a/src/core/marketplace.h b/src/core/marketplace.h index 47e25bd..758f758 100644 --- a/src/core/marketplace.h +++ b/src/core/marketplace.h @@ -1,7 +1,6 @@ #ifndef MARKETPLACE_H #define MARKETPLACE_H -#include "database.h" #include "article.h" #include "sale.h" #include "seller.h" @@ -24,7 +23,7 @@ class Marketplace Marketplace(); void storeToDb(bool onlyDelete = false); - Database::InitResult loadFromDb(); + void loadFromDb(); SellersVec& getSellers(); SalesVec& getSales(); @@ -70,4 +69,4 @@ std::string marketFeeAsString(int sumInCent, int percent, int maxFeeInCent); std::string paymentAsString(int sumInCent, int percent, int maxFeeInCent); std::string escapeCsvValue(const std::string& value, const char delimiter); -#endif +#endif \ No newline at end of file diff --git a/src/core/sale.h b/src/core/sale.h index 0cfb18c..c6de317 100644 --- a/src/core/sale.h +++ b/src/core/sale.h @@ -14,7 +14,7 @@ namespace using ArticlesVec = std::vector; } -class Sale : public EntityUuid +class Sale : public Entity { public: void addArticle(Article* articlePtr); @@ -34,4 +34,4 @@ class Sale : public EntityUuid mutable ArticlesVec articles_{}; }; -#endif +#endif \ No newline at end of file diff --git a/src/core/seller.cpp b/src/core/seller.cpp index cc053ce..9147934 100644 --- a/src/core/seller.cpp +++ b/src/core/seller.cpp @@ -7,14 +7,15 @@ Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo, int numArticlesOffered) - : EntityInt(sellerNo) + : Entity() { firstName_ = firstName; lastName_ = lastName; + sellerNo_ = sellerNo; numArticlesOffered_ = numArticlesOffered; } -void Seller::setSellerNo(int seller_no) { setId(seller_no); } +void Seller::setSellerNo(int seller_no) { sellerNo_ = seller_no; } void Seller::setFirstName(const std::string& firstName) { firstName_ = firstName; } @@ -32,13 +33,13 @@ std::string Seller::getFirstName() const { return firstName_; } std::string Seller::getLastName() const { return lastName_; } -int Seller::getSellerNo() const { return getId(); } +int Seller::getSellerNo() const { return sellerNo_; } std::string Seller::getSellerNoAsString() const { std::stringstream selNoStr; - selNoStr << std::setfill('0') << std::setw(3) << id_; + selNoStr << std::setfill('0') << std::setw(3) << sellerNo_; return selNoStr.str(); ; @@ -103,8 +104,8 @@ int Seller::sumInCents() std::string Seller::sumAsString() { return formatCentAsEuroString(sumInCents()); } -bool operator<(const Seller& li, const Seller& re) { return li.id_ < re.id_; } +bool operator<(const Seller& li, const Seller& re) { return li.sellerNo_ < re.sellerNo_; } bool operator<(const std::unique_ptr& li, const std::unique_ptr& re) { - return li->id_ < re->id_; -} + return li->sellerNo_ < re->sellerNo_; +} \ No newline at end of file diff --git a/src/core/seller.h b/src/core/seller.h index a4bfde1..db44a0f 100644 --- a/src/core/seller.h +++ b/src/core/seller.h @@ -2,7 +2,7 @@ #define SELLER_H #include "article.h" -#include "entityint.h" +#include "entity.h" #include #include @@ -10,11 +10,11 @@ // class Article; -class Seller : public EntityInt +class Seller : public Entity { public: Seller() = default; - ~Seller() = default; + // virtual ~Seller() = default; Seller(const std::string& firstName, const std::string& lastName, int sellerNo = 0, int numArticlesOffered = 0); @@ -42,10 +42,11 @@ class Seller : public EntityInt friend bool operator<(const std::unique_ptr& li, const std::unique_ptr& re); private: + int sellerNo_{-1}; int numArticlesOffered_{}; std::string firstName_{}; std::string lastName_{}; std::vector> articles_{}; }; -#endif +#endif \ No newline at end of file diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 4ce75db..678a5cf 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -35,13 +35,7 @@ MainWindow::MainWindow() ui_.setupUi(this); marketplace_ = std::make_unique(); - Database::InitResult res = marketplace_->loadFromDb(); - if (res == Database::InitResult::OUTDATED_REPLACED) { - QMessageBox(QMessageBox::Icon::Information, "Datenbankinformation", - "Es wurde eine veraltete Datenbankdatei erkannt.
Diese wurde " - "umbenannt und eine neue Datei wurde erstellt.") - .exec(); - } + marketplace_->loadFromDb(); statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT); BasketModel* model = new BasketModel(getMarketplace(), ui_.basketView); @@ -455,6 +449,14 @@ void MainWindow::onImportSellerExcelActionTriggered() return; } + QMessageBox( + QMessageBox::Icon::Information, "Bitte beachten", + "Achtung: Importieren Sie die Verkäuferdaten nur auf einer (!) " + "KIMA2-Installation.
" + "Verteilen Sie die Daten auf die anderen Installationen unbedingt über eine JSON-Datei!", + QMessageBox::StandardButton::Ok, this) + .exec(); + auto filename = QFileDialog::getOpenFileName( this, "Verkäufer importieren", QString(), "Alle unterstützte Dateien (*.xlsx *.csv);;Excel Dateien (*.xlsx);;CSV Dateien (*.csv)"); diff --git a/src/gui/reportdialog.cpp b/src/gui/reportdialog.cpp index 9cb7393..3a84ec4 100644 --- a/src/gui/reportdialog.cpp +++ b/src/gui/reportdialog.cpp @@ -102,7 +102,7 @@ void ReportDialog::onPrintReportButtonClicked() for (unsigned int j = 0; j < ENTRIES_PER_PAGE && (i - 1) * ENTRIES_PER_PAGE + j < sellers.size(); ++j) { int idx = (i - 1) * ENTRIES_PER_PAGE + j; - if (sellers.at(idx)->getId() == 0) { + if (sellers.at(idx)->getUuidAsString() == "11111111-1111-1111-1111-111111111111") { continue; } content += QString("%1 %2 %3 %4 %5 %6 %7\n") @@ -121,7 +121,7 @@ void ReportDialog::onPrintReportButtonClicked() } // pieces booked on the special account "Sonderkonto" - const auto specialSeller = market_->findSellerWithSellerNo(0); + const auto specialSeller = market_->findSellerWithUuid("11111111-1111-1111-1111-111111111111"); if (specialSeller && specialSeller->numArticlesSold() > 0) { printer.newPage(); painter.setFont(QFont("Arial", 16, QFont::Bold)); diff --git a/src/gui/reportmodel.cpp b/src/gui/reportmodel.cpp index 65d386f..888430b 100644 --- a/src/gui/reportmodel.cpp +++ b/src/gui/reportmodel.cpp @@ -59,7 +59,7 @@ QVariant ReportModel::data(const QModelIndex& index, int role) const switch (index.column()) { case 0: - return seller->getId(); + return seller->getUuidAsString().c_str(); case 1: return seller->getSellerNo(); case 2: @@ -104,4 +104,4 @@ QVariant ReportModel::headerData(int section, Qt::Orientation orientation, int r // return QStringLiteral("%1").arg(section); } else return ""; -} +} \ No newline at end of file diff --git a/src/gui/salemodel.cpp b/src/gui/salemodel.cpp index 3549003..0bf9a71 100644 --- a/src/gui/salemodel.cpp +++ b/src/gui/salemodel.cpp @@ -44,7 +44,7 @@ QModelIndex SaleModel::parent(const QModelIndex& index) const Sale* sale{}; Article* article{}; - EntityUuid* ent = static_cast(index.internalPointer()); + Entity* ent = static_cast(index.internalPointer()); sale = dynamic_cast(ent); diff --git a/src/gui/sellermodel.cpp b/src/gui/sellermodel.cpp index 9b9e660..7ec2356 100644 --- a/src/gui/sellermodel.cpp +++ b/src/gui/sellermodel.cpp @@ -31,7 +31,7 @@ QVariant SellerModel::data(const QModelIndex& index, int role) const */ switch (index.column()) { case 0: - return seller->getId(); + return seller->getUuidAsString().c_str(); case 1: return seller->getSellerNo(); case 2: @@ -85,7 +85,7 @@ bool SellerModel::setData(const QModelIndex& index, const QVariant& value, int r switch (index.column()) { case 0: - seller->setId(value.toInt()); + seller->setUuidFromString(value.toString().toStdString()); break; case 1: { if (value.toInt() < 0) @@ -126,6 +126,7 @@ bool SellerModel::insertRows(int row, int count, const QModelIndex& parent) { emit beginInsertRows(parent, row, row + count - 1); auto seller = std::make_unique(); + seller->createUuid(); seller->setSellerNo(marketplace_->getNextSellerNo()); marketplace_->getSellers().push_back(std::move(seller)); emit endInsertRows(); @@ -141,7 +142,7 @@ bool SellerModel::removeRows(int row, int count, const QModelIndex& parent) marketplace_->getSellers().erase( std::remove_if(marketplace_->getSellers().begin(), marketplace_->getSellers().end(), [&seller](const std::unique_ptr& a) { - return a->getId() == seller->getId(); + return a->getUuid() == seller->getUuid(); }), marketplace_->getSellers().end()); emit endRemoveRows(); @@ -155,4 +156,4 @@ bool SellerModel::removeRows(int row, int count, const QModelIndex& parent) } return false; -} +} \ No newline at end of file diff --git a/test/test_seller.cpp b/test/test_seller.cpp index 7d07b5b..45a41d6 100644 --- a/test/test_seller.cpp +++ b/test/test_seller.cpp @@ -9,14 +9,14 @@ BOOST_AUTO_TEST_CASE(create_uuid_nil) { Seller seller{}; - BOOST_TEST(seller.getId().is_nil() == true); + BOOST_TEST(seller.getUuid().is_nil() == true); } BOOST_AUTO_TEST_CASE(create_uuid) { Seller seller{}; seller.createUuid(); - BOOST_TEST(seller.getId().is_nil() == false); + BOOST_TEST(seller.getUuid().is_nil() == false); } BOOST_AUTO_TEST_CASE(create_many) @@ -25,7 +25,7 @@ BOOST_AUTO_TEST_CASE(create_many) std::array sellers; for (unsigned i = 0; i < sellers.size(); i++) { sellers[i] = Seller(); - //sellers[i].createUuid(); + sellers[i].createUuid(); } } @@ -37,4 +37,4 @@ BOOST_AUTO_TEST_CASE(with_article) { BOOST_TEST((article == nullptr)); BOOST_TEST(seller.getArticles(false).at(0)->getDescription() == "Test article"); BOOST_TEST(seller.numArticlesSold() == 0); -} +} \ No newline at end of file