📄 system_gui.c
字号:
#include "mydb.h"
char *term[]={"大一上","大一下","大二上","大二下","大三上","大三下","大四上","大四下"};
char waitgui[]="\\\|\/\-";
void login_gui()
{
if(!myfileinfo)
{
myfileinfo=NEW(fileinfo);
fcntl(0,READ,myfileinfo,FILEINFOSIZE);
}
char buf[20]={0},choice;
printf("\n欢迎使用我的成绩查询系统!\n");
if(!myfileinfo->stucount)
{
printf("\n系统初始密码为macosx!可进入系统后对其修改...\n");
printf("\n请您记好,下次登录本系统将会用到!\n");
system_gui();return;
}
while(1)
{
printf("\n\n请输入登录密码:");
INPUTBUF(buf);
if(!strcmp(buf,myfileinfo->key))
{
system_gui();
return;
}
else
{
printf("\n\n对不起,登录密码错误!重新输入吗?\n");
do
{
printf("\n1=重新输入 0=退出 :");
INPUTBUF(buf);
if(strlen(buf)-1)continue;
choice=*buf;
}while(choice-0x30&&choice-0x31);
if(choice==0x30)return;
}
}
}
bool system_gui()
{
if(!myfileinfo)
{
myfileinfo=NEW(fileinfo);
fcntl(0,READ,myfileinfo,FILEINFOSIZE);
}
int stucount=myfileinfo->stucount;
char choice,flag=1,buf[20];
while(!stucount)
{
printf("\n\n数据库为空!您需要添加新数据:\n\n");
printf("1.人工添加 2.系统自动添加\n");
do
{
printf("\n请作出选择:");
INPUTBUF(buf);
if(strlen(buf)-1)continue;
choice=*buf;
}while(choice-0x31&&choice-0x32);
system("cls");
if(choice==0x32)MakeDataBase();
else addstu_gui();
stucount=myfileinfo->stucount;
}
int subcount=myfileinfo->subcount;
while(!subcount)
{
printf("\n\n数据库中无任何科目!您需要添加新的科目:\n\n");
printf("1.人工添加 2.系统自动添加\n");
do
{
printf("\n请作出选择:");
INPUTBUF(buf);
if(strlen(buf)-1)continue;
choice=*buf;
}while(choice-0x31&&choice-0x32);
system("cls");
if(choice==0x32)makesub();
else editsub_gui(ADDSUB);
subcount=myfileinfo->subcount;
}
while(flag)
{
stucount=myfileinfo->stucount;
subcount=myfileinfo->subcount;
int subsitu;int tempflag=1;
while(tempflag)
{
tempflag=0;system("cls");
printf("\n 本程序由Professor Li完成!\n\n");
printf("1.添加学生\t\t\t2.编辑学生\t\t\t3.搜索学生\n");
printf("4.显示分数\t\t\t5.编辑分数\t\t\t6.修改密码\n");
if(subcount>0&&subcount<MAXSUBCOUNT)
{
printf("7.添加科目\t\t\t8.编辑科目\t\t\t9.退出程序\n\n");
subsitu=0;
}
if(!subcount)
{
printf("7.添加科目\t\t\t8.退出程序\n\n");
subsitu=1;
}
if(subcount&&subcount==MAXSUBCOUNT)
{
printf("7.编辑科目\t\t\t8.退出程序\n\n");
subsitu=2;
}
printf("\n请作出选择:");
INPUTBUF(buf);
if(strlen(buf)-1){tempflag=1;continue;}
choice=*buf;
if(!subsitu){if(choice<0x31||choice>0x39)tempflag=1;}
else if(choice<0x31||choice>0x38)tempflag=1;
}
printf("\n");
switch(choice)
{
case 0x31:addstu_gui();break;
case 0x32:editstu_gui();break;
case 0x33:search_gui();break;
case 0x34:showmark_gui();break;
case 0x35:editmark_gui();break;
case 0x36:changekey_gui();break;
case 0x37:if(!subsitu)editsub_gui(ADDSUB);
else editsub_gui(EDITSUB);break;
case 0x38:if(!subsitu)editsub_gui(EDITSUB);
else flag=0;break;
case 0x39:flag=0;break;
default:printf("\n\n请进行正确的输入!\n\n");break;
}
if(flag){printf("\n请按任意键继续.....");getch();}
if(!flag)
{
int j;
printf("\n请稍后,系统正在存储数据");
for(j=0;j<40;j++)
{
int i;
for(i=0;i<BIGNUMBER;i++);
printf("%c\b",waitgui[j%4]);
if(!(j%10))printf(".");
}
printf(".");
showfile();
}
}
freeparam();
return TRUE;
}
//本函数用于判别一个学号是否合法
bool isschid(char *buf)
{
int size=strlen(buf);
if(size-12)return FALSE;
int i=0;
for(;i<size;i++)
{
if(buf[i]<48||buf[i]>57)
{
printf("\n学号必须为数字!\n");
return FALSE;
}
}
return TRUE;
}
//本函数用于解决同名学生的选择问题
plink findstu_gui(char* stuname)
{
plink linkhead=NULL;char buf[20]={0};
while(1)
{
printf("\n请输入所要编辑的学生的学号:");
INPUTBUF(buf);
if(!isschid(buf))continue;
linkhead=search(buf,SEARCH_SCHID);
if(!linkhead)
{
printf("\n对不起,数据库中该学号不存在!\n");
continue;
}
break;
}
if(linkhead&&linkhead->next)
{
printf("\n\n对不起,数据库发现异常!\n\n");
return NULL;
}
printf("\n系统已为您找到了该学生!\n");
return linkhead;
}
//本函数用于添加学生
bool addstu_gui()
{
pmystu newstu=NEW(mystu);
memset(newstu,0,MYSTUSIZE);
printf("您将添加新的学生记录:\n");
printf("请输入姓名:");
char buf[20]={0};
INPUTBUF(buf);
strcpy(newstu->stu_name,buf);
while(1)
{
printf("请输入学号(12位数字):");
INPUTBUF(buf);
if(!isschid(buf))continue;
if(search(buf,SEARCH_SCHID))
{
printf("\n数据库中不能有相同的学号!\n");
continue;
}
break;
}
strcpy(newstu->stu_schid,buf);
do
{
printf("请输入性别:(0=男 1=女):");
INPUTBUF(buf);
if(strlen(buf)-1)continue;
}while(*buf-0x30&&*buf-0x31);
newstu->stu_sex=*buf-0x30;
printf("请输入专业班级:");
INPUTBUF(buf);strcpy(newstu->stu_major,buf);
addstu(newstu);printf("\n\n添加成功!按任意键返回主菜单.....\n\n");
getch();free(newstu);return TRUE;
}
//本函数用于编辑一个已经存在的学生
bool editstu_gui()
{
long seek=search_gui();
if(!seek)return FALSE;
printf("\n您需要编辑该记录还是删除该记录 ?\n");
char choice;char buf[20]={0};
do
{
printf("1.编辑 2.删除:");
INPUTBUF(buf);
if(strlen(buf)-1)continue;
choice=*buf;
}while(choice-0x31&&choice-0x32);
if(choice==0x32)
{
delstu(seek);
printf("\n该记录删除成功!\n\n");
return TRUE;
}
pmystu newstu=NEW(mystu);
memset(newstu,0,MYSTUSIZE);
if(!mystuinfo)mystuinfo=NEW(stuinfo);
memset(mystuinfo,0,STUINFOSIZE);
fcntl(seek,READ,mystuinfo,STUINFOSIZE);
printf("请输入姓名 :");
INPUTBUF(buf);
strcpy(newstu->stu_name,buf);
plink linkhead=NULL;
while(1)
{
printf("请输入学号(12位数字):");
INPUTBUF(buf);
if(!isschid(buf))continue;
linkhead=search(buf,SEARCH_SCHID);
if(linkhead&&linkhead->data-seek)
{
printf("数据库中不能有相同的学号!");
continue;
}
break;
}
strcpy(newstu->stu_schid,buf);
do
{
printf("请输入性别(0=男 1=女):");
INPUTBUF(buf);
if(strlen(buf)-1)continue;
}while(*buf-0x30&&*buf-0x31);
newstu->stu_sex=*buf-0x30;
printf("请输入专业班级:");
INPUTBUF(buf);
strcpy(newstu->stu_major,buf);
editstu(seek,newstu);
free(newstu);
return TRUE;
}
//本函数用于输入一个科目的信息,为了添加新科目和编辑已有科目之用
//type=ADDSUB 或 EDITSUB,backup
void inputsub_gui(int type,int backup)
{
psubinfo newsub=NEW(subinfo);
memset(newsub,0,SUBINFOSIZE);
newsub->sub_id=backup;
plink linkhead=NULL;int flag=0;
char buf[20]={0};
do
{
flag=0;
printf("\n\n请输入科目名称:");
INPUTBUF(buf);
linkhead=search(buf,SEARCH_SUB);
if(type==ADDSUB)
{
if(linkhead)
{printf("\n数据库中不能有同名的科目!\n");flag=1;}
}
else if(type==EDITSUB)
{
if(linkhead&&linkhead->data-backup)
{printf("\n数据库中不能有同名的科目!\n");flag=1;}
}
else return;
}while(flag);
strcpy(newsub->sub_name,buf);
do
{
printf("请输入科目开课的学期(1~8):");
scanf("%d",&newsub->sub_term);
}while(newsub->sub_term<1||newsub->sub_term>8);
do
{
printf("请输入科目所占的学分(1~6):");
scanf("%lf",&newsub->sub_rate);
}while(newsub->sub_rate<0.5||newsub->sub_rate>6);
newsub->flag=1;
if(type==ADDSUB)addsub(newsub);
else if(type==EDITSUB)editsub(newsub);
free(newsub);
}
bool editsub_gui(int edittype)
{
if(edittype==ADDSUB)
{
inputsub_gui(ADDSUB,0);
return TRUE;
}
if(!myfileinfo)
{
myfileinfo=NEW(fileinfo);
fcntl(0,READ,myfileinfo,FILEINFOSIZE);
}
int subcount=myfileinfo->subcount,i,j=0;
int subarray[MAXSUBCOUNT]={0},*psubarray=subarray;
psubinfo subtemp=myfileinfo->sub;
printf("\n\n数据库中有以下科目:\n\n");
for(i=0;i<subcount;i++,subtemp++)
{
if(!subtemp->flag){i--;continue;}
printf("%d.%s\t",i+1,subtemp->sub_name);j++;
*psubarray=subtemp->sub_id;psubarray++;
if(strlen(subtemp->sub_name)<=4)printf("\t");
if(strlen(subtemp->sub_name)==5&&i<10)printf("\t");
if(j>=5){printf("\n");j=0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -