commit f522412382c4a6722b240d86c76dd2bce914d45f Author: Иван Алексеев Date: Wed Jan 15 22:57:00 2025 +0400 готово diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4a0b530 --- /dev/null +++ b/.gitignore @@ -0,0 +1,74 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* +CMakeLists.txt.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/Factory.pro b/Factory.pro new file mode 100644 index 0000000..f07000d --- /dev/null +++ b/Factory.pro @@ -0,0 +1,43 @@ +QT += core gui sql + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++17 + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + presenter.cpp \ + service/filterparams.cpp \ + service/projectlogic.cpp \ + service/serviceloaddb.cpp \ + service/types.cpp \ + +HEADERS += \ + mainwindow.h \ + presenter.h \ + service/filterparams.h \ + service/projectlogic.h \ + service/serviceloaddb.h \ + service/types.h \ + +FORMS += \ + mainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +DISTFILES += \ + data/requestDeviceModels.sql \ + data/requestProjects.sql \ + data/requestStages.sql \ + data/requestWorkers.sql \ + +RESOURCES += \ + resources/resources.qrc diff --git a/data/requestDeviceModels.sql b/data/requestDeviceModels.sql new file mode 100644 index 0000000..7b0d70c --- /dev/null +++ b/data/requestDeviceModels.sql @@ -0,0 +1,8 @@ +SELECT + m.*, + dt.Name AS device_type_name +FROM + Model m +JOIN + DeviceType dt ON m.DeviceTypeID = dt.ID; + diff --git a/data/requestProjects.sql b/data/requestProjects.sql new file mode 100644 index 0000000..8930749 --- /dev/null +++ b/data/requestProjects.sql @@ -0,0 +1,10 @@ +SELECT + p.*, + t.Name AS team_name, + s.Name AS stage_name +FROM + Project p +JOIN + Team t ON p.TeamID = t.ID +JOIN + Stages s ON p.StagesID = s.ID; diff --git a/data/requestStages.sql b/data/requestStages.sql new file mode 100644 index 0000000..1528bab --- /dev/null +++ b/data/requestStages.sql @@ -0,0 +1,8 @@ +SELECT + s.*, + w.Name AS worker_name +FROM + Stages s +JOIN + Worker w ON s.WorkerID = w.ID; + diff --git a/data/requestWorkers.sql b/data/requestWorkers.sql new file mode 100644 index 0000000..b85f8f9 --- /dev/null +++ b/data/requestWorkers.sql @@ -0,0 +1,8 @@ +SELECT + w.*, + t.Name AS team_name +FROM + Worker w +JOIN + Team t ON w.TeamID = t.ID; + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..a7fb082 --- /dev/null +++ b/main.cpp @@ -0,0 +1,10 @@ +#include "presenter.h" +#include + +int main(int argc, char *argv[]) +{ + qDebug() << QSqlDatabase::drivers(); + QApplication a(argc, argv); + new Presenter(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..41b2c92 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,499 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + setWindowIcon(QIcon(":/images/mw-icon.png")); + + int width = frameGeometry().width(); + int height = frameGeometry().height(); + QScreen *screen = qApp->primaryScreen(); + int screenWidth = screen->geometry().width(); + int screenHeight = screen->geometry().height(); + setGeometry((screenWidth/2)-(width/2), (screenHeight/2)-(height/2), width, height); + + returnToDeviceList(); + + ui->tableWidget->verticalHeader()->setVisible(false); + ui->tableWidget->setColumnCount(2); + QStringList headers = QString("ID, Название").split(','); + ui->tableWidget->setHorizontalHeaderLabels(headers); + QHeaderView *header = ui->tableWidget->horizontalHeader(); + header->setSectionResizeMode(0, QHeaderView::Stretch); + header->setSectionResizeMode(1, QHeaderView::Stretch); + QFont headerFont = header->font(); + headerFont.setBold(true); + header->setFont(headerFont); + ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); + + ui->listWidgetProjects->setSpacing(10); + + ui->checkBoxIsWorking->setAttribute(Qt::WA_TransparentForMouseEvents); + ui->checkBoxIsWorking->setFocusPolicy(Qt::NoFocus); + + QStringList filterItems = { + "Все пороекты", + "Типы устройств", + "Этапы", + "Команды", + "Работники", + "Модели устройств" + }; + + ui->comboBoxFilters->addItems(filterItems); + + QStringList sortItems = { + "Сначала дешевые", + "Сначала дорогие", + "Сначала с лайком" + }; + + ui->comboBoxSort->addItems(sortItems); + + QLineEdit *searchEdit = ui->lineEditSearch; + QPushButton *searchButton = new QPushButton(this); + + searchButton->setCursor(Qt::PointingHandCursor); + searchButton->setStyleSheet("background: transparent; border: none;"); + searchButton->setIcon(QIcon(":/images/search.png")); + searchButton->setFixedSize(22, 22); + + QMargins margins = searchEdit->textMargins(); + searchEdit->setTextMargins(margins.left(), margins.top(), searchButton->width(), margins.bottom()); + searchEdit->setPlaceholderText(QStringLiteral("Поиск проектов по модели или типу...")); + searchEdit->setMaxLength(200); + + QHBoxLayout *searchLayout = new QHBoxLayout(); + searchLayout->addStretch(); + searchLayout->addWidget(searchButton); + searchLayout->setSpacing(0); + searchLayout->setContentsMargins(3, 2, 3, 2); + searchEdit->setLayout(searchLayout); + + QButtonGroup *buttonGroup = new QButtonGroup(this); + buttonGroup->addButton(ui->radioButtonWorking); + buttonGroup->addButton(ui->radioButtonNotWorking); + buttonGroup->addButton(ui->radioButtonDisregard); + ui->radioButtonWorking->setChecked(true); + + connect(ui->comboBoxFilters, SIGNAL(activated(int)), this, SLOT(updateTableWidget(int))); + connect(ui->comboBoxSort, SIGNAL(activated(int)), this, SLOT(changeSortOrder())); + connect(ui->tableWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(updateListWidget())); + connect(ui->listWidgetProjects, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showItemInfo(QListWidgetItem*))); + connect(ui->pushButtonBack, SIGNAL(clicked()), this, SLOT(pushButtonBackClicked())); + connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(pushButtonClearClicked())); + connect(searchEdit, SIGNAL(returnPressed()), this, SLOT(pushButtonSearchClicked())); + connect(searchButton, SIGNAL(clicked()), this, SLOT(pushButtonSearchClicked())); + connect(ui->pushButtonApplyFilters, SIGNAL(clicked()), this, SLOT(pushButtonApplyFiltersClicked())); + connect(ui->pushButtonCanselFilters, SIGNAL(clicked()), this, SLOT(pushButtonCancelFiltersClicked())); + connect(ui->pushButtonDefault, SIGNAL(clicked()), this, SLOT(pushButtonDefaultClicked())); + + QFile styleFile(":/styles.qss"); + if (styleFile.open(QFile::ReadOnly)) { + QTextStream ts(&styleFile); + QString style = ts.readAll(); + qApp->setStyleSheet(style); + } +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::getStages(QMap &map) +{ + mapStages = map; +} + +void MainWindow::getTeams(QMap &map) +{ + mapTeams = map; +} + +void MainWindow::getWorkers(QMap &map) +{ + mapWorkers = map; +} + +void MainWindow::getDeviceTypes(QMap &map) +{ + mapDeviceTypes = map; + for (int i = 1; i <= mapDeviceTypes.size(); i++) { + QString imagePath = QString(":/images/device-type-%1.png").arg(i); + deviceTypeImages[i] = imagePath; + } +} + +void MainWindow::getDeviceModels(QMap &map) +{ + mapDeviceModels = map; +} + +void MainWindow::getProjects(QMap &map) +{ + mapDevices = map; + updateTableWidget(0); +} + +void MainWindow::updateTableWidget(int index) +{ + returnToDeviceList(); + + ui->tableWidget->clearContents(); + ui->tableWidget->setRowCount(0); + + switch (index) { + case 0: // Все устройства + clearDevicesOutputSettings(); + updateListWidgetDevices(0); + break; + case 1: // Типы устройств + fillTable(mapDeviceTypes); + break; + case 2: // Этапы + fillTable(mapStages); + break; + case 3: // Команды + fillTable(mapTeams); + break; + case 4: // Работники + fillTable(mapWorkers); + break; + case 5: // Модели проектов + fillTable(mapDeviceModels); + break; + default: + break; + } +} + +void MainWindow::updateListWidget() +{ + returnToDeviceList(); + + int selectedEntityId = getSelectedIndex(); + + if (selectedEntityId == -1) + return; + + clearDevicesOutputSettings(); + updateListWidgetDevices(selectedEntityId); +} + +template +void MainWindow::fillTable(const QMap &map) +{ + int row = 0; + for (auto &item : map) { + ui->tableWidget->insertRow(row); + + QTableWidgetItem *idItem = new QTableWidgetItem(QString::number(item.id())); + QTableWidgetItem *nameItem = new QTableWidgetItem(item.name()); + + idItem->setFlags(idItem->flags() & ~Qt::ItemIsEditable); + nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable); + + ui->tableWidget->setItem(row, 0, idItem); + ui->tableWidget->setItem(row, 1, nameItem); + + idItem->setTextAlignment(Qt::AlignCenter); + nameItem->setTextAlignment(Qt::AlignCenter); + + row++; + } +} + +void MainWindow::updateListWidgetDevices(int entityId) +{ + ui->listWidgetProjects->clear(); + + auto filteredDevices = logic->findDevicesByAllParameters( + mapDevices, + entityId, + ui->comboBoxFilters->currentIndex(), + searchInfo, + filterParams, + ui->comboBoxSort->currentText() + ); + + if (filteredDevices.isEmpty()) { + QListWidgetItem *item = new QListWidgetItem(ui->listWidgetProjects); + ui->listWidgetProjects->addItem(item); + QWidget *cardWidget = createMessageEmptyCard(); + item->setSizeHint(cardWidget->minimumSizeHint()); + item->setFlags(item->flags() & ~Qt::ItemIsEnabled); + ui->listWidgetProjects->setItemWidget(item, cardWidget); + } else { + for (auto &device : filteredDevices) { + addDeviceToList(device); + } + } +} + +QWidget *MainWindow::createMessageEmptyCard() +{ + QWidget *cardWidget = new QWidget(ui->listWidgetProjects); + QVBoxLayout *cardLayout = new QVBoxLayout(cardWidget); + + QLabel *titleLabel = new QLabel("По заданным параметрам ничего не найдено", cardWidget); + QFont titleFont("Arial", 17, QFont::Bold); + titleLabel->setFont(titleFont); + + cardLayout->addWidget(titleLabel, 0, Qt::AlignCenter); + + cardLayout->setSpacing(12); + + QLabel *imageLabel = new QLabel(cardWidget); + QPixmap pixmap(":/images/question.png"); + imageLabel->setPixmap(pixmap.scaled(256, 256, Qt::KeepAspectRatio)); + + cardLayout->addWidget(imageLabel, 0, Qt::AlignCenter); + + return cardWidget; +} + +QWidget *MainWindow::createDeviceCard(const Project &project) +{ + QWidget *cardWidget = new QWidget(ui->listWidgetProjects); + QVBoxLayout *cardLayout = new QVBoxLayout(cardWidget); + + QFrame *topBorder = new QFrame(cardWidget); + topBorder->setFrameShape(QFrame::HLine); + topBorder->setFrameShadow(QFrame::Sunken); + + cardLayout->addWidget(topBorder); + + QHBoxLayout *iconTextlayout = new QHBoxLayout(); + + QLabel *imageLabel = new QLabel(cardWidget); + QString imagePath = deviceTypeImages[project.deviceModel().idType()]; + QPixmap pixmap(imagePath); + imageLabel->setPixmap(pixmap.scaled(100, 100, Qt::KeepAspectRatio)); + + iconTextlayout->addWidget(imageLabel); + + QVBoxLayout *textLayout = new QVBoxLayout(); + + QLabel *serialNumberLabel = new QLabel(project.name(), cardWidget); + QFont serialNumberFont("Arial", 14, QFont::Bold); + serialNumberLabel->setFont(serialNumberFont); + textLayout->addWidget(serialNumberLabel); + + QFont generalFont("Arial", 11); + + QString typeName = project.deviceModel().nameType(); + typeName = typeName.left(typeName.length()); + if (typeName == "Персональные компьютер") + typeName = "Персональный компьютер"; + QLabel *typeNameLabel = new QLabel(typeName + ": " + project.deviceModel().name(), cardWidget); + typeNameLabel->setFont(generalFont); + textLayout->addWidget(typeNameLabel); + + QLabel *statusLabel = new QLabel(project.isReady() ? "Готов" : "Не готов", cardWidget); + statusLabel->setFont(generalFont); + textLayout->addWidget(statusLabel); + + QHBoxLayout *priceLikeLayout = new QHBoxLayout(); + priceLikeLayout->setSpacing(100); + + QLabel *priceLabel = new QLabel(QString::number(project.budget()) + " ₽", cardWidget); + priceLabel->setFont(generalFont); + priceLabel->setFixedWidth(100); + priceLikeLayout->addWidget(priceLabel); + + priceLikeLayout->addSpacerItem(new QSpacerItem(40, 0, QSizePolicy::Expanding, QSizePolicy::Minimum)); + + QCheckBox *likeCheckBox = new QCheckBox("Нравится", cardWidget); + likeCheckBox->setChecked(project.isLiked()); + likeCheckBox->setFont(generalFont); + likeCheckBox->setStyleSheet(likeCheckBox->isChecked() ? "color: green;" : "color: black;"); + + connect(likeCheckBox, &QCheckBox::toggled, this, [this, project, likeCheckBox](bool checked) { + Project& deviceRef = mapDevices[project.id()]; + deviceRef.setIsLiked(checked); + + QString message = checked ? "Проект добавлен в избранное." : "Проект удален из избранного."; + QMessageBox::information(this, "Обновление", message); + + likeCheckBox->setStyleSheet(checked ? "color: green;" : "color: black;"); + }); + + priceLikeLayout->addWidget(likeCheckBox); + + textLayout->addLayout(priceLikeLayout); + + iconTextlayout->addSpacerItem(new QSpacerItem(40, 0, QSizePolicy::Expanding, QSizePolicy::Minimum)); + iconTextlayout->addLayout(textLayout); + + cardLayout->addLayout(iconTextlayout); + + QFrame *bottomBorder = new QFrame(cardWidget); + bottomBorder->setFrameShape(QFrame::HLine); + bottomBorder->setFrameShadow(QFrame::Sunken); + cardLayout->addWidget(bottomBorder); + + cardLayout->setContentsMargins(2, 0, 2, 0); + + return cardWidget; +} + +void MainWindow::addDeviceToList(const Project &device) +{ + QListWidgetItem *item = new QListWidgetItem(ui->listWidgetProjects); + ui->listWidgetProjects->addItem(item); + + QWidget *cardWidget = createDeviceCard(device); + + item->setSizeHint(cardWidget->minimumSizeHint()); + ui->listWidgetProjects->setItemWidget(item, cardWidget); + + item->setData(Qt::UserRole, device.id()); +} + +void MainWindow::returnToDeviceList() +{ + idCard = 0; + ui->stackedWidget->setCurrentIndex(0); +} + +void MainWindow::showItemInfo(QListWidgetItem *item) +{ + if (!item) + return; + + int deviceId = item->data(Qt::UserRole).toInt(); + Project device = mapDevices[deviceId]; + + idCard = deviceId; + if (!device.StartProjectDate().isValid()) + qDebug() << "StartProjectDate is invalid for device ID:" << device.id(); + if (!device.FinishProjectDate().isValid()) + qDebug() << "FinishProjectDate is invalid for device ID:" << device.id(); + ui->lineEditId->setText(QString::number(device.id())); + ui->lineEditSerialNum->setText(device.name()); + ui->lineEditPrice->setText(QString::number(device.budget(), 'f', 2)); + ui->lineEditEmployee->setText(device.nameTeam()); + ui->lineEditModel->setText(device.deviceModel().name()); + ui->lineEditType->setText(device.deviceModel().nameType()); + ui->textEditFurtherInformation->setPlainText(device.description()); + ui->checkBoxIsWorking->setChecked(device.isReady()); + + ui->stackedWidget->setCurrentIndex(1); +} + +void MainWindow::clearFilters() +{ + ui->radioButtonWorking->setChecked(true); + ui->doubleSpinBoxFrom->setValue(0.00); + ui->doubleSpinBoxTo->setValue(0.00); + filterParams.setIsReady(true); + filterParams.setPriceFrom(-1); + filterParams.setPriceTo(-1); + filterParams.setDisregardState(false); + filterParams.setApllyFilters(false); +} + +void MainWindow::clearDevicesOutputSettings() +{ + ui->comboBoxSort->setCurrentIndex(0); + + ui->lineEditSearch->setText(""); + searchInfo = ""; + + clearFilters(); +} + +int MainWindow::getSelectedIndex() +{ + QModelIndexList selectedIndexes = ui->tableWidget->selectionModel()->selectedRows(); + + if (selectedIndexes.isEmpty()) { + return -1; + } + + int rowIndex = selectedIndexes.first().row(); + + return ui->tableWidget->item(rowIndex, 0)->text().toInt(); +} + +void MainWindow::pushButtonBackClicked() +{ + returnToDeviceList(); +} + +void MainWindow::pushButtonClearClicked() +{ + ui->lineEditSearch->setText(""); +} + +void MainWindow::changeSortOrder() +{ + updateListWidgetDevices(getSelectedIndex()); +} + +void MainWindow::pushButtonSearchClicked() +{ + searchInfo = ui->lineEditSearch->text(); + if (searchInfo.isEmpty()) { + QMessageBox::warning(this, "Ошибка", "Пожалуйста, введите текст для поиска."); + return; + } + ui->comboBoxSort->setCurrentIndex(0); + clearFilters(); + updateListWidgetDevices(getSelectedIndex()); +} + +void MainWindow::pushButtonApplyFiltersClicked() +{ + double priceFrom = ui->doubleSpinBoxFrom->value(); + double priceTo = ui->doubleSpinBoxTo->value(); + if (priceFrom > priceTo) { + QMessageBox::warning(this, "Ошибка", "Начальное значение диапазона не может быть больше конечного значения."); + + ui->doubleSpinBoxFrom->setValue(filterParams.priceFrom()); + ui->doubleSpinBoxTo->setValue(filterParams.priceTo()); + + return; + } + + filterParams.setApllyFilters(true); + filterParams.setDisregardState(ui->radioButtonDisregard->isChecked()); + filterParams.setIsReady(ui->radioButtonWorking->isChecked()); + + if (priceFrom == 0.00 && priceTo == 0.00) { + filterParams.setPriceFrom(0.00); + filterParams.setPriceTo(std::numeric_limits::max()); + } else { + filterParams.setPriceFrom(priceFrom); + filterParams.setPriceTo(priceTo); + } + + updateListWidgetDevices(getSelectedIndex()); +} + +void MainWindow::pushButtonCancelFiltersClicked() +{ + clearFilters(); + updateListWidgetDevices(getSelectedIndex()); +} + +void MainWindow::pushButtonDefaultClicked() +{ + clearDevicesOutputSettings(); + updateListWidgetDevices(getSelectedIndex()); +} + +void MainWindow::closeEvent(QCloseEvent *event) +{ + ServiceLoadDB serviceLoadDB; + serviceLoadDB.updateLikesState(mapDevices); + + event->accept(); +} + diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..b5ea5c4 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,88 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +protected: + void closeEvent(QCloseEvent *event) override; + +private: + template + void fillTable(const QMap &map); + void updateListWidgetDevices(int entityId); + QWidget* createMessageEmptyCard(); + QWidget* createDeviceCard(const Project &project); + void addDeviceToList(const Project &project); + void returnToDeviceList(); + void showTableWithStructureElements(const QList& elements); + void showTableWithDeviceModelCharacteristics(const DeviceModel& model); + void clearFilters(); + void clearDevicesOutputSettings(); + int getSelectedIndex(); + + +public slots: + void getStages(QMap &map); + void getTeams(QMap &map); + void getWorkers(QMap &map); + void getDeviceTypes(QMap &map); + void getDeviceModels(QMap &map); + void getProjects(QMap &map); + +private slots: + void updateTableWidget(int index); + void updateListWidget(); + void showItemInfo(QListWidgetItem*); + void changeSortOrder(); + void pushButtonBackClicked(); + void pushButtonClearClicked(); + void pushButtonSearchClicked(); + void pushButtonApplyFiltersClicked(); + void pushButtonCancelFiltersClicked(); + void pushButtonStructureClicked(); + void pushButtonCharacteristicsClicked(); + void pushButtonDefaultClicked(); + +private: + Ui::MainWindow *ui; + ProjectLogic *logic; + + QString searchInfo = ""; + FilterParams filterParams; + + int idCard = 0; + + QMap deviceTypeImages; + + QMap mapStages; + QMap mapWorkers; + QMap mapTeams; + QMap mapDeviceTypes; + QMap mapDeviceModels; + QMap mapDevices; +}; +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..d4e9c60 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,732 @@ + + + MainWindow + + + + 0 + 0 + 1147 + 905 + + + + Factory + + + + + + 0 + 0 + 481 + 25 + + + + + 0 + 0 + + + + + Arial + 10 + + + + + + + 570 + 0 + 581 + 862 + + + + + 0 + 0 + + + + + Arial + 10 + + + + 1 + + + + + + 0 + 10 + 571 + 16 + + + + + Arial + 12 + true + + + + Проекты + + + Qt::AlignmentFlag::AlignCenter + + + + + + 0 + 80 + 571 + 461 + + + + + + + 0 + 42 + 321 + 25 + + + + + Arial + 10 + + + + + + + 0 + 560 + 451 + 25 + + + + + Arial + 10 + + + + + + + 460 + 560 + 111 + 26 + + + + + Arial + 10 + + + + Очистить + + + + + + 0 + 610 + 571 + 252 + + + + + + + + + 230 + 190 + 161 + 30 + + + + + Arial + 10 + + + + Применить фильтрацию + + + + + + 410 + 190 + 151 + 30 + + + + + Arial + 10 + + + + Отменить фильтры + + + + + + 10 + 10 + 561 + 16 + + + + + Arial + 12 + true + + + + Фильтры + + + Qt::AlignmentFlag::AlignCenter + + + + + + 10 + 40 + 751 + 16 + + + + + Arial + 10 + true + + + + Состояние + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + + + + + 10 + 110 + 751 + 16 + + + + + Arial + 10 + true + + + + Цена + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + + + + + 10 + 70 + 89 + 20 + + + + Готов + + + + + + 120 + 70 + 89 + 20 + + + + Не готов + + + + + + 40 + 150 + 151 + 22 + + + + 9999999.990000000223517 + + + + + + 240 + 150 + 151 + 22 + + + + 9999999.990000000223517 + + + + + + 10 + 150 + 21 + 16 + + + + от + + + + + + 210 + 150 + 21 + 16 + + + + до + + + + + + 230 + 70 + 141 + 20 + + + + + Arial + 10 + + + + Не учитывать + + + + + + + 410 + 40 + 161 + 30 + + + + + Arial + 11 + + + + PointingHandCursor + + + Вывод по умолчанию + + + + + + + + 0 + 10 + 571 + 16 + + + + + Arial + 12 + true + + + + Информация о проекте + + + Qt::AlignmentFlag::AlignCenter + + + + + + 140 + 50 + 431 + 22 + + + + true + + + + + + 0 + 52 + 131 + 16 + + + + + Arial + 11 + + + + Идентификатор + + + + + + 140 + 90 + 431 + 22 + + + + true + + + + + + 0 + 92 + 131 + 21 + + + + + Arial + 11 + + + + Название проекта + + + + + + 0 + 130 + 121 + 16 + + + + + Arial + 11 + + + + Стоимость + + + + + + 140 + 130 + 431 + 22 + + + + true + + + + + + 0 + 170 + 121 + 16 + + + + + Arial + 11 + + + + Отв. команда + + + + + + 140 + 170 + 431 + 22 + + + + true + + + + + + 0 + 210 + 121 + 16 + + + + + Arial + 11 + + + + Модель + + + + + + 140 + 210 + 431 + 22 + + + + true + + + + + + 0 + 250 + 121 + 16 + + + + + Arial + 11 + + + + Тип + + + + + + 140 + 250 + 431 + 22 + + + + true + + + + + + 140 + 290 + 431 + 91 + + + + true + + + + + + 0 + 300 + 121 + 51 + + + + + Arial + 11 + + + + <html><head/><body><p>Дополнительная </p><p>информация</p></body></html> + + + Qt::AlignmentFlag::AlignCenter + + + + + true + + + + 140 + 400 + 20 + 20 + + + + + + + true + + + + + + 0 + 400 + 121 + 16 + + + + + Arial + 11 + + + + Готов + + + + + + 470 + 820 + 101 + 30 + + + + Назад + + + + + + + + 0 + 40 + 481 + 821 + + + + + 0 + 0 + + + + + Arial + 10 + + + + QAbstractItemView::SelectionMode::SingleSelection + + + + + + + 0 + 0 + 1147 + 26 + + + + + + + + diff --git a/presenter.cpp b/presenter.cpp new file mode 100644 index 0000000..0689c42 --- /dev/null +++ b/presenter.cpp @@ -0,0 +1,24 @@ +#include "presenter.h" + +Presenter::Presenter(QObject *parent) + : QObject{parent} +{ + DB = new ServiceLoadDB(); + window = new MainWindow(); + window->show(); + + connect(DB, &ServiceLoadDB::sendStages, window, &MainWindow::getStages); + connect(DB, &ServiceLoadDB::sendTeams, window, &MainWindow::getTeams); + connect(DB, &ServiceLoadDB::sendWorkers, window, &MainWindow::getWorkers); + connect(DB, &ServiceLoadDB::sendDeviceTypes, window, &MainWindow::getDeviceTypes); + connect(DB, &ServiceLoadDB::sendDeviceModels, window, &MainWindow::getDeviceModels); + connect(DB, &ServiceLoadDB::sendProjects, window, &MainWindow::getProjects); + + DB->start(); +} + +Presenter::~Presenter() +{ + DB->deleteLater(); + window->deleteLater(); +} diff --git a/presenter.h b/presenter.h new file mode 100644 index 0000000..9235c94 --- /dev/null +++ b/presenter.h @@ -0,0 +1,21 @@ +#ifndef PRESENTER_H +#define PRESENTER_H + +#include + +#include "service/serviceloaddb.h" +#include "mainwindow.h" + +class Presenter : public QObject +{ + Q_OBJECT +public: + Presenter(QObject *parent = nullptr); + ~Presenter(); + +private: + ServiceLoadDB *DB; + MainWindow *window; +}; + +#endif // PRESENTER_H diff --git a/resources/images/device-type-1.png b/resources/images/device-type-1.png new file mode 100644 index 0000000..f554bca Binary files /dev/null and b/resources/images/device-type-1.png differ diff --git a/resources/images/device-type-2.png b/resources/images/device-type-2.png new file mode 100644 index 0000000..8cb6fa0 Binary files /dev/null and b/resources/images/device-type-2.png differ diff --git a/resources/images/device-type-3.png b/resources/images/device-type-3.png new file mode 100644 index 0000000..bf6115b Binary files /dev/null and b/resources/images/device-type-3.png differ diff --git a/resources/images/device-type-4.png b/resources/images/device-type-4.png new file mode 100644 index 0000000..1bb18a2 Binary files /dev/null and b/resources/images/device-type-4.png differ diff --git a/resources/images/device-type-5.png b/resources/images/device-type-5.png new file mode 100644 index 0000000..34ac3e6 Binary files /dev/null and b/resources/images/device-type-5.png differ diff --git a/resources/images/device-type-6.png b/resources/images/device-type-6.png new file mode 100644 index 0000000..c4fef45 Binary files /dev/null and b/resources/images/device-type-6.png differ diff --git a/resources/images/device-type-7.png b/resources/images/device-type-7.png new file mode 100644 index 0000000..e4e41ef Binary files /dev/null and b/resources/images/device-type-7.png differ diff --git a/resources/images/device-type-8.png b/resources/images/device-type-8.png new file mode 100644 index 0000000..2ebf3e7 Binary files /dev/null and b/resources/images/device-type-8.png differ diff --git a/resources/images/down-arrow.png b/resources/images/down-arrow.png new file mode 100644 index 0000000..e0d0bba Binary files /dev/null and b/resources/images/down-arrow.png differ diff --git a/resources/images/mw-icon.png b/resources/images/mw-icon.png new file mode 100644 index 0000000..1ddd10d Binary files /dev/null and b/resources/images/mw-icon.png differ diff --git a/resources/images/search.png b/resources/images/search.png new file mode 100644 index 0000000..7282ed7 Binary files /dev/null and b/resources/images/search.png differ diff --git a/resources/resources.qrc b/resources/resources.qrc new file mode 100644 index 0000000..3e39efd --- /dev/null +++ b/resources/resources.qrc @@ -0,0 +1,39 @@ + + + + images/mw-icon.png + + + images/search.png + + + images/down-arrow.png + + + images/device-type-1.png + + + images/device-type-2.png + + + images/device-type-3.png + + + images/device-type-4.png + + + images/device-type-5.png + + + images/device-type-6.png + + + images/device-type-7.png + + + images/device-type-8.png + + + styles.qss + + \ No newline at end of file diff --git a/resources/styles.qss b/resources/styles.qss new file mode 100644 index 0000000..1ff7186 --- /dev/null +++ b/resources/styles.qss @@ -0,0 +1,44 @@ +QComboBox, QPushButton, QLineEdit, QTextEdit, QListWidget, QTableWidget, QGroupBox { + border: 1px solid black; + border-radius: 2px; +} + +QLineEdit { + border-radius: 5px; +} + +QComboBox { + background-color: white; +} + +QComboBox::drop-down { + border: 0px; +} + +QComboBox::down-arrow { + width: 10px; + height: 10px; + image: url(:/images/down-arrow.png); +} + +QPushButton { + background-color: white; + padding: 5px; +} + +QPushButton:hover { + background-color: green; + color: white; +} + +QPushButton:pressed { + background-color: green; + border-radius: 4px; + border-width: 2px; + color: white; +} + +QPushButton#pushButtonSearch { + border: none; + background: transparent; +} \ No newline at end of file diff --git a/service/filterparams.cpp b/service/filterparams.cpp new file mode 100644 index 0000000..0e21bed --- /dev/null +++ b/service/filterparams.cpp @@ -0,0 +1,53 @@ +#include "filterparams.h" + +FilterParams::FilterParams() {} + +bool FilterParams::isReady() const +{ + return _isReady; +} + +void FilterParams::setIsReady(bool newIsReady) +{ + _isReady = newIsReady; +} + +double FilterParams::priceFrom() const +{ + return _priceFrom; +} + +void FilterParams::setPriceFrom(double newPriceFrom) +{ + _priceFrom = newPriceFrom; +} + +double FilterParams::priceTo() const +{ + return _priceTo; +} + +void FilterParams::setPriceTo(double newPriceTo) +{ + _priceTo = newPriceTo; +} + +bool FilterParams::getDisregardState() const +{ + return disregardState; +} + +void FilterParams::setDisregardState(bool newDisregardState) +{ + disregardState = newDisregardState; +} + +bool FilterParams::getApllyFilters() const +{ + return apllyFilters; +} + +void FilterParams::setApllyFilters(bool newApllyFilters) +{ + apllyFilters = newApllyFilters; +} diff --git a/service/filterparams.h b/service/filterparams.h new file mode 100644 index 0000000..8fe4995 --- /dev/null +++ b/service/filterparams.h @@ -0,0 +1,32 @@ +#ifndef FILTERPARAMS_H +#define FILTERPARAMS_H + +class FilterParams +{ +public: + FilterParams(); + + bool isReady() const; + void setIsReady(bool newIsReady); + + double priceFrom() const; + void setPriceFrom(double newPriceFrom); + + double priceTo() const; + void setPriceTo(double newPriceTo); + + bool getDisregardState() const; + void setDisregardState(bool newDisregardState); + + bool getApllyFilters() const; + void setApllyFilters(bool newApllyFilters); + +private: + bool _isReady = true; + double _priceFrom = -1; + double _priceTo = -1; + bool disregardState = false; + bool apllyFilters = false; +}; + +#endif // FILTERPARAMS_H diff --git a/service/projectlogic.cpp b/service/projectlogic.cpp new file mode 100644 index 0000000..b99f525 --- /dev/null +++ b/service/projectlogic.cpp @@ -0,0 +1,126 @@ +#include "projectlogic.h" + +ProjectLogic::ProjectLogic() {} + +QList ProjectLogic::findDevicesByAllParameters( + const QMap &projects, + int entityId, int currentEntity, + QString searchText, + const FilterParams &filterParams, + const QString &sortOrder + ) +{ + auto filteredDevices = filterByEntity(projects, entityId, currentEntity); + filteredDevices = searchDevices(filteredDevices, searchText); + filteredDevices = applyFilters(filteredDevices, filterParams); + return sortDevices(filteredDevices, sortOrder); +} + +QMap ProjectLogic::filterByEntity(const QMap &projects, int entityId, int currentEntity) +{ + QMap result; + if (entityId == -1 || currentEntity == 0) + return projects; // "Все проекты" + + for (auto &project : projects) { + switch (currentEntity) { + case 1: // Типы устройств + if (project.deviceModel().idType() == entityId) + result.insert(project.id(), project); + break; + case 2: // Команды + if (project.idTeam() == entityId) + result.insert(project.id(), project); + break; + case 3: // Работники + if (project.stages().idWorker() == entityId) + result.insert(project.id(), project); + break; + case 4: // Этапы + if (project.stages().id() == entityId) + result.insert(project.id(), project); + break; + case 5: // Модели устройств + if (project.deviceModel().id() == entityId) + result.insert(project.id(), project); + break; + default: break; + } + } + return result; +} + +QMap ProjectLogic::searchDevices(const QMap &projects, const QString &searchText) +{ + if (searchText.isEmpty()) + return projects; + + QMap result; + for (auto &project : projects) { + if (project.deviceModel().name().contains(searchText, Qt::CaseInsensitive) || + project.deviceModel().nameType().contains(searchText, Qt::CaseInsensitive)) { + result.insert(project.id(), project); + } + } + return result; +} + +QMap ProjectLogic::applyFilters(const QMap &projects, const FilterParams &filterParams) +{ + if (!filterParams.getApllyFilters()) + return projects; + QMap result; + if (filterParams.getDisregardState()) + { + for (auto &project : projects) { + if (project.budget() < filterParams.priceFrom() || project.budget() > filterParams.priceTo()) + continue; + result.insert(project.id(), project); + } + } + else + { + for (auto &project : projects) { + if (project.isReady() != filterParams.isReady()) + continue; + if (project.budget() < filterParams.priceFrom() || project.budget() > filterParams.priceTo()) + continue; + result.insert(project.id(), project); + } + } + + return result; +} + +QList ProjectLogic::sortDevices(QMap &projects, const QString &sortOrder) +{ + QList deviceList = projects.values(); + + if (sortOrder == "Сначала новые") { + std::sort(deviceList.begin(), deviceList.end(), [](const Project &a, const Project &b) { + return a.StartProjectDate() < b.StartProjectDate(); + }); + } + if (sortOrder == "Сначала старые") { + std::sort(deviceList.begin(), deviceList.end(), [](const Project &a, const Project &b) { + return a.FinishProjectDate() > b.FinishProjectDate(); + }); + } + if (sortOrder == "Сначала дешевые") { + std::sort(deviceList.begin(), deviceList.end(), [](const Project &a, const Project &b) { + return a.budget() < b.budget(); + }); + } + if (sortOrder == "Сначала дорогие") { + std::sort(deviceList.begin(), deviceList.end(), [](const Project &a, const Project &b) { + return a.budget() > b.budget(); + }); + } + if (sortOrder == "Сначала с лайком") { + std::sort(deviceList.begin(), deviceList.end(), [](const Project &a, const Project &b) { + return a.isLiked() > b.isLiked(); + }); + } + + return deviceList; +} diff --git a/service/projectlogic.h b/service/projectlogic.h new file mode 100644 index 0000000..16f1f06 --- /dev/null +++ b/service/projectlogic.h @@ -0,0 +1,27 @@ +#ifndef PROJECTLOGIC_H +#define PROJECTLOGIC_H + +#include "types.h" +#include "filterparams.h" + +class ProjectLogic +{ +public: + ProjectLogic(); + QList findDevicesByAllParameters( + const QMap &projects, + int entityId, + int currentEntity, + QString searchText, + const FilterParams &filterParams, + const QString &sortOrder + ); + +private: + QMap filterByEntity(const QMap &projects, int entityId, int currentEntity); + QMap searchDevices(const QMap &projects, const QString &searchText); + QMap applyFilters(const QMap &projects, const FilterParams &filterParams); + QList sortDevices(QMap &devices, const QString &sortOrder); +}; + +#endif // PROJECTLOGIC_H diff --git a/service/serviceloaddb.cpp b/service/serviceloaddb.cpp new file mode 100644 index 0000000..62faf55 --- /dev/null +++ b/service/serviceloaddb.cpp @@ -0,0 +1,276 @@ +#include "serviceloaddb.h" + +ServiceLoadDB::ServiceLoadDB(QObject *parent) + : QObject{parent} +{} + +void ServiceLoadDB::start() +{ + db = QSqlDatabase::addDatabase("QPSQL"); + db.setHostName("127.0.0.1"); + db.setDatabaseName("ProjectsAccountingDB"); + db.setUserName("postgres"); + db.setPassword("12345"); + if(!db.open()){ + qDebug() << "Не удалось открыть БД "; + return; + } + query = QSqlQuery(db); + + loadStages(); + loadWorkers(); + loadTeams(); + loadDeviceTypes(); + loadDeviceModels(); + loadProjects(); +} + +void ServiceLoadDB::loadStages() +{ + QFile file("../../data/requestStages.sql"); + if (!file.open(QIODevice::ReadOnly)) + return; + + db_input = QString(file.readAll()); + + if (!query.exec(db_input)) { + qDebug() << "Ошибка запроса к таблице stages: " << query.lastError().text(); + return; + } + + QSqlRecord rec; + while (query.next()) { + rec = query.record(); + + Stages stages; + int id = query.value(rec.indexOf("ID")).toInt(); + stages.setId(id); + stages.setName(query.value(rec.indexOf("Name")).toString()); + stages.setStartDate(query.value(rec.indexOf("StartDate")).toDateTime()); + stages.setFinishDate(query.value(rec.indexOf("FinishDate")).toDateTime()); + stages.setCompleted(query.value(rec.indexOf("Completed")).toBool()); + stages.setExpenses(query.value(rec.indexOf("Expenses")).toDouble()); + stages.setIdWorker(query.value(rec.indexOf("WorkerID")).toInt()); + stages.setNameWorker(query.value(rec.indexOf("worker_name")).toString()); + + mapStages.insert(stages.id(), stages); + } + + emit sendStages(mapStages); +} + +void ServiceLoadDB::loadWorkers() +{ + QFile file("../../data/requestWorkers.sql"); + if (!file.open(QIODevice::ReadOnly)) + return; + + db_input = QString(file.readAll()); + + if (!query.exec(db_input)) { + qDebug() << "Ошибка запроса к таблице Worker: " << query.lastError().text(); + return; + } + + QSqlRecord rec; + while (query.next()) { + rec = query.record(); + + Worker worker; + int id = query.value(rec.indexOf("ID")).toInt(); + worker.setId(id); + worker.setName(query.value(rec.indexOf("Name")).toString()); + worker.setExperience(query.value(rec.indexOf("Experience")).toInt()); + worker.setPhoneNumber(query.value(rec.indexOf("PhoneNumber")).toString()); + worker.setTeamName(query.value(rec.indexOf("team_name")).toString()); + + mapWorkers.insert(worker.id(), worker); + } + + emit sendWorkers(mapWorkers); +} + +void ServiceLoadDB::loadTeams() +{ + db_input = "SELECT * FROM public.Team"; + if (!query.exec(db_input)) { + qDebug() << "Ошибка запроса к таблице Team: " << query.lastError().text(); + return; + } + + QSqlRecord rec; + while (query.next()) { + rec = query.record(); + + Team team; + team.setId(query.value(rec.indexOf("ID")).toInt()); + team.setName(query.value(rec.indexOf("Name")).toString()); + team.setStatus(query.value(rec.indexOf("Status")).toBool()); + + mapTeams.insert(team.id(), team); + } + + emit sendTeams(mapTeams); +} + +void ServiceLoadDB::loadDeviceTypes() +{ + db_input = "SELECT * FROM public.DeviceType"; + if (!query.exec(db_input)) { + qDebug() << "Ошибка запроса к таблице DeviceType: " << query.lastError().text(); + return; + } + + QSqlRecord rec; + while (query.next()) { + rec = query.record(); + + DeviceType deviceType; + deviceType.setId(query.value(rec.indexOf("ID")).toInt()); + deviceType.setName(query.value(rec.indexOf("Name")).toString()); + + mapDeviceTypes.insert(deviceType.id(), deviceType); + } + + emit sendDeviceTypes(mapDeviceTypes); +} + +void ServiceLoadDB::loadDeviceModels() +{ + QFile file("../../data/requestDeviceModels.sql"); + if (!file.open(QIODevice::ReadOnly)) + return; + + db_input = QString(file.readAll()); + + if (!query.exec(db_input)) { + qDebug() << "Ошибка запроса при получении информации о моделях проектов: " << query.lastError().text(); + return; + } + + QSqlRecord rec; + while (query.next()) { + rec = query.record(); + + DeviceModel deviceModel; + int id = query.value(rec.indexOf("ID")).toInt(); + deviceModel.setId(id); + deviceModel.setName(query.value(rec.indexOf("Name")).toString()); + deviceModel.setDescription(query.value(rec.indexOf("Description")).toString()); + deviceModel.setWorkEfficiency(query.value(rec.indexOf("WorkEfficiency")).toInt()); + deviceModel.setReliability(query.value(rec.indexOf("reliability")).toInt()); + deviceModel.setDurability(query.value(rec.indexOf("durability")).toInt()); + deviceModel.setCreateDate(query.value(rec.indexOf("CreateDate")).toDateTime()); + deviceModel.setStructureElements(readStructureElements(id)); + deviceModel.setIdType(query.value(rec.indexOf("DeviceTypeID")).toInt()); + deviceModel.setNameType(query.value(rec.indexOf("device_type_name")).toString()); + + mapDeviceModels.insert(deviceModel.id(), deviceModel); + } + + emit sendDeviceModels(mapDeviceModels); +} + +void ServiceLoadDB::loadProjects() +{ + QFile file("../../data/requestProjects.sql"); + if (!file.open(QIODevice::ReadOnly)) + return; + db_input = QString(file.readAll()); + + if (!query.exec(db_input)) { + qDebug() << "Ошибка запроса при получении информации о проектах: " << query.lastError().text(); + return; + } + + QSqlRecord rec; + while (query.next()) { + rec = query.record(); + + Project project; + int id = query.value(rec.indexOf("id")).toInt(); + int idModel = query.value(rec.indexOf("ModelID")).toInt(); + if (!mapDeviceModels.contains(idModel)) { + qDebug() << "Не загружена модель проекта. Идентификатор проекта: " << id; + return; + } + + project.setId(id); + project.setName(query.value(rec.indexOf("Name")).toString()); + project.setDescription(query.value(rec.indexOf("Description")).toString()); + project.setStartProjectDate(query.value(rec.indexOf("StartProjectDate")).toDateTime()); + project.setFinishProjectDate(query.value(rec.indexOf("FinishProjectDate")).toDateTime()); + project.setBudget(query.value(rec.indexOf("Budget")).toDouble()); + project.setIsReady(query.value(rec.indexOf("isReady")).toBool()); + project.setIdTeam(query.value(rec.indexOf("TeamID")).toInt()); + project.setNameTeam(query.value(rec.indexOf("team_name")).toString()); + project.setIdStages(query.value(rec.indexOf("StagesID")).toInt()); + project.setNameStages(query.value(rec.indexOf("stages_name")).toString()); + project.setDeviceModel(mapDeviceModels[idModel]); + project.setIsLiked(query.value(rec.indexOf("isLiked")).toBool()); + + mapProjects.insert(project.id(), project); + } + + emit sendProjects(mapProjects); +} + +void ServiceLoadDB::updateLikesState(QMap &map) +{ + if (map.isEmpty()) { + qDebug() << "Нет проектов для обновления"; + return; + } + + QStringList updateQueries; + for (auto &project : map) { + int id = project.id(); + bool isLiked = project.isLiked(); + + updateQueries << QString("WHEN %1 THEN %2").arg(id).arg(isLiked ? "TRUE" : "FALSE"); + } + + QString caseQuery = updateQueries.join(" "); + + QStringList idStrings; + QList keys = map.keys(); + for (int id : keys) { + idStrings << QString::number(id); + } + + db_input = QString("UPDATE Project SET isLiked = CASE id %1 END WHERE id IN (%2)") + .arg(caseQuery, idStrings.join(", ")); + + if (!query.exec(db_input)) { + qDebug() << "Ошибка обновления состояния isLiked у проектов: " << query.lastError().text(); + } +} + +QList ServiceLoadDB::readStructureElements(int modelId) +{ + QSqlQuery secondQuery; + db_input = "SELECT * FROM get_model_structure(:model_id)"; + secondQuery.prepare(db_input); + secondQuery.bindValue(":model_id", modelId); + if (!secondQuery.exec()) { + qDebug() << "Ошибка при выполнении запроса для получения элементов структуры: " << secondQuery.lastError().text(); + return QList(); + } + + QSqlRecord rec; + QList elements; + while (secondQuery.next()) { + rec = secondQuery.record(); + + DeviceStructureElement element; + element.setId(secondQuery.value(rec.indexOf("Идентификатор элемента")).toInt()); + element.setName(secondQuery.value(rec.indexOf("Модель")).toString()); + element.setDescription(secondQuery.value(rec.indexOf("Описание элемента")).toString()); + element.setNameType(secondQuery.value(rec.indexOf("Тип элемента")).toString()); + element.setCount(secondQuery.value(rec.indexOf("Количество")).toInt()); + + elements.append(element); + } + + return elements; +} diff --git a/service/serviceloaddb.h b/service/serviceloaddb.h new file mode 100644 index 0000000..54c5c6b --- /dev/null +++ b/service/serviceloaddb.h @@ -0,0 +1,60 @@ +#ifndef SERVICELOADDB_H +#define SERVICELOADDB_H + +#include "service/types.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class ServiceLoadDB : public QObject +{ + Q_OBJECT +public: + explicit ServiceLoadDB(QObject *parent = nullptr); + void start(); + void updateLikesState(QMap &); + +private: + QList readStructureElements(int modelId); + +signals: + void sendStages(QMap &); + void sendWorkers(QMap &); + void sendTeams(QMap &); + void sendDeviceTypes(QMap &); + void sendDeviceModels(QMap &); + void sendProjects(QMap &); + +public slots: + void loadStages(); + void loadWorkers(); + void loadTeams(); + void loadDeviceTypes(); + void loadDeviceModels(); + void loadProjects(); + +private: + QSqlDatabase db; + QString db_input; + QSqlQuery query; + + QMap mapStages; + QMap mapWorkers; + QMap mapTeams; + QMap mapDeviceTypes; + QMap mapDeviceModels; + QMap mapProjects; +signals: +}; + +#endif // SERVICELOADDB_H diff --git a/service/types.cpp b/service/types.cpp new file mode 100644 index 0000000..e5f12c2 --- /dev/null +++ b/service/types.cpp @@ -0,0 +1,487 @@ +#include "types.h" + +Types::Types() {} + +Worker::Worker() {} + +int Worker::id() const +{ + return _id; +} + +void Worker::setId(int newId) +{ + _id = newId; +} + +QString Worker::name() const +{ + return _name; +} + +void Worker::setName(const QString &newName) +{ + _name = newName; +} + +int Worker::experience() const +{ + return _experience; +} + +void Worker::setExperience(int newExperience) +{ + _experience = newExperience; +} + +QString Worker::phoneNumber() const +{ + return _phoneNumber; +} + +void Worker::setPhoneNumber(const QString &newPhoneNumber) +{ + _phoneNumber = newPhoneNumber; +} + +QString Worker::teamName() const +{ + return _teamName; +} + +void Worker::setTeamName(const QString &newTeamName) +{ + _teamName = newTeamName; +} + +Team::Team() {} + +int Team::id() const +{ + return _id; +} + +void Team::setId(int newId) +{ + _id = newId; +} + +bool Team::status() const +{ + return _status; +} + +void Team::setStatus(bool newStatus) +{ + _status = newStatus; +} + +QString Team::name() const +{ + return _name; +} + +void Team::setName(const QString &newName) +{ + _name = newName; +} + +Stages::Stages() {} + +int Stages::id() const +{ + return _id; +} + +void Stages::setId(int newId) +{ + _id = newId; +} + +QString Stages::name() const +{ + return _name; +} + +void Stages::setName(const QString &newName) +{ + _name = newName; +} + +QDateTime Stages::StartDate() const +{ + return _StartDate; +} + +void Stages::setStartDate(const QDateTime &newStartDate) +{ + _StartDate = newStartDate; +} + +QDateTime Stages::FinishDate() const +{ + return _FinishDate; +} + +void Stages::setFinishDate(const QDateTime &newFinishDate) +{ + _FinishDate = newFinishDate; +} + +int Stages::expenses() const +{ + return _expenses; +} + +void Stages::setExpenses(int newExpenses) +{ + _expenses = newExpenses; +} + +QString Stages::nameWorker() const +{ + return _nameWorker; +} + +void Stages::setNameWorker(const QString &newNameWorker) +{ + _nameWorker = newNameWorker; +} + +int Stages::idWorker() const +{ + return _idWorker; +} + +void Stages::setIdWorker(int newIdWorker) +{ + _idWorker = newIdWorker; +} + +bool Stages::completed() const +{ + return _completed; +} + +void Stages::setCompleted(bool newCompleted) +{ + _completed = newCompleted; +} + +DeviceStructureElement::DeviceStructureElement() {} + +int DeviceStructureElement::id() const +{ + return _id; +} + +void DeviceStructureElement::setId(int newId) +{ + _id = newId; +} + +QString DeviceStructureElement::name() const +{ + return _name; +} + +void DeviceStructureElement::setName(const QString &newName) +{ + _name = newName; +} + +QString DeviceStructureElement::description() const +{ + return _description; +} + +void DeviceStructureElement::setDescription(const QString &newDescription) +{ + _description = newDescription; +} + +int DeviceStructureElement::count() const +{ + return _count; +} + +void DeviceStructureElement::setCount(int newCount) +{ + _count = newCount; +} + +QString DeviceStructureElement::nameType() const +{ + return _nameType; +} + +void DeviceStructureElement::setNameType(const QString &newNameType) +{ + _nameType = newNameType; +} + +DeviceModel::DeviceModel() {} + +int DeviceModel::id() const +{ + return _id; +} + +void DeviceModel::setId(int newId) +{ + _id = newId; +} + +QString DeviceModel::name() const +{ + return _name; +} + +void DeviceModel::setName(const QString &newName) +{ + _name = newName; +} + +QString DeviceModel::description() const +{ + return _description; +} + +void DeviceModel::setDescription(const QString &newDescription) +{ + _description = newDescription; +} + +int DeviceModel::workEfficiency() const +{ + return _workEfficiency; +} + +void DeviceModel::setWorkEfficiency(int newWorkEfficiency) +{ + _workEfficiency = newWorkEfficiency; +} + +int DeviceModel::reliability() const +{ + return _reliability; +} + +void DeviceModel::setReliability(int newReliability) +{ + _reliability = newReliability; +} + +int DeviceModel::durability() const +{ + return _durability; +} + +void DeviceModel::setDurability(int newDurability) +{ + _durability = newDurability; +} + +QDateTime DeviceModel::CreateDate() const +{ + return _CreateDate; +} + +void DeviceModel::setCreateDate(const QDateTime &newCreateDate) +{ + _CreateDate = newCreateDate; +} + +QList DeviceModel::structureElements() const +{ + return _structureElements; +} + +void DeviceModel::setStructureElements(const QList &newStructureElements) +{ + _structureElements = newStructureElements; +} + +int DeviceModel::idType() const +{ + return _idType; +} + +void DeviceModel::setIdType(int newIdType) +{ + _idType = newIdType; +} + +QString DeviceModel::nameType() const +{ + return _nameType; +} + +void DeviceModel::setNameType(const QString &newNameType) +{ + _nameType = newNameType; +} + +Project::Project() {} + +int Project::id() const +{ + return _id; +} + +void Project::setId(int newId) +{ + _id = newId; +} + +QString Project::description() const +{ + return _description; +} + +void Project::setDescription(const QString &newDescription) +{ + _description = newDescription; +} + +QDateTime Project::StartProjectDate() const +{ + return _StartProjectDate; +} + +void Project::setStartProjectDate(const QDateTime &newStartProjectDate) +{ + _StartProjectDate = newStartProjectDate; +} + +QDateTime Project::FinishProjectDate() const +{ + return _FinishProjectDate; +} + +void Project::setFinishProjectDate(const QDateTime &newFinishProjectDate) +{ + _FinishProjectDate = newFinishProjectDate; +} + +double Project::budget() const +{ + return _budget; +} + +void Project::setBudget(double newBudget) +{ + _budget = newBudget; +} + +int Project::idStages() const +{ + return _idStages; +} + +void Project::setIdStages(int newIdStages) +{ + _idStages = newIdStages; +} + +QString Project::nameStages() const +{ + return _nameStages; +} + +void Project::setNameStages(const QString &newNameStages) +{ + _nameStages = newNameStages; +} + +int Project::idTeam() const +{ + return _idTeam; +} + +void Project::setIdTeam(int newIdTeam) +{ + _idTeam = newIdTeam; +} + +QString Project::nameTeam() const +{ + return _nameTeam; +} + +void Project::setNameTeam(const QString &newNameTeam) +{ + _nameTeam = newNameTeam; +} + +DeviceModel Project::deviceModel() const +{ + return _deviceModel; +} + +void Project::setDeviceModel(const DeviceModel &newDeviceModel) +{ + _deviceModel = newDeviceModel; +} + +bool Project::isLiked() const +{ + return _isLiked; +} + +void Project::setIsLiked(bool newIsLiked) +{ + _isLiked = newIsLiked; +} + +bool Project::isReady() const +{ + return _isReady; +} + +void Project::setIsReady(bool newIsReady) +{ + _isReady = newIsReady; +} + +Stages Project::stages() const +{ + return _stages; +} + +void Project::setStages(const Stages &newStages) +{ + _stages = newStages; +} + +QString Project::name() const +{ + return _name; +} + +void Project::setName(const QString &newName) +{ + _name = newName; +} + +DeviceType::DeviceType() {} + +int DeviceType::id() const +{ + return _id; +} + +void DeviceType::setId(int newId) +{ + _id = newId; +} + +QString DeviceType::name() const +{ + return _name; +} + +void DeviceType::setName(const QString &newName) +{ + _name = newName; +} diff --git a/service/types.h b/service/types.h new file mode 100644 index 0000000..9e83759 --- /dev/null +++ b/service/types.h @@ -0,0 +1,257 @@ +#ifndef TYPES_H +#define TYPES_H + +#include +#include + +class Types +{ +public: + Types(); +}; + +class Worker +{ +public: + Worker(); + + int id() const; + void setId(int newId); + + QString name() const; + void setName(const QString &newName); + + int experience() const; + void setExperience(int newExperience); + + QString phoneNumber() const; + void setPhoneNumber(const QString &newPhoneNumber); + + QString teamName() const; + void setTeamName(const QString &newTeamName); + +private: + int _id = 0; + QString _name = ""; + int _experience = 0; + QString _phoneNumber = ""; + QString _teamName = ""; +}; + +class Team +{ +public: + Team(); + + int id() const; + void setId(int newId); + + bool status() const; + void setStatus(bool newStatus); + + QString name() const; + void setName(const QString &newName); + +private: + int _id = 0; + bool _status = true; + QString _name = ""; +}; + +class Stages +{ +public: + Stages(); + + int id() const; + void setId(int newId); + + QDateTime StartDate() const; + void setStartDate(const QDateTime &newStartDate); + + QDateTime FinishDate() const; + void setFinishDate(const QDateTime &newFinishDate); + + int expenses() const; + void setExpenses(int newExpenses); + + QString nameWorker() const; + void setNameWorker(const QString &newNameWorker); + + int idWorker() const; + void setIdWorker(int newIdWorker); + + QString name() const; + void setName(const QString &newName); + + bool completed() const; + void setCompleted(bool newCompleted); + +private: + int _id = 0; + QString _name = ""; + QDateTime _StartDate = QDateTime(); + QDateTime _FinishDate = QDateTime(); + bool _completed = ""; + int _expenses = 0; + int _idWorker = 0; + QString _nameWorker = ""; +}; + +class DeviceType +{ +public: + DeviceType(); + + int id() const; + void setId(int newId); + + QString name() const; + void setName(const QString &newName); + +private: + int _id = 0; + QString _name = ""; +}; + +class DeviceStructureElement +{ +public: + DeviceStructureElement(); + + int id() const; + void setId(int newId); + + QString name() const; + void setName(const QString &newName); + + QString description() const; + void setDescription(const QString &newDescription); + + int count() const; + void setCount(int newCount); + + QString nameType() const; + void setNameType(const QString &newNameType); + +private: + int _id = 0; + QString _name = ""; + QString _description = ""; + int _count = 1; + QString _nameType = ""; +}; + +class DeviceModel +{ +public: + DeviceModel(); + + int id() const; + void setId(int newId); + + QString name() const; + void setName(const QString &newName); + + QString description() const; + void setDescription(const QString &newDescription); + + int workEfficiency() const; + void setWorkEfficiency(int newWorkEfficiency); + + int reliability() const; + void setReliability(int newReliability); + + int durability() const; + void setDurability(int newDurability); + + QDateTime CreateDate() const; + void setCreateDate(const QDateTime &newCreateDate); + + QList structureElements() const; + void setStructureElements(const QList &newStructureElements); + + int idType() const; + void setIdType(int newIdType); + + QString nameType() const; + void setNameType(const QString &newNameType); + +private: + int _id = 0; + QString _name = ""; + QString _description = ""; + int _workEfficiency = 0; + int _reliability = 0; + int _durability = 0; + int _idType = 0; + QString _nameType = ""; + QDateTime _CreateDate = QDateTime(); + QList _structureElements; +}; + +class Project +{ +public: + Project(); + + int id() const; + void setId(int newId); + + QString description() const; + void setDescription(const QString &newDescription); + + QDateTime StartProjectDate() const; + void setStartProjectDate(const QDateTime &newStartProjectDate); + + QDateTime FinishProjectDate() const; + void setFinishProjectDate(const QDateTime &newFinishProjectDate); + + double budget() const; + void setBudget(double newBudget); + + int idStages() const; + void setIdStages(int newIdStages); + + QString nameStages() const; + void setNameStages(const QString &newNameStages); + + int idTeam() const; + void setIdTeam(int newIdTeam); + + QString nameTeam() const; + void setNameTeam(const QString &newNameTeam); + + DeviceModel deviceModel() const; + void setDeviceModel(const DeviceModel &newDeviceModel); + + bool isLiked() const; + void setIsLiked(bool newIsLiked); + + bool isReady() const; + void setIsReady(bool newIsReady); + + Stages stages() const; + void setStages(const Stages &newStages); + + QString name() const; + void setName(const QString &newName); + +private: + int _id = 0; + QString _description = ""; + QDateTime _StartProjectDate = QDateTime(); + QDateTime _FinishProjectDate = QDateTime(); + double _budget = 1; + int _idStages = 0; + QString _nameStages = ""; + int _idTeam = 0; + QString _nameTeam = ""; + DeviceModel _deviceModel; + Stages _stages; + bool _isLiked = false; + bool _isReady = true; + QString _name = ""; +}; + +#endif // TYPES_H