Show information dialog about outdated database file

This commit is contained in:
Martin Brodbeck 2019-10-04 15:50:13 +02:00
parent a33b9896b3
commit 57bfe3af62
5 changed files with 19 additions and 4 deletions

View file

@ -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;
}
}

View file

@ -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<std::unique_ptr<Seller>>& 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<Article*> articles);
void updateDbToVer2();
void updateDbToVer3();
InitResult initResult_{InitResult::OK};
};
#endif // DATABASE_H

View file

@ -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_; }

View file

@ -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
#endif

View file

@ -35,7 +35,13 @@ MainWindow::MainWindow()
ui_.setupUi(this);
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);
BasketModel* model = new BasketModel(getMarketplace(), ui_.basketView);