Deep QuickReport (2)

zhaozj2021-02-12  129

Deep QuickReport (2)

Author: Dongwei Chun

(This article has been published in the "9CBS Development Master" in the first, second and third phases, and the requirements of the majority of netizens, published in the 9CBS Author's document, which is slightly modified, but only here, not After 9CBS or author I agree with any individual and website must not be reproduced, you can take it, otherwise any of the consequences involved in copyright.

Part II: Deeply enter the Quickreprot routine

In the application, progress in practice, this is the biggest feeling I learned QuickReport, through the above introduction, I think you have a certain understanding of QuickReport, then next, we will pass the routine to gradually depth QuickReportj

Example 1: TquickRep, TQRLABEL, TQRDBText Components Application Practice is the best teacher, let's take a look at the quick and convenientness of the QR. 1) Create a new project. 2) Put a TTABLE to FORM, here we use the database from BCB. DatabaseName is set to bcdemos, TableName points to the Customer table, and Active is set to True. 3) Put a TQUickRep Control On Form, the DataSet property is Table1 (ie, the content to which Table1 is to be displayed). 4) Expand the tquickrep's bands property, set Hasdetail to True, then automatically add a Detail Band (a TQRBAND control, you can also put a TQRBAND control directly, the BandType property is set to RBDetail). This section is a repeating section. 5) Put a TQRLabel and the TQRDBText control on the detail band, TQRLabel's CAPTION property is set to "Company:" two words; tqrdbtext's DataSet points to Table1, Datafield points to Company. 6) Select the TQUickRep control (do not refer to the section), press the right button, select "Preview" Preview, you should see all field values ​​in the table Customer field Company. It is OK to this simple example. But after this program you compile, you will get the same QuickReport component as you arrange, you can't see the content you want. The program is to implement the effect of the preview that can only take advantage of TQRUickRepReprep, we only need to add a button in Form, write on its OnClick event: QuickRep1-> preview (); it is possible. No one wants the tquickrep component that does not display the form, which also tells us that there are two forms in our program: one is placing the control QuickReport display, print, or implement other functions, such as this example Place the control button; one is provided to the QuickReport layout component.

Of course, this is not to say that in a form that does not have the above functions, in fact, you can hide the tquickRep component in the form's oncreate event:

Void __fastcall tform1 :: form1create (TOBJECT * SENDER)

{

QuickRep1-> hide ();

}

Note that QR You can't use Show () call, then you will not get the program you want, of course, it is not wrong with preview (). Here are the program source code of this example: #pragma package (smart_init)

#pragma resource "* .dfm"

TFORM1 * FORM1;

/ / -------------------------------------------------------------------------------------------- ---------------

__fastcall tform1 :: tform1 (tComponent * Owner)

: TFORM (OWNER)

{

}

/ / -------------------------------------------------------------------------------------------- ---------------

Void __fastcall tform1 :: form1create (TOBJECT * SENDER)

{

QuickRep1-> hide ();

}

/ / -------------------------------------------------------------------------------------------- ---------------

Void __fastcall tform1 :: button1click (Tobject * Sender)

{

Quickrep1-> preview ();

}

/ / -------------------------------------------------------------------------------------------- ---------------

Further think: Sometimes we want to achieve vertical output, such as using the contents of TQRLabel we want to display whether it can be achieved vertically?

Of course it can be realized. As long as we set up as follows:

AutoSize = false; // Default to TRUE

AutoStrech = true; // default is false

WordWrap = true; // default is true, this is the focus of the settings, which is the same as the settings in Label.

CAPTION value should be noted that there must be space between each character; // General setting We will not leave the space, because the design space is not beautiful, there is no practical meaning, but here must stay space here

Further think: How should we do it with two decimal numbers? As long as the Mask property of the visualization component is set to 0.00.

Example 2: Application of TQRGROUP, TQREXPR Components

The statement first lists the state name, then lists all the companies and the total number of companies in the state, one state is listed in the next line (group interrupted), listing the new state name, then listed all companies under the new, did not fill in The company's company is unified in "I don't know what region" below. 1) Create a project. 2) Playing a TQuery on TFORM, its SQL property is: Select * from customer Order by State, Company, according to state, company sorting, DatabaseName is bcdemos, Active is True. 3) Put a TQUickRep control on Form1, Dataset is query1. 4) Place a TQRBAND in tquickrep, set its BandType to RBDetail.

5) Put a TQRGROUP control on TquickRep, then the default is Group Header. (This header will print out when Group is interrupted or higher, this header will print out. If there is an expression, according to the value of the expression), then add a Group Footer Band, but we can't find such one Component, how should I design a Group Footer Band section? Just put a Qrband2 in the report, point the TQRGroup's FooterBand attribute points to Qrband2. Look, Qrband2 is not a Group Footer Band. (An important feature of TQRGroup is an expression. When the value of the expression changes, Group will be interrupted. If the expression is listed in the city name, Liaoning Province is listed in Liaoning Province. After the expression value changes, the Group is interrupted, then the city name of other provinces), the EXPRESSION attribute of TQRGROUP1 is set to query1.state (interrupt according to different states). Note: Why don't you put a TQRGroup directly, because no matter how many systems we put, you will default to Group Header. 6) Put a TQREXPR control on the Group header, its expression attribute is: if (query1.state <> ', query1.state,' unclear what is the area '), that is, if the company's state is not filling, "Don't know what areas", otherwise you will be classified into specific states. 7) Put three tqrdbtext on detil, their DataSet points to Query1, DataField points to Company, Contact, Phone, respectively. 8) Place another TQREXPR control over the Group Footer Band, Expression is query1.state 'total:' str (count) 'company', the role is to show how many people in this state after each state company A company. 9) Place the mouse on the QuickRep component (cannot be placed on the BAND section), press the right to select the preview, you should see the different state names and its company name and the total number of companies.

Note: Everyone finds that it is not the total number of companies. Every state is listed after each state, and the total number of the last state is also added. Is it wrong, no, check your Expression? If the property value of the resetAfterPrint of the component (running count) is True, if not changed him to True, look at J

Further think: Every group of content is connected together, some are unhappy, if each group is separated from what is separated?

In fact, this is not difficult to achieve, we can set it to true if we set the Qrband2 (Group Footer) Haschild property. Of course, you directly put a TQRCHILDBAND component on QuickRep1, set her ParentBand property to QRBAND2, and you can also implement the above settings. In addition, we can also arrange other visual components in tqrchildband.

Further think: If you change the page after each group, isn't it more cool?

As long as we change the QRGroup1's ForceneWPage property, it is possible, and the same components have a ForceneWColumn. But must pay attention to, we have changed the two properties of which segment, starting from NewPage / NewColumn. Example 3, TQUickRep component's Page property application

PVC badges have some friends have seen it. Don't be too difficult to do such a card. Recently, the author participated in a bunch of badges. Here we have to talk about the design of the card.

1) Create a project.

2) Place a Table component and point it to our resource database and set Active to True.

3) Place a TQUickRep component on Form1 and set it to table1, put a tqrband on her, set its BandType value to RBDetail. Place four TQRLABEL components in the BAND section, three TQRDbText components with a TQRDBIMAGE component.

4) The three TQRDBText components are basically the same, specify the DataSet as Table1, and then select the correct field from DataField. We can set the related properties of TQRDBImage.

5) Setting up the page, which is the key. We can't print one on a piece of paper, the more you print, the more you do, the left is finished, and you can continue to print in the right, so you can make full use of raw materials. We used the columns here to set the Number of Columns attribute to 2, which is divided into two columns. Use the components in tquickRep Report Settings to open the Page Properties Editor window, do the following settings:

Where Pager Size is selected as custom, in the size of the paper, other settings can be described above. Of course, we can also clicking the Edit button left end of the Page property on the Object Viewer window to expand its attribute value for the correct setting, as shown below:

6) The Width of TQRBAND is set to 228 and then re-adjusted the position of the component on the BAND. 228 is actually obtained from 38 × 6.

7) Place the mouse on the QuickRep component (cannot be placed on the BAND section), press the right button to select the preview, look at the effect.

