home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c08 / where / bibview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  3.7 KB  |  156 lines

  1. // BiblioView.cpp : implementation of the CBiblioView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Biblio.h"
  6. #include "QueryDlg.h"
  7. #include "BibSet.h"
  8. #include "BibDoc.h"
  9. #include "BibView.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CBiblioView
  19.  
  20. IMPLEMENT_DYNCREATE(CBiblioView, CDaoRecordView)
  21.  
  22. BEGIN_MESSAGE_MAP(CBiblioView, CDaoRecordView)
  23.     //{{AFX_MSG_MAP(CBiblioView)
  24.     ON_COMMAND(ID_RECORD_QUERY, OnRecordQuery)
  25.     ON_UPDATE_COMMAND_UI(ID_RECORD_QUERY, OnUpdateRecordQuery)
  26.     //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CBiblioView construction/destruction
  31.  
  32. CBiblioView::CBiblioView()
  33.     : CDaoRecordView(CBiblioView::IDD)
  34. {
  35.     //{{AFX_DATA_INIT(CBiblioView)
  36.     m_pSet = NULL;
  37.     //}}AFX_DATA_INIT
  38.     // TODO: add construction code here
  39.  
  40. }
  41.  
  42. CBiblioView::~CBiblioView()
  43. {
  44. }
  45.  
  46. void CBiblioView::DoDataExchange(CDataExchange* pDX)
  47. {
  48.     CDaoRecordView::DoDataExchange(pDX);
  49.     //{{AFX_DATA_MAP(CBiblioView)
  50.     DDX_FieldText(pDX, IDC_TITLE, m_pSet->m_Title, m_pSet);
  51.     DDX_FieldText(pDX, IDC_ISBN, m_pSet->m_ISBN, m_pSet);
  52.     DDX_FieldText(pDX, IDC_YEAR_PUBLISHED, m_pSet->m_Year_Published, m_pSet);
  53.     DDX_FieldText(pDX, IDC_SUBJECT, m_pSet->m_Subject, m_pSet);
  54.     DDX_FieldText(pDX, IDC_NOTES, m_pSet->m_Notes, m_pSet);
  55.     DDX_FieldText(pDX, IDC_COMMENTS, m_pSet->m_Comments, m_pSet);
  56.     DDX_FieldText(pDX, IDC_DESCRIPTION, m_pSet->m_Description, m_pSet);
  57.     DDX_FieldText(pDX, IDC_PUBID, m_pSet->m_PubID, m_pSet);
  58.     //}}AFX_DATA_MAP
  59. }
  60.  
  61. BOOL CBiblioView::PreCreateWindow(CREATESTRUCT& cs)
  62. {
  63.     // TODO: Modify the Window class or styles here by modifying
  64.     //  the CREATESTRUCT cs
  65.  
  66.     return CDaoRecordView::PreCreateWindow(cs);
  67. }
  68.  
  69. void CBiblioView::OnInitialUpdate()
  70. {
  71.     m_pSet = &GetDocument()->m_biblioSet;
  72.  
  73.     CDaoRecordView::OnInitialUpdate();
  74.  
  75.     GetParentFrame()->RecalcLayout();
  76.     ResizeParentToFit();
  77. }
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CBiblioView diagnostics
  81.  
  82. #ifdef _DEBUG
  83. void CBiblioView::AssertValid() const
  84. {
  85.     CDaoRecordView::AssertValid();
  86. }
  87.  
  88. void CBiblioView::Dump(CDumpContext& dc) const
  89. {
  90.     CDaoRecordView::Dump(dc);
  91. }
  92.  
  93. CBiblioDoc* CBiblioView::GetDocument() // non-debug version is inline
  94. {
  95.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBiblioDoc)));
  96.     return (CBiblioDoc*)m_pDocument;
  97. }
  98. #endif //_DEBUG
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CBiblioView database support
  102. CDaoRecordset* CBiblioView::OnGetRecordset()
  103. {
  104.     return m_pSet;
  105. }
  106.  
  107.  
  108. /////////////////////////////////////////////////////////////////////////////
  109. // CBiblioView message handlers
  110.  
  111. void CBiblioView::OnRecordQuery() 
  112. {
  113.     ASSERT(m_pSet->IsOpen());
  114.  
  115.     CQueryDlg dlg;
  116.  
  117.     dlg.m_strWhere = m_pSet->m_strFilter;
  118.     dlg.m_pSet = m_pSet;
  119.     if(IDOK == dlg.DoModal())
  120.     {
  121.         m_pSet->m_strFilter = dlg.m_strWhere;
  122.         try
  123.         {
  124.             m_pSet->Requery();
  125.  
  126.             if (m_pSet->IsEOF())
  127.             {
  128.                 // Recordset is empty. Set the current record to NON-NULL
  129.                 m_pSet->SetFieldNull(NULL, FALSE);
  130.             }
  131.             else
  132.             {
  133.                 // Move to the first record is the recordset is NOT empty
  134.                 m_pSet->MoveFirst();
  135.             }
  136.             UpdateData(FALSE);
  137.         }
  138.         catch(CDaoException* e)
  139.         {
  140.             MessageBox(e->m_pErrorInfo->m_strDescription);
  141.             e->Delete();
  142.         }
  143.         catch(CMemoryException* e)
  144.         {
  145.             MessageBox("Memory Exception Occurred");
  146.             e->Delete();
  147.         }
  148.     }
  149. }
  150.  
  151. void CBiblioView::OnUpdateRecordQuery(CCmdUI* pCmdUI) 
  152. {
  153.     // Allow requery is the recordset is open AND can restart
  154.     pCmdUI->Enable(m_pSet->IsOpen() && m_pSet->CanRestart());
  155. }
  156.