QSqlQuery query;query.prepare("SELECT kt_text FROM kt WHERE id_kt=:id ");query.bindValue(":id", ?); <- Вот сюдаquery.exec();query.first();
switch (wins) { case 1: { model->setQuery("SELECT tp_text, id_tp FROM tp"); break; } case 2: { model->setQuery("SELECT kt_text, id_kt FROM kt"); break; } case 3: { model->setQuery("SELECT year, id_hour FROM hours"); break; } } QListView * view = ui->listView; view->setModel(model); view->setModelColumn(0);
C++ (Qt)class MyDialog : public QDialog {.............. QString id () const { return id_; } void setId (const QString& id) { id_ = id; }.................private: QString id_;//This is your id...................};
C++ (Qt)....................MyDialog d;if (d.exec ()) { const QString& id = d.id ();}...................
C++ (Qt)....................MyDialog d;d.setId (id);d.exec ();................}
C++ (Qt)#include "dots.h"#include "ui_dots.h" Dots::Dots(QWidget *parent) : QDialog(parent), ui(new Ui::Dots){ ui->setupUi(this); QTimer::singleShot (0, this, SLOT(slotStarted()));} Dots::~Dots(){ delete ui;} void Dots::on_pushButton_clicked(){ switch (wins) { case 1: { DotsEdit *dotsedit = new DotsEdit(this); dotsedit->setModal(true); dotsedit->setWindowTitle(trUtf8("Новая точка продаж")); dotsedit->exec(); break; } case 2: { Peoples *people = new Peoples(this); people->setModal(true); people->setWindowTitle(trUtf8("Новый консультант")); people->exec(); break; } case 3: { WorkTime *worktime = new WorkTime(this); worktime->setModal(true); worktime->setWindowTitle(trUtf8("Новый календарь")); worktime->exec(); break; } }} void Dots::on_pushButton_2_clicked(){ //Редактирование int row = ui->listView->currentIndex().row(); if (row > -1 ) { switch (wins) { case 1: { DotsEdit *dotsedit = new DotsEdit(this); dotsedit->setModal(true); dotsedit->setWindowTitle(trUtf8("Редактирование точки продаж")); dotsedit->exec(); break; } case 2: { Peoples *people = new Peoples(this); people->setModal(true); people->setWindowTitle(trUtf8("Редактирование консультанта")); people->exec(); break; } case 3: { WorkTime *worktime = new WorkTime(this); worktime->setModal(true); worktime->setWindowTitle(trUtf8("Редактирование календаря")); worktime->exec(); break; } } }} void Dots::on_pushButton_3_clicked(){ // delete} void Dots::slotStarted(){ QSqlQueryModel * model = new QSqlQueryModel(0); if (windowTitle().toUtf8() == "Список точек продаж") wins = 1; if (windowTitle().toUtf8() == "Список консультантов") wins = 2; if (windowTitle().toUtf8() == "Список рабочих часов") wins = 3; if (windowTitle().toUtf8() == "Список графиков") wins = 4; switch (wins) { case 1: { model->setQuery("SELECT tp_text, id_tp FROM tp"); break; } case 2: { model->setQuery("SELECT kt_text, id_kt FROM kt"); break; } case 3: { model->setQuery("SELECT year, id_hour FROM hours"); break; } } QListView * view = ui->listView; view->setModel(model); view->setModelColumn(0);}
C++ (Qt)#include "peoples.h"#include "ui_peoples.h" Peoples::Peoples(QWidget *parent) : QDialog(parent), ui(new Ui::Peoples){ ui->setupUi(this); QTimer::singleShot (0, this, SLOT(slotStarted()));} Peoples::~Peoples(){ delete ui;} void Peoples::on_pushButton_2_clicked(){ close();} void Peoples::slotStarted(){ if (windowTitle().toUtf8() == "Новый консультант") wins = 1; if (windowTitle().toUtf8() == "Редактирование консультанта") wins = 2; QDate date; switch (wins) { case 1: { date = QDate::currentDate(); ui->dateEdit->setDate(date); ui->dateEdit_2->setDate(date); break; } case 2: { QSqlQuery query; query.prepare("SELECT kt_text FROM kt WHERE id_kt=:id "); query.bindValue(":id",1); query.exec(); query.first(); ui->lineEdit->setText(query.value(0).toString()); query.prepare("SELECT begin, end FROM kt_time WHERE id_kt=:id "); query.bindValue(":id", 1); query.exec(); query.first(); QString dt; dt= query.value(0).toString(); date = QDate::fromString(dt,"dd.MM.yyyy"); ui->dateEdit->setDate(date); dt = query.value(1).toString(); date = QDate::fromString(dt,"dd.MM.yyyy"); ui->dateEdit_2->setDate(date); break; } }}
query.bindValue(":id", 1);
C++ (Qt)#ifndef PEOPLES_H#define PEOPLES_H #include <QDialog>#include <QTimer>#include <QSqlQuery>#include "dots.h" namespace Ui { class Peoples;} class Peoples : public QDialog{ Q_OBJECT public: explicit Peoples(QWidget *parent = 0, const int &id_rec=0, const int &id_id=0); ~Peoples(); private slots: void on_pushButton_2_clicked(); private: Ui::Peoples *ui; int wins; int id;}; #endif // PEOPLES_H
C++ (Qt)#include "peoples.h"#include "ui_peoples.h" Peoples::Peoples(QWidget *parent, const int &id_rec, const int &id_id) : QDialog(parent), ui(new Ui::Peoples){ ui->setupUi(this); wins = id_rec; id = id_id; QDate date; switch (wins) { case 1: { date = QDate::currentDate(); ui->dateEdit->setDate(date); ui->dateEdit_2->setDate(date); break; } case 2: { QSqlQuery query; query.prepare("SELECT kt_text FROM kt WHERE id_kt=:id "); query.bindValue(":id",1); query.exec(); query.first(); ui->lineEdit->setText(query.value(0).toString()); query.prepare("SELECT begin, end FROM kt_time WHERE id_kt=:id "); query.bindValue(":id", 1); query.exec(); query.first(); QString dt; dt= query.value(0).toString(); date = QDate::fromString(dt,"dd.MM.yyyy"); ui->dateEdit->setDate(date); dt = query.value(1).toString(); date = QDate::fromString(dt,"dd.MM.yyyy"); ui->dateEdit_2->setDate(date); break; } }} Peoples::~Peoples(){ delete ui;} void Peoples::on_pushButton_2_clicked(){ close();}
C++ (Qt)void Dots::on_pushButton_2_clicked(){ //Редактирование int row = ui->listView->currentIndex().row(); if (row > -1 ) { switch (wins) { case 1: { DotsEdit *dotsedit = new DotsEdit(this,1,wins); dotsedit->setModal(true); dotsedit->setWindowTitle(trUtf8("Редактирование точки продаж")); dotsedit->exec(); break; } case 2: { Peoples *people = new Peoples(this,1,wins); people->setModal(true); people->setWindowTitle(trUtf8("Редактирование консультанта")); people->exec(); break; } case 3: { WorkTime *worktime = new WorkTime(this,1,wins); worktime->setModal(true); worktime->setWindowTitle(trUtf8("Редактирование календаря")); worktime->exec(); break; } } }}