using System;
using System.Collections;
using System.Collections.Generic;
using FastReport.Data;
namespace FastReport.AdvMatrix
{
///
/// Contains a set of properties and methods to hold and manipulate the matrix descriptors.
///
///
/// This class contains two collections of descriptors such as and
/// . Use collections' methods to add/remove descriptors.
/// When you are done, call the method to refresh the matrix.
///
public class MatrixData
{
internal AdvMatrixObject Matrix { get; private set; }
internal bool Completed { get; private set; }
///
/// Gets a collection of column descriptors.
///
///
/// Note: after you add or remove items in this collection, call the
/// method to refresh the matrix.
///
public MatrixHeader Columns { get; private set; }
///
/// Gets a collection of row descriptors.
///
///
/// Note: after you add or remove items in this collection, call the
/// method to refresh the matrix.
///
public MatrixHeader Rows { get; private set; }
internal CellData CellData { get; private set; }
///
/// Gets context required for aggregate calculation.
///
public Context Context { get; private set; }
internal InteractiveSortInfo InteractiveSort { get; private set; }
internal bool IsEmpty { get { return Columns.Data.Items.Count == 0; } }
internal string[] GetExpressions()
{
List expressions = new List();
Columns.GetExpressions(expressions);
Rows.GetExpressions(expressions);
CellData.GetExpressions(expressions);
return expressions.ToArray();
}
internal void Init()
{
Columns.Init();
Rows.Init();
CellData.Init();
}
internal void Done()
{
if (!Completed)
{
if (IsEmpty && Matrix.PrintIfEmpty)
ProcessDataRow();
TopNBuilder.Process(Matrix);
Completed = true;
}
if (!IsEmpty)
ResultBuilder.BuildResult(Matrix);
}
internal void ProcessDataRows()
{
DataSourceBase dataSource = Matrix.DataSource;
if (dataSource != null)
{
dataSource.Init(Matrix.Filter);
while (dataSource.HasMoreRows)
{
ProcessDataRow();
dataSource.Next();
}
}
else
{
Matrix.OnManualBuild(EventArgs.Empty);
}
}
///
/// Processes single data row.
///
///
/// This method is used internally to process current data row. The matrix fills the column, row and cell data.
/// You should use this method if you fill a matrix in code using ManualBuild event.
///
public void ProcessDataRow()
{
CellData.ProcessDataRow(Columns.ProcessDataRow(), Rows.ProcessDataRow());
}
///
/// Resets the data from the previous report run.
///
public void Reset()
{
Completed = false;
}
///
/// Initializes a new instance of the class.
///
/// Reference to owner matrix.
public MatrixData(AdvMatrixObject matrix)
{
Matrix = matrix;
Columns = new MatrixHeader(matrix, "Columns");
Rows = new MatrixHeader(matrix, "Rows");
CellData = new CellData(matrix);
Context = new Context();
InteractiveSort = new InteractiveSortInfo(this);
}
}
}