-
Notifications
You must be signed in to change notification settings - Fork 0
/
SellerMenu.cpp
105 lines (91 loc) · 3.13 KB
/
SellerMenu.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
#include "SellerMenu.h"
#include "LoginMenu.h"
#include "selleredit.h"
#include "ui_sellermenu.h"
#include "Product.h"
#include "SuperMarket.h"
#include "Seller.h"
#include <QMessageBox>
SellerMenu::SellerMenu(QWidget *parent) :
QDialog(parent),
ui(new Ui::SellerMenu)
{
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);
}
SellerMenu::~SellerMenu()
{
delete ui;
}
void SellerMenu::on_pushButton_clicked()
{
// if (!this->supermarketobject.sellers.empty()) {
// this->supermarketobject.readAllFiles();
// }
// if (this->supermarketobject.customers.empty()) {
// this->supermarketobject.readAllFiles();
// }
QString name;
QString price;
QString category;
QString quantity;
name = ui->productname->text();
price = ui->productprice->text();
category = ui->productcategory->text();
quantity = ui->productquantity->text();
bool flag = false;
for (int i = 0 ; i<this->supermarketobject.products.size() ; i++) {
if(this->supermarketobject.products[i].getName() == name)
flag = true;
}
if (flag) {
QMessageBox::StandardButton reply = QMessageBox::question(
this , "Adding Product" , "Product Already Exists, Do you want to edit it?" ,
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
this->hide();
SellerEdit se;
se.setModal(true);
se.setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint);
se.exec();
}
else {
QMessageBox::information(this , "Adding Product" , "Product Still the same");
}
}
else {
QMessageBox::information(this , "Adding Product" , "Product Added");
QString id = supermarketobject.generateId();
QString ssid = supermarketobject.sellers[supermarketobject.loggedInIndex].getId();
Product temp(id , ssid , quantity , price , name , category,0,0,0);
this->supermarketobject.products.push_back(temp);
//move this line when clicking a button
this->supermarketobject.writeToFileFromProduct();
ui->productname->clear();
ui->productprice->clear();
ui->productcategory->clear();
ui->productquantity->clear();
}
}
void SellerMenu::on_pushButton_2_clicked()
{
this->supermarketobject.writeAllFiles();
this->hide();
loginmenu login;
login.setModal(true);
login.setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint);
login.exec();
}
void SellerMenu::on_pushButton_3_clicked()
{
this->hide();
SellerEdit se;
se.setModal(true);
se.setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint);
se.exec();
}