📄 exam8_3view.cpp
字号:
// Exam8_3View.cpp : implementation of the CExam8_3View class
//
#include "stdafx.h"
#include "Exam8_3.h"
#include "Exam8_3Doc.h"
#include "Exam8_3View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExam8_3View
IMPLEMENT_DYNCREATE(CExam8_3View, CFormView)
BEGIN_MESSAGE_MAP(CExam8_3View, CFormView)
//{{AFX_MSG_MAP(CExam8_3View)
ON_COMMAND(IDC_STUDENT_INSERT, OnStudentInsert)
ON_COMMAND(IDC_STUDENT_DEL, OnStudentDel)
ON_UPDATE_COMMAND_UI(IDC_STUDENT_DEL, OnUpdateStudentDel)
ON_COMMAND(IDC_STUDENT_END, OnStudentEnd)
ON_UPDATE_COMMAND_UI(IDC_STUDENT_END, OnUpdateStudentEnd)
ON_COMMAND(IDC_STUDENT_HOME, OnStudentHome)
ON_UPDATE_COMMAND_UI(IDC_STUDENT_HOME, OnUpdateStudentHome)
ON_COMMAND(IDC_STUDENT_NEXT, OnStudentNext)
ON_UPDATE_COMMAND_UI(IDC_STUDENT_NEXT, OnUpdateStudentNext)
ON_COMMAND(IDC_STUDENT_PREV, OnStudentPrev)
ON_UPDATE_COMMAND_UI(IDC_STUDENT_PREV, OnUpdateStudentPrev)
ON_COMMAND(IDC_EDIT_CLEAR, OnEditClear)
ON_BN_CLICKED(IDC_CLEAR, OnClear)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExam8_3View construction/destruction
CExam8_3View::CExam8_3View()
: CFormView(CExam8_3View::IDD)
{
//{{AFX_DATA_INIT(CExam8_3View)
m_Name = _T("");
m_Grade = 0;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CExam8_3View::~CExam8_3View()
{
}
void CExam8_3View::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExam8_3View)
DDX_Text(pDX, IDC_NAME, m_Name);
DDX_Text(pDX, IDC_GRADE, m_Grade);
//}}AFX_DATA_MAP
}
BOOL CExam8_3View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CExam8_3View::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CExam8_3View printing
BOOL CExam8_3View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CExam8_3View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CExam8_3View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CExam8_3View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CExam8_3View diagnostics
#ifdef _DEBUG
void CExam8_3View::AssertValid() const
{
CFormView::AssertValid();
}
void CExam8_3View::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CExam8_3Doc* CExam8_3View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExam8_3Doc)));
return (CExam8_3Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExam8_3View message handlers
void CExam8_3View::OnStudentInsert()
{
// TODO: Add your command handler code here
UpdateData(true);//更新控件变量
//调用文档类AddStu函数增加一条记录
GetDocument()->AddStu(m_Name,m_Grade);
//索引值指向最后一条记录(新增记录)
m_StuIndex=GetDocument()->GetStuNumber()-1;
}
void CExam8_3View::OnStudentDel()
{
// TODO: Add your command handler code here
//调用文档类DelStu函数删除当前记录
GetDocument()->DelStu(m_StuIndex);
}
void CExam8_3View::OnUpdateStudentDel(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_StuIndex>=0);
}
void CExam8_3View::OnStudentEnd()
{
// TODO: Add your command handler code here
//最后一学生记录的索引值为记录总数-1
m_StuIndex=GetDocument()->GetStuNumber()-1 ;
if(m_StuIndex>0)
{
m_pStu=GetDocument()->GetStu(m_StuIndex);
m_Grade=m_pStu->m_Grade;
m_Name=m_pStu->m_Name;
UpdateData(false);
UpdateWindow();
}
}
void CExam8_3View::OnUpdateStudentEnd(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_StuIndex<GetDocument()->GetStuNumber()-1 );
}
void CExam8_3View::OnStudentHome()
{
// TODO: Add your command handler code here
if(GetDocument()->GetStuNumber()>0) //文档数据不空
{
m_StuIndex=0;//第一个记录索引值为0
m_pStu=GetDocument()->GetStu(m_StuIndex);//获取第一个记录
//为控件变量赋值
m_Grade=m_pStu->m_Grade;
m_Name=m_pStu->m_Name;
//更新视图
UpdateData(false);
UpdateWindow();
}
}
void CExam8_3View::OnUpdateStudentHome(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_StuIndex>0);
}
void CExam8_3View::OnStudentNext()
{
// TODO: Add your command handler code here
m_StuIndex++;//索引值向后移动1位
m_pStu=GetDocument()->GetStu(m_StuIndex);
m_Grade=m_pStu->m_Grade;
m_Name=m_pStu->m_Name;
UpdateData(false);
UpdateWindow();
}
void CExam8_3View::OnUpdateStudentNext(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_StuIndex<GetDocument()->GetStuNumber()-1 );
}
void CExam8_3View::OnStudentPrev()
{
// TODO: Add your command handler code here
m_StuIndex--;//索引值向前移动1位
m_pStu=GetDocument()->GetStu(m_StuIndex);
m_Grade=m_pStu->m_Grade;
m_Name=m_pStu->m_Name;
UpdateData(false);
UpdateWindow();
}
void CExam8_3View::OnUpdateStudentPrev(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_StuIndex>0);
}
void CExam8_3View::OnEditClear()
{
// TODO: Add your command handler code here
m_StuIndex=-1;//索引值设为1,表示文档数据为空
//调用文档delStuAll删除所有记录,更新视图
GetDocument()->delStuAll();
}
void CExam8_3View::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
if(GetDocument()->GetStuNumber()>0)//文档数据不为空
{
m_StuIndex=0; //索引值为0
m_pStu=GetDocument()->GetStu(0);//取第一个学生记录
}
else//文档数据为空
{
m_StuIndex=-1;//索引值为-1
m_pStu=new CStudent("",0);//创建一个为空的学生记录
}
//为控件变量赋值,初始化视图
m_Grade=m_pStu->m_Grade ;
m_Name=m_pStu->m_Name ;
UpdateData(false);
}
void CExam8_3View::OnClear()
{
// TODO: Add your control notification handler code here
m_Name="";
m_Grade=0;
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -