📄 paperoptionview.cpp
字号:
// PaperOptionView.cpp : implementation file
//
#include "stdafx.h"
#include "TestApp.h"
#include "PaperOptionView.h"
#include "PaperDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPaperOptionView
IMPLEMENT_DYNCREATE(CPaperOptionView, CRecordView)
CPaperOptionView::CPaperOptionView()
: CRecordView(CPaperOptionView::IDD)
{
//{{AFX_DATA_INIT(CPaperOptionView)
m_papername = _T("新建试卷"); //默认试卷名称
m_totalscore =100;//试卷总分
m_spacetotalscore = 20;//判断题分数
m_spacescore = 1;//判断题每小题分数
m_spacecount2 = 2;//有两个空的判断题题数
m_spacecount1 = 16;//有个一个空判断题题数
m_spacecount = 20;//判断题总数
m_spacescale = 0;//判断题章节分配比例
m_singletotalscore = 20;//单选题题分数
m_singlescore = 1;//单选题每小题分数
m_singlescale = 0;//单选题章节题量分配比例
m_singlecount = 20;//单选题总数
m_morescale = 0;//多选题章节题量分配比例
m_moretotalscore = 40;//多选题分数
m_morescore = 2;//多选题每小题分数
m_morecount = 20;//多选题总数
m_judgecount = 20;//判断题总数
m_judgescore = 1;//判断题每小题分数
m_judgescale = 0;//判断题章节题量分配比例
m_judgetotalscore = 20;//判断题分数
m_judgescale2 = 0;
m_morescale2 = 0;
m_singlescale2 = 0;
m_spacescale2 = 0;
m_pSet = NULL;
//}}AFX_DATA_INIT
}
CPaperOptionView::~CPaperOptionView()
{ ((CTestAppApp*)AfxGetApp())->m_PaperOptionViews=0;//启用显示试卷定制窗口菜单命令
if (m_pSet)
delete m_pSet;
if (m_pSetChapter)
delete m_pSetChapter;//删除章节记录集指针
if (m_pSetJudge)
delete m_pSetJudge; //删除判断题记录集指针
if (m_pSetSpace)
delete m_pSetSpace; //删除填空题记录集指针
if (m_pSetSingle)
delete m_pSetSingle; //删除单选题记录集指针
if (m_pSetMore)
delete m_pSetMore; //删除多选题记录集指针
}
void CPaperOptionView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPaperOptionView)
DDX_Control(pDX, IDC_EDIT_PAPERNAME, m_objpapername);
DDX_Control(pDX, IDC_EDIT_SPACESCALE, m_objspacescale);
DDX_Control(pDX, IDC_EDIT_SINGLESCALE, m_objsinglescale);
DDX_Control(pDX, IDC_EDIT_MORESCALE, m_objmorescale);
DDX_Control(pDX, IDC_EDIT_JUDGESCALE, m_objjudgescale);
DDX_Control(pDX, IDC_COMBO_SPACE, m_space);
DDX_Control(pDX, IDC_COMBO_SINGLE, m_single);
DDX_Control(pDX, IDC_COMBO_MORE, m_more);
DDX_Control(pDX, IDC_COMBO_JUDGE, m_judge);
DDX_Text(pDX, IDC_EDIT_PAPERNAME, m_papername);
DDV_MaxChars(pDX, m_papername, 10);
DDX_Text(pDX, IDC_EDIT_TOTALSCORE, m_totalscore);
DDV_MinMaxInt(pDX, m_totalscore, 0, 500);
DDX_Text(pDX, IDC_EDIT_JUDGECOUNT, m_judgecount);
DDV_MinMaxInt(pDX, m_judgecount, 0, 100);
DDX_Text(pDX, IDC_EDIT_SPACETOTALSCORE, m_spacetotalscore);
DDX_Text(pDX, IDC_EDIT_SPACESCORE, m_spacescore);
DDV_MinMaxInt(pDX, m_spacescore, 0, 10);
DDX_Text(pDX, IDC_EDIT_SPACECOUNT2, m_spacecount2);
DDV_MinMaxInt(pDX, m_spacecount2, 0, 50);
DDX_Text(pDX, IDC_EDIT_SPACECOUNT1, m_spacecount1);
DDV_MinMaxInt(pDX, m_spacecount1, 0, 100);
DDX_Text(pDX, IDC_EDIT_SPACECOUNT, m_spacecount);
DDV_MinMaxInt(pDX, m_spacecount, 0, 100);
DDX_Text(pDX, IDC_EDIT_SPACESCALE, m_spacescale);
DDV_MinMaxInt(pDX, m_spacescale, 0, 100);
DDX_Text(pDX, IDC_EDIT_SINGLETOTALSCORE, m_singletotalscore);
DDX_Text(pDX, IDC_EDIT_SINGLESCORE, m_singlescore);
DDV_MinMaxInt(pDX, m_singlescore, 0, 10);
DDX_Text(pDX, IDC_EDIT_SINGLESCALE, m_singlescale);
DDV_MinMaxInt(pDX, m_singlescale, 0, 100);
DDX_Text(pDX, IDC_EDIT_SINGLECOUNT, m_singlecount);
DDV_MinMaxInt(pDX, m_singlecount, 0, 100);
DDX_Text(pDX, IDC_EDIT_MORESCALE, m_morescale);
DDV_MinMaxInt(pDX, m_morescale, 0, 100);
DDX_Text(pDX, IDC_EDIT_MORETOTALSCORE, m_moretotalscore);
DDX_Text(pDX, IDC_EDIT_MOREESCORE, m_morescore);
DDV_MinMaxInt(pDX, m_morescore, 0, 10);
DDX_Text(pDX, IDC_EDIT_MORECOUNT, m_morecount);
DDV_MinMaxInt(pDX, m_morecount, 1, 100);
DDX_Text(pDX, IDC_EDIT_JUDGESCORE, m_judgescore);
DDV_MinMaxInt(pDX, m_judgescore, 0, 10);
DDX_Text(pDX, IDC_EDIT_JUDGESCALE, m_judgescale);
DDV_MinMaxInt(pDX, m_judgescale, 0, 100);
DDX_Text(pDX, IDC_EDIT_JUDGETOTALSCORE, m_judgetotalscore);
DDX_Text(pDX, IDC_EDIT_JUDGESCALE2, m_judgescale2);
DDX_Text(pDX, IDC_EDIT_MORESCALE2, m_morescale2);
DDX_Text(pDX, IDC_EDIT_SINGLESCALE2, m_singlescale2);
DDX_Text(pDX, IDC_EDIT_SPACESCALE2, m_spacescale2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPaperOptionView, CRecordView)
//{{AFX_MSG_MAP(CPaperOptionView)
ON_BN_CLICKED(IDC_BUTTON_TESTAUTO, OnButtonTestauto)
ON_BN_CLICKED(IDC_BUTTON_TESTDIY, OnButtonTestdiy)
ON_CBN_SELENDOK(IDC_COMBO_JUDGE, OnSelendokComboJudge)
ON_CBN_SELENDOK(IDC_COMBO_MORE, OnSelendokComboMore)
ON_CBN_SELENDOK(IDC_COMBO_SINGLE, OnSelendokComboSingle)
ON_CBN_SELENDOK(IDC_COMBO_SPACE, OnSelendokComboSpace)
ON_EN_CHANGE(IDC_EDIT_SINGLECOUNT, OnChangeEditSinglecount)
ON_EN_CHANGE(IDC_EDIT_SINGLESCORE, OnChangeEditSinglescore)
ON_EN_CHANGE(IDC_EDIT_SPACECOUNT, OnChangeEditSpacecount)
ON_EN_CHANGE(IDC_EDIT_SPACECOUNT1, OnChangeEditSpacecount1)
ON_EN_CHANGE(IDC_EDIT_SPACECOUNT2, OnChangeEditSpacecount2)
ON_EN_CHANGE(IDC_EDIT_SPACESCORE, OnChangeEditSpacescore)
ON_EN_CHANGE(IDC_EDIT_MORECOUNT, OnChangeEditMorecount)
ON_EN_CHANGE(IDC_EDIT_MOREESCORE, OnChangeEditMoreescore)
ON_EN_CHANGE(IDC_EDIT_JUDGECOUNT, OnChangeEditJudgecount)
ON_EN_CHANGE(IDC_EDIT_JUDGESCORE, OnChangeEditJudgescore)
ON_EN_CHANGE(IDC_EDIT_JUDGESCALE, OnChangeEditJudgescale)
ON_EN_CHANGE(IDC_EDIT_MORESCALE, OnChangeEditMorescale)
ON_EN_CHANGE(IDC_EDIT_SINGLESCALE, OnChangeEditSinglescale)
ON_EN_CHANGE(IDC_EDIT_SPACESCALE, OnChangeEditSpacescale)
ON_EN_KILLFOCUS(IDC_EDIT_SPACESCALE, OnKillfocusEditSpacescale)
ON_EN_KILLFOCUS(IDC_EDIT_SINGLESCALE, OnKillfocusEditSinglescale)
ON_EN_KILLFOCUS(IDC_EDIT_MORESCALE, OnKillfocusEditMorescale)
ON_EN_KILLFOCUS(IDC_EDIT_JUDGESCALE, OnKillfocusEditJudgescale)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPaperOptionView diagnostics
#ifdef _DEBUG
void CPaperOptionView::AssertValid() const
{
CRecordView::AssertValid();
}
void CPaperOptionView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPaperOptionView message handlers
CRecordset* CPaperOptionView::OnGetRecordset()
{
if (m_pSet != NULL)
return m_pSet;
m_pSet = new CPapersDataSet(NULL);
m_pSet->Open();
return m_pSet;
}
CPapersDataSet* CPaperOptionView::GetRecordset()
{
CPapersDataSet* pData = (CPapersDataSet*) OnGetRecordset();
ASSERT(pData == NULL || pData->IsKindOf(RUNTIME_CLASS(CPapersDataSet)));
return pData;
}
void CPaperOptionView::OnInitialUpdate()
{
BeginWaitCursor();
GetRecordset();
CRecordView::OnInitialUpdate();
//创建用于访问各个试题和章节表的记录集指针
m_pSetChapter = new CChapterSet(NULL);
m_pSetJudge = new CJudgeSet(NULL);
m_pSetSpace = new CSpaceSet(NULL);
m_pSetSingle = new CSingleSet(NULL);
m_pSetMore = new CMoreSet(NULL);
GetDocument()->SetTitle("定制试卷");//设置文档标题
GetParent()->SetWindowText("定制试卷");//设置子窗口标题
if(!m_pSetChapter->IsOpen())
m_pSetChapter->Open();
//创建章节名称列表
while(!m_pSetChapter->IsEOF())
{
if(CB_ERR==m_judge.FindString(-1,m_pSetChapter->m_name)){
m_judge.AddString(m_pSetChapter->m_name);//不重复,加入列表
m_space.AddString(m_pSetChapter->m_name);
m_single.AddString(m_pSetChapter->m_name);
m_more.AddString(m_pSetChapter->m_name);
}
m_pSetChapter->MoveNext();
}
m_pSetChapter->MoveFirst();
//设置默认的章节题量比例
int n=m_judge.GetCount();
int m=100/n,s;
m_judgescale=m;
m_spacescale=m;
m_singlescale=m;
m_morescale=m;
for (int i=0;i<n;i++){
m_judge.SetItemData(i,m);
m_space.SetItemData(i,m);
m_single.SetItemData(i,m);
m_more.SetItemData(i,m);
s+=m;
}
if(s!=100){
m_judge.SetItemData(i,m+100-s);
m_space.SetItemData(i,m+100-s);
m_single.SetItemData(i,m+100-s);
m_more.SetItemData(i,m+100-s);
}
//设置默认章节名称
m_judge.SelectString(-1,m_pSetChapter->m_name);
m_space.SelectString(-1,m_pSetChapter->m_name);
m_single.SelectString(-1,m_pSetChapter->m_name);
m_more.SelectString(-1,m_pSetChapter->m_name);
UpdateData(false);
EndWaitCursor();
}
int CPaperOptionView::CheckPaperOption()
//检验试卷参数是否有效
{
UpdateData(true);//将窗口数据传入变量
if (""==m_papername )
{
AfxMessageBox("请指定试卷名称!");
m_objpapername.SetFocus();
return 0;
}
//检查题量剩余值是否都为0
if (m_spacescale2>0)
{
AfxMessageBox("填空题章节题量没有分配完!");
m_objspacescale.SetFocus();
return 0;
}
if (m_judgescale2>0)
{
AfxMessageBox("判断题章节题量没有分配完!");
m_objjudgescale.SetFocus();
return 0;
}
if (m_singlescale2>0)
{
AfxMessageBox("单选题章节题量没有分配完!");
m_objsinglescale.SetFocus();
return 0;
}
if (m_morescale2>0)
{
AfxMessageBox("多选题章节题量没有分配完!");
m_objmorescale.SetFocus();
return 0;
}
//检查数据库中是否有足够的各种类型试题
//检查判断题是否有足够试题
if(!m_pSetJudge->IsOpen())
m_pSetJudge->Open();
if(!m_pSetChapter->IsOpen())
m_pSetChapter->Open();
int chaptercount,chapterscale,n,i,x;
float y;
CString chaptername,str;
chaptercount=m_judge.GetCount();//获得章节数
for(i=0;i<chaptercount;i++)
{ m_judge.GetLBText(i,chaptername);//获得章节名称
chapterscale=m_judge.GetItemData(i);
x=chapterscale* m_judgecount / 100;//计算章节试题数
y=chapterscale * m_judgecount / 100.0;
if (x!=y)
{
str.Format("题量比例不正确,本章试题数不为整数:%d*%d/100=%f",
m_judgecount,chapterscale,y);
MessageBox(str);
m_judge.SelectString(-1,chaptername);
m_judgescale=chapterscale;
UpdateData(false);
m_objjudgescale.SetFocus();
return 0;
}
//使用章节名称筛选章节记录集,获得章节编号
m_pSetChapter->m_strFilter="name='" + chaptername + "'";
m_pSetChapter->Requery();
//使用章节编号筛选判断题记录集
str.Format("%d",m_pSetChapter->m_id);
m_pSetJudge->m_strFilter="chapterid=" +str;
m_pSetJudge->Requery();
while(!m_pSetJudge->IsEOF())
m_pSetJudge->MoveNext();
n=m_pSetJudge->GetRecordCount();
if (x>n)
{
str.Format(chaptername+"只有%d道判断题,题量比例最多%d!",
n,n *100/m_judgecount);
AfxMessageBox(str);
m_judge.SelectString(-1,chaptername);
m_judgescale=m_judge.GetItemData(i);
m_objjudgescale.SetFocus();
UpdateData(false);
return 0;
}
}
//检查填空题试题是否足够
if(!m_pSetSpace->IsOpen())
m_pSetSpace->Open();
for(i=0;i<chaptercount;i++)
{
m_space.GetLBText(i,chaptername);//获得章节名称
chapterscale=m_judge.GetItemData(i);
x=chapterscale* m_spacecount / 100;//计算章节试题数
y=chapterscale * m_spacecount / 100.0;
if (x!=y)
{
str.Format("题量比例不正确,本章试题数不为整数:%d*%d/100=%f",
m_spacecount,chapterscale,y);
MessageBox(str);
m_space.SelectString(-1,chaptername);
m_spacescale=chapterscale;
UpdateData(false);
m_objspacescale.SetFocus();
return 0;
}
//使用章节名称筛选章节记录集,获得章节编号
m_pSetChapter->m_strFilter="name='" + chaptername + "'";
m_pSetChapter->Requery();
//使用章节编号筛选判断题记录集
str.Format("%d",m_pSetChapter->m_id);
m_pSetSpace->m_strFilter="chapterid=" +str;
m_pSetSpace->Requery();
while(!m_pSetSpace->IsEOF())
m_pSetSpace->MoveNext();
n=m_pSetSpace->GetRecordCount();
if (x>n)
{
str.Format(chaptername+"只有%d道填空题,题量比例最多%d!",
n,n *100/m_spacecount);
AfxMessageBox(str);
m_space.SelectString(-1,chaptername);
m_spacescale=m_space.GetItemData(i);
m_objspacescale.SetFocus();
UpdateData(false);
return 0;
}
}
//检查单选题题试题是否足够
if(!m_pSetSingle->IsOpen())
m_pSetSingle->Open();
for(i=0;i<chaptercount;i++)
{
m_single.GetLBText(i,chaptername);//获得章节名称
chapterscale=m_single.GetItemData(i);
x=chapterscale* m_singlecount / 100;//计算章节试题数
y=chapterscale * m_singlecount / 100.0;
if (x!=y)
{
str.Format("题量比例不正确,本章试题数不为整数:%d*%d/100=%f",
m_singlecount,chapterscale,y);
MessageBox(str);
m_single.SelectString(-1,chaptername);
m_singlescale=chapterscale;
UpdateData(false);
m_objsinglescale.SetFocus();
return 0;
}
//使用章节名称筛选章节记录集,获得章节编号
m_pSetChapter->m_strFilter="name='" + chaptername + "'";
m_pSetChapter->Requery();
//使用章节编号筛选判断题记录集
str.Format("%d",m_pSetChapter->m_id);
m_pSetSingle->m_strFilter="chapterid=" +str;
m_pSetSingle->Requery();
while(!m_pSetSingle->IsEOF())
m_pSetSingle->MoveNext();
n=m_pSetSingle->GetRecordCount();
if (x>n)
{
str.Format(chaptername+"只有%d道填空题,题量比例最多%d!",
n,n *100/m_singlecount);
AfxMessageBox(str);
m_single.SelectString(-1,chaptername);
m_singlescale=m_single.GetItemData(i);
m_objsinglescale.SetFocus();
UpdateData(false);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -