Create or Design master detail report with Fortes Report

In my last blog (Create or design simple master report with Fortes Report) I have explained how to design a master report with using Fortes Report and its components. Now here in this blog I will show how to design master detail report with Fortes Report to show Customer and their orders. And for more detail about Fortes Report please visit Fortes Report and Components.

Here I have created a project which contains simple report to show Customer details and you can download the sample DB from link download dbdemos.db. I have saved the DB in C:\Test folder.

So now lets design Customer Order master detail report with Fortes Report components.

1. First create a project and add a form to the project lets say Unit1 (Form1).

2. Add a TADOConnection component to the form named connmain and set connection string.
ConnectionString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test\demos.mdb;Persist Security Info=False'
LoginPrompt = False
Provider = 'Microsoft.Jet.OLEDB.4.0'

3. Add 2 TADOQuery component to form named qrymaster, qrydetail and set 

Qrymaster.Connection = connmain
Qrymaster.Connection = connmain

4. Add 2 TADODatasource component to form named srcmaster, srcdetail and set 

srcmaster.Dataset = qrymaster
srcdetail.Dataset = qrydetail
 qrydetail.Datasource = srcmaster // for master detail link//

5. Add a TRLExpressionbar component to form to use Dataformula property for report components

6. Add TRLReport component to form named RLReport1 which is main report component and set following porperties

DataSource = srcmaster
Title = 'CUSTOMER ORDER REPORT'
ExpressionParser = RLExpressionParser1

7. Put TRLBand component on RLReport1 named RLBand1 for header and set following properties

BandType = btHeader
 Borders.DrawBottom = True

8. Put following components on header band RLBand1 and set following properties


RLDraw1: TRLDraw
Left = 0
Top = 48
Width = 718
Height = 26
Align = faClientBottom
Brush.Color = clSilver

RLLabel1: TRLLabel
Left = 217
Top = 0
Width = 284
Height = 32
Align = faCenterTop
Alignment = taCenter
Caption = 'CUSTOMER REPORT'
Font.Style = [fsUnderline]

RLSystemInfo1: TRLSystemInfo
Left = 631
Top = 0
Width = 87
Height = 16
Align = faRightTop
Alignment = taRightJustify
Info = itPageNumber

RLSystemInfo2: TRLSystemInfo
Left = 0
Top = 0
Width = 60
Height = 16
Align = faLeftTop
Info = itFullDate

RLLabel2: TRLLabel
Left = 3
Top = 53
Width = 66
Height = 16
Caption = 'CUST NO.'
Font.Style = [fsBold]

RLLabel3: TRLLabel
Left = 104
Top = 53
Width = 41
Height = 16
Caption = 'NAME'
Font.Style = [fsBold]

RLLabel4: TRLLabel
Left = 376
Top = 53
Width = 66
Height = 16
Caption = 'ADDRESS'
Font.Style = [fsBold]
9. Add another TRLBand component named RLband2 and set as detail band

BandType = btDetail

10. Add following components to detail band RLBand2 and set following properties

RLDBText1: TRLDBText
Left = 3
Top = 1
Width = 57
Height = 16
AutoSize = False
DataField = 'CUSTNO'
DataSource = srcmaster
RLDBText2: TRLDBText
Left = 104
Top = 1
Width = 217
Height = 16
AutoSize = False
DataField = 'COMPANY'
DataSource = srcmaster
RLDBMemo1: TRLDBMemo
Left = 376
Top = 1
Width = 273
Height = 16
Behavior = [beSiteExpander]
DataFormula = 'Addr1 +'#39' '#39'+City + '#39' '#39'+Phone'
DataSource = srcmaster

11. Add another TRLBand component named RLband3 and set as footer band

BandType = btFooter
  Borders.DrawTop = True

12. Add following components to footer band RLBand3 and set following properties

RLLabel5: TRLLabel
  Left = 298

Top = 24

Width = 121

Height = 16

Align = faCenterBottom

Caption = 'DIGITAL SIGNED....'

13. Now put TRLSubdetail band named RLSubDetail1 to print detail data and set following properties
   
DataSource = srcdetail

  As Fortes report is based on bands so here we have to put a Header, Detail and Footer band in Subdetail band to print data. 

14. Now put a TRLBand component in RLSubDetail1 as column header and name RLBand4
   
  BandType = btColumnHeader
  Font.Style = [fsBold]

15. Put following components in RLBand4 and set properties

