-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookadminhotelform.cpp
120 lines (114 loc) · 5.56 KB
/
lookadminhotelform.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
#include "lookadminhotelform.h"
#include "ui_lookadminhotelform.h"
LookAdminHotelForm::LookAdminHotelForm(Queue<Hotel> * queue) :
queue(queue),
ui(new Ui::LookAdminHotelForm)
{
ui->setupUi(this);
ui->spinBox->setMinimum(1);
ui->spinBox->setMaximum(queue->size());
ui->tableWidget->setColumnCount(3);
QTableWidgetItem *w = new QTableWidgetItem("Название отеля");
ui->tableWidget->setHorizontalHeaderItem(0, w);
ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Оценка"));
ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Выручка отеля"));
ui->tableWidget->setShowGrid(true);
ui->tableWidget->setEditTriggers(nullptr);
for (int i = 0; i < queue->size(); i++) {
ui->tableWidget->insertRow(i);
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(QString::fromStdString(queue->operator[](i).getName())));
ui->tableWidget->setItem(i, 1, new QTableWidgetItem(QString::number(queue->operator[](i).getMark())));
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(QString::number(queue->operator[](i).getMoney())));
}
ui->tableWidget->resizeColumnsToContents();
}
LookAdminHotelForm::~LookAdminHotelForm()
{
delete ui;
}
void LookAdminHotelForm::on_sortMark_clicked()
{
for (int i = 0; i < queue->size(); i++) {
for (int j = queue->size() - 1; j > i; j--) {
if (queue->operator[](i).getMark() < queue->operator[](j).getMark()) {
Hotel tmp = queue->operator[](i);
queue->operator[](i) = queue->operator[](j);
queue->operator[](j) = tmp;
}
}
}
ui->tableWidget->clear();
ui->tableWidget->setColumnCount(3);
QTableWidgetItem *w = new QTableWidgetItem("Название отеля");
ui->tableWidget->setHorizontalHeaderItem(0, w);
ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Оценка"));
ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Выручка отеля"));
ui->tableWidget->setShowGrid(true);
ui->tableWidget->setEditTriggers(nullptr);
for (int i = 0; i < queue->size(); i++) {
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(QString::fromStdString(queue->operator[](i).getName())));
ui->tableWidget->setItem(i, 1, new QTableWidgetItem(QString::number(queue->operator[](i).getMark())));
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(QString::number(queue->operator[](i).getMoney())));
}
ui->tableWidget->resizeColumnsToContents();
}
void LookAdminHotelForm::on_sortMoney_clicked()
{
for (int i = 0; i < queue->size(); i++) {
for (int j = queue->size() - 1; j > i; j--) {
if (queue->operator[](i).getMoney() > queue->operator[](j).getMoney()) {
Hotel tmp = queue->operator[](i);
queue->operator[](i) = queue->operator[](j);
queue->operator[](j) = tmp;
}
}
}
ui->tableWidget->clear();
ui->tableWidget->setColumnCount(3);
QTableWidgetItem *w = new QTableWidgetItem("Название отеля");
ui->tableWidget->setHorizontalHeaderItem(0, w);
ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Оценка"));
ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Выручка отеля"));
ui->tableWidget->setShowGrid(true);
ui->tableWidget->setEditTriggers(nullptr);
for (int i = 0; i < queue->size(); i++) {
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(QString::fromStdString(queue->operator[](i).getName())));
ui->tableWidget->setItem(i, 1, new QTableWidgetItem(QString::number(queue->operator[](i).getMark())));
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(QString::number(queue->operator[](i).getMoney())));
}
ui->tableWidget->resizeColumnsToContents();
}
void LookAdminHotelForm::on_delete_2_clicked()
{
if (queue->size() < 1) {
QMessageBox::critical(nullptr, "Удаление отеля", "Нет отелей для удаления!");
return;
}
for (int i = ui->spinBox->text().toInt() - 1; i < queue->size() - 1; i++) {
queue->operator[](i) = queue->operator[](i + 1);
}
queue->popTail();
QMessageBox::information(nullptr, "Удаление отеля", "Отель удалён успешно!");
ui->tableWidget->clear();
ui->spinBox->setMaximum(queue->size());
ui->tableWidget->setColumnCount(3);
QTableWidgetItem *w = new QTableWidgetItem("Название отеля");
ui->tableWidget->setHorizontalHeaderItem(0, w);
ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Оценка"));
ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Выручка отеля"));
ui->tableWidget->setShowGrid(true);
ui->tableWidget->setEditTriggers(nullptr);
for (int i = 0; i < queue->size(); i++) {
ui->tableWidget->insertRow(i);
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(QString::fromStdString(queue->operator[](i).getName())));
ui->tableWidget->setItem(i, 1, new QTableWidgetItem(QString::number(queue->operator[](i).getMark())));
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(QString::number(queue->operator[](i).getMoney())));
}
ui->tableWidget->resizeColumnsToContents();
Files::saveHotel(queue, "hotel.txt");
}
void LookAdminHotelForm::on_back_clicked()
{
this->close();
delete this;
}