-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditProduct.cpp
More file actions
130 lines (95 loc) · 3.83 KB
/
EditProduct.cpp
File metadata and controls
130 lines (95 loc) · 3.83 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
#include "EditProduct.h"
#include "ui_EditProduct.h"
#include "Global.h"
#include <QString>
#include "FastArrays.h"
#include <QMessageBox>
#include "CategoryDatas.h"
using namespace GlobalNameSpace;
EditProduct::EditProduct(QWidget *parent) :
QDialog(parent),
ui(new Ui::EditProduct)
{
ui->setupUi(this);
NodeProduct *p_node = &Globals::PRODUCT_LIST.getByKey(Globals::KEY_PRODUCT);
Product p_data = p_node->getData();
for (int i = 0; i < 31; i++){
ui->stateCombo->addItem(statesList[i]);
}
ui->stateCombo->setCurrentText(p_data.getState());
for (int i = 0; i < 11; i++){
ui->colorCombo->addItem(colorList[i]);
}
ui->colorCombo->setCurrentText(p_data.getColor());
for (int i = 0; i < 16; i++){
ui->categoryCombo_2->addItem(LIST_CATEGORY[i]);
}
ui->titleL->setText("<font color='red'>Title: </font>");
ui->priceL->setText("<font color='red'>Sell Price: </font>");
ui->stateL->setText("<font color='red'>State: </font>");
ui->colorL->setText("<font color='red'>Color: </font>");
ui->numberL->setText("<font color='red'>Available Number: </font>");
ui->categoryL_2->setText("<font color='red'>Category: </font>");
ui->sellPriceE->setValidator( new QIntValidator(0, 1000000000, this) );
ui->numberE->setValidator( new QIntValidator(0, 1000000000, this) );
ui->offPercentE->setValidator( new QIntValidator(0, 10, this) );
ui->titleE->setPlaceholderText(p_data.getName());
ui->creatorE->setPlaceholderText(p_data.getCreator());
ui->sellPriceE->setPlaceholderText(QString::number(p_data.getSellPrice()));
ui->numberE->setPlaceholderText(QString::number(p_data.getAvailableNumber()));
ui->descriptionE->setPlaceholderText(p_data.getDescription());
ui->offPercentE->setPlaceholderText(QString::number(p_data.getOffPercent()));
}
EditProduct::~EditProduct()
{
delete ui;
}
void EditProduct::on_confirmB_clicked()
{
NodeProduct* temp = &Globals::PRODUCT_LIST.getByKey(Globals::KEY_PRODUCT);
Product p = temp->getData();
if (ui->titleE->text() == "")
p.setName(ui->titleE->placeholderText());
else
p.setName(ui->titleE->text());
p.setColor(ui->colorCombo->currentText());
p.setState(ui->stateCombo->currentText());
if (ui->creatorE->text() == "")
p.setCreator(ui->creatorE->placeholderText());
else
p.setCreator(ui->creatorE->text());
if (ui->sellPriceE->text() == "")
p.setSellPrice(ui->sellPriceE->placeholderText().toDouble());
else
p.setSellPrice(ui->sellPriceE->text().toDouble());
if (ui->offPercentE->text() == "")
p.setOffPercent(ui->offPercentE->placeholderText().toFloat());
else
p.setOffPercent(ui->offPercentE->text().toFloat());
if (ui->numberE->text() == "")
p.setAvailableNumber(ui->numberE->placeholderText().toUInt());
else
p.setAvailableNumber(ui->numberE->text().toUInt());
if (ui->descriptionE->text() == "")
p.setDescription(ui->descriptionE->placeholderText());
else
p.setDescription(ui->descriptionE->text());
p.setNameCategory(ui->categoryCombo_2->currentText());
double purePrice = (double)(p.getSellPrice() * (1 - p.getOffPercent() / 100));
p.setPureSellPrice(purePrice);
temp->setData(p); // Edit this product on LinkedListProduct
Globals::PRODUCT_LIST.print();
TNodeUser<Dealer>* d_node = &Globals::DEALER_LIST.getByKey(Globals::KEY_USER);
Dealer d_data = d_node->getData();
d_data.deleteProductToListOfSell(p);
d_data.addKeyToListOfSell(p);
d_node->setData(d_data); // Edit this product on DealerList
Globals::DEALER_LIST.writeToFileUser();
Globals::PRODUCT_LIST.writeFile();
QMessageBox::information(this, "Done", "Product edited.");
this->close();
}
void EditProduct::on_cancelB_clicked()
{
this->close();
}