Show information dialog about outdated database file
This commit is contained in:
parent
a33b9896b3
commit
57bfe3af62
5 changed files with 19 additions and 4 deletions
|
@ -156,15 +156,19 @@ void Database::init()
|
||||||
switch (version) {
|
switch (version) {
|
||||||
case 0:
|
case 0:
|
||||||
createNew();
|
createNew();
|
||||||
|
initResult_ = InitResult::OK;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
updateDbToVer3();
|
updateDbToVer3();
|
||||||
|
initResult_ = InitResult::OUTDATED_REPLACED;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
updateDbToVer3();
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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};
|
||||||
|
@ -37,6 +39,7 @@ class Database
|
||||||
unsigned int storeArticles(std::vector<Article*> articles);
|
unsigned int storeArticles(std::vector<Article*> articles);
|
||||||
void updateDbToVer2();
|
void updateDbToVer2();
|
||||||
void updateDbToVer3();
|
void updateDbToVer3();
|
||||||
|
InitResult initResult_{InitResult::OK};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DATABASE_H
|
#endif // DATABASE_H
|
||||||
|
|
|
@ -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_; }
|
||||||
|
|
|
@ -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();
|
||||||
|
@ -69,4 +70,4 @@ std::string marketFeeAsString(int sumInCent, int percent, int maxFeeInCent);
|
||||||
std::string paymentAsString(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);
|
std::string escapeCsvValue(const std::string& value, const char delimiter);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue