-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdialogaddcar.cpp
More file actions
58 lines (49 loc) · 1.43 KB
/
Copy pathdialogaddcar.cpp
File metadata and controls
58 lines (49 loc) · 1.43 KB
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
#include "dialogaddcar.h"
#include "ui_dialogaddcar.h"
DialogAddCar::DialogAddCar(QSqlDatabase &db, QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogAddCar)
{
ui->setupUi(this);
query = new QSqlQuery(db);
query->exec("SELECT Model FROM Model");
while(query->next())
{
ui->comboBox_model->addItem(query->value(0).toString());
}
query->clear();
query->exec("SELECT Name FROM Brand");
while(query->next())
{
ui->comboBox_brand->addItem(query->value(0).toString());
}
query->clear();
query->exec("SELECT Phone_number, First_name + ' ' + Middle_name + ' ' + Last_name FROM Manager");
while(query->next())
{
ui->comboBox_manager->addItem(query->value(1).toString(), query->value(0));
}
}
DialogAddCar::~DialogAddCar()
{
delete ui;
delete query;
}
void DialogAddCar::on_pushButton_add_clicked()
{
QString model = ui->comboBox_model->currentText();
QString brand = ui->comboBox_brand->currentText();
QString year = ui->spinBox_year->text();
QString manager = ui->comboBox_manager->currentData().toString();
query->clear();
query->prepare("EXEC addCar :m, :n, :y, :b");
query->bindValue(":m", model);
query->bindValue(":n", manager);
query->bindValue(":y", year);
query->bindValue(":b", brand);
if(query->exec())
{
qDebug() << "Машина успешно добавлена.";
}
this->close();
}