home *** CD-ROM | disk | FTP | other *** search
- // QueryDefView.cpp : implementation of the CQueryDefView class
- //
-
- #include "stdafx.h"
- #include "QueryDef.h"
- #include "QDefYDlg.h"
- #include "QDefSet.h"
- #include "QDefDoc.h"
- #include "QDefView.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CQueryDefView
-
- IMPLEMENT_DYNCREATE(CQueryDefView, CDaoRecordView)
-
- BEGIN_MESSAGE_MAP(CQueryDefView, CDaoRecordView)
- //{{AFX_MSG_MAP(CQueryDefView)
- ON_COMMAND(ID_QUERYDEF_CREATE, OnQuerydefCreate)
- ON_COMMAND(ID_QUERYDEF_EXECUTE, OnQuerydefExecute)
- ON_UPDATE_COMMAND_UI(ID_QUERYDEF_EXECUTE, OnUpdateQuerydefExecute)
- ON_COMMAND(ID_QUERYDEF_REMOVE, OnQuerydefRemove)
- ON_UPDATE_COMMAND_UI(ID_QUERYDEF_REMOVE, OnUpdateQuerydefRemove)
- ON_UPDATE_COMMAND_UI(ID_QUERYDEF_CREATE, OnUpdateQuerydefCreate)
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CQueryDefView construction/destruction
-
- CQueryDefView::CQueryDefView()
- : CDaoRecordView(CQueryDefView::IDD)
- {
- //{{AFX_DATA_INIT(CQueryDefView)
- m_pSet = NULL;
- //}}AFX_DATA_INIT
- // TODO: add construction code here
- m_pQueryDef = NULL;
- m_nYear = 1994;
- }
-
- CQueryDefView::~CQueryDefView()
- {
- }
-
- void CQueryDefView::DoDataExchange(CDataExchange* pDX)
- {
- CDaoRecordView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CQueryDefView)
- DDX_FieldText(pDX, IDC_TITLE, m_pSet->m_Title, m_pSet);
- DDX_FieldText(pDX, IDC_ISBN, m_pSet->m_ISBN, m_pSet);
- DDX_FieldText(pDX, IDC_YEAR_PUBLISHED, m_pSet->m_Year_Published, m_pSet);
- DDX_FieldText(pDX, IDC_SUBJECT, m_pSet->m_Subject, m_pSet);
- DDX_FieldText(pDX, IDC_NOTES, m_pSet->m_Notes, m_pSet);
- DDX_FieldText(pDX, IDC_COMMENTS, m_pSet->m_Comments, m_pSet);
- DDX_FieldText(pDX, IDC_DESCRIPTION, m_pSet->m_Description, m_pSet);
- DDX_FieldText(pDX, IDC_PUBID, m_pSet->m_PubID, m_pSet);
- //}}AFX_DATA_MAP
- }
-
- BOOL CQueryDefView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return CDaoRecordView::PreCreateWindow(cs);
- }
-
- void CQueryDefView::OnInitialUpdate()
- {
- m_pSet = &GetDocument()->m_queryDefSet;
- CDaoRecordView::OnInitialUpdate();
-
- GetParentFrame()->RecalcLayout();
- ResizeParentToFit();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CQueryDefView diagnostics
-
- #ifdef _DEBUG
- void CQueryDefView::AssertValid() const
- {
- CDaoRecordView::AssertValid();
- }
-
- void CQueryDefView::Dump(CDumpContext& dc) const
- {
- CDaoRecordView::Dump(dc);
- }
-
- CQueryDefDoc* CQueryDefView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CQueryDefDoc)));
- return (CQueryDefDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CQueryDefView database support
- CDaoRecordset* CQueryDefView::OnGetRecordset()
- {
- return m_pSet;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CQueryDefView message handlers
-
- void CQueryDefView::OnQuerydefCreate()
- {
- // This is a fixed query that allows the user to specify a date for
- // viewing the titles in the database
- // Create the PARAMETERS string
- CString strParam = "PARAMETERS [Year Desired] Integer; ";
- // Create the query definition prefixing it with the PARAMETERS string
- CString strSQL = strParam + "SELECT * FROM Titles WHERE "
- "[Year Published] = [Year Desired]";
-
- // Create a QueryDef object using the database from the recordset
- m_pQueryDef = new CDaoQueryDef(m_pSet->m_pDatabase);
-
- // Create the underlying QueryDef object and give it a name. Because this
- // is to be a temporary object, the name will be NULL.
-
- m_pQueryDef->Create(NULL, strSQL);
- // To make this QueryDef persistent, you would call Append to add
- // it to the database's collection. Not calling CDaoQueryDef.Append
- // allows it to be used as a temporary object
- //m_pQueryDef->Append();
- }
-
- void CQueryDefView::OnUpdateQuerydefCreate(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!m_pQueryDef);
- }
-
- void CQueryDefView::OnQuerydefExecute()
- {
- // Execute the QueryDef for the desired year
- ASSERT(m_pQueryDef->IsOpen());
-
- CQDYearDlg dlg;
- dlg.m_nYear = m_nYear;
- if(IDOK == dlg.DoModal())
- {
- // Get the desired year
- m_nYear = dlg.m_nYear;
-
- // Set the QueryDef's parameter values. Note that you pass it as
- // a COleVariant.
- m_pQueryDef->SetParamValue("[Year Desired]", COleVariant(m_nYear));
-
- // Close and reopen the recordset based upon the QueryDef and new
- // parameter.
- m_pSet->Close();
- m_pSet->Open(m_pQueryDef, dbOpenDynaset);
-
- if(m_pSet->IsEOF())
- {
- // Empty Recordset. Mark fields as NULL.
- m_pSet->SetFieldNull(NULL, TRUE);
- }
- UpdateData(FALSE);
- }
- }
-
- void CQueryDefView::OnUpdateQuerydefExecute(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(m_pQueryDef && m_pQueryDef->IsOpen());
- }
-
- void CQueryDefView::OnQuerydefRemove()
- {
- ASSERT(m_pQueryDef);
- if(m_pQueryDef->IsOpen())
- m_pQueryDef->Close();
- delete m_pQueryDef;
- m_pQueryDef = NULL;
- }
-
- void CQueryDefView::OnUpdateQuerydefRemove(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(m_pQueryDef && m_pQueryDef->IsOpen());
- }
-
-
- void CQueryDefView::OnDestroy()
- {
- CDaoRecordView::OnDestroy();
-
- // Cleanup before terminating
- if (NULL != m_pQueryDef)
- OnQuerydefRemove();
- }
-