www.pudn.com > VC++practise.rar > DateBaseView.cpp
// DateBaseView.cpp : implementation of the CDateBaseView class
//
#include "stdafx.h"
#include "DateBase.h"
#include "DateBaseSet.h"
#include "DateBaseDoc.h"
#include "DateBaseView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDateBaseView
IMPLEMENT_DYNCREATE(CDateBaseView, CRecordView)
BEGIN_MESSAGE_MAP(CDateBaseView, CRecordView)
//{{AFX_MSG_MAP(CDateBaseView)
ON_COMMAND(IDM_RECORD_NEW, OnRecordNew)
ON_COMMAND(IDM_RECORD_DELETE, OnRecordDelete)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CDateBaseView construction/destruction
CDateBaseView::CDateBaseView()
: CRecordView(CDateBaseView::IDD)
{
//{{AFX_DATA_INIT(CDateBaseView)
m_pSet = NULL;
m_oledtDOB = COleDateTime::GetCurrentTime();
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CDateBaseView::~CDateBaseView()
{
}
void CDateBaseView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
if(pDX->m_bSaveAndValidate==FALSE)
m_oledtDOB=m_pSet->m_Birthday;
//{{AFX_DATA_MAP(CDateBaseView)
DDX_FieldCheck(pDX, IDC_CBCARD, m_pSet->m_PostalCard, m_pSet);
DDX_FieldText(pDX, IDC_EADDR, m_pSet->m_Address, m_pSet);
DDX_FieldText(pDX, IDC_ECITY, m_pSet->m_City_county, m_pSet);
DDX_FieldText(pDX, IDC_ECOUNTRY, m_pSet->m_Country, m_pSet);
DDX_FieldText(pDX, IDC_EEMAIL, m_pSet->m_E_mail, m_pSet);
DDX_FieldText(pDX, IDC_EFAX, m_pSet->m_Fax, m_pSet);
DDX_FieldText(pDX, IDC_EFNAME, m_pSet->m_First_Name, m_pSet);
DDX_FieldText(pDX, IDC_EHPHONE, m_pSet->m_HomePhone, m_pSet);
DDX_FieldText(pDX, IDC_EID, m_pSet->m_AddressID, m_pSet);
DDX_FieldText(pDX, IDC_ELNAME, m_pSet->m_Last_Name, m_pSet);
DDX_FieldText(pDX, IDC_ENOTES, m_pSet->m_Notes, m_pSet);
DDX_FieldText(pDX, IDC_ESNAME, m_pSet->m_SpouseName, m_pSet);
DDX_FieldText(pDX, IDC_ESTATE, m_pSet->m_Province, m_pSet);
DDX_FieldText(pDX, IDC_EWPHONE, m_pSet->m_WorkPhone, m_pSet);
DDX_FieldText(pDX, IDC_EZIP, m_pSet->m_Zip, m_pSet);
DDX_Text(pDX, IDC_EDOB, m_oledtDOB);
//}}AFX_DATA_MAP
if(pDX->m_bSaveAndValidate==TRUE)
m_pSet->m_Birthday=m_oledtDOB;
}
BOOL CDateBaseView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CDateBaseView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_dateBaseSet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CDateBaseView printing
BOOL CDateBaseView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDateBaseView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDateBaseView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDateBaseView diagnostics
#ifdef _DEBUG
void CDateBaseView::AssertValid() const
{
CRecordView::AssertValid();
}
void CDateBaseView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CDateBaseDoc* CDateBaseView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDateBaseDoc)));
return (CDateBaseDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDateBaseView database support
CRecordset* CDateBaseView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CDateBaseView message handlers
void CDateBaseView::OnRecordNew()
{
// TODO: Add your command handler code here
CRecordset *pSet=OnGetRecordset();
if(pSet->CanUpdate()&&!pSet->IsDeleted ())
{
pSet->Edit();
if(!UpdateData())
return;
pSet->Update();
}
long m_lNewID=m_pSet->GetMaxID()+1;
m_pSet->AddNew();
m_pSet->m_AddressID=m_lNewID;
m_pSet->Update();
m_pSet->Requery();
m_pSet->MoveLast();
UpdateData(FALSE);
}
void CDateBaseView::OnRecordDelete()
{
// TODO: Add your command handler code here
if(MessageBox("你确定删除这条记录吗?","删除?",
MB_YESNO|MB_ICONQUESTION)==IDYES)
{
m_pSet->Delete();
m_pSet->MovePrev();
UpdateData();
}
}