diff --git a/nicolodi/EditWindow.cpp b/nicolodi/EditWindow.cpp new file mode 100644 index 0000000..83dc0ca --- /dev/null +++ b/nicolodi/EditWindow.cpp @@ -0,0 +1,146 @@ +#include "EditWindow.h" +#include "ui_EditWindow.h" + +EditWindow::EditWindow(int idSocio, QString pin, QWidget *parent) : + QMainWindow(parent), + ui(new Ui::EditWindow) +{ + ui->setupUi(this); + + if (!db.open()) { + // QMessageBox::critical(this, "Nicolodi", "Problemi con la connessione al db"); + showError(db.lastError()); + this->doNotShow = true; + return; + } + + // Crea il model + model = new QSqlRelationalTableModel(this); + model->setTable("socio"); + model->setFilter(QString("socio.id = %1").arg(idSocio)); + model->setEditStrategy(QSqlTableModel::OnManualSubmit); + + // Indici dei campi in join + //professioneIdx = model->fieldIndex("professione"); + //fonteIdx = model->fieldIndex("fonte"); + + // La strategia di join da usare per le rleazioni e' LeftJoin + model->setJoinMode(QSqlRelationalTableModel::LeftJoin); + + // Imposta le relazioni + model->setRelation(professioneIdx, QSqlRelation("professione", "id", "professione")); + model->setRelation(fonteIdx, QSqlRelation("fonte", "id", "fonte")); + + // Popola il model + if (!model->select()) { + showError(model->lastError()); + showError(model->query().lastQuery()); + this->doNotShow = true; + return; + } + + // Inizializza la combo professioni + QSqlTableModel *professioneModel = model->relationModel(professioneIdx); + ui->comboBoxProfessione->setModel(professioneModel); + ui->comboBoxProfessione->setModelColumn(professioneModel->fieldIndex("professione")); + + // Inizializza la combo fonti + QSqlTableModel *fonteModel = model->relationModel(fonteIdx); + ui->comboBoxFonte->setModel(fonteModel); + ui->comboBoxFonte->setModelColumn(fonteModel->fieldIndex("fonte")); + + QDataWidgetMapper *mapper = new QDataWidgetMapper(this); + mapper->setModel(model); + mapper->setItemDelegate(new QSqlRelationalDelegate(this)); + mapper->addMapping(ui->lineEditId, model->fieldIndex("id")); + mapper->addMapping(ui->lineEditCognome, model->fieldIndex("cognome")); + mapper->addMapping(ui->lineEditNome, model->fieldIndex("nome")); + mapper->addMapping(ui->dateEditDataDiNascita, model->fieldIndex("dataNascita")); + mapper->addMapping(ui->lineEditComuneResidenza, model->fieldIndex("comuneResidenza")); + mapper->addMapping(ui->lineEditEmail, model->fieldIndex("email")); + mapper->addMapping(ui->comboBoxProfessione, professioneIdx); + mapper->addMapping(ui->comboBoxFonte, fonteIdx); + + mapper->toFirst(); +} + +void EditWindow::showError(const QSqlError &err) +{ + QMessageBox::critical(this, "Nicolodi", + "Errore nell'accesso ai dati: " + err.text()); +} + + +EditWindow::~EditWindow() +{ + delete ui; +} + +void EditWindow::closeEvent (QCloseEvent *event) +{ + if (model->isDirty()) { + QMessageBox::StandardButton resBtn; + resBtn = QMessageBox::question(this + , "Nicolodi" + , "Dati variati: esco senza salvare?" + , QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + if (resBtn == QMessageBox::Yes) { + event->accept(); + } else { + event->ignore(); + } + } +} + +void EditWindow::on_pushButtonAnnulla_clicked() +{ + this->close(); +} + +void EditWindow::on_pushButtonSalva_clicked() { + QMessageBox::StandardButton resBtn; + QSqlQuery query; + QString sql; + int abilitaQuestionarioIdx; + QSqlRecord currentRecord; + if (model->isDirty()) { + resBtn = QMessageBox::question(this + , "Nicolodi" + , "Dati variati: confermi salvataggio prima di uscire?" + , QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + if (resBtn == QMessageBox::Yes) { + abilitaQuestionarioIdx = model->fieldIndex("abilitaQuestionario"); + //currentRecord = model->record(0); + //currentRecord.setValue(abilitaQuestionarioIdx, false); + model->setData(model->index(0, abilitaQuestionarioIdx), false); + // //model->query() + // query = QSqlQuery(db); + // sql = QString("call aggiornaQuestionarioDaNicolodi(:parId") + // % QString(", :parPin") + // % QString(", :parNome") + // % QString(", :parCognome") + // % QString(", :parDataNascita") + // % QString(", :parComuneResidenza") + // % QString(", :parEmail") + // % QString(", :parProfessione") + // % QString(", :parFonte") + // % QString(");"); + // query.prepare(sql); + // + // //query.bindValue(":parId", ui->lineEditId->text()); + // //query.bindValue(":parId", model->fieldIndex("id")->); + model->database().transaction(); + if (model->submitAll()) { + model->database().commit(); + this->close(); + } else { + model->database().rollback(); + showError(model->lastError()); + } + } else { + this->close(); + } + } else { + this->close(); + } +} diff --git a/nicolodi/EditWindow.h b/nicolodi/EditWindow.h new file mode 100644 index 0000000..7d26999 --- /dev/null +++ b/nicolodi/EditWindow.h @@ -0,0 +1,42 @@ +#ifndef EDITWINDOW_H +#define EDITWINDOW_H + +#include +#include +#include +#include +#include +#include "db.h" + +namespace Ui { +class EditWindow; +} + +class EditWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit EditWindow(int idSocio, QString pin, QWidget *parent = nullptr); + ~EditWindow(); + + bool doNotShow = false; + +private slots: + void on_pushButtonAnnulla_clicked(); + + void on_pushButtonSalva_clicked(); + +private: + Ui::EditWindow *ui; + QSqlRelationalTableModel *model; + bool doNotShow_; + int professioneIdx; + int fonteIdx; + + void showError(const QSqlError &err); + void closeEvent(QCloseEvent *event); + +}; + +#endif // EDITWINDOW_H diff --git a/nicolodi/EditWindow.ui b/nicolodi/EditWindow.ui new file mode 100644 index 0000000..6d85d0e --- /dev/null +++ b/nicolodi/EditWindow.ui @@ -0,0 +1,147 @@ + + + EditWindow + + + + 0 + 0 + 800 + 304 + + + + MainWindow + + + + + + + + + + + + 0 + 0 + + + + Id + + + + + + + true + + + + + + + Cognome + + + + + + + + + + Nome + + + + + + + + + + QFrame::NoFrame + + + Data di nascita + + + + + + + true + + + + + + + E-mail + + + + + + + + + + Occupazione + + + + + + + + + + Fonte + + + + + + + + + + Comune di residenza + + + + + + + + + + + + + + &Salva + + + + + + + &Annulla + + + + + + + + + + + + + + diff --git a/nicolodi/MainWindow.cpp b/nicolodi/MainWindow.cpp deleted file mode 100644 index 7714da4..0000000 --- a/nicolodi/MainWindow.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "MainWindow.h" -#include "ui_MainWindow.h" - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) -{ - ui->setupUi(this); - - this->statusBar()->showMessage("Hello World"); -} - -MainWindow::~MainWindow() -{ - delete ui; -} diff --git a/nicolodi/MainWindow.h b/nicolodi/MainWindow.h deleted file mode 100644 index 9353441..0000000 --- a/nicolodi/MainWindow.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include - -namespace Ui { -class MainWindow; -} - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = nullptr); - ~MainWindow(); - -private: - Ui::MainWindow *ui; -}; - -#endif // MAINWINDOW_H diff --git a/nicolodi/MainWindow.ui b/nicolodi/MainWindow.ui deleted file mode 100644 index 6050363..0000000 --- a/nicolodi/MainWindow.ui +++ /dev/null @@ -1,24 +0,0 @@ - - MainWindow - - - - 0 - 0 - 400 - 300 - - - - MainWindow - - - - - - - - - - - diff --git a/nicolodi/Pin.cpp b/nicolodi/Pin.cpp new file mode 100644 index 0000000..373e6bf --- /dev/null +++ b/nicolodi/Pin.cpp @@ -0,0 +1,87 @@ +#include "Pin.h" +#include "ui_Pin.h" +#include "EditWindow.h" + +Pin::Pin(QWidget *parent) : + QDialog(parent), + ui(new Ui::Pin) +{ + ui->setupUi(this); + + // Imposta la dialog come non ingrandibile/riducibile + this->setFixedSize(this->size()); + + if (!QSqlDatabase::drivers().contains("QMYSQL")) { + QMessageBox::critical(this, "Nicolodi", "L'applicazione necessita del driver MYSQL"); + } + + ui->lineEditPin->setFocus(); +} + +Pin::~Pin() +{ + delete ui; +} + +void Pin::on_pushButtonOk_clicked() +{ + QSqlQuery query; + int idSocio = 0; + bool questionarioAbilitato; + QString pin = ui->lineEditPin->text(); + + connectDatabase(); + + if (db.open()) { + query = QSqlQuery(db); + query.prepare("SELECT id, abilitaQuestionario FROM socio WHERE pin = :pin"); + query.bindValue(":pin", QString("%1").arg(pin)); + if (!query.exec()) { + QMessageBox::critical(this, "Nicolodi", "Errore nella verifica del pin, verificare query."); + } else { + if (query.size() == 0) { + QMessageBox::warning(this, "Nicolodi", "Pin errato!"); + } else if (query.size() > 1) { + QMessageBox::warning(this, "Nicolodi", "Pin non univoco!"); + } else { + query.first(); + questionarioAbilitato = query.value(1).toBool(); + if (!questionarioAbilitato) { + QMessageBox::information(this, "Nicolodi", QString("Questionario non abilitato per PIN %1").arg(pin)); + } else { + idSocio = query.value(0).toInt(); + // QMessageBox::information(this, "Nicolodi", QString("Il socio ha id %1").arg(idSocio)); + } + } + } + // Pulizia oggetti db + // Per rilasciare le risorse + // Qui come funziona? Di solito le risorse tipo le connessioni + // sono risorse preziose che si devono aprire, usare per il minor + // tempo possibile e quindi chiudere + query.clear(); + db.close(); + } else { + QMessageBox::critical(this, "Nicolodi", "Impossibile connettersi al database, verificare impostazioni."); + } + + ui->lineEditPin->setText(""); + ui->lineEditPin->setFocus(); + + // Se ho scelto un socio valido proseguo con l'apertura + // delle editwindow + // Un socio e' valido se ha idSocio maggiore di zero + if (idSocio > 0) { + EditWindow *ew = new EditWindow(idSocio, pin, this); + ew->setAttribute(Qt::WA_DeleteOnClose); + ew->setWindowModality(Qt::ApplicationModal); + if (!ew->doNotShow) { + ew->show(); + } + } +} + +void Pin::on_pushButtonEsci_clicked() +{ + QApplication::exit(); +} diff --git a/nicolodi/Pin.h b/nicolodi/Pin.h new file mode 100644 index 0000000..b152d4c --- /dev/null +++ b/nicolodi/Pin.h @@ -0,0 +1,33 @@ +#ifndef PIN_H +#define PIN_H + +#include +#include +#include +#include +#include "db.h" +// #include "status.h" +// #include "fullQuery.h" + +namespace Ui { +class Pin; +} + +class Pin : public QDialog +{ + Q_OBJECT + +public: + explicit Pin(QWidget *parent = nullptr); + ~Pin(); + +private slots: + void on_pushButtonOk_clicked(); + + void on_pushButtonEsci_clicked(); + +private: + Ui::Pin *ui; +}; + +#endif // PIN_H diff --git a/nicolodi/Pin.ui b/nicolodi/Pin.ui new file mode 100644 index 0000000..58d859c --- /dev/null +++ b/nicolodi/Pin.ui @@ -0,0 +1,111 @@ + + + Pin + + + + 0 + 0 + 400 + 108 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Questionario GOLEM + + + + + 10 + 10 + 381 + 91 + + + + Accesso al questionario + + + + + 10 + 20 + 361 + 22 + + + + + + + Pin + + + + + + + + + + QLineEdit::Password + + + + + + + + + 210 + 50 + 75 + 23 + + + + + + + &Ok + + + + + + 290 + 50 + 75 + 23 + + + + + + + &Esci + + + + + + + diff --git a/nicolodi/db.cpp b/nicolodi/db.cpp new file mode 100644 index 0000000..47eafdf --- /dev/null +++ b/nicolodi/db.cpp @@ -0,0 +1,37 @@ +#include "db.h" + +QSqlDatabase db; + +void connectDatabase() { + /* retrieve settings for this application, group database */ + QSettings settings("it.linux.golem", "nicolodi"); + settings.beginGroup("database"); + + /* open database and attach query */ + db = QSqlDatabase::addDatabase("QMYSQL"); /* QMYSQL <-- database driver */ + + // db.setHostName(settings.value("hostname").toString()); + // db.setDatabaseName(settings.value("database").toString()); + // db.setUserName(settings.value("username").toString()); + // db.setPassword(settings.value("password").toString()); + + // db.setHostName(settings.value("hostname","serverozzo.golem.linux.it").toString()); + // db.setDatabaseName(settings.value("database","golem_gestionale").toString()); + // db.setPort(settings.value("port", "3306").toInt()); + // db.setUserName(settings.value("username").toString()); + // db.setPassword(settings.value("password").toString()); + + QString hostname = settings.value("hostname","localhost").toString(); + QString database = settings.value("database","golem_gestionale").toString(); + int port = settings.value("port", "3306").toInt(); + QString username = settings.value("username", "admin").toString(); + QString password = settings.value("password", "password").toString(); + + db.setHostName(hostname); + db.setDatabaseName(database); + db.setPort(port); + db.setUserName(username); + db.setPassword(password); + + // query = QSqlQuery(db); +} diff --git a/nicolodi/db.h b/nicolodi/db.h new file mode 100644 index 0000000..0be99df --- /dev/null +++ b/nicolodi/db.h @@ -0,0 +1,15 @@ +#ifndef DB_H +#define DB_H + +#include +#include +#include +#include +#include + +extern QSqlDatabase db; +// extern QSqlQuery query; + +extern void connectDatabase(); + +#endif // DB_H diff --git a/nicolodi/dump-golem_gestionale-201908130124.sql b/nicolodi/dump-golem_gestionale-201908130124.sql new file mode 100644 index 0000000..af85690 --- /dev/null +++ b/nicolodi/dump-golem_gestionale-201908130124.sql @@ -0,0 +1,168 @@ +-- MySQL dump 10.13 Distrib 8.0.17, for Win64 (x86_64) +-- +-- Host: localhost Database: golem_gestionale +-- ------------------------------------------------------ +-- Server version 8.0.17 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!50503 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `fonte` +-- + +DROP TABLE IF EXISTS `fonte`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `fonte` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `fonte` tinytext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `fonte` +-- + +LOCK TABLES `fonte` WRITE; +/*!40000 ALTER TABLE `fonte` DISABLE KEYS */; +INSERT INTO `fonte` VALUES (1,'Altro'),(2,'Socio fondatore'),(3,'Socio di vecchia data'),(4,'Passaparola'),(5,'Eventi organizzati dall\'associazione (es. Linux Day)'),(6,'Social network (Facebook, Twitter, ...)'); +/*!40000 ALTER TABLE `fonte` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `iscrizione` +-- + +DROP TABLE IF EXISTS `iscrizione`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `iscrizione` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `socio` int(11) NOT NULL, + `anno` date NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `iscrizione_UN` (`socio`,`anno`), + CONSTRAINT `iscrizione_FK` FOREIGN KEY (`socio`) REFERENCES `socio` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `iscrizione` +-- + +LOCK TABLES `iscrizione` WRITE; +/*!40000 ALTER TABLE `iscrizione` DISABLE KEYS */; +/*!40000 ALTER TABLE `iscrizione` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `professione` +-- + +DROP TABLE IF EXISTS `professione`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `professione` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `professione` tinytext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `professione` +-- + +LOCK TABLES `professione` WRITE; +/*!40000 ALTER TABLE `professione` DISABLE KEYS */; +INSERT INTO `professione` VALUES (1,'Altro'),(2,'Studente'),(3,'Casalingo'),(4,'Tecnico Informatico'),(5,'Professore, Insegnante'),(6,'Scrittore, Giornalista'),(7,'Membro del clero'),(8,'Medico, Farmacista, Infermiere'),(9,'Magistrato, Avvocato, Notaio'),(10,'Agronomo, Veterinario, Biologo'),(11,'Fisico, Chimico, Ingegnere, Geometra'),(12,'Matematico, Statistico'),(13,'Economista, Commercialista'),(14,'Imprenditore'),(15,'Impiegato amministrativo'),(16,'Membro dei corpi armati, dei corpi di polizia'); +/*!40000 ALTER TABLE `professione` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `questionario` +-- + +DROP TABLE IF EXISTS `questionario`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `questionario` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `socio` int(11) NOT NULL, + `dataCompilazione` date DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `questionario_UN` (`socio`), + CONSTRAINT `questionario_FK` FOREIGN KEY (`socio`) REFERENCES `socio` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `questionario` +-- + +LOCK TABLES `questionario` WRITE; +/*!40000 ALTER TABLE `questionario` DISABLE KEYS */; +INSERT INTO `questionario` VALUES (1,2,'2018-09-09'); +/*!40000 ALTER TABLE `questionario` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `socio` +-- + +DROP TABLE IF EXISTS `socio`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `socio` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `nome` tinytext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + `cognome` tinytext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + `dataNascita` date DEFAULT NULL, + `comuneResidenza` tinytext CHARACTER SET utf8 COLLATE utf8_bin, + `email` tinytext CHARACTER SET utf8 COLLATE utf8_bin, + `professione` int(11) DEFAULT NULL, + `fonte` int(11) DEFAULT NULL, + `abilitaQuestionario` tinyint(1) NOT NULL DEFAULT '0', + `pin` varchar(5) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `socio_FK` (`professione`), + KEY `socio_FK_1` (`fonte`), + CONSTRAINT `socio_FK` FOREIGN KEY (`professione`) REFERENCES `professione` (`id`) ON UPDATE CASCADE, + CONSTRAINT `socio_FK_1` FOREIGN KEY (`fonte`) REFERENCES `fonte` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `socio` +-- + +LOCK TABLES `socio` WRITE; +/*!40000 ALTER TABLE `socio` DISABLE KEYS */; +INSERT INTO `socio` VALUES (1,'Massimo','Moroni','1965-11-20','Fiesole','massimodafirenze@gmail.com',14,5,1,'123'),(2,'Linux','Morrox','1972-07-01','Catania','morrolinux@gmail.com',5,6,1,'456'),(3,'Simone','Bagni','1969-02-02','Montelupo Fiorentino','massimobagni@libero.it',4,3,0,NULL),(4,'Jane','Doe','1875-02-28','Naples','doe@linux.it',11,4,0,NULL),(5,'Paolino','Paperino','1930-01-01','Torino',NULL,3,NULL,0,NULL),(6,'Pinco','Pallino','1990-08-29','Empoli',NULL,1,NULL,0,NULL),(7,'Damigian','Damigiano',NULL,'Qui','Quo',15,2,1,NULL); +/*!40000 ALTER TABLE `socio` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Dumping routines for database 'golem_gestionale' +-- +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2019-08-13 1:24:18 diff --git a/nicolodi/dump-golem_gestionale-201908131659.sql b/nicolodi/dump-golem_gestionale-201908131659.sql new file mode 100644 index 0000000..cc5008a --- /dev/null +++ b/nicolodi/dump-golem_gestionale-201908131659.sql @@ -0,0 +1,284 @@ +-- MySQL dump 10.13 Distrib 8.0.17, for Win64 (x86_64) +-- +-- Host: localhost Database: golem_gestionale +-- ------------------------------------------------------ +-- Server version 8.0.17 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!50503 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `fonte` +-- + +DROP TABLE IF EXISTS `fonte`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `fonte` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `fonte` tinytext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `fonte` +-- + +LOCK TABLES `fonte` WRITE; +/*!40000 ALTER TABLE `fonte` DISABLE KEYS */; +INSERT INTO `fonte` VALUES (1,'Altro'),(2,'Socio fondatore'),(3,'Socio di vecchia data'),(4,'Passaparola'),(5,'Eventi organizzati dall\'associazione (es. Linux Day)'),(6,'Social network (Facebook, Twitter, ...)'); +/*!40000 ALTER TABLE `fonte` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `iscrizione` +-- + +DROP TABLE IF EXISTS `iscrizione`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `iscrizione` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `socio` int(11) NOT NULL, + `anno` date NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `iscrizione_UN` (`socio`,`anno`), + CONSTRAINT `iscrizione_FK` FOREIGN KEY (`socio`) REFERENCES `socio` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `iscrizione` +-- + +LOCK TABLES `iscrizione` WRITE; +/*!40000 ALTER TABLE `iscrizione` DISABLE KEYS */; +/*!40000 ALTER TABLE `iscrizione` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `professione` +-- + +DROP TABLE IF EXISTS `professione`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `professione` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `professione` tinytext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `professione` +-- + +LOCK TABLES `professione` WRITE; +/*!40000 ALTER TABLE `professione` DISABLE KEYS */; +INSERT INTO `professione` VALUES (1,'Altro'),(2,'Studente'),(3,'Casalingo'),(4,'Tecnico Informatico'),(5,'Professore, Insegnante'),(6,'Scrittore, Giornalista'),(7,'Membro del clero'),(8,'Medico, Farmacista, Infermiere'),(9,'Magistrato, Avvocato, Notaio'),(10,'Agronomo, Veterinario, Biologo'),(11,'Fisico, Chimico, Ingegnere, Geometra'),(12,'Matematico, Statistico'),(13,'Economista, Commercialista'),(14,'Imprenditore'),(15,'Impiegato amministrativo'),(16,'Membro dei corpi armati, dei corpi di polizia'); +/*!40000 ALTER TABLE `professione` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `questionario` +-- + +DROP TABLE IF EXISTS `questionario`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `questionario` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `socio` int(11) NOT NULL, + `dataCompilazione` date DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `questionario_UN` (`socio`), + CONSTRAINT `questionario_FK` FOREIGN KEY (`socio`) REFERENCES `socio` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `questionario` +-- + +LOCK TABLES `questionario` WRITE; +/*!40000 ALTER TABLE `questionario` DISABLE KEYS */; +INSERT INTO `questionario` VALUES (1,2,'2018-09-09'); +/*!40000 ALTER TABLE `questionario` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `socio` +-- + +DROP TABLE IF EXISTS `socio`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `socio` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `nome` tinytext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + `cognome` tinytext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + `dataNascita` date DEFAULT NULL, + `comuneResidenza` tinytext CHARACTER SET utf8 COLLATE utf8_bin, + `email` tinytext CHARACTER SET utf8 COLLATE utf8_bin, + `professione` int(11) DEFAULT NULL, + `fonte` int(11) DEFAULT NULL, + `abilitaQuestionario` tinyint(1) NOT NULL DEFAULT '0', + `pin` varchar(5) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `socio_FK` (`professione`), + KEY `socio_FK_1` (`fonte`), + CONSTRAINT `socio_FK` FOREIGN KEY (`professione`) REFERENCES `professione` (`id`) ON UPDATE CASCADE, + CONSTRAINT `socio_FK_1` FOREIGN KEY (`fonte`) REFERENCES `fonte` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `socio` +-- + +LOCK TABLES `socio` WRITE; +/*!40000 ALTER TABLE `socio` DISABLE KEYS */; +INSERT INTO `socio` VALUES (1,'Massimo','Moroni','1965-11-20','Fiesole','massimodafirenze@gmail.com',14,5,0,NULL),(2,'Linux','Morrox','1972-07-01','Catania','morrolinux@gmail.com',5,6,0,NULL),(3,'Simone','Bagni','1969-02-02','Montelupo Fiorentino','massimobagni@libero.it',4,3,0,NULL),(4,'Jane','Doe','1875-02-28','Naples','doe@linux.it',11,4,0,NULL),(5,'Paolino','Paperino','1930-01-01','Torino',NULL,NULL,NULL,0,NULL),(6,'Pinco','Pallino','1990-08-29','Empoli',NULL,1,NULL,0,NULL),(7,'Damigian','Damigiano',NULL,'Qui','Quo',15,2,0,NULL); +/*!40000 ALTER TABLE `socio` ENABLE KEYS */; +UNLOCK TABLES; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 */ /*!50003 TRIGGER `socio_BEFORE_INSERT` BEFORE INSERT ON `socio` FOR EACH ROW BEGIN + if new.abilitaQuestionario = 1 then + set new.pin = creaPin(new.pin); + else + set new.pin = null; + end if; +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 */ /*!50003 TRIGGER `socio_BEFORE_UPDATE` BEFORE UPDATE ON `socio` FOR EACH ROW BEGIN + if new.abilitaQuestionario = 1 then + set new.pin = creaPin(new.pin); + else + set new.pin = null; + end if; +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; + +-- +-- Dumping routines for database 'golem_gestionale' +-- +/*!50003 DROP FUNCTION IF EXISTS `creaPin` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE FUNCTION `creaPin`(pin varchar(5)) RETURNS varchar(5) CHARSET utf8mb4 + NO SQL +BEGIN + set @oldPin = pin; + case when @oldPin is null then + begin + set @charsBucket = '0123456789'; + set @charLen = length(@charsBucket); + set @randomPassword = ''; + while length(@randomPassword) < 5 + do + set @randomPassword = concat(@randomPassword, substring(@charsBucket, ceiling(rand() * @charLen), 1)); + end while; + set @newPin = @randomPassword; + end; + else + set @newPin = @oldPin; + end case; + return @newPin; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `aggiornaQuestionarioDaNicolodi` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE PROCEDURE `aggiornaQuestionarioDaNicolodi`(in parId int + , in parPin varchar(5) + , in parNome tinytext + , in parCognome tinytext + , in parDataNascita date + , in parComuneResidenza tinytext + , in parEmail tinytext + , in parProfessione int + , in parFonte int +) +BEGIN + UPDATE socio + SET nome = parNome + , cognome = parCognome + , dataNascita = parDataNascita + , comuneResidenza = parComuneResidenza + , email = parEmail + , professione = parProfessione + , fonte = parFonte + , abilitaQuestionario = false + WHERE id = parId + AND pin = parPin + AND abilitaQuestionario = true; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2019-08-13 16:59:06 diff --git a/nicolodi/dump-golem_gestionale-201908132220.sql b/nicolodi/dump-golem_gestionale-201908132220.sql new file mode 100644 index 0000000..eb61096 --- /dev/null +++ b/nicolodi/dump-golem_gestionale-201908132220.sql @@ -0,0 +1,290 @@ +-- MySQL dump 10.13 Distrib 8.0.17, for Win64 (x86_64) +-- +-- Host: localhost Database: golem_gestionale +-- ------------------------------------------------------ +-- Server version 8.0.17 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!50503 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `fonte` +-- + +DROP TABLE IF EXISTS `fonte`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `fonte` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `fonte` tinytext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `fonte` +-- + +LOCK TABLES `fonte` WRITE; +/*!40000 ALTER TABLE `fonte` DISABLE KEYS */; +INSERT INTO `fonte` VALUES (0,''),(1,'Altro'),(2,'Socio fondatore'),(3,'Socio di vecchia data'),(4,'Passaparola'),(5,'Eventi organizzati dall\'associazione (es. Linux Day)'),(6,'Social network (Facebook, Twitter, ...)'); +/*!40000 ALTER TABLE `fonte` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `iscrizione` +-- + +DROP TABLE IF EXISTS `iscrizione`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `iscrizione` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `socio` int(11) NOT NULL, + `anno` date NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `iscrizione_UN` (`socio`,`anno`), + CONSTRAINT `iscrizione_FK` FOREIGN KEY (`socio`) REFERENCES `socio` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `iscrizione` +-- + +LOCK TABLES `iscrizione` WRITE; +/*!40000 ALTER TABLE `iscrizione` DISABLE KEYS */; +/*!40000 ALTER TABLE `iscrizione` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `professione` +-- + +DROP TABLE IF EXISTS `professione`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `professione` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `professione` tinytext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `professione` +-- + +LOCK TABLES `professione` WRITE; +/*!40000 ALTER TABLE `professione` DISABLE KEYS */; +INSERT INTO `professione` VALUES (0,''),(1,'Altro'),(2,'Studente'),(3,'Casalingo'),(4,'Tecnico Informatico'),(5,'Professore, Insegnante'),(6,'Scrittore, Giornalista'),(7,'Membro del clero'),(8,'Medico, Farmacista, Infermiere'),(9,'Magistrato, Avvocato, Notaio'),(10,'Agronomo, Veterinario, Biologo'),(11,'Fisico, Chimico, Ingegnere, Geometra'),(12,'Matematico, Statistico'),(13,'Economista, Commercialista'),(14,'Imprenditore'),(15,'Impiegato amministrativo'),(16,'Membro dei corpi armati, dei corpi di polizia'); +/*!40000 ALTER TABLE `professione` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `questionario` +-- + +DROP TABLE IF EXISTS `questionario`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `questionario` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `socio` int(11) NOT NULL, + `dataCompilazione` date DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `questionario_UN` (`socio`), + CONSTRAINT `questionario_FK` FOREIGN KEY (`socio`) REFERENCES `socio` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `questionario` +-- + +LOCK TABLES `questionario` WRITE; +/*!40000 ALTER TABLE `questionario` DISABLE KEYS */; +INSERT INTO `questionario` VALUES (1,2,'2018-09-09'); +/*!40000 ALTER TABLE `questionario` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `socio` +-- + +DROP TABLE IF EXISTS `socio`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `socio` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `nome` tinytext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + `cognome` tinytext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + `dataNascita` date DEFAULT NULL, + `comuneResidenza` tinytext CHARACTER SET utf8 COLLATE utf8_bin, + `email` tinytext CHARACTER SET utf8 COLLATE utf8_bin, + `professione` int(11) NOT NULL DEFAULT '0', + `fonte` int(11) NOT NULL DEFAULT '0', + `abilitaQuestionario` tinyint(1) NOT NULL DEFAULT '0', + `pin` varchar(5) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, + `dataCreazione` datetime NOT NULL, + `dataModifica` datetime NOT NULL, + PRIMARY KEY (`id`), + KEY `socio_fonte_FK_idx` (`fonte`), + KEY `socio_professione_FK_idx` (`professione`), + CONSTRAINT `socio_fonte_FK` FOREIGN KEY (`fonte`) REFERENCES `fonte` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT `socio_professione_FK` FOREIGN KEY (`professione`) REFERENCES `professione` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `socio` +-- + +LOCK TABLES `socio` WRITE; +/*!40000 ALTER TABLE `socio` DISABLE KEYS */; +INSERT INTO `socio` VALUES (1,'Massimo','Moroni','1965-11-20','Fiesole','massimodafirenze@gmail.com',14,5,1,'49379','0000-00-00 00:00:00','2019-08-13 22:12:45'),(2,'Linux','Morrox','1972-07-01','Catania','morrolinux@gmail.com',5,6,1,'62264','0000-00-00 00:00:00','2019-08-13 22:12:45'),(3,'Simone','Bagni','1969-02-02','Montelupo Fiorentino','massimobagni@libero.it',4,3,1,'48740','0000-00-00 00:00:00','2019-08-13 22:12:45'),(4,'Jane','Doe','1875-02-28','Naples','doe@linux.it',11,4,1,'63807','0000-00-00 00:00:00','2019-08-13 22:12:45'),(5,'Paolino','Paperino','1930-01-01','Torino',NULL,1,0,1,'61695','0000-00-00 00:00:00','2019-08-13 22:12:45'),(6,'Pinco','Pallino','1990-08-29','Empoli',NULL,1,0,1,'18923','0000-00-00 00:00:00','2019-08-13 22:12:45'),(7,'Damigian','Damigiano',NULL,'Qui','Quo',15,2,1,'13603','0000-00-00 00:00:00','2019-08-13 22:12:45'),(8,'Ciccino','Pontorme','1980-01-11','casa sua',NULL,0,0,1,'56787','0000-00-00 00:00:00','2019-08-13 22:12:45'); +/*!40000 ALTER TABLE `socio` ENABLE KEYS */; +UNLOCK TABLES; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 */ /*!50003 TRIGGER `socio_BEFORE_INSERT` BEFORE INSERT ON `socio` FOR EACH ROW BEGIN + set @currentTimeStamp = current_timestamp(); + if new.abilitaQuestionario = 1 then + set new.pin = creaPin(new.pin); + else + set new.pin = null; + end if; + set new.dataCreazione = @currentTimeStamp; + set new.dataModifica = currentTimeStamp; +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 */ /*!50003 TRIGGER `socio_BEFORE_UPDATE` BEFORE UPDATE ON `socio` FOR EACH ROW BEGIN + if new.abilitaQuestionario = 1 then + set new.pin = creaPin(new.pin); + else + set new.pin = null; + end if; + set new.dataModifica = current_timestamp(); +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; + +-- +-- Dumping routines for database 'golem_gestionale' +-- +/*!50003 DROP FUNCTION IF EXISTS `creaPin` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE FUNCTION `creaPin`(pin varchar(5)) RETURNS varchar(5) CHARSET utf8mb4 + NO SQL +BEGIN + set @oldPin = pin; + case when @oldPin is null then + begin + set @charsBucket = '0123456789'; + set @charLen = length(@charsBucket); + set @randomPassword = ''; + while length(@randomPassword) < 5 + do + set @randomPassword = concat(@randomPassword, substring(@charsBucket, ceiling(rand() * @charLen), 1)); + end while; + set @newPin = @randomPassword; + end; + else + set @newPin = @oldPin; + end case; + return @newPin; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `aggiornaQuestionarioDaNicolodi` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE PROCEDURE `aggiornaQuestionarioDaNicolodi`(in parId int + , in parPin varchar(5) + , in parNome tinytext + , in parCognome tinytext + , in parDataNascita date + , in parComuneResidenza tinytext + , in parEmail tinytext + , in parProfessione int + , in parFonte int +) +BEGIN + UPDATE socio + SET nome = parNome + , cognome = parCognome + , dataNascita = parDataNascita + , comuneResidenza = parComuneResidenza + , email = parEmail + , professione = parProfessione + , fonte = parFonte + , abilitaQuestionario = false + WHERE id = parId + AND pin = parPin + AND abilitaQuestionario = true; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2019-08-13 22:20:53 diff --git a/nicolodi/fullQuery.cpp b/nicolodi/fullQuery.cpp new file mode 100644 index 0000000..dd71508 --- /dev/null +++ b/nicolodi/fullQuery.cpp @@ -0,0 +1,11 @@ +#include "fullQuery.h" + +QString fullQuery(const QSqlQuery& query) { + QString str = query.lastQuery(); + QMapIterator it(query.boundValues()); + while (it.hasNext()) { + it.next(); + str.replace(it.key(), it.value().toString()); + } + return str; +} \ No newline at end of file diff --git a/nicolodi/fullQuery.h b/nicolodi/fullQuery.h new file mode 100644 index 0000000..2fd6201 --- /dev/null +++ b/nicolodi/fullQuery.h @@ -0,0 +1,11 @@ +#ifndef FULLQUERY_H +#define FULLQUERY_H + +#include +#include +#include +#include + +QString fullQuery(const QSqlQuery& query); + +#endif \ No newline at end of file diff --git a/nicolodi/leggimi.txt b/nicolodi/leggimi.txt new file mode 100644 index 0000000..65ed4f6 --- /dev/null +++ b/nicolodi/leggimi.txt @@ -0,0 +1,19 @@ +Ci sono dei punti da risolvere usando l'approccio MVC: +- Il model vuole gestire l'interazione con il db. + Non ho trovato il modo per fare l'update tramite stored procedure + infatti l'update la fa da solo il model andando ad aggiornare soltanto + i singoli campi modificati +- Ci sono dei problemi se i campi professione e fonte sono null. + Il model avrebbe dei problemi se si facesse una inner join perche' + non mostrerebbe niente (cosa che sarebbe comunque gestibile); facendo + una left join mostra i dati, ma le combo abbinate ai dati in relazione + mostrano il primo elemento senza andare ad aggiornare effettivamente il + campo collegato e quindi quando si salva, se non si e' modificato + qualcos'altro, il record non risulta modificato. + +Ho fatto delle modifiche al db aggiungendo un paio di trigger e una +stored procedure che pero' si e' rivelata inutile per l'approccio MVC. + +Sicuramente ci sono delle opzioni per risolvere la cosa, ma la mia +conoscenza sia di QT che di C++ e' troppo limitata e Google non e' +stato di nessun aiuto. diff --git a/nicolodi/main.cpp b/nicolodi/main.cpp index af9caac..623b8ff 100644 --- a/nicolodi/main.cpp +++ b/nicolodi/main.cpp @@ -1,10 +1,11 @@ -#include "MainWindow.h" +// #include "MainWindow.h" +#include #include -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { QApplication a(argc, argv); - MainWindow w; + // MainWindow w; + Pin w; w.show(); return a.exec(); diff --git a/nicolodi/nicolodi.pro b/nicolodi/nicolodi.pro index 0e8d55f..24711a0 100644 --- a/nicolodi/nicolodi.pro +++ b/nicolodi/nicolodi.pro @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += core gui +QT += core gui sql greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -25,16 +25,27 @@ DEFINES += QT_DEPRECATED_WARNINGS CONFIG += c++11 SOURCES += \ + EditWindow.cpp \ + Pin.cpp \ + db.cpp \ + fullQuery.cpp \ main.cpp \ - MainWindow.cpp + status.cpp HEADERS += \ - MainWindow.h + EditWindow.h \ + Pin.h \ + db.h \ + fullQuery.h \ + status.h FORMS += \ - MainWindow.ui + EditWindow.ui \ + Pin.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target + +DISTFILES += diff --git a/nicolodi/status.cpp b/nicolodi/status.cpp new file mode 100644 index 0000000..30f1f23 --- /dev/null +++ b/nicolodi/status.cpp @@ -0,0 +1,50 @@ +#include "status.h" + +namespace Ui { + + void status(StatusType type, QString message) { + // //QStatusBar* statusBar = mw->findChild("statusBar"); + // QStatusBar* statusBar = mw->statusBar(); + QString prefix; + int timeout = 0; + + // /* choose background color */ + // if (statusBar != nullptr) { + // switch (type) { + // case INFO: statusBar->setStyleSheet("color: #007;"); break; + // case SUCCESS: statusBar->setStyleSheet("color: #0a0;"); break; + // case WARNING: statusBar->setStyleSheet("color: #f50;"); break; + // case ERROR: statusBar->setStyleSheet("color: #d00;"); break; + // default: statusBar->setStyleSheet("color: #555;"); break; + // } + // } + /* choose stderr prefix */ + switch(type) { + case INFO: prefix = "[II]"; break; + case SUCCESS: prefix = "[OK]"; break; + case WARNING: prefix = "[WW]"; break; + case ERROR: prefix = "[EE]"; break; + default: prefix = "[??]"; break; + } + /* choose timeout */ + switch (type) { + case INFO: case SUCCESS: timeout = 10000; break; + case WARNING: case ERROR: timeout = 0; break; + default: timeout = 0; break; + } + + /* print on stderr */ + switch (type) { + case INFO: case SUCCESS: qDebug().noquote() << prefix << message; break; + case WARNING: qWarning().noquote() << prefix << message; break; + case ERROR: qCritical().noquote() << prefix << message; break; + default: qWarning().noquote() << prefix << message; break; + } + // /* show message in GUI */ + // if (statusBar != nullptr) { + // statusBar->showMessage(message, timeout); + // statusBar->repaint(); + // } + } + +} diff --git a/nicolodi/status.h b/nicolodi/status.h new file mode 100644 index 0000000..dd450de --- /dev/null +++ b/nicolodi/status.h @@ -0,0 +1,22 @@ +#ifndef STATUS_H +#define STATUS_H + +#include +#include + +#include "Pin.h" + +namespace Ui { + + enum StatusType { + INFO, + SUCCESS, + WARNING, + ERROR + }; + + void status(StatusType type, QString message); + +} + +#endif