📄 sample02view.cpp
字号:
// Sample02View.cpp : implementation of the CSample02View class
//
#include "stdafx.h"
#include "Sample02.h"
#include "Sample02Set.h"
#include "Sample02Doc.h"
#include "Sample02View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSample02View
IMPLEMENT_DYNCREATE(CSample02View, CRecordView)
BEGIN_MESSAGE_MAP(CSample02View, CRecordView)
//{{AFX_MSG_MAP(CSample02View)
ON_COMMAND(ID_SORT, OnSort)
ON_COMMAND(ID_FILTER, OnFilter)
ON_COMMAND(ID_INSERT, OnInsert)
ON_COMMAND(ID_DELETE, OnDelete)
ON_COMMAND(ID_EDIT, OnEdit)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSample02View construction/destruction
CSample02View::CSample02View()
: CRecordView(CSample02View::IDD)
{
//{{AFX_DATA_INIT(CSample02View)
m_pSet = NULL;
//}}AFX_DATA_INIT
// TODO: add construction code here
m_bIsAdd = FALSE;
}
CSample02View::~CSample02View()
{
}
void CSample02View::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSample02View)
DDX_FieldText(pDX, IDC_ID, m_pSet->m_ID, m_pSet);
DDX_FieldText(pDX, IDC_NAME, m_pSet->m_column1, m_pSet);
DDX_FieldText(pDX, IDC_DEPT, m_pSet->m_column2, m_pSet);
DDX_FieldText(pDX, IDC_EMAIL, m_pSet->m_E_mail, m_pSet);
DDX_FieldText(pDX, IDC_PHONE, m_pSet->m_column3, m_pSet);
DDX_FieldText(pDX, IDC_REMARK, m_pSet->m_column4, m_pSet);
//}}AFX_DATA_MAP
}
BOOL CSample02View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CSample02View::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_Sample02Set;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CSample02View printing
BOOL CSample02View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSample02View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSample02View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CSample02View diagnostics
#ifdef _DEBUG
void CSample02View::AssertValid() const
{
CRecordView::AssertValid();
}
void CSample02View::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CSample02Doc* CSample02View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSample02Doc)));
return (CSample02Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSample02View database support
CRecordset* CSample02View::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CSample02View message handlers
void CSample02View::OnSort()
{
// 关闭记录集
m_pSet->Close();
// 指定排序字段
m_pSet->m_strSort = "ID DESC";
// 打开闭记录集
m_pSet->Open();
// 更新数据
UpdateData(FALSE);
}
void CSample02View::OnFilter()
{
// 关闭记录集
m_pSet->Close();
// 指定过滤条件
m_pSet->m_strFilter = "ID = 1";
// 打开闭记录集
m_pSet->Open();
// 更新数据
UpdateData(FALSE);
}
void CSample02View::OnInsert()
{
// 添加新记录
m_pSet->AddNew();
// 添加操作标志
m_bIsAdd = TRUE;
// 更新显示
UpdateData(FALSE);
}
void CSample02View::OnEdit()
{
// 编辑记录
m_pSet->Edit();
}
void CSample02View::OnDelete()
{
// 删除记录
m_pSet->Delete();
// 移动到下条记录
m_pSet->MoveNext();
// 判断是否到达最后一条记录
if (m_pSet->IsEOF() == TRUE)
m_pSet->MoveLast();
if (m_pSet->IsBOF() == TRUE)
m_pSet->SetFieldNull(NULL);
// 更新显示
UpdateData(FALSE);
}
BOOL CSample02View::OnMove(UINT nIDMoveCommand)
{
// 判断是否进行了记录添加操作
if (m_bIsAdd == TRUE)
{
// 标志复位
m_bIsAdd = FALSE;
// 更新显示
UpdateData(TRUE);
// 更新记录集
if (m_pSet->CanUpdate())
m_pSet->Update();
// 重建记录集
m_pSet->Requery();
// 更新显示
UpdateData(FALSE);
return TRUE;
}
return CRecordView::OnMove(nIDMoveCommand);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -