Compare commits
5 commits
2e6e2f9c09
...
86a9ed38b6
Author | SHA1 | Date | |
---|---|---|---|
86a9ed38b6 | |||
91f52df554 | |||
2f83321484 | |||
964c926fb0 | |||
a10ba7d7f6 |
6 changed files with 34 additions and 9 deletions
|
@ -186,6 +186,8 @@ void Database::beginTransaction() { exec("BEGIN TRANSACTION"); }
|
||||||
|
|
||||||
void Database::endTransaction() { exec("END TRANSACTION"); }
|
void Database::endTransaction() { exec("END TRANSACTION"); }
|
||||||
|
|
||||||
|
void Database::rollbackTransaction() { exec("ROLLBACK TRANSACTION"); }
|
||||||
|
|
||||||
unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& sellers, bool onlyDelete)
|
unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& sellers, bool onlyDelete)
|
||||||
{
|
{
|
||||||
int retCode{};
|
int retCode{};
|
||||||
|
@ -221,8 +223,9 @@ unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& seller
|
||||||
retCode = sqlite3_step(stmt);
|
retCode = sqlite3_step(stmt);
|
||||||
|
|
||||||
if (retCode != SQLITE_DONE) {
|
if (retCode != SQLITE_DONE) {
|
||||||
|
//rollbackTransaction();
|
||||||
std::string errMsg(sqlite3_errmsg(db_));
|
std::string errMsg(sqlite3_errmsg(db_));
|
||||||
|
errMsg += "\nSellerNo: " + std::to_string(seller->getSellerNo());
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
throw std::runtime_error(errMsg);
|
throw std::runtime_error(errMsg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ class Database
|
||||||
void init();
|
void init();
|
||||||
void beginTransaction();
|
void beginTransaction();
|
||||||
void endTransaction();
|
void endTransaction();
|
||||||
|
void rollbackTransaction();
|
||||||
void createNew();
|
void createNew();
|
||||||
int getVersion();
|
int getVersion();
|
||||||
unsigned int storeArticles(std::vector<Article*> articles);
|
unsigned int storeArticles(std::vector<Article*> articles);
|
||||||
|
|
|
@ -31,18 +31,24 @@ void JsonUtil::exportSellers(const fs::path& filePath, Marketplace* market)
|
||||||
writer->write(root, &file);
|
writer->write(root, &file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonUtil::importSellers(const fs::path& filePath, Marketplace* market)
|
void JsonUtil::importSellers(const fs::path& filePath, Marketplace* market, bool cleanup)
|
||||||
{
|
{
|
||||||
|
if (cleanup) {
|
||||||
for (auto& seller : market->getSellers()) {
|
for (auto& seller : market->getSellers()) {
|
||||||
seller->setState(Seller::State::DELETE);
|
seller->setState(Seller::State::DELETE);
|
||||||
}
|
}
|
||||||
market->storeToDb(true);
|
market->storeToDb(true);
|
||||||
|
}
|
||||||
|
|
||||||
Json::Value jsonValues;
|
Json::Value jsonValues;
|
||||||
std::ifstream file(filePath);
|
std::ifstream file(filePath);
|
||||||
file >> jsonValues;
|
file >> jsonValues;
|
||||||
|
|
||||||
for (auto val : jsonValues["sellers"]) {
|
for (auto val : jsonValues["sellers"]) {
|
||||||
|
auto sellerExist = market->findSellerWithUuid(val["uuid"].asString());
|
||||||
|
if (sellerExist) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
auto seller = std::make_unique<Seller>();
|
auto seller = std::make_unique<Seller>();
|
||||||
seller->setUuidFromString(val["uuid"].asString());
|
seller->setUuidFromString(val["uuid"].asString());
|
||||||
seller->setSellerNo(val["seller_no"].asInt());
|
seller->setSellerNo(val["seller_no"].asInt());
|
||||||
|
@ -80,6 +86,17 @@ void JsonUtil::exportSales(const fs::path& filePath, Marketplace* market, int ca
|
||||||
|
|
||||||
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
|
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
|
||||||
|
|
||||||
|
// Do export sellers (maybe there are new sellers created during sale)
|
||||||
|
for (const auto& seller : market->getSellers()) {
|
||||||
|
Json::Value newEntry;
|
||||||
|
newEntry["uuid"] = seller->getUuidAsString();
|
||||||
|
newEntry["seller_no"] = seller->getSellerNo();
|
||||||
|
newEntry["last_name"] = seller->getLastName();
|
||||||
|
newEntry["first_name"] = seller->getFirstName();
|
||||||
|
newEntry["num_offered_articles"] = seller->numArticlesOffered();
|
||||||
|
root["sellers"].append(newEntry);
|
||||||
|
}
|
||||||
|
|
||||||
root["source_no"] = cashPointNo;
|
root["source_no"] = cashPointNo;
|
||||||
|
|
||||||
for (const auto& sale : market->getSales()) {
|
for (const auto& sale : market->getSales()) {
|
||||||
|
@ -110,6 +127,9 @@ void JsonUtil::exportSales(const fs::path& filePath, Marketplace* market, int ca
|
||||||
|
|
||||||
void JsonUtil::importSales(const fs::path& filePath, Marketplace* market, int cashPointNo)
|
void JsonUtil::importSales(const fs::path& filePath, Marketplace* market, int cashPointNo)
|
||||||
{
|
{
|
||||||
|
// First import newly created sellers during the sale phase
|
||||||
|
importSellers(filePath, market, false);
|
||||||
|
|
||||||
Json::Value jsonValues;
|
Json::Value jsonValues;
|
||||||
std::ifstream file(filePath);
|
std::ifstream file(filePath);
|
||||||
file >> jsonValues;
|
file >> jsonValues;
|
||||||
|
|
|
@ -10,7 +10,7 @@ class JsonUtil
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void exportSellers(const std::filesystem::path& filePath, Marketplace* market);
|
static void exportSellers(const std::filesystem::path& filePath, Marketplace* market);
|
||||||
static void importSellers(const std::filesystem::path& filePath, Marketplace* market);
|
static void importSellers(const std::filesystem::path& filePath, Marketplace* market, bool cleanup = true);
|
||||||
static void exportSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo);
|
static void exportSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo);
|
||||||
static void importSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo);
|
static void importSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo);
|
||||||
};
|
};
|
||||||
|
|
|
@ -503,6 +503,7 @@ void MainWindow::onImportSalesJsonActionTriggered()
|
||||||
QMessageBox(QMessageBox::Icon::Warning, "Import nicht möglich", err.what(), QMessageBox::Ok,
|
QMessageBox(QMessageBox::Icon::Warning, "Import nicht möglich", err.what(), QMessageBox::Ok,
|
||||||
this)
|
this)
|
||||||
.exec();
|
.exec();
|
||||||
|
marketplace_->loadFromDb();
|
||||||
}
|
}
|
||||||
setSaleModel();
|
setSaleModel();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,14 +25,14 @@ SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent,
|
||||||
void SellerDialog::on_newButton_clicked()
|
void SellerDialog::on_newButton_clicked()
|
||||||
{
|
{
|
||||||
// Don't allow new seller if market has already started
|
// Don't allow new seller if market has already started
|
||||||
if (market_->getSales().size() > 0) {
|
/* if (market_->getSales().size() > 0) {
|
||||||
QMessageBox(QMessageBox::Icon::Warning, "Hinweis",
|
QMessageBox(QMessageBox::Icon::Warning, "Hinweis",
|
||||||
"Da die Verkaufsphase schon begonnen hat (Artikel wurden bereits verkauft) "
|
"Da die Verkaufsphase schon begonnen hat (Artikel wurden bereits verkauft) "
|
||||||
"können Sie keine Verkäufer mehr hinzufügen.",
|
"können Sie keine Verkäufer mehr hinzufügen.",
|
||||||
QMessageBox::StandardButton::Ok, this)
|
QMessageBox::StandardButton::Ok, this)
|
||||||
.exec();
|
.exec();
|
||||||
return;
|
return;
|
||||||
}
|
} */
|
||||||
|
|
||||||
ui_.tableView->reset();
|
ui_.tableView->reset();
|
||||||
ui_.tableView->model()->insertRows(ui_.tableView->model()->rowCount(), 1);
|
ui_.tableView->model()->insertRows(ui_.tableView->model()->rowCount(), 1);
|
||||||
|
|
Loading…
Reference in a new issue