-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
174 lines (171 loc) · 5.61 KB
/
main.c
File metadata and controls
174 lines (171 loc) · 5.61 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
#include <stdio.h>
#include "Master.h"
#include "Input.h"
#include "OutputEntities.h"
#include "Slave.h"
#include "Storage.h"
#include "Ingredient.h"
#define INDEXER_SIZE sizeof(struct Indexer)
int main()
{
struct Storage client;
struct Ingredient order;
while (1)
{
int choice;
int id;
char error[20];
printf("Acceptable Options:\n0 Insert Storage\n1 Get Storage\n2 Update Storage\n3 Delete Storage\n4 Print List of Storages\n5 Insert Ingredient\n6 Get Ingredient\n7 Update Ingredient\n8 Delete Ingredient \n9 Output List of Ingredients\n10 Info\n11 Exit\n");
scanf("%d", &choice);
switch (choice) {
case 0:
inputStorage(&client);
insertStorage(client);
break;
case 1:
printf("Enter ID: \n");
scanf("%d", &id);
if(getStorage(&client, id, error) != 0)
{
OutputStorage(client);
}
else
{
printf("Error: %s\n", error);
}
break;
case 2:
printf("Enter ID: \n");
scanf("%d", &id);
getStorage(&client, id, error);
inputStorage(&client);
if(updateStorage(client, error, id) == 0)
printf("%s", error);
else
printf("Update was successfully\n");
break;
case 3:
printf("Enter ID: \n");
scanf("%d", &id);
if(deleteStorage(id, error) != 0)
printf("Deleted successfully\n");
else
printf("Error: %s\n", error);
break;
case 4:
PrintListOfStorage(error);
break;
case 5:
printf("Enter the Storage id\n");
scanf("%d", &id);
if(getStorage(&client, id, error) != 0)
{
InputIngredient(&order);
order.StorageId = client.id;
insertIngredient(client, order, error);
printf("Insert was successfully \n");
}
else
{
printf("Error %s\n", error);
}
break;
case 6:
printf("Enter the Storage id \n");
scanf("%d", &id);
if(getStorage(&client, id, error))
{
printf("Enter the id of Ingredient \n");
scanf("%d", &id);
if(checkIfRecordExist(client, id,error))
{
getIngredient(client, &order, id, error);
OutputIngredient(order, client);
}
else
{
printf("Error %s\n", error);
}
}
else
{
printf("Error %s\n", error);
}
break;
case 7:
printf("Enter the Storage id \n");
scanf("%d", &id);
if(getStorage(&client, id, error))
{
printf("Enter the id of Ingredient\n ");
scanf("%d", &id);
if(checkIfRecordExist(client, id,error))
{
getIngredient(client, &order, id, error);
InputIngredient(&order);
updateIngredient(order);
printf("Updating was successfully \n ");
}
else
{
printf("Error %s\n", error);
}
}
else
{
printf("Error %s \n", error);
}
break;
case 8:
printf("Enter the Storage id \n");
scanf("%d", &id);
if(getStorage(&client, id, error))
{
printf("Enter the id of Ingredient \n");
scanf("%d", &id);
if(checkIfRecordExist(client, id,error))
{
getIngredient(client, &order, id, error);
deleteIngredient(client, order, error);
printf("Deleted was successfully \n");
}
else
{
printf("Error %s \n ", error);
}
}
else
{
printf("Error %s \n ", error);
}
break;
case 9:
printf("Enter the Storage id \n");
scanf("%d", &id);
if(getStorage(&client, id, error))
{
if(client.ingredientCount != 0)
{
PrintList(client);
}
else
{
printf("This Storage has no Ingredients\n");
}
}
else
{
printf("Error %s \n ", error);
}
break;
case 10:
info();
break;
case 11:
return 0;
default:
printf("No command :( \n");
}
printf("\n");
}
}