?? passwordsview.cpp
字號(hào):
// PasswordsView.cpp : implementation of the CPasswordsView class
//
#include "stdafx.h"
#include "Passwords.h"
#include "PasswordsSet.h"
#include "PasswordsDoc.h"
#include "PasswordsView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPasswordsView
IMPLEMENT_DYNCREATE(CPasswordsView, COleDBRecordView)
BEGIN_MESSAGE_MAP(CPasswordsView, COleDBRecordView)
//{{AFX_MSG_MAP(CPasswordsView)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, COleDBRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, COleDBRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, COleDBRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPasswordsView construction/destruction
CPasswordsView::CPasswordsView()
: COleDBRecordView(CPasswordsView::IDD)
{
//{{AFX_DATA_INIT(CPasswordsView)
// NOTE: the ClassWizard will add member initialization here
m_pSet = NULL;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CPasswordsView::~CPasswordsView()
{
}
void CPasswordsView::DoDataExchange(CDataExchange* pDX)
{
COleDBRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPasswordsView)
DDX_Text(pDX,IDC_EDIT1/*控件ID*/,
m_pSet->m_userid/*行集字段*/,
15/*字段長(zhǎng)度*/);
DDX_Text(pDX,IDC_EDIT2,m_pSet->m_password,10);
//}}AFX_DATA_MAP
}
BOOL CPasswordsView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return COleDBRecordView::PreCreateWindow(cs);
}
void CPasswordsView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_passwordsSet;
{
CWaitCursor wait;
HRESULT hr = m_pSet->Open();
if (hr != S_OK)
{
AfxMessageBox(_T("Record set failed to open."), MB_OK);
// Disable the Next and Previous record commands,
// since attempting to change the current record without an
// open RecordSet will cause a crash.
m_bOnFirstRecord = TRUE;
m_bOnLastRecord = TRUE;
}
}
COleDBRecordView::OnInitialUpdate();
}
/////////////////////////////////////////////////////////////////////////////
// CPasswordsView printing
BOOL CPasswordsView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CPasswordsView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CPasswordsView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CPasswordsView diagnostics
#ifdef _DEBUG
void CPasswordsView::AssertValid() const
{
COleDBRecordView::AssertValid();
}
void CPasswordsView::Dump(CDumpContext& dc) const
{
COleDBRecordView::Dump(dc);
}
CPasswordsDoc* CPasswordsView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPasswordsDoc)));
return (CPasswordsDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPasswordsView database support
CRowset* CPasswordsView::OnGetRowset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CPasswordsView message handlers
void CPasswordsView::OnButton1()
{
// 添加記錄
UpdateData(true);//將窗口數(shù)據(jù)寫(xiě)入行集
m_pSet->Insert();//使用添加數(shù)據(jù)創(chuàng)建新記錄
m_pSet->MoveLast();//使新記錄成為當(dāng)前記錄
if(m_bOnFirstRecord && m_bOnLastRecord)
{ //若以前沒(méi)有記錄,則設(shè)置記錄首和記錄尾標(biāo)志
//以便啟用記錄導(dǎo)航工具欄按鈕和菜單命令
m_bOnFirstRecord=false;
m_bOnLastRecord=false;
}
}
void CPasswordsView::OnButton2()
{
// 刪除記錄
if (MessageBox("刪除當(dāng)前記錄?",NULL,MB_YESNO)==IDYES)
{
m_pSet->Delete();//確認(rèn)刪除后,輸出當(dāng)前記錄
if(!OnMove(ID_RECORD_NEXT))//使下一條記錄成為當(dāng)前記錄
if(!OnMove(ID_RECORD_LAST))//若沒(méi)有下一條記錄,則使最后一條記錄成為當(dāng)前記錄
{
//若沒(méi)有記錄,則設(shè)置記錄首和記錄尾標(biāo)志
m_bOnFirstRecord=true;//該標(biāo)記為true,則禁止向前移動(dòng)記錄指針
m_bOnLastRecord=true;//該標(biāo)記為true,則禁止向后移動(dòng)記錄指針
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -