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

📄 main.cpp

📁 连接到数据库(sql和access)
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					p->SC_GRADE=atof((char *)_bstr_t(var));
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->TNO,"%s",(char *)_bstr_t(var));
				}
				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->SC_DATE,"%s",(char *)_bstr_t(var));
				}
				q->next=p;
				q=p;
				pRs->MoveNext();
			}
			break;
		}
	//从讲授表中读取数据
	case 10:
		{
			TC *p,*q;
			q=all->tchead;			
			while(!pRs->EndOfFile)
			{
				i=1;
				p=(TC *)malloc(sizeof(TC));
				p->next=NULL;

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->TNO,"%s",(char *)_bstr_t(var));
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->CO_NO,"%s",(char *)_bstr_t(var));
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->TC_T_DATETIME,"%s",(char *)_bstr_t(var));
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->TC_T_ADDRESS,"%s",(char *)_bstr_t(var));
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->TC_E_DATETIME,"%s",(char *)_bstr_t(var));
				}
				else
				{
					sprintf(p->TC_E_DATETIME,"");
				}
				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->TC_E_ADDRESS,"%s",(char *)_bstr_t(var));
				}
				else
				{
					sprintf(p->TC_E_ADDRESS,"");
				}
				q->next=p;
				q=p;
				pRs->MoveNext();
			}
			break;
		}
	//从参加活动表中读取数据
	case 11:
		{
			JOINACTIVITY *p,*q;
			q=all->joinactivityhead;			
			while(!pRs->EndOfFile)
			{
				i=1;
				p=(JOINACTIVITY *)malloc(sizeof(JOINACTIVITY));
				p->next=NULL;

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->ANO,"%s",(char *)_bstr_t(var));
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					p->J_GRADE=atof((char *)_bstr_t(var));
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->J_OTHER,"%s",(char *)_bstr_t(var));
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->SNO,"%s",(char *)_bstr_t(var));
				}
				q->next=p;
				q=p;
				pRs->MoveNext();
			}
			break;
		}
	//从登记表中读取数据
	case 12:
		{
			LOGON *p,*q;
			q=all->logonhead;			
			while(!pRs->EndOfFile)
			{
				i=1;
				p=(LOGON *)malloc(sizeof(LOGON));
				p->next=NULL;

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->RNO,"%s",(char *)_bstr_t(var));
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->SNO,"%s",(char *)_bstr_t(var));
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->L_DATE,"%s",(char *)_bstr_t(var));
				}
				q->next=p;
				q=p;
				pRs->MoveNext();
			}
			break;
		}
	//从学校活动表中读取数据
	case 13:
		{
			ACTIVITY *p,*q;
			q=all->activityhead;			
			while(!pRs->EndOfFile)
			{
				i=1;
				p=(ACTIVITY *)malloc(sizeof(ACTIVITY));
				p->next=NULL;

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->ANO,"%s",(char *)_bstr_t(var));
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->AN,"%s",(char *)_bstr_t(var));
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->A_DATE,"%s",(char *)_bstr_t(var));
				}
				q->next=p;
				q=p;
				pRs->MoveNext();
			}
			break;
		}
	//从寝室表中读取数据
	case 14:
		{
			CHAMBER *p,*q;
			q=all->chamberhead;			
			while(!pRs->EndOfFile)
			{

				i=1;
				p=(CHAMBER *)malloc(sizeof(CHAMBER));
				p->next=NULL;

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->CH_NO,"%s",(char *)_bstr_t(var));
				}

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					sprintf(p->CH_ADDRESS,"%s",(char *)_bstr_t(var));
				}
				

				var=pRs->GetCollect(row_num[choice][i]);
				i++;
				if(var.vt!=VT_NULL)
				{
					p->CH_NUM=atoi((char *)_bstr_t(var));
				}
				q->next=p;
				q=p;
				pRs->MoveNext();
			}
			break;
		}

	default:break;
	}
    
	pRs->Close();
	pRs.Release();
	pConn->Close();
	pConn.Release();
	}
	catch (_com_error)
	{
		if(choice==14)
		{
			printf("\n\n由于数据库不存在或格式错误,");
			printf("\n\n导致连接到数据库失败!程序即将关闭!\n\n");
			system("pause");
			exit(1);
		}
	}


}


/*-----------------------------------------------------------------*
 *函数:  ExecuteSQL()                                              *
 *参数:  字符数组                                                  *
 *作用:  执行相关SQL语句命令                                       *
 *返回: 无                                                        *
 *-----------------------------------------------------------------*/
void ExecuteSQL(char cmd[200])
{
	
	_ConnectionPtr pConn("ADODB.Connection");
	pConn->ConnectionTimeout=5;
	//建立.udl文件后打开可得到
	try
	{ 
		pConn->Open(db[0],"","",adConnectUnspecified);
		_CommandPtr pCmd("ADODB.Command");
		pCmd->ActiveConnection=pConn;
		pCmd->CommandText=cmd;
		pCmd->Execute(NULL,NULL,adCmdText);
		pConn->Close();
		pConn.Release();
	}
	catch (_com_error)
	{
		printf("\n\n由于数据库不存在或格式错误,");
		printf("\n\n导致连接到数据库失败!程序即将关闭!\n\n");
		system("pause");
		exit(1);
	}
}


/*-----------------------------------------------------------------*
 *函数:  Menu3()                                                   *
 *参数:  表结构指针                                                *
 *作用:  显示数据查询菜单                                          *
 *返回: 无                                                        *
 *-----------------------------------------------------------------*/
void Menu3(sys *all)
{
	int i,_exit=0,quit=0,choice[3],Find[3],column[13]={0},table;//column用1,0判断相应的列是否显示
	sys tmp;
	 do
	 {
		 system("cls");
		 _exit=0;
		 printf("c.数据查询");
		 printf("\n\n");
		 for(i=0;i<15;i++)
			 printf("\t%d.%s\n",i,c_txt[i]);
		 printf("\n\n请选择(0-14):");
		 choice[0]=Force();
		 while(choice[0]<0||choice[0]>14)
		 {
			 printf("\n\n输入错误,请重输:");
			 choice[0]=Force();
		 }
		 table=choice[0];
		 switch(choice[0])
		 {
		 case 0:
			 {
				 quit=1;
				 break;
			 }
		 case 1:
			 {
				 sys f_more[100];
				 int num=0,way;//num记录记录的个数
				 char ch[50];
				 Find[1]=table;
				 printf("\n请选择查询方式:1.姓名 2.学号\n\n");
				 way=Force();
				 if(way==1)
				 {
					 strcpy(ch,Input(Find,2,all).str1);
					 findmore(Find,ch,all,f_more);
				 }
				 else if(way==2)
				 {
					 strcpy(ch,Input(Find,1,all).str1);
					 f_more[0]=find(Find,ch,ch,all);
					 f_more[1].studenthead=NULL;
				 }
				 else
				 {
					 break;
				 }
				 
				 if(f_more[0].studenthead==NULL)
				 {
					 printf("\n未找到%s!\n\n",ch);
					 system("pause");
					 break;
				 }
				 do
				 {
					 system("cls");
					 printf("1.学生综合情况\n");
					 printf("2.校运动会\n");
					 printf("0.返回\n\n");
					 printf("\n\n请选择(0-2):");
					 choice[2]=Force();
					 
					 while(choice[2]<0||choice[2]>2)
					 {
						 printf("\n\n输入错误,请重输:");
						 choice[2]=Force();
					 }

					 if(choice[2]==0)
					 {
						 _exit=1;
						 break;
					 }

					 printf("\n\n");
					 num=0;
					 while(f_more[num].studenthead!=NULL)
					 {
						 printf("%d.%s\t\t",num+1,f_more[num].studenthead->SN);
						 num++;
					 }
					 printf("\n\n请选择要显示的学生(1-%d):",num);
					 choice[1]=Force();
					 while(choice[1]<1||choice[1]>num)
					 {
						 printf("\n\n输入错误,请重输:");
						 choice[1]=Force();
					 }
					 printf("\n\n\t\t");

					 switch(choice[2])
					 {
					 case 0:_exit=1;break;
					 case 1:
						 {
							 strcpy(ch,f_more[choice[1]-1].studenthead->SNO);
							 tmp=f_more[choice[1]-1];
							 //姓名
							 system("cls");
							 printf("%s:",row_txt[table][2]);
							 column[2]=1;
							 if(tmp.studenthead!=NULL)
							 {
								 display(table,column,tmp);
							 }
							 column[2]=0;
							 printf("\n\n\n基本情况:\n\n\t\t");
							 for(i=1;i<=9;i++)
							 {
								 if(i==2) continue;
								 printf("%10s:",row_txt[table][i]);
								 column[i]=1;
								 if(tmp.studenthead!=NULL)
								 {
									 display(table,column,tmp);
								 }
								 column[i]=0;
								 printf("\n\t\t");
							 }
							 Find[1]=table+5;
							 tmp=find(Find,tmp.studenthead->CNO,tmp.studenthead->CNO,all);
							 printf("\n\n\n所在班级情况:\n\n\t\t");
							 for(i=1;i<=5;i++)
							 {
								 printf("%10s:",row_txt[table+5][i]);
								 column[i]=1;
								 if(tmp.classhead!=NULL)
								 {
									 display(table+5,column,tmp);
								 }
								 column[i]=0;
								 printf("\n\t\t");
							 }
							 Find[1]=table;
							 tmp=find(Find,ch,ch,all);
							 Find[1]=0;
							 system("pause");
							 //姓名
							 system("cls");
							 printf("%s:",row_txt[table][2]);
							 column[2]=1;
							 if(tmp.studenthead!=NULL)
							 {
								 display(table,column,tmp);
							 }
							 column[2]=0;
							 Find[1]=table+3;
							 tmp=find(Find,tmp.studenthead->SP_NO,tmp.studenthead->SP_NO,all);
							 printf("\n\n\n所在专业情况:\n\n\t\t");
							 for(i=1;i<=4;i++)
							 {
								 printf("%10s:",row_txt[table+3][i]);
								 column[i]=1;
								 if(tmp.specialityhead!=NULL)
								 {
									 display(table+3,column,tmp);
								 }
								 column[i]=0;
								 printf("\n\t\t");
							 }
							 Find[1]=table+4;
							 tmp=find(Find,tmp.specialityhead->DNO,tmp.specialityhead->DNO,all);
							 printf("  所属系部:");
							 column[2]=1;
							 if(tmp.departmenthead!=NULL)
							 {
								 display(table+4,column,tmp);
							 }
							 column[2]=0;
							 Find[1]=table;
							 tmp=find(Find,ch,ch,all);
							 Find[1]=table+13;
							 tmp=find(Fin

⌨️ 快捷键说明

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