Difficulties: For the convenience, accurate, the TQUickRep component provides coordinates (one piece, with numbers on the side, will not tell me, I didn't see it J), from the paper settings we know each of these coordinates 10mm, but in the QR, there is no unit in many components. For this 10 mm, the corresponding unit length is 38, you must remember this.

Through three examples above, we can have some simple report design. From Example 4, we will learn further QUICKREPORT. The following routines are only on key points, focusing on analyzing, omitting some repetitive languages.

Example 4, Master / Detail Report, Application of TQRSUBDetail Components

Two points of design master / detail reports: One is the connection of the main / detail data sheet; the other is the correct use of the TQRSUBDetail component.

Labor-slave data table connection diagram 1 (TTABLE and TTABLE)

MASTER Table Related Detail Table

Component name TTable TdataSource1 TTable

Important attribute name <=== Dataset NametAblename Name <==== Datasource

Dabasename <=== pointing to the same library name ==> dabasename

(Specify Index Field) IndexfieldName Masterfield (click on the right "..." to call up the Field Link Designer dialog box, set the related fields)

Active <======= is set to true ========> Active

Labor-slave data sheet connection diagram 2 (TTABLE and TQUERY)

MASTER Table Related Detail Table

Component name TTable TDataSource1 TTQuery

Important attribute Name <=== Dataset Name

Tablename name <==== DataSource

Dabasename <=== pointing to the same library name ==> dabasename

(Specify Index Field) IndexFieldName SQL (click on the right "..." to call up the String List Editor dialog box to set the related field)

Active <======= is set to true ========> Active

Setting of tqrsubdetail components:

1) The value of Master is set to the name of the TQUickRep component;

2) The value of DataSet is set to connect the component name of the clear table;

3) Click on " " in front of BANDS, expand the attribute, you can see the two properties of Hasfooter and Hasheader, so that we get a pair of groups (of course, we can use other methods).

Note: The Group group generated by the Hasheader, Hasfooter in the TQRSUBDetail property BAN, does not have Expression in Group Header, and they are associated with the associated relationship of the master / schedule by default. In fact, there is no use, TQrsUBDetail is also used.

We build the main / detail report as shown below:

1) Set the data set

Place the TTABLE, TDATASOURCE, TQUERY components on the form, set Table1, Query1's DatabaseName property to bcdemos, set the table1's tablename to Customer.db (main table name), set indexfieldname to index field name Custno. Set DataSource1's DataSet to Table1, prepare for the master / detail data.

Connect the Query1 of the clear table, we set its DataSource to DataSource1 to establish a relationship, and set its SQL properties:

Select * from Orders Where Custno =: Custno ^ ^ ^ ^ ^ ^

|| || || || || ||

Select all fields from the Orders table (slave table) condition to establish a master from the field of the table.

In this way, we have established the association of the list of schedules and the primary table, and the schedule is packet in the above-style relationship, which is the same as the CustNO.

2) Set the report structure

First, place a report component tqucikrep on the previously designed form, expand the BAND attribute in the Object Viewer window, set its HascolumnHeader, Hasdetail, HaspageFooter, HaspageHeader, Hassummary, and Hastitle attribute to True.

Set the QuickRep1's DataSet property to Table1 to specify the data source for the report home table.

Then, put the TQRSUBDetAIL component on the QuickRep1 component as a tomogram. Set its master property to QuickRep1, set Bands Subheater and Hasfooter to True, and set its DataSet property to query1 to specify the source of the schedule data.

3) Set the main body of the main / detail report

Add the report tag components (TQRLABLE) used in the primary tables in the ColumnHeaderBand1 section, and their Caption is the customer number, company, phone, fax, and city. Add a report component (TQRDbText) that displays the primary table field value in the Detailband1 section, set the field corresponding to the previous title, pay attention to their DataSet is Table1.

In the detailed report part, we first place the table head tag (TQRLABLE) in GROUPHEADERBAND1, and their CAPTION is set to set numbers, terms, payment methods, total amount and unpaid amount. Place the component object (tqrdbtext) of the Detail News in the QrsubDetail1 section, and its DataSet property is query11, the field name is ORDERNO, TERMS, PaymentMethod and ItemStotal. Then add a TQREXPR component, set its master property to QRSUBDetail, open the expression editor, enter the following expression:

INT (query1.itemstotal-query1.amounpaid)

Add a statistical report component QRexPR2 in the GroupFooterBand1 section, and set its properties to QRSUBDetail1, open the expression editor, enter the following expression:

Sum (INT (query1.itemstotal-query1.amounpaid))

That is, the total amount of unpaid items is calculated, and the resetAfterPrinter property is TRUE so that the total amount of the fine table can be statistics.

Add a QREXPR3 to the SummaryBand1 section, open the expression editor, enter the following statement:

SUM (int (query1.itemstotal-query1.amounpaid) This subject we have finished, and other settings look at the picture above you should understand.

Let's add the following program code as an example, and one of this complex report.

This example is the main / detail data made with TTable with TQuery, and we can use TTable with TTABLE to do the main / detail data to implement this report.

转载请注明原文地址:https://www.9cbs.com/read-7227.html

New Post(0)