Compare commits

..

No commits in common. "e06458b419d9c66492e2a252977f4ede6184254b" and "300c883fdc6e2f3d788de810c1b21dcbd5a9bab7" have entirely different histories.

7 changed files with 7 additions and 59 deletions

View file

@ -397,41 +397,5 @@ 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;
}

View file

@ -17,7 +17,6 @@ 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};

View file

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

View file

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

View file

@ -18,7 +18,6 @@ void SellerDialog::on_newButton_clicked()
{
ui_.tableView->model()->insertRows(ui_.tableView->model()->rowCount(), 1);
ui_.tableView->scrollToBottom();
ui_.tableView->selectRow(ui_.tableView->model()->rowCount() - 1);
}
void SellerDialog::accept()

View file

@ -5,14 +5,6 @@
<property name="windowModality">
<enum>Qt::NonModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -46,7 +38,7 @@
<item>
<widget class="QPushButton" name="newButton">
<property name="text">
<string>&amp;Neu</string>
<string>Neu</string>
</property>
</widget>
</item>

View file

@ -22,10 +22,6 @@ QVariant SellerModel::data(const QModelIndex& index, int role) const
return QVariant();
Seller* seller = marketplace_->getSellers().at(index.row()).get();
if (seller->getState() == Seller::State::DELETE)
return QVariant::Invalid;
switch (index.column()) {
case 0:
return seller->getUuidAsString().c_str();
@ -121,12 +117,12 @@ bool SellerModel::setData(const QModelIndex& index, const QVariant& value, int r
bool SellerModel::insertRows(int row, int count, const QModelIndex& parent)
{
emit beginInsertRows(parent, row, row + count - 1);
beginInsertRows(parent, row, row + count - 1);
auto seller = std::make_unique<Seller>();
seller->createUuid();
seller->setSellerNo(marketplace_->getNextSellerNo());
marketplace_->getSellers().push_back(std::move(seller));
emit endInsertRows();
endInsertRows();
return true;
}