/***************************************************************************** * * Copyright (c) 1999, KL GROUP INC. All Rights Reserved. * http://www.klgroup.com * * This file is provided for demonstration and educational uses only. * Permission to use, copy, modify and distribute this file for * any purpose and without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies, and that the name of KL Group not be used in advertising * or publicity pertaining to this material without the specific, * prior written permission of an authorized representative of * KL Group. * * KL GROUP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. KL GROUP SHALL NOT BE LIABLE FOR ANY * DAMAGES SUFFERED BY USERS AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ #ifndef STRICT #define STRICT #endif #include #include #include #include #include #include #include #include "olch2d.h" #include "cashflow.h" #include "qrtrdata.h" /***************************************************************************************************************************/ /* GetQuarterData() - Creates a QuarterData struct with data for the quarter summary chart. In this demo it is hard-coded * to return data for the first quarter 1996, and get the data from specific files. It uses XrtDataCreateFromFile() to create * six XrtDataHandle's (income and expenses for three months); creates another XrtDataHandle using XrtDataCreate() which is * initialised with the quarter summary data on the fly from the first six XrtDataHandle's. The quarter data structure * returned must be freed with a call to FreeQuarterData(). */ QuarterData* GetQuarterData(){ int i; QuarterData* pQuarterData; double d1, d2, d3, d4; char buf[100]; /* Allocate zeroed QuarterData struct. */ if(!(pQuarterData=(QuarterData*)calloc(1,sizeof(QuarterData)))){ MessageBox(NULL,"Memory allocation failure.","CashFlow - GetQuarterData()",MB_OK|MB_ICONEXCLAMATION); return NULL; } /* This demo is hardcoded to first quarter 1996. */ pQuarterData->quarter=QUARTER1; pQuarterData->year=1996; /* Create XrtDataHandle's and load income data. */ if(!(pQuarterData->income[MONTH1] = XrtDataCreateFromFile("JAN96INC.DAT",buf))){ MessageBox(NULL,"Cannot find file: JAN96INC.DAT.","CashFlow - GetQuarterData()",MB_OK|MB_ICONEXCLAMATION); FreeQuarterData(pQuarterData); return 0; } if(!(pQuarterData->income[MONTH2] = XrtDataCreateFromFile("FEB96INC.DAT",buf))){ MessageBox(NULL,"Cannot find file: FEB96INC.DAT.","CashFlow - GetQuarterData()",MB_OK|MB_ICONEXCLAMATION); FreeQuarterData(pQuarterData); return 0; } if(!(pQuarterData->income[MONTH3] = XrtDataCreateFromFile("MAR96INC.DAT",buf))){ MessageBox(NULL,"Cannot find file: MAR96INC.DAT.","CashFlow - GetQuarterData()",MB_OK|MB_ICONEXCLAMATION); FreeQuarterData(pQuarterData); return 0; } /* Allocate XrtData structs and load expense data. */ if(!(pQuarterData->expenses[MONTH1] = XrtDataCreateFromFile("JAN96EXP.DAT",buf))){ MessageBox(NULL,"Cannot find file: JAN96EXP.DAT.","CashFlow - GetQuarterData()",MB_OK|MB_ICONEXCLAMATION); FreeQuarterData(pQuarterData); return 0; } if(!(pQuarterData->expenses[MONTH2] = XrtDataCreateFromFile("FEB96EXP.DAT",buf))){ MessageBox(NULL,"Cannot find file: FEB96EXP.DAT.","CashFlow - GetQuarterData()",MB_OK|MB_ICONEXCLAMATION); FreeQuarterData(pQuarterData); return 0; } if(!(pQuarterData->expenses[MONTH3] = XrtDataCreateFromFile("MAR96EXP.DAT",buf))){ MessageBox(NULL,"Cannot find file: MAR96EXP.DAT.","CashFlow - GetQuarterData()",MB_OK|MB_ICONEXCLAMATION); FreeQuarterData(pQuarterData); return 0; } /* Allocate an XrtData struct for summary data. */ if(!(pQuarterData->hSummaryData=XrtDataCreate(XRT_DATA_ARRAY,2,3))){ FreeQuarterData(pQuarterData); return 0; } /* Calculate summary data from income and expense data. */ XrtDataSetXElement(pQuarterData->hSummaryData, 0, MONTH1, (double)0); XrtDataSetXElement(pQuarterData->hSummaryData, 0, MONTH2, (double)1); XrtDataSetXElement(pQuarterData->hSummaryData, 0, MONTH3, (double)2); for (i=MONTH1; i<=MONTH3; i++) { d1 = XrtDataGetYElement(pQuarterData->income[i], SALARY, 0); d2 = XrtDataGetYElement(pQuarterData->income[i], INVEST, 0); XrtDataSetYElement(pQuarterData->hSummaryData, INCOME, i, (d1 + d2)); } for (i=MONTH1; i<=MONTH3; i++) { d1 = XrtDataGetYElement(pQuarterData->expenses[i], HOUSING, 0); d2 = XrtDataGetYElement(pQuarterData->expenses[i], AUTO, 0); d3 = XrtDataGetYElement(pQuarterData->expenses[i], TAXES, 0); d4 = XrtDataGetYElement(pQuarterData->expenses[i], FOOD, 0); XrtDataSetYElement(pQuarterData->hSummaryData, EXPENSES, i, (d1 + d2 + d3 + d4)); } return pQuarterData; } /***************************************************************************************************************************/ void FreeQuarterData(QuarterData* pQuarterData){ int i; if(pQuarterData){ if(pQuarterData->hSummaryData){ XrtDataDestroy(pQuarterData->hSummaryData); pQuarterData->hSummaryData=0; } for(i=0;iincome[i]){ XrtDataDestroy(pQuarterData->income[i]); pQuarterData->income[i]=0; } if(pQuarterData->expenses[i]){ XrtDataDestroy(pQuarterData->expenses[i]); pQuarterData->expenses[i]=0; } } free(pQuarterData); pQuarterData = 0; } } /***************************************************************************************************************************/