-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchemployedotherworker.cpp
88 lines (80 loc) · 3.17 KB
/
searchemployedotherworker.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
#include "searchemployedotherworker.h"
#include "ui_searchemployedotherworker.h"
#include "employedotherworkers.h"
#include <QLineEdit>
#include <QSqlQuery>
SearchEmployedOtherWorker::SearchEmployedOtherWorker(EmployedOtherWorkers *employedOtherWorkers, QWidget *parent) :
QDialog(parent),
ui(new Ui::SearchEmployedOtherWorker)
{
ui->setupUi(this);
m_pEmployedOtherWorkers = employedOtherWorkers;
m_period = false;
int counter;
QSqlQuery queryGetCountOtherWorkers;
queryGetCountOtherWorkers.exec("SELECT COUNT(*) FROM OtherWorkers");
while (queryGetCountOtherWorkers.next())
{
counter = queryGetCountOtherWorkers.value(0).toInt();
}
for (int i = 0; i < counter; i++)
{
QSqlQuery queryGetDataOtherWorkers;
queryGetDataOtherWorkers.prepare("SELECT lastName, name, middleName FROM OtherWorkers WHERE idOtherWorker = :rowCount");
queryGetDataOtherWorkers.bindValue(":rowCount", i);
queryGetDataOtherWorkers.exec();
while (queryGetDataOtherWorkers.next())
{
QString str1 = queryGetDataOtherWorkers.value(1).toString();
QString str2 = queryGetDataOtherWorkers.value(2).toString();
ui->comboBox->addItem(queryGetDataOtherWorkers.value(0).toString()+ " " + str1[0] + "." + str2[0] + ".");
}
}
}
SearchEmployedOtherWorker::~SearchEmployedOtherWorker()
{
delete ui;
}
void SearchEmployedOtherWorker::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 SearchEmployedOtherWorker::showSearchResult()
{
QSqlQuery queryGetDataEmployedOtherWorkers;
queryGetDataEmployedOtherWorkers.prepare("SELECT date, idOtherWorker, timeWorked, shift FROM EmployedOtherWorkers "
"WHERE date >= :dateFrom AND date <= :dateTo AND idOtherWorker = :worker");
if (m_period) {
queryGetDataEmployedOtherWorkers.bindValue(":dateFrom", ui->dateFrom->date());
queryGetDataEmployedOtherWorkers.bindValue(":dateTo", ui->dateTo->date());
} else {
queryGetDataEmployedOtherWorkers.bindValue(":dateFrom", ui->date->date());
queryGetDataEmployedOtherWorkers.bindValue(":dateTo", ui->date->date());
}
queryGetDataEmployedOtherWorkers.bindValue(":worker", ui->comboBox->lineEdit()->text());
queryGetDataEmployedOtherWorkers.exec();
QString arrayDataEmployedOtherWorkers[4];
int counter = 0;
bool dateNoExist = true;
while(queryGetDataEmployedOtherWorkers.next())
{
for (int i = 0; i < 4; i++)
arrayDataEmployedOtherWorkers[i] = queryGetDataEmployedOtherWorkers.value(i).toString();
m_pEmployedOtherWorkers->addTableWidgetRows(counter, arrayDataEmployedOtherWorkers);
counter++;
dateNoExist = false;
}
if (dateNoExist)
m_pEmployedOtherWorkers->addTableWidgetRows(-1, arrayDataEmployedOtherWorkers);
this->close();
}