new socio creation

This commit is contained in:
giomba 2019-08-07 17:18:09 +02:00
parent 511c6ea84b
commit c603c1dea3
1 changed files with 15 additions and 2 deletions

View File

@ -42,7 +42,7 @@ void MainWindow::on_buttonCerca_clicked() {
query.bindValue( ":nome", QString("%%1%").arg(lineNome->text()) );
query.bindValue( ":cognome", QString("%%1%").arg(lineCognome->text()) );
if ( ! query.exec() ) { qDebug() << query.lastQuery(); return; }
if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; }
if ( query.size() == 0) { status(Ui::INFO, "no results found"); return; }
if (sociModel != nullptr) delete sociModel; // TODO -- does this look a cunning thing?
@ -56,7 +56,20 @@ void MainWindow::on_buttonCerca_clicked() {
tableSoci->show();
}
void MainWindow::on_buttonNuovo_clicked() { /* TODO -- please implement me thanks */;}
void MainWindow::on_buttonNuovo_clicked() {
if (! db.open()) connectDatabase();
query.prepare("INSERT INTO socio (nome, cognome) VALUES (NULLIF(:nome, ''), NULLIF(:cognome, ''))");
query.bindValue(":nome", lineNome->text());
query.bindValue(":cognome", lineCognome->text());
if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; }
if (! query.lastInsertId().isValid()) { status(Ui::ERROR, fullQuery(query)); return; }
EditWindow*w = new EditWindow(query.lastInsertId().toInt(), this);
w->setAttribute(Qt::WA_DeleteOnClose);
w->show();
}
void MainWindow::on_tableSoci_clicked(const QModelIndex& index) {
if (index.isValid()) {