-
Notifications
You must be signed in to change notification settings - Fork 0
/
selleredit.cpp
87 lines (77 loc) · 3.1 KB
/
selleredit.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
#include "selleredit.h"
#include "ui_selleredit.h"
#include <QMessageBox>
SellerEdit::SellerEdit(QWidget *parent) :
QDialog(parent),
ui(new Ui::SellerEdit)
{
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);
}
SellerEdit::~SellerEdit()
{
delete ui;
}
void SellerEdit::on_pushButton_clicked()
{
ui->treeWidget->clear();
//ui->added->setText(supermarketobject.customers[supermarketobject.loggedInIndex].customer_cart.cart_items[0].getName());
ui->treeWidget->setColumnCount(4);
QStringList lables;
lables << "Product Name" << "Product Quantity" << "Product Price" << "Product Category";
ui->treeWidget->setHeaderLabels(lables);
for (int i=0 ; i<this->supermarketobject.products.size(); i++) {
if (supermarketobject.products[i].getSellerId() == supermarketobject.sellers[supermarketobject.loggedInIndex].getId()) {
QTreeWidgetItem *root = new QTreeWidgetItem(ui->treeWidget);
root->setText(0 , this->supermarketobject.products[i].getName());
root->setText(1 , this->supermarketobject.products[i].getQuantity());
root->setText(2 , this->supermarketobject.products[i].getPrice());
root->setText(3 , this->supermarketobject.products[i].getCategory());
}
}
}
void SellerEdit::on_pushButton_2_clicked()
{
if(supermarketobject.customers.empty())
{
supermarketobject.readFromFileIntoCustomer();
supermarketobject.readFromFileIntoSeller();
supermarketobject.readFromFileIntoProduct();
supermarketobject.readFromFileIntoCustomerCart();
supermarketobject.readindexfromfileintovariable();
}
QString productname = ui->lineEdit->text();
QString productquantity = ui->lineEdit_2->text();
bool flag = false;
bool ok;
int index;
for (int i=0 ; i<this->supermarketobject.products.size(); i++) {
if (supermarketobject.products[i].getName() == productname) {
flag = true;
index = i;
break;
}
}
if (flag) {
if (supermarketobject.products[index].getSellerId() == supermarketobject.sellers[supermarketobject.loggedInIndex].getId()) {
int gettquann = supermarketobject.products[index].getQuantity().toInt(&ok);
int editedquann = productquantity.toInt(&ok);
int sum = gettquann + editedquann;
QString newquan = QString::number(sum);
supermarketobject.products[index].setQuantity(newquan);
QMessageBox::information(this , "Edit" , "Product Quantity Increased by"" "+productquantity+" "+"And Become"+newquan);
//supermarketobject.writeAllFiles();
}
else {
QMessageBox::warning(this , "Edit" , "Not Your Product");
}
}
else {
QMessageBox::warning(this , "Edit" , "Not Found");
}
}