import / export sellers completed
This commit is contained in:
parent
045bc8dd20
commit
61da9adce5
5 changed files with 66 additions and 10 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include "jsonutil.h"
|
#include "jsonutil.h"
|
||||||
|
#include "database.h"
|
||||||
|
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
|
|
||||||
|
@ -15,17 +16,39 @@ void JsonUtil::exportSellers(const std::string& filename, Marketplace* market)
|
||||||
|
|
||||||
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
|
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
|
||||||
|
|
||||||
root["encoding"] = "UTF-8";
|
|
||||||
|
|
||||||
for (const auto& seller : market->getSellers()) {
|
for (const auto& seller : market->getSellers()) {
|
||||||
Json::Value newEntry;
|
Json::Value newEntry;
|
||||||
newEntry["uuid"] = seller->getUuidAsString();
|
newEntry["uuid"] = seller->getUuidAsString();
|
||||||
newEntry["seller_no"] = seller->getSellerNo();
|
newEntry["seller_no"] = seller->getSellerNo();
|
||||||
newEntry["last_name"] = seller->getLastName();
|
newEntry["last_name"] = seller->getLastName();
|
||||||
newEntry["first_name"] = seller->getFirstName();
|
newEntry["first_name"] = seller->getFirstName();
|
||||||
newEntry["num_offered_articles"] = seller->getFirstName();
|
newEntry["num_offered_articles"] = seller->numArticlesOffered();
|
||||||
root["sellers"].append(newEntry);
|
root["sellers"].append(newEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
writer->write(root, &file);
|
writer->write(root, &file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JsonUtil::importSellers(const std::string& filename, Marketplace* market)
|
||||||
|
{
|
||||||
|
for (auto& seller : market->getSellers())
|
||||||
|
{
|
||||||
|
seller->setState(Seller::State::DELETE);
|
||||||
|
}
|
||||||
|
market->storeToDb(true);
|
||||||
|
|
||||||
|
Json::Value jsonValues;
|
||||||
|
std::ifstream file(filename);
|
||||||
|
file >> jsonValues;
|
||||||
|
|
||||||
|
for(auto val : jsonValues["sellers"]) {
|
||||||
|
auto seller = std::make_unique<Seller>();
|
||||||
|
seller->setUuidFromString(val["uuid"].asString());
|
||||||
|
seller->setSellerNo(val["seller_no"].asInt());
|
||||||
|
seller->setLastName(val["last_name"].asString());
|
||||||
|
seller->setFirstName(val["first_name"].asString());
|
||||||
|
seller->setNumArticlesOffered(val["num_offered_articles"].asInt());
|
||||||
|
market->getSellers().push_back(std::move(seller));
|
||||||
|
}
|
||||||
|
market->storeToDb();
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ class JsonUtil
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void exportSellers(const std::string& filename, Marketplace* market);
|
static void exportSellers(const std::string& filename, Marketplace* market);
|
||||||
|
static void importSellers(const std::string& filename, Marketplace* market);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -62,8 +62,10 @@ MainWindow::MainWindow()
|
||||||
this->setWindowTitle("KIMA2 - Kasse Nr. " +
|
this->setWindowTitle("KIMA2 - Kasse Nr. " +
|
||||||
QSettings().value("global/cashPointNo").toString());
|
QSettings().value("global/cashPointNo").toString());
|
||||||
});
|
});
|
||||||
connect(ui_.importExcelAction, &QAction::triggered, this,
|
connect(ui_.importSellerExcelAction, &QAction::triggered, this,
|
||||||
&MainWindow::onImportSellerExcelActionTriggered);
|
&MainWindow::onImportSellerExcelActionTriggered);
|
||||||
|
connect(ui_.importSellerJsonAction, &QAction::triggered, this,
|
||||||
|
&MainWindow::onImportSellerJsonActionTriggered);
|
||||||
connect(ui_.exportSellerJsonAction, &QAction::triggered, this,
|
connect(ui_.exportSellerJsonAction, &QAction::triggered, this,
|
||||||
&MainWindow::onExportSellerJsonActionTriggered);
|
&MainWindow::onExportSellerJsonActionTriggered);
|
||||||
}
|
}
|
||||||
|
@ -258,6 +260,23 @@ void MainWindow::onImportSellerExcelActionTriggered()
|
||||||
ExcelReader::readSellersFromFile(filename.toStdString(), marketplace_.get());
|
ExcelReader::readSellersFromFile(filename.toStdString(), marketplace_.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onImportSellerJsonActionTriggered()
|
||||||
|
{
|
||||||
|
if (!marketplace_->getSales().empty()) {
|
||||||
|
QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich",
|
||||||
|
"Der Import ist nicht möglich, da schon Verkäufe getätigt wurden.",
|
||||||
|
QMessageBox::StandardButton::Ok, this)
|
||||||
|
.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto filename = QFileDialog::getOpenFileName(this, "Verkäufer importieren", QString(),
|
||||||
|
"JSON Dateien (*.json)");
|
||||||
|
|
||||||
|
JsonUtil::importSellers(filename.toStdString(), marketplace_.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::onExportSellerJsonActionTriggered()
|
void MainWindow::onExportSellerJsonActionTriggered()
|
||||||
{
|
{
|
||||||
auto filename = QFileDialog::getSaveFileName(this, "Verkäufer exportieren", QString(),
|
auto filename = QFileDialog::getSaveFileName(this, "Verkäufer exportieren", QString(),
|
||||||
|
|
|
@ -33,6 +33,7 @@ class MainWindow : public QMainWindow
|
||||||
void onSellerNoEditCheckSellerNo();
|
void onSellerNoEditCheckSellerNo();
|
||||||
void onPaidButtonTriggered();
|
void onPaidButtonTriggered();
|
||||||
void onImportSellerExcelActionTriggered();
|
void onImportSellerExcelActionTriggered();
|
||||||
|
void onImportSellerJsonActionTriggered();
|
||||||
void onExportSellerJsonActionTriggered();
|
void onExportSellerJsonActionTriggered();
|
||||||
void setSaleModel();
|
void setSaleModel();
|
||||||
|
|
||||||
|
|
|
@ -403,8 +403,15 @@ drucken</string>
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>&Verkäufer</string>
|
<string>&Verkäufer</string>
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QMenu" name="importSellerMenu">
|
||||||
|
<property name="title">
|
||||||
|
<string>Importieren</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="importSellerExcelAction"/>
|
||||||
|
<addaction name="importSellerJsonAction"/>
|
||||||
|
</widget>
|
||||||
<addaction name="actionEditSeller"/>
|
<addaction name="actionEditSeller"/>
|
||||||
<addaction name="importExcelAction"/>
|
<addaction name="importSellerMenu"/>
|
||||||
<addaction name="exportSellerJsonAction"/>
|
<addaction name="exportSellerJsonAction"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuHilfe">
|
<widget class="QMenu" name="menuHilfe">
|
||||||
|
@ -460,16 +467,21 @@ drucken</string>
|
||||||
<string>Auswertung</string>
|
<string>Auswertung</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="importExcelAction">
|
|
||||||
<property name="text">
|
|
||||||
<string>Importieren (Excel)</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
<action name="exportSellerJsonAction">
|
<action name="exportSellerJsonAction">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Exportieren (JSON)</string>
|
<string>Exportieren (JSON)</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="importSellerExcelAction">
|
||||||
|
<property name="text">
|
||||||
|
<string>Aus Excel-Datei</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="importSellerJsonAction">
|
||||||
|
<property name="text">
|
||||||
|
<string>Aus JSON-Datei</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
Loading…
Reference in a new issue