#include "frmUnValore_AME.h"
/*----------------------------------------------------------------------------*/
frmUnValore_AME
::frmUnValore_AME(QSqlTableModel *model,
const int &isItNew,
{
ui.setupUi(this);
this->setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
this->setAttribute(Qt::WA_DeleteOnClose);
modelAME = model;
if (modelAME->database().transaction())
{
qDebug() << "frmUnValore_AME TRANSACTION database!";
}
else
{
qDebug() << "frmUnValore_AME TRANSACTION FALSE!";
qDebug() << modelAME->database().lastError();
}
if (isItNew < 0)
{
id = modelAME->rowCount();
modelAME->insertRow(id);
}
else
{
id = isItNew;
}
mapper->setModel(modelAME);
mapper->addMapping(ui.lnePrimo, 1);
mapper->setCurrentIndex(id);
connect(ui.btnAnnulla, SIGNAL(clicked()), this, SLOT(revert()));
connect(ui.btnOk, SIGNAL(clicked()), this, SLOT(submit()));
qDebug() << "frmUnValore_AME Loaded!";
}
/*----------------------------------------------------------------------------*/
void frmUnValore_AME::revert()
{
mapper->revert();
qDebug() << "->frmUnValore_AME (Aggiunta Rifiutata!";
modelAME->revertAll();
modelAME->database().rollback();
qDebug() << "frmUnValore_AME closed!";
}
/*----------------------------------------------------------------------------*/
void frmUnValore_AME::submit()
{
if (mapper->submit())
{
mapper->setCurrentIndex(id);
qDebug() << "frmUnValore_AME Ok submit!";
if (modelAME->submitAll())
{
if (modelAME->database().commit())
{
qDebug() << "frmUnValore_AME COMMIT database!";
}
else
{
qDebug() << "frmUnValore_AME COMMIT FALSE!";
qDebug() << modelAME->database().lastError();
}
}
else
{
modelAME->revertAll();
modelAME->database().rollback();
tr("Il database ha riportato un errore: %1")
.arg(modelAME->lastError().text()));
}
}
else
{
qDebug() << "No submit!";
tr("Il database ha riportato un errore: %1")
.arg(modelAME->lastError().text()));
}
}
#include "frmUnValore_AME.h"
/*----------------------------------------------------------------------------*/
frmUnValore_AME::frmUnValore_AME(QSqlTableModel *model, const int &isItNew,
QWidget *parent) : QDialog(parent)
{
ui.setupUi(this);
this->setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
this->setAttribute(Qt::WA_DeleteOnClose);
modelAME = new QSqlTableModel(this);
modelAME = model;
if (modelAME->database().transaction())
{
qDebug() << "frmUnValore_AME TRANSACTION database!";
}
else
{
qDebug() << "frmUnValore_AME TRANSACTION FALSE!";
qDebug() << modelAME->database().lastError();
}
if (isItNew < 0)
{
id = modelAME->rowCount();
modelAME->insertRow(id);
}
else
{
id = isItNew;
}
mapper = new QDataWidgetMapper(this);
mapper->setModel(modelAME);
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
mapper->addMapping(ui.lnePrimo, 1);
mapper->setCurrentIndex(id);
connect(ui.btnAnnulla, SIGNAL(clicked()), this, SLOT(revert()));
connect(ui.btnOk, SIGNAL(clicked()), this, SLOT(submit()));
qDebug() << "frmUnValore_AME Loaded!";
}
/*----------------------------------------------------------------------------*/
void frmUnValore_AME::revert()
{
mapper->revert();
qDebug() << "->frmUnValore_AME (Aggiunta Rifiutata!";
modelAME->revertAll();
modelAME->database().rollback();
qDebug() << "frmUnValore_AME closed!";
}
/*----------------------------------------------------------------------------*/
void frmUnValore_AME::submit()
{
if (mapper->submit())
{
mapper->setCurrentIndex(id);
qDebug() << "frmUnValore_AME Ok submit!";
if (modelAME->submitAll())
{
if (modelAME->database().commit())
{
qDebug() << "frmUnValore_AME COMMIT database!";
}
else
{
qDebug() << "frmUnValore_AME COMMIT FALSE!";
qDebug() << modelAME->database().lastError();
}
}
else
{
modelAME->revertAll();
modelAME->database().rollback();
QMessageBox::warning(this, tr("Attenzione!"),
tr("Il database ha riportato un errore: %1")
.arg(modelAME->lastError().text()));
}
}
else
{
qDebug() << "No submit!";
QMessageBox::warning(this, tr("Attenzione!"),
tr("Il database ha riportato un errore: %1")
.arg(modelAME->lastError().text()));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks