-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoshop.cpp
More file actions
284 lines (247 loc) · 5.33 KB
/
Copy pathautoshop.cpp
File metadata and controls
284 lines (247 loc) · 5.33 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#include "autoshop.h"
AutoShop::AutoShop()
{
}
QVector<Manager *> AutoShop::get_managers() const
{
return managers;
}
QVector<Client *> AutoShop::get_clients() const
{
return clients;
}
QVector<Car *> AutoShop::get_cars() const
{
return cars;
}
QVector<Brand *> AutoShop::get_brands() const
{
return brands;
}
QVector<Buy *> AutoShop::get_buys() const
{
return buys;
}
void AutoShop::add_manager(int i, QString f, QString m, QString l, QString p, QDate d, int e)
{
try{
Manager* tmp = new Manager(i,f,m,l,p,d,e);
managers.push_back(tmp);
} catch(const QString s)
{
qDebug() << s;
}
}
void AutoShop::add_client(int i, QString f, QString m, QString l, QString p, QString a)
{
try{
Client* tmp = new Client(i,f,m,l,p,a);
clients.push_back(tmp);
} catch(const QString s)
{
qDebug() << s;
}
}
void AutoShop::add_car(int i, QString m, QString b, double p, QString em, QString et, int power, Brand br, int year, Manager ma)
{
try{
Car* tmp = new Car(i,m,b,p,em,et,power,br,year,ma);
cars.push_back(tmp);
} catch(const QString s)
{
qDebug() << s;
}
}
void AutoShop::add_brand(QString n, QString i)
{
try{
Brand* tmp = new Brand(n,i);
brands.push_back(tmp);
} catch(const QString s)
{
qDebug() << s;
}
}
void AutoShop::add_buy_from_database(Client c, Car ca, QDate d)
{
try{
Buy*tmp = new Buy(c, ca, d);
buys.push_back(tmp);
} catch(const QString s)
{
qDebug() << s;
}
}
void AutoShop::del_manager(int id)
{
auto tmp = std::find_if(managers.begin(), managers.end(),
[id](Manager* t){
return t->get_ID() == id;
});
if(tmp != managers.end())
{
managers.erase(tmp);
}
}
void AutoShop::del_client(int id)
{
auto tmp = std::find_if(clients.begin(), clients.end(),
[id](Client* t){
return t->get_ID() == id;
});
if(tmp != clients.end())
{
clients.erase(tmp);
}
}
void AutoShop::del_car(int id)
{
auto tmp = std::find_if(cars.begin(), cars.end(),
[id](Car* t){
return t->get_ID() == id;
});
if(tmp != cars.end())
{
cars.erase(tmp);
}
}
void AutoShop::del_brand(QString name)
{
auto tmp = std::find_if(brands.begin(), brands.end(),
[name](Brand* t){
return t->get_name() == name;
});
if(tmp != brands.end())
{
brands.erase(tmp);
}
}
void AutoShop::del_buy(int id) //id машины
{
auto tmp = std::find_if(buys.begin(), buys.end(),
[id](Buy* t){
return t->get_car().get_ID() == id;
});
if(tmp != buys.end())
{
buys.erase(tmp);
}
}
void AutoShop::sort_managers()
{
std::sort(managers.begin(), managers.end(), sort_manager);
}
void AutoShop::sort_clients()
{
std::sort(clients.begin(), clients.end(), sort_client);
}
void AutoShop::sort_cars()
{
std::sort(cars.begin(), cars.end(), sort_car);
}
void AutoShop::sort_brands()
{
std::sort(brands.begin(), brands.end(), sort_brand);
}
void AutoShop::sort_buys()
{
std::sort(buys.begin(), buys.end(), sort_buy);
}
Manager *AutoShop::find_manager(QString number) const
{
for(auto item : managers)
{
if(item->get_phone_number() == number)
{
return item;
}
}
return nullptr;
}
Client *AutoShop::find_client(QString number) const
{
for(auto item : clients)
{
if(item->get_phone_number() == number)
{
return item;
}
}
return nullptr;
}
Car *AutoShop::find_car(int id) const
{
for(auto item : cars)
{
if(item->get_ID() == id)
{
return item;
}
}
return nullptr;
}
Brand *AutoShop::find_brand(QString name) const
{
for(auto item : brands)
{
if(item->get_name() == name)
{
return item;
}
}
return nullptr;
}
Buy *AutoShop::find_buy(int id_car) const
{
for(auto item : buys)
{
if(item->get_car().get_ID() == id_car)
{
return item;
}
}
return nullptr;
}
AutoShop::~AutoShop()
{
for(int i = 0; i < buys.size(); i++)
{
delete buys[i];
}
for(int i = 0; i < cars.size(); i++)
{
delete cars[i];
}
for(int i = 0; i < brands.size(); i++)
{
delete brands[i];
}
for(int i = 0; i < managers.size(); i++)
{
delete managers[i];
}
for(int i = 0; i < clients.size(); i++)
{
delete clients[i];
}
}
bool sort_manager(Manager *left, Manager *right) //сортировка от большего опыта к меньшему
{
return left->get_experience() > right->get_experience();
}
bool sort_client(Client *left, Client *right) //сортировка по алфавиту фамилий
{
return left->get_last_name() < right->get_last_name();
}
bool sort_car(Car *left, Car *right) // сортировка по алфавиту моделей
{
return left->get_model() < right->get_model();
}
bool sort_brand(Brand *left, Brand *right) // сортировка по алфавиту имени брендов
{
return left->get_name() < right->get_name();
}
bool sort_buy(Buy *left, Buy *right) // сортировка по дате покупки
{
return left->get_date() < right->get_date();
}