|
|
|
@ -0,0 +1,472 @@
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <conio.h>
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#include "login.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
me*head = NULL;
|
|
|
|
|
|
|
|
|
|
int loginuser()
|
|
|
|
|
{
|
|
|
|
|
HideCursor2();
|
|
|
|
|
system("cls");
|
|
|
|
|
showtitle();
|
|
|
|
|
logininfo();
|
|
|
|
|
in();
|
|
|
|
|
enter();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int regist()
|
|
|
|
|
{
|
|
|
|
|
Settitle("|学生选课系统|注册界面|");
|
|
|
|
|
HideCursor2();
|
|
|
|
|
system("cls");
|
|
|
|
|
showtitle();
|
|
|
|
|
info();
|
|
|
|
|
in();
|
|
|
|
|
newone();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void logininfo()
|
|
|
|
|
{
|
|
|
|
|
setposition(LB+5,START+1);
|
|
|
|
|
printf("欢 迎 使 用 学 生 选 课 系 统");
|
|
|
|
|
setposition(LB+5,START+2);
|
|
|
|
|
printf("作 为 普 通 用 户 , 您 可 以 使 用 如 下 功 能 :");
|
|
|
|
|
setposition(LB+5,START+3);
|
|
|
|
|
printf("1. 浏 览 现 有 全 部 课 程 信 息");
|
|
|
|
|
setposition(LB+5,START+4);
|
|
|
|
|
printf("2. 选 课 与 退 课");
|
|
|
|
|
setposition(LB+5,START+6);
|
|
|
|
|
printf("登 陆 后 方 可 使 用");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void info()
|
|
|
|
|
{
|
|
|
|
|
Settitle("|学生选课系统|登陆界面|用户注册|");
|
|
|
|
|
setposition(LB+5,START+1);
|
|
|
|
|
printf("注 册 要 求 :");
|
|
|
|
|
setposition(LB+5,START+2);
|
|
|
|
|
printf("注 册 用 户 名 为 学 号");
|
|
|
|
|
setposition(LB+5,START+3);
|
|
|
|
|
printf("学 号 唯 一 , 不 可 重 复");
|
|
|
|
|
setposition(LB+5,START+4);
|
|
|
|
|
printf("学 号 与 密 码 长 度 不 多 于 2 0 个 字 符");
|
|
|
|
|
setposition(LB+5,START+5);
|
|
|
|
|
printf("无 法 注 册 管 理 员");
|
|
|
|
|
setposition(LB+5,START+6);
|
|
|
|
|
printf("账号和密码不允许出现空格若出现将自动省略空格后面部分");
|
|
|
|
|
setposition(LB+5,START+7);
|
|
|
|
|
printf("密 码 长 度 不 小 于 6 位");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void enter()
|
|
|
|
|
{
|
|
|
|
|
char aid[20],apass[20];
|
|
|
|
|
char password[20];
|
|
|
|
|
int more;
|
|
|
|
|
while(1){
|
|
|
|
|
system("cls");
|
|
|
|
|
showtitle();
|
|
|
|
|
logininfo();
|
|
|
|
|
setposition(LB+5,INFO);
|
|
|
|
|
printf("学号:");
|
|
|
|
|
scanf("%s",aid);
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
me *now = head;
|
|
|
|
|
if(now == NULL)
|
|
|
|
|
{
|
|
|
|
|
more = 0;
|
|
|
|
|
setposition(LB+5,INFO);
|
|
|
|
|
clean();
|
|
|
|
|
setposition(LB+5,INFO);
|
|
|
|
|
printf("无信息!");
|
|
|
|
|
login1();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
more = 0;
|
|
|
|
|
while(now!=NULL)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(now->id,aid) == 0)
|
|
|
|
|
{
|
|
|
|
|
user = now;
|
|
|
|
|
more = 1;
|
|
|
|
|
strcpy(password,now->pass);
|
|
|
|
|
strcpy(book1,now->book1);
|
|
|
|
|
strcpy(book2,now->book2);
|
|
|
|
|
strcpy(book3,now->book3);
|
|
|
|
|
booknum=now->booknum;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
now = now->next;
|
|
|
|
|
}
|
|
|
|
|
setposition(LB+5,INFO+1);
|
|
|
|
|
if(more == 1)
|
|
|
|
|
{
|
|
|
|
|
printf("密码:");
|
|
|
|
|
scanf("%s",apass);
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
setposition(LB+5,INFO+2);
|
|
|
|
|
if(strcmp(password,apass) == 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
books();
|
|
|
|
|
Sleep(1000);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("学号或密码错误");
|
|
|
|
|
Sleep(2000);
|
|
|
|
|
login1();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
printf("账号不存在!");
|
|
|
|
|
Sleep(2000);
|
|
|
|
|
login1();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void newone()
|
|
|
|
|
{
|
|
|
|
|
int flag = 1,more = 0;
|
|
|
|
|
char aid[21],apass[21],bpass[21];
|
|
|
|
|
do{
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
showtitle();
|
|
|
|
|
info();
|
|
|
|
|
setposition(LB,INFO);
|
|
|
|
|
printf("输入学号:");
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
scanf("%s",aid);
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
if(space(aid))
|
|
|
|
|
{
|
|
|
|
|
setposition(LB,INFO+1);
|
|
|
|
|
printf("学号非法");
|
|
|
|
|
Sleep(2000);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//查重功能
|
|
|
|
|
me *now = head;
|
|
|
|
|
if(now == NULL)
|
|
|
|
|
{
|
|
|
|
|
more = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
more = 0;
|
|
|
|
|
while(now!=NULL)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(now->id,aid) == 0)
|
|
|
|
|
{
|
|
|
|
|
more = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
now = now->next;
|
|
|
|
|
}
|
|
|
|
|
if(more == 1)
|
|
|
|
|
{
|
|
|
|
|
setposition(LB,INFO);
|
|
|
|
|
clean();
|
|
|
|
|
setposition(LB,INFO);
|
|
|
|
|
printf("学号重复!");
|
|
|
|
|
Sleep(2000);
|
|
|
|
|
}
|
|
|
|
|
else if(strlen(aid)>20)
|
|
|
|
|
{
|
|
|
|
|
setposition(LB,INFO);
|
|
|
|
|
clean();
|
|
|
|
|
setposition(LB,INFO);
|
|
|
|
|
printf("学号过长!");
|
|
|
|
|
Sleep(2000);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//查重功能
|
|
|
|
|
setposition(LB,INFO+1);
|
|
|
|
|
printf("请输入密码:");
|
|
|
|
|
gets(apass);
|
|
|
|
|
if(space(apass))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
setposition(LB,INFO+2);
|
|
|
|
|
printf("密码非法");
|
|
|
|
|
Sleep(2000);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else if(strlen(apass) > 20 || strlen(apass) < 6)
|
|
|
|
|
{
|
|
|
|
|
setposition(LB,INFO+1);
|
|
|
|
|
clean();
|
|
|
|
|
setposition(LB,INFO);
|
|
|
|
|
printf("密码长度不合法!");
|
|
|
|
|
Sleep(2000);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
setposition(LB,INFO+2);
|
|
|
|
|
printf("确认你的密码:");
|
|
|
|
|
gets(bpass);
|
|
|
|
|
if(strcmp(apass,bpass) == 0) flag = 0;
|
|
|
|
|
else {
|
|
|
|
|
setposition(LB,INFO+3);
|
|
|
|
|
printf("两次密码输入不一致!");
|
|
|
|
|
Sleep(1000);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(AI()){
|
|
|
|
|
setposition(LB,INFO+5);
|
|
|
|
|
printf("验证码错误!");
|
|
|
|
|
flag = 1;
|
|
|
|
|
Sleep(1000);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}while(flag);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setposition(LB,INFO+5);
|
|
|
|
|
HideCursor();
|
|
|
|
|
if(newok(aid,apass,"o","o","o",0))
|
|
|
|
|
{
|
|
|
|
|
printf("注册成功!");
|
|
|
|
|
Settitle("|学生选课系统|注册成功|");
|
|
|
|
|
int cnt = 0,cnt2;
|
|
|
|
|
for(cnt2 = 0; cnt2 < 3; cnt2++)
|
|
|
|
|
{
|
|
|
|
|
setposition(LB+10,INFO+5);
|
|
|
|
|
printf(" ");
|
|
|
|
|
Sleep(300);
|
|
|
|
|
setposition(LB+10,INFO+5);
|
|
|
|
|
for(cnt = 0;cnt < 3;cnt++)
|
|
|
|
|
{
|
|
|
|
|
printf(".");
|
|
|
|
|
Sleep(300);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
system("cls");
|
|
|
|
|
save();
|
|
|
|
|
Sleep(200);
|
|
|
|
|
login1();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("注册失败");
|
|
|
|
|
Sleep(300);
|
|
|
|
|
system("cls");
|
|
|
|
|
login1();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int newok(char * aid,char * apass,char* book1,char* book2,char* book3,int booknum)
|
|
|
|
|
{
|
|
|
|
|
me *new1 = NULL;
|
|
|
|
|
me *now = head;
|
|
|
|
|
new1 = (me*)malloc(sizeof(me));
|
|
|
|
|
if(new1 == NULL)
|
|
|
|
|
{
|
|
|
|
|
return 0;//返回0表示失败
|
|
|
|
|
}
|
|
|
|
|
if(head==NULL)
|
|
|
|
|
{
|
|
|
|
|
head = new1;
|
|
|
|
|
new1->next = NULL;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
while(now->next!=NULL)
|
|
|
|
|
{
|
|
|
|
|
now = now->next;
|
|
|
|
|
}
|
|
|
|
|
now->next = new1;
|
|
|
|
|
}
|
|
|
|
|
new1->next = NULL;
|
|
|
|
|
strcpy(new1->id,aid);
|
|
|
|
|
strcpy(new1->pass,apass);
|
|
|
|
|
strcpy(new1->book1,book1);
|
|
|
|
|
strcpy(new1->book2,book2);
|
|
|
|
|
strcpy(new1->book3,book3);
|
|
|
|
|
new1->booknum = booknum;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void showall()
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
showtitle();
|
|
|
|
|
admin_BOOK_info();
|
|
|
|
|
me *now = head;
|
|
|
|
|
if(now == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("用户信息丢失!");
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
int k = 0;
|
|
|
|
|
while(now!=NULL)
|
|
|
|
|
{
|
|
|
|
|
setposition(LB,INFO+k);
|
|
|
|
|
k++;
|
|
|
|
|
char dat1[20],dat2[20],dat3[20];
|
|
|
|
|
strcpy(dat1,now->book1);
|
|
|
|
|
strcpy(dat2,now->book2);
|
|
|
|
|
strcpy(dat3,now->book3);
|
|
|
|
|
if(strcmp(dat1 , "o") == 0) {dat1[0] = ' ' ; dat1[1] = 0;}
|
|
|
|
|
if(strcmp(dat2 , "o") == 0) {dat2[0] = ' ' ; dat2[1] = 0;}
|
|
|
|
|
if(strcmp(dat3 , "o") == 0) {dat3[0] = ' ' ; dat3[1] = 0;}
|
|
|
|
|
printf("ID = %s PASSWORD = %s CLASS:%s %s %s",now->id,now->pass,dat1,dat2,dat3);
|
|
|
|
|
now = now->next;
|
|
|
|
|
}
|
|
|
|
|
if(k == 0){
|
|
|
|
|
setposition(LB,INFO);
|
|
|
|
|
clean();
|
|
|
|
|
setposition(LB,INFO);
|
|
|
|
|
printf("用户细信息丢失");
|
|
|
|
|
}
|
|
|
|
|
setposition(LB,INFO+k);
|
|
|
|
|
}
|
|
|
|
|
system("pause");
|
|
|
|
|
admin_BOOK_choice();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ID()
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
showtitle();
|
|
|
|
|
admin_BOOK_info();
|
|
|
|
|
me *now = head;
|
|
|
|
|
char id[20];
|
|
|
|
|
setposition(LB,INFO);
|
|
|
|
|
printf("输入用户的ID:");
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
scanf("%s",id);
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
if(now == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("用户信息丢失!");
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
int k = 1;
|
|
|
|
|
while(now!=NULL)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(now->id,id) == 0)
|
|
|
|
|
{
|
|
|
|
|
change = now;
|
|
|
|
|
setposition(LB,INFO+k);
|
|
|
|
|
k++;
|
|
|
|
|
char dat1[20],dat2[20],dat3[20];
|
|
|
|
|
strcpy(dat1,now->book1);
|
|
|
|
|
strcpy(dat2,now->book2);
|
|
|
|
|
strcpy(dat3,now->book3);
|
|
|
|
|
if(strcmp(dat1 , "o") == 0) {dat1[0] = ' ' ; dat1[1] = 0;}
|
|
|
|
|
if(strcmp(dat2 , "o") == 0) {dat2[0] = ' ' ; dat2[1] = 0;}
|
|
|
|
|
if(strcmp(dat3 , "o") == 0) {dat3[0] = ' ' ; dat3[1] = 0;}
|
|
|
|
|
printf("ID = %s PASSWORD = %s CLASS:%s %s %s",now->id,now->pass,dat1,dat2,dat3);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
now = now->next;
|
|
|
|
|
}
|
|
|
|
|
if(k == 1){
|
|
|
|
|
setposition(LB,INFO+1);
|
|
|
|
|
clean();
|
|
|
|
|
setposition(LB,INFO+1);
|
|
|
|
|
printf("不存在该用户");
|
|
|
|
|
Sleep(800);
|
|
|
|
|
admin_BOOK_choice();
|
|
|
|
|
}
|
|
|
|
|
setposition(LB,INFO+k);
|
|
|
|
|
}
|
|
|
|
|
system("pause");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void in()
|
|
|
|
|
{
|
|
|
|
|
if((fp = fopen("norusers.dat","r"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
if((fp = fopen("norusers.dat","w"))==NULL)
|
|
|
|
|
printf("\nopen error\n");
|
|
|
|
|
else {
|
|
|
|
|
close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
head = NULL;
|
|
|
|
|
if(fgetc(fp)==EOF) return;
|
|
|
|
|
rewind(fp);
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
char a[20],b[20],book1[20],book2[20],book3[20];
|
|
|
|
|
int booknum;
|
|
|
|
|
fscanf(fp,"%s%s%s%s%s%d",a,b,book1,book2,book3,&booknum);
|
|
|
|
|
newok(a,b,book1,book2,book3,booknum);
|
|
|
|
|
}
|
|
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void save()
|
|
|
|
|
{
|
|
|
|
|
setposition(LB,INFO+3);
|
|
|
|
|
me *now = head;
|
|
|
|
|
if((fp = fopen("norusers.dat","w"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("打开文件失败");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
while(now!=NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf(fp," %s %s %s %s %s %d",now->id,now->pass,now->book1,now->book2,now->book3,now->booknum);
|
|
|
|
|
now = now->next;
|
|
|
|
|
}
|
|
|
|
|
close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void close()
|
|
|
|
|
{
|
|
|
|
|
setposition(LB,INFO+3);
|
|
|
|
|
if(fclose(fp))
|
|
|
|
|
{
|
|
|
|
|
printf("关闭文件失败");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int space(char *a)
|
|
|
|
|
{
|
|
|
|
|
int i,sum = 0;
|
|
|
|
|
for(i = 0; i <strlen(a);i++)
|
|
|
|
|
{
|
|
|
|
|
if(a[i] == ' ') sum++;
|
|
|
|
|
}
|
|
|
|
|
return sum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int AI()
|
|
|
|
|
{
|
|
|
|
|
int a,b;
|
|
|
|
|
srand(time(NULL));
|
|
|
|
|
a = rand();
|
|
|
|
|
if(a <= 999)
|
|
|
|
|
{
|
|
|
|
|
a += 1000;
|
|
|
|
|
}
|
|
|
|
|
setposition(LB,INFO+3);
|
|
|
|
|
printf("请输入验证码:%d",a%10000);
|
|
|
|
|
setposition(LB+14,INFO+4);
|
|
|
|
|
scanf("%d",&b);
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
if(a%10000 == b) return 0;
|
|
|
|
|
else return 1;
|
|
|
|
|
}
|