📄 paddressbookview.cpp
字号:
// PAddressBookView.cpp : implementation of the CPAddressBookView class
//
#include "stdafx.h"
#include "PAddressBook.h"
#include "SearchRecordDlg.h"
#include "PAddressBookSet.h"
#include "PAddressBookDoc.h"
#include "PAddressBookView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPAddressBookView
IMPLEMENT_DYNCREATE(CPAddressBookView, CRecordView)
BEGIN_MESSAGE_MAP(CPAddressBookView, CRecordView)
//{{AFX_MSG_MAP(CPAddressBookView)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel)
ON_COMMAND(ID_RECORD_ADD, OnRecordAdd)
ON_COMMAND(ID_RECORD_CLEARFIELDS, OnRecordClearfields)
ON_COMMAND(ID_RECORD_DELETE, OnRecordDelete)
ON_COMMAND(ID_RECORD_UPDATE, OnRecordUpdate)
ON_UPDATE_COMMAND_UI(ID_RECORD_UPDATE, OnUpdateRecordUpdate)
ON_UPDATE_COMMAND_UI(ID_RECORD_DELETE, OnUpdateRecordDelete)
ON_BN_CLICKED(IDC_SEARCH_RECORD, OnSearchRecord)
ON_WM_TIMER()
ON_WM_DESTROY()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CPAddressBookView construction/destruction
CPAddressBookView::CPAddressBookView()
: CRecordView(CPAddressBookView::IDD)
{
//{{AFX_DATA_INIT(CPAddressBookView)
// NOTE: the ClassWizard will add member initialization here
m_pSet = NULL;
m_bAdding=FALSE;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CPAddressBookView::~CPAddressBookView()
{
m_nRed=m_nGreen=m_nBlue=0;
}
void CPAddressBookView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
DDX_FieldText(pDX,IDC_EDIT_NAME,m_pSet->m_column1,m_pSet);
DDX_FieldText(pDX,IDC_EDIT_OFFTEL,m_pSet->m_column2,m_pSet);
DDX_FieldText(pDX,IDC_EDIT_HOMETEL,m_pSet->m_column3,m_pSet);
DDX_FieldText(pDX,IDC_EDIT_MOBTEL,m_pSet->m_column4,m_pSet);
// DDX_FieldText(pDX,IDC_EDIT_QQ,m_pSet->m_column5,m_pSet);
DDX_FieldText(pDX,IDC_EDIT_QQ,m_pSet->m_QQ_,m_pSet);
DDX_FieldText(pDX,IDC_EDIT_EMAIL,m_pSet->m_E_mail,m_pSet);
//{{AFX_DATA_MAP(CPAddressBookView)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BOOL CPAddressBookView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CPAddressBookView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_pAddressBookSet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
CView:: OnInitialUpdate();
SetTimer(0,1000,NULL);
}
/////////////////////////////////////////////////////////////////////////////
// CPAddressBookView printing
BOOL CPAddressBookView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CPAddressBookView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CPAddressBookView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CPAddressBookView diagnostics
#ifdef _DEBUG
void CPAddressBookView::AssertValid() const
{
CRecordView::AssertValid();
}
void CPAddressBookView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CPAddressBookDoc* CPAddressBookView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPAddressBookDoc)));
return (CPAddressBookDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPAddressBookView database support
CRecordset* CPAddressBookView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CPAddressBookView message handlers
void CPAddressBookView::OnButtonAdd()
{
m_pSet->AddNew();
if(UpdateData(true))
m_pSet->Update();
else
return;
m_pSet->Requery();
UpdateData(false);
}
void CPAddressBookView::OnButtonDel()
{
MessageBox("确定要删除吗?!");
m_pSet->Delete();
m_pSet->MoveNext();
if(m_pSet->IsEOF())
m_pSet->MoveLast();
UpdateData(false);
/* CRecordsetStatus status;
try {
m_pSet->Delete();
}
catch(CDBException* e) {
AfxMessageBox(e->m_strError);
e->Delete();
m_pSet->MoveFirst(); // lost our place!
UpdateData(FALSE);
}
m_pSet->GetStatus(status);
if (status.m_lCurrentRecord == 0) {
// We deleted last of 2 records
m_pSet->MoveFirst();
}
else {
m_pSet->MoveNext();
}
UpdateData(FALSE);*/
}
void CPAddressBookView::OnButtonCancel()
{
UpdateData(false);
}
void CPAddressBookView::OnRecordAdd()
{
// TODO: Add your command handler code here
m_pSet->AddNew();
m_bAdding=TRUE;
CEdit*pCtrl=(CEdit*)GetDlgItem(IDC_NAME);
int result=pCtrl->SetReadOnly(FALSE);
UpdateData(FALSE);
}
void CPAddressBookView::OnRecordClearfields()
{
// TODO: Add your command handler code here
m_pSet->SetFieldNull(NULL);
UpdateData(false);
}
void CPAddressBookView::OnRecordDelete()
{
// TODO: Add your command handler code here
/* m_pSet->Delete();
m_pSet->MoveNext();
if(m_pSet->IsEOF())
m_pSet->MoveLast();
UpdateData(false);*/
MessageBox("确定要删除吗?!");
try{
m_pSet->Delete();
}
catch (CDBException*e)
{
AfxMessageBox(e->m_strError);
e->Delete();
m_pSet->MoveFirst();
UpdateData(false);
return;
}
if(m_pSet->IsEOF())
m_pSet->MoveLast();
if(m_pSet->IsBOF())
m_pSet->SetFieldNull(NULL);
UpdateData(false);
}
void CPAddressBookView::OnRecordUpdate()
{
// TODO: Add your command handler code here
MessageBox("确定要更改吗?!");
m_pSet->Edit();
UpdateData(TRUE);
if(m_pSet->CanUpdate())
{
m_pSet->Update();
}
}
void CPAddressBookView::OnUpdateRecordUpdate(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_pSet->IsEOF());
}
void CPAddressBookView::OnUpdateRecordDelete(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_pSet->IsEOF());
}
void CPAddressBookView::OnSearchRecord()
{
CSearchRecordDlg dlg;
int result=dlg.DoModal();
if(result==IDOK)
{
CString info;
// info ="对不起,无法找到你所需要找的姓名!!!";
CString strFind;
m_pSet->MoveFirst();
/* if(m_pSet->IsEOF)
{
AfxMessageBox("此姓名不存在!");
// m_pSet.Close();
return;
}*/
while(!m_pSet->IsEOF())
{
if(m_pSet->m_column1==dlg.m_strName)
{
CString strTemp;//编辑输入信息
info+="姓 名:";
info+=m_pSet->m_column1;
info+="\n办公电话:";
info+=m_pSet->m_column2;
info+="\n家庭电话:";
info+=m_pSet->m_column3;
info+="\n移动电话:";
info+=m_pSet->m_column4;
info+="\nQQ:";
info+=m_pSet->m_QQ_;
info+="\nEmail:";
info+=m_pSet->m_E_mail;
break;
}
else
{
m_pSet->MoveNext();
}
}
MessageBox(info);
}
}
void CPAddressBookView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CRecordView::OnTimer(nIDEvent);
if(m_nRed<=205)
m_nRed+=150;
else if(m_nRed==255)
m_nRed=0;
else
m_nRed=255;
if(m_nGreen<=205)
m_nGreen+=50;
else if(m_nGreen==205)
m_nGreen=0;
else
m_nGreen=255;
if(m_nBlue<=205)
m_nBlue+=50;
else if(m_nBlue==255)
m_nBlue=0;
else
m_nBlue=255;
Invalidate();
}
void CPAddressBookView::OnDestroy()
{
CRecordView::OnDestroy();
// TODO: Add your message handler code here
KillTimer(0);
CView::OnDestroy();
}
void CPAddressBookView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
CPAddressBookDoc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
CString str ((" 欢迎来到志雄做的系统!"));
pDC->SetTextColor(RGB(m_nRed,m_nGreen,m_nBlue));
pDC->TextOut(100,10,str);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -