use path to open json file (sellers)

This commit is contained in:
Martin Brodbeck 2018-08-09 12:58:11 +02:00
parent a04e8ad837
commit 7d98033c4a
3 changed files with 10 additions and 7 deletions

View File

@ -29,7 +29,7 @@ void JsonUtil::exportSellers(const std::string& filename, Marketplace* market)
writer->write(root, &file);
}
void JsonUtil::importSellers(const std::string& filename, Marketplace* market)
void JsonUtil::importSellers(const std::filesystem::path& filePath, Marketplace* market)
{
for (auto& seller : market->getSellers()) {
seller->setState(Seller::State::DELETE);
@ -37,7 +37,7 @@ void JsonUtil::importSellers(const std::string& filename, Marketplace* market)
market->storeToDb(true);
Json::Value jsonValues;
std::ifstream file(filename);
std::ifstream file(filePath);
file >> jsonValues;
for (auto val : jsonValues["sellers"]) {

View File

@ -4,12 +4,13 @@
#include "marketplace.h"
#include <string>
#include <filesystem>
class JsonUtil
{
public:
static void exportSellers(const std::string& filename, Marketplace* market);
static void importSellers(const std::string& filename, Marketplace* market);
static void importSellers(const std::filesystem::path& filePath, Marketplace* market);
static void exportSales(const std::string& filename, Marketplace* market, int cashPointNo);
static void importSales(const std::string& filename, Marketplace* market, int cashPointNo);
};

View File

@ -15,8 +15,8 @@
#include <posprinter.h>
#include <exception>
#include <regex>
#include <filesystem>
#include <regex>
#include <QFileDialog>
#include <QMessageBox>
@ -377,9 +377,9 @@ void MainWindow::onImportSellerExcelActionTriggered()
if (filename.isEmpty())
return;
std::filesystem::path filePath(filename.toStdWString());
ExcelReader::readSellersFromFile(filePath, marketplace_.get());
}
@ -399,7 +399,9 @@ void MainWindow::onImportSellerJsonActionTriggered()
if (filename.isEmpty())
return;
JsonUtil::importSellers(filename.toStdString(), marketplace_.get());
std::filesystem::path filePath(filename.toStdWString());
JsonUtil::importSellers(filePath, marketplace_.get());
}
void MainWindow::onExportSellerJsonActionTriggered()