📄 tddlg.cpp
字号:
// TDDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "DBLogin.h"
#include "TDDlg.h"
#include "test.h"
#include ".\tddlg.h"
// TDDlg 对话框
IMPLEMENT_DYNAMIC(TDDlg, CDialog)
TDDlg::TDDlg(CWnd* pParent /*=NULL*/)
: CDialog(TDDlg::IDD, pParent)
, m_Answer(_T(""))
, m_NO(0)
, m_Score(0)
, m_Question(_T(""))
, m_Answer_A(_T(""))
, m_Answer_B(_T(""))
, m_Answer_C(_T(""))
, m_Answer_D(_T(""))
{
pDB = new CDatabase();
try{
if(!pDB->OpenEx("DSN=test"))
AfxMessageBox("Error,Can't open database");
pSet = new Ctest(pDB);
pSet->Open(CRecordset::dynaset);
}catch(CException *e){
e->ReportError();
}
this->SetTest();
}
TDDlg::~TDDlg()
{
if(pDB->IsOpen())
pDB->Close();
if(pSet->IsOpen())
pSet->Close();
delete pSet;
delete pDB;
}
void TDDlg::SetTest()
{
this->m_Answer = pSet->m_Answer;
this->m_NO = pSet->m_ID;
this->m_Score = pSet->m_Score;
this->m_Question = pSet->m_Question;
this->m_Answer_A = pSet->m_A;
this->m_Answer_B = pSet->m_B;
this->m_Answer_C = pSet->m_C;
this->m_Answer_D = pSet->m_D;
}
int TDDlg::GetMaxNo()
{
pSet->MoveLast();
return pSet->m_ID;
}
void TDDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_RScore, m_Answer);
DDX_Text(pDX, IDC_RScore3, m_NO);
DDX_Text(pDX, IDC_RScore2, m_Score);
DDX_Text(pDX, IDC_QText, m_Question);
DDX_Text(pDX, IDC_QA, m_Answer_A);
DDX_Text(pDX, IDC_Q_B, m_Answer_B);
DDX_Text(pDX, IDC_Q_C, m_Answer_C);
DDX_Text(pDX, IDC_Q_D, m_Answer_D);
}
BEGIN_MESSAGE_MAP(TDDlg, CDialog)
ON_BN_CLICKED(ID_FIRST, OnBnClickedFirst)
ON_BN_CLICKED(ID_PREV, OnBnClickedPrev)
ON_BN_CLICKED(ID_NEXT, OnBnClickedNext)
ON_BN_CLICKED(ID_END, OnBnClickedEnd)
ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_BN_CLICKED(IDOK2, OnBnClickedOk2)
// ON_BN_CLICKED(IDOK3, OnBnClickedOk3)
END_MESSAGE_MAP()
// TDDlg 消息处理程序
void TDDlg::OnBnClickedFirst()
{
// TODO: 在此添加控件通知处理程序代码
pSet->MoveFirst();
this->SetTest();
UpdateData(false);
}
void TDDlg::OnBnClickedPrev()
{
// TODO: 在此添加控件通知处理程序代码
pSet->MovePrev();
this->SetTest();
UpdateData(false);
if(pSet->IsBOF())
pSet->MoveFirst();
}
void TDDlg::OnBnClickedNext()
{
// TODO: 在此添加控件通知处理程序代码
pSet->MoveNext();
this->SetTest();
UpdateData(false);
if(pSet->IsEOF())
pSet->MoveLast();
}
void TDDlg::OnBnClickedEnd()
{
// TODO: 在此添加控件通知处理程序代码
pSet->MoveLast();
this->SetTest();
UpdateData(false);
}
void TDDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
//OnOK();
int n;
n = this->GetMaxNo();
UpdateData(true);
if(pSet->CanAppend())
{
pSet->AddNew();
pSet->m_Answer = this->m_Answer;
pSet->m_ID = this->m_NO;
pSet->m_Score = this->m_Score;
pSet->m_Question = this->m_Question;
pSet->m_A = this->m_Answer_A;
pSet->m_B = this->m_Answer_B;
pSet->m_C = this->m_Answer_C;
pSet->m_D = this->m_Answer_D;
pSet->m_ID = n+1;
pSet->Update();
AfxMessageBox("添加试题成功");
pSet->MoveLast();
this->SetTest();
UpdateData(false);
}else
AfxMessageBox("添加试题出错");
}
void TDDlg::OnBnClickedOk2()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(true);
if(pSet->CanUpdate())
{
pSet->Edit();
pSet->m_Answer = this->m_Answer;
pSet->m_ID = this->m_NO;
pSet->m_Score = this->m_Score;
pSet->m_Question = this->m_Question;
pSet->m_A = this->m_Answer_A;
pSet->m_B = this->m_Answer_B;
pSet->m_C = this->m_Answer_C;
pSet->m_D = this->m_Answer_D;
pSet->Update();
UpdateData(false);
AfxMessageBox("更改试题成功");
}else
AfxMessageBox("更改试题出错");
}
/*
void TDDlg::OnBnClickedOk3()
{
// TODO: 在此添加控件通知处理程序代码
if(this->GetMaxNo()<10)
{
AfxMessageBox("题库中题的数目太少,不能再删除");
return;
}
if(AfxMessageBox("真的要删除?",MB_YESNO) == IDYES)
{
if(pSet->CanUpdate())
pSet->Delete();
pSet->MoveNext();
if(pSet->IsBOF()){
pSet->SetFieldNull(NULL);
while(!pSet->IsEOF()){
pSet->Edit();
pSet->m_ID--;
pSet->Update();
pSet->MoveNext();
};
}else if(pSet->IsEOF())
{
pSet->MoveLast();
pSet->Edit();
pSet->m_ID--;
pSet->Update();
}else {
while(!pSet->IsEOF()){
pSet->Edit();
pSet->m_ID--;
pSet->Update();
pSet->MoveNext();
};
}
this->SetTest();
//UpdateData(false);
AfxMessageBox("删除成功");
}else
AfxMessageBox("删除失败");
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -