import sellers from excel works now

This commit is contained in:
Martin Brodbeck 2018-08-02 14:39:32 +02:00
parent 23708b0f1e
commit 67643c665f

View file

@ -4,6 +4,11 @@
void ExcelReader::readSellersFromFile(const std::string& filename, Marketplace* market)
{
for (auto& seller : market->getSellers()) {
seller->setState(Seller::State::DELETE);
}
market->storeToDb(true);
xlnt::workbook wb;
wb.load(filename);
auto ws = wb.sheet_by_index(0);
@ -15,12 +20,23 @@ void ExcelReader::readSellersFromFile(const std::string& filename, Marketplace*
for (const auto& row : ws.rows(false)) {
// auto test = row[0].value<int>();
if (rowCount < START_ROW) {
rowCount++;
++rowCount;
continue;
} else if (rowCount > END_ROW) {
break;
}
std::cout << row[0].value<int>() << "\n";
if(row[2].value<std::string>().empty() && row[3].value<std::string>().empty()) {
++rowCount;
continue;
}
auto seller = std::make_unique<Seller>();
seller->createUuid();
seller->setSellerNo(row[0].value<int>());
seller->setNumArticlesOffered(row[1].value<int>());
seller->setFirstName(row[2].value<std::string>());
seller->setLastName(row[3].value<std::string>());
market->getSellers().push_back(std::move(seller));
rowCount++;
}
market->storeToDb();
}