-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchvehiclemileage.cpp
86 lines (78 loc) · 2.94 KB
/
searchvehiclemileage.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
#include "searchvehiclemileage.h"
#include "ui_searchvehiclemileage.h"
#include "vehiclesmileage.h"
#include <QLineEdit>
#include <QSqlQuery>
SearchVehicleMileage::SearchVehicleMileage(VehiclesMileage *vehiclesMileage, QWidget *parent) :
QDialog(parent),
ui(new Ui::SearchVehicleMileage)
{
ui->setupUi(this);
m_pVehiclesMileage = vehiclesMileage;
m_period = false;
int counter;
QSqlQuery queryGetCountMotorTransport;
queryGetCountMotorTransport.exec("SELECT COUNT(*) FROM MotorTransport");
while (queryGetCountMotorTransport.next())
{
counter = queryGetCountMotorTransport.value(0).toInt();
}
for (int i = 0; i < counter; i++)
{
QSqlQuery queryGetDataMotorTransport;
queryGetDataMotorTransport.prepare("SELECT brand, stateNumber FROM MotorTransport WHERE idMotorTransport = :rowCount");
queryGetDataMotorTransport.bindValue(":rowCount", i);
queryGetDataMotorTransport.exec();
while (queryGetDataMotorTransport.next())
{
ui->motorTransport->addItem(queryGetDataMotorTransport.value(0).toString()+ " " + "(" + queryGetDataMotorTransport.value(1).toString() + ")");
}
}
}
SearchVehicleMileage::~SearchVehicleMileage()
{
delete ui;
}
void SearchVehicleMileage::checkBoxClicked()
{
if (ui->checkBox->isChecked()) {
ui->dateLabel->setEnabled(false);
ui->date->setEnabled(false);
ui->groupBox->setEnabled(true);
m_period = true;
} else {
ui->dateLabel->setEnabled(true);
ui->date->setEnabled(true);
ui->groupBox->setEnabled(false);
m_period = false;
}
}
void SearchVehicleMileage::showSearchResult()
{
QSqlQuery queryGetDataVehiclesMileage;
queryGetDataVehiclesMileage.prepare("SELECT idMotorTransport, date, mileage FROM TravelSheet "
"WHERE date >= :dateFrom AND date <= :dateTo AND idMotorTransport = :motorTransport");
if (m_period) {
queryGetDataVehiclesMileage.bindValue(":dateFrom", ui->dateFrom->date());
queryGetDataVehiclesMileage.bindValue(":dateTo", ui->dateTo->date());
} else {
queryGetDataVehiclesMileage.bindValue(":dateFrom", ui->date->date());
queryGetDataVehiclesMileage.bindValue(":dateTo", ui->date->date());
}
queryGetDataVehiclesMileage.bindValue(":motorTransport", ui->motorTransport->lineEdit()->text());
queryGetDataVehiclesMileage.exec();
QString arrayDataVehiclesMileage[3];
int counter = 0;
bool dateNoExist = true;
while(queryGetDataVehiclesMileage.next())
{
for (int i = 0; i < 3; i++)
arrayDataVehiclesMileage[i] = queryGetDataVehiclesMileage.value(i).toString();
m_pVehiclesMileage->addTableWidgetRows(counter, arrayDataVehiclesMileage);
counter++;
dateNoExist = false;
}
if (dateNoExist)
m_pVehiclesMileage->addTableWidgetRows(-1, arrayDataVehiclesMileage);
this->close();
}