Introduction to Rave Reports

zhaozj2021-02-12  155

Introduction to Rave Reports - Part IV: More Data Aware Reports

In Part III we have explored the data aware capabilities of Rave Reports, using the Driver Data View. On Part IV we are going to learn how to use Direct Data Views, the creation of Master / Detail reports, and the use of CalcOP and CalcTotal Components to Display Calculate Values ​​and Totals.

The Direct Data View

The Direct Data View allows you share the database connection established by your application, fetching data directly from the DataSets in your application. You can link them to any TDataSet descendant, and, with some code, you can even fetch data from custom DataStructures, like Arrays of records or tstringlists. Apart from That, IT Behaves in The Way As The Driver Data View We Explored on Part III.

Using DataSet Connections

Let's create a master detail report using Direct Data Views. Create a new application, and set up a connection with your database using your favorite Db Framework. I'll still be using BDE, for demonstration purposes. Add two tables (or queries, as you prefer), selecting data from the orders and items tables. For each DataSet, add a corresponding TRvDataSetConnection, available in the Rave tab, in the pallete. Set the property DataSet of each DataSetConnection to the corresponding component, and give them meaningful names ( I Called The M DSCITEMS and DSCORDERS.

The name is important:. It is the your application link to the report You will not be able to have two DataSet connections, even in different reports, with the same name, or you might run into trouble if someone tries to run both reports CONCURRENTLY.

After the DataSets are set up, return to the Rave Reports designer Choose New Data Connection, and you should see the DataSet Connections you added to your form in the Delphi designer:. Select dscItems to create the first DataView, then repeat the process to create The DataView for DScorders. You Should Now See The Fields in The Project Treeview, Under The Newly Created DataViews:

Don't forget to rename the dataviews to better names Than DataView1 and DataView2.

Creating the bands

After the DataViews have been created, we should set up the bands. Create a Region consisting of the whole page area, and add one band (Header), two DataBands (Master and Detail), and another Band (Footer). Set the ControllerBand property of Header, Detail and Footer to Master. Using the BandStyle property editor, set the style of the Header band to Body Header (B), the style of the Detail band to Detail (D), and the Footer band to Body Footer ( b). NOTICE How The Band Display Gives A Nice Preview of How The Bands Are Going to Printed:

You also need to link the DataView property of the Master band to dvOrders, and the Detail band to dvItems. To create the Master / Detail relashionship, set the MasterDataView property of the Detail band to dvOrders, and both the MasterKey and DetailKey properties to the Field ORDERNO.

The Fontmaster Component

You proably want similar items (all the items in the Detail Band, for example), to print with the same font. Instead of setting each Font property individually, you can you a FontMaster. Add a FontMaster component to the page and set its Font propert to Times New Roman, 10. in the next step, when adding the Text and DataText components, set their FontMirror property to the FontMaster. Now, if you ever change your mind about the font that is going to be used in this report, you do not need to change it in every component, just change it in the FontMaster and it will be reflect in every other component that is linked to it. you can have as much FontMasters in one report as you need.The FontMaster is a Non-Visual Component, Meaning It Won't show in the design area. If you need to reselect it, you will have to do it through the project treeview.

Adding the dattexts

Now its just a matter of adding Text and DataText components to the bands. Do not forget you can drag-and-drop (while pressing the ctrl and alt keys) from the Project Treeview to create them. I added OrderNo, SaleDate, Terms , PaymentMethod, AmountPaid and Freight to the Master band, and ItemNo, PartNo, Qty and Discount to the Detail band. Do not forget that the DisplayFormat of float fields is set in the fields themselves, in the Project Treeview, and not in the DataText Components.

Adding Totals and Calculate Fields

You can make calculations and aggregated values ​​using the CalcOP and CalcTotal components, available on the Report tab. The result of these calculations can be outputted to parameters, PI Vars, or used as intermediate result for other calculations. We are going to output them to parameters, so select your report in the Project Treeview and add two parameters, called AmountPaidTotal and FreightTotal: Now add two calcTotal components to your the Footer band, and set their Controller property to the Master band, their DataView property to dvOrders, the DataField to AmountPaid and Freight, and the DestParam to the params you created earlier, AmountPaidTotal and FreightTotal. It's also in the calcTotal component where you define the DisplayFormat of the value printed.

Note that the Calc components are evaluated in the order they appear in the Project Treeview. If a CalcOp result is going to printed by a DataText component, make sure it appears in the Treeview before it. You can use the buttons Move Forward and Move Behind From the alignment toolbar to change their order.

You can now add in the Footer Band two DataText components to print those variables. Notice that is has summed the values, and you can define through the CalcType property of the the CalcTotal components the operation you would like to perform.

The Sample Data Included in The DBDemos Does Not Have A Value for Freight In any of the records. Feel Free To Edit A Few Records To See Them Added Up.

Now let's suppose we need to sum both totals, and display them in the footer band. Add a new parameter called Total to the report and a CalcOp component below the CalcTotal components, in the Footer band, and set the Src1DataField to Param.AmountPaidTotal, And Scr2Datafield to Param.Freighttotal. Set The destparam Property to Total, and the displayformat of the value. Add a dattext to print this value.finishing up

To add the report to your project, just do the same as was done in the previous reports:. Just link it in a RvProject and call the execute method You might want to filter the DataSet based on user input, but that's the same way as You always done before.

Conclusions

We have seen how to create DataAware reports using Direct Data Views, how to set up master / detail relationships, and how to use Calc components. You can find a project containing the report developed here on CodeCentral. Part V will demonstrate the use of Custom Connections and some other tricks.

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

New Post(0)