-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.cpp
90 lines (79 loc) · 2.57 KB
/
routes.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "routes.h"
#include "ui_routes.h"
#include "newroute.h"
#include <QSqlQuery>
Routes::Routes(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Routes)
{
ui->setupUi(this);
m_pNewRoute = new NewRoute(this);
m_rowCountRoutes = this->searchRowCountRoutes();
ui->tableWidget->setRowCount(m_rowCountRoutes);
QSqlQuery queryShowDataRoutes;
queryShowDataRoutes.exec("SELECT nameRoute, direction, distance, flights, fuel, exitTime, returnTime "
"FROM Routes");
queryShowDataRoutes.next();
for (int i = 0; i < m_rowCountRoutes; i++)
{
for (int j = 0; j < 7; j++)
{
QTableWidgetItem *pItem = new QTableWidgetItem();
pItem->setText(QString(queryShowDataRoutes.value(j).toString()).arg(i).arg(j));
ui->tableWidget->setItem(i, j, pItem);
}
queryShowDataRoutes.next();
}
}
Routes::~Routes()
{
delete ui;
delete m_pNewRoute;
}
int Routes::searchRowCountRoutes()
{
int count;
QSqlQuery queryGetCountRoutes;
queryGetCountRoutes.exec("SELECT COUNT(*) FROM Routes");
while (queryGetCountRoutes.next())
{
count = queryGetCountRoutes.value(0).toInt();
}
return count;
}
void Routes::showNewRouteForm()
{
m_pNewRoute->show();
}
void Routes::addTableRowRoutes(int count)
{
ui->tableWidget->setRowCount(count + 1);
QSqlQuery queryGetDataRoutes;
queryGetDataRoutes.prepare("SELECT nameRoute, direction, distance, flights, fuel, exitTime, returnTime "
"FROM Routes "
"WHERE idRoute = :rowCount");
queryGetDataRoutes.bindValue(":rowCount", count);
queryGetDataRoutes.exec();
while (queryGetDataRoutes.next())
{
for (int j = 0; j < 7; j++)
{
QTableWidgetItem *pItem = new QTableWidgetItem();
pItem->setText(QString(queryGetDataRoutes.value(j).toString()).arg(count).arg(j));
ui->tableWidget->setItem(count, j, pItem);
}
}
}
void Routes::removeRoute()
{
QModelIndexList selectedRows = ui->tableWidget->selectionModel()->selectedRows();
while (!selectedRows.empty())
{
ui->tableWidget->removeRow(selectedRows[0].row());
QSqlQuery queryRemoveDataMotorTransport;
queryRemoveDataMotorTransport.prepare("DELETE FROM Routes WHERE idRoute = :route");
queryRemoveDataMotorTransport.bindValue(":route", selectedRows[0].row());
queryRemoveDataMotorTransport.exec();
selectedRows = ui->tableWidget->selectionModel()->selectedRows();
}
}