⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 system_gui.c

📁 sql数据库的实现
💻 C
📖 第 1 页 / 共 2 页
字号:
	}
	subtemp=myfileinfo->sub;
	psubarray=subarray;
	printf("\n\n您需要编辑哪一科目?\n");
	int subid;
	do
	{
		printf("请输入科目的选项号 :");
		fflush(stdin);scanf("%d",&subid);
		fflush(stdin);
	}while(subid<1||subid>subcount);
	subid--;subid=psubarray[subid];
	if(subid<1||subid>MAXSUBCOUNT)return FALSE;
	if(!subtemp[subid-1].flag)return FALSE;
	printf("\n1.编辑科目	2.删除科目\n");
	char choice,buf[20];
	do
	{
		printf("请作出选择:");
		INPUTBUF(buf);
		if(strlen(buf)-1)continue;
		choice=*buf;
	}while(choice-0x31&&choice-0x32);
	if(choice==0x32)
	{
		delsub(subid);
		printf("\n科目删除成功!\n");
		return TRUE;
	}
	inputsub_gui(EDITSUB,subid);
	return TRUE;
}
 


bool editmark_gui()
{
	if(!myfileinfo)
	{
		myfileinfo=NEW(fileinfo);
		fcntl(0,READ,myfileinfo,FILEINFOSIZE);
	}
	int i,j=0;
	int subarray[MAXSUBCOUNT]={0};int *psubarray=subarray;
	psubinfo subtemp=myfileinfo->sub;
	printf("\n\n数据库中有以下科目:\n\n");
	int subcount=myfileinfo->subcount;
	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;}
	}
	subtemp=myfileinfo->sub;
	psubarray=subarray;
	printf("\n\n您想编辑哪一科目的成绩?\n");
	int subid;
	do
	{
		printf("请输入科目的选项号 :");
		fflush(stdin);scanf("%d",&subid);
		fflush(stdin);
	}while(subid<1||subid>subcount);
	printf("\n接下来,您将编辑某个学生的成绩:");
	subid--;subid=psubarray[subid];
	long seek=search_gui();
	if(!seek)return FALSE;
	if(!mystuinfo)mystuinfo=NEW(stuinfo);
	memset(mystuinfo,0,STUINFOSIZE);
	fcntl(seek,READ,mystuinfo,STUINFOSIZE);
	psubmark newmark=NEW(submark);
	memset(newmark,0,SUBMARKSIZE);
	newmark->sub_id=subid;
	double mark;
	if(!mystuinfo->stu_mark[subid-1].flag)
	{
		printf("该科分数为空,请添加分数:");
		printf("\n请输入该科的分数(0~100):");
		do{scanf("%lf",&mark);}while(mark<0||mark>100);
		newmark->flag=1;
		newmark->sub_mark=mark;
		editmark(newmark,seek);
	}
	else
	{
		printf("\n您将编辑该生的分数:");
		printf("\n1.添加分数  2.删除分数\n");
		char choice,buf[20];
		do
		{
			printf("请您作出选择:");
			INPUTBUF(buf);
			if(strlen(buf)-1)continue;
			choice=*buf;
		}while(choice-0x31&&choice-0x32);
		if(choice==0x31)
		{
			newmark->flag=1;
			do
			{
				printf("请输入新的分数(0~100):");
				fflush(stdin);scanf("%lf",&mark);
				fflush(stdin);
			}while(mark<0||mark>100);
			newmark->sub_mark=mark;
			editmark(newmark,seek);
		}
		else editmark(newmark,seek);
	}
	free(newmark);
	return TRUE;
}
 
