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

📄 ex_addressview.cpp

📁 一系列的c++例子 一步一步由浅入深 有 聊天室
💻 CPP
字号:
// Ex_AddressView.cpp : implementation of the CEx_AddressView class
//

#include "stdafx.h"
#include "Ex_Address.h"

#include "Ex_AddressSet.h"
#include "Ex_AddressDoc.h"
#include "Ex_AddressView.h"
#include "PersonDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEx_AddressView

IMPLEMENT_DYNCREATE(CEx_AddressView, CRecordView)

BEGIN_MESSAGE_MAP(CEx_AddressView, CRecordView)
	//{{AFX_MSG_MAP(CEx_AddressView)
	ON_BN_CLICKED(IDC_BUTTON_QRERY, OnButtonQrery)
	ON_BN_CLICKED(IDC_REC_ADD, OnRecAdd)
	ON_BN_CLICKED(IDC_REC_DEL, OnRecDel)
	ON_BN_CLICKED(IDC_REC_EDIT, OnRecEdit)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CEx_AddressView construction/destruction

CEx_AddressView::CEx_AddressView()
	: CRecordView(CEx_AddressView::IDD)
{
	//{{AFX_DATA_INIT(CEx_AddressView)
	m_pSet = NULL;
	m_strQuery = _T("");
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CEx_AddressView::~CEx_AddressView()
{
}

void CEx_AddressView::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEx_AddressView)
	DDX_Text(pDX, IDC_EDIT_QUERY, m_strQuery);
	DDX_FieldText(pDX, IDC_EDIT_ADDRESS, m_pSet->m_address, m_pSet);
	DDV_MaxChars(pDX, m_pSet->m_address, 10);
	DDX_FieldText(pDX, IDC_EDIT_MAIL, m_pSet->m_email, m_pSet);
	DDX_FieldText(pDX, IDC_EDIT_NAME, m_pSet->m_name, m_pSet);
	DDX_FieldText(pDX, IDC_EDIT_TYPE, m_pSet->m_type, m_pSet);
	//}}AFX_DATA_MAP
}

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

	return CRecordView::PreCreateWindow(cs);
}

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

}

/////////////////////////////////////////////////////////////////////////////
// CEx_AddressView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CEx_AddressView diagnostics

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

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

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

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


/////////////////////////////////////////////////////////////////////////////
// CEx_AddressView message handlers

void CEx_AddressView::OnButtonQrery() 
{

	UpdateData();
	m_strQuery.TrimLeft();
   if(m_strQuery.IsEmpty())
   {
     MessageBox("姓名不能为空!");
      return;
   }
  if(m_pSet->IsOpen())
    m_pSet->Close();
    m_pSet->m_strFilter.Format("name='%s'",m_strQuery);
  
    m_pSet->Open();
    if(!m_pSet->IsEOF())
     UpdateData(FALSE);
    else
   MessageBox("没有找到你要的记录!");
}

void CEx_AddressView::OnRecAdd() 
{
  CPersonDlg  dlg;
  if(dlg.DoModal()==IDOK)
  {
   m_pSet->AddNew();
   m_pSet->m_address=dlg.m_strAddress;
   m_pSet->m_email=dlg.m_strMail;
   m_pSet->m_name=dlg.m_strName;
   m_pSet->m_type=dlg.m_strType;
   m_pSet->Update();
   m_pSet->Requery();
  }
	
}

void CEx_AddressView::OnRecDel() 
{
	CRecordsetStatus status;
	m_pSet->GetStatus(status);
	m_pSet->Delete();
	if(status.m_lCurrentRecord==0)
	    m_pSet->MoveNext();
	else
		m_pSet->MoveFirst();
   UpdateData(false);
}

void CEx_AddressView::OnRecEdit() 
{
  CPersonDlg  dlg;
   dlg.m_strAddress=m_pSet->m_address;
   dlg.m_strMail=m_pSet->m_email;
   dlg.m_strName=m_pSet->m_name;
   dlg.m_strType=m_pSet->m_type;
  if(dlg.DoModal()==IDOK)
  {
   m_pSet->Edit();
   m_pSet->m_address=dlg.m_strAddress;
   m_pSet->m_email=dlg.m_strMail;
   m_pSet->m_name=dlg.m_strName;
   m_pSet->m_type=dlg.m_strType;
   m_pSet->Update();
   UpdateData(false);
  }
}

⌨️ 快捷键说明

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