-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomer.cpp
More file actions
144 lines (132 loc) · 3.63 KB
/
Customer.cpp
File metadata and controls
144 lines (132 loc) · 3.63 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
#include "Customer.h"
#include <iostream>
Customer::Customer() {}
Customer::Customer(int _id, int _role, std::wstring _login, std::wstring _password) : User(_id, _role, _login, _password) {}
Order Customer::getOrder() { return this->order; }
void Customer::setOrder(Order _order) { this->order = _order; }
void Customer::showInfoProduct(Shop& shop, int id)
{
if (shop.getProducts().empty())
{
std::wcout << L"Íàðàç³ ó ìàãàçèí³ íåìຠïðîäóêò³â. Ïîâåðí³òüñÿ áóäü-ëàñêà, ï³çí³øå.\n";
}
else
{
for (auto& product : shop.getProducts())
{
if (product.getId() == id)
{
std::wcout << L"\nÍàçâà ïðîäóêòó: " << product.getName()
<< L"\nÂàðò³ñòü ïðîäóêòó: " << product.getCost()
<< L"\nÀðòèêëü: " << product.getArticle() << '\n';
}
}
}
}
void Customer::buyProduct(Shop& shop, int id)
{
std::deque<Product> orderProducts;
orderProducts = this->order.getProducts();
if (shop.getProducts().empty())
{
std::wcout << L"Íàðàç³ ó ìàãàçèí³ íåìຠïðîäóêò³â. Ïîâåðí³òüñÿ áóäü-ëàñêà, ï³çí³øå.\n";
}
else
{
for (auto& product : shop.getProducts())
{
if (product.getId() == id)
{
orderProducts.push_back(product);
this->order.setProducts(orderProducts);
}
}
}
}
void Customer::showAllOrders()
{
if (this->order.getProducts().empty())
{
std::wcout << L"Íàðàç³ ó âàñ íåìຠïîòî÷íèõ çàìîâëåíü.\n";
}
else
{
for (auto& product : this->order.getProducts())
{
std::wcout << L"\nÍàçâà ïðîäóêòó: " << product.getName()
<< L"\nÂàðò³ñòü ïðîäóêòó: " << product.getCost()
<< L"\nÀðòèêëü: " << product.getArticle() << '\n';
}
}
}
void Customer::delOrder(int id)
{
std::deque<Product> orderProducts;
orderProducts = this->order.getProducts();
if (this->order.getProducts().empty())
{
std::wcout << L"Íàðàç³ ó âàñ íåìຠïîòî÷íèõ çàìîâëåíü.\n";
}
else
{
for (auto product = orderProducts.begin(); product != orderProducts.end(); ++product)
{
if (product->getId() == id)
{
orderProducts.erase(product);
this->order.setProducts(orderProducts);
}
}
}
}
void Customer::showAllProducts(Shop& shop)
{
if (shop.getProducts().empty()) {
std::wcout << L"Íàðàç³ ó ìàãàçèí³ íåìຠïðîäóêò³â.\n";
}
else {
std::wcout << L"Ñïèñîê óñ³õ ïðîäóêò³â ó ìàãàçèí³\n";
for (auto& product : shop.getProducts()) {
std::wcout << L"ID: " << product.getId()
<< L"\nÍàçâà ïðîäóêòó: " << product.getName()
<< L"\nÂàðò³ñòü ïðîäóêòó: " << product.getCost()
<< L"\nÀðòèêëü: " << product.getArticle() << '\n';
}
}
}
void Customer::showInfoProductByName(Shop& shop, std::wstring productName)
{
if (shop.getProducts().empty()) {
std::wcout << L"Íàðàç³ ó ìàãàçèí³ íåìຠïðîäóêò³â.\n";
}
else {
for (auto& product : shop.getProducts()) {
if (product.getName() == productName) {
std::wcout << L"Ïðîäóêò ç ³ì'ÿì " << productName << L" óñï³øíî çàéäåíî.\n"
<< L"²íôîðìàö³ÿ ïðî çíàéäåíèé ïðîäóêò:\n"
<< L"ID: " << product.getId()
<< L"\nÍàçâà ïðîäóêòó: " << product.getName()
<< L"\nÂàðò³ñòü ïðîäóêòó: " << product.getCost()
<< L"\nÀðòèêëü: " << product.getArticle() << '\n';
}
}
}
}
void Customer::showInfoProductByArticle(Shop& shop, std::wstring article)
{
if (shop.getProducts().empty()) {
std::wcout << L"Íàðàç³ ó ìàãàçèí³ íåìຠïðîäóêò³â.\n";
}
else {
for (auto& product : shop.getProducts()) {
if (product.getName() == article) {
std::wcout << L"Ïðîäóêò ç àðòèêëåì " << article << L" óñï³øíî çàéäåíî.\n"
<< L"²íôîðìàö³ÿ ïðî çíàéäåíèé ïðîäóêò:\n"
<< L"ID: " << product.getId()
<< L"\nÍàçâà ïðîäóêòó: " << product.getName()
<< L"\nÂàðò³ñòü ïðîäóêòó: " << product.getCost()
<< L"\nÀðòèêëü: " << product.getArticle() << '\n';
}
}
}
}