exam9_1view.cpp

来自「This is Visual C++ basis operation. Usin」· C++ 代码 · 共 172 行

CPP
172
字号
// Exam9_1View.cpp : implementation of the CExam9_1View class
//

#include "stdafx.h"
#include "Exam9_1.h"

#include "Exam9_1Set.h"
#include "Exam9_1Doc.h"
#include "Exam9_1View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CExam9_1View

IMPLEMENT_DYNCREATE(CExam9_1View, CRecordView)

BEGIN_MESSAGE_MAP(CExam9_1View, CRecordView)
	//{{AFX_MSG_MAP(CExam9_1View)
	ON_COMMAND(ID_RECORD_ADD, OnRecordAdd)
	ON_COMMAND(ID_RECORD_DELECT, OnRecordDelect)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CExam9_1View construction/destruction

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

CExam9_1View::~CExam9_1View()
{
}

void CExam9_1View::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CExam9_1View)
	DDX_FieldText(pDX, IDC_Comments, m_pSet->m_Comments, m_pSet);
	DDX_FieldText(pDX, IDC_CustomerID, m_pSet->m_CustomerID, m_pSet);
	DDX_FieldText(pDX, IDC_FirstName, m_pSet->m_FirstName, m_pSet);
	DDX_FieldText(pDX, IDC_HomeCountry, m_pSet->m_HomeCountry, m_pSet);
	DDX_FieldText(pDX, IDC_LastName, m_pSet->m_LastName, m_pSet);
	DDX_FieldText(pDX, IDC_PhoneCall, m_pSet->m_PhoneNumber, m_pSet);
	//}}AFX_DATA_MAP
}

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

	return CRecordView::PreCreateWindow(cs);
}

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

}

/////////////////////////////////////////////////////////////////////////////
// CExam9_1View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CExam9_1View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CExam9_1View database support
CRecordset* CExam9_1View::OnGetRecordset()
{
	return m_pSet;
}


/////////////////////////////////////////////////////////////////////////////
// CExam9_1View message handlers

void CExam9_1View::OnRecordAdd() 
{
	// TODO: Add your command handler code here
	m_pSet->AddNew();   //进入添加模式
	m_addflg=true;    //设置添加模式标志	
	CEdit* m_pCtrl=(CEdit*)GetDlgItem(IDC_CustomerID);
	m_pCtrl->SetReadOnly(false); //清除ID编辑框的只读属性
	UpdateData(false);   //用新记录的字段数据成员值更新控件显示
}

void CExam9_1View::OnRecordDelect() 
{
	// 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);//更新控件显示
}

BOOL CExam9_1View::OnMove(UINT nIDMoveCommand) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(m_addflg)//添加模式处理
	{
		m_addflg=false;
		UpdateData(true);//使用控件值更新记录集字段数据成员
		if(m_pSet->CanUpdate() )//将记录集更新保存到表中		
		m_pSet->Update();
		m_pSet->Requery();//重新查询记录集
		UpdateData(false);//以更新后的记录集数据成员更新控件显示
		CEdit* m_pCtrl=(CEdit*)GetDlgItem(IDC_CustomerID);	
		m_pCtrl->SetReadOnly(true); //设置ID编辑框为只读
		return true;
	}
		else
	
	return CRecordView::OnMove(nIDMoveCommand);
}

⌨️ 快捷键说明

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