-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddflightwindow.cpp
More file actions
75 lines (67 loc) · 2.4 KB
/
Copy pathaddflightwindow.cpp
File metadata and controls
75 lines (67 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "addflightwindow.h"
#include "ui_addflightwindow.h"
#include "planetypedatabasecontroller.h"
#include "flightsdatabasecontroller.h"
#include "seatsdatabasecontroller.h"
AddFlightWindow::AddFlightWindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::AddFlightWindow)
{
ui->setupUi(this);
AddItemsToPlaneTypeComboBox();
PlaneTypeDatabaseController planeTypeDB(planeTypeDB_path);
planeTypeDB.CreateTable();
FlightsDatabaseController flightsDB(flightsDB_path);
flightsDB.CreateTable();
//SeatsDatabaseController seatsDB(seatsDB_path);
}
AddFlightWindow::~AddFlightWindow()
{
delete ui;
}
void AddFlightWindow::AddItemsToPlaneTypeComboBox()
{
PlaneTypeDatabaseController planeTypeDB(planeTypeDB_path);
for(int i=1;i<=planeTypeDB.CountItemsInDatabase();i++)
{
ui->planeTypeComboBox->addItem(planeTypeDB.GetPlaneTypeByID(i));
}
}
void AddFlightWindow::on_addFlightPushButton_clicked()
{
bool isDepartureDigit, isArrivalDigit;
FlightsDatabaseController flightsDB(flightsDB_path);
QString planeType, code ,departure, arrival;
planeType = ui->planeTypeComboBox->currentText();
departure = ui->departureLineEdit->text();
arrival = ui->arrivalLineEdit->text();
code = ui->codeLineEdit->text();
qDebug() << code.size();
if(!flightsDB.FlightExists(code) && code.size() == 4)
{
if(!departure.toDouble(&isDepartureDigit) && !arrival.toDouble(&isArrivalDigit) && !planeType.isEmpty() && !departure.isEmpty() && !arrival.isEmpty() && !code.isEmpty())
{
if(flightsDB.AddFlightToTable(planeType,code,departure,arrival))
{
ui->informationLabel->setText("Flight " + code + " added");
PlaneTypeDatabaseController planeTypeDB(planeTypeDB_path);
int seats = planeTypeDB.GetSeatsByPlaneType(planeType);
SeatsDatabaseController seatsDB(seatsDB_path);
seatsDB.CreatTable(code);
//MainWindow().UpdateFlightsList();
for(int i=1;i<=seats;i++)
{
seatsDB.AddSeat(0,code);
}
}
}
else
{
ui->informationLabel->setText("departure and arrival can not be a digit or empty");
}
}
else
{
ui->informationLabel->setText("Flight " + code + " already exist or code is given in wrong format");
}
}