?? stumanager.c
字號(hào):
#include <Conio.h>
#include <graphics.h>
#include <stdio.h>
#include <string.h>
#include <bios.h>
#include <stdlib.h>
#include "include.h"
void FileInit(void) /*初始化文件*/
{
FILE *fp;
char ch[][7]={"Class1","Class2","Class3"};
fp=fopen("stu.txt","r");
if(fp==NULL)
{
fp=fopen("stu.txt","w");
fprintf(fp,"%-5s%5d\r\n",ch[0],0);
fprintf(fp,"%-5s%5d\r\n",ch[1],0);
fprintf(fp,"%-5s%5d\r\n",ch[2],0);
fclose(fp);
}
else fclose(fp);
fp=fopen("info.txt","r");
if(fp==NULL)
{
fp=fopen("info.txt","w");
fprintf(fp,"%-5s%5d\r\n",ch[0],0);
fprintf(fp,"%-5s%5d\r\n",ch[1],0);
fprintf(fp,"%-5s%5d\r\n",ch[2],0);
fclose(fp);
}
else fclose(fp);
return;
}
void initgr(void)
{
int gd = DETECT, gm = 0;
registerbgidriver(EGAVGA_driver);
initgraph(&gd, &gm, "");
}
int main(void)
{
int accept=0,time=0;
char name[11]="";
FileInit();
initgr();
Operate(accept,time,name);
Draw();
getch();
closegr();
return 0;
}
void Member(int accept,char name[])
{
int i,n,j;
char temp[11]="";
char name1[11]="";
int yes=0;
FILE*fp;
if(accept==3||accept==2)
MemberList(name,accept);
else
{
fp=fopen("stu.txt","r");
for(i=0;i<3;i++)
{
fscanf(fp,"%s%d",temp,&n);
for(j=0;j<n;j++)
{
fscanf(fp,"%s%s%s",name1,temp,temp);
if(strcmp(name,name1)==0)
{
yes=1;
break;
}
}
if(yes==1)
break;
}
fclose(fp);
OperateClass(name,accept,i);
}
return;
}
void MemberList(char name[],int accept)
{
int key=0;
int i=0;
DrawMember(0);
while(1)
{
key=bioskey(0);
switch(key)
{
case Down:
if(i>=0&&i<2)
{
i++;
DrawMember(i);
}
break;
case Up:
if(i<=3&&i>0)
{
i--;
DrawMember(i);
}
break;
case Esc:setfillstyle(1,7);bar(120,37,200,82);return;
case Enter:
OperateClass(name,accept,i);break;
default:break ;
}
}
return;
}
void OperateClass(char name[],int accept,int t) /*參數(shù)傳遞成功*/
{
if(accept==1)
ShowInfo(name);
else
{
DrawMemberInfo();
OperateInfo(t+1);
}
setfillstyle(1,7);
bar(80,90,505,400);
return;
}
void DrawMemberInfo()
{
int x1=90,x2=505,y1=90,y2=390;
int i=0;
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," < >");
return;
}
void Draw(void)
{
char Title[]="STUDENT MANAGER";
setbkcolor(7);
setfillstyle(1,3);
bar(0,0,645,20);
setcolor(4);
line(0,20,645,20);
outtextxy(15,10,Title);
setfillstyle(1,8);
bar(0,23,645,35);
setcolor(YELLOW);
outtextxy(25,25,ch[0]);
outtextxy(325,25,ch[3]);
outtextxy(425,25,ch[4]);
setcolor(7);
outtextxy(225,25,ch[2]);
outtextxy(125,25,ch[1]);
return ;
}
void Drawyes(void)
{
char Mem[]="Member";
char Input[]="Input";
char Correct[]="Correct";
Draw();
setcolor(YELLOW);
outtextxy(125,25,Mem);
outtextxy(225,25,Input);
outtextxy(525,25,Correct);
return ;
}
void DrawMember(int m) /*畫(huà)下拉菜單2 Member*/
{
char Class[][7]={"Class1","Class2","Class3"};
int i=0;
setfillstyle(1,11);
bar(120,37,200,82);
setcolor(WHITE);
for(i=0;i<3;i++)
{
outtextxy(125,43+i*15,Class[i]);
}
setfillstyle(1,8);
bar(120,37+15*m,200,37+15*(m+1));
setcolor(RED);
outtextxy(125,43+m*15,Class[m]);
return;
}
void DrawLogin(int i)
{
int x1=190,x2=410,y1=200,y2=350;
int w=5;
char user[]="User : ";
char pass[]="Password :";
char ok[]="login";
char exit[]="Exit";
char title[]="LOGIN";
setfillstyle(1,12); /*畫(huà)登陸窗口*/
bar(x1,y1,x2,y2);
setfillstyle(1,3);
bar(x1-w,y1-w,x2+w,y1);
bar(x1-w,y2,x2+w,y2+w);
bar(x1-w,y1,x1,y2);
bar(x2,y1,x2+w,y2);
/*打印項(xiàng)目*/
setcolor(0);
outtextxy(220,270,user);
outtextxy(220,290,pass);
outtextxy(220,320,ok);
outtextxy(370,320,exit);
setcolor(1);
outtextxy(270,230,title);
setfillstyle(1,15);
bar(310,270,400,280); /* 文本框 */
bar(310,290,400,300);
switch(i)
{
case 3:
setfillstyle(1,10);
bar(218,318,263,330) ;
setcolor(1);
outtextxy(220,320,ok);
break;
case 4:
setfillstyle(1,10);
bar(360,318,405,330);
setcolor(1);
outtextxy(370,320,exit);
break;
default:break;
}
return;
}
void DrawCorrect(int i,char name[])
{
int x1=190,x2=410,y1=200,y2=350;
int w=5;
char pass[]="Password : ";
char again[]="Again :";
char ok[]="OK";
char cancel[]="Cancel";
char title[]="CORRECT";
setfillstyle(1,12); /*畫(huà)登陸窗口*/
bar(x1,y1,x2,y2);
setfillstyle(1,3);
bar(x1-w,y1-w,x2+w,y1);
bar(x1-w,y2,x2+w,y2+w);
bar(x1-w,y1,x1,y2);
bar(x2,y1,x2+w,y2);
/*打印項(xiàng)目*/
setcolor(0);
outtextxy(220,250,"User:");
outtextxy(220,270,pass);
outtextxy(220,290,again);
outtextxy(220,320,ok);
outtextxy(350,320,cancel);
setcolor(GREEN);
outtextxy(310,250,name);
setcolor(1);
outtextxy(260,230,title);
setfillstyle(1,15);
bar(310,270,400,280); /* 文本框 */
bar(310,290,400,300);
switch(i)
{
case 3:
setfillstyle(1,10);
bar(218,318,263,330) ;
setcolor(1);
outtextxy(220,320,ok);
break;
case 4:
setfillstyle(1,10);
bar(348,318,405,330);
setcolor(1);
outtextxy(350,320,cancel);
break;
default:break;
}
return;
}
void Correct(char name[])
{
void *text1,*text2;
int key;
int size1,size2;
int i=0,n1=0,n2=0;
char pass[11]="";
char again[11]="";
char test[2]="";
size1=imagesize(310,270,400,280);
size2=imagesize(310,290,400,300);
text1=malloc(size1);
text2=malloc(size2);
DrawCorrect(0,name);
while(1)
{
key=bioskey(0);
switch(key)
{
case Tab:
if(i>=0&&i<4)
i++;
else i=1;
getimage(310,270,400,280,text1);
getimage(310,290,400,300,text2);
DrawCorrect(i,name);
putimage(310,270,text1,0);
putimage(310,290,text2,0);
setfillstyle(1,15);
if(i==1)
line(310+n1*8+2,279,310+(n1+1)*8-2,279);
else if(i==2)
{ bar(310+n1*8,270,310+(n1+1)*8,280);
line(310+n2*8+2,299,310+(n2+1)*8-2,299);
}
else if(i==3)
bar(310+n2*8,290,310+(n2+1)*8,300);
break;
case Esc: setfillstyle(1,7);bar(180,190,420,360);return ;
case Backspace:
if(i==1&&n1>0)
{
setfillstyle(1,15);
bar(310+(n1-1)*8,270,310+n1*8,280);
bar(310+n1*8,270,310+(n1+1)*8,280);
line(310+(n1-1)*8+2,279,310+n1*8-2,279);
n1--;
pass[n1]='\0';
}
else if(i==2&&n2>0)
{
setfillstyle(1,15);
bar(310+(n2-1)*8,290,310+n2*8,300) ;
bar(310+n2*8,290,310+(n2+1)*8,300);
line(310+(n2-1)*8+2,299,310+n2*8-2,299);
n2--;
again[n2]='\0';
}
break;
case Enter:
if(i==4)
{
setfillstyle(1,7);
bar(185,195,415,355);
return;
}
PermitCorrect(name,pass,again);
getch();
setfillstyle(1,7);
bar(185,195,415,355);
return;
default :
if(i==1&&n1<10)
{
sprintf(test,"%c",key);
setfillstyle(1,15);
bar(310+n1*8,270,310+(n1+1)*8,280);
outtextxy(311+n1*8,271,"*");
strcat(pass,test);
n1++;
line(310+n1*8+2,279,310+(n1+1)*8-2,279);
}
else if(i==2&&n2<10)
{
sprintf(test,"%c",key);
setfillstyle(1,15);
bar(310+n2*8,290,310+(n2+1)*8,300);
outtextxy(311+n2*8,290,"*");
strcat(again,test);
n2++ ;
line(310+n2*8+2,299,310+(n2+1)*8-2,299);
}
break;
}
}
}
void PermitCorrect(char name[],char pass[],char again[])
{
char temp[11];
FILE*fp;
int n1,n2,n3,j=0;
struct Info*p1,*p2,*p3,*head1,*head2,*head3,*q;
if(strcmp(pass,"")==0||strcmp(again,"")==0)
{
setfillstyle(1,3);
bar(230,260,380,320);
setcolor(7);
outtextxy(285,280,"ERROR!");
outtextxy(250,300,"Password empty!");
return;
}
if(strcmp(pass,again)!=0)
{
setfillstyle(1,3);
bar(230,260,380,320);
setcolor(7);
outtextxy(285,280,"ERROR!");
outtextxy(250,300,"Password differ!");
return;
}
head1=p1=(struct Info*)malloc(sizeof(struct Info));
p1->next=NULL;
fp=fopen("stu.txt","r");
fscanf(fp,"%s%d",temp,&n1);
for(j=0;j<n1;j++)
{
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(name,p1->name)==0) q=p1;
}
head2=p2=(struct Info*)malloc(sizeof(struct Info));
p2->next=NULL;
fscanf(fp,"%s%d",temp,&n2);
for(j=0;j<n2;j++)
{
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(name,p2->name)==0) q=p2;
}
head3=p3=(struct Info*)malloc(sizeof(struct Info));
p3->next=NULL;
fscanf(fp,"%s%d",temp,&n3);
for(j=0;j<n3;j++)
{
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(name,p3->name)==0) q=p3;
}
strcpy(q->pass,pass);
fclose(fp);
fp=fopen("stu.txt","w");
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);
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -