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

📄 main.cpp

📁 连接到数据库(sql和access)
💻 CPP
📖 第 1 页 / 共 5 页
字号:
						 receive.logonhead=(LOGON  *)malloc(sizeof(LOGON ));
						 break;
					 }
				 case 13:
					 {	
						 receive.activityhead=(ACTIVITY *)malloc(sizeof(ACTIVITY));
						 break;
					 }
				 case 14:
					 {	
						 receive.chamberhead=(CHAMBER *)malloc(sizeof(CHAMBER));
						 break;
					 }
				 default:break;
				 }				 
				 
				 for(i=1;i<=m;i++)
				 {
					 j[1]=n;
					 j[2]=1;//是否提示输入的记录已存在
					 tmp=Input(j,i,all);
					 //插入学生表
					 if(n==1)
					 {
						 switch(i)
						 {
						 case 1:strcpy(receive.studenthead->SNO,tmp.str1);break;
						 case 2:strcpy(receive.studenthead->SN,tmp.str1);break;
						 case 3:strcpy(receive.studenthead->S_SEX,tmp.str1);break;
						 case 4:strcpy(receive.studenthead->S_BIRTHDAY,tmp.str1);break;
						 case 5:strcpy(receive.studenthead->S_DATE,tmp.str1);break;
						 case 6:strcpy(receive.studenthead->S_SCHOOL,tmp.str1);break;
						 case 7:receive.studenthead->S_GRADE=atoi(tmp.str1);break;
						 case 8:strcpy(receive.studenthead->S_PHONE,tmp.str1);break;
						 case 9:strcpy(receive.studenthead->S_ADDRESS,tmp.str1);break;
						 case 10:strcpy(receive.studenthead->SP_NO,tmp.str1);break;
						 case 11:strcpy(receive.studenthead->CNO,tmp.str1);break;
						 case 12:strcpy(receive.studenthead->CH_NO,tmp.str1);break;
						 default:break;
						 }
					 }
					 //插入教师表
					 if(n==2)
					 {
						 switch(i)
						 {
						 case 1:strcpy(receive.teacherhead->TNO,tmp.str1);break;
						 case 2:strcpy(receive.teacherhead->TN,tmp.str1);break;
						 case 3:strcpy(receive.teacherhead->T_SEX,tmp.str1);break;
						 case 4:strcpy(receive.teacherhead->T_PROF,tmp.str1);break;
						 case 5:strcpy(receive.teacherhead->T_BIRTHDAY,tmp.str1);break;
						 case 6:strcpy(receive.teacherhead->T_DATE,tmp.str1);break;
						 case 7:receive.teacherhead->T_SALARY=atoi(tmp.str1);break;
						 case 8:strcpy(receive.teacherhead->DNO,tmp.str1);break;
						 default:break;
						 }
					 }
					 //插入课程表
					 if(n==3)
					 {
						 switch(i)
						 {
						 case 1:strcpy(receive.coursehead->CO_NO,tmp.str1);break;
						 case 2:strcpy(receive.coursehead->CO_N,tmp.str1);break;
						 case 3:receive.coursehead->CO_T_TIME=atoi(tmp.str1);break;
						 case 4:receive.coursehead->CO_E_TIME=atoi(tmp.str1);break;
						 case 5:receive.coursehead->CO_S=atoi(tmp.str1);break;
						 case 6:strcpy(receive.coursehead->CO_BOOK,tmp.str1);break;
						 case 7:strcpy(receive.coursehead->DNO,tmp.str1);break;
						 default:break;
						 }
					 }
					 //插入专业表
					 if(n==4)
					 {
						 switch(i)
						 {
						 case 1:strcpy(receive.specialityhead->SP_NO,tmp.str1);break;
						 case 2:strcpy(receive.specialityhead->SP_N,tmp.str1);break;
						 case 3:strcpy(receive.specialityhead->SP_DATE,tmp.str1);break;
						 case 4:receive.specialityhead->SP_NUM=atoi(tmp.str1);break;
						 case 5:strcpy(receive.specialityhead->DNO,tmp.str1);break;
						 default:break;
						 }
					 }
					 //插入院系表
					 if(n==5)
					 {
						 switch(i)
						 {
						 case 1:strcpy(receive.departmenthead->DNO,tmp.str1);break;
						 case 2:strcpy(receive.departmenthead->DN,tmp.str1);break;
						 case 3:strcpy(receive.departmenthead->D_DATE,tmp.str1);break;
						 case 4:strcpy(receive.departmenthead->D_HEAD,tmp.str1);break;
						 case 5:strcpy(receive.departmenthead->D_ADDRESS,tmp.str1);break;
						 case 6:strcpy(receive.departmenthead->D_PHONE,tmp.str1);break;
						 default:break;
						 }
					 }
					 //插入班级表
					 if(n==6)
					 {
						 switch(i)
						 {
						 case 1:strcpy(receive.classhead->CNO,tmp.str1);break;
						 case 2:strcpy(receive.classhead->CN,tmp.str1);break;
						 case 3:strcpy(receive.classhead->C_DATE,tmp.str1);break;
						 case 4:strcpy(receive.classhead->C_CLASSROOM,tmp.str1);break;
						 case 5:receive.classhead->C_NUM=atoi(tmp.str1);break;
						 case 6:strcpy(receive.classhead->TNO,tmp.str1);break;
						 case 7:strcpy(receive.classhead->DNO,tmp.str1);break;
						 default:break;
						 }
					 }
					 //插入教学计划表
					 if(n==7)
					 {
						 switch(i)
						 {
						 case 1:
							 {
								 strcpy(receive.projecthead->SP_NO,tmp.str1);
								 strcpy(receive.projecthead->CO_NO,tmp.str2);
								 break;
							 }
						 case 3:strcpy(receive.projecthead->CLASS,tmp.str1);break;
						 default:break;
						 }
						 if(i==2)
						 {
							 strcat(between,ch2);
							 strcat(between,ch1);
							 strcat(between,receive.projecthead->CO_NO);
							 strcat(between,ch1);
							 continue;
						 }
					 }
					 //插入入校报到表
					 if(n==8)
					 {
						 switch(i)
						 {
						 case 1:strcpy(receive.registerhead->RNO,tmp.str1);break;
						 case 2:strcpy(receive.registerhead->DNO,tmp.str1);break;
						 case 3:receive.registerhead->R_COST=atoi(tmp.str1);break;
						 default:break;
						 }
					 }
					 //插入选修表
					 if(n==9)
					 {
						 switch(i)
						 {
						 case 1:
							 {
								 strcpy(receive.schead->SNO,tmp.str1);
								 strcpy(receive.schead->CO_NO,tmp.str2);
								 break;
							 }
						 case 3:strcpy(receive.schead->SC_CLASS,tmp.str1);break;
						 case 4:receive.schead->SC_GRADE=atoi(tmp.str1);break;
						 case 5:strcpy(receive.schead->TNO,tmp.str1);break;
						 case 6:strcpy(receive.schead->SC_DATE,tmp.str1);break;
						 default:break;
						 }
						 if(i==2)
						 {
							 strcat(between,ch2);
							 strcat(between,ch1);
							 strcat(between,receive.schead->CO_NO);
							 strcat(between,ch1);
							 continue;
						 }
					 }
					 //插入讲授表
					 if(n==10)
					 {
						 switch(i)
						 {
						 case 1:
							 {
								 strcpy(receive.tchead->TNO,tmp.str1);
								 strcpy(receive.tchead->CO_NO,tmp.str2);
								 break;
							 }
						 case 3:strcpy(receive.tchead->TC_T_DATETIME,tmp.str1);break;
						 case 4:strcpy(receive.tchead->TC_T_ADDRESS,tmp.str1);break;
						 case 5:strcpy(receive.tchead->TC_E_DATETIME,tmp.str1);break;
						 case 6:strcpy(receive.tchead->TC_E_ADDRESS,tmp.str1);break;
						 default:break;
						 }
						 if(i==2)
						 {
							 strcat(between,ch2);
							 strcat(between,ch1);
							 strcat(between,receive.tchead->CO_NO);
							 strcat(between,ch1);
							 continue;
						 }
					 }
					 
					 //插入参加活动表
					 if(n==11)
					 {
						 switch(i)
						 {
						 case 1:
							 {
								 strcpy(receive.joinactivityhead->ANO,tmp.str1);
								 strcpy(receive.joinactivityhead->SNO,tmp.str2);
								 break;
							 }
						 case 2:receive.joinactivityhead->J_GRADE=atoi(tmp.str1);break;
						 case 3:strcpy(receive.joinactivityhead->J_OTHER,tmp.str1);break;
						 default:break;
						 }
						 if(i==4)
						 {
							 strcat(between,ch2);
							 strcat(between,ch1);
							 strcat(between,receive.joinactivityhead->SNO);
							 strcat(between,ch1);
							 continue;
						 }
					 }
					 
					 //插入登记表
					 if(n==12)
					 {
						 switch(i)
						 {
						 case 1:
							 {
								 strcpy(receive.logonhead->RNO,tmp.str1);
								 strcpy(receive.logonhead->SNO,tmp.str2);
								 break;
							 }
						 case 3:strcpy(receive.logonhead->L_DATE,tmp.str1);break;
						 default:break;
						 }
						 if(i==2)
						 {
							 strcat(between,ch2);
							 strcat(between,ch1);
							 strcat(between,receive.logonhead->SNO);
							 strcat(between,ch1);
							 continue;
						 }
					 }
					 //插入学校活动表
					 if(n==13)
					 {
						 switch(i)
						 {
						 case 1:strcpy(receive.activityhead->ANO,tmp.str1);break;
						 case 2:strcpy(receive.activityhead->AN,tmp.str1);break;
						 case 3:strcpy(receive.activityhead->A_DATE,tmp.str1);break;
						 default:break;
						 }
					 }
					 //插入寝室表
					 if(n==14)
					 {
						 switch(i)
						 {
						 case 1:strcpy(receive.chamberhead->CH_NO,tmp.str1);break;
						 case 2:strcpy(receive.chamberhead->CH_ADDRESS,tmp.str1);break;
						 case 3:receive.chamberhead->CH_NUM=atoi(tmp.str1);break;
						 default:break;
						 }
					 }
					 if(i!=1)
					 {
						 strcat(between,ch2);//第一个插入的属性值前不加","  Values('','')
					 }
                     strcat(between,ch1);
					 strcat(between,tmp.str1);
					 strcat(between,ch1);

				 }
				 printf("\n稍等……\n");
				 //插入链表头
				 switch(n)
				 {
				 case 1:
					 {	
						 receive.studenthead->next=all->studenthead->next;
						 all->studenthead->next=receive.studenthead;
						 break;
					 }
				 case 2:
					 {	
						 receive.teacherhead->next=all->teacherhead->next;
						 all->teacherhead->next=receive.teacherhead;
						 break;
					 }
				 case 3:
					 {	
						 receive.coursehead->next=all->coursehead->next;
						 all->coursehead->next=receive.coursehead;
						 break;
					 }
				 case 4:
					 {
						 receive.specialityhead->next=all->specialityhead->next;
						 all->specialityhead->next=receive.specialityhead;						
						 break;
					 }
				 case 5:
					 {
						 receive.departmenthead->next=all->departmenthead->next;
						 all->departmenthead->next=receive.departmenthead;					
						 break;
					 }
				 case 6:
					 {
						 receive.classhead->next=all->classhead->next;
						 all->classhead->next=receive.classhead;						 
						 break;
					 }
				 case 7:
					 {	
						 receive.projecthead->next=all->projecthead->next;
						 all->projecthead->next=receive.projecthead;
						 break;
					 }
				 case 8:
					 {	
						 receive.registerhead->next=all->registerhead->next;
						 all->registerhead->next=receive.registerhead;
						 break;
					 }
				 case 9:
					 {	
						 receive.schead->next=all->schead->next;
						 all->schead->next=receive.schead;
						 break;
					 }
				 case 10:
					 {
						 receive.tchead->next=all->tchead->next;
						 all->tchead->next=receive.tchead;						 
						 break;
					 }
				 case 11:
					 {	
						 receive.joinactivityhead->next=all->joinactivityhead->next;
						 all->joinactivityhead->next=receive.joinactivityhead;
						 break;
					 }
				 case 12:
					 {	
						 receive.logonhead->next=all->logonhead->next;
						 all->logonhead->next=receive.logonhead;	
						 break;
					 }
				 case 13:
					 {	
						 receive.activityhead->next=all->activityhead->next;
						 all->activityhead->next=receive.activityhead;
						 break;
					 }
				 case 14:
					 {	
						 receive.chamberhead->next=all->chamberhead->next;
						 all->chamberhead->next=receive.chamberhead;
						 break;
					 }
				 default:break;
				 }
				 //插入数据库
	        	 sprintf(cmd,"INSERT INTO %s VALUES(%s)",row_num[n][0],between);
				 ExecuteSQL(cmd);
				 printf("成功插入1条记录!\n\n");
				 sprintf(between,"\0");
				 system("pause");
				 break;
				}
		 case 2:
			 {
				 i=1;
				 j[1]=n;
				 j[2]=2;//是否提示输入的记录不存在
				 //记录单属性主键
				 tmp=Input(j,1,all);
				 strcpy(temp[0],tmp.str1);
				 //记录双属性主键
				 if(n==7||n==9||n==10||n==12)
				 {
					 sprintf(between," %s=%s%s%s AND ",row_num[n][1],ch1,tmp.str1,ch1);
					 sprintf(temp[1]," %s=%s%s%s",row_num[n][2],ch1,tmp.str2,ch1);
					 strcat(between,temp[1]);
					 strcpy(temp[0],tmp.str1);
					 strcpy(temp[1],tmp.str2);
				 }
				 if(n==11)
				 {
					 sprintf(between," %s=%s%s%s AND ",row_num[n][1],ch1,tmp.str1,ch1);
					 sprintf(temp[1]," %s=%s%s%s",row_num[n][4],ch1,tmp.str2,ch1);
					 strcat(between,temp[1]);
					 strcpy(temp[0],tmp.str1);
					 strcpy(temp[1],tmp.str2);
				 }
				 //各表的删除
				 switch(n)
				 {
				 case 1:
					 {
						 
							 Find[1]=9;
							 Find[2]=1;
							 if(find(Find,temp[0],temp[0],all).schead!=NULL)
							 {
								 printf("\n该%s被%s表引用,不能删除,请重新输入!\n\n",row_txt[n][1],b_txt[Find[1]]);
								 flag=1;
							 }
							 Find[1]=11;
							 Find[2]=4;
							 if(find(Find,temp[0],temp[0],all).joinactivityhead!=NULL)
							 {
								 printf("\n该%s被%s表引用,不能删除,请重新输入!\n\n",row_txt[n][1],b_txt[Find[1]]);
								 flag=1;
							 }
							 Find[1]=12;
							 Find[2]=2;
							 if(find(Find,temp[0],temp[0],all).logonhead!=NULL)
							 {
								 printf("\n该%s被%s表引用,不能删除,请重新输入!\n\n",row_txt[n][1],b_txt[Find[1]]);
								 flag=1;
							 }
						 Find[1]=n;
						 delete_sys(n,find(Find,temp[0],temp[0],all),all);
						 break;
					 }
				 case 2:
					 {
							 Find[1]=6;
							 Find[2]=6;
							 if(find(Find,temp[0],temp[0],all).classhead!=NULL)
							 {
								 printf("\n该%s被%s表引用,不能删除,请重新输入!\n\n",row_txt[n][1],b_txt[Find[1]]);
								 flag=1;
							 }
							 Find[1]=9;
							 Find[2]=5;
							 if(find(Find,temp[0],temp[0],all).schead!=NULL)
							 {
								 printf("\n该%s被%s表引用,不能删除,请重新输入!\n\n",row_txt[n][1],b_txt[Find[1]]);
								 flag=1;
							 }
							 Find[1]=10;
							 Find[2]=1;
							 if(find(Find,temp[0],temp[0],all).tchead!=NULL)
							 {
								 printf("\n该%s被%s表引用,不能删除,请重新输入!\n\n",row_txt[n][1],b_txt[Find[1]]);
								 flag=1;
							 }
						 Find[1]=n;
						 delete_sys(n,find(Find,temp[0],temp[0],all),all);
						 break;
					 }
				 case 3:
					 {	
							 Find[1]=7;
							 Find[2]=2;
							 if(find(Find,temp[0],temp[0],all).projecthead!=NULL)
							 {
								 printf("\n该%s被%s表引用,不能删除,请重新输入!\n\n",row_txt[n][1],b_txt[Find[1]]);
								 flag=1;
							 }
							 Find[1]=9;
							 Find[2]=2;
							 if(find(Find,temp[0],temp[0],all).schead!=NULL)
							 {
								 printf("\n该%s被%s表引用,不能删除,请重新输入!\n\n",row_txt[n][1],b_txt[Find[1]]);
								 flag=1;
							 }
							 Find[1]=10;
							 Find[2]=2;
							 if(find(Find,temp[0],temp[0],all).tchead!=NULL)
							 {
								 printf("\n该%s被%s表引用,不能删除,请重新输入!\n\n",row_txt[n][1],b_txt[Find[1]]);
								 flag=1;
							 }
						 Find[1]=n;
						 delete_sys(n,find(Find,temp[0],temp[0],all),all);
						 break;
					 }
				 case 4:
					 {

⌨️ 快捷键说明

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