www.pudn.com > studentScore(v6.0).rar > Exam.cpp, change:2003-04-10,size:10369b


// Exam.cpp : 实现文件 
// 
 
#include "stdafx.h" 
#include "StudentScore.h" 
#include "Exam.h" 
 
 
// CExam 
 
CExam::CExam() 
{ 
	this->m_TblName="Exam";  
} 
 
CExam::~CExam() 
{ 
	if(this->m_TermList.GetCount()>0) 
   { 
      this->ClearTermList(); 
   } 
} 
 
// CExam 成员函数 
 
CStringList& CExam::GetTerms() 
{ 
   this->m_Storage.OpenSql("Term","学期编号"); 
   int count=this->m_Storage.GetRecordCount(); 
   if(this->m_TermList.GetCount()>0) 
   { 
      this->ClearTermList(); 
   } 
   if(count>0) 
   { 
      this->m_Storage.MoveFirst(); 
	  CString value; 
	  while(!this->m_Storage.IsEof()) 
	  { 
         this->m_Storage.GetFieldValue(0,value); 
	     m_TermList.AddTail(value); 
		 this->m_Storage.MoveNext(); 
	  } 
   } 
  return this->m_TermList; 
} 
 
void CExam::ClearTermList(void) 
{ 
	/* 
	POSITION p; 
	p=this->m_TermList.GetHeadPosition(); 
	while(p) 
	{ 
	   delete this->m_TermList.GetNext(p); 
	} 
	*/ 
	this->m_TermList.RemoveAll(); 
} 
 
CStringList* CExam::GetNos() 
{ 
   this->m_Storage.OpenSql("Exam","考试编号"); 
   int count=this->m_Storage.GetRecordCount(); 
   if(this->m_NoList.GetCount()>0) 
   { 
      this->ClearNoList(); 
   } 
   if(count>0) 
   { 
      this->m_Storage.MoveFirst(); 
	  CString value; 
	  while(!this->m_Storage.IsEof()) 
	  { 
         this->m_Storage.GetFieldValue(0,value); 
	     m_NoList.AddTail(value); 
		 this->m_Storage.MoveNext(); 
	  } 
   } 
  return &this->m_NoList; 
 
} 
 
void CExam::ClearNoList(void) 
{ 
	/* 
	POSITION p; 
	p=this->m_NoList.GetHeadPosition(); 
	while(p) 
	{ 
	   delete this->m_NoList.GetNext(p); 
	} 
	*/ 
	this->m_NoList.RemoveAll(); 
} 
void CExam::GetExamByNo(CString No)//获取考试信息 
{ 
   CString ConStr; 
   ConStr="where 考试编号='"+No+"'"; 
   this->m_Storage.OpenSql(this->m_TblName,"*",ConStr); 
   if(this->m_Storage.GetRecordCount()>0) 
   { 
      this->m_No=No; 
	  this->m_Storage.GetFieldValue("考试日期",(COleDateTime*) &this->m_Date); 
	  this->m_Storage.GetFieldValue("学期编号",this->m_TermNo); 
   } 
   else 
   { 
      this->m_No=""; 
	  this->m_TermNo="";  
   } 
} 
bool CExam::IsNoExisted(CString No) 
{ 
   CString ConStr; 
   ConStr="where 考试编号='"+No+"'"; 
   this->m_Storage.OpenSql(this->m_TblName,"*",ConStr); 
   if(this->m_Storage.GetRecordCount()>0) 
   { 
      return true; 
   } 
   else 
   { 
      return false; 
   } 
} 
void CExam::AddExam() 
{ 
   CString FldList,ValueList; 
   FldList="考试编号,考试日期,学期编号"; 
   ValueList="'"+this->m_No+"','"+this->m_Date.Format()+"','"+this->m_TermNo+"'"; 
   this->m_Storage.ExecInsertSql(this->m_TblName,FldList,ValueList);  
} 
void CExam::DeleteExamByNo(CString No) 
{ 
	CString ConStr; 
    ConStr="where 考试编号='"+No+"'"; 
    this->m_Storage.ExceDeleteSql(this->m_TblName,ConStr);  
} 
// CExamClass 
 
CExamClass::CExamClass() 
{ 
	this->m_TblName="ExamClass";  
} 
 
CExamClass::~CExamClass() 
{ 
} 
 
// CExamClass 成员函数 
void CExamClass::GetExamClassByExamNo(CString ExamNo) 
{ 
   CString SqlStr; 
   SqlStr="select a.编号,a.班级编号,b.班级名称,a.班级平均成绩,a.班级总成绩 "; 
   SqlStr+=" from ExamClass a,Class b where a.班级编号=b.班级编号 and "; 
   SqlStr+=" a.考试编号='"+ExamNo+"'"; 
   this->m_Storage.Open(SqlStr,CADODataset::openQuery); 
} 
void CExamClass::GetGrades() 
{ 
	if(this->m_GradeList.GetCount()>0) 
	{ 
	  this->m_GradeList.RemoveAll();   
	} 
	CFldValue value; 
	this->m_Storage.OpenSql("Grade","年级编号,年级名称"); 
	if(this->m_Storage.GetRecordCount()>0) 
	{    
		this->m_Storage.MoveFirst(); 
		CString fldvalue; 
		while(!this->m_Storage.IsEof()) 
		{ 
		   this->m_Storage.GetFieldValue("年级编号",fldvalue); 
		   strcpy(value.FieldValue,fldvalue); 
    	   this->m_Storage.GetFieldValue("年级名称",fldvalue); 
		   strcpy(value.DispalyFieldValue,fldvalue); 
           this->m_GradeList.AddTail(value); 
		   this->m_Storage.MoveNext(); 
		} 
	 
	} 
 
} 
void CExamClass::GetClassesByGradeNo(CString GradeNo) 
{ 
	if(this->m_ClassList.GetCount()>0) 
	{ 
	  this->m_ClassList.RemoveAll();   
	} 
	CFldValue value; 
	CString ConStr; 
	ConStr="where 年级编号='"+GradeNo+"'"; 
	this->m_Storage.OpenSql("Class","班级编号,班级名称",ConStr); 
	if(this->m_Storage.GetRecordCount()>0) 
	{    
		this->m_Storage.MoveFirst(); 
		CString fldvalue; 
		while(!this->m_Storage.IsEof()) 
		{ 
		   this->m_Storage.GetFieldValue("班级编号",fldvalue); 
		   strcpy(value.FieldValue,fldvalue); 
    	   this->m_Storage.GetFieldValue("班级名称",fldvalue); 
		   strcpy(value.DispalyFieldValue,fldvalue); 
           this->m_ClassList.AddTail(value); 
		   this->m_Storage.MoveNext(); 
		} 
	 
	} 
} 
 
void CExamClass::AddClass() 
{ 
   CString FldList,ValueList; 
   FldList="考试编号,班级编号"; 
   ValueList="'"+this->m_ExamNo+"','"+this->m_ClassNo+"'"; 
   this->m_Storage.ExecInsertSql(this->m_TblName,FldList,ValueList);  
} 
bool CExamClass::IsClassNoExisted(const CString ExamNo,CString ClassNo)//编号是否存在 
{ 
   CString ConStr; 
   ConStr="where 班级编号='"+ClassNo+"' and  考试编号='"+ExamNo+"'"; 
   this->m_Storage.OpenSql(this->m_TblName,"编号",ConStr); 
   if(this->m_Storage.GetRecordCount()>0) 
   { 
      return true; 
   } 
   else 
   { 
      return false; 
   } 
} 
 
void CExamClass::DelClassByNo(CString No) 
{ 
  CString constr; 
  constr="where 编号="+No; 
  this->m_Storage.ExceDeleteSql(this->m_TblName,constr);  
} 
 
//CExamStudent 
 
CExamStudent::CExamStudent() 
{ 
    this->m_TblName="ExamStudent" ; 
} 
CExamStudent::~CExamStudent() 
{ 
 
} 
 
//CExamStudent成员函数 
 
void CExamStudent::GetExamStudentBy(const CString ExamNo,const CString ClassNo) 
{ 
   CString SqlStr; 
   SqlStr="select a.考生编号 ,a.学号,b.姓名,a.总成绩,a.平均成绩 "; 
   SqlStr+=" from ExamStudent a,student b where a.考试编号='"+ExamNo+"' and  a.班级编号='"+ClassNo+"'"; 
   SqlStr+=" and a.学号=b.学号"; 
   this->m_Storage.Open(SqlStr,CADODataset::openQuery);  
} 
 
void CExamStudent::AddStudent() 
{ 
    CString FldList,ValueList; 
   FldList="考试编号,班级编号,学号"; 
   ValueList="'"+this->m_ExamNo+"','"+this->m_ClassNo+"','"+this->m_StudentNo+"'"; 
   this->m_Storage.ExecInsertSql(this->m_TblName,FldList,ValueList);  
} 
 
void CExamStudent::GetStudentsByClassNo(CString ClassNo) 
{ 
	if(this->m_StudentList.GetCount()>0) 
	{ 
	  this->m_StudentList.RemoveAll();   
	} 
	CFldValue value; 
	CString ConStr; 
	ConStr="where 班级编号='"+ClassNo+"'"; 
	this->m_Storage.OpenSql("student","学号,姓名",ConStr); 
	if(this->m_Storage.GetRecordCount()>0) 
	{    
		this->m_Storage.MoveFirst(); 
		CString fldvalue; 
		while(!this->m_Storage.IsEof()) 
		{ 
		   this->m_Storage.GetFieldValue("学号",fldvalue); 
		   strcpy(value.FieldValue,fldvalue); 
    	   this->m_Storage.GetFieldValue("姓名",fldvalue); 
		   strcpy(value.DispalyFieldValue,fldvalue); 
           this->m_StudentList.AddTail(value); 
		   this->m_Storage.MoveNext(); 
		} 
	 
	} 
} 
 
