home *** CD-ROM | disk | FTP | other *** search
- // MFCPViewSlow.cpp : implementation of the CMFCPViewSlow class
- //
- // 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 "DocSlow.h"
- #include "ViewSlow.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- #define MAXORDERROWS 35
- #define MAXDETAILROWS 25
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPViewSlow
- IMPLEMENT_DYNCREATE(CMFCPViewSlow, CRecordView)
-
- BEGIN_MESSAGE_MAP(CMFCPViewSlow, CRecordView)
- //{{AFX_MSG_MAP(CMFCPViewSlow)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPViewSlow construction/destruction
- CMFCPViewSlow::CMFCPViewSlow()
- : CRecordView(CMFCPViewSlow::IDD)
- {
- //{{AFX_DATA_INIT(CMFCPViewSlow)
- m_pSet = NULL;
- //}}AFX_DATA_INIT
-
- m_pOrders = NULL;
- m_pOrdersDetail = NULL;
-
- m_bInFill = TRUE;
- }
-
- CMFCPViewSlow::~CMFCPViewSlow()
- {
- if (m_pOrders != NULL)
- {
- delete m_pOrders;
- }
-
- if (m_pOrdersDetail != NULL)
- {
- delete m_pOrdersDetail;
- }
- }
-
- void CMFCPViewSlow::DoDataExchange(CDataExchange* pDX)
- {
- CRecordView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMFCPViewSlow)
- DDX_Control(pDX, IDC_STATIC_CLICK, m_staticClick);
- 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_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
- }
-
- void CMFCPViewSlow::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 CSlowOrdersSet(&(GetDocument()->m_Database));
- m_pOrdersDetail = new CSlowOrdersDetail(&(GetDocument()->m_Database));
-
- GetOrders();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPViewSlow diagnostics
- #ifdef _DEBUG
- void CMFCPViewSlow::AssertValid() const
- {
- CRecordView::AssertValid();
- }
-
- void CMFCPViewSlow::Dump(CDumpContext& dc) const
- {
- CRecordView::Dump(dc);
- }
-
- CMFCPDocSlow* CMFCPViewSlow::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCPDocSlow)));
- return (CMFCPDocSlow*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPViewSlow database support
- CRecordset* CMFCPViewSlow::OnGetRecordset()
- {
- return m_pSet;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPViewSlow message handlers
- BEGIN_EVENTSINK_MAP(CMFCPViewSlow, CRecordView)
- //{{AFX_EVENTSINK_MAP(CMFCPViewSlow)
- ON_EVENT(CMFCPViewSlow, IDC_GRID_ORDERS, 70 /* RowColChange */, OnRowColChangeOrders, VTS_NONE)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
- void CMFCPViewSlow::OnRowColChangeOrders()
- {
- if (!m_bInFill)
- {
- CString strOrderID = m_gridOrders.GetTextMatrix(m_gridOrders.GetRow(), 1);
- if (m_pOrdersDetail->m_strOrderID != strOrderID)
- {
- m_pOrdersDetail->m_strOrderID = strOrderID;
- GetDetails();
- }
- }
- }
-
- BOOL CMFCPViewSlow::OnMove(UINT nIDMoveCommand)
- {
- if (CRecordView::OnMove(nIDMoveCommand))
- {
- GetOrders();
- return (TRUE);
- }
-
- return (FALSE);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMFCPViewSlow grid update routines
- void CMFCPViewSlow::GetOrders()
- {
- m_pOrders->m_strFilter.Format("CustomerID = '%s'", m_pSet->m_CustomerID);
-
- m_bInFill = TRUE;
-
- short nRow = 1;
- 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_strOrderID = _T("");
- GetDetails();
- }
- else
- {
- m_pOrdersDetail->m_strOrderID.Format("%u", m_pOrders->m_OrderID);
-
- while (!m_pOrders->IsEOF() && nRow < MAXORDERROWS)
- {
- strOrder.Format("%u", m_pOrders->m_OrderID);
- m_gridOrders.SetTextMatrix(nRow, 1, strOrder);
- m_gridOrders.SetTextMatrix(nRow, 2,
- m_pOrders->m_OrderDate.Format("%B %d, %Y"));
- m_gridOrders.SetTextMatrix(nRow, 3,
- m_pOrders->m_RequiredDate.Format("%B %d, %Y"));
- if (m_pOrders->IsFieldNull((void*) &(m_pOrders->m_ShippedDate)))
- {
- m_gridOrders.SetTextMatrix(nRow, 4, "<null>");
- }
- else
- {
- m_gridOrders.SetTextMatrix(nRow, 4,
- m_pOrders->m_ShippedDate.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 CMFCPViewSlow::GetDetails()
- {
- short nRow = 1;
-
- m_gridDetails.SetRedraw(FALSE);
- m_gridDetails.SetRows(1);
- m_gridDetails.SetRows(MAXDETAILROWS);
-
- if (m_pOrdersDetail->m_strOrderID.GetLength())
- {
- m_pOrdersDetail->m_strFilter = m_pOrdersDetail->m_defFilter +
- _T(" and OrderID = ") + m_pOrdersDetail->m_strOrderID;
-
- if (m_pOrdersDetail->IsOpen())
- {
- m_pOrdersDetail->Requery();
- }
- else
- {
- m_pOrdersDetail->Open();
- }
-
- CString strDetail;
- while (!m_pOrdersDetail->IsEOF() && nRow < MAXDETAILROWS)
- {
- double dLineTotal = atof(m_pOrdersDetail->m_UnitPrice);
-
- m_gridDetails.SetTextMatrix(nRow, 1,
- m_pOrdersDetail->m_ProductName);
- m_gridDetails.SetTextMatrix(nRow, 2,
- m_pOrdersDetail->m_UnitPrice);
- strDetail.Format("%u", m_pOrdersDetail->m_Quantity);
- m_gridDetails.SetTextMatrix(nRow, 3, strDetail);
- m_gridDetails.SetTextMatrix(nRow, 4, m_pOrdersDetail->m_Discount);
-
- dLineTotal *= (1 - atof(m_pOrdersDetail->m_Discount));
- dLineTotal *= m_pOrdersDetail->m_Quantity;
-
- strDetail.Format("%.2f", dLineTotal);
- m_gridDetails.SetTextMatrix(nRow, 5, strDetail);
-
- 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);
- }
-