added safety query before to prevent starting same race again

This commit is contained in:
2018-12-11 19:25:30 +01:00
parent 5d31497f1c
commit 9cfb50983a

View File

@@ -10,7 +10,9 @@
#include <QObject> #include <QObject>
#include <QShortcut> #include <QShortcut>
#include <iostream> #include <iostream>
#include <sstream>
#include <vector> #include <vector>
using std::vector; using std::vector;
MainWindow::MainWindow(QWidget * parent) MainWindow::MainWindow(QWidget * parent)
@@ -65,6 +67,46 @@ void MainWindow::NewWindowSettings() {
} }
void MainWindow::WindowRennen() { void MainWindow::WindowRennen() {
// check if a valid racelist has been created
// get last race id
string statement = "select aktRennen.id_rennen from aktRennen order by "
"id_rennen DESC limit 1";
try {
string raceId =
this->db->getData2(statement, 1).at(0).at(0).toStdString();
std::stringstream ss;
ss << "select count(*) from Zeiten where zeiten.id_rennen like "
<< raceId;
int res = this->db->getData2(ss.str(), 1).at(0).at(0).toInt();
if (res > 0) {
// current race was raced before
QMessageBox msgBox;
msgBox.setText(
"Aktuelles Rennen wurde bereits gefahren! Trotzdem fahren?");
msgBox.setInformativeText("");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No);
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::No:
return;
case QMessageBox::Yes:
// do nothing
break;
default:
// should never be reached
break;
}
}
} catch (std::exception & e) {
Q_UNUSED(e);
}
this->interfaceRace = new WindowRace(this->db, this); this->interfaceRace = new WindowRace(this->db, this);
this->interfaceRace->show(); this->interfaceRace->show();
this->interfaceRennliste = new WindowRennliste(this->db, this); this->interfaceRennliste = new WindowRennliste(this->db, this);