📄 stumanager.c
字号:
bar(185,145,415,355);
return;
case Left:
case Up:
case Down:break;
case Esc:
setfillstyle(1,7);
bar(185,145,415,355);
return;
default:
if(i==1&&n1<10)
{
sprintf(test,"%c",key);
setfillstyle(1,15);
bar(310+n1*8,220,310+(n1+1)*8,230);
outtextxy(311+n1*8,221,test);
strcat(name,test);
n1++;
line(310+n1*8+2,229,310+(n1+1)*8-2,229);
}
else if(i==3&&n3<10)
{
sprintf(test,"%c",key);
setfillstyle(1,15);
bar(310+n3*8,260,310+(n3+1)*8,270);
outtextxy(311+n3*8,261,"*");
strcat(password1,test);
n3++;
line(310+n3*8+2,269,310+(n3+1)*8-2,269);
}
else if(i==4&&n4<10)
{
sprintf(test,"%c",key);
setfillstyle(1,15);
bar(310+n4*8,280,310+(n4+1)*8,290);
outtextxy(311+n4*8,281,"*");
strcat(password2,test);
n4++;
line(310+n4*8+2,289,310+(n4+1)*8-2,289);
}
break;
}
}
return;
}
/*注册过程进行数据确认*/
void Permit(struct stu*p)
{
FILE *fp;
struct Info *p1,*p2,*p3,*q,*head1,*head2,*head3;
int n1=0,n2=0,n3=0,i=0;
char temp[7]="";
int cla=0;
int error=0;
if(strcmp(p->user,"")==0)
error=1;
if((strcmp(p->pass1,p->pass2)!=0)&&(error==0))
error=2;
if((strcmp(p->pass1,"")==0)&&(error==0))
error=4;
if(strcmp(p->Class,"Class1")==0)
cla=1;
else if(strcmp(p->Class,"Class2")==0)
cla=2;
else if(strcmp(p->Class,"Class3")==0)
cla=3;
if(error!=0)
{
if(error==1)
{
setcolor(2);outtextxy(220,195,"Error!");
outtextxy(220,205,"Empty Name!");
}
else if(error==2)
{
setcolor(2);outtextxy(220,195,"Error!");
outtextxy(220,205,"The password is differ!");
}
else if(error==4)
{
setcolor(2);outtextxy(220,195,"Error!");
outtextxy(220,205,"The password is empty!");
}
return ;
}
p1=p2=p3=q=NULL;
fp=fopen("stu.txt","r");
if(fp==NULL) { outtextxy(220,205,"Open failed!");return; }
/*读取Class1文件*/
fscanf(fp,"%s%d",temp,&n1);
p1=q=head1=(struct Info*)malloc(sizeof(struct Info));
for(i=0;i<n1;i++)
{
q=p1;
p1=p1->next=(struct Info*)malloc(sizeof(struct Info));
p1->next=NULL;
fscanf(fp,"%s%s%s",p1->name,p1->pass,p1->pope);
if(strcmp(p->user,p1->name)==0)
{
error=3;
break;
}
}
if(error==3) /*如遇重名,释放内存*/
{
setcolor(2);
outtextxy(220,195,"Error!");
outtextxy(220,205,"The user is existed!");
p1=head1;
while(p1)
{
q=p1;
free(p1);
p1=p1->next;
}
fclose(fp);
return;
}
/*读取Class2文件*/
fscanf(fp,"%s%d",temp,&n2);
q=p2=head2=(struct Info*)malloc(sizeof(struct Info));
for(i=0;i<n2;i++)
{
q=p2;
p2=p2->next=(struct Info*)malloc(sizeof(struct Info));
p2->next=NULL;
fscanf(fp,"%s%s%s",p2->name,p2->pass,p2->pope);
if(strcmp(p->user,p2->name)==0)
{
error=3;
break;
}
}
if(error==3)
{
setcolor(2);
outtextxy(220,195,"Error!");
outtextxy(220,205,"The user is existed!");
p1=head1;
p2=head2;
while(p1)
{
q=p1;
free(p1);
p1=q->next;
}
while(p1)
{
q=p2;
free(p2);
p2=q->next;
}
fclose(fp);
return;
}
/*读取Class3文件*/
fscanf(fp,"%s%d",temp,&n3);
q=p3=head3=(struct Info*)malloc(sizeof(struct Info));
for(i=0;i<n3;i++)
{
q=p3;
p3=p3->next=(struct Info*)malloc(sizeof(struct Info));
p3->next=NULL;
fscanf(fp,"%s%s%s",p3->name,p3->pass,p3->pope);
if(strcmp(p->user,p3->name)==0)
{
error=3;
break;
}
}
if(error==3)
{
setcolor(2);
outtextxy(220,195,"Error!");
outtextxy(220,205,"The user is existed!");
p1=head1;
p2=head2;
p3=head3;
while(p1)
{
q=p1;
free(p1);
p1=q->next;
}
while(p2)
{
q=p2;
free(p2);
p2=q->next;
}
while(p3)
{
q=p3;
free(p3);
p3=q->next;
}
fclose(fp);
return;
}
fclose(fp);
if(strcmp(p->Class,"Class1")==0)
{
if(n1==0)
{
p1=head1->next=(struct Info*)malloc(sizeof(struct Info));
}
else
{
p1=p1->next=(struct Info*)malloc(sizeof(struct Info));
}
n1++;
strcpy(p1->name,p->user);
strcpy(p1->pass,p->pass1);
strcpy(p1->pope,"stu");
p1->next=NULL;
}
else if(strcmp(p->Class,"Class2")==0)
{
if(n2==0)
{
p2=head2->next=(struct Info*)malloc(sizeof(struct Info));
}
else
{
p2=p2->next=(struct Info*)malloc(sizeof(struct Info));
}
n2++;
strcpy(p2->name,p->user);
strcpy(p2->pass,p->pass1);
strcpy(p2->pope,"stu");
p2->next=NULL;
}
else if(strcmp(p->Class,"Class3")==0)
{
if(n3==0)
{
p3=head3->next=(struct Info*)malloc(sizeof(struct Info));
}
else
{
p3=p3->next=(struct Info*)malloc(sizeof(struct Info));
}
n3++;
strcpy(p3->name,p->user);
strcpy(p3->pass,p->pass1);
strcpy(p3->pope,"stu");
p3->next=NULL;
}
fp=fopen("stu.txt","w");
if(fp==NULL) { outtextxy(220,205,"Open failed!");return; }
fprintf(fp,"%-5s%5d\n","Class1",n1);
p1=head1->next;
free(head1);
while(p1)
{
fprintf(fp,"%-10s%10s%10s\r\n",p1->name,p1->pass,p1->pope);
q=p1;
p1=p1->next;
free(q);
}
fprintf(fp,"\n%-5s%5d\n","Class2",n2);
p2=head2->next;
free(head2);
while(p2)
{
fprintf(fp,"%-10s%10s%10s\r\n",p2->name,p2->pass,p2->pope);
q=p2;
p2=p2->next;
free(q);
}
fprintf(fp,"\n%-5s%5d\n","Class3",n3);
p3=head3->next;
free(head3);
while(p3)
{
fprintf(fp,"%-10s%10s%10s\r\n",p3->name,p3->pass,p3->pope);
q=p3;
p3=p3->next;
free(q);
}
fclose(fp); /****************************************************/
Update1(cla); /*添加更新函数*/
setcolor(2); /****************************************************/
outtextxy(220,195,"Congratulations!");
outtextxy(220,205,"Register success!");
return;
}
void Operate(int accept,int time,char name[]) /*对主界面进行操作*/
{
int key;
struct log*p=(struct log*)malloc(sizeof(struct log));
if(accept==0)
{
Draw();
}
else
{
Drawyes();
}
setfillstyle(1,GREEN);
bar(20+time*100,23,90+time*100,35);
setcolor(RED);
outtextxy(25+100*time,25,ch[time]);
while(1)
{
key=bioskey(0);
switch(key)
{
case Right:
if(time>=0&&time<4)
{
if(time==0&&accept==0)
time+=3;
else
time++;
Operate(accept,time,name);
}
if(time==4&&accept!=0)
{
time++;Operate(accept,time,name);
}
break;
case Left:
{
if(time<=5&&time>0)
{
if(time==3&&accept==0)
time-=3;
else
time--;
Operate(accept,time,name);
}
break;
}
case Enter:
{
switch(time)
{
/**/ case 0:File();break;
case 1:Member(accept,name);break;
case 2:Input(name,accept);break;
case 3:
if(accept==0)
{ p=Login();Operate(p->accept,time,p->name); } /*p已成功传回*/
else
{ accept=Logout(accept);Operate(accept,time,name);}
break;
case 4:
Register();break;
case 5:
Correct(name);break;
default:break;
}
}
break;
default:break;
}
}
}
void ShowInfo (char name[])
{
int x1=90,x2=505,y1=90,y2=390;
int i=0;
int cla=1;
int n;
int yes=0;
char temp1[11]="",user[11]="";
FILE*fp;
fp=fopen("stu.txt","r");
for(cla=1;cla<4;cla++)
{
fscanf(fp,"%s%d",temp1,&n);
for(i=0;i<n;i++)
{
fscanf(fp,"%s%s%s",user,temp1,temp1);
if(strcmp(user,name)==0)
{
yes=1;break;
}
}
if(yes==1)break;
}
fclose(fp);
/**********************画图******************/
setfillstyle(1,10);
bar(x1,y1,x2,y1+20);
bar(x1,y1+20,x1+10,y2);
bar(x2-10,y1+20,x2,y2);
bar(x1+10,y2-5,x2-10,y2);
setcolor(15);
outtextxy(x1+30,y1+25,"Name");
outtextxy(x1+25+10*8+10,y1+25,"Iden") ;
outtextxy(260,y1+25,"Math");
outtextxy(312,y1+25,"Eng");
outtextxy(364,y1+25,"C");
outtextxy(416,y1+25,"C++");
outtextxy(458,y1+25,"Java");
setfillstyle(1,15);
bar(x1+12,y1+42,x2-12,y2-7);
setcolor(7);
line(x1+25+10*8,y1+42,x1+25+10*8,y2-7);
line(x1+25+10*8+50,y1+42,x1+25+10*8+50,y2-7);
for(i=1;i<5;i++)
line(245+i*52,y1+42,245+i*52,y2-7);
setcolor(7);
outtextxy(430,100," < >");
OperateInfo(cla);
setfillstyle(1,7);
bar(x1-10,y1,x2+10,y2+10);
return;
}
void OperateInfo(int cla)
{
FILE *fp=NULL;
int t;
int n,j,i;
int k;
int p=1;
int key=0;
int temp=0;
char name[11];
fp=fopen("Info.txt","r");
for(i=0;i<cla-1;i++)
{
fscanf(fp,"%s%d",name,&n);
for(j=0;j<n;j++)
fscanf(fp,"%s%s%d%d%d%d%d",name,name,&temp,&temp,&temp,&temp,&temp);
}
fscanf(fp,"%s%d",name,&n);
fclose(fp);
t=n/16;
if(n%16!=0) t++;
setcolor(5);
if(cla==1)
outtextxy(280,95,"Class1");
else if(cla==2)
outtextxy(280,95,"Class2");
else if(cla==3)
outtextxy(280,95,"Class3");
Display(cla,p);
while(1)
{
key=bioskey(0);
switch(key)
{
case Right:
{
if(p<t)
{
p++;Display(cla,p);
}
break;
}
case Left:
{
if(p>1)
{
p--;Display(cla,p);
}
}
break;
case Esc:return;
default:break;
}
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -