Browse Source

started work on dbValidate class

fiffty-50 4 years ago
parent
commit
c94985e63a
18 changed files with 213 additions and 30 deletions
  1. 1 0
      dbaircraft.cpp
  2. 0 3
      dbaircraft.h
  3. 1 0
      dbairport.cpp
  4. 1 3
      dbairport.h
  5. 44 0
      dbapi.h
  6. 1 2
      dbflight.cpp
  7. 0 3
      dbflight.h
  8. 1 0
      dbpilots.cpp
  9. 0 3
      dbpilots.h
  10. 1 0
      dbsettings.cpp
  11. 0 3
      dbsettings.h
  12. 2 2
      dbsetup.cpp
  13. 1 7
      dbsetup.h
  14. 1 0
      dbstat.cpp
  15. 0 4
      dbstat.h
  16. 88 0
      dbvalidate.cpp
  17. 68 0
      dbvalidate.h
  18. 3 0
      openLog.pro

+ 1 - 0
dbaircraft.cpp

@@ -16,6 +16,7 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "dbaircraft.h"
+#include "dbapi.h"
 /*!
  * \brief RetreiveRegistration Looks up tail_id from Database
  * \param tail_ID Primary Key of tails database

+ 0 - 3
dbaircraft.h

@@ -2,9 +2,6 @@
 #define DBAIRCRAFT_H
 
 #include <QCoreApplication>
-#include <QSqlQuery>
-#include <QSqlError>
-#include <QDebug>
 
 /*!
  * \brief The dbAircraft class provides functionality for retreiving and storing

+ 1 - 0
dbairport.cpp

@@ -16,6 +16,7 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "dbairport.h"
+#include "dbapi.h"
 
 /*!
      * \brief RetreiveAirportNameFromIcaoOrIata Looks up Airport Name

+ 1 - 3
dbairport.h

@@ -19,9 +19,7 @@
 #define DBAIRPORT_H
 
 #include <QCoreApplication>
-#include <QSqlQuery>
-#include <QSqlError>
-#include <QDebug>
+
 
 /*!
  * \brief The dbAirport class provides functionality for retreiving airport related

+ 44 - 0
dbapi.h

@@ -0,0 +1,44 @@
+/*
+ *openPilot Log - A FOSS Pilot Logbook Application
+ *Copyright (C) 2020  Felix Turowsky
+ *
+ *This program is free software: you can redistribute it and/or modify
+ *it under the terms of the GNU General Public License as published by
+ *the Free Software Foundation, either version 3 of the License, or
+ *(at your option) any later version.
+ *
+ *This program is distributed in the hope that it will be useful,
+ *but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *GNU General Public License for more details.
+ *
+ *You should have received a copy of the GNU General Public License
+ *along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+#ifndef DBAPI_H
+#define DBAPI_H
+
+/* This header can be used to include database functionality for widgets
+ * or classes that need it.
+ */
+
+// Qt modules
+#include <QCoreApplication>
+#include <QDateTime>
+#include <QFile>
+#include <QSqlQuery>
+#include <QSqlError>
+#include <QSqlRecord>
+#include <QSqlField>
+#include <QSqlDriver>
+// openPilotLog classes
+#include "dbsetup.h"
+#include "dbsettings.h"
+#include "dbairport.h"
+#include "dbaircraft.h"
+#include "dbflight.h"
+#include "dbpilots.h"
+#include "dbstat.h"
+#include "dbvalidate.h"
+
+#endif // DBAPI_H

+ 1 - 2
dbflight.cpp

@@ -16,8 +16,7 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "dbflight.h"
-#include "dbpilots.h"
-#include "dbaircraft.h"
+#include "dbapi.h"
 
 
 /*!

+ 0 - 3
dbflight.h

@@ -19,9 +19,6 @@
 #define DBFLIGHT_H
 
 #include <QCoreApplication>
-#include <QSqlQuery>
-#include <QSqlError>
-#include <QDebug>
 #include "flight.h"
 #include "calc.h"
 

+ 1 - 0
dbpilots.cpp

@@ -16,6 +16,7 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "dbpilots.h"
+#include "dbapi.h"
 
 
 /*!

+ 0 - 3
dbpilots.h

@@ -19,9 +19,6 @@
 #define DBPILOTS_H
 
 #include <QCoreApplication>
-#include <QSqlQuery>
-#include <QSqlError>
-#include <QDebug>
 
 /*!
  * \brief The dbPilots class class provides a databank interface for actions related to the

+ 1 - 0
dbsettings.cpp

@@ -16,6 +16,7 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "dbsettings.h"
+#include "dbapi.h"
 
 
 /*

+ 0 - 3
dbsettings.h

@@ -19,9 +19,6 @@
 #define DBSETTINGS_H
 
 #include <QCoreApplication>
-#include <QSqlQuery>
-#include <QSqlError>
-#include <QDebug>
 
 /*!
  * \brief The dbSettings class provides functionality for retreiving settings

+ 2 - 2
dbsetup.cpp

@@ -16,6 +16,7 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "dbsetup.h"
+#include "dbapi.h"
 
 // Statements for creation of database table
 const QString createTablePilots = "CREATE TABLE pilots ( "
@@ -326,8 +327,7 @@ QVector<QString> dbSetup::getColumnNames(QString table)
 {
     QSqlDatabase db = QSqlDatabase::database("qt_sql_default_connection");
     QVector<QString> columnNames;
-
-    QSqlRecord fields = db.driver()->record(table);
+    QSqlRecord fields = db.record(table);
     for(int i = 0; i < fields.count(); i++){
         columnNames << fields.field(i).name();
     }

+ 1 - 7
dbsetup.h

@@ -19,13 +19,7 @@
 #define DBSETUP_H
 
 #include <QCoreApplication>
-#include <QSqlQuery>
-#include <QSqlError>
-#include <QSqlRecord>
-#include <QSqlField>
-#include <QSqlDriver>
-#include <QDebug>
-#include <QFile>
+
 
 /*!
  * \brief The dbSetup class is responsible for the inital setup of the database when

+ 1 - 0
dbstat.cpp

@@ -16,6 +16,7 @@
  *along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 #include "dbstat.h"
+#include "dbapi.h"
 
 
 /*!

+ 0 - 4
dbstat.h

@@ -19,10 +19,6 @@
 #define DBSTAT_H
 
 #include <QCoreApplication>
-#include <QDate>
-#include <QSqlQuery>
-#include <QSqlError>
-#include <QDebug>
 
 
 /*!

+ 88 - 0
dbvalidate.cpp

@@ -0,0 +1,88 @@
+/*
+ *openPilot Log - A FOSS Pilot Logbook Application
+ *Copyright (C) 2020  Felix Turowsky
+ *
+ *This program is free software: you can redistribute it and/or modify
+ *it under the terms of the GNU General Public License as published by
+ *the Free Software Foundation, either version 3 of the License, or
+ *(at your option) any later version.
+ *
+ *This program is distributed in the hope that it will be useful,
+ *but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *GNU General Public License for more details.
+ *
+ *You should have received a copy of the GNU General Public License
+ *along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+#include "dbvalidate.h"
+#include "dbapi.h"
+
+
+
+dbValidate::dbValidate()
+{
+    isValid = false;
+    qDebug() << "Default Constructor";
+}
+
+
+
+bool dbValidate::verify_id(QString id)
+{
+    if (id.toInt()>=0){return true;}else{return false;}
+}
+bool verify_doft(QString doft)
+{
+    return QDate::fromString(doft,Qt::ISODate).isValid();
+}
+bool verify_dept(QString dept)
+{
+    return dbAirport::checkICAOValid(dept);
+}
+
+bool verify_dest(QString dest)
+{
+    return dbAirport::checkICAOValid(dest);
+}
+bool verify_tofb(QString tofb)
+{
+    return QTime::fromString(tofb,"hh:mm").isValid();
+}
+bool verify_tonb(QString tonb)
+{
+    return QTime::fromString(tonb,"hh:mm").isValid();
+}
+bool verify_pic(QString picname)
+{
+    return dbPilots::verifyPilotExists(picname.split(QLatin1Char(',')));
+}
+bool verify_acft(QString registration)
+{
+    return !dbAircraft::retreiveTailId(registration).isEmpty();
+}
+bool verify_tblk(QString tblk)
+{
+    return QTime::fromString(tblk,"hh:mm").isValid();
+}
+/*bool verify_tSPSE();
+bool verify_tSPME();
+bool verify_tMP();
+bool verify_tNIGHT();
+bool verify_tIFR();
+bool verify_tPIC();
+bool verify_tPICUS();
+bool verify_tSIC();
+bool verify_tDual();
+bool verify_tFI();
+bool verify_tSIM();
+bool verify_pilotFlying();
+bool verify_toDay();
+bool verify_toNight();
+bool verify_ldgDay();
+bool verify_ldgNight();
+bool verify_autoland();
+bool verify_secondPilot();
+bool verify_thirdPilot();
+bool verify_FlightNumber();
+bool verify_Remarks();*/

