From 69a1332ddeb376a6968c624d6037c8a4ec4274f4 Mon Sep 17 00:00:00 2001 From: 18570281412 <1509636344@qq.com> Date: Fri, 11 Jan 2019 17:22:11 +0800 Subject: [PATCH] adoptio --- BOOKUI.h | 47 ++++++ login.c | 472 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ login.h | 34 ++++ 3 files changed, 553 insertions(+) create mode 100644 BOOKUI.h create mode 100644 login.c create mode 100644 login.h diff --git a/BOOKUI.h b/BOOKUI.h new file mode 100644 index 0000000..e1eaf71 --- /dev/null +++ b/BOOKUI.h @@ -0,0 +1,47 @@ +#ifndef BOOKUI_H_INCLUDED +#define BOOKUI_H_INCLUDED + +#include +#include +#include +#include "admin.h" +#define LB 19 +#define START 3 +#define INFO 12 +int choice; +void player(); +char first[2][20]; +char login[2][20]; +void position(); +void Settitle(char *);//设置控制台标题 +void HideCursor(); //隐藏光标 +void HideCursor2(); //显示光标 +/* + +对应的颜色码表: + +0 = 黑色 8 = 灰色 + +1 = 蓝色 9 = 淡蓝色 + +2 = 绿色 10 = 淡绿色 + +3 = 浅绿色 11 = 淡浅绿色 + +4 = 红色 12 = 淡红色 + +5 = 紫色 13 = 淡紫色 + +6 = 黄色 14 = 淡黄色 + +7 = 白色 15 = 亮白色 + +*/ +void setcolor(int forecolor,int bgcolor); +void setposition(int x,int y); +void showtitle();//显示标题 +void welcome();//欢迎界面以及登陆 +void comuser(int); +void clean();//清除本行的数据 + +#endif // BOOKUI_H_INCLUDED diff --git a/login.c b/login.c new file mode 100644 index 0000000..00b1d64 --- /dev/null +++ b/login.c @@ -0,0 +1,472 @@ +#include +#include +#include +#include +#include +#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 +#include "BOOKS.h" +#include "admin.h" +FILE *fp; +typedef struct memer{ + char id[20],pass[20]; + char book1[20],book2[20],book3[20]; + int booknum; + struct memer *next; +}me; + +me*change; +me*user; + +void newone();//输入新增用户 +int newok(char * aid,char * apass,char* book1,char* book2,char* book3,int booknum);//新增用户写入链表 +void showall();//展示 +void in();//从文件读取用户数据 +void close();//关闭文件 +void save();//储存现有数据 +int regist();//注册 +void info();//提示信息 +int space(char*);//空格检测 +int AI();//验证码 +int loginuser();//普通用户登陆 +void logininfo();//登陆提示 +void enter();//登陆的实际操作 +void ID();//筛选ID +#endif // LOGIN_H_INCLUDED