// WWWQuote.cpp : Defines the initialization routines for the DLL. // // This is a part of the Microsoft Foundation Classes C++ library. // Copyright (C) 1992-1998 Microsoft Corporation // All rights reserved. // // This source code is only intended as a supplement to the // Microsoft Foundation Classes Reference and related // electronic documentation provided with the library. // See these sources for detailed information regarding the // Microsoft Foundation Classes product. #include "stdafx.h" #include "WWWQuote.h" #include "Queries.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CWWWQuoteApp BEGIN_MESSAGE_MAP(CWWWQuoteApp, CWinApp) //{{AFX_MSG_MAP(CWWWQuoteApp) // 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() ///////////////////////////////////////////////////////////////////////////// // CWWWQuoteApp construction CWWWQuoteApp::CWWWQuoteApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // The one and only CWWWQuoteApp object CWWWQuoteApp theApp; // Database logins // and resource type names // these are some of our // favorite strings // You might need to change szConnectString to be appropriate for your // database and database server. static const TCHAR szConnectString[] = _T("UID=sa;PWD=;"); static const TCHAR szHTMLType[] = _T("CustomHTML"); ///////////////////////////////////////////////////////////////////////////// // CWWWQuote theExtension; BEGIN_PARSE_MAP(CWWWQuote, CHttpServer) DEFAULT_PARSE_COMMAND(Quote, CWWWQuote) ON_PARSE_COMMAND(Quote, CWWWQuote, ITS_EMPTY) ON_PARSE_COMMAND(Issues, CWWWQuote, ITS_PSTR) ON_PARSE_COMMAND_PARAMS("Method") ON_PARSE_COMMAND(GetQuotes, CWWWQuote, ITS_PSTR ITS_I4 ITS_I4 ITS_I4 ITS_I4 ITS_I4 ITS_I4) ON_PARSE_COMMAND_PARAMS("Ticker=~ Month=0 Year=0 MinMonth=0 MinYear=0 MaxMonth=0 MaxYear=0") ON_PARSE_COMMAND(PreviousMonth, CWWWQuote, ITS_PSTR ITS_I4 ITS_I4 ITS_I4 ITS_I4 ITS_I4 ITS_I4) ON_PARSE_COMMAND_PARAMS("Ticker Month Year MinMonth MinYear MaxMonth MaxYear") ON_PARSE_COMMAND(NextMonth, CWWWQuote, ITS_PSTR ITS_I4 ITS_I4 ITS_I4 ITS_I4 ITS_I4 ITS_I4) ON_PARSE_COMMAND_PARAMS("Ticker Month Year MinMonth MinYear MaxMonth MaxYear") END_PARSE_MAP(CWWWQuote) CWWWQuote::CWWWQuote() { } CWWWQuote::~CWWWQuote() { } BOOL CWWWQuote::LoadLongResource(CString& str, UINT nID) { HRSRC hRes; HINSTANCE hInst = AfxGetResourceHandle(); BOOL bResult = FALSE; hRes = FindResource(hInst, MAKEINTRESOURCE(nID), szHTMLType); if (hRes == NULL) ISAPITRACE1("Error: Resource %d could not be found\r\n", nID); else { DWORD dwSize = SizeofResource(hInst, hRes); if (dwSize == 0) { str.Empty(); bResult = TRUE; } else { LPTSTR pszStorage = str.GetBufferSetLength(dwSize); HGLOBAL hGlob = LoadResource(hInst, hRes); if (hGlob != NULL) { LPVOID lpData = LockResource(hGlob); if (lpData != NULL) { memcpy(pszStorage, lpData, dwSize); bResult = TRUE; } FreeResource(hGlob); } } } #ifdef _DEBUG if (!bResult) str.Format(_T("Could not find string %d"), nID); #endif return bResult; } void CWWWQuote::WritePageTitle(CHttpServerContext* pCtxt, UINT nID) { CString strTitle; CString strAddOn; strTitle.LoadString(IDS_PAGE_TITLE); if (strAddOn.LoadString(nID)) { strTitle += ": "; strTitle += strAddOn; } *pCtxt << ""; *pCtxt << strTitle; *pCtxt << ""; } void CWWWQuote::Quote(CHttpServerContext* pCtxt) { StartContent(pCtxt); WritePageTitle(pCtxt, IDS_WELCOME); CString strOutput; LoadLongResource(strOutput, IDS_HTML_WELCOME); *pCtxt << strOutput; EndContent(pCtxt); } void CWWWQuote::WriteIssuesHeader(CHttpServerContext* pCtxt) { CString strOutput; LoadLongResource(strOutput, IDS_ISSUES_HEADER); *pCtxt << strOutput; } void CWWWQuote::Issues(CHttpServerContext* pCtxt, LPCTSTR pszMethod) { StartContent(pCtxt); WritePageTitle(pCtxt, IDS_ISSUES); BOOL bByCUSIP; CString strOutput; if (_tcscmp(pszMethod, _T("ByCUSIP")) == 0) bByCUSIP = TRUE; else if (_tcscmp(pszMethod, _T("ByName")) == 0) bByCUSIP = FALSE; else { LoadLongResource(strOutput, IDS_HTML_LOOKUPMETHOD); *pCtxt << strOutput; EndContent(pCtxt); return; } try { CDatabase db; CString strConnect(szConnectString); strConnect += "DSN=Stock Quotes;"; if (!db.OpenEx(szConnectString, CDatabase::openReadOnly | CDatabase::noOdbcDialog)) { *pCtxt << _T("ODBC Datasource 'Stock Quotes' could not be opened
\r\n"); *pCtxt << _T("Did you set it up as a system data source?
\r\n"); } else { CIssueQuery IssueQuery(&db, bByCUSIP); if (IssueQuery.Open()) { if (IssueQuery.IsBOF()) *pCtxt << _T("Sorry, no issues are available at this time.
\r\n"); else { LPCTSTR pszText; BOOL bFirstRow = TRUE; while (!IssueQuery.IsEOF()) { if (bFirstRow == TRUE) { WriteIssuesHeader(pCtxt); bFirstRow = FALSE; } if (bByCUSIP) pszText = IssueQuery.m_strCUSIP; else pszText = IssueQuery.m_strName; strOutput.Format(_T("