-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.c
More file actions
226 lines (201 loc) · 6.23 KB
/
menu.c
File metadata and controls
226 lines (201 loc) · 6.23 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
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <conio.h>
#include "list.h"
#include "file_manager.h"
#include "checks.h"
#include "search.h"
#include "sort.h"
// For adaptive clear screen
#ifdef _WIN32
#define CLEAR "cls"
#else
#define CLEAR "clear"
#endif
ShopItem *readItem(ShopItem *shopItem) {
shopItem->name = enterString("Write name of item: ");
shopItem->type = enterString("Write type of item: ");
shopItem->description = enterString("Write description of item: ");
shopItem->count = enterInt("Write count of items: ");
shopItem->price = enterDouble("Write price of item: ");
shopItem->stars = enterDouble("Write stars of item: ");
return shopItem;
}
void showAbout() {
system(CLEAR);
puts("================= [About] ===================");
puts("Title: \"Shop Manager\"");
puts("Author: Zub Vitaliy 8307");
puts("Description: In the application, you can\nstore your store data in a structured\nway. Follow the menu to work with the\napplication.");
puts("=============================================");
printf("Press anything to continue: ");
getch();
}
void showAdd(List *list) {
ShopItem *shopItem = malloc(sizeof(ShopItem));
system(CLEAR);
puts("================== [Add] ====================");
puts("At this point you can add a new item\nto the library. Follow the instructions.");
puts("=============================================");
readItem(shopItem);
add(shopItem, list);
puts("Item wad added to library");
printf("Write anything to continue: ");
getch();
}
void showEdit(List *list) {
int id = 0;
system(CLEAR);
puts("================= [Edit] ====================");
puts("At this point you can edit item\nfrom the library. Follow the instructions.");
puts("=============================================");
id = enterInt("Write ID of note to edit: ");
ShopItem *shopItem = get(id, list);
if (shopItem == NULL) {
puts("There is no such id");
printf("Write anything to continue: ");
getch();
} else {
readItem(shopItem);
puts("Item wad edited");
printf("Write anything to continue: ");
getch();
}
}
void showDelete(List *list) {
int id = 0;
system(CLEAR);
puts("================ [Delete] ===================");
puts("At this point you can delete item\nfrom the library. Follow the instructions.");
puts("=============================================");
id = enterInt("Write ID of note to delete: ");
ShopItem *shopItem = get(id, list);
if (shopItem == NULL) {
puts("There is no such id");
printf("Write anything to continue: ");
getch();
} else {
delete(id, list);
puts("Item wad deleted");
printf("Write anything to continue: ");
getch();
}
}
void showList(List *list) {
system(CLEAR);
puts("================= [List] ====================");
display(list);
puts("=============================================");
printf("Write anything to continue: ");
getch();
}
void showSearchMenu(List *list) {
int id = 0;
system(CLEAR);
puts("================ [Search] ===================");
puts("0. ID");
puts("1. Name");
puts("2. Type");
puts("3. Description");
puts("4. Count");
puts("5. Price");
puts("6. Stars");
puts("=============================================");
id = enterInt("Write your field: ");
if (id == 0) {
id = enterInt("Write id of item: ");
puts("");
getSearchListById(list, id);
} else if (id == 1) {
char *name = enterString("Write name of item: ");
puts("");
getSearchListByName(list, name);
} else if (id == 2) {
char *type = enterString("Write type of item: ");
puts("");
getSearchListByType(list, type);
} else if (id == 3) {
char *description = enterString("Write description of item: ");
puts("");
getSearchListByDescription(list, description);
} else if (id == 4) {
int count = enterInt("Write count of items: ");
puts("");
getSearchListByCount(list, count);
} else if (id == 5) {
double price = enterDouble("Write price of item: ");
puts("");
getSearchListByPrice(list, price);
} else if (id == 6) {
double stars = enterDouble("Write stars of item: ");
puts("");
getSearchListByStars(list, stars);
}
printf("Write anything to continue: ");
getch();
}
void showSortMenu(List *list) {
int id = 0;
system(CLEAR);
puts("================= [Sort] ====================");
puts("0. ID");
puts("1. Name");
puts("2. Type");
puts("3. Description");
puts("4. Count");
puts("5. Price");
puts("6. Stars");
puts("=============================================");
id = enterInt("Write your field: ");
if (id == 0) {
sortById(list);
} else if (id == 1) {
sortByName(list);
} else if (id == 2) {
sortByType(list);
} else if (id == 3) {
sortByDescription(list);
} else if (id == 4) {
sortByCount(list);
} else if (id == 5) {
sortByPrice(list);
} else if (id == 6) {
sortByStars(list);
}
puts("List was sorted");
printf("Write anything to continue: ");
getch();
}
void showMenu(List *list) {
int menu = 0;
while (menu != 7) {
system(CLEAR);
puts("================= [MENU] ===================");
puts("0. About");
puts("1. Add new note");
puts("2. Edit note");
puts("3. Delete note");
puts("4. Print list");
puts("5. Search");
puts("6. Sort");
puts("7. Exit");
puts("============================================");
menu = enterInt("Write your command: ");
if (menu == 0) {
showAbout();
} else if (menu == 1) {
showAdd(list);
} else if (menu == 2) {
showEdit(list);
} else if (menu == 3) {
showDelete(list);
} else if (menu == 4) {
showList(list);
} else if (menu == 5) {
showSearchMenu(list);
} else if (menu == 6) {
showSortMenu(list);
}
}
}