#include #include #include #include #include #include #include "information.h" int v; int g; struct BOOK b; struct BOOK *i; struct BOOK *j; struct BOOK *H; struct BOOK *T; struct BOOK *Head; struct BOOK *Temp; extern int vip; extern struct STUDENT *HEAD; extern struct STUDENT *TEMP; void cls(); void Login(); void stu_menu(); void adm_menu(); void read_user(); void adm_window(); void view1_book(); void view2_book(); void recovery_window(); void book_printf(int a); void tp(short x, short y); void color(short x); void Swap(char *a, char *b) { char t[21]; strcpy(t, a); strcpy(a, b); strcpy(b, t); } void Swap_num(int *a, int *b) { int t; t = *a; *a = *b; *b = t; } void read_book() { struct BOOK *p; T = (struct BOOK *)malloc(sizeof(struct BOOK)); H = T; FILE *fp = fopen("book.txt", "r"); if(fp == NULL) { cls(); color(12); tp(39, 8); printf("无法打开文件"); tp(39, 10); printf("按任意键退出..."); tp(39, 12); getch(); exit(2); } while(!feof(fp)) { p = T; fscanf(fp, "%s %s %s %s %d\n", T->name, T->author, T->type, T->publish, &T->number); T->next = (struct BOOK *)malloc(sizeof(struct BOOK)); T = T->next; } free(T); p->next = NULL; fclose(fp); } void read_lend() { struct BOOK *p; Temp = (struct BOOK *)malloc(sizeof(struct BOOK)); Head = Temp; FILE *fp = fopen("lend.txt", "r"); if(fp == NULL) { cls(); color(12); tp(39, 8); printf("无法打开文件"); tp(39, 10); printf("按任意键退出..."); tp(39, 12); getch(); exit(2); } while(!feof(fp)) { p = Temp; fscanf(fp, "%s %s %s %s %s\n", Temp->name, Temp->author, Temp->type, Temp->publish, Temp->user); Temp->next = (struct BOOK *)malloc(sizeof(struct BOOK)); Temp = Temp->next; } free(Temp); p->next = NULL; fclose(fp); } int user_num(int z, int h) { int d = 0, n = 0; char t, u[10]; t = getch(); while(1) { if(t == 13) { if(n == 0) { tp(65, 6); printf(" "); tp(65, 6); printf("输入数量不能为空"); tp(45 + h, z); t = getch(); continue; } else break; } if(t == 27) adm_menu(); if(t == 8 && n == 0) { t = getch(); continue; } else if(t == 8) { tp(65, 6); printf(" "); tp(45 + h, z); printf(" "); tp(45 + h, z); n--; u[n] = 0; printf("%s", u); t = getch(); continue; } if(n == 10) { tp(65, 6); printf(" "); tp(65, 6); printf("超出字数限制"); tp(45 + h, z); t = getch(); continue; } if(t > 47 && t < 58) { tp(65, 6); printf(" "); tp(45 + h, z); u[n] = t; n++; u[n] = 0; printf("%s", u); t = getch(); continue; } else { tp(65, 6); printf(" "); tp(65, 6); printf("请不要输入数字以外的符号"); tp(45 + h, z); t = getch(); continue; } } for(int i = n - 1, j = 1; i >= 0; i--, j *= 10) d += (u[i] - 48)*j; return d; } void user_name(int z, char *u, int h) { int n = 0; char t; t = getch(); while(1) { if(t == 13) { if(v == 1 && n < 6) { tp(65, 6); printf(" "); tp(65, 6); printf("密码过短"); tp(45 + h, z); t = getch(); continue; } if(n == 0) { tp(65, 6); printf(" "); tp(65, 6); printf("输入内容不能为空"); tp(45 + h, z); t = getch(); continue; } else break; } if(t == 27) { if(vip == 1) { if(g == 1) view2_book(); else adm_menu(); } else { if(g == 1) view1_book(); else stu_menu(); } } if(t == 8 && n == 0) { t = getch(); continue; } else if(t == 8) { tp(65, 6); printf(" "); tp(45 + h, z); printf(" "); tp(45 + h, z); n--; u[n] = 0; if(u[n - 1] < 0) { n--; u[n] = 0; } printf("%s", u); t = getch(); continue; } if(n == 20) { tp(65, 6); printf(" "); tp(65, 6); printf("超出字数限制"); tp(45 + h, z); t = getch(); continue; } if(t == 32) { tp(65, 6); printf(" "); tp(65, 6); printf("请不要输入空格"); tp(45 + h, z); t = getch(); continue; } if(t == 0 || t == -32) { getch(); t = getch(); continue; } if(t < 0) { tp(65, 6); printf(" "); tp(45 + h, z); u[n] = t; n++; t = getch(); u[n] = t; n++; u[n] = 0; printf("%s", u); t = getch(); continue; } tp(65, 6); printf(" "); tp(45 + h, z); u[n] = t; n++; u[n] = 0; printf("%s", u); t = getch(); } u[n] = 0; } int search_book() { cls(); int x = 0; struct BOOK temp; color(12); tp(39, 8); printf("请输入图书信息"); color(11); tp(39, 10); printf("书名:"); tp(39, 12); printf("作者:"); tp(39, 14); printf("出版社:"); color(8); tp(39, 16); printf("按ESC返回菜单"); color(11); tp(44, 10); user_name(10, temp.name, -1); tp(44, 12); user_name(12, temp.author, -1); tp(46, 14); user_name(14, temp.publish, 1); tp(39, 18); read_book(); T = H; while(T != NULL) { if(!strcmp(temp.name, T->name) && !strcmp(temp.author, T->author) && !strcmp(temp.publish, T->publish)) { x = 1; break; } T = T->next; } return x; } void no_info() { color(12); printf("未找到相应的信息"); color(11); tp(39, 20); printf("按任意键返回..."); tp(39, 22); getch(); } void inquire1() { if(search_book()) { cls(); tp(39, 8); printf("书名:%s", T->name); tp(39, 10); printf("作者:%s", T->author); tp(39, 12); printf("类型:%s", T->type); tp(39, 14); printf("出版社:%s", T->publish); tp(39, 16); printf("数量:%d\n", T->number); tp(39, 18); printf("| 1.图书借出 |"); tp(39, 20); printf("| 2.图书归还 |"); tp(39, 22); printf("| 任意键返回菜单 |"); switch(getch()) { case '1':book_printf(-1);break; case '2':book_printf(1); default :break; } } else no_info(); } void inquire2() { if(search_book()) { cls(); tp(39, 8); printf("书名:%s", T->name); tp(39, 10); printf("作者:%s", T->author); tp(39, 12); printf("类型:%s", T->type); tp(39, 14); printf("出版社:%s", T->publish); tp(39, 16); printf("数量:%d\n", T->number); tp(39, 18); printf("任意键返回菜单..."); getch(); } else no_info(); } void change_question() { cls(); color(11); tp(39, 8); printf("书名:%s", T->name); tp(39, 10); printf("作者:%s", T->author); tp(39, 12); printf("类型:%s", T->type); tp(39, 14); printf("出版社:%s", T->publish); tp(39, 16); printf("数量:%d", T->number); color(12); tp(39, 18); printf("是否修改该图书"); tp(39, 20); printf("| 1.是 |"); tp(39, 22); printf("| 2.否 |"); tp(39, 24); switch(getch()) { case '1':break; case '2':adm_menu(); case '\e':adm_menu(); default :change_question(); } } void change_book() { cls(); int x = 0; struct BOOK t; color(12); tp(39, 8); printf("请输入需要修改的图书信息"); color(11); tp(39, 10); printf("书名:"); tp(39, 12); printf("作者:"); tp(39, 14); printf("出版社:"); color(8); tp(39, 16); printf("按ESC返回菜单"); color(11); tp(44, 10); user_name(10, t.name, -1); tp(44, 12); user_name(12, t.author, -1); tp(46, 14); user_name(14, t.publish, 1); tp(39, 18); read_book(); T = H; while(T != NULL) { if(!strcmp(t.name, T->name) && !strcmp(t.author, T->author) && !strcmp(t.publish, T->publish)) { x = 1; break; } T = T->next; } if(x) { change_question(); cls(); color(11); tp(30, 8); printf("书名:%s", T->name); tp(54, 8); printf("->"); tp(30, 10); printf("作者:%s", T->author); tp(54, 10); printf("->"); tp(30, 12); printf("类型:%s", T->type); tp(54, 12); printf("->"); tp(30, 14); printf("出版社:%s", T->publish); tp(54, 14); printf("->"); tp(30, 16); printf("数量:%d", T->number); tp(54, 16); printf("->"); color(8); tp(39, 18); printf("按ESC返回菜单"); color(11); tp(64, 8); user_name(8, T->name, 19); tp(64, 10); user_name(10, T->author, 19); tp(64, 12); user_name(12, T->type, 19); tp(64, 14); user_name(14, T->publish, 19); tp(64, 16); T->number = user_num(16, 19); tp(39, 20); for(i = H; i != NULL; i = i->next) for(j = i->next; j != NULL; j = j->next) if(i->number > j->number) { Swap(i->name, j->name); Swap(i->author, j->author); Swap(i->type, j->type); Swap(i->publish, j->publish); Swap_num(&i->number, &j->number); } T = H; FILE *fp = fopen("book.txt", "w"); while(T != NULL) { fprintf(fp, "%s %s %s %s %d\n", T->name, T->author, T->type, T->publish, T->number); T = T->next; } fclose(fp); color(12); printf("修改图书成功"); tp(39, 22); color(11); printf("按任意键返回..."); tp(39, 22); getch(); } else no_info(); } void add_() { T = H; while(T != NULL) { if(b.number <= H->number) { i = H; H = &b; b.next = i; break; } if(T->next == NULL) { T->next = &b; b.next = NULL; break; } if(b.number <= T->next->number) { i = T->next; T->next = &b; b.next = i; break; } T = T->next; } for(i = H; i != NULL; i = i->next) for(j = i->next; j != NULL; j = j->next) if(i->number > j->number) { Swap(i->name, j->name); Swap(i->author, j->author); Swap(i->type, j->type); Swap(i->publish, j->publish); Swap_num(&i->number, &j->number); } T = H; FILE *fp = fopen("book.txt", "w"); while(T != NULL) { fprintf(fp, "%s %s %s %s %d\n", T->name, T->author, T->type, T->publish, T->number); T = T->next; } fclose(fp); cls(); color(12); tp(39, 8); printf("添加成功"); color(11); tp(39, 10); printf("按任意键返回..."); tp(39, 12); getch(); } void add_question() { color(12); tp(39, 22); printf("是否添加该图书"); tp(39, 24); printf("| 1.是 |"); tp(39, 26); printf("| 2.否 |"); tp(39, 28); switch(getch()) { case '1':add_();break; case '2':break; case '\e':adm_menu(); default :add_question(); } } void add_book() { cls(); int x = 0; color(12); tp(39, 8); printf("请输入需要添加的图书信息"); color(11); tp(39, 10); printf("书名:"); tp(39, 12); printf("作者:"); tp(39, 14); printf("类型:"); tp(39, 16); printf("出版社:"); tp(39, 18); printf("数量:"); color(8); tp(39, 20); printf("按ESC返回菜单"); color(11); tp(44, 10); user_name(10, b.name, -1); tp(44, 12); user_name(12, b.author, -1); tp(44, 14); user_name(14, b.type, -1); tp(46, 16); user_name(16, b.publish, 1); tp(44, 18); b.number = user_num(18, -1); tp(39, 22); read_book(); T = H; while(T != NULL) { if(!strcmp(b.name, T->name) && !strcmp(b.author, T->author) && !strcmp(b.publish, T->publish)) { x = 1; break; } T = T->next; } if(x) { cls(); color(12); tp(39, 8); printf("该图书已存在"); color(11); tp(39, 10); printf("按任意键返回..."); tp(39, 12); getch(); } else add_question(); } void del_() { struct BOOK *p = H; if(T == H) { H = T->next; free(T); } else { while(p != NULL && p->next != T) p = p->next; p->next = T->next; free(T); } T = H; FILE *fp = fopen("book.txt", "w"); while(T != NULL) { fprintf(fp, "%s %s %s %s %d\n", T->name, T->author, T->type, T->publish, T->number); T = T->next; } fclose(fp); color(12); printf("删除图书成功"); tp(39, 26); color(11); printf("按任意键返回..."); tp(39, 28); getch(); } void del_question() { cls(); color(11); tp(39, 8); printf("书名:%s", T->name); tp(39, 10); printf("作者:%s", T->author); tp(39, 12); printf("类型:%s", T->type); tp(39, 14); printf("出版社:%s", T->publish); tp(39, 16); printf("数量:%d", T->number); color(12); tp(39, 18); printf("是否删除该图书"); tp(39, 20); printf("| 1.是 |"); tp(39, 22); printf("| 2.否 |"); tp(39, 24); switch(getch()) { case '1':del_();break; case '2':break; case '\e':adm_menu(); default :del_question(); } } void delete_book() { cls(); int x = 0; struct BOOK t; color(12); tp(39, 8); printf("请输入需要删除的图书信息"); color(11); tp(39, 10); printf("书名:"); tp(39, 12); printf("作者:"); tp(39, 14); printf("出版社:"); color(8); tp(39, 16); printf("按ESC返回菜单"); color(11); tp(44, 10); user_name(10, t.name, -1); tp(44, 12); user_name(12, t.author, -1); tp(46, 14); user_name(14, t.publish, 1); tp(39, 18); read_book(); T = H; while(T != NULL) { if(!strcmp(t.name, T->name) && !strcmp(t.author, T->author) && !strcmp(t.publish, T->publish)) { x = 1; break; } T = T->next; } if(x) del_question(); else no_info(); } void print() { printf("-------------------------------------------------------------------------------------------------\n"); printf(" 书名 作者 类型 出版社 数量\n"); printf("-------------------------------------------------------------------------------------------------\n"); } void All() { cls(); int x = 3; read_book(); print(); T = H; color(12); while(T != NULL) { tp(0, x); printf("%s", T->name); tp(24, x); printf("%s", T->author); tp(45, x); printf("%s", T->type); tp(65, x); printf("%s", T->publish); tp(88, x); printf("%d", T->number); x++; T = T->next; } color(11); printf("\n\n按任意键返回..."); getch(); cls(); } void Auth() { cls(); int z = 0, x = 3; char t[21]; color(12); tp(39, 8); printf("作者查询"); color(11); tp(39, 10); printf("请输入需要查询的作者:"); color(8); tp(39, 12); printf("按ESC返回菜单"); color(11); tp(60, 10); user_name(10, t, 15); tp(39, 14); read_book(); T = H; color(12); while(T != NULL) { if(strcmp(t, T->author) == 0 && z == 0) { cls(); print(); tp(0, x); printf("%s", T->name); tp(24, x); printf("%s", T->author); tp(45, x); printf("%s", T->type); tp(65, x); printf("%s", T->publish); tp(88, x); printf("%d", T->number); x++; z++; } else if(strcmp(t, T->author) == 0) { tp(0, x); printf("%s", T->name); tp(24, x); printf("%s", T->author); tp(45, x); printf("%s", T->type); tp(65, x); printf("%s", T->publish); tp(88, x); printf("%d", T->number); x++; } T = T->next; } if(z == 0) { printf("无该作者的信息"); color(11); tp(39, 16); printf("按任意键返回..."); getch(); cls(); } else { color(11); printf("\n\n按任意键返回..."); getch(); cls(); } } void Type() { cls(); int z = 0, x = 3; char t[21]; color(12); tp(39, 8); printf("类型查询"); color(11); tp(39, 10); printf("请输入需要查询的类型:"); color(8); tp(39, 12); printf("按ESC返回菜单"); color(11); tp(60, 10); user_name(10, t, 15); tp(39, 14); read_book(); T = H; color(12); while(T != NULL) { if(strcmp(t, T->type) == 0 && z == 0) { cls(); print(); tp(0, x); printf("%s", T->name); tp(24, x); printf("%s", T->author); tp(45, x); printf("%s", T->type); tp(65, x); printf("%s", T->publish); tp(88, x); printf("%d", T->number); x++; z++; } else if(strcmp(t, T->type) == 0) { tp(0, x); printf("%s", T->name); tp(24, x); printf("%s", T->author); tp(45, x); printf("%s", T->type); tp(65, x); printf("%s", T->publish); tp(88, x); printf("%d", T->number); x++; } T = T->next; } if(z == 0) { printf("无该类型的信息"); color(11); tp(39, 16); printf("按任意键返回..."); getch(); cls(); } else { color(11); printf("\n\n按任意键返回..."); getch(); cls(); } } void Publish() { cls(); int z = 0, x = 3; char t[21]; color(12); tp(39, 8); printf("出版社查询"); color(11); tp(39, 10); printf("请输入需要查询的出版社:"); color(8); tp(39, 12); printf("按ESC返回菜单"); color(11); tp(62, 10); user_name(10, t, 17); tp(39, 14); read_book(); T = H; color(12); while(T != NULL) { if(strcmp(t, T->publish) == 0 && z == 0) { cls(); print(); tp(0, x); printf("%s", T->name); tp(24, x); printf("%s", T->author); tp(45, x); printf("%s", T->type); tp(65, x); printf("%s", T->publish); tp(88, x); printf("%d", T->number); x++; z++; } else if(strcmp(t, T->publish) == 0) { tp(0, x); printf("%s", T->name); tp(24, x); printf("%s", T->author); tp(45, x); printf("%s", T->type); tp(65, x); printf("%s", T->publish); tp(88, x); printf("%d", T->number); x++; } T = T->next; } if(z == 0) { printf("无该出版社的信息"); color(11); tp(39, 16); printf("按任意键返回..."); getch(); cls(); } else { color(11); printf("\n\n按任意键返回..."); getch(); cls(); } } void lend_user() { cls(); read_lend(); Temp = Head; int z = 0, x = 3; color(12); while(Temp != NULL) { if(!strcmp(Temp->user, TEMP->name) && z == 0) { color(11); printf("-------------------------------------------------------------------------------------------------\n"); printf(" 书名 作者 类型 出版社\n"); printf("-------------------------------------------------------------------------------------------------\n"); color(12); tp(0, x); printf("%s", Temp->name); tp(28, x); printf("%s", Temp->author); tp(54, x); printf("%s", Temp->type); tp(80, x); printf("%s", Temp->publish); x++; z++; } else if(!strcmp(Temp->user, TEMP->name)) { tp(0, x); printf("%s", Temp->name); tp(28, x); printf("%s", Temp->author); tp(54, x); printf("%s", Temp->type); tp(80, x); printf("%s", Temp->publish); x++; } Temp = Temp->next; } if(z == 0) { tp(39, 8); printf("您未曾借过本图书馆的图书"); color(11); tp(39, 10); printf("按任意键返回..."); getch(); cls(); } else { color(11); printf("\n\n按任意键返回..."); getch(); cls(); } } void view1_book() { cls(); g = 1; color(12); tp(39, 8); printf("图书总览"); color(11); tp(39, 10); printf("| 1.全部 |"); tp(39, 12); printf("| 2.作者查询 |"); tp(39, 14); printf("| 3.类型查询 |"); tp(39, 16); printf("| 4.出版社查询 |"); tp(39, 18); printf("| 5.已借图书 |"); tp(39, 20); printf("| 6.返回菜单 |"); tp(39, 22); printf("| 7.退出 |"); switch(getch()) { case '1':All();view1_book(); case '2':Auth();view1_book(); case '3':Type();view1_book(); case '4':Publish();view1_book(); case '5':lend_user();view1_book(); case '6':g = 0;stu_menu(); case '7':exit(0); case '\e':g = 0;stu_menu(); default :view1_book(); } } void lend_() { cls(); printf("-------------------------------------------------------------------------------------------------\n"); printf(" 书名 作者 类型 出版社 借书人\n"); printf("-------------------------------------------------------------------------------------------------\n"); read_lend(); Temp = Head; int x = 3; color(12); while(Temp != NULL) { tp(0, x); printf("%s", Temp->name); tp(24, x); printf("%s", Temp->author); tp(45, x); printf("%s", Temp->type); tp(65, x); printf("%s", Temp->publish); tp(88, x); printf("%s", Temp->user); x++; Temp = Temp->next; } color(11); printf("\n\n按任意键返回..."); getch(); cls(); } void view2_book() { cls(); g = 1; color(12); tp(39, 8); printf("图书总览"); color(11); tp(39, 10); printf("| 1.全部 |"); tp(39, 12); printf("| 2.作者查询 |"); tp(39, 14); printf("| 3.类型查询 |"); tp(39, 16); printf("| 4.出版社查询 |"); tp(39, 18); printf("| 5.已借图书 |"); tp(39, 20); printf("| 6.返回菜单 |"); tp(39, 22); printf("| 7.退出 |"); switch(getch()) { case '1':All();view2_book(); case '2':Auth();view2_book(); case '3':Type();view2_book(); case '4':Publish();view2_book(); case '5':lend_();view2_book(); case '6':g = 0;adm_menu(); case '7':exit(0); case '\e':g = 0;adm_menu(); default :view2_book(); } } void view_user() { cls(); read_user(); printf("-------------------------------------------------------------------------------------------------\n"); printf(" 姓名 帐号 密码\n"); printf("-------------------------------------------------------------------------------------------------\n"); color(12); TEMP = HEAD; while(TEMP != NULL) { printf("%22s %28s %23s\n", TEMP->name, TEMP->user_id, TEMP->password); TEMP = TEMP->next; } color(11); printf("\n按任意键返回..."); getch(); } void del_user() { struct STUDENT *p = HEAD; if(TEMP == HEAD) { HEAD = TEMP->next; free(TEMP); } else { while(p != NULL && p->next != TEMP) p = p->next; p->next = TEMP->next; free(TEMP); } TEMP = HEAD; FILE *fp = fopen("user.txt", "w"); while(TEMP != NULL) { fprintf(fp, "%s %s %s\n", TEMP->name, TEMP->user_id, TEMP->password); TEMP = TEMP->next; } fclose(fp); color(12); printf("删除用户成功"); tp(39, 26); color(11); printf("按任意键返回..."); tp(39, 28); getch(); } void change_user_ques() { cls(); color(12); tp(39, 8); printf("用户信息"); color(11); tp(39, 10); printf("姓名:%s", TEMP->name); tp(39, 12); printf("帐号:%s", TEMP->user_id); tp(39, 14); printf("密码:%s", TEMP->password); color(12); tp(39, 16); printf("是否修改该用户信息"); tp(39, 18); printf("| 1.是 |"); tp(39, 20); printf("| 2.否 |"); tp(39, 22); printf("| 9.删除用户 |"); tp(39, 24); switch(getch()) { case '1':break; case '2':adm_menu(); case '9':del_user();adm_menu(); case '\e':adm_menu(); default :change_user_ques(); } } void change_user() { cls(); int x = 0; char user[21]; read_user(); color(12); tp(36, 8); printf("请输入需要修改的用户姓名或帐号"); color(8); tp(45, 12); printf("按ESC返回菜单"); color(11); tp(45, 10); user_name(10, user, 0); tp(44, 14); TEMP = HEAD; while(TEMP != NULL) { if(!strcmp(user, TEMP->name) || !strcmp(user, TEMP->user_id)) { x = 1; break; } TEMP = TEMP->next; } if(x) { change_user_ques(); cls(); color(11); tp(30, 8); printf("姓名:%s", TEMP->name); tp(54, 8); printf("->"); tp(30, 10); printf("帐号:%s", TEMP->user_id); tp(54, 10); printf("->"); tp(30, 12); printf("密码:%s", TEMP->password); tp(54, 12); printf("->"); color(8); tp(45, 14); printf("按ESC返回菜单"); color(11); tp(64, 8); user_name(8, TEMP->name, 19); tp(64, 10); user_name(10, TEMP->user_id, 19); tp(64, 12); v = 1; user_name(12, TEMP->password, 19); v = 0; tp(45, 16); TEMP = HEAD; FILE *fp = fopen("user.txt", "w"); while(TEMP != NULL) { fprintf(fp, "%s %s %s\n", TEMP->name, TEMP->user_id, TEMP->password); TEMP = TEMP->next; } fclose(fp); cls(); color(12); tp(39, 8); printf("修改成功"); tp(39, 10); color(11); printf("按任意键返回..."); tp(39, 12); getch(); } else { color(12); printf("未找到相应的信息"); color(11); tp(45, 16); printf("按任意键返回..."); tp(45, 18); getch(); } } void Num(int a) { int x = 0; read_lend(); if(a == -1) { Temp = Head; while(Temp != NULL) { if(!strcmp(Temp->name, T->name) && !strcmp(Temp->author, T->author) && !strcmp(Temp->type, T->type) && !strcmp(Temp->publish, T->publish) && !strcmp(Temp->user, TEMP->name)) { x = 1; break; } Temp = Temp->next; } if(x == 1) { tp(39, 18); printf(" "); tp(39, 20); printf(" "); tp(39, 22); printf(" "); color(12); tp(39, 18); printf("您已借用一本相同的书,请先归还"); color(11); tp(39, 20); printf("按任意键返回..."); tp(39, 22); getch(); return; } else { FILE *fp = fopen("lend.txt", "a+"); fprintf(fp, "%s %s %s %s %s\n", T->name, T->author, T->type, T->publish, TEMP->name); fclose(fp); } } else { Temp = Head; while(Temp != NULL) { if(!strcmp(Temp->name, T->name) && !strcmp(Temp->author, T->author) && !strcmp(Temp->type, T->type) && !strcmp(Temp->publish, T->publish) && !strcmp(Temp->user, TEMP->name)) { x = 1; break; } Temp = Temp->next; } if(x == 1) { struct BOOK *p = Head; if(Temp == Head) { Head = Temp->next; free(Temp); } else { while(p != NULL && p->next != Temp) p = p->next; p->next = Temp->next; free(Temp); } Temp = Head; FILE *fp = fopen("lend.txt", "w"); while(Temp != NULL) { fprintf(fp, "%s %s %s %s %s\n", Temp->name, Temp->author, Temp->type, Temp->publish, Temp->user); Temp = Temp->next; } fclose(fp); } else { tp(39, 18); printf(" "); tp(39, 20); printf(" "); tp(39, 22); printf(" "); color(12); tp(39, 18); printf("您未曾借过这本书(若想存入图书馆,请联系管理员)"); color(11); tp(39, 20); printf("按任意键返回..."); tp(39, 22); getch(); return; } } T->number += a; for(i = H; i != NULL; i = i->next) for(j = i->next; j != NULL; j = j->next) if(i->number > j->number) { Swap(i->name, j->name); Swap(i->author, j->author); Swap(i->type, j->type); Swap(i->publish, j->publish); Swap_num(&i->number, &j->number); } T = H; FILE *fp = fopen("book.txt", "w"); while(T != NULL) { fprintf(fp, "%s %s %s %s %d\n", T->name, T->author, T->type, T->publish, T->number); T = T->next; } fclose(fp); cls(); color(12); tp(39, 8); printf("操作成功"); tp(39, 10); color(11); printf("按任意键返回..."); tp(39, 12); getch(); } void book_printf(int a) { cls(); tp(39, 8); printf("书名:%s", T->name); tp(39, 10); printf("作者:%s", T->author); tp(39, 12); printf("类型:%s", T->type); tp(39, 14); printf("出版社:%s", T->publish); tp(39, 16); printf("数量:%d", T->number); tp(39, 18); if(T->number == 0 && a == -1) { color(12); printf("书本数量不足"); color(11); tp(39, 20); printf("按任意键返回..."); tp(39, 22); getch(); } else if(a == -1){ printf("是否借出"); tp(39, 20); printf("| 1.是 |"); tp(39, 22); printf("| 2.否 |"); tp(39, 24); switch(getch()) { case '1':Num(a);break; case '2':break; case '\e':break; default :book_printf(a); } } else { printf("是否归还"); tp(39, 20); printf("| 1.是 |"); tp(39, 22); printf("| 2.否 |"); tp(39, 24); switch(getch()) { case '1':Num(a);break; case '2':break; case '\e':break; default :book_printf(a); } } } void lend_book() { if(search_book()) book_printf(-1); else no_info(); } void remand_book() { if(search_book()) book_printf(1); else no_info(); } void stu_menu() { cls(); color(12); tp(36, 8); printf("尊敬的%s欢迎您使用图书管理系统", TEMP->name); color(11); tp(39, 10); printf("| 1.图书查询 |"); tp(39, 12); printf("| 2.图书借出 |"); tp(39, 14); printf("| 3.图书归还 |"); tp(39, 16); printf("| 4.图书总览 |"); tp(39, 18); printf("| 5.返回登录界面 |"); tp(39, 20); printf("| 6.退出 |"); tp(39, 22); switch(getch()) { case '1':inquire1();stu_menu(); case '2':lend_book();stu_menu(); case '3':remand_book();stu_menu(); case '4':view1_book();stu_menu(); case '5':Login(); case '6':exit(0); case '\e':exit(0); default :stu_menu(); } } void adm_menu() { cls(); adm_window(); color(12); tp(36, 8); printf("尊敬的管理员欢迎您使用图书管理系统"); color(11); tp(39, 10); printf("| 1.图书查询 |"); tp(39, 12); printf("| 2.修改图书 |"); tp(39, 14); printf("| 3.添加图书 |"); tp(39, 16); printf("| 4.删除图书 |"); tp(39, 18); printf("| 5.图书总览 |"); tp(39, 20); printf("| 6.用户总览 |"); tp(39, 22); printf("| 7.修改用户 |"); tp(39, 24); printf("| 8.返回登录界面 |"); tp(39, 26); printf("| 9.退出 |"); tp(39, 28); switch(getch()) { case '1':inquire2();adm_menu(); case '2':change_book();adm_menu(); case '3':add_book();adm_menu(); case '4':delete_book();adm_menu(); case '5':view2_book();adm_menu(); case '6':view_user();adm_menu(); case '7':change_user();adm_menu(); case '8':recovery_window();Login(); case '9':exit(0); case '\e':exit(0); default :adm_menu(); } }