📄 daosnapview.cpp
字号:
// DaoSnapView.cpp : implementation of the CDaoSnapView class
//
#include "stdafx.h"
#include "DaoSnap.h"
#include "DaoSnapSet.h"
#include "DaoSnapDoc.h"
#include "DaoSnapView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDaoSnapView
IMPLEMENT_DYNCREATE(CDaoSnapView, CDaoRecordView)
BEGIN_MESSAGE_MAP(CDaoSnapView, CDaoRecordView)
//{{AFX_MSG_MAP(CDaoSnapView)
ON_COMMAND(ID_RCD_ADD, OnRcdAdd)
ON_COMMAND(ID_RCD_DELETE, OnRcdDelete)
ON_COMMAND(ID_RCD_REFRESH, OnRcdRefresh)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CDaoRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CDaoRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CDaoRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDaoSnapView construction/destruction
CDaoSnapView::CDaoSnapView()
: CDaoRecordView(CDaoSnapView::IDD)
{
//{{AFX_DATA_INIT(CDaoSnapView)
m_pSet = NULL;
m_bAddMode=FALSE;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CDaoSnapView::~CDaoSnapView()
{
}
void CDaoSnapView::DoDataExchange(CDataExchange* pDX)
{
CDaoRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDaoSnapView)
DDX_FieldText(pDX, IDC_EDIT1, m_pSet->m_Capacity, m_pSet);
DDX_FieldText(pDX, IDC_EDIT2, m_pSet->m_CourseID, m_pSet);
DDX_FieldText(pDX, IDC_EDIT3, m_pSet->m_InstructorID, m_pSet);
DDX_FieldText(pDX, IDC_EDIT4, m_pSet->m_RoomNo, m_pSet);
DDX_FieldText(pDX, IDC_EDIT5, m_pSet->m_Schedule, m_pSet);
DDX_FieldText(pDX, IDC_EDIT6, m_pSet->m_SectionNo, m_pSet);
//}}AFX_DATA_MAP
}
BOOL CDaoSnapView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CDaoRecordView::PreCreateWindow(cs);
}
void CDaoSnapView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_daoSnapSet;
CDaoRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CDaoSnapView printing
BOOL CDaoSnapView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDaoSnapView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDaoSnapView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDaoSnapView diagnostics
#ifdef _DEBUG
void CDaoSnapView::AssertValid() const
{
CDaoRecordView::AssertValid();
}
void CDaoSnapView::Dump(CDumpContext& dc) const
{
CDaoRecordView::Dump(dc);
}
CDaoSnapDoc* CDaoSnapView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDaoSnapDoc)));
return (CDaoSnapDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDaoSnapView database support
CDaoRecordset* CDaoSnapView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CDaoSnapView message handlers
//●:
void CDaoSnapView::OnRcdAdd()
{
// TODO: Add your command handler code here
if(m_bAddMode)
{
OnMove(ID_RECORD_FIRST);
}
m_pSet->AddNew();
m_bAddMode=TRUE;
UpdateData(FALSE);
}
void CDaoSnapView::OnRcdDelete()
{
// TODO: Add your command handler code here
m_pSet->Delete();
m_pSet->MoveNext();
if(m_pSet->IsEOF())
{
m_pSet->MoveLast();
}
if(m_pSet->IsBOF())
{
m_pSet->SetFieldNull(NULL);
}
UpdateData(FALSE);
}
void CDaoSnapView::OnRcdRefresh()
{
// TODO: Add your command handler code here
if(m_bAddMode)
{
m_pSet->CancelUpdate();
m_pSet->Move(0);
m_bAddMode=FALSE;
}
m_pSet->Edit();
UpdateData(TRUE);
m_pSet->Update();
}
BOOL CDaoSnapView::OnMove(UINT nIDMoveCommand)
{
// TODO: Add your specialized code here and/or call the base class
if(m_bAddMode)
{
if(!UpdateData())
{
return FALSE;
}
try
{
m_pSet->Update();
}
catch(CDaoException * e)
{
AfxMessageBox(e->m_pErrorInfo->m_strDescription);
e->Delete();
return FALSE;
}
m_pSet->Requery();
UpdateData(FALSE);
m_bAddMode=FALSE;
return TRUE;
}
else
{
return CDaoRecordView::OnMove(nIDMoveCommand);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -