This site is associated with the Yahoo group www.groups.yahoo.com/MCSD_study_group, the site contains details of the currect group project for that group.
The aim of this project is to practice the skills gained as we go through the Microsoft Teach Yourself Kit for Exam 70-016 (Developing Desktop Applications using Visual C++).
The application to be developed is a modified version of the STUpload sample app that is built through the course of the book. This app is called STUProject.
The modifications to be made on the STUpload app are as follows:
1) The app should be web based. That means like this; The app is created from COM components. You can call these from an application or in a web-page. The idea here is to take the COM components and create a web-page or a group of pages that will provide the application's functionality through pages displayed in a web-browser.
It will not initially be possible to implement this untill later on in the book after the creation of the ActiveX components, so initially STUProject is a SDI app.
2)The app should process real financial data on share prices that is available freely on-line from various on-line financial services organisations. STUProject will convert this data into graphical format and upload it to a central data-base as the STUpload application does.
There are many sources of such information
on the internet, one such source is
ftp://www.stockwatch.com.au/pub/txt
3) There are a number of other minor
changes we could make as we go through the development of STUpload such
as the addition of a resizable view, etc. Let's leave deciding what these
should be till we get to the individiual labs that deal with the user-interface
etc.
Group Synchronisation
Please post any alternative ways that you would design the app or the code to the group.
I will upload a copy of the project workspace to the group's file section after each lab so you can carry on from these if you leave out a few labs.
Labs
The order of the labs for the group project
follows the order of the labs for STUpload.
Lab 1
So far, in Lab1 , the only difference between STUpload and STUProject is to change the extension name to .txt as this is the type of file that the app will open.
Lab 3
changes to STUpload in lab 3 for the group project are as follows:
a) as regular share prices text files contain data all from the same
day it is more logical to move the COleDateTime variable from
CStockData to CStockDataList (so that we can date each list instead
of dating each share price)
1) remove all references to the COleDateTime variable from CStockData
2) add a COleDateTime variable to CStockDataList
b) you will now need an array of CStockDataList objects in the
document class to represent the share prices over a number of days.
this is accomplished with a CTypedPtrArray MFC collection class that
stores an array of pointers to CStockDataList objects.
c) the OnDraw() function of the view class is modified to iterate
through the collection of CStockDataList pointers and to display
their date as well as the list of CStockData objects that they
contain.
d) the document class constructor is modified to initilialise the
CTypedPtrArray with dummy data
**********************************************************************
document class constructor:
CSTUProjectDoc::CSTUProjectDoc()
{
for (int i=0;i<3;i++)
{
CStockDataList *pCStockDataList = new CStockDataList;
pCStockDataList->AddTail( CStockData( _T("AAAWXA"),
22.33+i ));
pCStockDataList->AddTail( CStockData( _T("AAA"),
23.44+i ));
pCStockDataList->AddTail( CStockData( _T("AAI"),
24.55-i ));
pCStockDataList->AddTail( CStockData( _T("AAPWMA"),
25.66-i ));
pCStockDataList->AddTail( CStockData( _T("AAP"),
26.77+i ));
pCStockDataList->m_date = (COleDateTime (1999,4,4+i,0,0,0));
m_arStockDataSet.Add(pCStockDataList);
myArray.Add(pCStockDataList);
}
}
view classes OnDraw() function:
void CSTUProjectView::OnDraw(CDC* pDC)
{
CSTUProjectDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// Save the current state of the device context
int nDC = pDC->SaveDC();
// Create font for axis labels
CFont aFont;
if( aFont.
CreateFont( 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
FF_MODERN, 0 ))
pDC->SelectObject( &aFont );
else
{
AfxMessageBox( "Unable to create font" );
return;
}
int numStockDataLists = pDoc->GetNumberStockDataLists();
int yCoord=10;
for(int i=0;i<numStockDataLists;i++)
{
const CStockDataList *pointerData = pDoc-
>GetStockDataList(i);
const CStockDataList &pData = *pointerData;
const COleDateTime date = pData.m_date;
CString strDate = (pData.m_date).Format( "%m/%d/%Y" );
pDC->TextOut( 10, yCoord, strDate);
int nTextHeight = pDC->GetTextExtent( "A" ).cy;
yCoord += nTextHeight;
int yPos = yCoord;
POSITION pos = pData.GetHeadPosition();
while( pos )
{
CStockData sd = pData.GetNext( pos );
pDC->TextOut( 10, yPos, sd.GetAsString() );
yPos += nTextHeight;
}
yCoord=yPos+nTextHeight;
}
// Restore the original device context
pDC->RestoreDC( nDC );
}
Lab 4
Lab 4, implementing the user-interface, is the same for this project as it is for the Microsoft application.
This is because the applications only in their internal design but not in their output.
Lab 5
Lab 5 implements the display of the app, therefore the only change for Lab 5 is in the OnDraw() function of the view class.
Because information on each fund is held in a number of different
CStockDataList lists, you have to iterate through the collection of
CStockDataLists in order to get all the prices of each fund.
The beginning of the OnDraw() function is therefore modified as
follows:
void CSTUProjectView::OnDraw(CDC* pDC)
{
//Create two new temporary arrays to hold
//the date of the Stock Data List and the
//price of the fund on that date
CArray <COleDateTime, COleDateTime> arrDates;
CArray <double, double> arrPrices;
arrDates.RemoveAll();
arrPrices.RemoveAll();
int nPrices = 0;
int yCoord=10;
//Get the number of Stock Data Lists that are
//held in the typed pointer array in the document class
int numStockDataLists = pDoc->GetNumberStockDataLists();
//Now loop through the arrays to get the dates and prices
//of the current fund
for(int k=0;k<numStockDataLists;k++)
{
const CStockDataList *pointerData = pDoc->GetStockDataList(k);
const CStockDataList &pData = *pointerData;
const COleDateTime date = pData.m_date;
arrDates.Add(date);
double price = pData.GetPriceOfFund( strCurrentFund);
arrPrices.Add(price);
nPrices++;
}
//The rest of the code is the same as the microsoft app
//with the substitution of the price and date arrays
//for the CStockData array in the microsoft code
Lab 6
getting the group project data serialized proved to be a little
tricky. the problem is like this:
the data in this application is held in an array of CList derived
lists.
each CList represents the closing prices of one day.
in order to identify which day the prices refer to, a COleDateTime
variable is added to the CList lists.
now...
you can serialize a CList of simple data types using the
CList::Serialize() member function
CList::Serialize() calls CList::SerializeElements() to serialize all
the elements of the list.
furthermore, if the CList is comprised of complex data types then can
write your own version of the SerializeElements() function using the
function template.
template <> void AFXAPI SerializeElements <CMyClass>
(CArchive& ar, CMyClass * pNewMC, int nCount)
{
for (int i = 0; i < nCount; i++, pNewMC++)
{
// Serialize each CMyClass object
pNewMC->Serialize(ar);
}
}
now, what happens when not only is the CList comprised of complex
data types, as it is in the group project application, but it also
contains an additional variable that has to be serialized?
the COleDateTime variable can not be serialized using the
SerializeElements() template because, in the template, you have to
follow the template signature and you cannot pass in any additional
variables other than the type of object that is held in the list.
you could change the data structure of the application and, instead
of having the COleDateTime object as a member of the CList, instead
create a CObject derived object that would have the CList and the
COleDateTime objects as members variables. you could then serialize
the CList and COleDateTime variables seperately.
however doing this would require re-designing the entire app.
Lab 7
changes to the STUProject for lab 7 - adding database support are as
follows:
1) the SQL database is comprised of one table. the primary key for
this table is the fund name, the other columns contain the closing
prices. (this table is available for download from the group project
web-site.)
2) as a result, the query string in
CSTUProjectDoc::OnDataQuerydatabase()
changes to:
CString fromdate;
fromdate = aQDlg.m_fromdate.Format("%Y%m%d" );
// Construct query
CString strQuery = "select fund, [";
strQuery += fromdate;
strQuery += "] from tblClosingPrices;";
- this returns all the closing prices for the date selected.
this enables you to check for duplicate data from the same date
before uploading data to the central data-base.
3) the query dialog box is also modified to contain only one date-
time picker control, as the information returned from the database
represents only one date and not a range of dates.
4) the ADO data control's record source command text is modified to
connect to retreive data from the new database that is constructed
from the stockwatch.com's text files.
Downloads
Comments
Please post to
MCSD_study_group@yahoogroups.com