Browse Source

load sellers

allow_new_sellers
Martin Brodbeck 4 years ago
parent
commit
90e132bcc8
  1. 36
      src/core/database.cpp
  2. 1
      src/core/database.h
  3. 8
      src/core/marketplace.cpp
  4. 2
      src/gui/mainwindow.cpp

36
src/core/database.cpp

@ -397,5 +397,41 @@ unsigned int Database::storeArticles(std::vector<Article*> articles)
}
}
return count;
}
unsigned int Database::loadSellers(std::vector<std::unique_ptr<Seller>>& sellers)
{
int retCode{};
int count{};
sqlite3_stmt* stmt;
retCode = sqlite3_prepare_v2(db_,
"SELECT id, seller_no, first_name, last_name, "
"num_offered_articles FROM sellers ORDER BY seller_no",
-1, &stmt, nullptr);
if (retCode != SQLITE_OK)
throw std::runtime_error(sqlite3_errmsg(db_));
retCode = sqlite3_step(stmt);
sellers.clear();
while (retCode != SQLITE_DONE) {
++count;
auto seller = std::make_unique<Seller>();
seller->setUuidFromString(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)));
seller->setSellerNo(sqlite3_column_int(stmt, 1));
seller->setFirstName(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2)));
seller->setLastName(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3)));
seller->setNumArticlesOffered(sqlite3_column_int(stmt, 4));
seller->setState(Seller::State::OK);
sellers.push_back(std::move(seller));
retCode = sqlite3_step(stmt);
}
sqlite3_finalize(stmt);
return count;
}

1
src/core/database.h

@ -17,6 +17,7 @@ class Database
Database& operator=(const Database&) = delete;
void exec(const std::string& sql);
unsigned int storeSellers(std::vector<std::unique_ptr<Seller>>& sellers);
unsigned int loadSellers(std::vector<std::unique_ptr<Seller>>& sellers);
private:
sqlite3* db_{nullptr};

8
src/core/marketplace.cpp

@ -12,13 +12,15 @@ Marketplace::Marketplace()
void Marketplace::storeToDb()
{
//const std::string DB_PATH{"/tmp/kima2.db"};
Database db;
db.storeSellers(sellers_);
}
void Marketplace::loadFromDb() {}
void Marketplace::loadFromDb()
{
Database db;
db.loadSellers(sellers_);
}
std::vector<std::unique_ptr<Seller>>& Marketplace::getSellers() { return sellers_; }

2
src/gui/mainwindow.cpp

@ -27,7 +27,7 @@ void MainWindow::on_actionEditSeller_triggered()
STATUSBAR_TIMEOUT);
} else {
marketplace_->loadFromDb();
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten <b>verworfen</b>.",
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten verworfen!",
STATUSBAR_TIMEOUT);
}
}
Loading…
Cancel
Save