-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrivers.cpp
90 lines (79 loc) · 2.66 KB
/
drivers.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 "drivers.h"
#include "ui_drivers.h"
#include "newdriver.h"
#include <QSqlQuery>
Drivers::Drivers(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Drivers)
{
ui->setupUi(this);
m_pNewDriver = new NewDriver(this);
m_rowCountDrivers = this->searchRowCountDrivers();
ui->tableWidget->setRowCount(m_rowCountDrivers);
QSqlQuery queryShowDataDrivers;
queryShowDataDrivers.exec("SELECT personalNumber, lastName, name, middleName, dateOfBirth, passportNumber, driversLicence, idMotorTransport "
"FROM Drivers");
queryShowDataDrivers.next();
for (int i = 0; i < m_rowCountDrivers; i++)
{
for (int j = 0; j < 8; j++)
{
QTableWidgetItem *pItem = new QTableWidgetItem();
pItem->setText(QString(queryShowDataDrivers.value(j).toString()).arg(i).arg(j));
ui->tableWidget->setItem(i, j, pItem);
}
queryShowDataDrivers.next();
}
}
Drivers::~Drivers()
{
delete ui;
delete m_pNewDriver;
}
int Drivers::searchRowCountDrivers()
{
int count;
QSqlQuery queryGetCountDrivers;
queryGetCountDrivers.exec("SELECT COUNT(*) FROM Drivers");
while (queryGetCountDrivers.next())
{
count = queryGetCountDrivers.value(0).toInt();
}
return count;
}
void Drivers::showNewDriverForm()
{
m_pNewDriver->show();
}
void Drivers::addTableRowDrivers(int count)
{
ui->tableWidget->setRowCount(count + 1);
QSqlQuery queryGetDataDrivers;
queryGetDataDrivers.prepare("SELECT personalNumber, lastName, name, middleName, dateOfBirth, passportNumber, driversLicence, idMotorTransport "
"FROM Drivers "
"WHERE idDriver = :rowCount");
queryGetDataDrivers.bindValue(":rowCount", count);
queryGetDataDrivers.exec();
while (queryGetDataDrivers.next())
{
for (int j = 0; j < 8; j++)
{
QTableWidgetItem *pItem = new QTableWidgetItem();
pItem->setText(QString(queryGetDataDrivers.value(j).toString()).arg(count).arg(j));
ui->tableWidget->setItem(count, j, pItem);
}
}
}
void Drivers::removeDriver()
{
QModelIndexList selectedRows = ui->tableWidget->selectionModel()->selectedRows();
while (!selectedRows.empty())
{
ui->tableWidget->removeRow(selectedRows[0].row());
QSqlQuery queryRemoveDataDrivers;
queryRemoveDataDrivers.prepare("DELETE FROM Drivers WHERE idDriver = :driver");
queryRemoveDataDrivers.bindValue(":driver", selectedRows[0].row());
queryRemoveDataDrivers.exec();
selectedRows = ui->tableWidget->selectionModel()->selectedRows();
}
}