AdvMatrixObject.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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. internal Matrix.MatrixStyleSheet StyleSheet { get; private set; }
  320. private BandBase ParentBand
  321. {
  322. get
  323. {
  324. BandBase parentBand = this.Band;
  325. if (parentBand is ChildBand)
  326. parentBand = (parentBand as ChildBand).GetTopParentBand;
  327. return parentBand;
  328. }
  329. }
  330. private DataBand FootersDataBand
  331. {
  332. get
  333. {
  334. DataBand dataBand = null;
  335. if (ParentBand is GroupFooterBand)
  336. dataBand = ((ParentBand as GroupFooterBand).Parent as GroupHeaderBand).GroupDataBand;
  337. else if (ParentBand is DataFooterBand)
  338. dataBand = ParentBand.Parent as DataBand;
  339. return dataBand;
  340. }
  341. }
  342. private bool IsOnFooter
  343. {
  344. get
  345. {
  346. DataBand dataBand = FootersDataBand;
  347. if (dataBand != null)
  348. {
  349. return DataSource == dataBand.DataSource;
  350. }
  351. return false;
  352. }
  353. }
  354. #endregion
  355. #region Private Methods
  356. private void CreateResultTable()
  357. {
  358. SetResultTable(new TableResult());
  359. // assign properties from this object. Do not use Assign method: TableResult is incompatible with AdvMatrixObject.
  360. ResultTable.OriginalComponent = OriginalComponent;
  361. ResultTable.Alias = Alias;
  362. ResultTable.Border = Border.Clone();
  363. ResultTable.Fill = Fill.Clone();
  364. ResultTable.Bounds = Bounds;
  365. ResultTable.PrintOnParent = PrintOnParent;
  366. ResultTable.RepeatHeaders = RepeatHeaders;
  367. ResultTable.RepeatRowHeaders = RepeatRowHeaders;
  368. ResultTable.RepeatColumnHeaders = RepeatColumnHeaders;
  369. ResultTable.Layout = Layout;
  370. ResultTable.WrappedGap = WrappedGap;
  371. ResultTable.AdjustSpannedCellsWidth = AdjustSpannedCellsWidth;
  372. ResultTable.SetReport(Report);
  373. ResultTable.AfterData += ResultTable_AfterData;
  374. }
  375. private void DisposeResultTable()
  376. {
  377. ResultTable.Dispose();
  378. SetResultTable(null);
  379. }
  380. private void ResultTable_AfterData(object sender, EventArgs e)
  381. {
  382. OnModifyResult(e);
  383. }
  384. private void DataSource_Disposed(object sender, EventArgs e)
  385. {
  386. dataSource = null;
  387. }
  388. private void WireEvents(bool wire)
  389. {
  390. if (IsOnFooter)
  391. {
  392. DataBand dataBand = FootersDataBand;
  393. if (wire)
  394. dataBand.BeforePrint += dataBand_BeforePrint;
  395. else
  396. dataBand.BeforePrint -= dataBand_BeforePrint;
  397. }
  398. }
  399. private void dataBand_BeforePrint(object sender, EventArgs e)
  400. {
  401. bool firstRow = (sender as DataBand).IsFirstRow;
  402. if (firstRow)
  403. Data.Init();
  404. object match = true;
  405. if (!String.IsNullOrEmpty(Filter))
  406. match = Report.Calc(Filter);
  407. if (match is bool && (bool)match == true)
  408. Data.ProcessDataRow();
  409. }
  410. #endregion
  411. #region Protected Methods
  412. /// <inheritdoc/>
  413. protected override void DeserializeSubItems(FRReader reader)
  414. {
  415. if (String.Compare(reader.ItemName, "Columns", true) == 0)
  416. reader.Read(Data.Columns);
  417. else if (String.Compare(reader.ItemName, "Rows", true) == 0)
  418. reader.Read(Data.Rows);
  419. else
  420. base.DeserializeSubItems(reader);
  421. }
  422. #endregion
  423. #region Public Methods
  424. /// <inheritdoc/>
  425. public override void Assign(Base source)
  426. {
  427. BaseAssign(source);
  428. AdvMatrixObject src = source as AdvMatrixObject;
  429. DataSource = src.DataSource;
  430. }
  431. /// <inheritdoc/>
  432. public override void Serialize(FRWriter writer)
  433. {
  434. if (writer.SerializeTo != SerializeTo.SourcePages)
  435. {
  436. writer.Write(Data.Columns);
  437. writer.Write(Data.Rows);
  438. }
  439. base.Serialize(writer);
  440. AdvMatrixObject c = writer.DiffObject as AdvMatrixObject;
  441. if (DataSource != c.DataSource)
  442. writer.WriteRef("DataSource", DataSource);
  443. if (Filter != c.Filter)
  444. writer.WriteStr("Filter", Filter);
  445. if (Style != c.Style)
  446. writer.WriteStr("Style", Style);
  447. if (EvenStylePriority != c.EvenStylePriority)
  448. writer.WriteValue("EvenStylePriority", EvenStylePriority);
  449. if (DataRowPriority != c.DataRowPriority)
  450. writer.WriteValue("DataRowPriority", DataRowPriority);
  451. if (PrintIfEmpty != c.PrintIfEmpty)
  452. writer.WriteBool("PrintIfEmpty", PrintIfEmpty);
  453. if (ResetDataOnRun != c.ResetDataOnRun)
  454. writer.WriteBool("ResetDataOnRun", ResetDataOnRun);
  455. if (ManualBuildEvent != c.ManualBuildEvent)
  456. writer.WriteStr("ManualBuildEvent", ManualBuildEvent);
  457. if (ModifyResultEvent != c.ModifyResultEvent)
  458. writer.WriteStr("ModifyResultEvent", ModifyResultEvent);
  459. }
  460. /// <summary>
  461. /// Creates or updates the matrix template.
  462. /// </summary>
  463. /// <remarks>
  464. /// Call this method after you modify the matrix descriptors using the <see cref="Data"/> object's properties.
  465. /// </remarks>
  466. public void BuildTemplate()
  467. {
  468. if (Data.Columns.Descriptor.Items.Count == 0)
  469. Data.Columns.Descriptor.Add();
  470. if (Data.Rows.Descriptor.Items.Count == 0)
  471. Data.Rows.Descriptor.Add();
  472. TemplateBuilder.BuildTemplate(this);
  473. }
  474. /// <summary>
  475. /// This method fires the <b>ManualBuild</b> event and the script code connected to the <b>ManualBuildEvent</b>.
  476. /// </summary>
  477. /// <param name="e">Event data.</param>
  478. public void OnManualBuild(EventArgs e)
  479. {
  480. if (ManualBuild != null)
  481. ManualBuild(this, e);
  482. InvokeEvent(ManualBuildEvent, e);
  483. }
  484. /// <summary>
  485. /// This method fires the <b>ModifyResult</b> event and the script code connected to the <b>ModifyResultEvent</b>.
  486. /// </summary>
  487. /// <param name="e">Event data.</param>
  488. public void OnModifyResult(EventArgs e)
  489. {
  490. if (ModifyResult != null)
  491. ModifyResult(this, e);
  492. InvokeEvent(ModifyResultEvent, e);
  493. }
  494. /// <summary>
  495. /// Toggles visible state of the column with specified index. For internal use only.
  496. /// </summary>
  497. /// <param name="index">Index of column.</param>
  498. /// <param name="collapseAll">If true collapse all items.</param>
  499. /// <param name="expandAll">If true expand all items.</param>
  500. public void ToggleColumnVisible(int index, bool collapseAll = false, bool expandAll = false)
  501. {
  502. Data.Columns.Data.ToggleVisible(index, collapseAll, expandAll);
  503. }
  504. /// <summary>
  505. /// Toggles visible state of the row with specified index. For internal use only.
  506. /// </summary>
  507. /// <param name="index">Index of row.</param>
  508. /// <param name="collapseAll">If true collapse all items.</param>
  509. /// <param name="expandAll">If true expand all items.</param>
  510. public void ToggleRowVisible(int index, bool collapseAll = false, bool expandAll = false)
  511. {
  512. Data.Rows.Data.ToggleVisible(index, collapseAll, expandAll);
  513. }
  514. /// <summary>
  515. /// Sort columns based on values of row with specified index. For internal use only.
  516. /// </summary>
  517. /// <param name="rowIndex">Index of row.</param>
  518. /// <param name="sort">The sort order.</param>
  519. public void SortColumnsByRow(int rowIndex, SortOrder sort)
  520. {
  521. Data.InteractiveSort.Row.Index = rowIndex;
  522. Data.InteractiveSort.Row.Sort = sort;
  523. }
  524. /// <summary>
  525. /// Sort rows based on values of column with specified index. For internal use only.
  526. /// </summary>
  527. /// <param name="columnIndex">Index of column.</param>
  528. /// <param name="sort">The sort order.</param>
  529. public void SortRowsByColumn(int columnIndex, SortOrder sort)
  530. {
  531. Data.InteractiveSort.Column.Index = columnIndex;
  532. Data.InteractiveSort.Column.Sort = sort;
  533. }
  534. #endregion
  535. #region Report Engine
  536. /// <inheritdoc/>
  537. public override void InitializeComponent()
  538. {
  539. base.InitializeComponent();
  540. WireEvents(true);
  541. }
  542. /// <inheritdoc/>
  543. public override void FinalizeComponent()
  544. {
  545. base.FinalizeComponent();
  546. WireEvents(false);
  547. }
  548. /// <inheritdoc/>
  549. public override string[] GetExpressions()
  550. {
  551. List<string> expressions = new List<string>();
  552. TemplateBuilder.UpdateDescriptors(this);
  553. expressions.AddRange(base.GetExpressions());
  554. expressions.AddRange(Data.GetExpressions());
  555. if (!String.IsNullOrEmpty(Filter))
  556. expressions.Add(Filter);
  557. return expressions.ToArray();
  558. }
  559. /// <inheritdoc/>
  560. public override void SaveState()
  561. {
  562. saveVisible = Visible;
  563. BandBase parent = Parent as BandBase;
  564. if (!Visible || (parent != null && !parent.Visible))
  565. return;
  566. // create the result table that will be rendered in the preview
  567. CreateResultTable();
  568. Visible = false;
  569. if (parent != null && !PrintOnParent)
  570. {
  571. parent.Height = Top;
  572. parent.CanGrow = false;
  573. parent.CanShrink = false;
  574. parent.AfterPrint += ResultTable.GeneratePages;
  575. }
  576. }
  577. /// <inheritdoc/>
  578. public override void GetData()
  579. {
  580. base.GetData();
  581. if (ResetDataOnRun)
  582. Data.Reset();
  583. if (!IsOnFooter && !Data.Completed)
  584. {
  585. // skip data processing if it was done before. It may happen if:
  586. // - second pass of two-pass report
  587. // - preview window needs to refresh a report due to user interaction
  588. Data.Init();
  589. Data.ProcessDataRows();
  590. }
  591. }
  592. /// <inheritdoc/>
  593. public override void OnAfterData(EventArgs e)
  594. {
  595. base.OnAfterData(e);
  596. Data.Done();
  597. if (PrintOnParent)
  598. ResultTable.AddToParent(Parent);
  599. }
  600. /// <inheritdoc/>
  601. public override void RestoreState()
  602. {
  603. BandBase parent = Parent as BandBase;
  604. if (!saveVisible || (parent != null && !parent.Visible))
  605. return;
  606. if (parent != null && !PrintOnParent)
  607. parent.AfterPrint -= ResultTable.GeneratePages;
  608. DisposeResultTable();
  609. Visible = saveVisible;
  610. }
  611. #endregion
  612. /// <summary>
  613. /// Initializes a new instance of the <see cref="AdvMatrixObject"/> class.
  614. /// </summary>
  615. public AdvMatrixObject()
  616. {
  617. BaseName = "Matrix";
  618. Data = new MatrixData(this);
  619. Filter = "";
  620. PrintIfEmpty = true;
  621. StyleSheet = new Matrix.MatrixStyleSheet();
  622. StyleSheet.Load(ResourceLoader.GetStream("cross.frss"));
  623. style = "";
  624. ManualBuildEvent = "";
  625. ModifyResultEvent = "";
  626. }
  627. }
  628. }