home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / internet / wwwquote / queries.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  4.9 KB  |  209 lines

  1. // Queries.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "WWWQuote.h"
  15. #include "Queries.h"
  16.  
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CIssueQuery
  25.  
  26. IMPLEMENT_DYNAMIC(CIssueQuery, CRecordset)
  27.  
  28. CIssueQuery::CIssueQuery(CDatabase* pdb, BOOL bByCUSIP)
  29.     : CRecordset(pdb)
  30. {
  31.     //{{AFX_FIELD_INIT(CIssueQuery)
  32.     m_strCUSIP = _T("");
  33.     m_strName = _T("");
  34.     m_strTicker = _T("");
  35.     m_nFields = 3;
  36.     //}}AFX_FIELD_INIT
  37.     m_nDefaultType = snapshot;
  38.     m_bByCUSIP = bByCUSIP;
  39. }
  40.  
  41.  
  42. CString CIssueQuery::GetDefaultConnect()
  43. {
  44.     return _T("ODBC;DSN=Stock Quotes");
  45. }
  46.  
  47. CString CIssueQuery::GetDefaultSQL()
  48. {
  49.     CString strQuery;
  50.  
  51.     if (m_bByCUSIP)
  52.         strQuery = _T("SELECT Ticker, CUSIP, Name FROM Issues ORDER BY CUSIP");
  53.     else
  54.         strQuery = _T("SELECT Ticker, CUSIP, Name FROM Issues ORDER BY Name");
  55.  
  56.     return strQuery;
  57. }
  58.  
  59. void CIssueQuery::DoFieldExchange(CFieldExchange* pFX)
  60. {
  61.     //{{AFX_FIELD_MAP(CIssueQuery)
  62.     pFX->SetFieldType(CFieldExchange::outputColumn);
  63.     RFX_Text(pFX, _T("[Ticker]"), m_strTicker);
  64.     RFX_Text(pFX, _T("[CUSIP]"), m_strCUSIP);
  65.     RFX_Text(pFX, _T("[Name]"), m_strName);
  66.     //}}AFX_FIELD_MAP
  67. }
  68.  
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CIssueQuery diagnostics
  71.  
  72. #ifdef _DEBUG
  73. void CIssueQuery::AssertValid() const
  74. {
  75.     CRecordset::AssertValid();
  76. }
  77.  
  78. void CIssueQuery::Dump(CDumpContext& dc) const
  79. {
  80.     CRecordset::Dump(dc);
  81. }
  82. #endif //_DEBUG
  83.  
  84.  
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CQuoteQuery
  87.  
  88. IMPLEMENT_DYNAMIC(CQuoteQuery, CRecordset)
  89.  
  90. CQuoteQuery::CQuoteQuery(CDatabase* pdb, LPCTSTR strTicker, int nMonth, int nYear)
  91.     : CRecordset(pdb), m_strTicker(strTicker)
  92. {
  93.     //{{AFX_FIELD_INIT(CQuoteQuery)
  94.     m_Volume = 0;
  95.     m_HighAsk = _T("");
  96.     m_LowBid = _T("");
  97.     m_CloseAvg = _T("");
  98.     m_nFields = 5;
  99.     //}}AFX_FIELD_INIT
  100.     m_nDefaultType = snapshot;
  101.  
  102.     m_nMonth = nMonth;
  103.     m_nYear = nYear;
  104. }
  105.  
  106.  
  107. CString CQuoteQuery::GetDefaultConnect()
  108. {
  109.     return _T("ODBC;DSN=Stock Quotes");
  110. }
  111.  
  112. const int nMonthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  113.  
  114. CString CQuoteQuery::GetDefaultSQL()
  115. {
  116.     CString strQuery;
  117.  
  118.     strQuery.Format("SELECT Date, Volume, HighAsk, LowBid, CloseAvg"
  119.                     "  FROM Issues, Quotes"
  120.                     " WHERE Date BETWEEN {ts '%4.4d-%2.2d-01 00:00:00'}"
  121.                     "   AND {ts '%4.4d-%2.2d-%2.2d 00:00:00'}"
  122.                     "   AND Issues.Ticker = '%s'"
  123.                     "   AND Issues.Ticker = Quotes.Ticker"
  124.                     " ORDER BY Date",
  125.                     m_nYear, m_nMonth,
  126.                     m_nYear, m_nMonth, nMonthDays[m_nMonth-1],
  127.                     m_strTicker);
  128.  
  129.     return strQuery;
  130. }
  131.  
  132. void CQuoteQuery::DoFieldExchange(CFieldExchange* pFX)
  133. {
  134.     //{{AFX_FIELD_MAP(CQuoteQuery)
  135.     pFX->SetFieldType(CFieldExchange::outputColumn);
  136.     RFX_Date(pFX, _T("[Date]"), m_Date);
  137.     RFX_Long(pFX, _T("[Volume]"), m_Volume);
  138.     RFX_Text(pFX, _T("[HighAsk]"), m_HighAsk);
  139.     RFX_Text(pFX, _T("[LowBid]"), m_LowBid);
  140.     RFX_Text(pFX, _T("[CloseAvg]"), m_CloseAvg);
  141.     //}}AFX_FIELD_MAP
  142. }
  143.  
  144. /////////////////////////////////////////////////////////////////////////////
  145. // CQuoteQuery diagnostics
  146.  
  147. #ifdef _DEBUG
  148. void CQuoteQuery::AssertValid() const
  149. {
  150.     CRecordset::AssertValid();
  151. }
  152.  
  153. void CQuoteQuery::Dump(CDumpContext& dc) const
  154. {
  155.     CRecordset::Dump(dc);
  156. }
  157. #endif //_DEBUG
  158.  
  159. /////////////////////////////////////////////////////////////////////////////
  160. // CRangeQuery
  161.  
  162. IMPLEMENT_DYNAMIC(CRangeQuery, CRecordset)
  163.  
  164. CRangeQuery::CRangeQuery(CDatabase* pdb, LPCTSTR pszTicker)
  165.     : CRecordset(pdb), m_strTicker(pszTicker)
  166. {
  167.     //{{AFX_FIELD_INIT(CRangeQuery)
  168.     m_nFields = 2;
  169.     //}}AFX_FIELD_INIT
  170.     m_nDefaultType = snapshot;
  171. }
  172.  
  173. CString CRangeQuery::GetDefaultConnect()
  174. {
  175.     return _T("ODBC;DSN=Stock Quotes");
  176. }
  177.  
  178. CString CRangeQuery::GetDefaultSQL()
  179. {
  180.     CString str;
  181.     str.Format("SELECT MIN(Date) 'Lo', MAX(Date) 'Hi' "
  182.             " FROM Quotes WHERE Ticker = '%s'", m_strTicker);
  183.     return str;
  184. }
  185.  
  186. void CRangeQuery::DoFieldExchange(CFieldExchange* pFX)
  187. {
  188.     //{{AFX_FIELD_MAP(CRangeQuery)
  189.     pFX->SetFieldType(CFieldExchange::outputColumn);
  190.     RFX_Date(pFX, "Lo", m_tMin);
  191.     RFX_Date(pFX, "Hi", m_tMax);
  192.     //}}AFX_FIELD_MAP
  193. }
  194.  
  195. /////////////////////////////////////////////////////////////////////////////
  196. // CRangeQuery diagnostics
  197.  
  198. #ifdef _DEBUG
  199. void CRangeQuery::AssertValid() const
  200. {
  201.     CRecordset::AssertValid();
  202. }
  203.  
  204. void CRangeQuery::Dump(CDumpContext& dc) const
  205. {
  206.     CRecordset::Dump(dc);
  207. }
  208. #endif //_DEBUG
  209.