bool CExamStudent::IsStudentNoExisted(const CString ExamNo,const CString ClassNo,const CString StudentNo)//编号是否存在 
{ 
	CString ConStr; 
	ConStr="where 考试编号='"+ExamNo+"' and 班级编号='"+ClassNo+"' and 学号='"; 
	ConStr+=StudentNo+"'"; 
   this->m_Storage.OpenSql(this->m_TblName,"考生编号",ConStr); 
   if(this->m_Storage.GetRecordCount()>0) 
   { 
      return true; 
   } 
   else 
   { 
      return false; 
   } 
} 
 
void CExamStudent::DelStudent(const CString ExamNo,const CString ClassNo,const CString StudentNo) 
{ 
	CString ConStr; 
	ConStr="where 考试编号='"+ExamNo+"' and 班级编号='"+ClassNo+"' and 学号='"; 
	ConStr+=StudentNo+"'"; 
	this->m_Storage.ExceDeleteSql(this->m_TblName,ConStr);  
} 
void CExamStudent::DelStudentByNo(const CString No) 
{ 
    CString ConStr; 
	ConStr="where 考生编号="+No; 
	this->m_Storage.ExceDeleteSql(this->m_TblName,ConStr);  
} 
 
//CExamSubject 
void CExamSubject::GetExamSubjectBy(const CString ExamNo,const CString ClassNo) 
{ 
   CString SqlStr; 
   SqlStr="select a.编号 ,a.学号,b.姓名,a.课程编号,c.课程名称,a.成绩 "; 
   SqlStr+=" from ExamSubject a,student b,subject c where a.考试编号='"+ExamNo+"' and  a.班级编号='"+ClassNo+"'"; 
   SqlStr+=" and a.学号=b.学号 and a.课程编号=c.课程编号"; 
   this->m_Storage.Open(SqlStr,CADODataset::openQuery);  
} 
void CExamSubject::GetStudentsByClassNo(CString ClassNo)//获取学生列表 
{ 
   	if(this->m_StudentList.GetCount()>0) 
	{ 
	  this->m_StudentList.RemoveAll();   
	} 
	CFldValue value; 
	CString ConStr; 
	ConStr="where 班级编号='"+ClassNo+"'"; 
	this->m_Storage.OpenSql("student","学号,姓名",ConStr); 
	if(this->m_Storage.GetRecordCount()>0) 
	{    
		this->m_Storage.MoveFirst(); 
		CString fldvalue; 
		while(!this->m_Storage.IsEof()) 
		{ 
		   this->m_Storage.GetFieldValue("学号",fldvalue); 
		   strcpy(value.FieldValue,fldvalue); 
    	   this->m_Storage.GetFieldValue("姓名",fldvalue); 
		   strcpy(value.DispalyFieldValue,fldvalue); 
           this->m_StudentList.AddTail(value); 
		   this->m_Storage.MoveNext(); 
		} 
	 
	} 
} 
void CExamSubject::GetSubjectsByClassNo(CString ClassNo)//科目列表 
{ 
   	if(this->m_SubjectList.GetCount()>0) 
	{ 
	  this->m_SubjectList.RemoveAll();   
	} 
	CFldValue value; 
	CString SqlStr; 
	SqlStr="select a.课程编号,b.课程名称 from SubjectClass a,Subject b "; 
	SqlStr+="where a.课程编号=b.课程编号 and a.班级编号='"+ClassNo+"'"; 
    this->m_Storage.Open(SqlStr,CADODataset::openQuery);  
	if(this->m_Storage.GetRecordCount()>0) 
	{    
		this->m_Storage.MoveFirst(); 
		CString fldvalue; 
		while(!this->m_Storage.IsEof()) 
		{ 
		   this->m_Storage.GetFieldValue("课程编号",fldvalue); 
		   strcpy(value.FieldValue,fldvalue); 
    	   this->m_Storage.GetFieldValue("课程名称",fldvalue); 
		   strcpy(value.DispalyFieldValue,fldvalue); 
           this->m_SubjectList.AddTail(value); 
		   this->m_Storage.MoveNext(); 
		} 
	 
	} 
} 
void CExamSubject::AddSubject()//添加科目 
{ 
   CString FldList,ValueList; 
   char a[50]; 
   FldList="考试编号,班级编号,学号,课程编号,成绩"; 
   ValueList="'"+this->m_ExamNo+"','"+this->m_ClassNo+"','"; 
   ValueList+=this->m_StudentNo+"','"+this->m_SubjectNo+"',"; 
   sprintf(a,"%f",this->m_Score);  
   ValueList+=a; 
   this->m_Storage.ExecInsertSql(this->m_TblName,FldList,ValueList);  
} 
void CExamSubject::DelSubjectByNo(const CString No)//删除科目 
{ 
    CString ConStr; 
	ConStr="where 编号="+No; 
	this->m_Storage.ExceDeleteSql(this->m_TblName,ConStr);  
}