void MainWindow::locate()
{
if(db.isOpen())
{
int daysAttended = 0;
int daysMissed = 0;
int matchingRow = 0;
QString searchTag
= barcodeEdit
->text
().
toUpper();
if(query
->exec
(QString("select * from persons where UID = \"%0\" LIMIT 0,1").
arg(searchTag
))) {
if(query->isSelect() && query->next() && query->value(0).isValid())
{
int matchingRow = query->value(0).toInt();
daysAttended = model->record(matchingRow).value(6).toInt();
datesAttended = model->record(matchingRow).value(5).toString();
if(model
->setData
(model
->index
(matchingRow,
6),
QVariant(daysAttended
+ 1)) && model
->setData
(model
->index
(matchingRow,
5),
QVariant(datesAttended
+ QDateTime::currentDateTime().
toString()))) {barcodeEdit->setText("");} else {
QMessageBox::critical(0, qApp
->tr
("Error Setting Record!"),
qApp->tr(" %0.\n \n"
"Click Close to continue.").
arg(model
->lastError
().
text()),
QMessageBox::Close);
} } else {
QMessageBox::critical(0, qApp
->tr
("Could not find an entry with the matching criticia!"),
qApp->tr("Unable to find a person with the matching criticia! \n\n"
} else {
QMessageBox::critical(0, qApp
->tr
("Error Executing Query!"),
qApp->tr(" %0.\n \n"
"Click Close to continue.").
arg(query
->lastError
().
text()),
QMessageBox::Close);
} } else {
QMessageBox::critical(0, qApp
->tr
("Database Not Open!"),
qApp->tr("You must have a database open before you can use this function!. \n\n"
}
void MainWindow::locate()
{
if(db.isOpen())
{
QString datesAttended = "";
int daysAttended = 0;
int daysMissed = 0;
int matchingRow = 0;
QString searchTag = barcodeEdit->text().toUpper();
if(query->exec(QString("select * from persons where UID = \"%0\" LIMIT 0,1").arg(searchTag)))
{
if(query->isSelect() && query->next() && query->value(0).isValid())
{
int matchingRow = query->value(0).toInt();
daysAttended = model->record(matchingRow).value(6).toInt();
datesAttended = model->record(matchingRow).value(5).toString();
if(model->setData(model->index(matchingRow,6),QVariant(daysAttended + 1)) && model->setData(model->index(matchingRow,5),QVariant(datesAttended + QDateTime::currentDateTime().toString())))
{barcodeEdit->setText("");} else {
QMessageBox::critical(0, qApp->tr("Error Setting Record!"),
qApp->tr(" %0.\n \n"
"Click Close to continue.").arg(model->lastError().text()), QMessageBox::Close);}
} else {
QMessageBox::critical(0, qApp->tr("Could not find an entry with the matching criticia!"),
qApp->tr("Unable to find a person with the matching criticia! \n\n"
"Click Close to continue."), QMessageBox::Close);}
} else {
QMessageBox::critical(0, qApp->tr("Error Executing Query!"),
qApp->tr(" %0.\n \n"
"Click Close to continue.").arg(query->lastError().text()), QMessageBox::Close);}
} else {
QMessageBox::critical(0, qApp->tr("Database Not Open!"),
qApp->tr("You must have a database open before you can use this function!. \n\n"
"Click Close to continue."), QMessageBox::Close);}
}
To copy to clipboard, switch view to plain text mode
bool MainWindow::save()
{
if(db.isOpen()){
model->database().transaction();
if (model->submitAll()) {
model->database().commit();
return true;
} else {
model->database().rollback();
tr("The database reported an error: %1")
.arg(model->lastError().text()));
return false;
}
} else {
tr("No database is open!"));
return false;
}
}
bool MainWindow::save()
{
if(db.isOpen()){
model->database().transaction();
if (model->submitAll()) {
model->database().commit();
return true;
} else {
model->database().rollback();
QMessageBox::warning(this, tr("Cached Table"),
tr("The database reported an error: %1")
.arg(model->lastError().text()));
return false;
}
} else {
QMessageBox::warning(this, tr("Database Not Open!"),
tr("No database is open!"));
return false;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks