You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
3.6 KiB

#include "user.h"
#include "BOOKUI.h"
#include "login.h"
#include <string.h>
int login1()
{
system("cls");
HideCursor();
showtitle();
while(1)
{
welcome();
HideCursor();
char a,b;
b = getch();
if(b==-32)
a = getch();
fflush(stdin);
if(a == UP && b == -32)
{
choice--;
}
else if(a == DOWN && b == -32)
{
choice++;
}
else if(b==13){
login2(choice);
break;
}
else{
setposition(19,12);
printf("输入“↑”或“↓”,回车键确认");
}
if(choice<0) choice = 1;
if(choice>1) choice = 0;
}
return 0;
}
int login2(int k)
{
//k==0为登陆
if(k == 0)
{
Settitle("|学生选课系统|登陆界面|");
while(1)
{
comuser(choice);
HideCursor();
char a,b;
b = getch();
if(b == -32)
a = getch();
fflush(stdin);
if(a == UP && b == -32)
{
choice--;
}
else if(a == DOWN && b == -32)
{
choice++;
}
else if(b==13){
login3(choice);
break;
}
else{
setposition(LB,12);
printf("输入“↑”或“↓”,回车键确认");
}
if(choice<0) choice = 1;
if(choice>1) choice = 0;
}
return 0;
}
//k==1为注册
if(k == 1)
{
regist();
}
return 0;
}
void login3(int k)
{
//k==0表示普通用户登陆
if(k==0)
{
Settitle("|学生选课系统|登陆界面|普通用户登陆|");
loginuser();
}
//k==1表示管理员登陆
if(k==1)
{
Settitle("|学生选课系统|登陆界面|管理员登陆|");
int lim = 5;
while(lim--)
{
if(!admin())
{
Sleep(300);
setposition(LB,15);
printf("你还剩%d次机会\n",lim);
HideCursor();
Sleep(1000);
system("cls");
showtitle();
comuser(1);
setposition(LB,12);
HideCursor2();
}
else break;
}
}
}
int admin()
{
Settitle("|学生选课系统|管理员登陆|");
char adminpw[50];
char adminpwr[50];
system("cls");
showtitle();
comuser(1);
setposition(LB,12);
HideCursor2();
printf("请输入管理员账号:");
gets(ADMIN.id);
if((fp = fopen(ADMIN.id,"r"))==NULL)
{
system("cls");
printf("\n\n\t不存在该管理员!");
printf("\n\n\t3秒后退出程序\n");
Sleep(3000);
exit(0);
}
if(fgetc(fp)==EOF)
{
printf("\n\n\t不安全的管理员!");
printf("\n\n\t3秒后退出程序\n");
Sleep(3000);
exit(0);
}
rewind(fp);
fscanf(fp,"%s",adminpwr);
setposition(LB,13);
printf("请输入管理员密码:");
gets(adminpw);
rewind(fp);
setposition(LB,14);
if(strcmp(adminpw,adminpwr) == 0)
{
fscanf(fp,"%s%s%s%s%d",ADMIN.pass,ADMIN.book1,ADMIN.book2,ADMIN.book3,&ADMIN.booknum);
close();
admin_BOOK_choice();
return 1;
}
else if(strcmp(adminpw,adminpwr) != 0)
{
printf("密码错误");
close();
return 0;
}
return 0;
}