diff --git a/deleteticketdialog.cpp b/deleteticketdialog.cpp index e4fd282f2e41b478e5179ad4ea0a0965964c5503..7c8330d8766a53cd4b4e90f69b26ab0cebd65f96 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 9ab8e642dbd86c5af7397a87365ec57601159109..236490d2af9e414ee9b51793c410def502a3076c 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 34682f1833f78b3711ca89ffd98f9dee476653c2..3916b8232a7512484cc6c5b1d910008b78c1473e 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 40aa6535caab1b034ab1b5b3a997408e114b6937..52bb45e6dd254185431dc8acda7adab38f7d506c 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