From 57bfe3af623ee7b27ad3ba2aa56325d466865a43 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 4 Oct 2019 15:50:13 +0200 Subject: [PATCH] Show information dialog about outdated database file --- src/core/database.cpp | 4 ++++ src/core/database.h | 3 +++ src/core/marketplace.cpp | 3 ++- src/core/marketplace.h | 5 +++-- src/gui/mainwindow.cpp | 8 +++++++- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/core/database.cpp b/src/core/database.cpp index f02d82a..f95deae 100644 --- a/src/core/database.cpp +++ b/src/core/database.cpp @@ -156,15 +156,19 @@ 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; break; default: // Do nothing because we are up-to-date. + initResult_ = InitResult::OK; break; } } diff --git a/src/core/database.h b/src/core/database.h index ee24794..2cf1b63 100644 --- a/src/core/database.h +++ b/src/core/database.h @@ -11,6 +11,7 @@ class Database { public: + enum class InitResult {OK, OUTDATED_REPLACED}; explicit Database(const std::string& dbname); Database(); ~Database(); @@ -25,6 +26,7 @@ class Database std::vector>& sellers); void updateCashPointNo(int oldCashPointNo, int newCashPointNo); void newDb(); + InitResult getInitResult() {return initResult_;} private: sqlite3* db_{nullptr}; @@ -37,6 +39,7 @@ class Database unsigned int storeArticles(std::vector articles); void updateDbToVer2(); void updateDbToVer3(); + InitResult initResult_{InitResult::OK}; }; #endif // DATABASE_H diff --git a/src/core/marketplace.cpp b/src/core/marketplace.cpp index 7f446b0..c9f4b7a 100644 --- a/src/core/marketplace.cpp +++ b/src/core/marketplace.cpp @@ -25,11 +25,12 @@ void Marketplace::storeToDb(bool onlyDelete) db.storeSales(sales_); } -void Marketplace::loadFromDb() +Database::InitResult Marketplace::loadFromDb() { Database db; db.loadSellers(sellers_); db.loadSales(sales_, sellers_); + return db.getInitResult(); } SellersVec& Marketplace::getSellers() { return sellers_; } diff --git a/src/core/marketplace.h b/src/core/marketplace.h index 758f758..47e25bd 100644 --- a/src/core/marketplace.h +++ b/src/core/marketplace.h @@ -1,6 +1,7 @@ #ifndef MARKETPLACE_H #define MARKETPLACE_H +#include "database.h" #include "article.h" #include "sale.h" #include "seller.h" @@ -23,7 +24,7 @@ class Marketplace Marketplace(); void storeToDb(bool onlyDelete = false); - void loadFromDb(); + Database::InitResult loadFromDb(); SellersVec& getSellers(); SalesVec& getSales(); @@ -69,4 +70,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 \ No newline at end of file +#endif diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 4853a86..4ce75db 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -35,7 +35,13 @@ MainWindow::MainWindow() ui_.setupUi(this); marketplace_ = std::make_unique(); - marketplace_->loadFromDb(); + 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(); + } statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT); BasketModel* model = new BasketModel(getMarketplace(), ui_.basketView);