📄 doc_viewview.cpp
字号:
// Doc_ViewView.cpp : implementation of the CDoc_ViewView class
//
#include "stdafx.h"
#include "Doc_View.h"
#include "Doc_ViewDoc.h"
#include "Doc_ViewView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDoc_ViewView
IMPLEMENT_DYNCREATE(CDoc_ViewView, CFormView)
BEGIN_MESSAGE_MAP(CDoc_ViewView, CFormView)
//{{AFX_MSG_MAP(CDoc_ViewView)
ON_COMMAND(ID_MOVE_FIRST, OnMoveFirst)
ON_UPDATE_COMMAND_UI(ID_MOVE_FIRST, OnUpdateMoveFirst)
ON_COMMAND(ID_MOVE_LAST, OnMoveLast)
ON_UPDATE_COMMAND_UI(ID_MOVE_LAST, OnUpdateMoveLast)
ON_COMMAND(ID_MOVE_NEXT, OnMoveNext)
ON_UPDATE_COMMAND_UI(ID_MOVE_NEXT, OnUpdateMoveNext)
ON_COMMAND(ID_MOVE_PREV, OnMovePrev)
ON_UPDATE_COMMAND_UI(ID_MOVE_PREV, OnUpdateMovePrev)
ON_COMMAND(ID_REMOVE_RECORD, OnRemoveRecord)
ON_UPDATE_COMMAND_UI(ID_REMOVE_RECORD, OnUpdateRemoveRecord)
ON_COMMAND(ID_ADD_RECORD, OnAddRecord)
ON_UPDATE_COMMAND_UI(ID_ADD_RECORD, OnUpdateAddRecord)
//}}AFX_MSG_MAP
// Standard printing commands
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDoc_ViewView construction/destruction
CDoc_ViewView::CDoc_ViewView()
: CFormView(CDoc_ViewView::IDD)
{
//{{AFX_DATA_INIT(CDoc_ViewView)
m_nAge = 0;
m_strName = _T("");
m_nSex = 0;
m_strSocialNO = _T("");
//}}AFX_DATA_INIT
m_nPersonIndex = 0;
}
CDoc_ViewView::~CDoc_ViewView()
{
}
void CDoc_ViewView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDoc_ViewView)
DDX_Text(pDX, IDC_AGE_EDIT, m_nAge);
DDV_MinMaxInt(pDX, m_nAge, 0, 150);
DDX_Text(pDX, IDC_NAME_EDIT, m_strName);
DDX_Radio(pDX, IDC_SEX_RADIO, m_nSex);
DDX_Text(pDX, IDC_NO_EDIT, m_strSocialNO);
//}}AFX_DATA_MAP
}
BOOL CDoc_ViewView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CDoc_ViewView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
m_pArray = GetDocument()->GetPersonArray();
m_nPersonIndex = 0;
ShowNewData();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CDoc_ViewView printing
/////////////////////////////////////////////////////////////////////////////
// CDoc_ViewView diagnostics
#ifdef _DEBUG
void CDoc_ViewView::AssertValid() const
{
CFormView::AssertValid();
}
void CDoc_ViewView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CDoc_ViewDoc* CDoc_ViewView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDoc_ViewDoc)));
return (CDoc_ViewDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDoc_ViewView message handlers
void CDoc_ViewView::OnMoveFirst()
{
m_nPersonIndex = 0;
ShowNewData();
}
void CDoc_ViewView::OnUpdateMoveFirst(CCmdUI* pCmdUI)
{
pCmdUI->Enable( (m_nPersonIndex != 0) && (m_pArray->GetSize() >0) );
}
void CDoc_ViewView::OnMoveLast()
{
m_nPersonIndex = m_pArray->GetUpperBound();
ShowNewData();
}
void CDoc_ViewView::OnUpdateMoveLast(CCmdUI* pCmdUI)
{
pCmdUI->Enable( m_nPersonIndex < m_pArray->GetUpperBound() );
}
void CDoc_ViewView::OnMoveNext()
{
m_nPersonIndex++;
ShowNewData();
}
void CDoc_ViewView::OnUpdateMoveNext(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_nPersonIndex < m_pArray->GetUpperBound());
}
void CDoc_ViewView::OnMovePrev()
{
m_nPersonIndex--;
ShowNewData();
}
void CDoc_ViewView::OnUpdateMovePrev(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_nPersonIndex > 0);
}
void CDoc_ViewView::OnRemoveRecord()
{
CPerson* pPerson;
pPerson = m_pArray->GetAt(m_nPersonIndex);
m_pArray->RemoveAt(m_nPersonIndex);
delete pPerson;
if(m_nPersonIndex > m_pArray->GetUpperBound())
{
m_nPersonIndex = m_pArray->GetUpperBound();
}
ShowNewData();
GetDocument()->SetModifiedFlag();
GetDocument()->UpdateAllViews(this);
}
void CDoc_ViewView::OnUpdateRemoveRecord(CCmdUI* pCmdUI)
{
pCmdUI->Enable( (m_nPersonIndex < m_pArray->GetSize()) && (m_nPersonIndex >= 0) );
}
void CDoc_ViewView::OnAddRecord()
{
UpdateData(TRUE);
if( RecordExist(m_strSocialNO) == TRUE )
{
AfxMessageBox( "record with the same social number exists in the data set!");
}
else
{
CPerson* pPerson = new CPerson;
pPerson->SetAge(m_nAge);
pPerson->SetName(m_strName);
pPerson->SetSex((SEX_TYPE)m_nSex);
pPerson->SetSocialNO(m_strSocialNO);
m_pArray->Add(pPerson);
m_nPersonIndex = m_pArray->GetUpperBound();
GetDocument()->SetModifiedFlag();
GetDocument()->UpdateAllViews(this);
}
}
void CDoc_ViewView::OnUpdateAddRecord(CCmdUI* pCmdUI)
{
UpdateData(TRUE);
if( (m_strName.IsEmpty() == TRUE) || (m_strSocialNO.IsEmpty() == TRUE) )
{
pCmdUI->Enable( FALSE );
}
else
{
pCmdUI->Enable( TRUE );
}
}
void CDoc_ViewView::ShowNewData()
{
if( (m_nPersonIndex < 0) || (m_nPersonIndex > m_pArray->GetUpperBound()) )
{
m_nAge = 0;
m_nSex = 0;
m_strName.Empty();
m_strSocialNO.Empty();
}
else
{
CPerson *pCurrentPerson;
pCurrentPerson = m_pArray->GetAt(m_nPersonIndex);
m_nAge = pCurrentPerson->GetAge();
m_nSex = (int)pCurrentPerson->GetSex();
m_strName = pCurrentPerson->GetName();
m_strSocialNO = pCurrentPerson->GetSocialNO();
}
UpdateData(FALSE);
}
void CDoc_ViewView::GetNewData()
{
UpdateData(TRUE);
}
BOOL CDoc_ViewView::RecordExist(CString strSocialNO)
{
BOOL bExist;
int nIndex,nCount;
CPerson* pPerson;
nIndex = 0;
nCount = m_pArray->GetSize();
bExist = FALSE;
while( (nIndex < nCount) && (bExist == FALSE) )
{
pPerson = m_pArray->GetAt(nIndex);
if( strSocialNO.CompareNoCase(pPerson->GetSocialNO()) == 0 )
{
bExist = TRUE;
}
nIndex++;
}
return bExist;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -