Sort Group By Total.frx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Report ScriptLanguage="CSharp" DoublePass="true" ReportInfo.Description="Demonstrates how to sort groups by the total value of a group. To create this report:&#13;&#10;- create the group report similar to the &quot;General/Groups&quot; report;&#13;&#10;- make it two-pass (&quot;Report/Options...&quot; menu, &quot;Double pass&quot; checkbox);&#13;&#10;- add the GroupFooter1.BeforePrint script that will calculate and remember the total value for each group on the first pass;&#13;&#10;- add the GroupRank method that will return the calculated total value for each group on the second pass;&#13;&#10;- turn off the sort in the group header's editor;&#13;&#10;- 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">
  3. <ScriptText>using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Windows.Forms;
  8. using System.Drawing;
  9. using System.Data;
  10. using FastReport;
  11. using FastReport.Data;
  12. using FastReport.Dialog;
  13. using FastReport.Barcode;
  14. using FastReport.Table;
  15. using FastReport.Utils;
  16. namespace FastReport
  17. {
  18. public class ReportScript
  19. {
  20. private Hashtable groupList = new Hashtable();
  21. private void GroupFooter1_BeforePrint(object sender, EventArgs e)
  22. {
  23. if (Engine.FirstPass)
  24. {
  25. string groupName = ((String)Report.GetColumnValue(&quot;Products.ProductName&quot;)).Substring(0,1);
  26. int groupTotal = Report.GetTotalValue(&quot;TotalProducts&quot;);
  27. groupList.Add(groupName, groupTotal);
  28. }
  29. }
  30. private object GroupRank()
  31. {
  32. if (Engine.FinalPass)
  33. {
  34. string groupName = ((String)Report.GetColumnValue(&quot;Products.ProductName&quot;)).Substring(0,1);
  35. return groupList[groupName];
  36. }
  37. return 0;
  38. }
  39. }
  40. }
  41. </ScriptText>
  42. <Styles>
  43. <Style Name="EvenRows" Fill.Color="229, 239, 229" Font="Arial, 10pt"/>
  44. </Styles>
  45. <Dictionary>
  46. <TableDataSource Name="Products" ReferenceName="NorthWind.Products" DataType="System.Int32" Enabled="true">
  47. <Column Name="ProductID" DataType="System.Int32"/>
  48. <Column Name="ProductName" DataType="System.String"/>
  49. <Column Name="SupplierID" DataType="System.Int32"/>
  50. <Column Name="CategoryID" DataType="System.Int32"/>
  51. <Column Name="QuantityPerUnit" DataType="System.String"/>
  52. <Column Name="UnitPrice" DataType="System.Decimal"/>
  53. <Column Name="UnitsInStock" DataType="System.Int16"/>
  54. <Column Name="UnitsOnOrder" DataType="System.Int16"/>
  55. <Column Name="ReorderLevel" DataType="System.Int16"/>
  56. <Column Name="Discontinued" DataType="System.Boolean" BindableControl="CheckBox"/>
  57. <Column Name="EAN13" DataType="System.String"/>
  58. </TableDataSource>
  59. <Total Name="TotalProducts" TotalType="Count" Evaluator="Data1" PrintOn="GroupFooter1"/>
  60. </Dictionary>
  61. <ReportPage Name="Page1" Watermark.Font="Arial, 60pt">
  62. <ReportTitleBand Name="ReportTitle1" Width="718.2" Height="37.8" CanGrow="true">
  63. <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"/>
  64. </ReportTitleBand>
  65. <GroupHeaderBand Name="GroupHeader1" Top="39.8" Width="718.2" Height="37.8" KeepWithData="true" Condition="[Products.ProductName].Substring(0,1)" SortOrder="None">
  66. <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"/>
  67. <DataBand Name="Data1" Top="79.6" Width="718.2" Height="18.9" DataSource="Products">
  68. <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"/>
  69. <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"/>
  70. <Sort>
  71. <Sort Expression="GroupRank()" Descending="true"/>
  72. <Sort Expression="[Products.ProductName]"/>
  73. </Sort>
  74. </DataBand>
  75. <GroupFooterBand Name="GroupFooter1" Top="100.5" Width="718.2" Height="47.25" BeforePrintEvent="GroupFooter1_BeforePrint" KeepWithData="true">
  76. <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"/>
  77. </GroupFooterBand>
  78. </GroupHeaderBand>
  79. <PageFooterBand Name="PageFooter1" Top="149.75" Width="718.2" Height="28.35" Fill.Color="WhiteSmoke">
  80. <TextObject Name="Text9" Left="614.25" Top="9.45" Width="94.5" Height="18.9" Text="[PageN]" HorzAlign="Right" Font="Segoe UI, 9pt"/>
  81. <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"/>
  82. </PageFooterBand>
  83. </ReportPage>
  84. </Report>