|
|
#include<stdio.h>
|
|
|
#include<string.h>
|
|
|
#include<stdlib.h>
|
|
|
#include<math.h>
|
|
|
#include<ctype.h>
|
|
|
#include<windows.h>
|
|
|
#include<conio.h>
|
|
|
#define BACKSPACE 8
|
|
|
#define PASS_MAXLEN 128
|
|
|
#define LEN sizeof(struct Book)
|
|
|
#define LEN1 sizeof(struct reader)
|
|
|
//建立书籍的结构体
|
|
|
void toxy(int x, int y)//定位光标位置到指定坐标
|
|
|
{
|
|
|
HANDLE hOut;
|
|
|
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
COORD pos = { x,y };
|
|
|
SetConsoleCursorPosition(hOut, pos);
|
|
|
}
|
|
|
struct Book//图书信息
|
|
|
{
|
|
|
char num[20],nam[20],aut[20],pub[20],cat[20];
|
|
|
int many;
|
|
|
float price;
|
|
|
struct Book *next;
|
|
|
};
|
|
|
struct reader//读者信息
|
|
|
{
|
|
|
int xuehao;
|
|
|
char username[20],time[20],name[20];
|
|
|
struct reader *next;
|
|
|
};
|
|
|
void home();//注册总页面
|
|
|
void Reg();//注册
|
|
|
void Log();//登录
|
|
|
void Adm();//管理员
|
|
|
int UserMenu();//用户主页
|
|
|
int AdminMenu();//管理员主页
|
|
|
void BroBook();//借书
|
|
|
void BacBook();//还书
|
|
|
void LooBook(int n);//查询书籍
|
|
|
void AddBook();//添加书籍
|
|
|
void DelBook();//删除书籍
|
|
|
void FixBook();//修改书籍
|
|
|
int Total();//统计书的总数
|
|
|
int Total1();//统计账户总数->用于修改用户名重复的问题
|
|
|
int Total2();//统计读者总数
|
|
|
void SBAll(int q);//查询所有书籍
|
|
|
void SBAut(int q);//图书作者查询
|
|
|
void SBNam(int q);//图书名字查询
|
|
|
void SBCat(int q);//图书分类查询
|
|
|
void ed();//结束
|
|
|
void Reader();//读者借阅信息
|
|
|
void Readername();//按名字查找借阅
|
|
|
void Allreader();//所有查看
|
|
|
|
|
|
void ed(void)
|
|
|
{
|
|
|
system("cls");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* 图书管理系统(Version 2.0) *\n");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 酱,拜拜咯ヾ(·ω·`)o *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* *\n");
|
|
|
printf("******************************************************************************************\n");
|
|
|
Sleep(1000);
|
|
|
system("cls");
|
|
|
home();
|
|
|
}
|
|
|
//管理员菜单
|
|
|
int AdminMenu(){
|
|
|
system("cls");
|
|
|
char t[10];
|
|
|
while(1){
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* 图书管理系统(Version 2.0) *\n");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* *\n");
|
|
|
printf("* kuo`ni`ji`wa,我的主人: *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 有什么能为您效劳的吗~ *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 1、增加图书。 *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 2、删除图书。 *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 3、查询图书。 *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 4、修改图书信息。 *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 5、查询读者借阅信息 *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 6、没事了,退出。 *\n");
|
|
|
printf("* *\n");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("\n\n\t\t\t\t\t\t\t\t\t您想执行的操作:");
|
|
|
scanf("%s",&t);
|
|
|
if(strcmp(t,"1")==0){
|
|
|
AddBook();
|
|
|
break;
|
|
|
}else if(strcmp(t,"2")==0){
|
|
|
DelBook();
|
|
|
break;
|
|
|
}else if(strcmp(t,"3")==0){
|
|
|
LooBook(1);
|
|
|
break;
|
|
|
}else if(strcmp(t,"4")==0){
|
|
|
FixBook();
|
|
|
break;
|
|
|
}else if(strcmp(t,"6")==0){
|
|
|
ed();
|
|
|
}else if(strcmp(t,"5")==0){
|
|
|
Reader();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
void LooBook(int n){
|
|
|
system("cls");
|
|
|
while(1){
|
|
|
char t;
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* 图书管理系统(Version 2.0) *\n");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 搜索方式: *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 1、按书名查找 *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 2、按作者查找 *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 3、按分类查找 *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 4、全书总览 *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 按ESC返回 *\n");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("\n\n\t\t\t\t\t\t\t\t\t您想执行的操作:");
|
|
|
t=getch();
|
|
|
while(t!='1'&&t!='2'&&t!='3'&&t!='4'&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t=='1'){
|
|
|
SBNam(n);
|
|
|
break;
|
|
|
}else if(t=='2'){
|
|
|
SBAut(n);
|
|
|
break;
|
|
|
}else if(t=='3'){
|
|
|
SBCat(n);
|
|
|
break;
|
|
|
}else if(t=='4'){
|
|
|
SBAll(n);
|
|
|
break;
|
|
|
}
|
|
|
else if(t==27){
|
|
|
if(n==0){
|
|
|
UserMenu();
|
|
|
}else if(n==1){
|
|
|
AdminMenu();
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void SBAll(int q){
|
|
|
system("cls");
|
|
|
int n=0;
|
|
|
int m=0,Many=0;
|
|
|
float Price=0;
|
|
|
char t,ReName[100];
|
|
|
int i=0,k=0,j=0;
|
|
|
char Num[20]={'\0'},Aut[20]={'\0'},Pub[20]={'\0'},Nam[20]={'\0'},Cat[20]={'\0'};
|
|
|
FILE *fp;
|
|
|
fp=fopen("图书.txt","r");
|
|
|
if(fp=NULL){
|
|
|
system("cls");
|
|
|
printf("出错了,请联系管理员,按Esc键返回\n");
|
|
|
t=getch();
|
|
|
for(;t!=27;)
|
|
|
t=getch();
|
|
|
if(q==0){
|
|
|
UserMenu();
|
|
|
}else if(q==1){
|
|
|
AdminMenu();
|
|
|
}
|
|
|
}else{
|
|
|
j=Total();
|
|
|
fp=fopen("图书.txt","r");
|
|
|
for(int m=0;m<j;m++){
|
|
|
fscanf(fp,"%s%s%s%s%s%d%f",Num,Nam,Aut,Pub,Cat,&Many,&Price);
|
|
|
n++;
|
|
|
if(n==1){
|
|
|
printf("查询结果:\n");
|
|
|
printf("书号\t书名\t作者\t\t出版社\t\t类别\t\t现存量\t\t单价\n");
|
|
|
}
|
|
|
printf("%-8s%-8s%-16s%-16s%-16s%-10d%10.2f\n",Num,Nam,Aut,Pub,Cat,Many,Price);
|
|
|
|
|
|
}
|
|
|
fclose(fp);
|
|
|
printf("按Esc键返回\n");
|
|
|
t=getch();
|
|
|
for(;t!=27;){
|
|
|
t=getch();
|
|
|
}
|
|
|
if(q==0){
|
|
|
UserMenu();
|
|
|
}else if(q==1){
|
|
|
AdminMenu();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void SBAut(int q){
|
|
|
system("cls");
|
|
|
struct Book *head;
|
|
|
struct Book *p1,*p2;
|
|
|
FILE *fp;
|
|
|
int n=0;
|
|
|
int m=0,Many=0;
|
|
|
float Price=0;
|
|
|
char t,ReName[100];
|
|
|
int i=0,k=0,j=0;
|
|
|
char Num[20]={'\0'},Aut[20]={'\0'},Pub[20]={'\0'},Nam[20]={'\0'},Cat[20]={'\0'};
|
|
|
if((fp=fopen("图书.txt","r"))==NULL){
|
|
|
printf("无法打开该文件\n");
|
|
|
printf("按ESC键返回\n");
|
|
|
t=getch();
|
|
|
while(t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
UserMenu();
|
|
|
}
|
|
|
else{
|
|
|
printf("请输入你想要查找书的作者名字:\n");
|
|
|
scanf("%s",ReName);
|
|
|
j=Total();
|
|
|
for(int i=0;i<j;i++){
|
|
|
fscanf(fp,"%s%s%s%s%s%d%f",Num,Nam,Aut,Pub,Cat,&Many,&Price);
|
|
|
if(strcmp(Aut,ReName)==0){
|
|
|
if(k==0){
|
|
|
printf("查询结果是:\n");
|
|
|
printf("书号\t书名\t作者\t\t出版社\t\t类别\t\t现存量\t\t单价\n");
|
|
|
}
|
|
|
k++;
|
|
|
printf("%-8s%-8s%-16s%-16s%-16s%-10d%10.2f\n",Num,Nam,Aut,Pub,Cat,Many,Price);
|
|
|
}
|
|
|
}
|
|
|
if(k==0){
|
|
|
printf("\n无符合条件的书籍\n");
|
|
|
printf("按Esc键回到主页面,按回车键继续查询\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
SBAut(q);
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
if(q==0){
|
|
|
UserMenu();
|
|
|
}else if(q==1){
|
|
|
AdminMenu();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
printf("继续查询请按回车键,退出查询返回主菜单请按ESC\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
SBAut(q);
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
if(q==0){
|
|
|
UserMenu();
|
|
|
}else if(q==1){
|
|
|
AdminMenu();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
void SBNam(int q){
|
|
|
system("cls");
|
|
|
struct Book *head;
|
|
|
struct Book *p1,*p2;
|
|
|
FILE *fp;
|
|
|
int n=0;
|
|
|
int m=0,Many=0;
|
|
|
float Price=0;
|
|
|
char t,ReName[100];
|
|
|
int i=0,k=0,j=0;
|
|
|
char Num[20]={'\0'},Aut[20]={'\0'},Pub[20]={'\0'},Nam[20]={'\0'},Cat[20]={'\0'};
|
|
|
if((fp=fopen("图书.txt","r"))==NULL){
|
|
|
printf("无法打开该文件\n");
|
|
|
printf("按ESC键返回\n");
|
|
|
t=getch();
|
|
|
while(t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
UserMenu();
|
|
|
}
|
|
|
else{
|
|
|
printf("请输入你想要查找书的名字:\n");
|
|
|
scanf("%s",ReName);
|
|
|
j=Total();
|
|
|
for(int i=0;i<j;i++){
|
|
|
fscanf(fp,"%s%s%s%s%s%d%f",Num,Nam,Aut,Pub,Cat,&Many,&Price);
|
|
|
if(strcmp(Nam,ReName)==0){
|
|
|
if(k==0){
|
|
|
printf("查询结果是:\n");
|
|
|
printf("书号\t书名\t作者\t\t出版社\t\t类别\t\t现存量\t\t单价\n");
|
|
|
}
|
|
|
k++;
|
|
|
printf("%-8s%-8s%-16s%-16s%-16s%-10d%10.2f\n",Num,Nam,Aut,Pub,Cat,Many,Price);
|
|
|
}
|
|
|
}
|
|
|
if(k==0){
|
|
|
printf("\n无符合条件的书籍\n");
|
|
|
printf("按Esc键回到主页面,按回车键继续查询\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
SBAut(q);
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
if(q==0){
|
|
|
UserMenu();
|
|
|
}else if(q==1){
|
|
|
AdminMenu();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
printf("继续查询请按回车键,退出查询返回主菜单请按ESC\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
SBAut(q);
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
if(q==0){
|
|
|
UserMenu();
|
|
|
}else if(q==1){
|
|
|
AdminMenu();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void SBCat(int q){
|
|
|
system("cls");
|
|
|
struct Book *head;
|
|
|
struct Book *p1,*p2;
|
|
|
FILE *fp;
|
|
|
int n=0;
|
|
|
int m=0,Many=0;
|
|
|
float Price=0;
|
|
|
char t,ReName[100];
|
|
|
int i=0,k=0,j=0;
|
|
|
char Num[20]={'\0'},Aut[20]={'\0'},Pub[20]={'\0'},Nam[20]={'\0'},Cat[20]={'\0'};
|
|
|
if((fp=fopen("图书.txt","r"))==NULL){
|
|
|
printf("无法打开该文件\n");
|
|
|
printf("按ESC键返回\n");
|
|
|
t=getch();
|
|
|
while(t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
UserMenu();
|
|
|
}
|
|
|
else{
|
|
|
printf("请输入你想要查找书的类别:\n");
|
|
|
scanf("%s",ReName);
|
|
|
j=Total();
|
|
|
for(int i=0;i<j;i++){
|
|
|
fscanf(fp,"%s%s%s%s%s%d%f",Num,Nam,Aut,Pub,Cat,&Many,&Price);
|
|
|
if(strcmp(Cat,ReName)==0){
|
|
|
if(k==0){
|
|
|
printf("查询结果是:\n");
|
|
|
printf("书号\t书名\t作者\t\t出版社\t\t类别\t\t现存量\t\t单价\n");
|
|
|
}
|
|
|
k++;
|
|
|
printf("%-8s%-8s%-16s%-16s%-16s%-10d%10.2f\n",Num,Nam,Aut,Pub,Cat,Many,Price);
|
|
|
}
|
|
|
}
|
|
|
if(k==0){
|
|
|
printf("\n无符合条件的书籍\n");
|
|
|
printf("按Esc键回到主页面,按回车键继续查询\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
SBCat(q);
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
if(q==0){
|
|
|
UserMenu();
|
|
|
}else if(q==1){
|
|
|
AdminMenu();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
printf("继续查询请按回车键,退出查询返回主菜单请按ESC\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
SBAut(q);
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
if(q==0){
|
|
|
UserMenu();
|
|
|
}else if(q==1){
|
|
|
AdminMenu();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//增加书籍
|
|
|
void AddBook(){
|
|
|
system("cls");
|
|
|
int Many;
|
|
|
float Price;
|
|
|
FILE *fp;
|
|
|
int i;
|
|
|
char Num[20]={'\0'},Aut[20]={'\0'},Pub[20]={'\0'},Nam[20]={'\0'},Cat[20]={'\0'};
|
|
|
if((fp=fopen("图书.txt","r"))==NULL){
|
|
|
fp=fopen("图书.txt","w+");
|
|
|
fclose(fp);
|
|
|
}
|
|
|
fp=fopen("图书.txt","a");// ************************
|
|
|
printf("请输入书号:");scanf("%s",Num);
|
|
|
printf("请输入书名:");scanf("%s",Nam);
|
|
|
printf("请输入作者:");scanf("%s",Aut);
|
|
|
printf("请输入出版社:");scanf("%s",Pub);
|
|
|
printf("请输入图书类别:");scanf("%s",Cat);
|
|
|
printf("请输入图书数量:");scanf("%d",&Many);
|
|
|
printf("请输入图书价格(最多两位小数):");scanf("%f",&Price);
|
|
|
fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",Num,Nam,Aut,Pub,Cat,Many,Price);
|
|
|
system("cls");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t┌──────────────────────────────────────────────┐\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ 正在写入图书信息. │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(500);
|
|
|
system("cls");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t┌──────────────────────────────────────────────┐\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ 正在写入图书信息.. │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(500);
|
|
|
system("cls");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t┌──────────────────────────────────────────────┐\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ 正在写入图书信息... │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(500);
|
|
|
system("cls");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t┌──────────────────────────────────────────────┐\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ 正在写入图书信息. │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(500);
|
|
|
system("cls");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t┌──────────────────────────────────────────────┐\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ 正在写入图书信息.. │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(500);
|
|
|
system("cls");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t┌──────────────────────────────────────────────┐\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ 操作成功,是否要继续增加? │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t├───────────────────────┬──────────────────────│\n");
|
|
|
printf("\t\t\t│ 1.是 │ 2.否 │\n");
|
|
|
printf("\t\t\t└───────────────────────┴ ─────────────────────┘\n");
|
|
|
fclose(fp);
|
|
|
char t;
|
|
|
while(1) //利用死循环可有效防止其他按键干扰
|
|
|
{
|
|
|
t=getch();
|
|
|
if(t=='1') AddBook();
|
|
|
else if(t=='2') AdminMenu();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//删除书籍
|
|
|
void DelBook(){
|
|
|
system("cls");
|
|
|
struct Book *head;
|
|
|
struct Book *p,*p1,*p2;
|
|
|
FILE *fp;
|
|
|
int n=0;
|
|
|
int m=0,Many=0;
|
|
|
float Price=0;
|
|
|
char t;
|
|
|
int i=0,k=0,j=0;
|
|
|
char Num[20]={'\0'},Aut[20]={'\0'},Pub[20]={'\0'},Nam[20]={'\0'},Cat[20]={'\0'};
|
|
|
char ReName[20]={'\0'};
|
|
|
if((fp=fopen("图书.txt","r"))==NULL){
|
|
|
printf("无法找到该文件,按任意键返回\n");
|
|
|
t=getch();
|
|
|
AdminMenu();
|
|
|
}else{
|
|
|
printf("请输入你想要删除的书籍书号:\n");
|
|
|
scanf("%s",ReName);
|
|
|
printf("按回车键继续删除,按ESC键取消\n");
|
|
|
for(;t!=13&&t!=27;)
|
|
|
t=getch();
|
|
|
if(t==27){
|
|
|
AdminMenu();
|
|
|
}
|
|
|
fp=fopen("图书.txt","r");
|
|
|
j=Total();
|
|
|
|
|
|
for(k=0;k<j;k++){
|
|
|
fscanf(fp,"%s%s%s%s%s%d%f",Num,Nam,Aut,Pub,Cat,&Many,&Price);
|
|
|
if(strcmp(Num,ReName)){
|
|
|
n++;
|
|
|
if(n==1){
|
|
|
p1=p2=(struct Book*)malloc(LEN);
|
|
|
head=p1;
|
|
|
}
|
|
|
else{
|
|
|
p2->next =p1;
|
|
|
p2=p1;
|
|
|
p1=(struct Book*)malloc(LEN);
|
|
|
}
|
|
|
strcpy(p1->num,Num);//复制书号
|
|
|
strcpy(p1->nam,Nam);//复制书名
|
|
|
strcpy(p1->aut,Aut);//复制作者名字
|
|
|
strcpy(p1->pub,Pub);//复制出版社
|
|
|
strcpy(p1->cat,Cat);//复制类别
|
|
|
p1->many=Many;//复制个数
|
|
|
p1->price=Price;//复制单价
|
|
|
}
|
|
|
}
|
|
|
if(n==0){
|
|
|
head=NULL;
|
|
|
}else{
|
|
|
p2->next=p1;
|
|
|
p1->next=NULL;
|
|
|
fclose(fp);
|
|
|
}
|
|
|
}
|
|
|
fp=fopen("图书.txt","w");
|
|
|
fclose(fp);
|
|
|
fp=fopen("图书.txt","a");
|
|
|
p=head;
|
|
|
|
|
|
for(;p!=NULL;){
|
|
|
fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",p->num,p->nam,p->aut,p->pub,p->cat,p->many,p->price);
|
|
|
p=p->next;
|
|
|
}
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("删除成功,按任意键返回上一层\n");
|
|
|
t=getch();
|
|
|
AdminMenu();
|
|
|
}
|
|
|
|
|
|
//修改书籍
|
|
|
void FixBook(){
|
|
|
system("cls");
|
|
|
struct Book *head,*p1,*p2,*p;
|
|
|
int i,n;
|
|
|
char Rename[100];
|
|
|
char Num[20],Nam[20],Aut[20],Pub[20],Cat[20];
|
|
|
int Many;
|
|
|
float Price;
|
|
|
printf("请输入您要修改图书的书名:");
|
|
|
scanf("%s",Rename);
|
|
|
FILE *fp;
|
|
|
fp = fopen("图书.txt","r");
|
|
|
n = Total();
|
|
|
int count=0;
|
|
|
int k=0;
|
|
|
for(i=0;i<n;i++)
|
|
|
{
|
|
|
fscanf(fp,"%s%s%s%s%s%d%f",Num,Nam,Aut,Pub,Cat,&Many,&Price);
|
|
|
if(strcmp(Rename,Nam)==0)
|
|
|
{
|
|
|
count++;//查无此书
|
|
|
if(k==0){
|
|
|
printf("查询的图书如下:\n");
|
|
|
printf("书号\t书名\t作者\t\t出版社\t\t类别\t\t现存量\t\t单价\n");
|
|
|
}
|
|
|
k++;
|
|
|
printf("%-8s%-8s%-16s%-16s%-16s%-10d%10.2f\n",Num,Nam,Aut,Pub,Cat,Many,Price);
|
|
|
}
|
|
|
}
|
|
|
char op;
|
|
|
if(count==0)
|
|
|
{
|
|
|
printf("没有这本书,重新查询请按回车,退出请按ESC");
|
|
|
while(1)
|
|
|
{
|
|
|
op = getch();
|
|
|
if(op==13) break;
|
|
|
if(op==27) AdminMenu();
|
|
|
}
|
|
|
}
|
|
|
printf("是否为您想修改的图书?修改请按回车,否则请按ESC");
|
|
|
while(1)
|
|
|
{
|
|
|
op = getch();
|
|
|
if(op==13) break;
|
|
|
if(op==27) AdminMenu();
|
|
|
}
|
|
|
int j=0;
|
|
|
fclose(fp);
|
|
|
fp = fopen("图书.txt","r");
|
|
|
for(i=0;i<n;i++)
|
|
|
{
|
|
|
fscanf(fp,"%s%s%s%s%s%d%f",Num,Nam,Aut,Pub,Cat,&Many,&Price);
|
|
|
if(strcmp(Nam,Rename)!=0){
|
|
|
j++;
|
|
|
if(j==1){
|
|
|
p1=p2=head=(struct Book*)malloc(LEN);
|
|
|
head = p1;
|
|
|
}
|
|
|
else{
|
|
|
p2->next=p1;
|
|
|
p2=p1;
|
|
|
p1=(struct Book*)malloc(LEN);
|
|
|
}
|
|
|
strcpy(p1->num,Num);//复制书号
|
|
|
strcpy(p1->nam,Nam);//复制书名
|
|
|
strcpy(p1->aut,Aut);//复制作者名字
|
|
|
strcpy(p1->pub,Pub);//复制出版社
|
|
|
strcpy(p1->cat,Cat);//复制类别
|
|
|
p1->many=Many;//复制个数
|
|
|
p1->price=Price;//复制单价
|
|
|
}
|
|
|
}
|
|
|
if(n==0){
|
|
|
head = NULL;
|
|
|
}
|
|
|
else{
|
|
|
p2->next=p1;
|
|
|
p1->next=NULL;
|
|
|
fclose(fp);
|
|
|
}
|
|
|
fp=fopen("图书.txt","w");
|
|
|
fclose(fp);
|
|
|
fp=fopen("图书.txt","a");
|
|
|
p=head;
|
|
|
|
|
|
for(;p!=NULL;){
|
|
|
fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",p->num,p->nam,p->aut,p->pub,p->cat,p->many,p->price);
|
|
|
p=p->next;
|
|
|
}
|
|
|
fclose(fp);
|
|
|
fp = fopen("图书.txt","a");
|
|
|
system("cls");
|
|
|
printf("请输入书号:");scanf("%s",Num);
|
|
|
printf("请输入书名:");scanf("%s",Nam);
|
|
|
printf("请输入作者:");scanf("%s",Aut);
|
|
|
printf("请输入出版社:");scanf("%s",Pub);
|
|
|
printf("请输入图书类别:");scanf("%s",Cat);
|
|
|
printf("请输入图书数量:");scanf("%d",&Many);
|
|
|
printf("请输入图书价格(最多两位小数):");scanf("%f",&Price);
|
|
|
fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",Num,Nam,Aut,Pub,Cat,Many,Price);
|
|
|
system("cls");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t┌──────────────────────────────────────────────┐\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ 正在写入图书信息. │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(500);
|
|
|
system("cls");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t┌──────────────────────────────────────────────┐\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ 正在写入图书信息.. │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(500);
|
|
|
system("cls");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t┌──────────────────────────────────────────────┐\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ 正在写入图书信息... │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(500);
|
|
|
system("cls");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t┌──────────────────────────────────────────────┐\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ 正在写入图书信息. │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(500);
|
|
|
system("cls");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t┌──────────────────────────────────────────────┐\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ 正在写入图书信息.. │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(500);
|
|
|
system("cls");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t┌──────────────────────────────────────────────┐\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ 操作成功,是否要继续? │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t├───────────────────────┬──────────────────────│\n");
|
|
|
printf("\t\t\t│ 1.是 │ 2.否 │\n");
|
|
|
printf("\t\t\t└───────────────────────┴ ─────────────────────┘\n");
|
|
|
fclose(fp);
|
|
|
char t;
|
|
|
while(1) //利用死循环可有效防止其他按键干扰
|
|
|
{
|
|
|
t=getch();
|
|
|
if(t=='1') AddBook();
|
|
|
else if(t=='2') AdminMenu();
|
|
|
}
|
|
|
}
|
|
|
//统计图书数量
|
|
|
int Total(){
|
|
|
FILE *fp;
|
|
|
int txcl=0,n;
|
|
|
float tprice=0;
|
|
|
char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'},tkind[20]={'\0'},tshuhao[20]={'\0'};
|
|
|
|
|
|
fp=fopen("图书.txt","r");//打开文件
|
|
|
|
|
|
for (n=0;!feof(fp);n++)//逐个读文件
|
|
|
fscanf(fp,"%s%s%s%s%s%d%f",tshuhao,tname,tauthor,tchuban,tkind,&txcl,&tprice);
|
|
|
n--;//减去最后一个
|
|
|
fclose(fp);//关闭文件
|
|
|
return (n);//返回个数
|
|
|
}
|
|
|
//统计账号数量
|
|
|
int Total1(){
|
|
|
int n;
|
|
|
char name[100],password[100];
|
|
|
FILE *fp=fopen("账号管理.txt","r");
|
|
|
for(n=0;!feof(fp);n++){
|
|
|
fscanf(fp,"%s%s",name,password);
|
|
|
}
|
|
|
n--;
|
|
|
fclose(fp);
|
|
|
return (n);
|
|
|
}
|
|
|
//统计读者数量
|
|
|
int Total2(){
|
|
|
int n;
|
|
|
int num;
|
|
|
char username[20],time[20],name[20];
|
|
|
FILE *fp=fopen("读者.txt","r");
|
|
|
for(n=0;!feof(fp);n++){
|
|
|
fscanf(fp,"%d%s%s%s",&num,username,time,name);
|
|
|
}
|
|
|
n--;
|
|
|
fclose(fp);
|
|
|
return (n);
|
|
|
}
|
|
|
void Reader()
|
|
|
{
|
|
|
system("cls");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* 图书管理系统(Version 2.0) *\n");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 搜索方式: *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 1、按账号查找 *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 2、所有借书总览 *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 按ESC返回 *\n");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("\n\n\t\t\t\t\t\t\t\t\t您想执行的操作:");
|
|
|
char op;
|
|
|
while(1)
|
|
|
{
|
|
|
op = getch();
|
|
|
if(op=='1') Readername();
|
|
|
else if(op=='2') Allreader();
|
|
|
else if(op==27) AdminMenu();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void Readername()
|
|
|
{
|
|
|
system("cls");
|
|
|
printf("您想查看的读者的名字:");
|
|
|
char Name[100];
|
|
|
char username[100],time[100],name[100];
|
|
|
int num;
|
|
|
scanf("%s",Name);
|
|
|
FILE *fp;
|
|
|
fp = fopen("读者.txt","r");
|
|
|
int n = Total2();
|
|
|
int i;int count=0;
|
|
|
for(i=0;i<n;i++)
|
|
|
{
|
|
|
fscanf(fp,"%d%s%s%s",&num,username,time,name);
|
|
|
if(strcmp(Name,username)==0)
|
|
|
{
|
|
|
count++;
|
|
|
if(count==1) {
|
|
|
printf("**************借阅明细****************\n");
|
|
|
printf("学号 姓名 借阅时间 书名\n");
|
|
|
}
|
|
|
printf("%-16d%-8s%-10s%s\n",num,username,time,name);
|
|
|
}
|
|
|
}
|
|
|
fclose(fp);
|
|
|
if(!count){
|
|
|
printf("未找到信息,请确认后再试!将返回管理员菜单!");
|
|
|
Sleep(1000);
|
|
|
AdminMenu();
|
|
|
}
|
|
|
system("pause");
|
|
|
AdminMenu();
|
|
|
}
|
|
|
|
|
|
void Allreader()
|
|
|
{
|
|
|
system("cls");
|
|
|
FILE *fp;
|
|
|
fp = fopen("读者.txt","r");
|
|
|
char Name[100];
|
|
|
char username[100],time[100],name[100];
|
|
|
int num;
|
|
|
int n = Total2();
|
|
|
int i;int count=0;
|
|
|
for(i=0;i<n;i++)
|
|
|
{
|
|
|
fscanf(fp,"%d%s%s%s",&num,username,time,name);
|
|
|
count++;
|
|
|
if(count==1) {
|
|
|
printf("**************借阅明细****************\n");
|
|
|
printf("学号 姓名 借阅时间 书名\n");
|
|
|
}
|
|
|
printf("%-16d%-8s%-10s%s\n",num,username,time,name);
|
|
|
}
|
|
|
fclose(fp);
|
|
|
if(!count){
|
|
|
printf("未找到信息,请确认后再试!将返回管理员菜单!");
|
|
|
AdminMenu();}
|
|
|
system("pause");
|
|
|
AdminMenu();
|
|
|
}
|