123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?xml version="1.0" encoding="utf-8"?>
- <Report ScriptLanguage="CSharp" DoublePass="true" ReportInfo.Description="Demonstrates how to sort groups by the total value of a group. To create this report: - create the group report similar to the "General/Groups" report; - make it two-pass ("Report/Options..." menu, "Double pass" checkbox); - add the GroupFooter1.BeforePrint script that will calculate and remember the total value for each group on the first pass; - add the GroupRank method that will return the calculated total value for each group on the second pass; - turn off the sort in the group header's editor; - invoke the data band's editor and set sort by GroupRank(), then by ProductName." ReportInfo.Created="01/17/2008 04:31:41" ReportInfo.Modified="03/30/2023 02:26:38" ReportInfo.CreatorVersion="1.0.0.0">
- <ScriptText>using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Drawing;
- using System.Data;
- using FastReport;
- using FastReport.Data;
- using FastReport.Dialog;
- using FastReport.Barcode;
- using FastReport.Table;
- using FastReport.Utils;
- namespace FastReport
- {
- public class ReportScript
- {
- private Hashtable groupList = new Hashtable();
- private void GroupFooter1_BeforePrint(object sender, EventArgs e)
- {
- if (Engine.FirstPass)
- {
- string groupName = ((String)Report.GetColumnValue("Products.ProductName")).Substring(0,1);
- int groupTotal = Report.GetTotalValue("TotalProducts");
- groupList.Add(groupName, groupTotal);
- }
- }
-
- private object GroupRank()
- {
- if (Engine.FinalPass)
- {
- string groupName = ((String)Report.GetColumnValue("Products.ProductName")).Substring(0,1);
- return groupList[groupName];
- }
- return 0;
- }
- }
- }
- </ScriptText>
- <Styles>
- <Style Name="EvenRows" Fill.Color="229, 239, 229" Font="Arial, 10pt"/>
- </Styles>
- <Dictionary>
- <TableDataSource Name="Products" ReferenceName="NorthWind.Products" DataType="System.Int32" Enabled="true">
- <Column Name="ProductID" DataType="System.Int32"/>
- <Column Name="ProductName" DataType="System.String"/>
- <Column Name="SupplierID" DataType="System.Int32"/>
- <Column Name="CategoryID" DataType="System.Int32"/>
- <Column Name="QuantityPerUnit" DataType="System.String"/>
- <Column Name="UnitPrice" DataType="System.Decimal"/>
- <Column Name="UnitsInStock" DataType="System.Int16"/>
- <Column Name="UnitsOnOrder" DataType="System.Int16"/>
- <Column Name="ReorderLevel" DataType="System.Int16"/>
- <Column Name="Discontinued" DataType="System.Boolean" BindableControl="CheckBox"/>
- <Column Name="EAN13" DataType="System.String"/>
- </TableDataSource>
- <Total Name="TotalProducts" TotalType="Count" Evaluator="Data1" PrintOn="GroupFooter1"/>
- </Dictionary>
- <ReportPage Name="Page1" Watermark.Font="Arial, 60pt">
- <ReportTitleBand Name="ReportTitle1" Width="718.2" Height="37.8" CanGrow="true">
- <TextObject Name="Text1" Width="718.2" Height="37.8" Text="PRODUCT LIST SORTED BY GROUP TOTAL" HorzAlign="Center" VertAlign="Center" Font="Segoe UI, 14pt, style=Bold"/>
- </ReportTitleBand>
- <GroupHeaderBand Name="GroupHeader1" Top="39.8" Width="718.2" Height="37.8" KeepWithData="true" Condition="[Products.ProductName].Substring(0,1)" SortOrder="None">
- <TextObject Name="Text7" Left="9.45" Top="9.45" Width="699.3" Height="28.35" Border.Lines="All" Border.Color="130, 180, 130" Fill.Color="130, 180, 130" Text="[[Products.ProductName].Substring(0,1)]" Padding="5, 0, 0, 0" VertAlign="Center" Font="Segoe UI, 12pt, style=Bold" TextFill.Color="White"/>
- <DataBand Name="Data1" Top="79.6" Width="718.2" Height="18.9" DataSource="Products">
- <TextObject Name="Text2" Left="9.45" Width="604.8" Height="18.9" Border.Lines="Left" Border.Color="130, 180, 130" EvenStyle="EvenRows" Text="[Products.ProductName]" VertAlign="Center" Font="Segoe UI, 9pt"/>
- <TextObject Name="Text4" Left="614.25" Width="94.5" Height="18.9" Border.Lines="Right" Border.Color="130, 180, 130" EvenStyle="EvenRows" Text="[Products.UnitPrice]" Format="Currency" Format.UseLocale="true" Format.DecimalDigits="2" HorzAlign="Right" VertAlign="Center" Font="Segoe UI, 9pt"/>
- <Sort>
- <Sort Expression="GroupRank()" Descending="true"/>
- <Sort Expression="[Products.ProductName]"/>
- </Sort>
- </DataBand>
- <GroupFooterBand Name="GroupFooter1" Top="100.5" Width="718.2" Height="47.25" BeforePrintEvent="GroupFooter1_BeforePrint" KeepWithData="true">
- <TextObject Name="Text8" Left="9.45" Width="699.3" Height="18.9" Border.Lines="Left, Right, Bottom" Border.Color="130, 180, 130" Text="Total products: [TotalProducts]" HorzAlign="Right" VertAlign="Center" Font="Segoe UI, 9pt, style=Bold"/>
- </GroupFooterBand>
- </GroupHeaderBand>
- <PageFooterBand Name="PageFooter1" Top="149.75" Width="718.2" Height="28.35" Fill.Color="WhiteSmoke">
- <TextObject Name="Text9" Left="614.25" Top="9.45" Width="94.5" Height="18.9" Text="[PageN]" HorzAlign="Right" Font="Segoe UI, 9pt"/>
- <TextObject Name="Text12" Left="9.45" Width="217.35" Height="28.35" Cursor="Hand" Hyperlink.Value="https://www.fast-report.com/en/product/fast-report-net/" Text="Generated by FastReport" VertAlign="Center" Font="Segoe UI, 9pt, style=Underline" TextFill.Color="Blue"/>
- </PageFooterBand>
- </ReportPage>
- </Report>
|