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

  1. // MFCPViewFast.cpp : implementation file
  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 "DocFast.h"
  13. #include "ViewFast.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. // CMFCPViewFast
  26. IMPLEMENT_DYNCREATE(CMFCPViewFast, CRecordView)
  27.  
  28. CMFCPViewFast::CMFCPViewFast()
  29.     : CRecordView(CMFCPViewFast::IDD)
  30.     {
  31.     //{{AFX_DATA_INIT(CMFCPViewFast)
  32.     m_pSet = NULL;
  33.     //}}AFX_DATA_INIT
  34.     
  35.     m_pOrders = NULL;
  36.     m_pOrdersDetail = NULL;
  37.  
  38.     m_bInFill = TRUE;
  39.     }
  40.  
  41. CMFCPViewFast::~CMFCPViewFast()
  42.     {
  43.     if (m_pOrders != NULL)
  44.         {
  45.         delete m_pOrders;
  46.         }
  47.  
  48.     if (m_pOrdersDetail != NULL)
  49.         {
  50.         delete m_pOrdersDetail;
  51.         }
  52.     }
  53.  
  54. void CMFCPViewFast::DoDataExchange(CDataExchange* pDX)
  55.     {
  56.     CRecordView::DoDataExchange(pDX);
  57.     //{{AFX_DATA_MAP(CMFCPViewFast)
  58.     DDX_Control(pDX, IDC_STATIC_TOSEE, m_staticToSee);
  59.     DDX_Control(pDX, IDC_EDIT_COUNTRY, m_editCountry);
  60.     DDX_Control(pDX, IDC_EDIT_COMPANY, m_editCompany);
  61.     DDX_Control(pDX, IDC_STATIC_CLICK, m_staticClick);
  62.     DDX_FieldText(pDX, IDC_EDIT_COMPANY, m_pSet->m_CompanyName, m_pSet);
  63.     DDX_FieldText(pDX, IDC_EDIT_COUNTRY, m_pSet->m_Country, m_pSet);
  64.     DDX_Control(pDX, IDC_GRID_DETAILS, m_gridDetails);
  65.     DDX_Control(pDX, IDC_GRID_ORDERS, m_gridOrders);
  66.     //}}AFX_DATA_MAP
  67.     }
  68.  
  69. BEGIN_MESSAGE_MAP(CMFCPViewFast, CRecordView)
  70.     //{{AFX_MSG_MAP(CMFCPViewFast)
  71.         // NOTE - the ClassWizard will add and remove mapping macros here.
  72.     //}}AFX_MSG_MAP
  73. END_MESSAGE_MAP()
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CMFCPViewFast diagnostics
  77. #ifdef _DEBUG
  78. void CMFCPViewFast::AssertValid() const
  79.     {
  80.     CRecordView::AssertValid();
  81.     }
  82.  
  83. void CMFCPViewFast::Dump(CDumpContext& dc) const
  84.     {
  85.     CRecordView::Dump(dc);
  86.     }
  87.  
  88. CMFCPDocFast* CMFCPViewFast::GetDocument() // non-debug version is inline
  89.     {
  90.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCPDocFast)));
  91.     return (CMFCPDocFast*)m_pDocument;
  92.     }
  93. #endif //_DEBUG
  94.  
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CMFCPViewFast message handlers
  97. CRecordset* CMFCPViewFast::OnGetRecordset()
  98.     {
  99.     if (m_pSet != NULL)
  100.         return m_pSet;
  101.  
  102.     m_pSet = new CMFCPCust(NULL);
  103.     m_pSet->Open();
  104.  
  105.     return m_pSet;
  106.     }
  107.  
  108. CMFCPCust* CMFCPViewFast::GetRecordset()
  109.     {
  110.     CMFCPCust* pData = (CMFCPCust*) OnGetRecordset();
  111.     ASSERT(pData == NULL || pData->IsKindOf(RUNTIME_CLASS(CMFCPCust)));
  112.     return pData;
  113.     }
  114.  
  115. void CMFCPViewFast::OnInitialUpdate()
  116.     {
  117.     m_pSet = GetDocument()->m_pMFCPCust;
  118.     try
  119.         {
  120.         CRecordView::OnInitialUpdate();
  121.         }
  122.     catch (CException* e)
  123.         {
  124.         AfxMessageBox(_T("Error opening customer cursor. Database may not exist."));
  125.         
  126.         GetDocument()->m_Database.Close();
  127.         e->Delete();
  128.         return;
  129.         }
  130.  
  131.     SetForm(this->GetParent(), m_editCompany, m_editCountry, m_gridOrders,
  132.         m_gridDetails, m_staticClick, m_staticToSee);
  133.  
  134.     m_pOrders = new CFastOrdersSet(&(GetDocument()->m_Database));
  135.     m_pOrdersDetail = new CFastOrdersDetail(&(GetDocument()->m_Database));
  136.  
  137.     GetOrders();
  138.     }
  139.  
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CMFCPViewFast grid update routines
  142. void CMFCPViewFast::GetOrders()
  143.     {
  144.     short nRow = 1;
  145.  
  146.     m_pOrders->m_strCustID = m_pSet->m_CustomerID;
  147.     m_bInFill = TRUE;
  148.  
  149.     m_gridOrders.SetRedraw(FALSE);
  150.     m_gridOrders.SetRows(1);
  151.     m_gridOrders.SetRows(MAXORDERROWS);
  152.  
  153.     if (m_pOrders->IsOpen())
  154.         {
  155.         m_pOrders->Requery();
  156.         }
  157.     else
  158.         {
  159.         m_pOrders->Open();
  160.         }
  161.  
  162.     CString strOrder;
  163.  
  164.     if (m_pOrders->IsEOF())
  165.         {
  166.         m_pOrdersDetail->m_nOrderID = 0;
  167.         }
  168.     else
  169.         {
  170.         m_pOrdersDetail->m_nOrderID = m_pOrders->m_nOrderID;
  171.         }
  172.  
  173.     while (!m_pOrders->IsEOF() && nRow < MAXORDERROWS)
  174.         {
  175.         strOrder.Format("%u", m_pOrders->m_nOrderID);
  176.         m_gridOrders.SetTextMatrix(nRow, 1, strOrder);
  177.  
  178.         m_gridOrders.SetTextMatrix(nRow, 2,
  179.             m_pOrders->m_timeOrder.Format("%B %d, %Y"));
  180.  
  181.         m_gridOrders.SetTextMatrix(nRow, 3,
  182.             m_pOrders->m_timeRequired.Format("%B %d, %Y"));
  183.  
  184.         if (m_pOrders->IsFieldNull((void*) &(m_pOrders->m_timeShipped)))
  185.             {
  186.             m_gridOrders.SetTextMatrix(nRow, 4, "<null>");
  187.             }
  188.         else
  189.             {
  190.             m_gridOrders.SetTextMatrix(nRow, 4, 
  191.                 m_pOrders->m_timeShipped.Format("%B %d, %Y"));
  192.             }
  193.  
  194.         nRow++;
  195.         m_pOrders->MoveNext();
  196.         }
  197.  
  198.     GetDetails();
  199.  
  200.     m_gridOrders.SetRows(nRow == 1 ? 2 : nRow);
  201.     m_gridOrders.SetFixedRows(1);
  202.     m_gridOrders.SetRow(1);
  203.     m_gridOrders.SetCol(1);
  204.     m_gridOrders.SetRedraw(TRUE);
  205.  
  206.     m_bInFill = FALSE;
  207.     }
  208.  
  209. void CMFCPViewFast::GetDetails()
  210.     {
  211.     short nRow = 1;
  212.  
  213.     m_gridDetails.SetRedraw(FALSE);
  214.     m_gridDetails.SetRows(1);
  215.     m_gridDetails.SetRows(MAXDETAILROWS);
  216.  
  217.     if (m_pOrdersDetail->m_nOrderID)
  218.         {
  219.         if (m_pOrdersDetail->IsOpen())
  220.             {
  221.             m_pOrdersDetail->Requery();
  222.             }
  223.         else
  224.             {
  225.             m_pOrdersDetail->Open();
  226.             }
  227.  
  228.         CString strDetail;
  229.         while (!m_pOrdersDetail->IsEOF() && nRow < MAXDETAILROWS)
  230.             {
  231.             m_gridDetails.SetTextMatrix(nRow, 1, 
  232.                 m_pOrdersDetail->m_strProductName);
  233.             
  234.             m_gridDetails.SetTextMatrix(nRow, 2,
  235.                 m_pOrdersDetail->m_strUnitPrice);
  236.             
  237.             strDetail.Format("%u", m_pOrdersDetail->m_nQuantity);
  238.             m_gridDetails.SetTextMatrix(nRow, 3, strDetail);
  239.  
  240.             strDetail.Format("%2.0f%c", m_pOrdersDetail->m_nDiscount, '%');
  241.             m_gridDetails.SetTextMatrix(nRow, 4, strDetail);
  242.  
  243.             m_gridDetails.SetTextMatrix(nRow, 5,
  244.                 m_pOrdersDetail->m_strExtendPrice);
  245.  
  246.             nRow++;
  247.             m_pOrdersDetail->MoveNext();
  248.             }
  249.         }
  250.  
  251.     m_gridDetails.SetRows(nRow == 1 ? 2 : nRow);
  252.     m_gridDetails.SetFixedRows(1);
  253.     m_gridDetails.SetRow(1);
  254.     m_gridDetails.SetCol(1);
  255.     m_gridDetails.SetRedraw(TRUE);
  256.     }
  257.  
  258. BOOL CMFCPViewFast::OnMove(UINT nIDMoveCommand) 
  259.     {
  260.     if (CRecordView::OnMove(nIDMoveCommand))
  261.         {
  262.            GetOrders();
  263.         return (TRUE);
  264.         }
  265.     
  266.     return (FALSE);
  267.     }
  268.  
  269. BEGIN_EVENTSINK_MAP(CMFCPViewFast, CRecordView)
  270.     //{{AFX_EVENTSINK_MAP(CMFCPViewFast)
  271.     ON_EVENT(CMFCPViewFast, IDC_GRID_ORDERS, 70 /* RowColChange */, OnRowColChangeOrders, VTS_NONE)
  272.     //}}AFX_EVENTSINK_MAP
  273. END_EVENTSINK_MAP()
  274.  
  275. void CMFCPViewFast::OnRowColChangeOrders() 
  276.     {
  277.     if (!m_bInFill)
  278.         {
  279.         int nOrderID = _ttoi(m_gridOrders.GetTextMatrix(m_gridOrders.GetRow(), 1));
  280.         if (m_pOrdersDetail->m_nOrderID != nOrderID)
  281.             {
  282.             m_pOrdersDetail->m_nOrderID = nOrderID;
  283.             GetDetails();
  284.             }
  285.         }
  286.     }
  287.