home *** CD-ROM | disk | FTP | other *** search
- // MFCPViewFast.cpp : implementation file
- //
- // This file is part of Microsoft SQL Server online documentation.
- // Copyright (C) 1992-1997 Microsoft Corporation. All rights reserved.
- //
- // This source code is an intended supplement to the Microsoft SQL
- // Server online references and related electronic documentation.
- #include "stdafx.h"
- #include "MFCPerf.h"
-
- #include "MFCPCust.h"
- #include "DocFast.h"
- #include "ViewFast.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- #define MAXORDERROWS 35
- #define MAXDETAILROWS 25
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPViewFast
- IMPLEMENT_DYNCREATE(CMFCPViewFast, CRecordView)
-
- CMFCPViewFast::CMFCPViewFast()
- : CRecordView(CMFCPViewFast::IDD)
- {
- //{{AFX_DATA_INIT(CMFCPViewFast)
- m_pSet = NULL;
- //}}AFX_DATA_INIT
-
- m_pOrders = NULL;
- m_pOrdersDetail = NULL;
-
- m_bInFill = TRUE;
- }
-
- CMFCPViewFast::~CMFCPViewFast()
- {
- if (m_pOrders != NULL)
- {
- delete m_pOrders;
- }
-
- if (m_pOrdersDetail != NULL)
- {
- delete m_pOrdersDetail;
- }
- }
-
- void CMFCPViewFast::DoDataExchange(CDataExchange* pDX)
- {
- CRecordView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMFCPViewFast)
- DDX_Control(pDX, IDC_STATIC_TOSEE, m_staticToSee);
- DDX_Control(pDX, IDC_EDIT_COUNTRY, m_editCountry);
- DDX_Control(pDX, IDC_EDIT_COMPANY, m_editCompany);
- DDX_Control(pDX, IDC_STATIC_CLICK, m_staticClick);
- DDX_FieldText(pDX, IDC_EDIT_COMPANY, m_pSet->m_CompanyName, m_pSet);
- DDX_FieldText(pDX, IDC_EDIT_COUNTRY, m_pSet->m_Country, m_pSet);
- DDX_Control(pDX, IDC_GRID_DETAILS, m_gridDetails);
- DDX_Control(pDX, IDC_GRID_ORDERS, m_gridOrders);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CMFCPViewFast, CRecordView)
- //{{AFX_MSG_MAP(CMFCPViewFast)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPViewFast diagnostics
- #ifdef _DEBUG
- void CMFCPViewFast::AssertValid() const
- {
- CRecordView::AssertValid();
- }
-
- void CMFCPViewFast::Dump(CDumpContext& dc) const
- {
- CRecordView::Dump(dc);
- }
-
- CMFCPDocFast* CMFCPViewFast::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCPDocFast)));
- return (CMFCPDocFast*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPViewFast message handlers
- CRecordset* CMFCPViewFast::OnGetRecordset()
- {
- if (m_pSet != NULL)
- return m_pSet;
-
- m_pSet = new CMFCPCust(NULL);
- m_pSet->Open();
-
- return m_pSet;
- }
-
- CMFCPCust* CMFCPViewFast::GetRecordset()
- {
- CMFCPCust* pData = (CMFCPCust*) OnGetRecordset();
- ASSERT(pData == NULL || pData->IsKindOf(RUNTIME_CLASS(CMFCPCust)));
- return pData;
- }
-
- void CMFCPViewFast::OnInitialUpdate()
- {
- m_pSet = GetDocument()->m_pMFCPCust;
- try
- {
- CRecordView::OnInitialUpdate();
- }
- catch (CException* e)
- {
- AfxMessageBox(_T("Error opening customer cursor. Database may not exist."));
-
- GetDocument()->m_Database.Close();
- e->Delete();
- return;
- }
-
- SetForm(this->GetParent(), m_editCompany, m_editCountry, m_gridOrders,
- m_gridDetails, m_staticClick, m_staticToSee);
-
- m_pOrders = new CFastOrdersSet(&(GetDocument()->m_Database));
- m_pOrdersDetail = new CFastOrdersDetail(&(GetDocument()->m_Database));
-
- GetOrders();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPViewFast grid update routines
- void CMFCPViewFast::GetOrders()
- {
- short nRow = 1;
-
- m_pOrders->m_strCustID = m_pSet->m_CustomerID;
- m_bInFill = TRUE;
-
- m_gridOrders.SetRedraw(FALSE);
- m_gridOrders.SetRows(1);
- m_gridOrders.SetRows(MAXORDERROWS);
-
- if (m_pOrders->IsOpen())
- {
- m_pOrders->Requery();
- }
- else
- {
- m_pOrders->Open();
- }
-
- CString strOrder;
-
- if (m_pOrders->IsEOF())
- {
- m_pOrdersDetail->m_nOrderID = 0;
- }
- else
- {
- m_pOrdersDetail->m_nOrderID = m_pOrders->m_nOrderID;
- }
-
- while (!m_pOrders->IsEOF() && nRow < MAXORDERROWS)
- {
- strOrder.Format("%u", m_pOrders->m_nOrderID);
- m_gridOrders.SetTextMatrix(nRow, 1, strOrder);
-
- m_gridOrders.SetTextMatrix(nRow, 2,
- m_pOrders->m_timeOrder.Format("%B %d, %Y"));
-
- m_gridOrders.SetTextMatrix(nRow, 3,
- m_pOrders->m_timeRequired.Format("%B %d, %Y"));
-
- if (m_pOrders->IsFieldNull((void*) &(m_pOrders->m_timeShipped)))
- {
- m_gridOrders.SetTextMatrix(nRow, 4, "<null>");
- }
- else
- {
- m_gridOrders.SetTextMatrix(nRow, 4,
- m_pOrders->m_timeShipped.Format("%B %d, %Y"));
- }
-
- nRow++;
- m_pOrders->MoveNext();
- }
-
- GetDetails();
-
- m_gridOrders.SetRows(nRow == 1 ? 2 : nRow);
- m_gridOrders.SetFixedRows(1);
- m_gridOrders.SetRow(1);
- m_gridOrders.SetCol(1);
- m_gridOrders.SetRedraw(TRUE);
-
- m_bInFill = FALSE;
- }
-
- void CMFCPViewFast::GetDetails()
- {
- short nRow = 1;
-
- m_gridDetails.SetRedraw(FALSE);
- m_gridDetails.SetRows(1);
- m_gridDetails.SetRows(MAXDETAILROWS);
-
- if (m_pOrdersDetail->m_nOrderID)
- {
- if (m_pOrdersDetail->IsOpen())
- {
- m_pOrdersDetail->Requery();
- }
- else
- {
- m_pOrdersDetail->Open();
- }
-
- CString strDetail;
- while (!m_pOrdersDetail->IsEOF() && nRow < MAXDETAILROWS)
- {
- m_gridDetails.SetTextMatrix(nRow, 1,
- m_pOrdersDetail->m_strProductName);
-
- m_gridDetails.SetTextMatrix(nRow, 2,
- m_pOrdersDetail->m_strUnitPrice);
-
- strDetail.Format("%u", m_pOrdersDetail->m_nQuantity);
- m_gridDetails.SetTextMatrix(nRow, 3, strDetail);
-
- strDetail.Format("%2.0f%c", m_pOrdersDetail->m_nDiscount, '%');
- m_gridDetails.SetTextMatrix(nRow, 4, strDetail);
-
- m_gridDetails.SetTextMatrix(nRow, 5,
- m_pOrdersDetail->m_strExtendPrice);
-
- nRow++;
- m_pOrdersDetail->MoveNext();
- }
- }
-
- m_gridDetails.SetRows(nRow == 1 ? 2 : nRow);
- m_gridDetails.SetFixedRows(1);
- m_gridDetails.SetRow(1);
- m_gridDetails.SetCol(1);
- m_gridDetails.SetRedraw(TRUE);
- }
-
- BOOL CMFCPViewFast::OnMove(UINT nIDMoveCommand)
- {
- if (CRecordView::OnMove(nIDMoveCommand))
- {
- GetOrders();
- return (TRUE);
- }
-
- return (FALSE);
- }
-
- BEGIN_EVENTSINK_MAP(CMFCPViewFast, CRecordView)
- //{{AFX_EVENTSINK_MAP(CMFCPViewFast)
- ON_EVENT(CMFCPViewFast, IDC_GRID_ORDERS, 70 /* RowColChange */, OnRowColChangeOrders, VTS_NONE)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
- void CMFCPViewFast::OnRowColChangeOrders()
- {
- if (!m_bInFill)
- {
- int nOrderID = _ttoi(m_gridOrders.GetTextMatrix(m_gridOrders.GetRow(), 1));
- if (m_pOrdersDetail->m_nOrderID != nOrderID)
- {
- m_pOrdersDetail->m_nOrderID = nOrderID;
- GetDetails();
- }
- }
- }
-