Create or Design reports with Groups in Fortes Report
In my last blog (Create or Design master detail report with Fortes Report) I have explained how to design a master detail report with using Fortes Report and its components. Now here in this blog I will show how to design grouping report with Fortes Report to show Customer and their orders with Customer No. as group. And for more detail about Fortes Report please visit Fortes Report and Components.
Here I have created a project which contains 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 detail report with Grouping as Customer No using Fortes Report components.
So now lets design Customer Order detail report with Grouping as Customer No using 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 and set
Qrymaster.Connection = connmain
4. Add 2 TADODatasource component to form named srcmaster, srcdetail and set
srcmaster.Dataset = qrymaster
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 GROUP 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
RLLabel1: TRLLabel
Left = 217 Top = 0 Width = 284 Height = 32 Align = faCenterTop Alignment = taCenter Caption = 'CUSTOMER ORDER GROUP REPORT' Font.Height = -27 Font.Style = [fsUnderline] ParentFont = False RLSystemInfo1: TRLSystemInfo Left = 631 Top = 0 Width = 87 Height = 16 Align = faRightTop Alignment = taRightJustify Info = itPageNumber Text = '' RLSystemInfo2: TRLSystemInfo Left = 0 Top = 0 Width = 60 Height = 16 Align = faLeftTop Info = itFullDate Text = ''
Left = 217 Top = 0 Width = 284 Height = 32 Align = faCenterTop Alignment = taCenter Caption = 'CUSTOMER ORDER GROUP REPORT' Font.Height = -27 Font.Style = [fsUnderline] ParentFont = False RLSystemInfo1: TRLSystemInfo Left = 631 Top = 0 Width = 87 Height = 16 Align = faRightTop Alignment = taRightJustify Info = itPageNumber Text = '' RLSystemInfo2: TRLSystemInfo Left = 0 Top = 0 Width = 60 Height = 16 Align = faLeftTop Info = itFullDate Text = ''
9. Add another TRLBand component named RLband2 and set as footer band
BandType = btFooter
Borders.DrawTop = True
10. Add following components to footer band RLBand2 and set following properties
RLLabel5: TRLLabel
Left = 298
Top = 24
Width = 121
Height = 16
Align = faCenterBottom
Left = 298
Top = 24
Width = 121
Height = 16
Align = faCenterBottom
Caption = 'DIGITAL SIGNED....'
11. Add TRLGroup band component named RLGroup1 and set following properties. And set DataFields property to CUSTNO for grouping as per Customer No. field value.
RLGroup1: TRLGroup
RLGroup1: TRLGroup
Left = 38
Top = 81
Width = 718
Height = 106
DataFields = 'CUSTNO'
FooterMeasuring = fmBeforeDetail
As Fortes report is based on bands so here we have to put a Header, Detail and Footer band in Group band to print data.
12. Now put a TRLBand component in RLGroup1 as header and name RLBand3
RLBand3: TRLBand
Left = 0
Top = 0
Width = 718
Height = 25
BandType = btHeader
Color = cl3DLight
Font.Height = -13
Font.Style = [fsBold]
ParentColor = False
ParentFont = False
Transparent = False
13. Put following components in RLBand3 and set properties
RLLabel3: TRLLabel
Left = 16
Top = 6
Width = 112
Height = 16
Caption = 'CUSTOMER NO. :'
Transparent = False
RLDBText1: TRLDBText
Left = 135
Top = 6
Width = 58
Height = 16
DataField = 'CUSTNO'
DataSource = srcmaster
Text = ''
Transparent = False
14. Now put another TRLBand component in RLGroup1 as column header and name RLBand4
RLBand4: TRLBand
Left = 0
Top = 25
Width = 718
Height = 24
BandType = btColumnHeader
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -13
Font.Name = 'Arial'
Font.Style = [fsBold]
ParentFont = False
15. Put following components in RLBand4 and set properties
RLLabel4: TRLLabel
Left = 16
Top = 6
Width = 76
Height = 16
Caption = 'ORDER NO.'
RLLabel5: TRLLabel
Left = 116
Top = 6
Width = 85
Height = 16
Caption = 'SALES DATE'
RLLabel6: TRLLabel
Left = 217
Top = 6
Width = 73
Height = 16
Caption = 'SHIP DATE'
RLLabel7: TRLLabel
Left = 305
Top = 6
Width = 61
Height = 16
Caption = 'SHIP VIA'
RLLabel8: TRLLabel
Left = 377
Top = 6
Width = 87
Height = 16
Caption = 'PAYMENT BY'
RLLabel9: TRLLabel
Left = 487
Top = 5
Width = 91
Height = 16
Alignment = taRightJustify
Caption = 'ITEMS TOTAL'
RLLabel10: TRLLabel
Left = 614
Top = 5
Width = 68
Height = 16
Alignment = taRightJustify
Caption = 'TAX RATE'
16. Put another TRLBand component in RLGroup1 as detail and name RLBand5
RLBand5: TRLBand
Left = 0
Top = 49
Width = 718
Height = 24
17. Put following components in RLBand5 and set properties
RLDBText2: TRLDBText
Left = 16
Top = 3
Width = 69
Height = 16
DataField = 'ORDERNO'
DataSource = srcmaster
Text = ''
RLDBText3: TRLDBText
Left = 116
Top = 3
Width = 72
Height = 16
DataField = 'SALEDATE'
DataSource = srcmaster
Text = ''
RLDBText4: TRLDBText
Left = 217
Top = 3
Width = 68
Height = 16
DataField = 'SHIPDATE'
DataSource = srcmaster
Text = ''
RLDBText5: TRLDBText
Left = 305
Top = 3
Width = 55
Height = 16
DataField = 'SHIPVIA'
DataSource = srcmaster
Text = ''
RLDBText6: TRLDBText
Left = 377
Top = 3
Width = 122
Height = 16
DataField = 'PAYMENTMETHOD'
DataSource = srcmaster
Text = ''
RLDBText7: TRLDBText
Left = 495
Top = 3
Width = 83
Height = 16
Alignment = taRightJustify
DataField = 'ITEMSTOTAL'
DataSource = srcmaster
DisplayMask = '0.00'
Text = ''
RLDBText8: TRLDBText
Left = 621
Top = 3
Width = 61
Height = 16
Alignment = taRightJustify
DataField = 'TAXRATE'
DataSource = srcmaster
DisplayMask = '0.00'
Text = ''
18. Put another TRLBand component in RLGroup1 as footer and name RLBand6
BandType = btFooter
Font.Style = [fsBold]
19. Put following components in RLBand6 and set properties
RLLabel11: TRLLabel
Left = 377
Top = 2
Width = 106
Height = 16
Caption = 'GROUP TOTAL :'
RLDBResult1: TRLDBResult
Left = 450
Top = 2
Width = 128
Height = 16
Alignment = taRightJustify
DataField = 'ITEMSTOTAL'
DataSource = srcmaster
DisplayMask = '0.00'
Info = riSum
ResetAfterPrint = True
Text = ''
RLDBResult2: TRLDBResult
Left = 577
Top = 1
Width = 105
Height = 16
Alignment = taRightJustify
DataField = 'TAXRATE'
DataSource = srcmaster
DisplayMask = '0.00'
Info = riSum
ResetAfterPrint = True
Text = ''
20. Put report filter components on form to save report in different format during preview
12. Now put a TRLBand component in RLGroup1 as header and name RLBand3
RLBand3: TRLBand
Left = 0
Top = 0
Width = 718
Height = 25
BandType = btHeader
Color = cl3DLight
Font.Height = -13
Font.Style = [fsBold]
ParentColor = False
ParentFont = False
Transparent = False
RLLabel3: TRLLabel
Left = 16
Top = 6
Width = 112
Height = 16
Caption = 'CUSTOMER NO. :'
Transparent = False
RLDBText1: TRLDBText
Left = 135
Top = 6
Width = 58
Height = 16
DataField = 'CUSTNO'
DataSource = srcmaster
Text = ''
Transparent = False
RLBand4: TRLBand
Left = 0
Top = 25
Width = 718
Height = 24
BandType = btColumnHeader
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -13
Font.Name = 'Arial'
Font.Style = [fsBold]
ParentFont = False
RLLabel4: TRLLabel
Left = 16
Top = 6
Width = 76
Height = 16
Caption = 'ORDER NO.'
RLLabel5: TRLLabel
Left = 116
Top = 6
Width = 85
Height = 16
Caption = 'SALES DATE'
RLLabel6: TRLLabel
Left = 217
Top = 6
Width = 73
Height = 16
Caption = 'SHIP DATE'
RLLabel7: TRLLabel
Left = 305
Top = 6
Width = 61
Height = 16
Caption = 'SHIP VIA'
RLLabel8: TRLLabel
Left = 377
Top = 6
Width = 87
Height = 16
Caption = 'PAYMENT BY'
RLLabel9: TRLLabel
Left = 487
Top = 5
Width = 91
Height = 16
Alignment = taRightJustify
Caption = 'ITEMS TOTAL'
RLLabel10: TRLLabel
Left = 614
Top = 5
Width = 68
Height = 16
Alignment = taRightJustify
Caption = 'TAX RATE'
16. Put another TRLBand component in RLGroup1 as detail and name RLBand5
RLBand5: TRLBand
Left = 0
Top = 49
Width = 718
Height = 24
17. Put following components in RLBand5 and set properties
RLDBText2: TRLDBText
Left = 16
Top = 3
Width = 69
Height = 16
DataField = 'ORDERNO'
DataSource = srcmaster
Text = ''
RLDBText3: TRLDBText
Left = 116
Top = 3
Width = 72
Height = 16
DataField = 'SALEDATE'
DataSource = srcmaster
Text = ''
RLDBText4: TRLDBText
Left = 217
Top = 3
Width = 68
Height = 16
DataField = 'SHIPDATE'
DataSource = srcmaster
Text = ''
RLDBText5: TRLDBText
Left = 305
Top = 3
Width = 55
Height = 16
DataField = 'SHIPVIA'
DataSource = srcmaster
Text = ''
RLDBText6: TRLDBText
Left = 377
Top = 3
Width = 122
Height = 16
DataField = 'PAYMENTMETHOD'
DataSource = srcmaster
Text = ''
RLDBText7: TRLDBText
Left = 495
Top = 3
Width = 83
Height = 16
Alignment = taRightJustify
DataField = 'ITEMSTOTAL'
DataSource = srcmaster
DisplayMask = '0.00'
Text = ''
RLDBText8: TRLDBText
Left = 621
Top = 3
Width = 61
Height = 16
Alignment = taRightJustify
DataField = 'TAXRATE'
DataSource = srcmaster
DisplayMask = '0.00'
Text = ''
BandType = btFooter
Font.Style = [fsBold]
19. Put following components in RLBand6 and set properties
RLLabel11: TRLLabel
Left = 377
Top = 2
Width = 106
Height = 16
Caption = 'GROUP TOTAL :'
RLDBResult1: TRLDBResult
Left = 450
Top = 2
Width = 128
Height = 16
Alignment = taRightJustify
DataField = 'ITEMSTOTAL'
DataSource = srcmaster
DisplayMask = '0.00'
Info = riSum
ResetAfterPrint = True
Text = ''
RLDBResult2: TRLDBResult
Left = 577
Top = 1
Width = 105
Height = 16
Alignment = taRightJustify
DataField = 'TAXRATE'
DataSource = srcmaster
DisplayMask = '0.00'
Info = riSum
ResetAfterPrint = True
Text = ''
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 ORDERS ORDER BY CUSTNO'; qrymaster.Open; srcmaster.DataSet := qrymaster; RLReport1.PreviewModal; Close;
end;
srcmaster.DataSet := qrymaster; qrymaster.Connection := Form1.ADOConnection1; qrymaster.SQL.Clear; qrymaster.SQL.Text := 'SELECT * FROM ORDERS ORDER BY CUSTNO'; qrymaster.Open; srcmaster.DataSet := qrymaster; 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
Post a Comment