Browse Source

fixed bug in delete flight function

fiffty-50 4 years ago
parent
commit
d287a524c7
5 changed files with 47 additions and 20 deletions
  1. 23 3
      dbman.cpp
  2. 2 5
      homewidget.cpp
  3. 1 1
      homewidget.ui
  4. 19 10
      logbookwidget.cpp
  5. 2 1
      mainwindow.cpp

+ 23 - 3
dbman.cpp

@@ -281,16 +281,36 @@ public:
     }
 
 
-    static bool DeleteFlightById(QString flight_id)
+    static bool deleteFlightById(QString flight_id) // To Do: also remove associated extras
     {
+        /*QString extras_id = flight_id;
+        QSqlQuery query;
+        query.prepare("DELETE FROM flights WHERE id = :flight_id");
+        query.bindValue(":flight_id", flight_id);
+        query.exec();
+        QString error = query.lastError().text();
+
+        QSqlQuery query2;
+        query2.prepare("DELETE FROM extras WHERE extras_id = :extras_id");
+        query2.bindValue(":extras_id", extras_id);
+        query2.exec();
+        QString error2 = query2.lastError().text();*/
         QSqlQuery query;
         query.prepare("DELETE FROM flights WHERE id = ?");
         query.addBindValue(flight_id);
         query.exec();
         QString error = query.lastError().text();
-        qDebug() << "db::DeleteFlightById: Removing flight with ID#: " << flight_id << "Query Error: " << error;
-        if(error.length() > 0)
+
+        QSqlQuery query2;
+        query2.prepare("DELETE FROM extras WHERE extras_id = ?");
+        query2.addBindValue(flight_id);
+        query2.exec();
+        QString error2 = query2.lastError().text();
+
+        qDebug() << "db::deleteFlightById: Removing flight with ID#: " << flight_id;
+        if(error.length() > 0 || error2.length() > 0)
         {
+            qWarning() << "db::deleteFlightsById: Errors have occured: " << error << " " << error2;
             return false;
         }else
         {

+ 2 - 5
homewidget.cpp

@@ -10,17 +10,14 @@ homeWidget::homeWidget(QWidget *parent) :
     ui->setupUi(this);
     qDebug() << "homeWidget: Activated";
 
-    //ui->backgroundLabel->clear();
-    //QPixmap pix("://background_gradient.png");
-    //ui->backgroundLabel->setPixmap(pix);
-    //ui->backgroundLabel->setStyleSheet("background-color: rgba(13, 196, 254, 20);");
+
     /*
      * To Do: Functions to retreive values from DB
      */
 
     ui->totalTimeDisplayLabel->setText("123:45");
     ui->blockHoursDisplayLabel->setText("123:45");
-    ui->currencyDisplayLabel->setText("17 Take Offs and 15 Landings in the last 90 days.");
+    ui->currencyDisplayLabel->setText("17 Take Offs\n15 Landings");
 }
 
 homeWidget::~homeWidget()

+ 1 - 1
homewidget.ui

@@ -182,7 +182,7 @@
      <item row="2" column="1">
       <widget class="QLabel" name="currencyLabel">
        <property name="text">
-        <string>Currency:</string>
+        <string>Currency (last 90 days):</string>
        </property>
       </widget>
      </item>

+ 19 - 10
logbookwidget.cpp

@@ -64,10 +64,13 @@ void logbookWidget::on_newFlightButton_clicked()
     nf.exec();
 }
 
-void logbookWidget::on_editFlightButton_clicked()
+void logbookWidget::on_editFlightButton_clicked() // To Do: Fix!
 {
-    EditFlight ef(this);
-    ef.exec();
+    QMessageBox *nope = new QMessageBox(this); // edit widget currently INOP
+    nope->setText("This feature is temporarily INOP.");
+    nope->exec();
+    //EditFlight ef(this);
+    //ef.exec();
 }
 
 void logbookWidget::on_deleteFlightPushButton_clicked()
@@ -76,13 +79,19 @@ void logbookWidget::on_deleteFlightPushButton_clicked()
     {
         qDebug() << "Valid Flight Selected";
         // To Do: Confirmation Dialog
-        db::DeleteFlightById(QString::number(SelectedFlight));
-
-        QSqlTableModel *ShowAllModel = new QSqlTableModel; //refresh view
-        ShowAllModel->setTable("Logbook");
-        ShowAllModel->select();
-
-        ui->tableView->setModel(ShowAllModel);
+        QMessageBox::StandardButton reply;
+        reply = QMessageBox::question(this, "Delete Flight", "The following flight will be deleted:\n{retreive Flight Details}\nAre you sure?",
+                                      QMessageBox::Yes|QMessageBox::No);
+        if (reply == QMessageBox::Yes)
+        {
+            qDebug() << "Deleting Flight with ID# " << SelectedFlight;
+            db::deleteFlightById(QString::number(SelectedFlight));
+
+            QSqlTableModel *ShowAllModel = new QSqlTableModel; //refresh view
+            ShowAllModel->setTable("Logbook");
+            ShowAllModel->select();
+            ui->tableView->setModel(ShowAllModel);
+        }
     }else
     {
         QMessageBox NoFlight;

+ 2 - 1
mainwindow.cpp

@@ -80,7 +80,7 @@ MainWindow::~MainWindow()
 
 void MainWindow::nope()
 {
-    QMessageBox nope; //error box
+    QMessageBox nope(this); //error box
     nope.setText("This feature is not yet available!");
     nope.exec();
 }
@@ -117,6 +117,7 @@ void MainWindow::on_actionLogbook_triggered()
 
 void MainWindow::on_actionSettings_triggered()
 {
+    nope();
     auto sw = new settingsWidget(this);
     ui->stackedWidget->addWidget(sw);
     ui->stackedWidget->setCurrentWidget(sw);