Compare commits
2 commits
300c883fdc
...
e06458b419
Author | SHA1 | Date | |
---|---|---|---|
e06458b419 | |||
90e132bcc8 |
7 changed files with 59 additions and 7 deletions
|
@ -399,3 +399,39 @@ unsigned int Database::storeArticles(std::vector<Article*> articles)
|
||||||
|
|
||||||
return count;
|
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;
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ class Database
|
||||||
Database& operator=(const Database&) = delete;
|
Database& operator=(const Database&) = delete;
|
||||||
void exec(const std::string& sql);
|
void exec(const std::string& sql);
|
||||||
unsigned int storeSellers(std::vector<std::unique_ptr<Seller>>& sellers);
|
unsigned int storeSellers(std::vector<std::unique_ptr<Seller>>& sellers);
|
||||||
|
unsigned int loadSellers(std::vector<std::unique_ptr<Seller>>& sellers);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sqlite3* db_{nullptr};
|
sqlite3* db_{nullptr};
|
||||||
|
|
|
@ -12,13 +12,15 @@ Marketplace::Marketplace()
|
||||||
|
|
||||||
void Marketplace::storeToDb()
|
void Marketplace::storeToDb()
|
||||||
{
|
{
|
||||||
//const std::string DB_PATH{"/tmp/kima2.db"};
|
|
||||||
|
|
||||||
Database db;
|
Database db;
|
||||||
db.storeSellers(sellers_);
|
db.storeSellers(sellers_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Marketplace::loadFromDb() {}
|
void Marketplace::loadFromDb()
|
||||||
|
{
|
||||||
|
Database db;
|
||||||
|
db.loadSellers(sellers_);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::unique_ptr<Seller>>& Marketplace::getSellers() { return sellers_; }
|
std::vector<std::unique_ptr<Seller>>& Marketplace::getSellers() { return sellers_; }
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ void MainWindow::on_actionEditSeller_triggered()
|
||||||
STATUSBAR_TIMEOUT);
|
STATUSBAR_TIMEOUT);
|
||||||
} else {
|
} else {
|
||||||
marketplace_->loadFromDb();
|
marketplace_->loadFromDb();
|
||||||
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten <b>verworfen</b>.",
|
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten verworfen!",
|
||||||
STATUSBAR_TIMEOUT);
|
STATUSBAR_TIMEOUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,6 +18,7 @@ void SellerDialog::on_newButton_clicked()
|
||||||
{
|
{
|
||||||
ui_.tableView->model()->insertRows(ui_.tableView->model()->rowCount(), 1);
|
ui_.tableView->model()->insertRows(ui_.tableView->model()->rowCount(), 1);
|
||||||
ui_.tableView->scrollToBottom();
|
ui_.tableView->scrollToBottom();
|
||||||
|
ui_.tableView->selectRow(ui_.tableView->model()->rowCount() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SellerDialog::accept()
|
void SellerDialog::accept()
|
||||||
|
|
|
@ -5,6 +5,14 @@
|
||||||
<property name="windowModality">
|
<property name="windowModality">
|
||||||
<enum>Qt::NonModal</enum>
|
<enum>Qt::NonModal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>600</width>
|
||||||
|
<height>400</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
|
@ -38,7 +46,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="newButton">
|
<widget class="QPushButton" name="newButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Neu</string>
|
<string>&Neu</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -22,6 +22,10 @@ QVariant SellerModel::data(const QModelIndex& index, int role) const
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
Seller* seller = marketplace_->getSellers().at(index.row()).get();
|
Seller* seller = marketplace_->getSellers().at(index.row()).get();
|
||||||
|
|
||||||
|
if (seller->getState() == Seller::State::DELETE)
|
||||||
|
return QVariant::Invalid;
|
||||||
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
return seller->getUuidAsString().c_str();
|
return seller->getUuidAsString().c_str();
|
||||||
|
@ -117,12 +121,12 @@ bool SellerModel::setData(const QModelIndex& index, const QVariant& value, int r
|
||||||
|
|
||||||
bool SellerModel::insertRows(int row, int count, const QModelIndex& parent)
|
bool SellerModel::insertRows(int row, int count, const QModelIndex& parent)
|
||||||
{
|
{
|
||||||
beginInsertRows(parent, row, row + count - 1);
|
emit beginInsertRows(parent, row, row + count - 1);
|
||||||
auto seller = std::make_unique<Seller>();
|
auto seller = std::make_unique<Seller>();
|
||||||
seller->createUuid();
|
seller->createUuid();
|
||||||
seller->setSellerNo(marketplace_->getNextSellerNo());
|
seller->setSellerNo(marketplace_->getNextSellerNo());
|
||||||
marketplace_->getSellers().push_back(std::move(seller));
|
marketplace_->getSellers().push_back(std::move(seller));
|
||||||
endInsertRows();
|
emit endInsertRows();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
Loading…
Reference in a new issue