First Commit
This commit is contained in:
commit
9055bc1b14
|
@ -0,0 +1,75 @@
|
||||||
|
#include "ImmuNoattri.hpp"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "ui_ImmuNoattri.h"
|
||||||
|
|
||||||
|
bool decodeCodfis(const QString& input, QString& codfis, QString& anagrafica) {
|
||||||
|
codfis = input.mid(1, 16);
|
||||||
|
if (codfis.length() != 16) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int end_anagrafica = input.indexOf(0x5f);
|
||||||
|
if (end_anagrafica < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
anagrafica = input.mid(17, end_anagrafica - 17);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow::MainWindow(QWidget* parent)
|
||||||
|
: QMainWindow(parent),
|
||||||
|
ui(new Ui::MainWindow),
|
||||||
|
sqliteInterface("presenze.db") {
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
|
||||||
|
connect(&lineTessera_timer, &QTimer::timeout, this,
|
||||||
|
&MainWindow::on_lineTessera_timer_timeout);
|
||||||
|
|
||||||
|
int registrati = sqliteInterface.count();
|
||||||
|
ui->lineRegistrati->setText(QString::number(registrati));
|
||||||
|
ui->lineStato->setText("Strusciare tessera magnetica");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow::~MainWindow() {}
|
||||||
|
|
||||||
|
void MainWindow::on_actionNuovo_triggered() {
|
||||||
|
qDebug() << "Falla finita di ciacciare";
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionApri_triggered() {
|
||||||
|
qDebug() << "Falla finita di ciacciare";
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_lineTessera_textEdited(const QString& text) {
|
||||||
|
// The magnetic reader has three newline characters
|
||||||
|
lineTessera_timer.start(std::chrono::milliseconds(500));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_lineTessera_timer_timeout() {
|
||||||
|
lineTessera_timer.stop();
|
||||||
|
|
||||||
|
QString codfis;
|
||||||
|
QString anagrafica;
|
||||||
|
// Validating input
|
||||||
|
if (decodeCodfis(ui->lineTessera->text(), codfis, anagrafica)) {
|
||||||
|
int registrati = ui->lineRegistrati->text().toInt();
|
||||||
|
registrati++;
|
||||||
|
ui->lineRegistrati->setText(QString(registrati));
|
||||||
|
ui->lineStato->setText("Tessera valida! Strusciare la prossima");
|
||||||
|
sqliteInterface.addVisitor(codfis, anagrafica);
|
||||||
|
} else {
|
||||||
|
ui->lineStato->setText("Tessera non valida, riprovare a strusciare!");
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->lineTessera->setText("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_pushMano_clicked() {}
|
||||||
|
|
||||||
|
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||||
|
qDebug() << "Pulisco db";
|
||||||
|
sqliteInterface.cleanup();
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
QT = core gui
|
||||||
|
QT += sql
|
||||||
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
|
TARGET = ImmuNoattri
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
SOURCES += main.cpp \
|
||||||
|
ImmuNoattri.cpp \
|
||||||
|
sqliteInterface.cpp
|
||||||
|
|
||||||
|
HEADERS += ImmuNoattri.hpp \
|
||||||
|
sqliteInterface.hpp
|
||||||
|
|
||||||
|
FORMS += ImmuNoattri.ui
|
||||||
|
|
||||||
|
QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO
|
||||||
|
QMAKE_CFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO
|
||||||
|
QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO
|
|
@ -0,0 +1,129 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>600</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>MainWindow</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labelImmuNoattri">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>15</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>ImmuNoattri</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labelTessera">
|
||||||
|
<property name="text">
|
||||||
|
<string>Tessera strusciata:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineTessera">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labelStato">
|
||||||
|
<property name="text">
|
||||||
|
<string>Stato attuale:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineStato">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labelRegistrati">
|
||||||
|
<property name="text">
|
||||||
|
<string>Registrati stasera:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineRegistrati">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushMano">
|
||||||
|
<property name="text">
|
||||||
|
<string>Inserisci a mano</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>30</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menuFile">
|
||||||
|
<property name="title">
|
||||||
|
<string>File</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionNuovo"/>
|
||||||
|
<addaction name="actionApri"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuFile"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
<action name="actionApri">
|
||||||
|
<property name="text">
|
||||||
|
<string>Apri</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionNuovo">
|
||||||
|
<property name="text">
|
||||||
|
<string>Nuovo</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -0,0 +1,12 @@
|
||||||
|
#include <QtCore>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
#include "ImmuNoattri.hpp"
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
// Q_INIT_RESOURCE(application);
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
MainWindow w;
|
||||||
|
w.show();
|
||||||
|
return a.exec();
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
#include "sqliteInterface.hpp"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QSqlQuery>
|
||||||
|
#include <QSqlError>
|
||||||
|
|
||||||
|
SqliteInterface::SqliteInterface(const QString& path) {
|
||||||
|
m_db = QSqlDatabase::addDatabase("QSQLITE");
|
||||||
|
m_db.setDatabaseName(path);
|
||||||
|
|
||||||
|
if (!m_db.open()) {
|
||||||
|
qDebug() << "Error: connection with database fail";
|
||||||
|
} else {
|
||||||
|
qDebug() << "Database: connection ok";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SqliteInterface::addVisitor(const QString& codfis,
|
||||||
|
const QString& anagrafica) {
|
||||||
|
bool success = false;
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare(
|
||||||
|
"INSERT INTO presenze (checkin, codfis, anagrafica) VALUES "
|
||||||
|
"(DATETIME('now'), :codfis, "
|
||||||
|
":anagrafica)");
|
||||||
|
query.bindValue(":codfis", codfis);
|
||||||
|
query.bindValue(":anagrafica", anagrafica);
|
||||||
|
if (query.exec()) {
|
||||||
|
success = true;
|
||||||
|
} else {
|
||||||
|
qDebug() << __FUNCTION__ << " error: " << query.lastError();
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SqliteInterface::cleanup() {
|
||||||
|
bool success = false;
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare(
|
||||||
|
"DELETE FROM presenze WHERE checkin < DATETIME('NOW', '-15 days')");
|
||||||
|
if (query.exec()) {
|
||||||
|
success = true;
|
||||||
|
} else {
|
||||||
|
qDebug() << __FUNCTION__ << " error: " << query.lastError();
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SqliteInterface::count() {
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare("SELECT COUNT(*) from presenze");
|
||||||
|
if (query.exec()) {
|
||||||
|
query.first();
|
||||||
|
return query.value(0).toInt();
|
||||||
|
} else {
|
||||||
|
qDebug() << __FUNCTION__ << " error: " << query.lastError();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue