⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 实例view.cpp

📁 本程序是一个数据库开发应用程序,实用于初学者,是一个很不错的例子
💻 CPP
字号:
// 实例View.cpp : implementation of the CMyView class
//

#include "stdafx.h"
#include "实例.h"

#include "实例Set.h"
#include "实例Doc.h"
#include "实例View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyView

IMPLEMENT_DYNCREATE(CMyView, CRecordView)

BEGIN_MESSAGE_MAP(CMyView, CRecordView)
	//{{AFX_MSG_MAP(CMyView)
	ON_BN_CLICKED(IDC_RECORD_FIRST, OnRecordFirst)
	ON_BN_CLICKED(IDC_RECORD_LAST, OnRecordLast)
	ON_BN_CLICKED(IDC_RECORD_NEXT, OnRecordNext)
	ON_BN_CLICKED(IDC_RECORD_PRE, OnRecordPre)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction

CMyView::CMyView()
	: CRecordView(CMyView::IDD)
{
	//{{AFX_DATA_INIT(CMyView)
	m_pSet = NULL;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CMyView::~CMyView()
{
}

void CMyView::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyView)
	DDX_FieldText(pDX, IDC_EDIT1, m_pSet->m_ID, m_pSet);
	DDX_FieldText(pDX, IDC_EDIT2, m_pSet->m_Name, m_pSet);
	DDX_FieldText(pDX, IDC_EDIT3, m_pSet->m_GradYear, m_pSet);
	//}}AFX_DATA_MAP
}

BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CRecordView::PreCreateWindow(cs);
}

void CMyView::OnInitialUpdate()
{
	m_pSet = &GetDocument()->m_mySet;
	CRecordView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CMyView printing

BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics

#ifdef _DEBUG
void CMyView::AssertValid() const
{
	CRecordView::AssertValid();
}

void CMyView::Dump(CDumpContext& dc) const
{
	CRecordView::Dump(dc);
}

CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
	return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyView database support

CRecordset* CMyView::OnGetRecordset()
{
	return m_pSet;
}


/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers

//移动到第一个记录
void CMyView::OnRecordFirst() 
{
	// TODO: Add your control notification handler code here

	//判断是否为空
	if(m_pSet->IsBOF())
	{
		m_pSet->SetFieldNull(NULL);
	}
	else
	{
	    m_pSet->MoveFirst();
	    UpdateData(FALSE);//更新对话框窗口
	}	
	
}

//移动到最后一个记录
void CMyView::OnRecordLast() 
{
	// TODO: Add your control notification handler code here
	m_pSet->MoveLast();
	UpdateData(FALSE);//更新对话框窗口

}

//移动到下一个记录
void CMyView::OnRecordNext() 
{
	// TODO: Add your control notification handler code here
	if(m_pSet->IsBOF())
	{
		m_pSet->SetFieldNull(NULL);
	}
	//判断是否溢出
    if(m_pSet->IsEOF())
	{
		AfxMessageBox("已经到达最后记录");
	}
	else
	{
		m_pSet->MoveNext();
	}
	UpdateData(FALSE);
	
}

//移动到上一个记录
void CMyView::OnRecordPre() 
{
	// TODO: Add your control notification handler code here
	if(m_pSet->IsBOF())
	{
		AfxMessageBox("已经到达第一个记录");
	}
	m_pSet->MovePrev();
	UpdateData(FALSE);
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -