Aggiunta blandamente la feature di auto rinnovo per l'anno corrente all'atto della registrazione #7
|
@ -34,15 +34,30 @@ void SociListTab::on_buttonCerca_clicked() {
|
|||
}
|
||||
|
||||
void SociListTab::on_buttonNuovo_clicked() {
|
||||
QSqlQuery query;
|
||||
query.prepare("INSERT INTO socio (nome, cognome) VALUES (NULLIF(:nome, ''), NULLIF(:cognome, ''))");
|
||||
query.bindValue(":nome", ui->lineNome->text());
|
||||
query.bindValue(":cognome", ui->lineCognome->text());
|
||||
if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; }
|
||||
int lastInsertId = 0;
|
||||
|
||||
if (! query.lastInsertId().isValid()) { status(Ui::ERROR, fullQuery(query)); return; }
|
||||
// Add new associate
|
||||
{
|
||||
QSqlQuery query;
|
||||
query.prepare("INSERT INTO socio (nome, cognome) VALUES (NULLIF(:nome, ''), NULLIF(:cognome, ''))");
|
||||
query.bindValue(":nome", ui->lineNome->text());
|
||||
query.bindValue(":cognome", ui->lineCognome->text());
|
||||
if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; }
|
||||
|
||||
EditWindow*w = new EditWindow(query.lastInsertId().toInt(), this);
|
||||
if (! query.lastInsertId().isValid()) { status(Ui::ERROR, fullQuery(query)); return; }
|
||||
|
||||
lastInsertId = query.lastInsertId().toInt();
|
||||
}
|
||||
|
||||
// Auto renewal for current year
|
||||
{
|
||||
QSqlQuery query;
|
||||
query.prepare("INSERT INTO iscrizione (socio) VALUES (:socio)");
|
||||
query.bindValue(":socio", lastInsertId);
|
||||
if (! query.exec()) { status(Ui::ERROR, fullQuery(query)); return; }
|
||||
}
|
||||
|
||||
|
||||
EditWindow*w = new EditWindow(lastInsertId, this);
|
||||
w->setAttribute(Qt::WA_DeleteOnClose);
|
||||
w->show();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Forse questa doppia operazione andrebbe fatta in una transaction.
https://forum.qt.io/topic/109778/qsqldatabase-sqlite-transaction-inside-of-qsqlquery-how/2
(non testato)