Objects Inside The Matrix.frx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Report ScriptLanguage="CSharp" ReportInfo.Description="Demonstrates how to print other objects inside the matrix. In this example each data cell has an indicator which is red if value &lt; 100; yellow if value &lt; 3000; or green if value &gt;= 3000. To do this:&#13;&#10;- create a matrix;&#13;&#10;- put three Shape objects inside the data cell;&#13;&#10;- increase the cell's width to contain both text and indicator. To do this, select the cell, go to Properties window and set the Padding.Left property to 50;&#13;&#10;- in the same window, click &quot;Events&quot; button and create a &quot;BeforePrint&quot; event handler;&#13;&#10;- in the handler, set the shapes' visibility and color based on the cell's Value. See the handler code for more details." ReportInfo.Created="05/16/2008 01:44:40" ReportInfo.Modified="03/30/2023 01:18:19" 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 void Cell4_BeforePrint(object sender, EventArgs e)
  21. {
  22. // cast the cell's value to decimal because [MatrixDemo.Revenue]
  23. // data column is of System.Decimal type
  24. decimal value = Cell4.Value == null ? 0 : (decimal)Cell4.Value;
  25. // set shapes visibility: one shape if value &lt; 100; two if &lt; 3000; three if &gt;= 3000
  26. Shape1.Visible = true;
  27. Shape2.Visible = value &gt;= 100;
  28. Shape3.Visible = value &gt;= 3000;
  29. // Highlight: red &lt; 100; yellow &lt; 3000; green &gt;= 3000
  30. Color color = Color.Red;
  31. if (value &gt;= 100)
  32. color = Color.Yellow;
  33. if (value &gt;= 3000)
  34. color = Color.GreenYellow;
  35. Shape1.Fill = new SolidFill(color);
  36. Shape2.Fill = new SolidFill(color);
  37. Shape3.Fill = new SolidFill(color);
  38. }
  39. }
  40. }
  41. </ScriptText>
  42. <Dictionary>
  43. <TableDataSource Name="MatrixDemo" ReferenceName="NorthWind.MatrixDemo" DataType="System.Int32" Enabled="true">
  44. <Column Name="Name" DataType="System.String"/>
  45. <Column Name="Year" DataType="System.Int32"/>
  46. <Column Name="Month" DataType="System.Int32"/>
  47. <Column Name="ItemsSold" DataType="System.Int32"/>
  48. <Column Name="Revenue" DataType="System.Decimal"/>
  49. </TableDataSource>
  50. </Dictionary>
  51. <ReportPage Name="Page1" RawPaperSize="9" Watermark.Font="Arial, 60pt">
  52. <ReportTitleBand Name="ReportTitle1" Width="718.2" Height="56.7" CanGrow="true">
  53. <TextObject Name="Text1" Top="37.8" Width="718.2" Height="18.9" Text="Highlight: red &lt; 100; yellow &lt; 3000; green &gt;= 3000" HorzAlign="Center" VertAlign="Center" Font="Segoe UI, 9pt"/>
  54. <TextObject Name="Text13" Width="718.2" Height="37.8" Text="REVENUE BY EMPLOYEE" HorzAlign="Center" VertAlign="Center" Font="Segoe UI, 14pt, style=Bold"/>
  55. </ReportTitleBand>
  56. <DataBand Name="Data1" Top="58.7" Width="718.2" Height="80.28">
  57. <MatrixObject Name="Matrix1" Top="9.45" Width="199.66" Height="61.38" FixedRows="1" FixedColumns="1" DataSource="MatrixDemo" Style="BlueWhite">
  58. <MatrixColumns>
  59. <Header Expression="[MatrixDemo.Year]"/>
  60. </MatrixColumns>
  61. <MatrixRows>
  62. <Header Expression="[MatrixDemo.Name]"/>
  63. </MatrixRows>
  64. <MatrixCells>
  65. <Cell Expression="[MatrixDemo.Revenue]"/>
  66. </MatrixCells>
  67. <TableColumn Name="Column1" Width="62.31" AutoSize="true"/>
  68. <TableColumn Name="Column2" Width="101.16" AutoSize="true"/>
  69. <TableColumn Name="Column3" Width="36.19" AutoSize="true"/>
  70. <TableRow Name="Row1" Height="20.46" AutoSize="true">
  71. <TableCell Name="Cell1" Border.Lines="All" Border.Color="White" Fill.Color="110, 145, 190" Text="Employee" HorzAlign="Center" VertAlign="Center" Font="Segoe UI, 9pt" TextFill.Color="White"/>
  72. <TableCell Name="Cell2" Border.Lines="All" Border.Color="White" Fill.Color="110, 145, 190" Text="[Year]" HorzAlign="Center" VertAlign="Center" Font="Segoe UI, 9pt" TextFill.Color="White"/>
  73. <TableCell Name="Cell7" Border.Lines="All" Border.Color="White" Fill.Color="110, 145, 190" Text="Total" HorzAlign="Center" VertAlign="Center" Font="Segoe UI, 9pt" TextFill.Color="White"/>
  74. </TableRow>
  75. <TableRow Name="Row2" Height="20.46" AutoSize="true">
  76. <TableCell Name="Cell3" Border.Lines="All" Border.Color="White" Fill.Color="110, 145, 190" Text="[Name]" VertAlign="Center" Font="Segoe UI, 9pt" TextFill.Color="White"/>
  77. <TableCell Name="Cell4" Border.Lines="All" Border.Color="White" Fill.Color="WhiteSmoke" BeforePrintEvent="Cell4_BeforePrint" Text="[Revenue]" Padding="40, 1, 2, 1" Format="Currency" Format.UseLocale="true" Format.DecimalDigits="2" HorzAlign="Right" VertAlign="Center" Font="Segoe UI, 9pt">
  78. <ShapeObject Name="Shape1" Left="4" Top="5.67" Width="9.45" Height="9.45" Border.Color="White" Fill.Color="GreenYellow"/>
  79. <ShapeObject Name="Shape2" Left="13.45" Top="5.67" Width="9.45" Height="9.45" Border.Color="White" Fill.Color="GreenYellow"/>
  80. <ShapeObject Name="Shape3" Left="22.9" Top="5.67" Width="9.45" Height="9.45" Border.Color="White" Fill.Color="GreenYellow"/>
  81. </TableCell>
  82. <TableCell Name="Cell8" Border.Lines="All" Border.Color="White" Fill.Color="WhiteSmoke" Format="Currency" Format.UseLocale="true" Format.DecimalDigits="2" HorzAlign="Right" VertAlign="Center" Font="Segoe UI, 9pt"/>
  83. </TableRow>
  84. <TableRow Name="Row4" Height="20.46" AutoSize="true">
  85. <TableCell Name="Cell5" Border.Lines="All" Border.Color="White" Fill.Color="110, 145, 190" Text="Total" HorzAlign="Center" VertAlign="Center" Font="Segoe UI, 9pt" TextFill.Color="White"/>
  86. <TableCell Name="Cell6" Border.Lines="All" Border.Color="White" Fill.Color="WhiteSmoke" Format="Currency" Format.UseLocale="true" Format.DecimalDigits="2" HorzAlign="Right" VertAlign="Center" Font="Segoe UI, 9pt"/>
  87. <TableCell Name="Cell9" Border.Lines="All" Border.Color="White" Fill.Color="WhiteSmoke" Format="Currency" Format.UseLocale="true" Format.DecimalDigits="2" HorzAlign="Right" VertAlign="Center" Font="Segoe UI, 9pt"/>
  88. </TableRow>
  89. </MatrixObject>
  90. </DataBand>
  91. <PageFooterBand Name="PageFooter1" Top="140.98" Width="718.2" Height="28.35" Fill.Color="WhiteSmoke">
  92. <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"/>
  93. </PageFooterBand>
  94. </ReportPage>
  95. </Report>