OOFILE | Downloads | Purchasing | Press | Services | Company Information | Soapbox | References | F.A.Q. | HOME

OOFTST 14 - HTML reports

ooftst04 introduced us to report writing. We carry it on from here to reports suitable for html documents.


#include "oofile.h"	// the general oofile library
#include "oofhtml.h"    // contains functions for creating html reports
#include "ooftst01.h"	// the declarations for the database classes we will be using in this test.
  
int main()
{
	cout << "OOFILE Validation Suite - Test HTML\n"
		 << "Simple test of the HTML Report Writer\n";

We must first declare our database and table 

	dbConnect_ram    theDB;
	dbPeople     People;  

Here we create the database and add the test data, having it initially sorted by lastName

	theDB.newConnection();
	People.AddTestData();
	People.setSortOrder(People.LastName);
	  
	cout << "This test produces the columnar and pagewise reports in two variants," << endl
	<< "first using plain HTML then using the Netscape tables" << endl << endl	
	<< "Producing simple HTML Columnar report to oofts14a.htm...";

You can only pass dbViews to a report, so here we must declare ours. 

Note: Passing in false is faster to avoid cloning an iterator HACK for this release only

	dbView theView(People, false); 
	theView << People.LastName << People.OtherNames << People.Description;   

We now create an ofstream to the file we wish to use.

	ofstream fs("oofts14a.htm");

Now it's time to declare the report. We want it to be in html so must use the declaration dbRepHTML instead of ooftst04 where we just used dbRep. Note that the rest of the report is declared in much the same way.

Here we declare a columnar report and must specify each column width and pass in the dbView of which fields we actually want in each column.

Testing: HTML report - columnar

	dbRepHTML tempReport(dbRepSizer("Demo Columnar Report").pageHeight(80),
					dbRepColWidths() << 10 << 15 << 50, theView);

Now we ask the report to be drawn by using draw(), then close the file's stream with close().

	tempReport.draw(fs);
	fs.close();

Now we create a new output stream file.

 	cout << endl << "Creating a PageWise report to oofts14b.htm"<< endl;	
	ofstream fs2("oofts14b.htm");

Here we declare a pagewise report. We still must specify each column width and pass in the dbView, but must also specify we want it to be pagewise by puttingdbRep::pageWise at the end.

Testing: HTML report - pageWise

	dbRepHTML tempReport2(dbRepSizer("Demo Page-wise Report").pageHeight(80),
					 dbRepColWidths() << 15 << 60,theView, dbRep::pageWise);

Now we ask this report to be drawn by using draw(), then close this second file's stream with close().

	tempReport2.draw(fs2);
	fs2.close();
	
  

Now we are going to test the use of 'dbRepTable's. As you can see, these are declared nearly identically to the reports as above, but will create an html table on the page instead of just a columnar list.

??????????? check this!!!

First we create another output stream file.

 	cout << endl << "Creating a Columnar report to oofts14c.htm"<< endl;
	ofstream fs3("oofts14c.htm");

Then we declare a columnar report and must specify each column width and pass in the dbView of which fields we actually want in each column. The only difference to the reports above is that we specify it as being a 'dbRepHTMLTable' instead of just a 'dbRepHTML'.

Testing: HTML table - columnar

	dbRepHTMLTable tempReport3(dbRepSizer("Demo Columnar Report").pageHeight(80),
					dbRepColWidths() << 10 << 15 << 50, theView);

Now we ask for our table to be drawn by using draw(), then close the file's stream with close().

	tempReport3.draw(fs3);
 	fs3.close();
	  

We must create another output stream file.

 	cout << endl << "Creating a PageWise report to oofts14d.htm"<< endl;
		ofstream fs4("oofts14d.htm");

Here we declare a pagewise table report. We still must specify each column width and pass in the dbView, but must also specify we want it to be pagewise by puttingdbRep::pageWise at the end. Again, the only difference to the reports above is that we specify it as being a 'dbRepHTMLTable' instead of just a 'dbRepHTML'.

Testing: HTML report - pageWise

	dbRepHTMLTable tempReport4(dbRepSizer("Demo Page-wise Report").pageHeight(80),
					 dbRepColWidths() << 15 << 60,theView, dbRep::pageWise);

Now we ask for this table to be drawn using draw(), then close the file's stream with close().

	tempReport4.draw(fs4);
 	fs4.close();
	  
	cout << "done" << endl;  
	return EXIT_SUCCESS;
}        

 

Feature index

(c) Copyright A.D. Software 1994-2000 (All Rights Reserved).
Last Updated: 9th September 2001