【VC开源代码栏目提醒】:网学会员鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“通讯录View.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_APPENDRECORD, OnAppendrecord)
ON_BN_CLICKED(IDC_DELETERECORD, OnDeleterecord)
ON_BN_CLICKED(IDC_EDITRECORD, OnEditrecord)
//}}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
m_IP = FALSE;
}
CMyView::~CMyView()
{
}
void CMyView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyView)
DDX_FieldText(pDX, IDC_ADDRESS, m_pSet->m_address, m_pSet);
DDX_FieldText(pDX, IDC_AGE, m_pSet->m_age, m_pSet);
DDX_FieldText(pDX, IDC_COMPANY, m_pSet->m_company, m_pSet);
DDX_FieldText(pDX, IDC_EMAIL, m_pSet->m_email, m_pSet);
DDX_FieldText(pDX, IDC_MOBILE, m_pSet->m_mobile, m_pSet);
DDX_FieldText(pDX, IDC_NAME, m_pSet->m_name, m_pSet);
DDX_FieldText(pDX, IDC_PAGER, m_pSet->m_pager, m_pSet);
DDX_FieldText(pDX, IDC_POSITION, m_pSet->m_position, m_pSet);
DDX_FieldText(pDX, IDC_SEX, m_pSet->m_sex, m_pSet);
DDX_FieldText(pDX, IDC_TELEPHON, m_pSet->m_telphone, m_pSet);
DDX_FieldText(pDX, IDC_RELATION, m_pSet->m_friendship, 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::OnAppendrecord()
{
// TODO: Add your control notification handler code here
if (m_IP)
OnMove(ID_RECORD_FIRST);
try
{
m_pSet->AddNew();
}
catch(CDBException* e)
{
AfxMessageBox(e->m_strError);
e->Delete();
}
m_IP = TRUE;
UpdateData(FALSE);
}
void CMyView::OnDeleterecord()
{
// TODO: Add your control notification handler code here
try
{
m_pSet->Delete();
}
catch(CDBException* e)
{
AfxMessageBox(e->m_strError);
e->Delete();
}
// END_CATCH
m_pSet->MoveNext();
if (m_pSet->IsEOF())
m_pSet->MoveLast();
if (m_pSet->IsBOF())
m_pSet->SetFieldNull(NULL);
UpdateData(FALSE);
}
void CMyView::OnEditrecord()
{
// TODO: Add your control notification handler code here
if (m_IP == TRUE)
{
m_pS