From 9cfb50983af106da6e11844ee5ebdb5233aaa864 Mon Sep 17 00:00:00 2001 From: Johannes Paehr Date: Tue, 11 Dec 2018 19:25:30 +0100 Subject: [PATCH] added safety query before to prevent starting same race again --- mainwindow.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/mainwindow.cpp b/mainwindow.cpp index 8f96ee3..ac264dc 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -10,7 +10,9 @@ #include #include #include +#include #include + using std::vector; MainWindow::MainWindow(QWidget * parent) @@ -65,6 +67,46 @@ void MainWindow::NewWindowSettings() { } 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->show(); this->interfaceRennliste = new WindowRennliste(this->db, this);