123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- #include "dbflight.h"
- #include "dbapi.h"
- flight dbFlight::verifyInput(flight object)
- {
- if (object.doft.isValid()){
- object.invalidItems.removeOne("doft");
- qDebug() << "doft verified.";
- }else{
- qWarning() << "Invalid entry: doft";
- }
- if(dbAirport::checkICAOValid(object.dept)){
- object.invalidItems.removeOne("dept");
- qDebug() << "dept verified.";
- }else{
- qWarning() << "Invalid entry: dept";
- }
- if(dbAirport::checkICAOValid(object.dest)){
- object.invalidItems.removeOne("dest");
- qDebug() << "dest verified.";
- }else{
- qWarning() << "Invalid entry: dest";
- }
- if(object.tofb.isValid()){
- object.invalidItems.removeOne("tofb");
- qDebug() << "tofb verified.";
- }else{
- qWarning() << "Invalid entry: tofb";
- }
- if(object.tonb.isValid()){
- object.invalidItems.removeOne("tonb");
- qDebug() << "tonb verified.";
- }else{
- qWarning() << "Invalid entry: tonb";
- }
- if(dbPilots::verifyPilotExists(object.pic.split(QLatin1Char(',')))){
- object.invalidItems.removeOne("pic");
- qDebug() << "pic verified.";
- }else{
- qWarning() << "Invalid entry: pic";
- }
-
- QTime tblkcheck = calc::blocktime(object.tofb, object.tonb);
- if(object.tblk.isValid() && !object.tblk.isNull() && tblkcheck == object.tblk){
- object.invalidItems.removeOne("tblk");
- qDebug() << "tblk verified.";
- }else{
- qWarning() << "Invalid entry: tblk";
- }
- if(!dbAircraft::retreiveTailId(object.acft).isEmpty()){
- object.invalidItems.removeOne("acft");
- qDebug() << "acft verified.";
- }else{
- qWarning() << "Invalid entry: acft";
- }
- if(object.invalidItems.isEmpty()){
- object.isValid = true;
- qDebug() << "All checks passed. Object is now verified.";
- }else{
- qDebug() << "Not all checks have been passed.";
- qDebug() << "Invalid items: " << object.invalidItems;
- }
- return object;
-
-
- }
- flight dbFlight::retreiveFlight(QString flight_id)
- {
- QSqlQuery query;
- query.prepare("SELECT * FROM flights WHERE id = ?");
- query.addBindValue(flight_id);
- query.exec();
- if(query.first());
- else
- {
- qWarning() << __func__ << "No Flight with this ID found";
- return flight();
- }
- flight object;
- object.id = query.value(0).toInt();
- object.doft = QDate::fromString(query.value(1).toString(),Qt::ISODate);
- object.dept = query.value(2).toString();
- object.dest = query.value(3).toString();
- object.tofb = QTime::fromString(
- calc::minutes_to_string(
- query.value(4).toString()),"hh:mm");
- object.tonb = QTime::fromString(
- calc::minutes_to_string(
- query.value(5).toString()),"hh:mm");
- object.pic = dbPilots::retreivePilotNameFromID(
- query.value(6).toString());
- object.acft = dbAircraft::retreiveRegistration(
- query.value(7).toString());
- object.tblk = QTime::fromString(
- calc::minutes_to_string(
- query.value(8).toString()),"hh:mm");
- object.tSPSE = QTime::fromString(
- calc::minutes_to_string(
- query.value(9).toString()),"hh:mm");
- object.tSPME = QTime::fromString(
- calc::minutes_to_string(
- query.value(10).toString()),"hh:mm");
- object.tMP = QTime::fromString(
- calc::minutes_to_string(
- query.value(11).toString()),"hh:mm");
- object.tNIGHT = QTime::fromString(
- calc::minutes_to_string(
- query.value(12).toString()),"hh:mm");
- object.tIFR = QTime::fromString(
- calc::minutes_to_string(
- query.value(13).toString()),"hh:mm");
- object.tPIC = QTime::fromString(
- calc::minutes_to_string(
- query.value(14).toString()),"hh:mm");
- object.tPICUS = QTime::fromString(
- calc::minutes_to_string(
- query.value(15).toString()),"hh:mm");
- object.tSIC = QTime::fromString(
- calc::minutes_to_string(
- query.value(16).toString()),"hh:mm");
- object.tDUAL = QTime::fromString(
- calc::minutes_to_string(
- query.value(17).toString()),"hh:mm");
- object.tFI = QTime::fromString(
- calc::minutes_to_string(
- query.value(18).toString()),"hh:mm");
- object.tSIM = QTime::fromString(
- calc::minutes_to_string(
- query.value(19).toString()),"hh:mm");
- object.pilotFlying = query.value(20).toInt();
- object.toDay = query.value(21).toInt();
- object.toNight = query.value(22).toInt();
- object.ldgDay = query.value(23).toInt();
- object.ldgNight = query.value(24).toInt();
- object.autoland = query.value(25).toInt();
- object.secondPilot = query.value(26).toInt();
- object.thirdPilot = query.value(27).toInt();
- object.approachType = query.value(28).toString();
- object.flightNumber = query.value(29).toString();
- object.remarks = query.value(30).toString();
-
- object.isValid = true;
- object.invalidItems.clear();
- return object;
- }
- bool dbFlight::commitFlight(flight object)
- {
-
- qDebug() << object;
- return false;
- }
- QVector<QString> dbFlight::selectFlightById(QString flight_id)
- {
- QSqlQuery query;
- query.prepare("SELECT * FROM flights WHERE id = ?");
- query.addBindValue(flight_id);
- query.exec();
- if(query.first());
- else
- {
- qDebug() << "db::SelectFlightById - No Flight with this ID found";
- QVector<QString> flight;
- return flight;
- }
- QVector<QString> flight;
- flight.append(query.value(0).toString());
- flight.append(query.value(1).toString());
- flight.append(query.value(2).toString());
- flight.append(query.value(3).toString());
- flight.append(query.value(4).toString());
- flight.append(query.value(5).toString());
- flight.append(query.value(6).toString());
- flight.append(query.value(7).toString());
- flight.append(query.value(8).toString());
- qDebug() << "db::SelectFlightById - retreived flight: " << flight;
- return flight;
- }
- bool dbFlight::deleteFlightById(QString flight_id)
- {
- QSqlQuery query;
- query.prepare("DELETE FROM flights WHERE id = ?");
- query.addBindValue(flight_id);
- query.exec();
- QString error = query.lastError().text();
- 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
- {
- return true;
- }
- }
- QVector<QString> dbFlight::createFlightVectorFromInput(QString doft, QString dept, QTime tofb, QString dest,
- QTime tonb, QTime tblk, QString pic, QString acft)
- {
- QVector<QString> flight;
- flight.insert(0, "");
- flight.insert(1, doft);
- flight.insert(2, dept);
- flight.insert(3, QString::number(calc::time_to_minutes(tofb)));
- flight.insert(4, dest);
- flight.insert(5, QString::number(calc::time_to_minutes(tonb)));
- flight.insert(6, QString::number(calc::time_to_minutes(tblk)));
- flight.insert(7, pic);
- flight.insert(8, acft);
-
- return flight;
- }
- void dbFlight::commitToScratchpad(QVector<QString> flight)
- {
-
- QSqlQuery query;
- query.prepare("INSERT INTO scratchpad (doft, dept, tofb, dest, tonb, tblk, pic, acft) "
- "VALUES (:doft, :dept, :tofb, :dest, :tonb, :tblk, :pic, :acft)");
-
- query.bindValue(":doft", flight[1]);
- query.bindValue(":dept", flight[2]);
- query.bindValue(":tofb", flight[3].toInt());
- query.bindValue(":dest", flight[4]);
- query.bindValue(":tonb", flight[5].toInt());
- query.bindValue(":tblk", flight[6].toInt());
- query.bindValue(":pic", flight[7].toInt());
- query.bindValue(":acft", flight[8].toInt());
- query.exec();
- qDebug() << query.lastError().text();
- }
- QVector<QString> dbFlight::retreiveScratchpad()
- {
-
- QSqlQuery query;
- query.prepare("SELECT * FROM scratchpad");
- query.exec();
- if(query.first());
- else
- {
-
- QVector<QString> flight;
- return flight;
- }
- query.previous();
- QVector<QString> flight;
- while (query.next()) {
- flight.append(query.value(0).toString());
- flight.append(query.value(1).toString());
- flight.append(query.value(2).toString());
- flight.append(calc::minutes_to_string((query.value(3).toString())));
- flight.append(query.value(4).toString());
- flight.append(calc::minutes_to_string((query.value(5).toString())));
- flight.append(calc::minutes_to_string((query.value(6).toString())));
- flight.append(query.value(7).toString());
- flight.append(query.value(8).toString());
- }
- clearScratchpad();
- return flight;
- }
- bool dbFlight::checkScratchpad()
- {
-
- QSqlQuery query;
- query.prepare("SELECT * FROM scratchpad");
- query.exec();
- if(query.first())
- {
-
- return 1;
- }
- else
- {
-
- return 0;
- }
- }
- void dbFlight::clearScratchpad()
- {
- qDebug() << "Deleting scratchpad";
- QSqlQuery query;
- query.prepare("DELETE FROM scratchpad;");
- query.exec();
- }
|