-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_to_cart.cpp
155 lines (140 loc) · 5.37 KB
/
add_to_cart.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
145
146
147
148
149
150
151
152
153
154
#include "add_to_cart.h"
#include "ui_add_to_cart.h"
#include<QMovie>
#include "Global.h"
#include "QMessageBox"
#include "client.h"
#include "admin.h"
add_to_cart::add_to_cart(QWidget *parent) :
QDialog(parent),
ui(new Ui::add_to_cart),
id{0}
{
ui->setupUi(this);
this->setFixedSize(1241,688);
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
QMovie* movie=new QMovie(":/new/prefix1/iranserver.gif");
QMovie* movie1=new QMovie(":/new/prefix1/XXwt.gif");
ui->label_8->setMovie(movie);
ui->label_9->setMovie(movie1);
movie1->start();
movie->start();
ui->pushButton_4->hide();
}
add_to_cart::~add_to_cart()
{
delete ui;
}
void add_to_cart::set(int id)
{
this->id=id;
ui->pushButton->show();
ui->pushButton_2->show();
if(Global::serch_id_cloths(id)!=-1)
{
int index=Global::serch_id_cloths(id);
ui->label_name->setText(Global::vec_article_cloths[index].get_name());
ui->label_price->setText(QString::number(Global::vec_article_cloths[index].get_price()));
ui->label_seller->setText(Global::vec_article_cloths[index].get_seller_username());
ui->label_weight->setText(QString::number(Global::vec_article_cloths[index].get_weight()));
ui->label_type->setText("cloths");
ui->label_coler->setText(Global::vec_article_cloths[index].get_color());
ui->label_brand->setText(Global::vec_article_cloths[index].get_brand_name());
ui->label_other->setText(Global::vec_article_cloths[index].get_gender());
QString file=Global::vec_article_cloths[index].get_image_file();
QString x="QWidget {background-image: url("+file+") ;}";
ui->widget->setStyleSheet(x);
ui->spinBox->setMaximum(Global::vec_article_cloths[index].get_stock());
}
else if(Global::serch_id_sporting_goods(id)!=-1)
{
int index=Global::serch_id_sporting_goods(id);
ui->label_name->setText(Global::vec_article_sporting_goods[index].get_name());
ui->label_price->setText(QString::number(Global::vec_article_sporting_goods[index].get_price()));
ui->label_seller->setText(Global::vec_article_sporting_goods[index].get_seller_username());
ui->label_weight->setText(QString::number(Global::vec_article_sporting_goods[index].get_weight()));
ui->label_type->setText("sporting_goods");
ui->label_coler->setText(Global::vec_article_sporting_goods[index].get_color());
ui->label_brand->setText(Global::vec_article_sporting_goods[index].get_brand_name());
ui->label_other->setText(Global::vec_article_sporting_goods[index].get_material());
QString file=Global::vec_article_sporting_goods[index].get_image_file();
QString x="QWidget {background-image: url("+file+") ;}";
ui->widget->setStyleSheet(x);
ui->spinBox->setMaximum(Global::vec_article_sporting_goods[index].get_stock());
}
}
void add_to_cart::admin()
{
ui->pushButton_4->show();
ui->pushButton->hide();
ui->pushButton_2->hide();
ui->spinBox->hide();
}
void add_to_cart::on_pushButton_clicked()
{
Global::load_all();
if(Global::serch_id_cloths(id)!=-1&&(Global::vec_article_cloths[Global::serch_id_cloths(id)].get_stock()<ui->spinBox->value()))
{
QMessageBox *x=new QMessageBox;
x->setText("not in stock");
x->exec();
}
else if(Global::serch_id_sporting_goods(id)!=-1 && (Global::vec_article_sporting_goods[Global::serch_id_sporting_goods(id)].get_stock()<ui->spinBox->value()))
{
QMessageBox *x=new QMessageBox;
x->setText("not in stock");
x->exec();
}
else if(Global::serch_id_cloths(id)!=-1)
{
Global::Shopping_cart[index_vector].push_back(qMakePair(id , ui->spinBox->value()));
Global::vec_article_cloths[Global::serch_id_cloths(id)].set_stock(Global::vec_article_cloths[Global::serch_id_cloths(id)].get_stock()-ui->spinBox->value());
QMessageBox *x=new QMessageBox;
x->setText("added");
x->exec();
}
else if(Global::serch_id_sporting_goods(id)!=-1)
{
Global::Shopping_cart[index_vector].push_back(qMakePair(id , ui->spinBox->value()));
Global::vec_article_sporting_goods[Global::serch_id_sporting_goods(id)].set_stock(Global::vec_article_sporting_goods[Global::serch_id_sporting_goods(id)].get_stock()-ui->spinBox->value());
QMessageBox *x=new QMessageBox;
x->setText("added");
x->exec();
}
Global::save_all();
std::string x;
x="save_"+Global::Active_person[index_vector].get_user_name().toStdString()+".txt";
std::fstream out(x , std::ios::out);
for (int i=0;i<Global::Shopping_cart[index_vector].size() ; i++)
{
out<<Global::Shopping_cart[index_vector][i].first<<"\n"
<<Global::Shopping_cart[index_vector][i].second<<"\n";
}
out.close();
this->close();
Client *y= new Client(index_vector);
y->setIndex_vector(index_vector);
y->show();
}
void add_to_cart::on_pushButton_2_clicked()
{
this->close();
Client *y= new Client(index_vector);
y->setIndex_vector(index_vector);
y->show();
}
void add_to_cart::on_pushButton_4_clicked()
{
Admin *x=new Admin(index_vector);
x->show();
x->setIndex_vector(index_vector);
this->close();
}
int add_to_cart::getIndex_vector() const
{
return index_vector;
}
void add_to_cart::setIndex_vector(int newIndex_vector)
{
index_vector = newIndex_vector;
}