-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch.cpp
More file actions
173 lines (159 loc) · 6.09 KB
/
Search.cpp
File metadata and controls
173 lines (159 loc) · 6.09 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "Search.h"
#include "recipet.h"
#include "ui_search.h"
#include <CustomerMenu.h>
#include <vector>
#include <QString>
#include "SuperMarket.h"
#include <QTreeWidget>
#include <QMessageBox>
Search::Search(QWidget *parent) :
QDialog(parent),
ui(new Ui::Search)
{
ui->setupUi(this);
supermarketobject.readAllFiles();
QPixmap bkgnd("D:/qt/login.jpg");
bkgnd = bkgnd.scaled(this->size(), Qt::IgnoreAspectRatio);
QPalette palette;
palette.setBrush(QPalette::Background, bkgnd);
this->setPalette(palette);
}
Search::~Search()
{
delete ui;
}
void Search::on_pushButton_clicked()
{
ui->comboBox->clear();
//search
QString searchname;
QString results ;
bool flag = false;
searchname = ui->searching->text();
if(ui->radioButton->isChecked())
{
for(int i = 0 ; i < supermarketobject.products.size() ; i++)
{
if(supermarketobject.products[i].getCategory() == searchname)
{
flag = true;
results += supermarketobject.products[i].getName() + " ";
ui->comboBox->addItem(results);
results.clear();
}
}
if(flag){
QMessageBox::information(this , "Searching" , searchname+"""Added To combo box");
}
else if(!flag) {
QMessageBox::critical(this, "Searching" , searchname+"""Not Exist At SuperMarket");
}
}
else if(ui->radioButton_2->isChecked())
{
for(int i = 0 ; i < supermarketobject.products.size() ; i++)
{
if(supermarketobject.products[i].getName() == searchname)
{
flag = true;
results += supermarketobject.products[i].getName();
ui->comboBox->addItem(results);
results.clear();
}
}
if(flag){
QMessageBox::information(this , "Searching" , searchname+"""Added To combo box");
}
else if(!flag) {
QMessageBox::critical(this, "Searching" , searchname+"""Not Exist At SuperMarket");
}
}
}
void Search::on_pushButton_2_clicked()
{
//add
//add product
QString name;
QString quantity;
name = ui->addproduct->text();
quantity = ui->addquantity->text();
bool flag = true;
bool ok;
int quan = quantity.toInt(&ok);
// enter name and quantity of product
// if name found then check the quantity and compare them
// if current quantity is less than product real quantity(can add) :
//
for(int i = 0 ; i < supermarketobject.products.size() ; i++)
{
int getquan = supermarketobject.products[i].getQuantity().toInt(&ok);
int userquan;
int index;
if(supermarketobject.products[i].getName() == name)
{
if (quan <= getquan) {
for(int j = 0 ; j < supermarketobject.customers[supermarketobject.loggedInIndex].customer_cart.cart_items.size() ; j++)
{
if(supermarketobject.customers[supermarketobject.loggedInIndex].customer_cart.cart_items[j].getName() == name)
{
flag = false;
bool ok;
int nn = supermarketobject.customers[supermarketobject.loggedInIndex].customer_cart.cart_items[j].getQuantity().toInt(&ok);
userquan = nn;
index = j;
break;
}
}
}
else {
QMessageBox::information(this, "title" , "Over Available Amount");
break;
}
if(flag)
{
// product[i].getQuantity in an int and current input quantity in another int
// then int = productquantity - inputquantity then convert to QString again
// then product[i].setQuantity(result)
int sum = getquan - quan;
QString result = QString::number(sum);
supermarketobject.products[i].setQuantity(result);
this->supermarketobject.customers[supermarketobject.loggedInIndex].customer_cart.cart_items.push_back(supermarketobject.products[i]);
supermarketobject.customers[supermarketobject.loggedInIndex].customer_cart.cart_items.back().setQuantity(quantity);
QMessageBox::information(this, "title" , "Product" " "+name+"quantity" " "+quantity + " has added to your cart .");
}
else
{
QMessageBox::information(this , "title" , "quantity increased by " " " + quantity);
userquan += quan;
QString quanuser = QString::number(userquan);
supermarketobject.customers[supermarketobject.loggedInIndex].customer_cart.cart_items[index].setQuantity(quanuser);
int sum = getquan - quan;
QString result = QString::number(sum);
supermarketobject.products[i].setQuantity(result);
}
break;
}
}
supermarketobject.writeToFileFromCustomer();
supermarketobject.writeToFileFromSeller();
supermarketobject.writeToFileFromProduct();
supermarketobject.writeToFileFromCustomerCart();
supermarketobject.writeindextofilefromvariable();
}
void Search::on_pushButton_4_clicked()
{
this->hide();
Recipet recipet;
recipet.setModal(true);
recipet.setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint);
recipet.exec();
}
void Search::on_pushButton_3_clicked()
{
this->hide();
CustomerMenu cusmenu;
cusmenu.setModal(true);
cusmenu.setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint);
cusmenu.exec();
}