-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
219 lines (210 loc) · 5.79 KB
/
main.c
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
#include <manager.h>
int search_book(); //查找图书
void student(); //学生模块
void teacher(); //教师模块
void manager(); //图书管理员模块
void sys(); //系统管理员模块
void test(); //调试接口
int main()
{
// test();
init_all(); //初始化数据
int user;
char opt;
while (1)
{
print_menu(INIT); //打印菜单
opt=_getch(); //获取输入
if ( opt == '1' )
{
system("CLS");
user=login(); //用户登陆
switch (user)
{
case STUDENT:
student();break;
case TEACHER:
teacher();break;
case MANAGER:
manager();break;
case SYSTEM:
sys();break;
}
}
else if (opt == '0')
{
printf("\n期待下次使用,再见!");
return 0;
}
else
{
printf("\n请选择登录系统或者退出系统\n按任意键重新输入");
_getch();
}
}
}
void sys()
{
char opt;
while (1)
{
print_menu(SYSTEM); //打印菜单
opt=_getch(); //获取用户选项
switch (opt)
{
case '1':
list_user();break; //显示所有用户
case '2':
add_user();break; //添加用户
case '3':
del_user();break; //删除用户
case '4':
list_book(ALL);break; //显示所有图书
case '5':
del_book();break; //删除图书
case '6':
add_book();break; //添加图书
case '7':
init_password();break; //初始化用户密码
case '8':
if (change_password()) //修改密码
return;
break;
case '9':
return;
default:
return;
}
}
}
void student()
{
char opt;
while (1)
{
print_menu(STUDENT); //打印菜单
opt=_getch(); //获取用户选项
switch (opt)
{
case '1':
list_book(ALL);break; //列出所有图书
case '5':
if (change_password()) //修改密码
return;
break;
case '0': break;
default: break;
}
}
}
void teacher()
{
char opt;
while (1)
{
print_menu(TEACHER); //打印菜单
opt=_getch(); //获取用户选项
switch (opt)
{
case '1':
list_book(ALL);break; //列出所有图书
case '6':
if (change_password()) //修改密码
return;
break;
case '0':
return;
default:
return;
}
}
}
void manager()
{
char opt;
while (1)
{
print_menu(MANAGER); //打印菜单
opt=_getch(); //获取用户选项
switch (opt)
{
case '1':
list_book(ALL);break; //列出所有图书
case '6':
add_book();break; //添加图书
case '7':
if (change_password()) //修改密码
return;
break;
case '0':
return;
default:
return;
}
}
}
void test() //调试接口
{
FILE * user_text;
int t=0;
int i=0;
int j=0;
user_text=fopen("pwd.txt","r");
while (fscanf(user_text,"%s",&user[user_amount].name) != EOF) //读取用户信息
{
fscanf(user_text,"%s",&user[user_amount].password);
fscanf(user_text,"%d",&user[user_amount++].user_type);
}
fclose(user_text);
for (t = 0 ; t < user_amount ; t ++ )
{
for (i = 0 ; i < 16 ; i ++ )
if (user[t].name[i] == '\0')
for (j = i+1 ; j < 16 ; j ++ )
user[t].name[j] = '\0';
for (i = 0 ; i < 16 ; i ++ )
if (user[t].password[i] == '\0')
for (j = i+1 ; j < 16 ; j ++ )
user[t].password[j] = '\0';
}
user_text=fopen("pwd.bd","wb"); //更新数据文件
for (t = 0 ; t < user_amount ; t ++ )
{
for (i = 0 ; i < 16 ; i ++ )
user[t].name[i] += SECURE;
for (j = 0 ; j < 16 ; j ++ )
user[t].password[j] += SECURE;
user[t].user_type += SECURE;
fwrite(user[t].name,sizeof(user[t].name),1,user_text);
fwrite(user[t].password,sizeof(user[t].password),1,user_text);
fwrite(&user[t].user_type,sizeof(int),1,user_text);
}
fclose(user_text);
user_text=fopen("pwd.bd","rb");
t=0;
while (!feof(user_text)) //读取用户信息
{
fread(user[t].name,sizeof(user[t].name),1,user_text);
fread(user[t].password,sizeof(user[t].password),1,user_text);
fread(&user[t].user_type,sizeof(int),1,user_text);
for (i = 0 ; i < 16 ; i ++ )
user[t].name[i] -= SECURE;
for (j = 0 ; j < 16 ; j ++ )
user[t].password[j] -= SECURE;
user[t].user_type -= SECURE;
t++;
}
fclose(user_text);
for (t = 0 ; t < user_amount ; t ++ )
{
printf("%s\n%s\n%d\n",user[t].name,user[t].password,user[t].user_type);
}
for (t = 0 ; t < user_amount ; t ++ )
{
for (i = 0 ; i < 16 ; i ++ )
printf("%d ",user[t].name[i]);
for (i = 0 ; i < 16 ; i ++ )
printf("%d ",user[t].password[i]);
}
// exit(0);
}