//count表backup中元素的个数
bool showstu(plink linkhead,int type,int *backup,int count)
{
	if(!linkhead)return FALSE;
	if(!myfileinfo)
	{
		myfileinfo=NEW(fileinfo);
		fcntl(0,READ,myfileinfo,FILEINFOSIZE);
	}
	if(!mystuinfo)mystuinfo=NEW(stuinfo);
	pmystu stutemp=NULL;
	psubmark marktemp=NULL;
	psubinfo subtemp=NULL;
	int flag=0;int pause=1;char choice,buf[20];
	for(;linkhead&&pause;linkhead=linkhead->next)
	{
		memset(mystuinfo,0,STUINFOSIZE);
		fcntl(linkhead->data,READ,mystuinfo,STUINFOSIZE);
		stutemp=&mystuinfo->stu_privacy;
		if(type==SHOW_PRIV)
		{
			if(!flag)printf("\n\n学号\t\t\t姓名\t\t性别\t\t专业班级\n");
			printf("%s\t\t",stutemp->stu_schid);
			printf("%s\t",stutemp->stu_name);
			if(strlen(stutemp->stu_name)<8)printf("\t");
			if(stutemp->stu_sex)printf("女\t\t");
			else printf("男\t\t");
			printf("%s\n",stutemp->stu_major);
			flag++;pause++;
			if(!(pause%20))
			{
				do
				{
					printf("\n您还想继续查看吗?(1=yes,0=no)");
					INPUTBUF(buf);
					if(strlen(buf)-1)continue;
					choice=*buf;
				}while(choice-0x31&&choice-0x30);
				if(choice==0x31)system("cls");
				else return TRUE;
			}
		}
		marktemp=mystuinfo->stu_mark;
		subtemp=myfileinfo->sub;
		if(type==SHOW_PERMARK)
		{
			int k=1,j;
			printf("\n\n时间\t\t科目\t\t\t学分\t\t\t成绩\n\n\n");
			printf("***********************************");
			printf("*************************************\n");
			for(k=1;k<=8;k++)//8个学期
			{
				printf("\n\n%s\t",term[k-1]);
				for(j=0;j<MAXSUBCOUNT;j++)
				if(subtemp[j].sub_term==k&&subtemp[j].flag)
				{
					printf("\t%s\t\t",subtemp[j].sub_name);
					if(strlen(subtemp[j].sub_name)<8)printf("\t");
					printf("%3.1f\t\t\t",subtemp[j].sub_rate);
					if(!marktemp[j].flag)printf("空\n\n\t");
					else printf("%4.1f\n\n\t",marktemp[j].sub_mark);
				}
				printf("\n\n***********************************");
				printf("*************************************\n\n\n");
			}
			printf("加权成绩:%4.1f\n\n\n",mystuinfo->stu_avemark);
		}
		else if(type==SHOW_ALLMARK)
		{
			if(!backup)
			{
				printf("\n对不起,没有要显示成绩的科目!\n");
				return FALSE;
			}
			int i;
			if(!flag)
			{
				printf("\n\n学号\t\t\t\t姓名\t\t\t\t");
				for(i=0;i<count&&i<SHOWMAX&&*(backup+i);i++)
				{
					if(*(backup+i)==-1)				//数组中元素为-1表示显示加权成绩
					printf("加权\t\t");
					else if(*(backup+i)<1||*(backup+i)>MAXSUBCOUNT)
					{
						printf("\n对不起,数据库出错!\n");
						return FALSE;
					}
					printf("%s\t\t",subtemp[*(backup+i)-1].sub_name);
				}
			}
			flag++;
			printf("\n%s\t\t\t",stutemp->stu_schid);
			printf("%s\t\t\t",stutemp->stu_name);
			if(strlen(stutemp->stu_name)<8)
			printf("\t");
			for(i=0;i<count&&i<SHOWMAX&&*(backup+i);i++)
			{
				if(*(backup+i)==-1)
				printf("%4.1f\t\t\t",mystuinfo->stu_avemark);
				else
				printf("%4.1f\t\t\t",marktemp[*(backup+i)-1].sub_mark);
			}
			pause++;
			if(!(pause%20))
			{
				do
				{
					printf("\n您还想继续查看吗?(1=yes,0=no)");
					INPUTBUF(buf);
					if(strlen(buf)-1)continue;
					choice=*buf;
				}while(choice-0x31&&choice-0x30);
				if(choice==0x31)system("cls");
				else return TRUE;
			}
		}
	}
	return TRUE;
}


