Poročilo z dvema nivojema podatkov (Master-Detail)
Poročilo z dvema nivojema podatkov (Master-Detail)
Do sedaj so naši primeri poročil uporabljali le en podatkovni pas (“Podatki prve ravni” ali ”MasterData”) za nadzor izhoda podatkov. To je bilo zadostno za izhod podatkov iz ene baze podatkov. Pantheon omogoča tudi oblikovanje poročil z do šestimi nivoji podatkov, vse na eni oblikovni strani. Poleg tega je mogoče doseči neomejeno število nivojev podatkov v poročilih z uporabo objekta “Subreport” - ta objekt bo obravnavan kasneje. Večina poročil na splošno potrebuje le en, dva ali tri nivoje podatkov, večje število nivojev podatkov je redko.
Poglejmo, kako oblikovati poročilo z dvema nivojema podatkov. Poročilo bo izhodilo podatke iz tabel: “tHE_SetSubj” in “tHE_Order”. Prva tabela je seznam predmetov in druga je seznam naročil, ki jih oddajo ti predmeti (stranke).
Druga tabela vsebuje seznam vseh naročil, ki jih oddajo vse stranke. Da bi si ogledali naročila iz tHE_Order table which are placed by one customer in the Customers table, the two tables are linked on the “acSubject” field from customers and "acConsignee" field from order table.
Let's design the report. Create a new report and place two “TfrxDlDBTable” components on the form. Set the component properties as shown here:
Table1:
TableName = 'tHE_SetSubj'
UserName = 'Subjects'
Table2:
TableName = 'tHE_Order'
UserName = 'Orders'
Now add a “MasterData” and a “DetailData” band to the page:

Note that the “MasterData” band must be placed above the “DetailData” band! Drag it there if necessary. If the Master is placed under the Detail, Pantheon will generate an error message when you preview the report.
If you previewed the report now, you would see that the list of orders remains the same for every customer and contains all the records from the “Orders” table. In code on the report add two lines as you can also see on the picture

Now we have set a 'Master-Detail' relationship and link between fields in two sources.
When creating the preview FastReport does the following. After a record is output from the master table (Customer), it sets the filter on the detail table (Orders). Only those records which meet the 'Orders.acConsignee = Subjects.acSubject' condition will remain in the table. This means that for each customer only those orders which belong to the current customer will be displayed in the detail band. This is an important concept to grasp. Even though data bands may be of master or of detail type, they only control the positioning of the data on the output page (order and number of times displayed). The data displayed by the objects in the bands is dependent on which fields the objects are linked to and on the external linking of the two tables.
This is the final output:

Reports can containing up to 6 data levels can be constructed in a similar manner.
In a lot of cases Master-Detail relationship is in set up in the program code.
Let's look an example of the report '3C0 - Travel Management Report' that is in the program menu 'Personnel | Travel Management | Reports' .
On the report master table is 'main' table of travel orders, detail table is the table with positions of travel order. In this case we have also one more level (subdetail table) namely costs on the position of travel order.

On this report we have also two bands with "RowCount" property set to value 1 and subreports which we will meet later.