AdvMatrixObject.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing.Design;
  5. using FastReport.Data;
  6. using FastReport.Table;
  7. using FastReport.Utils;
  8. namespace FastReport.AdvMatrix
  9. {
  10. /// <summary>
  11. /// Describes how the even style is applied to a matrix.
  12. /// </summary>
  13. public enum HeaderPriority
  14. {
  15. /// <summary>
  16. /// The even style is applied to matrix rows.
  17. /// </summary>
  18. Rows,
  19. /// <summary>
  20. /// The even style is applied to matrix columns.
  21. /// </summary>
  22. Columns
  23. }
  24. /// <summary>
  25. /// Represents the matrix object that is used to print cross-table.
  26. /// </summary>
  27. /// <remarks>
  28. /// The matrix consists of the following elements: columns, rows and data cells. Each element is
  29. /// represented by the <b>descriptor</b>. The <see cref="HeaderDescriptor"/> class represents
  30. /// columns and rows; data cells use dynamically created descriptors.
  31. /// The <see cref="Data"/> property holds two root descriptors - <b>Columns.Descriptor</b> and <b>Rows.Descriptor</b>.
  32. /// <para/>To create the matrix in a code, you should perform the following actions:
  33. /// <list type="bullet">
  34. /// <item>
  35. /// <description>create an instance of the <b>AdvMatrixObject</b> and add it to the report;</description>
  36. /// </item>
  37. /// <item>
  38. /// <description>create descriptors for columns and rows and add it to the
  39. /// root descriptor using the <b>matrix.Data.Columns.Descriptor</b> and <b>matrix.Data.Rows.Descriptor</b> respectively;</description>
  40. /// </item>
  41. /// <item>
  42. /// <description>call the <see cref="BuildTemplate"/> method to create the matrix template
  43. /// that will be used to create a result;</description>
  44. /// </item>
  45. /// <item>
  46. /// <description>set the data cells content;</description>
  47. /// </item>
  48. /// <item>
  49. /// <description>modify the matrix template (change captions, set the visual appearance).</description>
  50. /// </item>
  51. /// </list>
  52. /// <para/>To connect the matrix to a datasource, use the <see cref="DataSource"/> property. If
  53. /// this property is not set, the result matrix will be empty. In this case you may use
  54. /// the <see cref="ManualBuild"/> event handler to fill the matrix.
  55. /// </remarks>
  56. /// <example>This example demonstrates how to create a matrix in a code.
  57. /// <code>
  58. /// // create an instance of AdvMatrixObject
  59. /// AdvMatrixObject matrix = new AdvMatrixObject();
  60. /// matrix.Name = "Matrix1";
  61. /// // add it to the report title band of the first report page
  62. /// matrix.Parent = (Report.Pages[0] as ReportPage).ReportTitle;
  63. ///
  64. /// // create two nested column descriptors and a total
  65. /// HeaderDescriptor column = new HeaderDescriptor("[MatrixDemo.Year]");
  66. /// matrix.Data.Columns.Descriptor.Add(column);
  67. /// HeaderDescriptor nestedColumn = new HeaderDescriptor("[MatrixDemo.Month]");
  68. /// column.Add(nestedColumn);
  69. /// HeaderDescriptor columnTotal = new HeaderDescriptor();
  70. /// columnTotal.DisplayText = "Total";
  71. /// matrix.Data.Columns.Descriptor.Add(columnTotal);
  72. ///
  73. /// // create one row descriptor and a total
  74. /// HeaderDescriptor row = new HeaderDescriptor("[MatrixDemo.Name]");
  75. /// matrix.Data.Rows.Descriptor.Add(row);
  76. /// HeaderDescriptor rowTotal = new HeaderDescriptor();
  77. /// rowTotal.DisplayText = "Total";
  78. /// matrix.Data.Rows.Descriptor.Add(rowTotal);
  79. ///
  80. /// // connect matrix to a datasource
  81. /// matrix.DataSource = Report.GetDataSource("MatrixDemo");
  82. ///
  83. /// // create the matrix template
  84. /// matrix.BuildTemplate();
  85. ///
  86. /// // change the style
  87. /// matrix.Style = "Gray";
  88. ///
  89. /// // create data cells
  90. /// string cellText = "[Sum([MatrixDemo.Revenue])]";
  91. /// for (int i = matrix.Data.Rows.Size; i &lt; matrix.ColumnCount; i++)
  92. /// for (int j = matrix.Data.Columns.Size; j &lt; matrix.RowCount; j++)
  93. /// matrix[i, j].Text = cellText;
  94. /// </code>
  95. /// </example>
  96. public partial class AdvMatrixObject : TableBase
  97. {
  98. #region Fields
  99. private DataSourceBase dataSource;
  100. private string style;
  101. private bool saveVisible;
  102. #endregion
  103. #region Properties
  104. /// <summary>
  105. /// Gets or sets a data source.
  106. /// </summary>
  107. /// <remarks>
  108. /// When you create the matrix in the designer by drag-drop data columns into it,
  109. /// this property will be set automatically. However you need to set it if you create
  110. /// the matrix in code.
  111. /// </remarks>
  112. [Category("Data")]
  113. public DataSourceBase DataSource
  114. {
  115. get { return dataSource; }
  116. set
  117. {
  118. if (dataSource != value)
  119. {
  120. if (dataSource != null)
  121. dataSource.Disposed -= DataSource_Disposed;
  122. if (value != null)
  123. value.Disposed += DataSource_Disposed;
  124. }
  125. dataSource = value;
  126. }
  127. }
  128. /// <summary>
  129. /// Gets the row filter expression.
  130. /// </summary>
  131. /// <remarks>
  132. /// This property can contain any valid boolean expression. If the expression returns <b>false</b>,
  133. /// the corresponding data row will be skipped.
  134. /// </remarks>
  135. [Category("Data")]
  136. [Editor("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
  137. public string Filter { get; set; }
  138. /// <summary>
  139. /// Gets or sets a matrix style.
  140. /// </summary>
  141. [Category("Appearance")]
  142. [Editor("FastReport.TypeEditors.AdvMatrixStyleEditor, FastReport", typeof(UITypeEditor))]
  143. public new string Style
  144. {
  145. get { return style; }
  146. set
  147. {
  148. style = value;
  149. TemplateBuilder.UpdateStyle(this);
  150. }
  151. }
  152. /// <summary>
  153. /// Gets or sets even style priority for matrix cells.
  154. /// </summary>
  155. [Category("Behavior")]
  156. [DefaultValue(HeaderPriority.Rows)]
  157. public new HeaderPriority EvenStylePriority { get; set; }
  158. /// <summary>
  159. /// Gets or sets data row priority for matrix cells.
  160. /// </summary>
  161. [Category("Behavior")]
  162. [DefaultValue(HeaderPriority.Rows)]
  163. public HeaderPriority DataRowPriority { get; set; }
  164. /// <summary>
  165. /// Gets or sets a value indicating that empty matrix should be printed.
  166. /// </summary>
  167. [Category("Behavior")]
  168. [DefaultValue(true)]
  169. public bool PrintIfEmpty { get; set; }
  170. /// <summary>
  171. /// Gets or sets a value indicating that the matrix should reset its data on each report run.
  172. /// </summary>
  173. /// <remarks>
  174. /// Default value is false. In this case the matrix will use already prepared data when you refresh a report.
  175. /// If you set it to true the matrix data will be reset on each report refresh. This also resets all user interaction such as
  176. /// interactive sort and collapse state.
  177. /// </remarks>
  178. [Category("Behavior")]
  179. [DefaultValue(false)]
  180. public bool ResetDataOnRun { get; set; }
  181. /// <summary>
  182. /// Gets or sets a script method name that will be used to handle the
  183. /// <see cref="ManualBuild"/> event.
  184. /// </summary>
  185. /// <remarks>
  186. /// See the <see cref="ManualBuild"/> event for more details.
  187. /// </remarks>
  188. [Category("Build")]
  189. public string ManualBuildEvent { get; set; }
  190. /// <summary>
  191. /// Gets or sets a script method name that will be used to handle the
  192. /// <see cref="ModifyResult"/> event.
  193. /// </summary>
  194. /// <remarks>
  195. /// See the <see cref="ModifyResult"/> event for more details.
  196. /// </remarks>
  197. [Category("Build")]
  198. public string ModifyResultEvent { get; set; }
  199. /// <summary>
  200. /// Allows to fill the matrix in code.
  201. /// </summary>
  202. public event EventHandler ManualBuild;
  203. /// <summary>
  204. /// Allows to modify the prepared matrix elements such as cells, rows, columns.
  205. /// </summary>
  206. public event EventHandler ModifyResult;
  207. /// <summary>
  208. /// Gets the object that holds the collection of descriptors used to build a matrix.
  209. /// </summary>
  210. /// <remarks>
  211. /// See the <see cref="MatrixData"/> class for more details.
  212. /// </remarks>
  213. [Browsable(false)]
  214. public MatrixData Data { get; private set; }
  215. /// <summary>
  216. /// Gets or sets array of values that describes the currently printing column.
  217. /// </summary>
  218. /// <remarks>
  219. /// Use this property when report is running. It can be used to highlight matrix elements
  220. /// depending on values of the currently printing column. To do this:
  221. /// <list type="bullet">
  222. /// <item>
  223. /// <description>select the cell that you need to highlight;</description>
  224. /// </item>
  225. /// <item>
  226. /// <description>click the "Highlight" button on the "Text" toolbar;</description>
  227. /// </item>
  228. /// <item>
  229. /// <description>add a new highlight condition. Use the <b>Matrix.ColumnValues</b> to
  230. /// refer to the value you need to analyze. Note: these values are array of <b>dynamic</b>,
  231. /// so you don't need to cast it to actual type before making any comparisons. Example of highlight
  232. /// condition: <c>Matrix1.ColumnValues[0] == 2000</c>.
  233. /// </description>
  234. /// </item>
  235. /// </list>
  236. /// </remarks>
  237. [Browsable(false)]
  238. public dynamic[] ColumnValues { get; set; }
  239. /// <summary>
  240. /// Gets or sets array of values that describes the currently printing row.
  241. /// </summary>
  242. /// <remarks>
  243. /// Use this property when report is running. It can be used to highlight matrix elements
  244. /// depending on values of the currently printing row. To do this:
  245. /// <list type="bullet">
  246. /// <item>
  247. /// <description>select the cell that you need to highlight;</description>
  248. /// </item>
  249. /// <item>
  250. /// <description>click the "Highlight" button on the "Text" toolbar;</description>
  251. /// </item>
  252. /// <item>
  253. /// <description>add a new highlight condition. Use the <b>Matrix.RowValues</b> to
  254. /// refer to the value you need to analyze. Note: these values are arrays of <b>dynamic</b>,
  255. /// so you don't need to cast it to actual type before making any comparisons. Example of highlight
  256. /// condition: <c>Matrix1.RowValues[0] == "Andrew Fuller"</c>.
  257. /// </description>
  258. /// </item>
  259. /// </list>
  260. /// </remarks>
  261. [Browsable(false)]
  262. public dynamic[] RowValues { get; set; }
  263. /// <summary>
  264. /// Gets or sets the index of currently printing column.
  265. /// </summary>
  266. /// <remarks>
  267. /// This property may be used to print even columns with alternate color. To do this:
  268. /// <list type="bullet">
  269. /// <item>
  270. /// <description>select the cell that you need to highlight;</description>
  271. /// </item>
  272. /// <item>
  273. /// <description>click the "Highlight" button on the "Text" toolbar;</description>
  274. /// </item>
  275. /// <item>
  276. /// <description>add a new highlight condition that uses the <b>Matrix.ColumnIndex</b>,
  277. /// for example: <c>Matrix1.ColumnIndex % 2 == 1</c>.
  278. /// </description>
  279. /// </item>
  280. /// </list>
  281. /// </remarks>
  282. [Browsable(false)]
  283. public int ColumnIndex { get; set; }
  284. /// <summary>
  285. /// Gets or sets the index of currently printing row.
  286. /// </summary>
  287. /// <remarks>
  288. /// This property may be used to print even rows with alternate color. To do this:
  289. /// <list type="bullet">
  290. /// <item>
  291. /// <description>select the cell that you need to highlight;</description>
  292. /// </item>
  293. /// <item>
  294. /// <description>click the "Highlight" button on the "Text" toolbar;</description>
  295. /// </item>
  296. /// <item>
  297. /// <description>add a new highlight condition that uses the <b>Matrix.RowIndex</b>,
  298. /// for example: <c>Matrix1.RowIndex % 2 == 1</c>.
  299. /// </description>
  300. /// </item>
  301. /// </list>
  302. /// </remarks>
  303. [Browsable(false)]
  304. public int RowIndex { get; set; }
  305. /// <summary>
  306. /// Gets or sets the data row index of currently printing header.
  307. /// </summary>
  308. /// <remarks>
  309. /// Use this value if you want to display the header value with its data row number, e.g. "1. Andrew Fuller".
  310. /// To do this, set the header's DisplayExpression to something like this: Matrix1.RowNo + ". " + Value
  311. /// </remarks>
  312. [Browsable(false)]
  313. public int RowNo { get; set; }
  314. /// <summary>
  315. /// Gets or sets count of items in the currently printing header.
  316. /// </summary>
  317. [Browsable(false)]
  318. public int ItemCount { get; set; }
  319. protected internal override bool IsCompilationNeeded => true;
  320. internal Matrix.MatrixStyleSheet StyleSheet { get; private set; }
  321. private BandBase ParentBand
  322. {
  323. get
  324. {
  325. BandBase parentBand = this.Band;
  326. if (parentBand is ChildBand)
  327. parentBand = (parentBand as ChildBand).GetTopParentBand;
  328. return parentBand;
  329. }
  330. }
  331. private DataBand FootersDataBand
  332. {
  333. get
  334. {
  335. DataBand dataBand = null;
  336. if (ParentBand is GroupFooterBand)
  337. dataBand = ((ParentBand as GroupFooterBand).Parent as GroupHeaderBand).GroupDataBand;
  338. else if (ParentBand is DataFooterBand)
  339. dataBand = ParentBand.Parent as DataBand;
  340. return dataBand;
  341. }
  342. }
  343. private bool IsOnFooter
  344. {
  345. get
  346. {
  347. DataBand dataBand = FootersDataBand;
  348. if (dataBand != null)
  349. {
  350. return DataSource == dataBand.DataSource;
  351. }
  352. return false;
  353. }
  354. }
  355. #endregion
  356. #region Private Methods
  357. private void CreateResultTable()
  358. {
  359. SetResultTable(new TableResult());
  360. // assign properties from this object. Do not use Assign method: TableResult is incompatible with AdvMatrixObject.
  361. ResultTable.OriginalComponent = OriginalComponent;
  362. ResultTable.Alias = Alias;
  363. ResultTable.Border = Border.Clone();
  364. ResultTable.Fill = Fill.Clone();
  365. ResultTable.Bounds = Bounds;
  366. ResultTable.PrintOnParent = PrintOnParent;
  367. ResultTable.RepeatHeaders = RepeatHeaders;
  368. ResultTable.RepeatRowHeaders = RepeatRowHeaders;
  369. ResultTable.RepeatColumnHeaders = RepeatColumnHeaders;
  370. ResultTable.Layout = Layout;
  371. ResultTable.WrappedGap = WrappedGap;
  372. ResultTable.AdjustSpannedCellsWidth = AdjustSpannedCellsWidth;
  373. ResultTable.SetReport(Report);
  374. ResultTable.AfterData += ResultTable_AfterData;
  375. }
  376. private void DisposeResultTable()
  377. {
  378. ResultTable.Dispose();
  379. SetResultTable(null);
  380. }
  381. private void ResultTable_AfterData(object sender, EventArgs e)
  382. {
  383. OnModifyResult(e);
  384. }
  385. private void DataSource_Disposed(object sender, EventArgs e)
  386. {
  387. dataSource = null;
  388. }
  389. private void WireEvents(bool wire)
  390. {
  391. if (IsOnFooter)
  392. {
  393. DataBand dataBand = FootersDataBand;
  394. if (wire)
  395. dataBand.BeforePrint += dataBand_BeforePrint;
  396. else
  397. dataBand.BeforePrint -= dataBand_BeforePrint;
  398. }
  399. }
  400. private void dataBand_BeforePrint(object sender, EventArgs e)
  401. {
  402. bool firstRow = (sender as DataBand).IsFirstRow;
  403. if (firstRow)
  404. Data.Init();
  405. object match = true;
  406. if (!String.IsNullOrEmpty(Filter))
  407. match = Report.Calc(Filter);
  408. if (match is bool && (bool)match == true)
  409. Data.ProcessDataRow();
  410. }
  411. #endregion
  412. #region Protected Methods
  413. /// <inheritdoc/>
  414. protected override void DeserializeSubItems(FRReader reader)
  415. {
  416. if (String.Compare(reader.ItemName, "Columns", true) == 0)
  417. reader.Read(Data.Columns);
  418. else if (String.Compare(reader.ItemName, "Rows", true) == 0)
  419. reader.Read(Data.Rows);
  420. else
  421. base.DeserializeSubItems(reader);
  422. }
  423. #endregion
  424. #region Public Methods
  425. /// <inheritdoc/>
  426. public override void Assign(Base source)
  427. {
  428. BaseAssign(source);
  429. AdvMatrixObject src = source as AdvMatrixObject;
  430. DataSource = src.DataSource;
  431. }
  432. /// <inheritdoc/>
  433. public override void Serialize(FRWriter writer)
  434. {
  435. if (writer.SerializeTo != SerializeTo.SourcePages)
  436. {
  437. writer.Write(Data.Columns);
  438. writer.Write(Data.Rows);
  439. }
  440. base.Serialize(writer);
  441. AdvMatrixObject c = writer.DiffObject as AdvMatrixObject;
  442. if (DataSource != c.DataSource)
  443. writer.WriteRef("DataSource", DataSource);
  444. if (Filter != c.Filter)
  445. writer.WriteStr("Filter", Filter);
  446. if (Style != c.Style)
  447. writer.WriteStr("Style", Style);
  448. if (EvenStylePriority != c.EvenStylePriority)
  449. writer.WriteValue("EvenStylePriority", EvenStylePriority);
  450. if (DataRowPriority != c.DataRowPriority)
  451. writer.WriteValue("DataRowPriority", DataRowPriority);
  452. if (PrintIfEmpty != c.PrintIfEmpty)
  453. writer.WriteBool("PrintIfEmpty", PrintIfEmpty);
  454. if (ResetDataOnRun != c.ResetDataOnRun)
  455. writer.WriteBool("ResetDataOnRun", ResetDataOnRun);
  456. if (ManualBuildEvent != c.ManualBuildEvent)
  457. writer.WriteStr("ManualBuildEvent", ManualBuildEvent);
  458. if (ModifyResultEvent != c.ModifyResultEvent)
  459. writer.WriteStr("ModifyResultEvent", ModifyResultEvent);
  460. }
  461. /// <summary>
  462. /// Creates or updates the matrix template.
  463. /// </summary>
  464. /// <remarks>
  465. /// Call this method after you modify the matrix descriptors using the <see cref="Data"/> object's properties.
  466. /// </remarks>
  467. public void BuildTemplate()
  468. {
  469. if (Data.Columns.Descriptor.Items.Count == 0)
  470. Data.Columns.Descriptor.Add();
  471. if (Data.Rows.Descriptor.Items.Count == 0)
  472. Data.Rows.Descriptor.Add();
  473. TemplateBuilder.BuildTemplate(this);
  474. }
  475. /// <summary>
  476. /// This method fires the <b>ManualBuild</b> event and the script code connected to the <b>ManualBuildEvent</b>.
  477. /// </summary>
  478. /// <param name="e">Event data.</param>
  479. public void OnManualBuild(EventArgs e)
  480. {
  481. if (ManualBuild != null)
  482. ManualBuild(this, e);
  483. InvokeEvent(ManualBuildEvent, e);
  484. }
  485. /// <summary>
  486. /// This method fires the <b>ModifyResult</b> event and the script code connected to the <b>ModifyResultEvent</b>.
  487. /// </summary>
  488. /// <param name="e">Event data.</param>
  489. public void OnModifyResult(EventArgs e)
  490. {
  491. if (ModifyResult != null)
  492. ModifyResult(this, e);
  493. InvokeEvent(ModifyResultEvent, e);
  494. }
  495. /// <summary>
  496. /// Toggles visible state of the column with specified index. For internal use only.
  497. /// </summary>
  498. /// <param name="index">Index of column.</param>
  499. /// <param name="collapseAll">If true collapse all items.</param>
  500. /// <param name="expandAll">If true expand all items.</param>
  501. public void ToggleColumnVisible(int index, bool collapseAll = false, bool expandAll = false)
  502. {
  503. Data.Columns.Data.ToggleVisible(index, collapseAll, expandAll);
  504. }
  505. /// <summary>
  506. /// Toggles visible state of the row with specified index. For internal use only.
  507. /// </summary>
  508. /// <param name="index">Index of row.</param>
  509. /// <param name="collapseAll">If true collapse all items.</param>
  510. /// <param name="expandAll">If true expand all items.</param>
  511. public void ToggleRowVisible(int index, bool collapseAll = false, bool expandAll = false)
  512. {
  513. Data.Rows.Data.ToggleVisible(index, collapseAll, expandAll);
  514. }
  515. /// <summary>
  516. /// Sort columns based on values of row with specified index. For internal use only.
  517. /// </summary>
  518. /// <param name="rowIndex">Index of row.</param>
  519. /// <param name="sort">The sort order.</param>
  520. public void SortColumnsByRow(int rowIndex, SortOrder sort)
  521. {
  522. Data.InteractiveSort.Row.Index = rowIndex;
  523. Data.InteractiveSort.Row.Sort = sort;
  524. }
  525. /// <summary>
  526. /// Sort rows based on values of column with specified index. For internal use only.
  527. /// </summary>
  528. /// <param name="columnIndex">Index of column.</param>
  529. /// <param name="sort">The sort order.</param>
  530. public void SortRowsByColumn(int columnIndex, SortOrder sort)
  531. {
  532. Data.InteractiveSort.Column.Index = columnIndex;
  533. Data.InteractiveSort.Column.Sort = sort;
  534. }
  535. #endregion
  536. #region Report Engine
  537. /// <inheritdoc/>
  538. public override void ResetData()
  539. {
  540. Data.Reset();
  541. }
  542. /// <inheritdoc/>
  543. public override void InitializeComponent()
  544. {
  545. base.InitializeComponent();
  546. WireEvents(true);
  547. }
  548. /// <inheritdoc/>
  549. public override void FinalizeComponent()
  550. {
  551. base.FinalizeComponent();
  552. WireEvents(false);
  553. }
  554. /// <inheritdoc/>
  555. public override string[] GetExpressions()
  556. {
  557. List<string> expressions = new List<string>();
  558. TemplateBuilder.UpdateDescriptors(this);
  559. expressions.AddRange(base.GetExpressions());
  560. expressions.AddRange(Data.GetExpressions());
  561. if (!String.IsNullOrEmpty(Filter))
  562. expressions.Add(Filter);
  563. return expressions.ToArray();
  564. }
  565. /// <inheritdoc/>
  566. public override void SaveState()
  567. {
  568. saveVisible = Visible;
  569. BandBase parent = Parent as BandBase;
  570. if (!Visible || (parent != null && !parent.Visible))
  571. return;
  572. // create the result table that will be rendered in the preview
  573. CreateResultTable();
  574. Visible = false;
  575. if (parent != null && !PrintOnParent)
  576. {
  577. parent.Height = Top;
  578. parent.CanGrow = false;
  579. parent.CanShrink = false;
  580. parent.AfterPrint += ResultTable.GeneratePages;
  581. }
  582. }
  583. /// <inheritdoc/>
  584. public override void GetData()
  585. {
  586. base.GetData();
  587. if (ResetDataOnRun)
  588. Data.Reset();
  589. if (!IsOnFooter && !Data.Completed)
  590. {
  591. // skip data processing if it was done before. It may happen if:
  592. // - second pass of two-pass report
  593. // - preview window needs to refresh a report due to user interaction
  594. Data.Init();
  595. Data.ProcessDataRows();
  596. }
  597. }
  598. /// <inheritdoc/>
  599. public override void OnAfterData(EventArgs e)
  600. {
  601. base.OnAfterData(e);
  602. Data.Done();
  603. if (PrintOnParent)
  604. ResultTable.AddToParent(Parent);
  605. }
  606. /// <inheritdoc/>
  607. public override void RestoreState()
  608. {
  609. BandBase parent = Parent as BandBase;
  610. if (!saveVisible || (parent != null && !parent.Visible))
  611. return;
  612. if (parent != null && !PrintOnParent)
  613. parent.AfterPrint -= ResultTable.GeneratePages;
  614. DisposeResultTable();
  615. Visible = saveVisible;
  616. }
  617. #endregion
  618. /// <summary>
  619. /// Initializes a new instance of the <see cref="AdvMatrixObject"/> class.
  620. /// </summary>
  621. public AdvMatrixObject()
  622. {
  623. BaseName = "Matrix";
  624. Data = new MatrixData(this);
  625. Filter = "";
  626. PrintIfEmpty = true;
  627. StyleSheet = new Matrix.MatrixStyleSheet();
  628. StyleSheet.Load(ResourceLoader.GetStream("cross.frss"));
  629. style = "";
  630. ManualBuildEvent = "";
  631. ModifyResultEvent = "";
  632. }
  633. }
  634. }