-
Notifications
You must be signed in to change notification settings - Fork 0
/
customerpanel.cpp
144 lines (105 loc) · 4.32 KB
/
customerpanel.cpp
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "customerpanel.h"
#include "ui_customerpanel.h"
#include "user.h"
#include "mainwindow.h"
#include <QSettings>
#include "buy.h"
#include "pay.h"
#include "addproduct.h"
#include "showproductcustomer.h"
#include <QDesktopWidget>
customerPanel::customerPanel(QWidget *parent) :
QWidget(parent),
ui(new Ui::customerPanel)
{
ui->setupUi(this);
QSettings settings("c:/windows/winf32.ini", QSettings::IniFormat);
customerPanel::username = settings.value("username").toString();
ui->customerLabel->setText(settings.value("name").toString() + " عزیز ! خوش آمدید");
qint64 allBay = buy::getTotalBuyForCustomer(username);
qint64 allPay = pay::getTotoalPayForCustomer(username);
ui->buyLabel->setText(QString::number(allBay));
ui->payLabel->setText(QString::number(allPay));
fillTables();
}
customerPanel::~customerPanel()
{
delete ui;
}
void customerPanel::fillTables(){
ui->buyTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
QJsonArray buy = buy::getBuyForCustomer(username);
ui->buyTable->setRowCount(buy.size());
ui->buyTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
for (int i = 0; i < buy.size(); i++) {
QTableWidgetItem *item1 = new QTableWidgetItem();
QTableWidgetItem *item2 = new QTableWidgetItem();
QTableWidgetItem *item3 = new QTableWidgetItem();
QTableWidgetItem *item4 = new QTableWidgetItem();
QTableWidgetItem *item5 = new QTableWidgetItem();
QTableWidgetItem *item6 = new QTableWidgetItem();
ui->buyTable->setItem(i,0,item1);
item1->setText(QString::number(buy.at(i)["id"].toInt()));
item1->setTextAlignment(Qt::AlignCenter);
ui->buyTable->setItem(i,1,item2);
item2->setText(buy.at(i)["date"].toString());
item2->setTextAlignment(Qt::AlignCenter);
ui->buyTable->setItem(i,2,item3);
item3->setText(buy.at(i)["product_name"].toString());
item3->setTextAlignment(Qt::AlignCenter);
ui->buyTable->setItem(i,3,item4);
item4->setText(QString::number(buy.at(i)["count"].toInt()) + "*");
item4->setTextAlignment(Qt::AlignCenter);
ui->buyTable->setItem(i,4,item5);
item5->setText(QString::number(buy.at(i)["price"].toInt()));
item5->setTextAlignment(Qt::AlignCenter);
ui->buyTable->setItem(i,5,item6);
item6->setText(buy.at(i)["buyer"].toString());
item6->setTextAlignment(Qt::AlignCenter);
}
ui->payTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
QJsonArray pay = pay::getPayForCustomer(username);
ui->payTable->setRowCount(pay.size());
ui->payTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
for (int i = 0; i < pay.size(); i++) {
QTableWidgetItem *item1 = new QTableWidgetItem();
QTableWidgetItem *item2 = new QTableWidgetItem();
QTableWidgetItem *item3 = new QTableWidgetItem();
ui->payTable->setItem(i,0,item1);
item1->setText(QString::number(pay.at(i)["id"].toInt()));
item1->setTextAlignment(Qt::AlignCenter);
ui->payTable->setItem(i,1,item2);
item2->setText(pay.at(i)["date"].toString());
item2->setTextAlignment(Qt::AlignCenter);
ui->payTable->setItem(i,2,item3);
item3->setText(QString::number(pay.at(i)["amount"].toInt()));
item3->setTextAlignment(Qt::AlignCenter);
item3->setTextColor(QColor("green"));
}
}
void customerPanel::on_logoutBtn_clicked()
{
user::logout();
this->close();
MainWindow *m = new MainWindow();
m->setWindowTitle(" ");
m->setWindowIcon(QIcon(":/images/icon"));
m->show();
}
void customerPanel::on_showProductBtn_clicked()
{
showproductcustomer *show = new showproductcustomer();
show->setFixedSize(show->width(),show->height());
show->showMaximized();
show->setWindowTitle(" ");
show->setWindowIcon(QIcon(":/images/icon"));
show->show();
}
void customerPanel::on_addProductBtn_clicked()
{
addProduct *add = new addProduct();
add->setWindowTitle(" ");
add->setWindowIcon(QIcon(":/images/icon"));
add->setFixedSize(add->width(),add->height());
add->show();
}