2019-08-05 13:55:29 +00:00
|
|
|
#include "editwindow.h"
|
2019-08-03 15:24:44 +00:00
|
|
|
|
2019-08-05 21:52:33 +00:00
|
|
|
EditWindow::EditWindow(int idSocio, QWidget* parent) : QMainWindow(parent), ui(new Ui::EditWindow) {
|
2019-08-03 15:24:44 +00:00
|
|
|
ui->setupUi(this);
|
|
|
|
|
2019-08-05 21:52:33 +00:00
|
|
|
/* retrieve all elements of the GUI */
|
2019-08-05 13:32:44 +00:00
|
|
|
lineID = this->findChild<QLineEdit*>("lineID");
|
|
|
|
lineNome = this->findChild<QLineEdit*>("lineNome");
|
|
|
|
lineCognome = this->findChild<QLineEdit*>("lineCognome");
|
|
|
|
lineComuneResidenza = this->findChild<QLineEdit*>("lineComuneResidenza");
|
|
|
|
lineEmail = this->findChild<QLineEdit*>("lineEmail");
|
|
|
|
dateDataNascita = this->findChild<QDateEdit*>("dateDataNascita");
|
|
|
|
dateDataCompilazione = this->findChild<QDateEdit*>("dateDataCompilazione");
|
|
|
|
comboProfessione = this->findChild<QComboBox*>("comboProfessione");
|
|
|
|
comboFonte = this->findChild<QComboBox*>("comboFonte");
|
|
|
|
checkAbilitaQuestionario = this->findChild<QCheckBox*>("checkAbilitaQuestionario");
|
|
|
|
|
2019-08-05 21:52:33 +00:00
|
|
|
/* retrieve professione and fonte from database */
|
2019-08-04 14:00:50 +00:00
|
|
|
query.prepare("SELECT id, professione FROM professione ORDER BY professione");
|
|
|
|
query.exec();
|
2019-08-03 15:24:44 +00:00
|
|
|
while (query.next()) {
|
2019-08-03 16:18:29 +00:00
|
|
|
comboProfessione->addItem(query.value(1).toString(), query.value(0).toInt());
|
2019-08-03 15:24:44 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 14:00:50 +00:00
|
|
|
query.prepare("SELECT id, fonte FROM fonte ORDER BY fonte");
|
|
|
|
query.exec();
|
2019-08-03 15:48:30 +00:00
|
|
|
while (query.next()) {
|
2019-08-03 16:18:29 +00:00
|
|
|
comboFonte->addItem(query.value(1).toString(), query.value(0).toInt());
|
2019-08-03 15:48:30 +00:00
|
|
|
}
|
|
|
|
|
2019-08-05 21:52:33 +00:00
|
|
|
/* populate fields from database */
|
|
|
|
query.prepare("SELECT s.id, s.nome, s.cognome, \
|
|
|
|
s.dataNascita, s.comuneResidenza, s.email, s.professione, s.fonte, s.abilitaQuestionario, \
|
|
|
|
q.dataCompilazione \
|
|
|
|
FROM socio AS s LEFT OUTER JOIN questionario AS q ON s.id = q.socio \
|
|
|
|
WHERE s.id = :id");
|
|
|
|
query.bindValue( ":id", idSocio );
|
|
|
|
query.exec();
|
|
|
|
query.first();
|
|
|
|
|
2019-08-06 09:11:20 +00:00
|
|
|
/* show everything in the interface */
|
|
|
|
lineID->setText(query.value( query.record().indexOf("id") ).toString());
|
|
|
|
lineNome->setText(query.value( query.record().indexOf("nome") ).toString());
|
|
|
|
lineCognome->setText(query.value( query.record().indexOf("cognome") ).toString());
|
|
|
|
lineComuneResidenza->setText(query.value(query.record().indexOf("comuneResidenza")).toString());
|
|
|
|
lineEmail->setText(query.value(query.record().indexOf("email")).toString());
|
|
|
|
comboProfessione->setCurrentIndex(comboProfessione->findData(query.value(query.record().indexOf("professione")).toInt()));
|
|
|
|
comboFonte->setCurrentIndex(comboFonte->findData(query.value(query.record().indexOf("fonte")).toInt()));
|
|
|
|
dateDataNascita->setDate(QDate(1900, 1, 1)); dateDataNascita->setDate(query.value(query.record().indexOf("dataNascita")).toDate());
|
|
|
|
dateDataCompilazione->setDate(QDate(1900, 1, 1)); dateDataCompilazione->setDate(query.value(query.record().indexOf("dataCompilazione")).toDate());
|
|
|
|
checkAbilitaQuestionario->setChecked( query.value(query.record().indexOf("abilitaQuestionario")).toBool() );
|
2019-08-03 15:24:44 +00:00
|
|
|
}
|
|
|
|
|
2019-08-05 21:52:33 +00:00
|
|
|
/*
|
2019-08-05 13:55:29 +00:00
|
|
|
void EditWindow::on_buttonCerca_clicked() {
|
2019-08-03 16:18:29 +00:00
|
|
|
QLineEdit* lineCognome = this->findChild<QLineEdit*>("lineCognome");
|
|
|
|
|
2019-08-05 21:52:33 +00:00
|
|
|
|
2019-08-03 16:18:29 +00:00
|
|
|
|
2019-08-05 13:32:44 +00:00
|
|
|
if ( ! query.exec() ) { setStatus(Ui::ERROR, "query error"); qDebug() << query.lastQuery(); return; }
|
2019-08-04 14:00:50 +00:00
|
|
|
if ( query.size() == 0) { setStatus(Ui::INFO, "no results found"); return; }
|
2019-08-03 16:18:29 +00:00
|
|
|
|
2019-08-04 14:00:50 +00:00
|
|
|
setStatus(Ui::INFO, QString("%1 results found").arg(query.size()));
|
|
|
|
query.first();
|
|
|
|
showFound();
|
|
|
|
}
|
2019-08-05 21:52:33 +00:00
|
|
|
*/
|
2019-08-03 16:18:29 +00:00
|
|
|
|
2019-08-06 09:11:20 +00:00
|
|
|
void EditWindow::on_buttonSalva_clicked() {
|
2019-08-05 13:32:44 +00:00
|
|
|
|
|
|
|
query.prepare("UPDATE socio \
|
|
|
|
SET nome = NULLIF(:nome, ''), \
|
|
|
|
cognome = NULLIF(:cognome, ''), \
|
|
|
|
dataNascita = NULLIF(:dataNascita, '1900-01-01'), \
|
|
|
|
comuneResidenza = NULLIF(:comuneResidenza, ''), \
|
|
|
|
email = NULLIF(:email, ''), \
|
|
|
|
professione = NULLIF(:professione, 0), \
|
|
|
|
fonte = NULLIF(:fonte, 0), \
|
|
|
|
abilitaQuestionario = :abilitaQuestionario \
|
|
|
|
WHERE id = :id");
|
|
|
|
query.bindValue(":id", lineID->text());
|
|
|
|
query.bindValue(":nome", lineNome->text());
|
|
|
|
query.bindValue(":cognome", lineCognome->text());
|
|
|
|
query.bindValue(":comuneResidenza", lineComuneResidenza->text());
|
|
|
|
query.bindValue(":email", lineEmail->text());
|
|
|
|
query.bindValue(":dataNascita", (dateDataNascita->date()).toString("yyyy-MM-dd"));
|
|
|
|
query.bindValue(":professione", comboProfessione->currentData().toInt());
|
|
|
|
query.bindValue(":fonte", comboFonte->currentData().toInt());
|
|
|
|
query.bindValue(":abilitaQuestionario", checkAbilitaQuestionario->isChecked());
|
|
|
|
|
|
|
|
if ( ! query.exec() ) {
|
|
|
|
qDebug() << fullQuery(query);
|
|
|
|
qDebug() << db.lastError().text();
|
|
|
|
setStatus(Ui::ERROR, "query error");
|
|
|
|
return;
|
|
|
|
}
|
2019-08-03 16:18:29 +00:00
|
|
|
|
2019-08-05 13:32:44 +00:00
|
|
|
setStatus(Ui::SUCCESS, "successfull update");
|
2019-08-03 16:18:29 +00:00
|
|
|
}
|
|
|
|
|
2019-08-05 13:55:29 +00:00
|
|
|
void EditWindow::setStatus(Ui::StatusType type, QString message) {
|
2019-08-04 14:00:50 +00:00
|
|
|
QStatusBar* statusBar = this->findChild<QStatusBar*>("statusBar");
|
|
|
|
int timeout = 0;
|
|
|
|
|
|
|
|
/* choose background color */
|
|
|
|
switch (type) {
|
|
|
|
case Ui::INFO: statusBar->setStyleSheet("background-color: #9dd;"); break;
|
|
|
|
case Ui::SUCCESS: statusBar->setStyleSheet("background-color: #5a0;"); break;
|
|
|
|
case Ui::WARNING: statusBar->setStyleSheet("background-color: #ff7;"); break;
|
|
|
|
case Ui::ERROR: statusBar->setStyleSheet("background-color: #d00;"); break;
|
|
|
|
}
|
|
|
|
/* choose timeout */
|
|
|
|
switch (type) {
|
|
|
|
case Ui::INFO: case Ui::SUCCESS: timeout = 10000; break;
|
|
|
|
case Ui::WARNING: case Ui::ERROR: timeout = 0; break;
|
|
|
|
}
|
|
|
|
statusBar->showMessage(message, timeout);
|
|
|
|
}
|
|
|
|
|
2019-08-06 09:11:20 +00:00
|
|
|
void EditWindow::on_buttonAnnulla_clicked() {
|
|
|
|
this->close();
|
|
|
|
}
|
2019-08-03 16:18:29 +00:00
|
|
|
|
2019-08-05 13:55:29 +00:00
|
|
|
EditWindow::~EditWindow()
|
2019-08-03 15:24:44 +00:00
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|