|
|
#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)
|
|
|
|
|
|
void start();
|
|
|
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 SBAut();
|
|
|
int SBNam();
|
|
|
int SBCat();
|
|
|
|
|
|
int main(){
|
|
|
home();
|
|
|
}
|
|
|
|
|
|
//建立书籍的结构体
|
|
|
|
|
|
struct Book//图书信息
|
|
|
{
|
|
|
char num[20],nam[20],aut[20],pub[20],cat[20];
|
|
|
int many;
|
|
|
float price;
|
|
|
struct Book *next;
|
|
|
};
|
|
|
struct reader{
|
|
|
int num;
|
|
|
char username[20],time[20],name[20];
|
|
|
struct reader *next;
|
|
|
};
|
|
|
|
|
|
|
|
|
//主页面
|
|
|
void home(){
|
|
|
system("cls");
|
|
|
while(1){
|
|
|
char c;
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* 图书管理系统(Version 1.0 BETA) *\n");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 你好呀,欢迎使用图书管理系统! *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 请问你想干什么呢? *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 麻烦按下数字表示您要执行的操作 *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* *\n");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("*您是普通用户吗?? * 你是我的Master吗?? *\n");
|
|
|
printf("* * *\n");
|
|
|
printf("* 1.注册用户,和我签订契约吧o(* ̄▽ ̄*)ブ * 3.Master登陆 (*/▽\*) *\n");
|
|
|
printf("* 2.契约签订好了?直接登陆吧 * *\n");
|
|
|
printf("* * *\n");
|
|
|
printf("******************************************************************************************\n\n\n");
|
|
|
printf("\t\t\t\t\t\t\t\t\t您想执行的操作:");
|
|
|
c=getch();
|
|
|
if(c=='1'){
|
|
|
Reg();
|
|
|
break;
|
|
|
}else if(c=='2'){
|
|
|
Log();
|
|
|
break;
|
|
|
}else if (c=='3'){
|
|
|
Adm();
|
|
|
}else{
|
|
|
printf("WRONG!!");
|
|
|
}
|
|
|
|
|
|
Sleep(1000);
|
|
|
system("cls");//清屏
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//注册
|
|
|
void Reg(){
|
|
|
FILE *fp=fopen("D:\\图书管理系统\\账号管理.txt","r");
|
|
|
fp=fopen("D:\\图书管理系统\\账号管理.txt","r");
|
|
|
system("cls");
|
|
|
int k=0;
|
|
|
char t;
|
|
|
static char UserName[50],PassWord[10],RePassWord[10];
|
|
|
char name[100],password[100];
|
|
|
printf("输入用户名:\n");//输入用户名
|
|
|
scanf("%s",UserName);
|
|
|
printf("请输入你的密码:\n");//输入密码
|
|
|
while(1){
|
|
|
int i=0;
|
|
|
char c;
|
|
|
while(1){
|
|
|
c=getch();
|
|
|
if(c=='\n'||c=='\r'){
|
|
|
PassWord[i]=0;
|
|
|
break;
|
|
|
}
|
|
|
else if(c==BACKSPACE){
|
|
|
PassWord[--i]='\0';
|
|
|
putchar(BACKSPACE);
|
|
|
putchar(' ');
|
|
|
putchar(BACKSPACE);
|
|
|
}//可以用DELETE键
|
|
|
else{
|
|
|
PassWord[i++]=c;
|
|
|
putchar('*');
|
|
|
}
|
|
|
}
|
|
|
i=0;
|
|
|
printf("\n");
|
|
|
printf("请确定你的密码:\n");//确认密码
|
|
|
while(1){
|
|
|
c=getch();
|
|
|
if(c=='\n'||c=='\r'){
|
|
|
RePassWord[i]=0;
|
|
|
break;
|
|
|
}
|
|
|
else if(c==8)
|
|
|
{
|
|
|
if(i==0) i=0;
|
|
|
else
|
|
|
{
|
|
|
printf("\b \b");
|
|
|
i=i-1;
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
RePassWord[i++]=c;
|
|
|
putchar('*');
|
|
|
}
|
|
|
}
|
|
|
printf("\n");
|
|
|
int j=Total1();//一共有j个用户,Total是用来统计文本里面有多少个用户的
|
|
|
for(int i=0;i<j;i++){
|
|
|
fscanf(fp,"%s %s",name,password);//用文档里面的name一个一个和UserName进行比较如果发现有一样的就k++
|
|
|
if(strcmp(UserName,name)==0){
|
|
|
k++;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if(k==0){
|
|
|
if(strcmp(PassWord,RePassWord)==0){
|
|
|
char t;
|
|
|
fprintf(fp,"%s %s",UserName,PassWord);
|
|
|
fputs("\n",fp);
|
|
|
fflush(stdin);
|
|
|
fclose(fp);
|
|
|
printf("注册成功,是否继续登录,确认请按回车,按任意键返回菜单\n");
|
|
|
t=getch();
|
|
|
if(t==13){
|
|
|
Log();
|
|
|
break;
|
|
|
}
|
|
|
home();
|
|
|
}else {
|
|
|
printf("两次密码不一样,请重新注册\n");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
Reg();
|
|
|
}
|
|
|
}else{
|
|
|
printf("用户名已经被占用\n重新注册请按回车,回到主页面请按ESC\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
Reg();
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
home();
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//登录
|
|
|
void Log(){
|
|
|
system("cls");
|
|
|
char UserName[50],PassWord[100];
|
|
|
char name[50],password[100];
|
|
|
char c;
|
|
|
int i=0;
|
|
|
int k=0;
|
|
|
char t;
|
|
|
FILE *fp=fopen("D:\\图书管理系统\\账号管理.txt","r");
|
|
|
printf("欢迎来到登录界面\n");
|
|
|
printf("请输入你的用户名\n");
|
|
|
while(1){
|
|
|
c=getch();
|
|
|
if(c=='\r'||c=='\n'){
|
|
|
UserName[i]=0;
|
|
|
break;
|
|
|
}
|
|
|
else if(c==8)
|
|
|
{
|
|
|
if(i==0) i=0;
|
|
|
else
|
|
|
{
|
|
|
printf("\b \b");
|
|
|
i=i-1;
|
|
|
}
|
|
|
}else if((c<='Z'&&c>='A')||(c<='z'&&c>='a')||(c<='9'&&c>='0')){
|
|
|
UserName[i++]=c;
|
|
|
putchar(c);
|
|
|
}
|
|
|
}
|
|
|
printf("\n请输入你的密码:\n");
|
|
|
i=0;
|
|
|
while(1){
|
|
|
c=getch();
|
|
|
if(c=='\r'||c=='\n'){
|
|
|
PassWord[i]=0;
|
|
|
break;
|
|
|
}
|
|
|
else if(c==8)
|
|
|
{
|
|
|
if(i==0) i=0;
|
|
|
else
|
|
|
{
|
|
|
printf("\b \b");
|
|
|
i=i-1;
|
|
|
}
|
|
|
}
|
|
|
else if((c<='Z'&&c>='A')||(c<='z'&&c>='a')||(c<='9'&&c>='0')){
|
|
|
PassWord[i++]=c;
|
|
|
putchar('*');
|
|
|
}
|
|
|
}
|
|
|
int j=Total1();
|
|
|
for(int f=0;f<j;f++){
|
|
|
fscanf(fp,"%s%s",name,password);
|
|
|
if(strcmp(UserName,name)==0){
|
|
|
if(strcmp(PassWord,password)==0){
|
|
|
printf("登录成功\n");
|
|
|
printf("正在跳转用户界面...\n");
|
|
|
Sleep(1000);
|
|
|
UserMenu();
|
|
|
break;
|
|
|
}else{
|
|
|
printf("用户名和密码不匹配,重新登录请按回车,回到主菜单请按Esc\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
Log();
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
home();
|
|
|
}
|
|
|
}
|
|
|
k++;
|
|
|
}
|
|
|
}
|
|
|
if(k==0){
|
|
|
printf("用户名不存在\n");
|
|
|
printf("注册请按1,登录请按2,退出请按Esc");
|
|
|
t=getch();
|
|
|
while(t!='1'&&t!='2'&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t=='1'){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
Reg();
|
|
|
}else if(t=='2'){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
Log();
|
|
|
}else if(t==27){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
home();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//管理员
|
|
|
void Adm(){
|
|
|
system("cls");
|
|
|
char c;
|
|
|
int k=0;
|
|
|
char AdminName[50],PassWord[10],t;
|
|
|
char name[100],password[100];
|
|
|
int i=0;
|
|
|
FILE *fp=fopen("D:\\图书管理系统\\管理员专属.txt","r");
|
|
|
printf("欢迎来到管理员界面\n");
|
|
|
printf("请输入你的管理员用户名字:\n");
|
|
|
while(1){
|
|
|
c=getch();
|
|
|
if(c=='\r'||c=='\n'){
|
|
|
AdminName[i]=0;
|
|
|
break;
|
|
|
}
|
|
|
else if(c==8)
|
|
|
{
|
|
|
if(i==0) i=0;
|
|
|
else
|
|
|
{
|
|
|
printf("\b \b");
|
|
|
i=i-1;
|
|
|
}
|
|
|
}else if((c<='Z'&&c>='A')||(c<='z'&&c>='a')||(c<='9'&&c>='0')){
|
|
|
AdminName[i++]=c;
|
|
|
putchar(c);
|
|
|
}
|
|
|
}
|
|
|
printf("\n请输入你的密码:\n");
|
|
|
i=0;
|
|
|
while(1){
|
|
|
c=getch();
|
|
|
if(c=='\r'||c=='\n'){
|
|
|
PassWord[i]=0;
|
|
|
break;
|
|
|
}
|
|
|
else if(c==8)
|
|
|
{
|
|
|
if(i==0) i=0;
|
|
|
else
|
|
|
{
|
|
|
printf("\b \b");
|
|
|
i=i-1;
|
|
|
}
|
|
|
}
|
|
|
else if((c<='Z'&&c>='A')||(c<='z'&&c>='a')||(c<='9'&&c>='0')){
|
|
|
PassWord[i++]=c;
|
|
|
putchar('*');
|
|
|
}
|
|
|
}
|
|
|
int j=1;
|
|
|
for(int f=0;f<j;f++){
|
|
|
fscanf(fp,"%s%s",name,password);
|
|
|
if(strcmp(AdminName,name)==0){
|
|
|
if(strcmp(PassWord,password)==0){
|
|
|
printf("登录成功\n");
|
|
|
printf("正在跳转用户界面...\n");
|
|
|
Sleep(1000);
|
|
|
AdminMenu();
|
|
|
break;
|
|
|
}else{
|
|
|
printf("用户名和密码不匹配,重新登录请按回车,回到主菜单请按Esc\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
Log();
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
home();
|
|
|
}
|
|
|
}
|
|
|
k++;
|
|
|
}
|
|
|
}
|
|
|
if(k==0){
|
|
|
printf("用户名不存在\n");
|
|
|
printf("退出请按Esc");
|
|
|
t=getch();
|
|
|
while(t!='1'&&t!='2'&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==27){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
home();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//管理员菜单
|
|
|
int AdminMenu(){
|
|
|
system("cls");
|
|
|
char t[10];
|
|
|
while(1){
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* 图书管理系统(Version 1.0 BETA) *\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("******************************************************************************************\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,"5")==0){
|
|
|
printf("Bye~~~");
|
|
|
return 0;
|
|
|
}else{
|
|
|
printf("Wrong");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//用户菜单
|
|
|
int UserMenu(){
|
|
|
system("cls");
|
|
|
char t[10];
|
|
|
while(1)
|
|
|
{
|
|
|
system("cls");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* 图书管理系统(Version 1.0 BETA) *\n");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* *\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("\n\n\t\t\t\t\t\t\t\t\t您想执行的操作:");
|
|
|
scanf("%s",t);
|
|
|
if(strcmp(t,"1")==0){
|
|
|
BroBook();
|
|
|
break;
|
|
|
}else if(strcmp(t,"2")==0){
|
|
|
BacBook();
|
|
|
break;
|
|
|
}else if(strcmp(t,"3")==0){
|
|
|
LooBook(0);
|
|
|
break;
|
|
|
}else if(strcmp(t,"4")==0){
|
|
|
printf("Bye~~~");
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//借书
|
|
|
void BroBook(){
|
|
|
system("cls");
|
|
|
printf("欢迎来到图书管理系统:\n");
|
|
|
struct Book *head=NULL;
|
|
|
struct Book *p,*p1,*p2;
|
|
|
FILE *fp,*fp1;
|
|
|
float Price=0;
|
|
|
char t,ReName[100];
|
|
|
int Many;
|
|
|
int n=0,j=0,k=0,flag=0;//k是库存的数量;
|
|
|
char Num[20]={'\0'},Aut[20]={'\0'},Pub[20]={'\0'},Nam[20]={'\0'},Cat[20]={'\0'};
|
|
|
int Xuehao;
|
|
|
char Mingzi[20]={'\0'},Riqi[20]={'\0'},Shuming[20]={'\0'};
|
|
|
fp=fopen("D:\\图书管理系统\\图书.txt","r");
|
|
|
if(fp==NULL){
|
|
|
system("cls");
|
|
|
printf("文件无法读取,请联系工作人员,按回车键返回");
|
|
|
t=getch();
|
|
|
while(t!=13){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
UserMenu();
|
|
|
}
|
|
|
else{
|
|
|
printf("\n请输入想要借的书的名字:\n");
|
|
|
scanf("%s",ReName);
|
|
|
j=Total();
|
|
|
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){
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
p=head;
|
|
|
for(;p!=NULL;){
|
|
|
if(!strcmp(p->nam,ReName)){
|
|
|
flag=1;
|
|
|
k=p->many;
|
|
|
(p->many)--;
|
|
|
}
|
|
|
p=p->next;
|
|
|
}
|
|
|
if((k>0)&&flag){
|
|
|
|
|
|
fp=fopen("D:\\图书管理系统\\图书.txt","w");
|
|
|
fclose(fp);
|
|
|
fp=fopen("D:\\图书管理系统\\图书.txt","a");
|
|
|
p=head;
|
|
|
for(;p!=NULL;){
|
|
|
fprintf(fp,"%-8d%-8s%-16s%-16s%-16s%-10d%10.2f\n",Num,Nam,Aut,Pub,Cat,Many,Price);
|
|
|
p=p->next;
|
|
|
}
|
|
|
free(p);
|
|
|
fclose(fp);
|
|
|
if((fp1=fopen("D:\\图书管理系统\\读者.txt","r"))==NULL){
|
|
|
fp1=fopen("D:\\图书管理系统\\读者.txt","w");
|
|
|
fclose(fp1);
|
|
|
}
|
|
|
fp1=fopen("D:\\图书管理系统\\读者.txt","a");
|
|
|
printf("请按照以下格式输入读者信息:\n 学号 姓名 借书日期 借书书名\n请输入:\n");
|
|
|
scanf("%d%s%s%s",&Xuehao,Mingzi,Riqi,Shuming);
|
|
|
fprintf(fp1,"\n%-8d%-23s%-18s%-10s\n",Xuehao,Mingzi,Riqi,Shuming);
|
|
|
fclose(fp1);
|
|
|
printf("借书成功,请按时归还,按Esc键退出\n");
|
|
|
t=getch();
|
|
|
while(t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==27){
|
|
|
UserMenu();
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
if(flag!=0){
|
|
|
printf("库存不足\n,按Esc键返回\n");
|
|
|
while(t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
UserMenu();
|
|
|
}else{
|
|
|
printf("没有你要的书籍\n,按Esc键返回\n");
|
|
|
}
|
|
|
}
|
|
|
while(t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
UserMenu();
|
|
|
}
|
|
|
|
|
|
//还书
|
|
|
void BacBook(){
|
|
|
system("cls");
|
|
|
printf("BacBook\n");
|
|
|
system("pause");
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
//看书信息
|
|
|
void LooBook(int n){
|
|
|
system("cls");
|
|
|
while(1){
|
|
|
char t;
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* 图书管理系统(Version 1.0 BETA) *\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("* 按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!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t=='1'){
|
|
|
SBNam();
|
|
|
break;
|
|
|
}else if(t=='2'){
|
|
|
SBAut();
|
|
|
break;
|
|
|
}else if(t=='3'){
|
|
|
SBCat();
|
|
|
break;
|
|
|
}else if(t==27){
|
|
|
if(n==0){
|
|
|
UserMenu();
|
|
|
}else if(n==1){
|
|
|
AdminMenu();
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int SBAut(){
|
|
|
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("D:\\图书管理系统\\图书.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();
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
UserMenu();
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
printf("继续查询请按回车键,退出查询返回主菜单请按ESC\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
SBAut();
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
UserMenu();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
system("pause");
|
|
|
}
|
|
|
|
|
|
int SBNam(){
|
|
|
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("D:\\图书管理系统\\图书.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();
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
UserMenu();
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
printf("继续查询请按回车键,退出查询返回主菜单请按ESC\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
SBAut();
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
UserMenu();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
int SBCat(){
|
|
|
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("D:\\图书管理系统\\图书.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);
|
|
|
SBAut();
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
UserMenu();
|
|
|
}
|
|
|
}
|
|
|
else{
|
|
|
printf("继续查询请按回车键,退出查询返回主菜单请按ESC\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
SBAut();
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
UserMenu();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//增加书籍
|
|
|
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("D:\\图书管理系统\\图书.txt","r"))==NULL){
|
|
|
fp=fopen("D:\\图书管理系统\\图书.txt","w");
|
|
|
fclose(fp);
|
|
|
}
|
|
|
fp=fopen("D:\\图书管理系统\\图书.txt","a");
|
|
|
printf("\n请按以下格式输入图书信息:\n书号 书名 作者 出版社 类别 库存量 单价\n");
|
|
|
for(;i!=27;)//为了实现输入一次后按esc退出
|
|
|
{
|
|
|
printf("请输入:\n");
|
|
|
scanf("%s%s%s%s%s%d%f",Num,Nam,Aut,Pub,Cat,&Many,&Price);
|
|
|
fprintf(fp,"%-8s%-9s%-14s%-16s%-18s%-7d%-8.2f\n",Num,Nam,Aut,Pub,Cat,Many,Price);
|
|
|
printf("继续输入请按回车,结束输入请按Esc\n");
|
|
|
i=getch();//暂停程序当i接收后继续下一条指令
|
|
|
for (;i!=13&&i!=27;)//保证只能是CR和ESC才能退出循环,输入其他字符无用,暂停程序,按'CR'继续。
|
|
|
i=getch();
|
|
|
}
|
|
|
fclose(fp);
|
|
|
printf("\n保存成功,按任意键返回上一层!");
|
|
|
getch();
|
|
|
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("D:\\图书管理系统\\图书.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("D:\\图书管理系统\\图书.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(Nam,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("D:\\图书管理系统\\图书.txt","w");
|
|
|
fclose(fp);
|
|
|
fp=fopen("D:\\图书管理系统\\图书.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");
|
|
|
printf("FixBook\n");
|
|
|
system("pause");
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
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("D:\\图书管理系统\\图书.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("D:\\图书管理系统\\账号管理.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("D:\\图书管理系统\\读者.txt","r");
|
|
|
for(n=0;!feof(fp);n++){
|
|
|
fscanf(fp,"%d%s%s%s",num,username,time,name);
|
|
|
}
|
|
|
n--;
|
|
|
fclose(fp);
|
|
|
return (n);
|
|
|
}
|