#include
#include
#include
#include
using namespace std;
int Adp; /// 管理员密码
int pdt; /// 比较密码
int cnt = 0; /// 图书当前本数
int N = 0; /// 记录用户数目
struct user /// 用户
{
int id; /// 用户名
int pd; /// 密码
char name[20]; /// 姓名
int age; /// 年龄
int sex; /// 性别 1、男 2、女
char tel[20]; /// 联系方式
} user[101];
struct book
{
int num; /// 书号
char name[20]; /// 书名
char writer[20]; /// 作者
char publish[20]; /// 出版社
char publishtime[20]; /// 出版时间
double price; ///价格
int state; /// 借阅状态
} book[101];
/*
** 功能:保存用户信息
** 时间:17/7/8
*/
void saveUser()
{
FILE *fp = fopen("user.txt", "w");
for (int i = 1; i <= 100; i++)
{
if (strcmp(user[i].name, "") == 0)
strcpy(user[i].name, "-");
if (strcmp(user[i].tel, "") == 0)
strcpy(user[i].tel, "-");
fprintf(fp, "%d %d %s %d %d %s\n", user[i].id, user[i].pd, user[i].name, user[i].age, user[i].sex, user[i].tel);
}
fprintf(fp, "%d\n", N);
fclose(fp);
}
/*
** 功能:读取用户信息
** 时间:17/7/8
*/
void loadUser()
{
FILE *fp = fopen("user.txt", "r");
for (int i = 1; i <= 100; i++)
{
fscanf(fp, "%d%d%s%d%d%s", &user[i].id, &user[i].pd, user[i].name, &user[i].age, &user[i].sex, user[i].tel);
}
fscanf(fp, "%d", &N);
fclose(fp);
}
/*
** 功能:保存书籍信息
** 时间:17/7/8
*/
void saveBook()
{
FILE *fp = fopen("book.txt", "w");
for (int i = 1; i <= 100; i++)
{
if (strcmp(book[i].name, "") == 0)
strcpy(book[i].name, "-");
if (strcmp(book[i].writer, "") == 0)
strcpy(book[i].writer, "-");
if (strcmp(book[i].publish, "") == 0)
strcpy(book[i].publish, "-");
if (strcmp(book[i].publishtime, "") == 0)
strcpy(book[i].publishtime, "-");
fprintf(fp, "%d %s %s %s %s %lf %d\n", book[i].num, book[i].name, book[i].writer, book[i].publish, book[i].publishtime, book[i].price, book[i].state);
}
fprintf(fp, "%d\n", cnt);
fclose(fp);
}
/*
** 功能:读取书籍信息
** 时间:17/7/8
*/
void loadBook()
{
FILE *fp = fopen("book.txt", "r");
for (int i = 1; i <= 100; i++)
{
fscanf(fp, "%d %s %s %s %s %lf %d\n", &book[i].num, book[i].name, book[i].writer, book[i].publish, book[i].publishtime, &book[i].price, &book[i].state);
}
fscanf(fp, "%d", &cnt);
fclose(fp);
}
/*
** 功能:输入隐藏密码
** 时间:17/7/8
*/
int psWd()
{
char ch;
int num[6];
int m=0;
while(m<6)
{
ch=getch();
num[m]=ch-'0';
printf("*");
m++;
}
int pwd=num[0]*100000+num[1]*10000+num[2]*1000+num[3]*100+num[4]*10+num[5];
printf("\n");
return pwd;
}
/*
** 功能:更改管理员密码
** 时间:17/7/8
*/
void ChangeAdp()
{
while(true)
{
printf("\t\t\t 请输入六位新密码:\n\n");
printf("\t\t\t");
pdt = psWd();
printf("\t\t\t 请确认密码:\n\n");
printf("\t\t\t");
Adp = psWd();
if(pdt == Adp)
{
MessageBox (NULL,TEXT("密码修改成功!"), TEXT("Tips"),MB_OK);
FILE * fp = fopen("admin.txt", "w");
fprintf(fp, "%d", Adp);
fclose(fp);
return;
}
else
{
MessageBox (NULL,TEXT("两次密码输入不一致,请重新输入"), TEXT("Tips"),MB_OK);
}
}
}
/*
** 功能:提示
** 时间:17/7/8
*/
void Tips()
{
int i;
printf("\n\n\n\n\t\t==========================================\n\n");
printf("\n\n\n\t\t\t\t正在初始化");
for(i=0; i<=100; i++)
{
printf("%02d%%",i);
Sleep(10);
printf("\b\b\b");
}
printf("\n\n\t\t\t\t初始化成功\n");
printf("\n\n\n\t\t==========================================\n\n");
Sleep(1000);
system("cls");
MessageBox (NULL,TEXT("欢迎使用图书管理系统!"), TEXT("欢迎"),MB_OK);
printf("\t\t==========================================\n\n");
printf("\t\t|| 欢迎使用图书管理系统 ||\n\n");
printf("\t\t==========================================\n\n");
if (access("admin.txt", 0))
{
printf("\t\t|| * 管理员请更改初始密码 * ||\n\n");
printf("\t\t==========================================\n\n");
ChangeAdp();
}
else
{
FILE * fp = fopen("admin.txt", "r");
fscanf(fp, "%d", &Adp);
fclose(fp);
}
}
/*
** 功能:系统选择界面
** 时间:17/7/8
*/
int systemChoose()
{
system("cls");
int choose;
printf("\t\t===========================================\n\n");
printf("\t\t|| 欢迎使用图书管理系统 ||\n\n");
printf("\t\t===========================================\n\n");
printf("\t\t|| 1 ==> 用户系统 ||\n\n");
printf("\t\t|| 2 ==> 管理员系统 ||\n\n");
printf("\t\t|| 0 ==> 退出 ||\n\n");
printf("\t\t===========================================\n\n");
printf("\t\t\t请选择您要登录的系统:");
scanf("%d",&choose);
return choose;
}
/*
** 功能:图书书号查重
** 时间:17/7/8
*/
int booknumCheck(int idt)
{
int flag,i;
flag = 1;
for(i = 1; i <= cnt; i++)
{
if(book[i].num == idt)
{
flag = 0;
}
else
{
flag = 1;
}
}
return flag;
}
/*
** 功能:用户ID查重
** 时间:17/7/11
*/
int useridCheck(int idt)
{
int flag,i;
flag = 1;
for(i = 1; i <= N; i++)
{
if(user[i].id == idt)
{
flag = 0;
}
else
{
flag = 1;
}
}
return flag;
}
void admSystem();
/*
** 功能:管理员系统の图书信息录入
** 时间:17/7/9
*/
void informationEntry()
{
while(true)
{
system("cls");
int choose;
int num,i,flag; /// 如果flag == 1 则书号合法
int idt;
printf("\t\t===========================================\n\n");
printf("\t\t|| 欢迎使用图书管理系统の图书信息录入 ||\n\n");
printf("\t\t===========================================\n\n");
printf("\t\t\t请输入您要录入的图书本数:");
scanf("%d",&num);
for(i = 1; i <= num; i++)
{
while(true)
{
printf("\t\t\t请输入您要录入的图书书号:");
scanf("%d",&idt);
flag = booknumCheck(idt);
if(flag == 1)
{
///MessageBox (NULL,TEXT("图书书号录入成功!"), TEXT("Tips"),MB_OK);
book[cnt+1].num = idt;
break;
}
else
{
MessageBox (NULL,TEXT("图书书号已存在!请重新输入"), TEXT("Tips"),MB_OK);
}
}
printf("\t\t\t请输入您要录入的图书书名:");
scanf("%s",book[cnt+1].name);
printf("\t\t\t请输入您要录入的图书作者:");
scanf("%s",book[cnt+1].writer);
printf("\t\t\t请输入您要录入的图书出版社:");
scanf("%s",book[cnt+1].publish);
printf("\t\t\t请输入您要录入的图书时间(XXXX.XX.XX):");
scanf("%s",book[cnt+1].publishtime);
printf("\t\t\t请输入您要录入的图书价格:");
scanf("%lf",&book[cnt+1].price);
book[cnt+1].state = 0;
MessageBox (NULL,TEXT("图书信息录入成功!"), TEXT("Tips"),MB_OK);
printf("\t========================================================================\n\n");
printf("\t|| 书号 || 书名 || 作者 || 出版社 || 出版时间 || 图书价格 || 借阅状态 ||\n\n");
printf("\t|| %d || %s || %s || %s || %s || %lf || 未借出 ||\n\n",book[cnt+1].num,book[cnt+1].name,book[cnt+1].writer,book[cnt+1].publish,book[cnt+1].publishtime,book[cnt+1].price);
printf("\t========================================================================\n\n");
cnt++;
}
printf("\t\t==========================================\n\n");
printf("\t\t|| 是否继续?: ||\n\n");
printf("\t\t|| 1 ==> 继续 ||\n\n");
printf("\t\t|| 0 ==> 退出 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t\t请选择:");
scanf("%d",&choose);
printf("Choose: %d\n", choose);
if(choose == 0)
{
return;
//admSystem();
}
}
}
/*
** 功能:管理员系统の图书信息浏览
** 时间:17/7/91
*/
void informationScan()
{
int i;
printf("\t\t******************************************\n\n");
printf("\t\t|| 欢迎使用图书管理系统の图书信息浏览 ||\n\n");
printf("\t\t******************************************\n\n");
if(cnt == 0)
{
MessageBox (NULL,TEXT("您未录入任何图书信息!"), TEXT("Tips"),MB_OK);
}
else
{
printf("\t\t============================================================\n\n");
printf("\t\t||书号||书名||作者||出版社||出版时间||图书价格 ||借阅状态 ||\n\n");
for(i = 1; i <= cnt; i++)
{
if(book[i].state == 1)
{
printf("\t\t|| %d || %s || %s || %s || %s || %.2f || 已借出 ||\n\n",book[i].num,book[i].name,book[i].writer,book[i].publish,book[i].publishtime,book[i].price);
}
else
{
printf("\t\t|| %d || %s || %s || %s || %s || %.2f || 未借出 ||\n\n",book[i].num,book[i].name,book[i].writer,book[i].publish,book[i].publishtime,book[i].price);
}
}
printf("\t\t============================================================\n\n");
system("pause");
return;
//admSystem();
}
}
/*
** 功能:管理员系统の图书信息查询
** 时间:17/7/9
*/
void informationQuery()
{
int a,flag;
int i,choose;
char na[20];
char wr[20];
printf("\t\t==========================================\n\n");
printf("\t\t|| 欢迎使用图书管理系统の图书信息查询 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t|| 查找方式: ||\n\n");
printf("\t\t|| 1 ==> Search by name ||\n\n");
printf("\t\t|| 2 ==> Search by writer ||\n\n");
printf("\t\t==========================================\n\n");
while(true)
{
if(cnt == 0)
{
MessageBox (NULL,TEXT("您未录入任何图书信息!"), TEXT("Tips"),MB_OK);
return;
}
else
{
flag = 0;
printf("\t\t\t请选择您的查找方式:");
scanf("%d",&choose);
if(choose == 1)
{
printf("\t\t==========================================\n\n");
printf("\t\t\t请输入您要查找的书名:");
scanf("%s",na);
for(i = 0; i <= cnt; i++)
{
if(strcmp(book[i].name,na) == 0)
{
flag = 1;
if(book[i].state == 1)
{
printf("\t\t============================================================\n\n");
printf("\t\t||书号||书名||作者||出版社||出版时间||图书价格 ||借阅状态 ||\n\n");
printf("\t\t|| %d || %s || %s || %s || %s || %.2f || 已借出 ||\n\n",book[i].num,book[i].name,book[i].writer,book[i].publish,book[i].publishtime,book[i].price);
printf("\t\t==========================================================\n\n");
}
else
{
printf("\t\t============================================================\n\n");
printf("\t\t||书号||书名||作者||出版社||出版时间||图书价格 ||借阅状态 ||\n\n");
printf("\t\t|| %d || %s || %s || %s || %s || %.2f || 未借出 ||\n\n",book[i].num,book[i].name,book[i].writer,book[i].publish,book[i].publishtime,book[i].price);
printf("\t\t==========================================================\n\n");
}
}
}
if(flag == 0)
{
MessageBox (NULL,TEXT("您查找的图书不存在!"), TEXT("Tips"),MB_OK);
return;
}
}
else
{
printf("\t\t==========================================\n\n");
printf("\t\t\t请输入您要查找的作者:");
scanf("%s",wr);
for(i = 0; i <= cnt; i++)
{
flag = 1;
if(strcmp(book[i].writer,wr) == 0)
{
if(book[i].state == 1)
{
printf("\t\t============================================================\n\n");
printf("\t\t||书号||书名||作者||出版社||出版时间||图书价格 ||借阅状态 ||\n\n");
printf("\t\t|| %d || %s || %s || %s || %s || %.2f || 已借出 ||\n\n",book[i].num,book[i].name,book[i].writer,book[i].publish,book[i].publishtime,book[i].price);
printf("\t\t==========================================================\n\n");
}
else
{
printf("\t\t============================================================\n\n");
printf("\t\t||书号||书名||作者||出版社||出版时间||图书价格 ||借阅状态 ||\n\n");
printf("\t\t|| %d || %s || %s || %s || %s || %.2f || 未借出 ||\n\n",book[i].num,book[i].name,book[i].writer,book[i].publish,book[i].publishtime,book[i].price);
printf("\t\t==========================================================\n\n");
}
}
}
if(flag == 0)
{
MessageBox (NULL,TEXT("您查找的图书不存在!"), TEXT("Tips"),MB_OK);
return;
}
}
printf("\t\t==========================================\n\n");
printf("\t\t|| 是否继续?: ||\n\n");
printf("\t\t|| 1 ==> 继续 ||\n\n");
printf("\t\t|| 0 ==> 退出 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t\t请选择:");
scanf("%d",&a);
if(a == 0)
{
printf("\t\t\t感谢您的使用!\n\n");
//admSystem();
system("pause");
return;
}
}
}
}
/*
** 功能:管理员系统の图书信息删除
** 时间:17/7/9
*/
void informationDelete()
{
int n,i;
int a;
printf("\t\t==========================================\n\n");
printf("\t\t|| 欢迎使用图书管理系统の图书信息删除 ||\n\n");
printf("\t\t==========================================\n\n");
while(true)
{
int flag = 0;
if(cnt == 0)
{
MessageBox (NULL,TEXT("您未录入任何图书信息!"), TEXT("Tips"),MB_OK);
break;
}
else
{
printf("\t\t\t请输入您要删除的图书书号:");
scanf("%d",&n);
for(i = 1; i < cnt; i++)
{
if(n == book[i].num)
{
book[i] = book[i+1];
flag = 1;
cnt--;
printf("\n\t\t\t删除图书成功!\n\n");
}
}
if(flag == 0)
{
MessageBox (NULL,TEXT("未找到匹配图书信息!"), TEXT("Tips"),MB_OK);
}
}
printf("\t\t==========================================\n\n");
printf("\t\t|| 是否继续?: ||\n\n");
printf("\t\t|| 1 ==> 继续 ||\n\n");
printf("\t\t|| 0 ==> 退出 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t\t请选择:");
scanf("%d",&a);
if(a == 0)
{
printf("\t\t\t感谢您的使用!\n\n");
break;
}
}
}
/*
** 功能:管理员系统の图书信息修改
** 时间:17/7/9
*/
void informationChange()
{
int i;
printf("\t\t==========================================\n\n");
printf("\t\t|| 欢迎使用图书管理系统の图书信息修改 ||\n\n");
printf("\t\t==========================================\n\n");
while(true)
{
int flag = 0;
if(cnt == 0)
{
MessageBox (NULL,TEXT("您未录入任何图书信息!"), TEXT("Tips"),MB_OK);
break;
}
else
{
int iid;
int a;
printf("\t\t\t请输入所要修改的书籍的书号\n\n");
printf("\t\t\tPlease Enter Your Choose : ");
scanf("%d",&iid);
for(i = 1; i <= cnt; i++)
{
if(book[i].num == iid)
{
int choose;
printf("\t\t==========================================\n\n");
printf("\t\t||\t请选择您要修改的内容: ||\n\n");
printf("\t\t||\t1 ==> 书名 ||\n\n");
printf("\t\t||\t2 ==> 作者 ||\n\n");
printf("\t\t||\t3 ==> 出版社 ||\n\n");
printf("\t\t||\t4 ==> 出版时间 ||\n\n");
printf("\t\t||\t5 ==> 图书价格 ||\n\n");
printf("\t\t||\t0 ==> 退出 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t\t请选择:");
scanf("%d",&choose);
if(choose == 1)
{
printf("\n\t\t\t请输入新的书名:");
scanf("%s",book[i].name);
}
else if(choose == 2)
{
printf("\n\t\t\t请输入新的作者名:");
scanf("%s",book[i].writer);
}
else if(choose == 3)
{
printf("\n\t\t\t请输入新的出版社名称:");
scanf("%s",book[i].publish);
}
else if(choose == 4)
{
printf("\n\t\t\t请输入新的出版时间:例如2017年7月8日请输入(2017.07.08):");
scanf("%s",book[cnt+1].publishtime);
}
else if(choose == 5)
{
printf("\n\t\t\t请输入新的图书价格:");
scanf("%lf",&book[i].price);
}
flag = 1;
printf("\n\t\t\t图书信息修改成功!\n\n");
printf("\n\t\t\t当前图书信息显示:\n\n");
if(book[i].state == 1)
{
printf("\t\t============================================================\n\n");
printf("\t\t||书号||书名||作者||出版社||出版时间||图书价格 ||借阅状态 ||\n\n");
printf("\t\t\t|| %d || %s || %s || %s || %s || %lf || 已借出 ||\n\n",book[i].num,book[i].name,book[i].writer,book[i].publish,book[i].publishtime,book[i].price);
printf("\t\t\t==========================================================\n\n");
}
else
{
printf("\t\t============================================================\n\n");
printf("\t\t||书号||书名||作者||出版社||出版时间||图书价格 ||借阅状态 ||\n\n");
printf("\t\t\t|| %d || %s || %s || %s || %s || %lf || 未借出 ||\n\n",book[i].num,book[i].name,book[i].writer,book[i].publish,book[i].publishtime,book[i].price);
printf("\t\t\t==========================================================\n\n");
}
break;
}
}
if(flag == 0)
{
MessageBox (NULL,TEXT("未找到匹配图书信息!"), TEXT("Tips"),MB_OK);
}
printf("\t\t==========================================\n\n");
printf("\t\t|| 是否继续?: ||\n\n");
printf("\t\t|| 1 ==> 继续 ||\n\n");
printf("\t\t|| 0 ==> 退出 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t\t请选择:");
scanf("%d",&a);
if(a == 0)
{
printf("\t\t\t感谢您的使用!\n\n");
break;
}
}
}
}
/*
** 管理员系统主界面
** 时间:17/7/8
*/
void admSystem()
{
int choose;
while (true)
{
system("cls");
printf("\t\t==========================================\n\n");
printf("\t\t||\t欢迎使用图书管理系统の管理员系统 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t|| 1 ==> 图书信息录入 ||\n\n");
printf("\t\t|| 2 ==> 图书信息浏览 ||\n\n");
printf("\t\t|| 3 ==> 图书信息查询 ||\n\n");
printf("\t\t|| 4 ==> 图书信息删除 ||\n\n");
printf("\t\t|| 5 ==> 图书信息修改 ||\n\n");
printf("\t\t|| 0 ==> 退出 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t\t请选择功能号:");
scanf("%d",&choose);
switch (choose)
{
case 1:
informationEntry(); /// 图书信息录入
saveBook();
break;
case 2:
informationScan(); /// 图书信息浏览
saveBook();
break;
case 3:
informationQuery(); /// 图书信息查询
break;
case 4:
informationDelete(); ///图书信息删除
saveBook();
break;
case 5:
informationChange(); ///图书信息修改
saveBook();
break;
case 0:
return ;
break;
}
}
}
/*
** 功能:管理员登录界面
** 时间:17/7/8
*/
void admLogin()
{
system("cls");
printf("\t\t==========================================\n\n");
printf("\t\t|| 欢迎使用图书管理系统の管理员系统 ||\n\n");
printf("\t\t==========================================\n\n");
int j;
for (j = 0; j < 3; j++)
{
printf("\t\t\t请输入您的密码:");
pdt = psWd();
if(pdt == Adp)
{
MessageBox (NULL,TEXT("登录成功!"), TEXT("Tips"),MB_OK);
admSystem();
return;
}
else
{
printf("\n\t\t\t密码错误!\n\t\t\t你还剩%d次输入密码的机会\n\n", 2 - j);
}
}
if (j == 3)
{
MessageBox (NULL,TEXT("3次密码输入错误,退出!"), TEXT("Tips"),MB_OK);
return;
}
}
void userSystem();
/*
** 功能:用户系统の查询所有图书
** 时间:17/7/10
*/
void listBook()
{
int i;
printf("\t\t==========================================\n\n");
printf("\t\t|| 欢迎使用用户系统の查询所有图书 ||\n\n");
printf("\t\t==========================================\n\n");
if(cnt == 0)
{
MessageBox (NULL,TEXT("您未录入任何图书信息!"), TEXT("Tips"),MB_OK);
}
else
{
for(i = 1; i <= cnt; i++)
{
if(book[i].state == 1)
{
printf("\t\t============================================================\n\n");
printf("\t\t||书号||书名||作者||出版社||出版时间||图书价格 ||借阅状态 ||\n\n");
printf("\t\t|| %d || %s || %s || %s || %s || %lf || 已借出 ||\n\n",book[i].num,book[i].name,book[i].writer,book[i].publish,book[i].publishtime,book[i].price);
printf("\t\t==========================================================\n\n");
}
else
{
printf("\t\t============================================================\n\n");
printf("\t\t||书号||书名||作者||出版社||出版时间||图书价格 ||借阅状态 ||\n\n");
printf("\t\t|| %d || %s || %s || %s || %s || %lf || 未借出 ||\n\n",book[i].num,book[i].name,book[i].writer,book[i].publish,book[i].publishtime,book[i].price);
printf("\t\t==========================================================\n\n");
}
}
system("pause");
}
//userSystem();
}
/*
** 功能:用户系统の归还已借图书
** 时间:17/7/10
*/
void returnBook()
{
int numt;
int day,a;
int i;
printf("\t\t==========================================\n\n");
printf("\t\t|| 欢迎使用用户系统の归还已借图书 ||\n\n");
printf("\t\t==========================================\n\n");
while(true)
{
int flag = 0;
printf("\t\t\t请输入您要归还的图书号:");
scanf("%d",&numt);
for(i = 1; i <= cnt; i++)
{
if(numt == book[i].num)
{
flag = 1;
if(book[i].state == 0)
{
MessageBox (NULL,TEXT("您已归还!请勿重复归还!"), TEXT("Tips"),MB_OK);
}
else
{
book[i].state = 0;
printf("\t\t\t请输入您已借阅天数:");
scanf("%d",&day);
if(day <= 30)
{
printf("\t\t\t您的免费借阅天数还有 %d 天\n\n",30-day);
}
else
{
printf("您已逾期 %d 天,请缴纳 %.2f 元的逾期费用!\n\n",day-30,0.1*(day-30));
}
MessageBox (NULL,TEXT("归还成功!"), TEXT("Tips"),MB_OK);
}
}
}
if(flag == 0)
{
MessageBox (NULL,TEXT("未找到匹配书号的图书!"), TEXT("Tips"),MB_OK);
}
printf("\t\t==========================================\n\n");
printf("\t\t|| 是否继续?: ||\n\n");
printf("\t\t|| 1 ==> 继续 ||\n\n");
printf("\t\t|| 0 ==> 退出 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t\t请选择:");
scanf("%d",&a);
if(a == 0)
{
printf("\t\t\t感谢您的使用!\n\n");
break;
}
}
}
/*
** 功能:用户系统の租借现有图书
** 时间:17/7/10
*/
void rentBook()
{
int numt;
int a;
int i;
printf("\t\t==========================================\n\n");
printf("\t\t|| 欢迎使用用户系统の租借现有图书 ||\n\n");
printf("\t\t==========================================\n\n");
while(true)
{
int flag = 0;
printf("\t\t\t请输入您要借阅的图书号:");
scanf("%d",&numt);
for(i = 1; i <= cnt; i++)
{
if(numt == book[i].num)
{
if(book[i].state == 1)
{
MessageBox (NULL,TEXT("该图书已借出!"), TEXT("Tips"),MB_OK);
}
else
{
flag = 1;
book[i].state = 1;
printf("\t\t====================Tips==================\n\n");
printf("\t\t|| * 您的免费借阅时间为 30 天 * ||\n\n");
printf("\t\t|| * 逾期费用为每天 0.1 元 * ||\n\n");
printf("\t\t==========================================\n\n");
MessageBox (NULL,TEXT("借阅成功!"), TEXT("Tips"),MB_OK);
}
}
}
if(flag == 0)
{
MessageBox (NULL,TEXT("未找到匹配书号的图书!"), TEXT("Tips"),MB_OK);
}
printf("\t\t==========================================\n\n");
printf("\t\t|| 是否继续?: ||\n\n");
printf("\t\t|| 1 ==> 继续 ||\n\n");
printf("\t\t|| 0 ==> 退出 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t\t请选择:");
scanf("%d",&a);
if(a == 0)
{
printf("\t\t\t感谢您的使用!\n\n");
return;
}
}
}
void userChoose();
/*
** 用户系统主界面
** 时间:17/7/10
*/
void userSystem()
{
while(true)
{
system("cls");
int choose;
printf("\t\t==========================================\n\n");
printf("\t\t|| 欢迎使用图书借阅系统の用户系统 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t|| 1 ==> 查询所有图书 ||\n\n");
printf("\t\t|| 2 ==> 归还已借图书 ||\n\n");
printf("\t\t|| 3 ==> 租借现有图书 ||\n\n");
printf("\t\t|| 0 ==> 退出 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t\t请选择功能号:");
scanf("%d",&choose);
switch (choose)
{
case 1:
listBook(); /// 查看所有图书
break;
case 2:
returnBook(); /// 归还已借图书
saveBook();
break;
case 3:
rentBook(); /// 租借现有图书
saveBook();
break;
case 0:
//userChoose();
return ;
break;
}
}
}
/*
** 功能:用户登录界面
** 时间:17/7/10
*/
void userLogin()
{
while(true)
{
system("cls");
int idt;
printf("\t\t==========================================\n\n");
printf("\t\t|| 欢迎使用图书借阅系统の用户系统 ||\n\n");
printf("\t\t==========================================\n\n");
if(N == 0)
{
MessageBox (NULL,TEXT("不存在注册用户!"), TEXT("Tips"),MB_OK);
break;
}
int j = 1;
int i;
int flag = 0;
printf("\t\t\t请输入您的用户名ID:");
scanf("%d",&idt);
for(i = 1; i <= N; i++)
{
/// 首先通过用户名找到对应的用户
if(idt == user[i].id)
{
/// 验证用户输入的密码
for (j = 0; j < 3; j++)
{
printf("\t\t\t请输入您的密码:");
pdt = psWd();
if(pdt == user[i].pd)
{
MessageBox (NULL,TEXT("登录成功!"), TEXT("Tips"),MB_OK);
userSystem();
return;
}
else
{
printf("\n\t\t\t密码错误!\n\t\t\t你还剩%d次输入密码的机会\n\n", 2 - j);
}
}
if (j == 3)
{
MessageBox (NULL,TEXT("3次密码输入错误,退出!"), TEXT("Tips"),MB_OK);
return;
}
}
}
if(flag)
{
MessageBox (NULL,TEXT("未找到该用户!"), TEXT("Tips"),MB_OK);
}
}
}
/*
** 功能:用户注册
** 时间:17/7/10
*/
void userSignin()
{
while(true)
{
system("cls");
int numt,sext;
int pdt,choose;
int flag;
printf("\t\t==========================================\n\n");
printf("\t\t|| 欢迎使用用户系统の注册 ||\n\n");
printf("\t\t==========================================\n\n");
while(true)
{
printf("\t\t\t请输入您的注册ID:");
scanf("%d",&numt);
flag = useridCheck(numt);
if(flag == 1)
{
printf("\t\t==========================================\n\n");
printf("\t\t|| * 该用户ID可用 * ||\n\n");
printf("\t\t==========================================\n\n");
user[N+1].id = numt;
break;
}
else
{
printf("\t\t==========================================\n\n");
printf("\t\t|| * 该用户ID已存在!请重新创建 * ||\n\n");
printf("\t\t==========================================\n\n");
continue;
}
}
while(true)
{
printf("\t\t==========================================\n\n");
printf("\t\t\t请输入六位密码:\n\n");
printf("\t\t\t");
pdt = psWd();
printf("\t\t\t请确认密码:\n\n");
printf("\t\t\t");
user[N+1].pd = psWd();
if(pdt == user[N+1].pd)
{
printf("\t\t==========================================\n\n");
printf("\t\t|| * 密码设置成功 * ||\n\n");
printf("\t\t==========================================\n\n");
break;
}
else
{
printf("\n\t\t\t两次密码输入不一致!\n\t\t\t请重新输入\n\n");
}
}
printf("\t\t\t请输入您的姓名:");
scanf("%s",user[N+1].name);
printf("\n\t\t\t请输入您的年龄:");
scanf("%d",&user[N+1].age);
printf("\n\t\t\t请输入您的性别:");
printf("\n\n\t\t==========================================\n\n");
printf("\t\t|| 1 ==> 男 ||\n\n");
printf("\t\t|| 2 ==> 女 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t\t请选择:");
scanf("%d",&sext);
if(sext == 1)
{
user[N+1].sex = 1;
}
else
{
user[N+1].sex = 2;
}
printf("\n\t\t\t请输入您的联系方式:");
scanf("%s",user[N+1].tel);
printf("\n\t\t================* 用 * 户 * 信 * 息 *=================\n\n");
printf("\t\t|| 用户ID || 姓名 || 年龄 || 性别 || 联系方式 ||\n\n");
if(user[N+1].sex == 1)
{
printf("\t\t|| %d || %s || %d || 男 || %s ||\n\n",user[N+1].id,user[N+1].name,user[N+1].age,user[N+1].tel);
}
else
{
printf("\t\t|| %d || %s || %d || 女 || %s ||\n\n",user[N+1].id,user[N+1].name,user[N+1].age,user[N+1].tel);
}
MessageBox (NULL,TEXT("注册成功!"), TEXT("Tips"),MB_OK);
N++;
saveUser();
return;
///先删除掉这个我认为反人类的设计
/**
printf("\t\t==========================================\n\n");
printf("\t\t|| 是否继续?: ||\n\n");
printf("\t\t|| 1 ==> 继续 ||\n\n");
printf("\t\t|| 0 ==> 退出 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t\t请选择:");
scanf("%d",&choose);
if(choose == 0)
{
printf("\t\t==========================================\n\n");
printf("\t\t|| 感谢您的使用 ||\n\n");
printf("\t\t==========================================\n\n");
break;
}
**/
}
}
/*
** 功能:用户系统
** 时间:17/7/10
*/
void userChoose()
{
int choose;
while(true)
{
system("cls");
printf("\t\t==========================================\n\n");
printf("\t\t|| 欢迎使用图书借阅系统の用户系统 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t|| 1 ==> 登录 ||\n\n");
printf("\t\t|| 2 ==> 注册 ||\n\n");
printf("\t\t|| 0 ==> 退出 ||\n\n");
printf("\t\t==========================================\n\n");
printf("\t\t\t请选择功能号:");
scanf("%d",&choose);
if(choose == 1)
{
userLogin();
}
else if(choose == 2)
{
userSignin();
}
else
{
printf("\n\t\t\t感谢您的使用!\n\n");
return ;
}
}
}
/*
** 功能:主函数
** 时间:17/7/8
*/
int main()
{
system("COLOR 4f");
int systemTag;
Tips();
loadUser();
loadBook();
while(true)
{
systemTag = systemChoose(); /// 选择系统
if(systemTag == 0)
{
printf("\t\t==========================================\n\n");
printf("\t\t|| * 感谢您的使用 * ||\n\n");
printf("\t\t==========================================\n\n");
system("pause");
exit(0);
}
else if(systemTag == 1)
{
userChoose();
}
else
{
admLogin();
}
}
return 0;
}