Aggiunta blandamente la feature di auto rinnovo per l'anno corrente all'atto della registrazione

This commit is contained in:
giuliof 2023-05-02 21:59:25 +02:00
parent 004a53300e
commit d1113f48fe
1 changed files with 22 additions and 7 deletions

View File

@ -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();
}