OOFILE | Downloads | Purchasing | Press | Services | Company Information | Soapbox | References | F.A.Q. | HOME |
Shows two forms of report output. Keep the ooftest4.sav to compare against the ooftest4.out you will produce.
The include files are:
#include "oofile.h" // the general oofile library #include "oofrw.h" // Report writer library #include "ooftst02.h" // the declarations for the database classes we will be using in this test.
These are the global variables that define the database using the ooftst02 classes. We define, here, the database, both tables and the relationship between the two tables.
dbConnect_ram theDB; dbPatients Patients; dbVisits Visits; dbRelationship PatientVisits(Patients.Visits, Visits.Patient);
int main()
{
cout << "OOFILE Validation Suite - Test 4\n"
<< "Simple test to demonstrate use of the report-writer" << endl
<< "using the database from ooftest2 and output to a file" << endl;
Here we create the database and add the test data.
theDB.newConnection(); Patients.AddTestData();
We set the sort order. We then declare a stream (named "ooftst04.out") to send our output to. This means that we can send information or dbViews to this stream and it will be saved in the above-mentioned file for later perusal.
Patients.setSortOrder(Patients.LastName);
cout << "Listing records to ooftst04.out...";
ofstream fs("ooftst04.out");
We then create a dbView. By default, a dbView will clone a dbTable so it can iterate the table independently, but a dbView it should not affect the current dbTable from which it is initialised, passing in false prevents that cloning. This is a hack until we fix the dbView copy constructor.
After creating the dbView we pass in the fields we wish to list.
Testing: creation of dbView passing in false
dbView theView(Patients, false); theView << Patients.PatientNo << Patients.LastName << Patients.Salary;
Here we specify our report. First, we pass in the name of our report and then the page height. This is an example of a columnar report so it we specify the column widths by passing the sizes into dbRepColWidths(). It uses the fields in the dbView as the three columns and this must be passed in after the column sizes.
Testing: creation of columnar report
dbRepChar tempReport(dbRepSizer("Demo Columnar Report").pageHeight(80),
dbRepColWidths() << 8 << 10 << 30, theView);
Now the report is printed by using the draw() command. Note that we specify that we wish to draw it to the output stream declared earlier.
Testing:
Drawing of columnar report to ofstream
Testing: function draw()
tempReport.draw(fs);
fs << endl << endl << "Repeating the report with the same data view"<< endl << endl;
To specify that a report is pagewise, we merely declare dbRep::pageWise. Note that we do not pass in column widths, here, we just pass the report the dbView.
Testing: creation of
pageWise report
Testing: function
dbRep::pageWise
dbRepChar tempReport2(dbRepSizer("Demo Columnar Report").pageHeight(80),
theView, dbRep::pageWise);
We use draw() again to print the report, specifying that we want it to print to the output stream declared earlier.
Testing: Drawing of pageWise report to ofstream
tempReport2.draw(fs);
We then close up the output file before the program ends using close().
fs.close();
cout << "done" << endl;
return EXIT_SUCCESS; }
(c) Copyright A.D. Software 1994-2000 (All Rights Reserved).
Last Updated: 9th September 2001