-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathДенисов.cpp
137 lines (118 loc) · 4.7 KB
/
Денисов.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "createproductiondialog.h"
CreateProductionDialog::CreateProductionDialog(int userId, QWidget *parent) : QDialog(parent) {
mUserId = userId;
codec = QTextCodec::codecForLocale();
ui.setupUi(this);
setModal(true);
QComboBox* comboBox = setComboBox();
QSpinBox* spinBox = setSpinBox();
ui.gridLayout->addWidget(comboBox, 1, 0);
ui.gridLayout->addWidget(spinBox, 1, 1);
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancelCreate()));
connect(ui.addWorkButton, SIGNAL(clicked()), this, SLOT(addWork()));
connect(ui.createWorkButton, SIGNAL(clicked()), this, SLOT(createWork()));
}
CreateProductionDialog::~CreateProductionDialog() {
// my second commit to master
}
void CreateProductionDialog::cancelCreate() {
// My second commit to my own `Denisov` branch
reject();
}
/**
My first commit to my own `Denisov` branch
*/
void CreateProductionDialog::addWork() {
int row = ui.gridLayout->rowCount();
QComboBox* comboBox = setComboBox();
QSpinBox* spinBox = setSpinBox();
QPushButton* deleteButton = setDeleteButton(row);
ui.gridLayout->addWidget(comboBox, row, 0);
ui.gridLayout->addWidget(spinBox, row, 1);
ui.gridLayout->addWidget(deleteButton, row, 2);
}
void CreateProductionDialog::deleteWork() {
QPushButton* button = qobject_cast<QPushButton*>(sender());
int row = button->property("row").toInt();
for (int i = 0; i < 3; ++i) {
QLayoutItem* layoutItem = ui.gridLayout->itemAtPosition(row, i);
ui.gridLayout->removeItem(layoutItem);
delete layoutItem->widget();
delete layoutItem;
}
ui.gridLayout->update();
}
QPushButton* CreateProductionDialog::setDeleteButton(int row) {
QPushButton* button = new QPushButton(codec->toUnicode("Óáðàòü"), this);
button->setStyleSheet("background:none;color:blue;text-decoration:underline;border:none;text-align:left;");
button->setCursor(Qt::PointingHandCursor);
button->setProperty("row", row);
connect(button, SIGNAL(clicked()), this, SLOT(deleteWork()));
return button;
}
QComboBox* CreateProductionDialog::setComboBox() {
QComboBox* comboBox = new QComboBox(this);
QSqlQuery query = DataBaseProvider::getQuery();
query.prepare("SELECT * FROM type_product");
bool success = DataBaseProvider::execQuery(query);
//TODO
//çàïðîñ ê ÁÄ ïîëó÷åíèå ñïèñêà âñåõ òèïîâ ïðäóêöèè - Ïîëó÷åíèå äàííûõ äëÿ comboBox
if (success) {
while (query.next()) {
comboBox->addItem(query.value("name").toString(), query.value("id"));
}
comboBox->setCurrentIndex(0);
}
return comboBox;
}
/** This is my first commit to `master` branch
An informative documenting comment for setSpinBox() method.
*/
QSpinBox* CreateProductionDialog::setSpinBox() {
QSpinBox* spinBox = new QSpinBox(this);
spinBox->setMinimum(1);
spinBox->setMaximum(10000);
return spinBox;
}
void CreateProductionDialog::createWork() {
QString date = ui.workDateEdit->date().toString("dd.MM.yyyy");
QList<QPair<int, QPair<QString, int> > > workList = QList<QPair<int, QPair<QString, int> > >();
int countRow = ui.gridLayout->rowCount();
QVariantList prodTypes;
QVariantList numProduct;
QVariantList statuses;
QVariantList salary;
QSqlQuery query = DataBaseProvider::getQuery();
query.prepare("SELECT salary.id FROM salary WHERE salary.idWorker = ? AND salary.idBillingPeriod = (SELECT billng_period.id FROM billng_period WHERE endDate IS NULL OR endDate = '')");
query.addBindValue(mUserId);
bool success = DataBaseProvider::execQuery(query);
query.next();
int salaryId = query.value(0).toInt();
for (int i = 1; i < countRow; ++i) {
QPair<int, QPair<QString, int> > work;
work.first = 0; /*ID çàèíñåð÷åíîé çàïèñè*/
if (ui.gridLayout->itemAtPosition(i, 0) == 0) {
continue;
}
QComboBox* comboBox = qobject_cast<QComboBox*>(ui.gridLayout->itemAtPosition(i, 0)->widget());
QSpinBox* spinBox = qobject_cast<QSpinBox*>(ui.gridLayout->itemAtPosition(i, 1)->widget());
work.second = QPair<QString, int>(comboBox->currentText(), spinBox->value());
prodTypes << comboBox->currentData().toInt();
numProduct << spinBox->value();
statuses << 0;
salary << salaryId;
workList.append(work);
}
int l = workList.length();
for(int i = 0; i < l; i++) {
QSqlQuery queryInsert = DataBaseProvider::getQuery();
queryInsert.prepare("INSERT INTO `fact_of_work`(`idType`, `numProduct`, `status`, `idSalary`) VALUES (?,?,?,?)");
queryInsert.addBindValue(prodTypes.at(i).toInt());
queryInsert.addBindValue(numProduct.at(i).toInt());
queryInsert.addBindValue(statuses.at(i).toInt());
queryInsert.addBindValue(salary.at(i).toInt());
DataBaseProvider::execQuery(queryInsert);
workList[i].first = query.lastInsertId().toInt();
}
emit worksCreated(date, workList);
}