RLLabel6: TRLLabel
Left = 104
Top = 0
Width = 76
Height = 16
Caption = 'ORDER NO.'

RLLabel7: TRLLabel
Left = 208
Top = 0
Width = 76
Height = 16
Caption = 'SALE DATE'

RLLabel8: TRLLabel
Left = 311
Top = 0
Width = 73
Height = 16
Caption = 'SHIP DATE'

RLLabel9: TRLLabel
Left = 408
Top = 1
Width = 89
Height = 16
Caption = 'PAY METHOD'

RLLabel10: TRLLabel
Left = 550
Top = -1
Width = 60
Height = 16
Caption = 'AMOUNT'

RLLabel11: TRLLabel
Left = 677
Top = 0
Width = 30
Height = 16
Caption = 'TAX'

16. Put a TRLBand component in RLSubDetail1 as detail and name RLBand5
   
  BandType = btDetail

17. Put following components in RLBand5 and set properties 

RLDBText3: TRLDBText
Left = 104
Top = 2
Width = 69
Height = 16
DataField = 'ORDERNO'
DataSource = srcdetail

RLDBText4: TRLDBText
Left = 208
Top = 2
Width = 72
Height = 16
DataField = 'SALEDATE'
DataSource = srcdetail

RLDBText5: TRLDBText
Left = 311
Top = 2
Width = 68
Height = 16
DataField = 'SHIPDATE'
DataSource = srcdetail

RLDBText6: TRLDBText
Left = 408
Top = 2
Width = 122
Height = 16
DataField = 'PAYMENTMETHOD'
DataSource = srcdetail

RLDBText7: TRLDBText
Left = 527
Top = 2
Width = 83
Height = 16
Alignment = taRightJustify
DataField = 'ITEMSTOTAL'
DataSource = srcdetail
DisplayMask = '0.00'

RLDBText8: TRLDBText
Left = 646
Top = 2
Width = 61
Height = 16
Alignment = taRightJustify
DataField = 'TAXRATE'
DataSource = srcdetail
DisplayMask = '0.00'

18. Put a TRLBand component in RLSubDetail1 as column footer and name RLBand6

  BandType = btColumnFooter
  Font.Style = [fsBold]

19. Put following components in RLBand6 and set properties

RLLabel12: TRLLabel
Left = 408
Top = 3
Width = 106
Height = 16
Caption = 'TOTAL VALUE  :'

RLDBResult1: TRLDBResult
Left = 482
Top = 3
Width = 128
Height = 16
Alignment = taRightJustify
DataField = 'ITEMSTOTAL'
DataSource = srcdetail
DisplayMask = '0.00'
Info = riSum

RLDBResult2: TRLDBResult
Left = 602
Top = 3
Width = 105
Height = 16
Alignment = taRightJustify
DataField = 'TAXRATE'
DataSource = srcdetail
DisplayMask = '0.00'
Info = riSum

20. Put report filter components on form to save report in different format during preview

RLRichFilter1: TRLRichFilter;
RLPDFFilter1: TRLPDFFilter;
RLXLSFilter1: TRLXLSFilter;
RLHTMLFilter1: TRLHTMLFilter;

21. Now Customer Order Report design is ready and add codes to show report. Here I have added a procedure ShowReport to Form1 to preview report.

  procedure TForm1.ShowReport; begin srcmaster.DataSet := qrymaster; qrymaster.Connection := Form1.ADOConnection1; qrymaster.SQL.Clear; qrymaster.SQL.Text := 'SELECT * FROM CUSTOMER'; qrymaster.Open; srcdetail.DataSet := qrydetail; qrydetail.DataSource := srcmaster; qrydetail.Connection := Form1.ADOConnection1; qrydetail.SQL.Clear; qrydetail.SQL.Text := 'SELECT * FROM ORDERS WHERE CUSTNO = :CUSTNO'; qrydetail.Open; RLReport1.PreviewModal;
Close; end;

22. Now I will add another form to the same project and will set that as main form. Then on a button click I will show the report.

So add a new form Form2 and put a TButton component name Customer1 on that form. And on button click write following code.

 uses
    Form1; 
  ......
  ......
procedure TForm2.Customer1Click(Sender: TObject);
begin
Form1 := TForm1.Create(Self);

Form1.ShowReport;

Comments

Popular posts from this blog

ShellExecute in Delphi

How to send Email in Delphi?

Drawing Shapes in Delphi