home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 32 / IOPROG_32.ISO / SOFT / SqlEval7 / devtools / samples / ODBC / mfcperf / viewslow.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-20  |  7.9 KB  |  281 lines

  1. // MFCPViewSlow.cpp : implementation of the CMFCPViewSlow class
  2. //
  3. // This file is part of Microsoft SQL Server online documentation.
  4. // Copyright (C) 1992-1997 Microsoft Corporation. All rights reserved.
  5. //
  6. // This source code is an intended supplement to the Microsoft SQL
  7. // Server online references and related electronic documentation.
  8. #include "stdafx.h"
  9. #include "MFCPerf.h"
  10.  
  11. #include "MFCPCust.h"
  12. #include "DocSlow.h"
  13. #include "ViewSlow.h"
  14.  
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20.  
  21. #define MAXORDERROWS    35
  22. #define MAXDETAILROWS   25
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CMFCPViewSlow
  26. IMPLEMENT_DYNCREATE(CMFCPViewSlow, CRecordView)
  27.  
  28. BEGIN_MESSAGE_MAP(CMFCPViewSlow, CRecordView)
  29.     //{{AFX_MSG_MAP(CMFCPViewSlow)
  30.         // NOTE - the ClassWizard will add and remove mapping macros here.
  31.         //    DO NOT EDIT what you see in these blocks of generated code!
  32.     //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CMFCPViewSlow construction/destruction
  37. CMFCPViewSlow::CMFCPViewSlow()
  38.     : CRecordView(CMFCPViewSlow::IDD)
  39.     {
  40.     //{{AFX_DATA_INIT(CMFCPViewSlow)
  41.     m_pSet = NULL;
  42.     //}}AFX_DATA_INIT
  43.  
  44.     m_pOrders = NULL;
  45.     m_pOrdersDetail = NULL;
  46.  
  47.     m_bInFill = TRUE;
  48.     }
  49.  
  50. CMFCPViewSlow::~CMFCPViewSlow()
  51.     {
  52.     if (m_pOrders != NULL)
  53.         {
  54.         delete m_pOrders;
  55.         }
  56.  
  57.     if (m_pOrdersDetail != NULL)
  58.         {
  59.         delete m_pOrdersDetail;
  60.         }
  61.     }
  62.  
  63. void CMFCPViewSlow::DoDataExchange(CDataExchange* pDX)
  64.     {
  65.     CRecordView::DoDataExchange(pDX);
  66.     //{{AFX_DATA_MAP(CMFCPViewSlow)
  67.     DDX_Control(pDX, IDC_STATIC_CLICK, m_staticClick);
  68.     DDX_Control(pDX, IDC_STATIC_TOSEE, m_staticToSee);
  69.     DDX_Control(pDX, IDC_EDIT_COUNTRY, m_editCountry);
  70.     DDX_Control(pDX, IDC_EDIT_COMPANY, m_editCompany);
  71.     DDX_FieldText(pDX, IDC_EDIT_COMPANY, m_pSet->m_CompanyName, m_pSet);
  72.     DDX_FieldText(pDX, IDC_EDIT_COUNTRY, m_pSet->m_Country, m_pSet);
  73.     DDX_Control(pDX, IDC_GRID_DETAILS, m_gridDetails);
  74.     DDX_Control(pDX, IDC_GRID_ORDERS, m_gridOrders);
  75.     //}}AFX_DATA_MAP
  76.     }
  77.  
  78. void CMFCPViewSlow::OnInitialUpdate()
  79.     {
  80.     m_pSet = GetDocument()->m_pMFCPCust;
  81.     try
  82.         {
  83.         CRecordView::OnInitialUpdate();
  84.         }
  85.     catch (CException* e)
  86.         {
  87.         AfxMessageBox(_T("Error opening customer cursor. Database may not exist."));
  88.  
  89.         GetDocument()->m_Database.Close();
  90.         e->Delete();
  91.         return;
  92.         }
  93.  
  94.     SetForm(this->GetParent(), m_editCompany, m_editCountry, m_gridOrders,
  95.         m_gridDetails, m_staticClick, m_staticToSee);
  96.  
  97.     m_pOrders = new CSlowOrdersSet(&(GetDocument()->m_Database));
  98.     m_pOrdersDetail = new CSlowOrdersDetail(&(GetDocument()->m_Database));
  99.  
  100.     GetOrders();
  101.     }
  102.  
  103. /////////////////////////////////////////////////////////////////////////////
  104. // CMFCPViewSlow diagnostics
  105. #ifdef _DEBUG
  106. void CMFCPViewSlow::AssertValid() const
  107.     {
  108.     CRecordView::AssertValid();
  109.     }
  110.  
  111. void CMFCPViewSlow::Dump(CDumpContext& dc) const
  112.     {
  113.     CRecordView::Dump(dc);
  114.     }
  115.  
  116. CMFCPDocSlow* CMFCPViewSlow::GetDocument() // non-debug version is inline
  117.     {
  118.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCPDocSlow)));
  119.     return (CMFCPDocSlow*)m_pDocument;
  120.     }
  121. #endif //_DEBUG
  122.  
  123. /////////////////////////////////////////////////////////////////////////////
  124. // CMFCPViewSlow database support
  125. CRecordset* CMFCPViewSlow::OnGetRecordset()
  126.     {
  127.     return m_pSet;
  128.     }
  129.  
  130. /////////////////////////////////////////////////////////////////////////////
  131. // CMFCPViewSlow message handlers
  132. BEGIN_EVENTSINK_MAP(CMFCPViewSlow, CRecordView)
  133.     //{{AFX_EVENTSINK_MAP(CMFCPViewSlow)
  134.     ON_EVENT(CMFCPViewSlow, IDC_GRID_ORDERS, 70 /* RowColChange */, OnRowColChangeOrders, VTS_NONE)
  135.     //}}AFX_EVENTSINK_MAP
  136. END_EVENTSINK_MAP()
  137.  
  138. void CMFCPViewSlow::OnRowColChangeOrders() 
  139.     {
  140.     if (!m_bInFill)
  141.         {
  142.         CString strOrderID = m_gridOrders.GetTextMatrix(m_gridOrders.GetRow(), 1);
  143.         if (m_pOrdersDetail->m_strOrderID != strOrderID)
  144.             {
  145.             m_pOrdersDetail->m_strOrderID = strOrderID;
  146.             GetDetails();
  147.             }
  148.         }
  149.     }
  150.  
  151. BOOL CMFCPViewSlow::OnMove(UINT nIDMoveCommand) 
  152.     {
  153.     if (CRecordView::OnMove(nIDMoveCommand))
  154.         {
  155.            GetOrders();
  156.         return (TRUE);
  157.         }
  158.     
  159.     return (FALSE);
  160.     }
  161.  
  162. /////////////////////////////////////////////////////////////////////////////
  163. // CMFCPViewSlow grid update routines
  164. void CMFCPViewSlow::GetOrders()
  165.     {
  166.     m_pOrders->m_strFilter.Format("CustomerID = '%s'", m_pSet->m_CustomerID);
  167.  
  168.     m_bInFill = TRUE;
  169.  
  170.     short nRow = 1;
  171.     m_gridOrders.SetRedraw(FALSE);
  172.     m_gridOrders.SetRows(1);
  173.     m_gridOrders.SetRows(MAXORDERROWS);
  174.  
  175.     if (m_pOrders->IsOpen())
  176.         {
  177.         m_pOrders->Requery();
  178.         }
  179.     else
  180.         {
  181.         m_pOrders->Open();
  182.         }
  183.  
  184.     CString strOrder;
  185.  
  186.     if (m_pOrders->IsEOF())
  187.         {
  188.         m_pOrdersDetail->m_strOrderID = _T("");
  189.         GetDetails();
  190.         }
  191.     else
  192.         {
  193.         m_pOrdersDetail->m_strOrderID.Format("%u", m_pOrders->m_OrderID);
  194.  
  195.         while (!m_pOrders->IsEOF() && nRow < MAXORDERROWS)
  196.             {
  197.             strOrder.Format("%u", m_pOrders->m_OrderID);
  198.             m_gridOrders.SetTextMatrix(nRow, 1, strOrder);
  199.             m_gridOrders.SetTextMatrix(nRow, 2, 
  200.                 m_pOrders->m_OrderDate.Format("%B %d, %Y"));
  201.             m_gridOrders.SetTextMatrix(nRow, 3,
  202.                 m_pOrders->m_RequiredDate.Format("%B %d, %Y"));
  203.             if (m_pOrders->IsFieldNull((void*) &(m_pOrders->m_ShippedDate)))
  204.                 {
  205.                 m_gridOrders.SetTextMatrix(nRow, 4, "<null>");
  206.                 }
  207.             else
  208.                 {
  209.                 m_gridOrders.SetTextMatrix(nRow, 4,
  210.                     m_pOrders->m_ShippedDate.Format("%B %d, %Y"));
  211.                 }
  212.  
  213.             nRow++;
  214.             m_pOrders->MoveNext();
  215.             }
  216.  
  217.         GetDetails();
  218.         }
  219.  
  220.     m_gridOrders.SetRows(nRow == 1 ? 2 : nRow);
  221.     m_gridOrders.SetFixedRows(1);
  222.     m_gridOrders.SetRow(1);
  223.     m_gridOrders.SetCol(1);
  224.     m_gridOrders.SetRedraw(TRUE);
  225.  
  226.     m_bInFill = FALSE;
  227.     }
  228.  
  229. void CMFCPViewSlow::GetDetails()
  230.     {
  231.     short nRow = 1;
  232.  
  233.     m_gridDetails.SetRedraw(FALSE);
  234.     m_gridDetails.SetRows(1);
  235.     m_gridDetails.SetRows(MAXDETAILROWS);
  236.  
  237.     if (m_pOrdersDetail->m_strOrderID.GetLength())
  238.         {
  239.         m_pOrdersDetail->m_strFilter = m_pOrdersDetail->m_defFilter + 
  240.             _T(" and OrderID = ") + m_pOrdersDetail->m_strOrderID;
  241.  
  242.         if (m_pOrdersDetail->IsOpen())
  243.             {
  244.             m_pOrdersDetail->Requery();
  245.             }
  246.         else
  247.             {
  248.             m_pOrdersDetail->Open();
  249.             }
  250.  
  251.         CString strDetail;
  252.         while (!m_pOrdersDetail->IsEOF() && nRow < MAXDETAILROWS)
  253.             {
  254.             double   dLineTotal = atof(m_pOrdersDetail->m_UnitPrice);
  255.  
  256.             m_gridDetails.SetTextMatrix(nRow, 1,
  257.                 m_pOrdersDetail->m_ProductName);
  258.             m_gridDetails.SetTextMatrix(nRow, 2,
  259.                 m_pOrdersDetail->m_UnitPrice);
  260.             strDetail.Format("%u", m_pOrdersDetail->m_Quantity);
  261.             m_gridDetails.SetTextMatrix(nRow, 3, strDetail);
  262.             m_gridDetails.SetTextMatrix(nRow, 4, m_pOrdersDetail->m_Discount);
  263.  
  264.             dLineTotal *= (1 - atof(m_pOrdersDetail->m_Discount));
  265.             dLineTotal *= m_pOrdersDetail->m_Quantity;
  266.  
  267.             strDetail.Format("%.2f", dLineTotal);
  268.             m_gridDetails.SetTextMatrix(nRow, 5, strDetail);
  269.  
  270.             nRow++;
  271.             m_pOrdersDetail->MoveNext();
  272.             }
  273.         }
  274.  
  275.     m_gridDetails.SetRows(nRow == 1 ? 2 : nRow);
  276.     m_gridDetails.SetFixedRows(1);
  277.     m_gridDetails.SetRow(1);
  278.     m_gridDetails.SetCol(1);
  279.     m_gridDetails.SetRedraw(TRUE);
  280.     }
  281.