-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdialogbrand.cpp
More file actions
108 lines (81 loc) · 2.44 KB
/
Copy pathdialogbrand.cpp
File metadata and controls
108 lines (81 loc) · 2.44 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "dialogbrand.h"
#include "ui_dialogbrand.h"
DialogBrand::DialogBrand(QSqlDatabase &db, QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogBrand)
{
ui->setupUi(this);
addBrand = new DialogAddBrand(db);
query = new QSqlQuery(db);
}
DialogBrand::~DialogBrand()
{
delete ui;
delete query;
delete addBrand;
}
void DialogBrand::showBrands() const
{
ui->tableWidget_Brand->setRowCount(0);
query->exec("SELECT * FROM Brand");
int i = 0;
while(query->next())
{
QString name = query->value(0).toString();
QString info = query->value(1).toString();
ui->tableWidget_Brand->setRowCount(i + 1);
QTableWidgetItem* Name = new QTableWidgetItem();
QTableWidgetItem* Info = new QTableWidgetItem();
Name->setText(name);
Info->setText(info);
ui->tableWidget_Brand->setItem(i, 0, Name);
ui->tableWidget_Brand->setItem(i, 1, Info);
i++;
}
}
void DialogBrand::on_pushButton_add_clicked()
{
addBrand->show();
this->close();
}
void DialogBrand::on_pushButton_sort_clicked()
{
ui->tableWidget_Brand->setRowCount(0);
query->exec("SELECT * FROM Brand ORDER BY Name ASC");
int i = 0;
while(query->next())
{
QString name = query->value(0).toString();
QString info = query->value(1).toString();
ui->tableWidget_Brand->setRowCount(i + 1);
QTableWidgetItem* Name = new QTableWidgetItem();
QTableWidgetItem* Info = new QTableWidgetItem();
Name->setText(name);
Info->setText(info);
ui->tableWidget_Brand->setItem(i, 0, Name);
ui->tableWidget_Brand->setItem(i, 1, Info);
i++;
}
}
void DialogBrand::on_pushButton_search_clicked()
{
ui->tableWidget_Brand->setRowCount(0);
QString n = ui->lineEdit_name->text();
query->prepare("SELECT * FROM Brand WHERE UPPER(Name) like :n");
query->bindValue(":n", "%" + n.toUpper() + "%");
query->exec();
int i = 0;
while(query->next())
{
QString name = query->value(0).toString();
QString info = query->value(1).toString();
ui->tableWidget_Brand->setRowCount(i + 1);
QTableWidgetItem* Name = new QTableWidgetItem();
QTableWidgetItem* Info = new QTableWidgetItem();
Name->setText(name);
Info->setText(info);
ui->tableWidget_Brand->setItem(i, 0, Name);
ui->tableWidget_Brand->setItem(i, 1, Info);
i++;
}
}