-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·294 lines (240 loc) · 6.68 KB
/
Copy pathmain.cpp
File metadata and controls
executable file
·294 lines (240 loc) · 6.68 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
285
286
287
288
289
290
291
292
293
294
/************************************************
Notes:
1. 调试指令:
gcc main.cpp database.cpp login.cpp register.cpp search_order.cpp add_goods.cpp print_shop_index.cpp cart.cpp shopping.cpp buy_search_all.cpp search_for_goods.cpp search_for_market.cpp change_admin.cpp change_consumer.cpp check_time.cpp -o a.out
************************************************/
#include "add_goods.h"//添加菜品模块
#include "buy_search_all.h"//购买搜索模块
#include "cart.h"//
#include "change_admin.h"
#include "change_consumer.h"
#include "check_time.h"
#include "database.h"
#include "login.h"
#include "print_shop_index.h"
#include "register.h"
#include "search_for_goods.h"
#include "search_for_market.h"
#include "search_order.h"
#include "shopping.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*******************消费者系统********************/
// 消费者主选单
int consumer_choose() {
char choose[10]; // 记录管理员操作时的选择
int choose_num;
// 用户界面
printf("\n---------------欢迎进入顾客系统!----------------\n");
printf("\n---------------请选择您需要的操作---------------\n");
printf("\n1. 菜品查询.\n2. 查看购物车\n3. 查看已完成订单.\n"
"4. 充值与个人信息管理\n0. 退出.\n");
printf("\n---------------------------------------------\n");
printf("请按数字键选择要执行的操作:\n");
scanf("%s", choose);
// 容错判断
if (strcmp(choose, "1") != 0 && strcmp(choose, "2") != 0 &&
strcmp(choose, "3") != 0 && strcmp(choose, "4") != 0 &&
strcmp(choose, "5") != 0 && strcmp(choose, "0") != 0) {
printf("\n您的输入有误, 请按照操作选项再次输入.\n\n");
choose_num = consumer_choose();
} else
choose_num = atoi(choose);
// 返回选项
return choose_num;
}
void consumer(char user_id[30]) {
int choose = consumer_choose();
switch (choose) {
// 菜品查询
case 1: {
buy_search_all(user_id);
consumer(user_id);
break;
}
// 查看购物车
case 2: {
cart_main(user_id);
consumer(user_id);
break;
}
// 查看已完成订单
case 3: {
search_order(user_id, 0);
consumer(user_id);
break;
}
// 个人信息管理
case 4: {
change_consumer(user_id);
consumer(user_id);
break;
}
// 返回上一层
case 0: {
break;
}
}
return;
}
/*******************消费者系统********************/
/*******************管理员系统********************/
// 管理员第一层第二选单
int admin_choose_2() {
char choose[10]; // 记录管理员操作时的选择
int choose_num;
// 用户界面
printf("\n---------------请选择您需要的操作---------------\n");
printf("\n1. 查看现有菜品.\n2. 添加新菜品.\n0. 返回.\n");
printf("\n---------------------------------------------\n");
printf("请按数字键选择要执行的操作:\n");
scanf("%s", choose);
// 容错判断
if (strcmp(choose, "1") != 0 && strcmp(choose, "2") != 0 &&
strcmp(choose, "0") != 0) {
printf("\n您的输入有误, 请按照操作选项再次输入.\n\n");
choose_num = admin_choose_2();
} else
choose_num = atoi(choose);
// 返回选项
return choose_num;
}
// 菜品管理
void admin_2(char user_id[30]) {
int choose = admin_choose_2();
switch (choose) {
// 查看现有菜品
case 1: {
print_shop_index_main(user_id);
admin_2(user_id);
break;
}
// 添加新菜品
case 2: {
add_goods_main(user_id);
admin_2(user_id);
break;
}
// 返回上一层
case 0: {
break;
}
}
return;
}
// 管理员主选单
int admin_choose() {
char choose[10]; // 记录管理员操作时的选择
int choose_num;
// 用户界面
printf("\n---------------欢迎进入管理员系统!--------------\n");
printf("\n---------------请选择您需要的操作---------------\n");
printf("\n1. 订单管理.\n2. 菜品管理.\n3. 个人信息管理.\n0. 退出.\n");
printf("\n---------------------------------------------\n");
printf("请按数字键选择要执行的操作:\n");
scanf("%s", choose);
// 容错判断
if (strcmp(choose, "1") != 0 && strcmp(choose, "2") != 0 &&
strcmp(choose, "3") != 0 && strcmp(choose, "0") != 0) {
printf("\n您的输入有误, 请按照操作选项再次输入.\n\n");
choose_num = admin_choose();
} else
choose_num = atoi(choose);
// 返回选项
return choose_num;
}
// 管理员系统第一层
void admin(char user_id[30], int user_type) {
int choose = admin_choose();
switch (choose) {
// 订单管理
case 1: {
search_order(user_id, user_type);
admin(user_id, user_type);
break;
}
// 菜品管理
case 2: {
admin_2(user_id);
admin(user_id, user_type);
break;
}
// 个人信息管理
case 3: {
change_admin(user_id);
admin(user_id, user_type);
break;
}
// 返回上一层
case 0: {
break;
}
}
return;
}
/*******************管理员系统********************/
// 登陆与注册选项
int main_choose() {
char choose[10]; // 记录管理员操作时的选择
int choose_num;
// 用户界面
printf("\n------------欢迎进入网上饭店管理系统!------------\n");
printf("\n---------------请选择您需要的操作---------------\n");
printf("\n1. 登陆.\n2. 注册.\n0. 退出.\n");
printf("\n---------------------------------------------\n");
printf("请按数字键选择要执行的操作:\n");
scanf("%s", choose);
// 容��判断
if (strcmp(choose, "1") != 0 && strcmp(choose, "2") != 0 &&
strcmp(choose, "0") != 0) {
printf("\n您的输入有误, 请按照操作选项再次输入.\n\n");
choose_num = main_choose();
} else
choose_num = atoi(choose);
// 返回选项
return choose_num;
}
// 主程序
int main() {
int choose = main_choose(); // 用户界面传入指令
switch (choose) {
// 登陆
case 1: {
if (login_main()) {
// 从数据库中取出 user_id 以及 user_type
FILE *flogin;
char file_name[300];
strcpy(file_name, path); // 该字符串用于处理文件名
strcat(file_name, "login_result.txt"); // 文件名为"login_result.txt"
flogin = fopen(file_name, "r");
char user_id[30];
int user_type;
fscanf(flogin, "%s %d", user_id, &user_type);
fclose(flogin);
if (user_type)
admin(user_id, user_type);
else
consumer(user_id);
break;
} else {
main();
break;
}
break;
}
// 注册
case 2: {
register_main();
main();
break;
}
// 返回上一层
case 0: {
printf("感谢您的使用, 再见.\n");
printf("程序运行结束.\n");
break;
}
}
return 0;
}