|
|
#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 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 SBAut(int q);//图书作者查询
|
|
|
void SBNam(int q);//图书名字查询
|
|
|
void SBCat(int q);//图书分类查询
|
|
|
void ed();//结束
|
|
|
|
|
|
////注册总页面
|
|
|
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 xuehao;
|
|
|
char username[20],time[20],name[20];
|
|
|
struct reader *next;
|
|
|
};
|
|
|
|
|
|
void ed(void)
|
|
|
{
|
|
|
system("cls");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* 图书管理系统(Version 1.0 BETA) *\n");
|
|
|
printf("******************************************************************************************\n");
|
|
|
printf("* *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* 酱,拜拜咯ヾ(·ω·`)o *\n");
|
|
|
printf("* *\n");
|
|
|
printf("* *\n");
|
|
|
printf("******************************************************************************************\n");
|
|
|
Sleep(1000);
|
|
|
system("cls");
|
|
|
home();
|
|
|
}
|
|
|
//主页面
|
|
|
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();
|
|
|
}
|
|
|
system("cls");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//注册
|
|
|
void Reg(){
|
|
|
FILE *fp=fopen("账号管理.txt","r");
|
|
|
fp=fopen("账号管理.txt","r");
|
|
|
system("cls");
|
|
|
int k=0;
|
|
|
char t;
|
|
|
int i=0;
|
|
|
char c;
|
|
|
char UserName[50],PassWord[10],RePassWord[10];
|
|
|
char name[100],password[100];
|
|
|
printf("\n\n\t\t\t\t\t签订契约\n\n\n");
|
|
|
printf(" 取个好听的名字吧φ(゜▽゜*)/,只能是英文,下划线,数字哦:(按ESC回到登陆界面)\n\n ");
|
|
|
while(1){
|
|
|
c=getch();
|
|
|
if(c==27) home();
|
|
|
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 请输入您的密码,不要随便泄露密码给别人鸭(小声BB)╯ 3╰ :\n\n ");
|
|
|
while(1){
|
|
|
int i=0;
|
|
|
char c;
|
|
|
while(1){
|
|
|
c=getch();
|
|
|
if(c==27) home();
|
|
|
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\n 确认一下密码QAQ:\n\n ");
|
|
|
while(1){
|
|
|
c=getch();
|
|
|
if(c==27) home();
|
|
|
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('*');
|
|
|
}
|
|
|
}
|
|
|
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");
|
|
|
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);
|
|
|
system("cls");
|
|
|
printf("\n\n\n");
|
|
|
printf("\t\t\t┌──────────────────────────────────────────────┐\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ 契约签订成功!( ·v ·)人(^▽^ ) │\n");
|
|
|
printf("\t\t\t│ 继续登陆请按Enter │\n");
|
|
|
printf("\t\t\t│ 回到主菜单请按Esc │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n"); t=getch();
|
|
|
if(t==13){
|
|
|
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(400);
|
|
|
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(400);
|
|
|
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(400);
|
|
|
system("cls");
|
|
|
Log();
|
|
|
break;
|
|
|
}
|
|
|
home();
|
|
|
}else {
|
|
|
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│ 两次密码不对吖,麻烦在输入一次啦~QAQ │\n");
|
|
|
printf("\t\t\t│ 稍后将返回注册界面哟(^V^)ノ~ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(1500);
|
|
|
Reg();
|
|
|
}
|
|
|
}else{
|
|
|
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│ 重新注册请按Enter │\n");
|
|
|
printf("\t\t\t│ 回到主菜单请按ESC │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
Reg();
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
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("账号管理.txt","r");
|
|
|
printf("\n\n\t\t\t\t你好啊~一直在等你呢 ̄ω ̄(按ESC回到主页面)\n\n\n");
|
|
|
printf(" 输入你的名字呢~\n\n ");
|
|
|
while(1){
|
|
|
c=getch();
|
|
|
if(c==27) home();
|
|
|
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 请输入您的密码:\n\n ");
|
|
|
i=0;
|
|
|
while(1){
|
|
|
c=getch();
|
|
|
if(c==27) home();
|
|
|
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();
|
|
|
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");
|
|
|
for(int f=0;f<j;f++){
|
|
|
fscanf(fp,"%s%s",name,password);
|
|
|
if(strcmp(UserName,name)==0){
|
|
|
if(strcmp(PassWord,password)==0){
|
|
|
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│ 登陆成功!( ·v ·)人(^▽^ ) │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(1000);
|
|
|
UserMenu();
|
|
|
break;
|
|
|
}else{
|
|
|
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│ 重新登陆请按Enter │\n");
|
|
|
printf("\t\t\t│ 返回主菜单请按Esc │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
Log();
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
home();
|
|
|
}
|
|
|
}
|
|
|
k++;
|
|
|
}
|
|
|
}
|
|
|
if(k==0){
|
|
|
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│ 回到主菜单请按Esc(·_·)/ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t├───────────────────────┬──────────────────────│\n");
|
|
|
printf("\t\t\t│ 1.注册 │ 2.重新登陆 │\n");
|
|
|
printf("\t\t\t└───────────────────────┴ ─────────────────────┘\n");
|
|
|
t=getch();
|
|
|
while(t!='1'&&t!='2'&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t=='1'){
|
|
|
system("cls");
|
|
|
Reg();
|
|
|
}else if(t=='2'){
|
|
|
system("cls");
|
|
|
Log();
|
|
|
}else if(t==27){
|
|
|
system("cls");
|
|
|
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("管理员专属.txt","r");
|
|
|
printf("\n\n 我的Master~一直在等你哟 ̄ω ̄(按ESC回到主页面)\n\n\n");
|
|
|
printf(" 输入你的名字呢~\n\n ");
|
|
|
while(1){
|
|
|
c=getch();
|
|
|
if(c==27) home();
|
|
|
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 请输入您的密码:\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;
|
|
|
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");
|
|
|
for(int f=0;f<j;f++){
|
|
|
fscanf(fp,"%s%s",name,password);
|
|
|
if(strcmp(AdminName,name)==0){
|
|
|
if(strcmp(PassWord,password)==0){
|
|
|
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│ 登陆成功!( ·v ·)人(^▽^ ) │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(1000);
|
|
|
AdminMenu();
|
|
|
break;
|
|
|
}else{
|
|
|
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│ 重新登陆请按Enter │\n");
|
|
|
printf("\t\t\t│ 返回主菜单请按Esc │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==13){
|
|
|
system("cls");
|
|
|
Adm();
|
|
|
}else if(t==27){
|
|
|
fclose(fp);
|
|
|
system("cls");
|
|
|
printf("正在跳转...");
|
|
|
home();
|
|
|
}
|
|
|
}
|
|
|
k++;
|
|
|
}
|
|
|
}
|
|
|
if(k==0){
|
|
|
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│ 重新登陆请按Enter │\n");
|
|
|
printf("\t\t\t│ 返回主菜单请按Esc │\n");
|
|
|
printf("\t\t\t│ │\n");
|
|
|
printf("\t\t\t└──────────────────────────────────────────────┘\n");
|
|
|
Sleep(1000);
|
|
|
t=getch();
|
|
|
while(t!='1'&&t!='2'&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==27){
|
|
|
system("cls");
|
|
|
home();
|
|
|
}
|
|
|
else if(t==13){
|
|
|
system("cls");
|
|
|
Adm();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//管理员菜单
|
|
|
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){
|
|
|
ed();
|
|
|
}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){
|
|
|
ed();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//借书
|
|
|
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是库存的数量;
|
|
|
int Xuehao;
|
|
|
char Num[20]={'\0'},Aut[20]={'\0'},Pub[20]={'\0'},Nam[20]={'\0'},Cat[20]={'\0'};
|
|
|
char Mingzi[20]={'\0'},Riqi[20]={'\0'},Shuming[20]={'\0'};
|
|
|
fp=fopen("图书.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("图书.txt","w");
|
|
|
fclose(fp);
|
|
|
fp=fopen("图书.txt","a");
|
|
|
p=head;
|
|
|
for(;p!=NULL;){
|
|
|
fprintf(fp,"%-8s%-8s%-16s%-16s%-16s%-10d%10.2f\n",p->num,p->nam,p->aut,p->pub,p->cat,p->many,p->price);
|
|
|
p=p->next;
|
|
|
}
|
|
|
free(p);
|
|
|
fclose(fp);
|
|
|
if((fp1=fopen("读者.txt","r"))==NULL){
|
|
|
fp1=fopen("读者.txt","w");
|
|
|
fclose(fp1);
|
|
|
}
|
|
|
fp1=fopen("读者.txt","a");
|
|
|
printf("请输入学号:");
|
|
|
scanf("%d",&Xuehao);
|
|
|
printf("请输入名字:");
|
|
|
scanf("%s",Mingzi);
|
|
|
printf("请输入借书日期(年份/月份/日):");
|
|
|
scanf("%s",Riqi);
|
|
|
printf("请输入书名:");
|
|
|
scanf("%s",Shuming);
|
|
|
fprintf(fp1,"%-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");
|
|
|
struct reader *head=NULL;
|
|
|
struct Book *zhead=NULL;
|
|
|
struct Book *zp,*zp1,*zp2;
|
|
|
struct reader *p,*p1,*p2;
|
|
|
FILE *fp,*fp1;
|
|
|
float Price=0;
|
|
|
char t,ReName[100];
|
|
|
int Many;
|
|
|
int n=0,j=0,k=0,flag=0,l=0;//k是库存的数量;
|
|
|
char Num[20]={'\0'},Aut[20]={'\0'},Pub[20]={'\0'},Nam[20]={'\0'},Cat[20]={'\0'};
|
|
|
int Xuehao,ReXuehao;
|
|
|
char Mingzi[20]={'\0'},Riqi[20]={'\0'},Shuming[20]={'\0'};
|
|
|
fp=fopen("读者.txt","r");
|
|
|
if(fp==NULL){
|
|
|
system("cls");
|
|
|
printf("未存在读者文件,请联系管理员\n");
|
|
|
printf("按Esc返回\n");
|
|
|
t=getch();
|
|
|
while(t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
UserMenu();
|
|
|
}else{
|
|
|
printf("请输入学号:");//
|
|
|
scanf("%d",&ReXuehao);
|
|
|
printf("请输入姓名:");
|
|
|
scanf("%s",ReName);
|
|
|
j=Total2();
|
|
|
for(int i=0;i<j;i++){
|
|
|
fscanf(fp,"%d%s%s%s",&Xuehao,Mingzi,Riqi,Shuming);
|
|
|
if((Xuehao==ReXuehao)&&!strcmp(Shuming,ReName)){
|
|
|
flag=1;
|
|
|
}
|
|
|
}
|
|
|
fclose(fp);
|
|
|
fp=fopen("读者.txt","r");
|
|
|
if(flag){
|
|
|
for(int i=0;i<j;i++){
|
|
|
fscanf(fp,"%d%s%s%s",&Xuehao,Mingzi,Riqi,Shuming);
|
|
|
if(!(Xuehao==ReXuehao&&!strcmp(Shuming,ReName))){
|
|
|
n++;
|
|
|
if(n==1){
|
|
|
p1=p2=(struct reader*)malloc(LEN1);
|
|
|
head=p1;
|
|
|
}
|
|
|
else{
|
|
|
p2->next=p1;
|
|
|
p2=p1;
|
|
|
p1=(struct reader*)malloc(LEN1);
|
|
|
}
|
|
|
p1->xuehao=Xuehao;
|
|
|
strcpy(p1->username,Mingzi);
|
|
|
strcpy(p1->time,Riqi);
|
|
|
strcpy(p1->name,Shuming);
|
|
|
}
|
|
|
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,"%-8d%-23s%-18s%-10s\n",p->xuehao,p->username,p->time,p->name);
|
|
|
p=p->next;
|
|
|
}
|
|
|
free(p);
|
|
|
fclose(fp);
|
|
|
if(flag){
|
|
|
printf("是否确认还书,还书请按回车,退出请按Esc\n");
|
|
|
t=getch();
|
|
|
while(t!=13&&t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==27){
|
|
|
printf("正在跳转...");
|
|
|
Sleep(1000);
|
|
|
UserMenu();
|
|
|
}
|
|
|
printf("还书成功,按Esc键返回");
|
|
|
n=0,flag=0;
|
|
|
l=Total();
|
|
|
fp1=fopen("图书.txt","r");
|
|
|
for(int i=0;i<l;i++){
|
|
|
fscanf(fp1,"%s%s%s%s%s%d%f",Num,Nam,Aut,Pub,Cat,&Many,&Price);
|
|
|
n++;
|
|
|
if(n==1){
|
|
|
zp1=zp2=(struct Book*)malloc(LEN);
|
|
|
zhead=zp1;
|
|
|
}else{
|
|
|
zp2->next=zp1;
|
|
|
zp2=zp1;
|
|
|
zp1=(struct Book*)malloc(LEN);
|
|
|
}
|
|
|
strcpy(zp1->num,Num);//复制书号
|
|
|
strcpy(zp1->nam,Nam);//复制书名
|
|
|
strcpy(zp1->aut,Aut);//复制作者名字
|
|
|
strcpy(zp1->pub,Pub);//复制出版社
|
|
|
strcpy(zp1->cat,Cat);//复制类别
|
|
|
zp1->many=Many;//复制个数
|
|
|
zp1->price=Price;//复制单价
|
|
|
}
|
|
|
if(n==0){
|
|
|
zhead=NULL;
|
|
|
}
|
|
|
else{
|
|
|
zp2->next=zp1;
|
|
|
zp1->next=NULL;
|
|
|
fclose(fp1);
|
|
|
}
|
|
|
}
|
|
|
zp=zhead;
|
|
|
for(;zp!=NULL;){
|
|
|
if(!strcmp(zp->nam,ReName)){
|
|
|
k=zp->many;
|
|
|
(zp->many)++;
|
|
|
}
|
|
|
zp=zp->next;
|
|
|
}
|
|
|
fp1=fopen("图书.txt","w");
|
|
|
fclose(fp1);
|
|
|
fp1=fopen("图书.txt","a");
|
|
|
zp=zhead;
|
|
|
for(;zp!=NULL;){
|
|
|
fprintf(fp1,"%-8s%-8s%-16s%-16s%-16s%-10d%10.2f\n",zp->num,zp->nam,zp->aut,zp->pub,zp->cat,zp->many,zp->price);
|
|
|
zp=zp->next;
|
|
|
}
|
|
|
fclose(fp1);
|
|
|
t=getch();
|
|
|
while(t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==27){
|
|
|
UserMenu();
|
|
|
}
|
|
|
else{
|
|
|
system("cls");
|
|
|
printf("不存在这个书,按Esc键返回\n");
|
|
|
while(t!=27){
|
|
|
t=getch();
|
|
|
continue;
|
|
|
}
|
|
|
if(t==27){
|
|
|
UserMenu();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//看书信息
|
|
|
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(n);
|
|
|
break;
|
|
|
}else if(t=='2'){
|
|
|
SBAut(n);
|
|
|
break;
|
|
|
}else if(t=='3'){
|
|
|
SBCat(n);
|
|
|
break;
|
|
|
}else if(t==27){
|
|
|
if(n==0){
|
|
|
UserMenu();
|
|
|
}else if(n==1){
|
|
|
AdminMenu();
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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(Nam,ReName)!=0){
|
|
|
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");
|
|
|
printf("fixbook");
|
|
|
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("图书.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);
|
|
|
}
|