BOOL CRecordView::IsOnFirstRecord() { ASSERT_VALID(this); CRecordsetStatus status; OnGetRecordset()->GetStatus(status); return status.m_lCurrentRecord == 0; }
void CRecordView::OnUpdateRecordLast(CCmdUI* pCmdUI) { CRecordset* prs = OnGetRecordset(); // enable if opened, can scroll, pCmdUI->Enable(prs->IsOpen() && prs->CanScroll() && // >= 1 records present and not already on last record !(prs->IsEOF() && prs->IsBOF()) && !IsOnLastRecord()); }
void CRecordView::OnUpdateRecordNext(CCmdUI* pCmdUI) { CRecordset* prs = OnGetRecordset(); // enable if opened and >= 1 records present pCmdUI->Enable(prs->IsOpen() && !(prs->IsEOF() && prs->IsBOF()) // and not already on last record && !IsOnLastRecord()); }
BOOL CRecordView::IsOnLastRecord() { ASSERT_VALID(this); CRecordset* pRecordset = OnGetRecordset(); CRecordsetStatus status; pRecordset->GetStatus(status); if (!status.m_bRecordCountFinal) return FALSE; return ((status.m_lCurrentRecord+1 == pRecordset->GetRecordCount())); }
void CRecordView::OnInitialUpdate() { CRecordset* pRecordset = OnGetRecordset(); // recordset must be allocated already ASSERT(pRecordset != NULL); if (!pRecordset->IsOpen()) { CWaitCursor wait; pRecordset->Open(); } CFormView::OnInitialUpdate(); }
void CDaoRecordView::OnInitialUpdate() { ASSERT_VALID(this); CDaoRecordset* pRecordset = OnGetRecordset(); // recordset must be allocated already ASSERT(pRecordset != NULL); if (!pRecordset->IsOpen()) { CWaitCursor wait; pRecordset->Open(); } if (!pRecordset->IsEOF()) { // Determine recordset properties for move button enabling if (pRecordset->CanBookmark()) { // Get the bookmark of the first record m_varBookmarkCurrent = pRecordset->GetBookmark(); m_varBookmarkFirst = m_varBookmarkCurrent; } // Enable forward scrolling buttons m_nStatus |= AFX_DAOVIEW_SCROLL_NEXT; // Enable backward scrolling buttons if possible if (pRecordset->CanScroll()) { m_nStatus |= AFX_DAOVIEW_SCROLL_LAST; m_nStatus |= AFX_DAOVIEW_SCROLL_BACKWARD; } else { m_nStatus &= ~AFX_DAOVIEW_SCROLL_LAST; m_nStatus &= ~AFX_DAOVIEW_SCROLL_BACKWARD; } } else { // Disable scrolling m_nStatus &= ~AFX_DAOVIEW_SCROLL_NEXT; m_nStatus &= ~AFX_DAOVIEW_SCROLL_LAST; m_nStatus &= ~AFX_DAOVIEW_SCROLL_BACKWARD; } CFormView::OnInitialUpdate(); }
BOOL CRecordView::OnMove(UINT nIDMoveCommand) { CRecordset* pSet = OnGetRecordset(); if (pSet->CanUpdate() && !pSet->IsDeleted()) { pSet->Edit(); if (!UpdateData()) return TRUE; pSet->Update(); } switch (nIDMoveCommand) { case ID_RECORD_PREV: pSet->MovePrev(); if (!pSet->IsBOF()) break; case ID_RECORD_FIRST: pSet->MoveFirst(); break; case ID_RECORD_NEXT: pSet->MoveNext(); if (!pSet->IsEOF()) break; if (!pSet->CanScroll()) { // clear out screen since we're sitting on EOF pSet->SetFieldNull(NULL); break; } case ID_RECORD_LAST: pSet->MoveLast(); break; default: // Unexpected case value ASSERT(FALSE); } // Show results of move operation UpdateData(FALSE); return TRUE; }
BOOL CDaoRecordView::OnMove(UINT nIDMoveCommand) { ASSERT_VALID(this); CDaoRecordset* pSet = OnGetRecordset(); if (pSet->CanUpdate()) { pSet->Edit(); if (!UpdateData()) return TRUE; pSet->Update(); } BOOL bBookmarkable = pSet->CanBookmark(); BOOL bScrollable = pSet->CanScroll(); switch (nIDMoveCommand) { case ID_RECORD_PREV: pSet->MovePrev(); if (!pSet->IsBOF()) { if (bBookmarkable) m_varBookmarkCurrent = pSet->GetBookmark(); // Enable forward scrolling m_nStatus |= AFX_DAOVIEW_SCROLL_NEXT; if (bScrollable) { m_nStatus |= AFX_DAOVIEW_SCROLL_LAST; if (IsOnFirstRecord()) // Disable backward scrolling m_nStatus &= ~AFX_DAOVIEW_SCROLL_BACKWARD; else m_nStatus |= AFX_DAOVIEW_SCROLL_BACKWARD; } else { m_nStatus &= ~AFX_DAOVIEW_SCROLL_LAST; m_nStatus &= ~AFX_DAOVIEW_SCROLL_BACKWARD; } break; } // Fall through to reset to first record case ID_RECORD_FIRST: pSet->MoveFirst(); // backward scrolling never allowed after movefirst m_nStatus &= ~AFX_DAOVIEW_SCROLL_BACKWARD; if (pSet->IsEOF()) { // Empty recordset, disable forward too m_nStatus &= ~AFX_DAOVIEW_SCROLL_NEXT; m_nStatus &= ~AFX_DAOVIEW_SCROLL_LAST; } else { if (bBookmarkable) { m_varBookmarkCurrent = pSet->GetBookmark(); m_varBookmarkFirst = m_varBookmarkCurrent; } // Enable forward scrolling m_nStatus |= AFX_DAOVIEW_SCROLL_NEXT; if (bScrollable) m_nStatus |= AFX_DAOVIEW_SCROLL_LAST; else m_nStatus &= ~AFX_DAOVIEW_SCROLL_LAST; } break; case ID_RECORD_NEXT: pSet->MoveNext(); if (!pSet->IsEOF()) { if (bBookmarkable) m_varBookmarkCurrent = pSet->GetBookmark(); if (IsOnLastRecord()) { // Disable forward scrolling m_nStatus &= ~AFX_DAOVIEW_SCROLL_NEXT; m_nStatus &= ~AFX_DAOVIEW_SCROLL_LAST; } else { m_nStatus |= AFX_DAOVIEW_SCROLL_NEXT; m_nStatus |= AFX_DAOVIEW_SCROLL_LAST; } if (bScrollable) m_nStatus |= AFX_DAOVIEW_SCROLL_BACKWARD; else { m_nStatus &= ~AFX_DAOVIEW_SCROLL_LAST; m_nStatus &= ~AFX_DAOVIEW_SCROLL_BACKWARD; } break; } // Can't fall through to move last if (!bScrollable) { // At the end of forward only recordset m_nStatus &= ~AFX_DAOVIEW_SCROLL_NEXT; m_nStatus &= ~AFX_DAOVIEW_SCROLL_LAST; m_nStatus &= ~AFX_DAOVIEW_SCROLL_BACKWARD; break; } // Fall through to reset to last record case ID_RECORD_LAST: pSet->MoveLast(); // forward scrolling never allowed after movelast m_nStatus &= ~AFX_DAOVIEW_SCROLL_NEXT; m_nStatus &= ~AFX_DAOVIEW_SCROLL_LAST; if (pSet->IsBOF()) { // Empty recordset, disable backward too m_nStatus &= ~AFX_DAOVIEW_SCROLL_BACKWARD; } else { if (bBookmarkable) { m_varBookmarkCurrent = pSet->GetBookmark(); m_varBookmarkLast = m_varBookmarkCurrent; } // Enable backward scrolling if (bBookmarkable) m_nStatus |= AFX_DAOVIEW_SCROLL_BACKWARD; else m_nStatus &= ~AFX_DAOVIEW_SCROLL_BACKWARD; } break; default: // Unexpected case value ASSERT(FALSE); } // Show results of move operation UpdateData(FALSE); return TRUE; }
CCustomerSet* CCustomerView::GetRecordset() { return static_cast<CCustomerSet*>(OnGetRecordset()); }