Prima versione di Nicolodi

This commit is contained in:
gbiotti 2019-08-13 22:29:55 +02:00
parent dce7be8dc8
commit 5d8a743d20
21 changed files with 1493 additions and 70 deletions

146
nicolodi/EditWindow.cpp Normal file
View File

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

42
nicolodi/EditWindow.h Normal file
View File

@ -0,0 +1,42 @@
#ifndef EDITWINDOW_H
#define EDITWINDOW_H
#include <QMainWindow>
#include <QtSql>
#include <QMessageBox>
#include <QtWidgets>
#include <QCloseEvent>
#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

147
nicolodi/EditWindow.ui Normal file
View File

@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditWindow</class>
<widget class="QMainWindow" name="EditWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>304</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<widget class="QLabel" name="labelId">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Id</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditId">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelCognome">
<property name="text">
<string>Cognome</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEditCognome"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelNome">
<property name="text">
<string>Nome</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEditNome"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelDataDiNascita">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="text">
<string>Data di nascita</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDateEdit" name="dateEditDataDiNascita">
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="labelEmail">
<property name="text">
<string>E-mail</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="lineEditEmail"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelProfessione">
<property name="text">
<string>Occupazione</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QComboBox" name="comboBoxProfessione"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelFonte">
<property name="text">
<string>Fonte</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QComboBox" name="comboBoxFonte"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="labelComuneResidenza">
<property name="text">
<string>Comune di residenza</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="lineEditComuneResidenza"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButtonSalva">
<property name="text">
<string>&amp;Salva</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonAnnulla">
<property name="text">
<string>&amp;Annulla</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>

View File

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

View File

@ -1,22 +0,0 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

View File

@ -1,24 +0,0 @@
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>MainWindow</string>
</property>
<widget class="QMenuBar" name="menuBar" />
<widget class="QToolBar" name="mainToolBar" />
<widget class="QWidget" name="centralWidget" />
<widget class="QStatusBar" name="statusBar" />
</widget>
<layoutDefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<resources/>
<connections/>
</ui>

87
nicolodi/Pin.cpp Normal file
View File

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

33
nicolodi/Pin.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef PIN_H
#define PIN_H
#include <QDialog>
#include <QtSql>
#include <QMessageBox>
#include <QSettings>
#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

111
nicolodi/Pin.ui Normal file
View File

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Pin</class>
<widget class="QDialog" name="Pin">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>108</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>Questionario GOLEM</string>
</property>
<widget class="QGroupBox" name="groupBoxPin">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>381</width>
<height>91</height>
</rect>
</property>
<property name="title">
<string>Accesso al questionario</string>
</property>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>361</width>
<height>22</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="labelPin">
<property name="text">
<string>Pin</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditPin">
<property name="whatsThis">
<string/>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QPushButton" name="pushButtonOk">
<property name="geometry">
<rect>
<x>210</x>
<y>50</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="whatsThis">
<string/>
</property>
<property name="text">
<string>&amp;Ok</string>
</property>
</widget>
<widget class="QPushButton" name="pushButtonEsci">
<property name="geometry">
<rect>
<x>290</x>
<y>50</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="whatsThis">
<string/>
</property>
<property name="text">
<string>&amp;Esci</string>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>

37
nicolodi/db.cpp Normal file
View File

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

15
nicolodi/db.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef DB_H
#define DB_H
#include <QSettings>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QSqlRecord>
extern QSqlDatabase db;
// extern QSqlQuery query;
extern void connectDatabase();
#endif // DB_H

View File

@ -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

View File

@ -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

View File

@ -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,'<NON IMPOSTATO>'),(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,'<NON IMPOSTATO>'),(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

11
nicolodi/fullQuery.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "fullQuery.h"
QString fullQuery(const QSqlQuery& query) {
QString str = query.lastQuery();
QMapIterator<QString, QVariant> it(query.boundValues());
while (it.hasNext()) {
it.next();
str.replace(it.key(), it.value().toString());
}
return str;
}

11
nicolodi/fullQuery.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef FULLQUERY_H
#define FULLQUERY_H
#include <QMapIterator>
#include <QString>
#include <QSqlQuery>
#include <QVariant>
QString fullQuery(const QSqlQuery& query);
#endif

19
nicolodi/leggimi.txt Normal file
View File

@ -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.

View File

@ -1,10 +1,11 @@
#include "MainWindow.h"
// #include "MainWindow.h"
#include <Pin.h>
#include <QApplication>
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();

View File

@ -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 +=

50
nicolodi/status.cpp Normal file
View File

@ -0,0 +1,50 @@
#include "status.h"
namespace Ui {
void status(StatusType type, QString message) {
// //QStatusBar* statusBar = mw->findChild<QStatusBar*>("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();
// }
}
}

22
nicolodi/status.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef STATUS_H
#define STATUS_H
#include <QStatusBar>
#include <QString>
#include "Pin.h"
namespace Ui {
enum StatusType {
INFO,
SUCCESS,
WARNING,
ERROR
};
void status(StatusType type, QString message);
}
#endif