?? studentquery.~cpp
字號:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "StudentQuery.h"
#include "DataUnit.h"
#include "ModifyPassword.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TStuQryForm *StuQryForm;
//---------------------------------------------------------------------------
__fastcall TStuQryForm::TStuQryForm(TComponent* Owner)
: TForm(Owner)
{
m_nTotalScore = 0 ;
m_strStudentNo = "" ;
m_strName = "" ;
j = 0 ;
}
//---------------------------------------------------------------------------
void __fastcall TStuQryForm::OKBtnClick(TObject *Sender)
{
Close() ;
}
//---------------------------------------------------------------------------
void __fastcall TStuQryForm::FormCreate(TObject *Sender)
{
StringGrid1->Cells[0][0] = "課程名稱" ;
StringGrid1->Cells[1][0] = "開課學期" ;
StringGrid1->Cells[2][0] = "課程學分" ;
StringGrid1->Cells[3][0] = "課程成績" ;
}
//---------------------------------------------------------------------------
void __fastcall TStuQryForm::FormShow(TObject *Sender)
{
//首先構造查詢Course數據表的SQL語句
AnsiString queryString = "Select * from Course " ;
DataMod->CourseQuery->SQL->Clear() ;
DataMod->CourseQuery->SQL->Add(queryString) ;
//執行查詢
DataMod->CourseQuery->ExecSQL() ;
DataMod->CourseQuery->Active = true ;
for(int i=0; i<DataMod->CourseQuery->RecordCount;i++)
{
//得到課程的名稱
AnsiString CourseName = DataMod->CourseQuery->FieldValues["CourseName"] ;
//得到課程的學分
int nScore = DataMod->CourseQuery->FieldValues["Score"] ;
//然后構造查詢成績表的SQL語句
AnsiString otherQuery = "Select * from Grade " ;
otherQuery += " where StudentNo =\"" ;
otherQuery += m_strStudentNo ;
otherQuery += "\"" ;
otherQuery += " and CourseNo=\"" ;
otherQuery += DataMod->CourseQuery->FieldValues["CourseNo"] ;
otherQuery += "\"" ;
try
{
//執行查詢
DataMod->GradeQuery->SQL->Clear() ;
DataMod->GradeQuery->SQL->Add(otherQuery) ;
DataMod->GradeQuery->ExecSQL() ;
DataMod->GradeQuery->Active = true ;
}
catch(EDBEngineError &E)
{
//將當前指針移動到下一個記錄
DataMod->CourseQuery->Next() ;
continue ;
}
if(DataMod->GradeQuery->RecordCount)
{
j++ ;
//根據情況得到相應的學生查詢數據
AnsiString strGrade=DataMod->GradeQuery->FieldByName("Score")->AsString ;
if(strGrade != "" )
{
StringGrid1->Cells[0][j] = CourseName ;
StringGrid1->Cells[1][j] = DataMod->GradeQuery->FieldValues["Term"];
StringGrid1->Cells[2][j] = IntToStr(nScore) ;
StringGrid1->Cells[3][j] = DataMod->GradeQuery->FieldValues["Score"];
//將該課程的學分加入到總學分中
m_nTotalScore += nScore ;
}
else
{
StringGrid1->Cells[0][j] = CourseName ;
StringGrid1->Cells[1][j] = DataMod->GradeQuery->FieldValues["Term"];
StringGrid1->Cells[2][j] = IntToStr(nScore) ;
StringGrid1->Cells[3][j] = "";
}
}
//將當前指針移動到下一個記錄
DataMod->CourseQuery->Next() ;
}
//顯示學號,姓名與總學分(已有成績的)
StuNoEdt->Text = m_strStudentNo ;
NameEdt->Text = m_strName ;
ScoreEdt->Text = IntToStr(m_nTotalScore) ;
}
//---------------------------------------------------------------------------
void __fastcall TStuQryForm::PasswordBtnClick(TObject *Sender)
{
TMdfPwdDlg *MdfPwdDlg = new TMdfPwdDlg(this) ;
if(MdfPwdDlg->ShowModal() == mrOk )
{
DataMod->StudentQuery->SQL->Clear() ;
DataMod->StudentQuery->Close() ;
try
{
AnsiString queryString = "Select * from Student" ;
queryString += " where StudentNo =\"" ;
queryString += m_strStudentNo ;
queryString += "\"" ;
DataMod->StudentQuery->SQL->Add(queryString) ;
DataMod->StudentQuery->RequestLive = true ;
DataMod->StudentQuery->ExecSQL() ;
DataMod->StudentQuery->Active = true ;
DataMod->StudentQuery->Edit() ;
DataMod->StudentQuery->FieldValues["SPassword"]=
MdfPwdDlg->FstTimeEdt->Text ;
DataMod->StudentQuery->Post() ;
DataMod->StudentQuery->Close() ;
}
catch(EDBEngineError &E)
{
MessageBox(this,"不能修改口令!","錯誤",mbOK ) ;
delete MdfPwdDlg ;
return ;
}
}
delete MdfPwdDlg ;
}
//---------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -