From e7a26bfcea1c7c21ba5996e21d21feba84ee686c Mon Sep 17 00:00:00 2001 From: Yuri Maximov Date: Wed, 3 Apr 2024 15:24:09 +0300 Subject: [PATCH] =?UTF-8?q?=20=D0=BF=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deleteticketdialog.cpp | 29 +++++++++++++++++++++++++++++ deleteticketdialog.h | 12 ++++++++++++ filmratingdialog.cpp | 12 ++++++++++++ filmratingdialog.h | 3 +++ 4 files changed, 56 insertions(+) diff --git a/deleteticketdialog.cpp b/deleteticketdialog.cpp index e4fd282..7c8330d 100644 --- a/deleteticketdialog.cpp +++ b/deleteticketdialog.cpp @@ -8,9 +8,38 @@ deleteTicketDialog::deleteTicketDialog(QWidget *parent) : ui->setupUi(this); this->show(); + if (!m_db.open()) qDebug()<<"Error: DB not connectred"; + else qDebug()<<"DB connected succesfully"; + m_query = new QSqlQuery(m_db); + tableView(); + connect(ui->tableView, &QTableView::clicked, this, &deleteTicketDialog::update_tableView); + } deleteTicketDialog::~deleteTicketDialog() { delete ui; } + +void deleteTicketDialog::tableView() +{ + QSqlQueryModel* result_model = new QSqlQueryModel(this); + m_query->exec("SELECT ticket_id, row AS \"ряд\", seat AS \"место\", session_id AS \"номер сеанса\", customer AS \"покупатель\", purchase_date AS \"время покупки\" FROM Tickets;"); + result_model->setQuery(*m_query); + ui->tableView->setModel(result_model); +} + +void deleteTicketDialog::update_tableView(const QModelIndex &index) +{ + row = index.row(); +} + +void deleteTicketDialog::on_pushButton_clicked() +{ + qDebug() << row; + m_query->prepare("DELETE FROM Tickets WHERE ticket_id = :ticket_id;"); + m_query->bindValue(":ticket_id", row); + + tableView(); +} + diff --git a/deleteticketdialog.h b/deleteticketdialog.h index 9ab8e64..236490d 100644 --- a/deleteticketdialog.h +++ b/deleteticketdialog.h @@ -18,9 +18,21 @@ public: ~deleteTicketDialog(); QSqlDatabase m_db; + int row; + +private slots: + + + void update_tableView(const QModelIndex &index); + + void on_pushButton_clicked(); private: + Ui::deleteTicketDialog *ui; + QSqlTableModel *m_table_model ; + QSqlQuery *m_query ; + void tableView(); }; #endif // DELETETICKETDIALOG_H diff --git a/filmratingdialog.cpp b/filmratingdialog.cpp index 34682f1..3916b82 100644 --- a/filmratingdialog.cpp +++ b/filmratingdialog.cpp @@ -8,9 +8,21 @@ filmRatingDialog::filmRatingDialog(QWidget *parent) : ui->setupUi(this); this->show(); + if (!m_db.open()) qDebug()<<"Error: DB not connectred"; + else qDebug()<<"DB connected succesfully"; + m_query = new QSqlQuery(m_db); + tableView(); } filmRatingDialog::~filmRatingDialog() { delete ui; } + +void filmRatingDialog::tableView() +{ + QSqlQueryModel* result_model = new QSqlQueryModel(this); + m_query->exec("SELECT title, director, duration, year, Rating FROM films;"); + result_model->setQuery(*m_query); + ui->tableView->setModel(result_model); +} diff --git a/filmratingdialog.h b/filmratingdialog.h index 40aa653..52bb45e 100644 --- a/filmratingdialog.h +++ b/filmratingdialog.h @@ -22,6 +22,9 @@ public: private: Ui::filmRatingDialog *ui; + QSqlTableModel *m_table_model ; + QSqlQuery *m_query ; + void tableView(); }; #endif // FILMRATINGDIALOG_H -- GitLab