Compare commits
3 commits
b2d696ccb5
...
da4e223b16
Author | SHA1 | Date | |
---|---|---|---|
da4e223b16 | |||
61da9adce5 | |||
045bc8dd20 |
9 changed files with 140 additions and 18 deletions
|
@ -3,7 +3,8 @@ set(Boost_USE_STATIC_LIBS ON)
|
|||
find_package(Boost 1.62 COMPONENTS date_time REQUIRED)
|
||||
find_package(SQLite3 REQUIRED)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(XLNT REQUIRED xlnt)
|
||||
pkg_check_modules(XLNT REQUIRED xlnt>=1.3)
|
||||
pkg_check_modules(JSONCPP REQUIRED jsoncpp)
|
||||
|
||||
set(CORE_SOURCES
|
||||
database.cpp
|
||||
|
@ -13,10 +14,11 @@ set(CORE_SOURCES
|
|||
sale.cpp
|
||||
marketplace.cpp
|
||||
excelreader.cpp
|
||||
jsonutil
|
||||
)
|
||||
|
||||
add_library(core STATIC ${CORE_SOURCES})
|
||||
target_link_libraries(core Boost::boost Boost::date_time sqlite3 ${XLNT_LIBRARIES})
|
||||
target_link_libraries(core Boost::boost Boost::date_time sqlite3 ${XLNT_LIBRARIES} ${JSONCPP_LIBRARIES})
|
||||
if (WIN32)
|
||||
target_link_libraries(core bcrypt)
|
||||
endif()
|
||||
|
|
|
@ -8,15 +8,19 @@ void ExcelReader::readSellersFromFile(const std::string& filename, Marketplace*
|
|||
wb.load(filename);
|
||||
auto ws = wb.sheet_by_index(0);
|
||||
|
||||
const int START_ROW = 6;
|
||||
const int END_ROW = 349;
|
||||
const int START_ROW = 5;
|
||||
const int END_ROW = 350;
|
||||
|
||||
int rowCount{};
|
||||
for (const auto& row : ws.rows(false)) {
|
||||
// auto test = row[0].value<int>();
|
||||
if (rowCount < START_ROW)
|
||||
if (rowCount < START_ROW) {
|
||||
rowCount++;
|
||||
continue;
|
||||
std::cout << row[0].to_string() << "\n";
|
||||
} else if (rowCount > END_ROW) {
|
||||
break;
|
||||
}
|
||||
std::cout << row[0].value<int>() << "\n";
|
||||
rowCount++;
|
||||
}
|
||||
}
|
||||
|
|
54
src/core/jsonutil.cpp
Normal file
54
src/core/jsonutil.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include "jsonutil.h"
|
||||
#include "database.h"
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
void JsonUtil::exportSellers(const std::string& filename, Marketplace* market)
|
||||
{
|
||||
Json::Value root;
|
||||
std::ofstream file(filename);
|
||||
|
||||
Json::StreamWriterBuilder builder;
|
||||
builder["commentStyle"] = "None";
|
||||
builder["indentation"] = " ";
|
||||
|
||||
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
15
src/core/jsonutil.h
Normal file
15
src/core/jsonutil.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef JSON_H
|
||||
#define JSON_H
|
||||
|
||||
#include "marketplace.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class JsonUtil
|
||||
{
|
||||
public:
|
||||
static void exportSellers(const std::string& filename, Marketplace* market);
|
||||
static void importSellers(const std::string& filename, Marketplace* market);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -16,9 +16,6 @@ using SalesVec = std::vector<std::unique_ptr<Sale>>;
|
|||
using BasketVec = std::vector<std::unique_ptr<Article>>;
|
||||
} // namespace
|
||||
|
||||
struct Basket {
|
||||
};
|
||||
|
||||
class Marketplace
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -14,8 +14,8 @@ int main(int argc, char* argv[])
|
|||
|
||||
// Set the locale to german, so that currency is correct
|
||||
// std::locale german("de_DE.utf-8");
|
||||
std::locale myLocale("");
|
||||
std::locale::global(myLocale);
|
||||
//std::locale myLocale("");
|
||||
//std::locale::global(myLocale);
|
||||
|
||||
QApplication kimaApp{argc, argv};
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "basketmodel.h"
|
||||
#include "config.h"
|
||||
#include "jsonutil.h"
|
||||
#include "pricedialog.h"
|
||||
#include "reportdialog.h"
|
||||
#include "salemodel.h"
|
||||
|
@ -61,8 +62,12 @@ MainWindow::MainWindow()
|
|||
this->setWindowTitle("KIMA2 - Kasse Nr. " +
|
||||
QSettings().value("global/cashPointNo").toString());
|
||||
});
|
||||
connect(ui_.importExcelAction, &QAction::triggered, this,
|
||||
&MainWindow::onImportExcelActionTriggered);
|
||||
connect(ui_.importSellerExcelAction, &QAction::triggered, this,
|
||||
&MainWindow::onImportSellerExcelActionTriggered);
|
||||
connect(ui_.importSellerJsonAction, &QAction::triggered, this,
|
||||
&MainWindow::onImportSellerJsonActionTriggered);
|
||||
connect(ui_.exportSellerJsonAction, &QAction::triggered, this,
|
||||
&MainWindow::onExportSellerJsonActionTriggered);
|
||||
}
|
||||
|
||||
void MainWindow::onActionEditSellerTriggered()
|
||||
|
@ -239,7 +244,7 @@ void MainWindow::onAbout()
|
|||
">info@rustysoft.de</a>></p>");
|
||||
}
|
||||
|
||||
void MainWindow::onImportExcelActionTriggered()
|
||||
void MainWindow::onImportSellerExcelActionTriggered()
|
||||
{
|
||||
if (!marketplace_->getSales().empty()) {
|
||||
QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich",
|
||||
|
@ -253,4 +258,29 @@ void MainWindow::onImportExcelActionTriggered()
|
|||
"Excel Dateien (*.xlsx *.xls)");
|
||||
|
||||
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()
|
||||
{
|
||||
auto filename = QFileDialog::getSaveFileName(this, "Verkäufer exportieren", QString(),
|
||||
"JSON Dateien (*.json)");
|
||||
|
||||
JsonUtil::exportSellers(filename.toStdString(), marketplace_.get());
|
||||
}
|
|
@ -32,7 +32,9 @@ class MainWindow : public QMainWindow
|
|||
void onActionEditSellerTriggered();
|
||||
void onSellerNoEditCheckSellerNo();
|
||||
void onPaidButtonTriggered();
|
||||
void onImportExcelActionTriggered();
|
||||
void onImportSellerExcelActionTriggered();
|
||||
void onImportSellerJsonActionTriggered();
|
||||
void onExportSellerJsonActionTriggered();
|
||||
void setSaleModel();
|
||||
|
||||
Ui::MainWindow ui_;
|
||||
|
|
|
@ -403,8 +403,16 @@ drucken</string>
|
|||
<property name="title">
|
||||
<string>&Verkäufer</string>
|
||||
</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="importExcelAction"/>
|
||||
<addaction name="importSellerMenu"/>
|
||||
<addaction name="exportSellerJsonAction"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuHilfe">
|
||||
<property name="title">
|
||||
|
@ -459,9 +467,19 @@ drucken</string>
|
|||
<string>Auswertung</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="importExcelAction">
|
||||
<action name="exportSellerJsonAction">
|
||||
<property name="text">
|
||||
<string>Importieren (Excel)</string>
|
||||
<string>Exportieren (JSON)</string>
|
||||
</property>
|
||||
</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>
|
||||
|
|
Loading…
Reference in a new issue