+ 68 - 0
dbvalidate.h

@@ -0,0 +1,68 @@
+/*
+ *openPilot Log - A FOSS Pilot Logbook Application
+ *Copyright (C) 2020  Felix Turowsky
+ *
+ *This program is free software: you can redistribute it and/or modify
+ *it under the terms of the GNU General Public License as published by
+ *the Free Software Foundation, either version 3 of the License, or
+ *(at your option) any later version.
+ *
+ *This program is distributed in the hope that it will be useful,
+ *but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *GNU General Public License for more details.
+ *
+ *You should have received a copy of the GNU General Public License
+ *along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+#ifndef DBVALIDATE_H
+#define DBVALIDATE_H
+#include <QCoreApplication>
+
+/*!
+ * \brief The dbValidate class provides functions providing validation functionality
+ * for data entries. All return types are boolean (true = valid, false = invalid)
+ */
+class dbValidate
+{
+public:
+
+    bool isValid;
+
+    dbValidate();
+
+    dbValidate(QString table, QString field, QString value);
+
+    bool verify_id(QString);
+    bool verify_doft(QString);
+    bool verify_dept(QString);
+    bool verify_dest(QString);
+    bool verify_tofb(QString);
+    bool verify_tonb(QString);
+    bool verify_pic(QString);
+    bool verify_acft(QString);
+    bool verify_tblk(QString);
+    bool verify_tSPSE(QString);
+    bool verify_tSPME(QString);
+    bool verify_tMP(QString);
+    bool verify_tNIGHT(QString);
+    bool verify_tIFR(QString);
+    bool verify_tPIC(QString);
+    bool verify_tPICUS(QString);
+    bool verify_tSIC(QString);
+    bool verify_tDual(QString);
+    bool verify_tFI(QString);
+    bool verify_tSIM(QString);
+    bool verify_pilotFlying(QString);
+    bool verify_toDay(QString);
+    bool verify_toNight(QString);
+    bool verify_ldgDay(QString);
+    bool verify_ldgNight(QString);
+    bool verify_autoland(QString);
+    bool verify_secondPilot(QString);
+    bool verify_thirdPilot(QString);
+    bool verify_FlightNumber(QString);
+    bool verify_Remarks(QString);
+};
+
+#endif // DBVALIDATE_H

+ 3 - 0
openLog.pro

@@ -30,6 +30,7 @@ SOURCES += \
     dbsettings.cpp \
     dbsetup.cpp \
     dbstat.cpp \
+    dbvalidate.cpp \
     easaview.cpp \
     editflight.cpp \
     flight.cpp \
@@ -47,11 +48,13 @@ HEADERS += \
     calc.h \
     dbaircraft.h \
     dbairport.h \
+    dbapi.h \
     dbflight.h \
     dbpilots.h \
     dbsettings.h \
     dbsetup.h \
     dbstat.h \
+    dbvalidate.h \
     easaview.h \
     editflight.h \
     flight.h \