long search_gui()
{
	printf("\n\n系统将为您搜索学生记录:\n\n");
	printf("请输入该学生的姓名或学号:");
	char buf[20]={0};plink linkhead=NULL;
	INPUTBUF(buf);
	if(isschid(buf))
	{
		linkhead=search(buf,SEARCH_SCHID);
		if(linkhead&&linkhead->next)
		SETERR("\n对不起,数据库中无该生记录!\n");
	}
	else linkhead=search(buf,SEARCH_NAME);
	if(!linkhead)SETERR("\n对不起,数据库中无该生记录!\n");
		showstu(linkhead,SHOW_PRIV,0,0);
	if(linkhead->next)
	{
		linkhead=findstu_gui(buf);
		if(!linkhead)SETERR("对不起,程序出现异常!");
		if(linkhead&&linkhead->next)
		SETERR("对不起,程序出现异常!");
		showstu(linkhead,SHOW_PRIV,0,0);
	}
	long seek=linkhead->data;
	if(!mystuinfo)mystuinfo=NEW(stuinfo);
	fcntl(seek,READ,mystuinfo,STUINFOSIZE);
	if(!mystuinfo->stu_markcount)return seek;
	printf("\n您想查看这学生的成绩吗?\n");
	char choice;
	do
	{
		printf("请作出选择 (y/n):");
		INPUTBUF(buf);
		if(strlen(buf)-1)continue;
		choice=*buf;
	}while(choice-'y'&&choice-'n');
	if(choice=='y')showstu(linkhead,SHOW_PERMARK,0,0);
	return seek;
}
 

bool showmark_gui()
{
	if(!myfileinfo)
	{
		myfileinfo=NEW(fileinfo);
		fcntl(0,READ,myfileinfo,FILEINFOSIZE);
	}
	int i,j=0,subcount=myfileinfo->subcount;
	psubinfo subtemp=myfileinfo->sub;
	int subarray[MAXSUBCOUNT]={0};int *psubarray=subarray;
	printf("数据库中有以下科目:\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;}
	}
	psubarray=subarray;
	subtemp=myfileinfo->sub;
	int subid;
	printf("\n\n分数将按降序或升序排列显示:\n\n");
	printf("您需要查看哪门科目的分数(0表示查看加权分)?");
	do
	{
		printf("\n\n请输入该科目的选项号 :");
		fflush(stdin);scanf("%d",&subid);
		if(!subid)break;fflush(stdin);
	}while((subid<1||subid>subcount)||!psubarray[subid-1]);
	if(subid)subid=psubarray[subid-1];
	else subid=-1;
	printf("\n您想升序排列还是降序排列(1=降序 2=升序)\n\n");
	char choice,buf[20];
	do
	{
		printf("请作出选择:");
		INPUTBUF(buf);
		if(strlen(buf)-1)continue;
		choice=*buf;
	}while(choice-0x31&&choice-0x32);
	plink linkhead=marklink(subid);					
	if(!linkhead)
	{
		printf("\n\n对不起,该科目所有学生都暂时没有成绩!\n\n");
		return TRUE;
	}
	if(choice==0x31)linkhead=sortlink(linkhead,SORT_DECLINE);
	else linkhead=sortlink(linkhead,SORT_INCLINE);
	system("cls");
	showstu(linkhead,SHOW_ALLMARK,&subid,1);
	freelink(linkhead);
	return TRUE;
}


void changekey_gui()
{
	if(!myfileinfo)
	{
		myfileinfo=NEW(fileinfo);
		fcntl(0,READ,myfileinfo,FILEINFOSIZE);
	}
	char buf[20]={0},choice;
	do
	{
		printf("\n请输入旧的密码:");
		INPUTBUF(buf);
		if(strcmp(buf,myfileinfo->key))
		{
			printf("\n密码输入错误!(1=重新输入 0=退出)\n");
			do
			{	
				printf("\n请作出选择:");
				INPUTBUF(buf);
				if(strlen(buf)-1)continue;
				choice=*buf;
			}while(choice-0x30&&choice-0x31);
			if(choice==0x30)return;
		}
		else break;
	}while(choice);
	printf("\n请输入新密码:");
	INPUTBUF(buf);
	strcpy(myfileinfo->key,buf);
	fcntl(0,WRITE,myfileinfo,FILEINFOSIZE);
	printf("\n\n密码修改成功!\n\n");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -