?? submission.html
字號:
<!--#include virtual="header.shtml" -->
<!--#include virtual="/global/getCss.inc" --><CENTER><H3><FONT COLOR="#AOAO99">
Easy! Reports</FONT></H3></CENTER><HR>
<!-- Author and contact details -->This article was contributed by
<A HREF="mailto:vipullal@hotmail.com">Vipul Lal</A>.
<!-- Sample image - gif or jpg --><P><IMG SRC="[image filename here]" >
<!-- For which environment is this code specific??? -->
<p><u>Environment:</u> VC6<p>
<!-- The 'p' starts a paragraph of normal text -->
<p>
One of the problems while writing programs in C++ is that the tools and API that one can use to generate reports is very limited. For instance, there are a plethora of classes to view (CView, CHtmlView etc.) but no reporting API.
<p>
The present tool here is a simple API that can be used to print fairly complex business style reports.
<p>
Almost all reports have the following standard elements:
<ol>
<li>
A Report header. Typically, this is the establishment name, business address etc. The report header is printed only on the first page of the report.
</li>
<li>
The page header. This generally consists of the report title, e.g. "Payroll Summary" and a date. This page header is printed on every page of the report.
</li>
<li>
The page header is followed by one or more tabular sections. For instance, a payroll summary may include employee names and their salaries grouped by their department. There may be several sections, one for each department. Each group may be followed by a summary section, summarizing the data for that group.
</li>
<li>
The data section is followed by a page footer. This page footer generally consists of a page number. The page footer is generally printed on every page.
</li>
<li>
The page footer is optionally followed by the Report footer. This report footer is printed only on the last page.
</li>
</ol>
<p>
Given the above, we present a simple yet powerful layout class. This class is called "CEasyReport". There are basically three functions that are really the key.
<ol>
<li>
"SetDataCols", which starts a new tabular section. The arguments are a array of CColInfo items describing each column in the section. The description includes the column name, the column width and alignment. The column name can contain '\n', which sets up a multiple row column heading.
<li>
"AtTab(int, CString)". This is the workhorse function which can be used to print text in columns. The first parameter is the column number and the second character is the text to be printed. For instance, if your tabular section consists of a "Name" column and a "Date of Birth" column, you would print the name using:
<pre>
AtTab(0,"Lal, Vipul"); // write the name in col 0
AtTab(1,"12/04/1980"); // write DOB in col 1
</pre>
We could have overloaded this function to print a long, double, a CTime etc, but we left that to the user to suit his/her own requirements.
</li>
<li>
Call "NextRow" to advance the printing to the next row. Typically, you would do this when you have printed all the columns in one row. This function checks to see if there is enough space on the current page to print another row, and ejects the page if not.
</li>
<p>
</ol>
Whenever you need to start a new section, simply call SetDataCols. Thus, if your report consists of a main section followed by a summary section for each group, your typical code loop would be:
<pre>
m_Recordset.Open(...);
while(! m_Recordset.IsEof())
{
SetDataCols(ColsInMainSection...)
m_CurGroup = m_Recordset.GroupColumnData;
do
{
AtTab(0,DataForGroupCol);
... other columns...
NextRow(); // advance the printer row
m_Recordset.next;
// compute summary items
}
while( !m_Recordset.IsEof() &&
m_Recordset.GroupColumnData == m_CurGroup);
// Start a summary section...
SetDataCols(ColsInSummarySection);
AtTab(...); // print summary data
NextRow();
}
</pre>
<p>
While generating a report content, no actual image is generated. Rather, the generation process simply generates "report objects". For instance, a CTextObject contains the text to be written and the rectangular co-ordinates for the text. Thus, every page consists of a set of "report objects". Later, when we are called to print or preview the report, we simply call upon the report object to draw itself. Since every such object has the co-ordinates with respect to the top of the page, we can draw any page. Thus, the user can select to print or preview page 3,5 and 7 of the report and we simply draw all objects for those pages. The current version supports a Text object, a Line object and a Date and PageNumber object.
<p>
Note: The current version simply generates these report objects in memory. You might want to serialize these to disk if the report is really long.
<p>
The API has a "RepeatHdr" flag, which forces the column headings to be printed on every page. When this flag is off, the column header is printed every time the tabular section is set up.
<p>
The report also has "SuppressBlankHdr" flag. When this flag is set, the column headings are not printed unless you print something in one of the columns.
<p>
The report also has a "word-wrap" mode in which one can print a "paragraph" of text. The text is aligned within the page margins.
<p>
Please do feel free to email me your suggestions, comments and bug fixes.
<!-- create more blocks of article text as needed separated -->
<!-- with the <p> HTML tag --><!-- start a block of source code --><PRE>
[your source code goes here]<!-- end the block of source code --></PRE>
<h3>Downloads</h3><!-- demo and source files -->
<A HREF="[demo project zip file name here]">
Download demo project - [size in KB] Kb</A><BR>
<A HREF="[source code zip file name here]">Download source - [size in KB] Kb</A>
<h3>History</h3>Date Posted: [today's date in the format month day, year]<BR>
<!-- Only use the following if the article is updated -->
<!-- Date Last Updated: [today's date in the format month day, year] -->
<!--#include virtual="footer.shtml" -->
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -