using System; using System.Collections.Generic; using System.Text; using FastReport.Utils; using System.Collections; namespace FastReport.Matrix { /// /// Contains a set of properties and methods to hold and manipulate the matrix descriptors. /// /// /// This class contains three collections of descriptors such as , /// and . Use collections' methods to add/remove /// descriptors. When you are done, call the /// method to refresh the matrix. /// To fill a matrix in code, use the AddValue method. /// public class MatrixData { #region Fields private MatrixHeader columns; private MatrixHeader rows; private MatrixCells cells; #endregion #region Properties /// /// Gets a collection of column descriptors. /// /// /// Note: after you change something in this collection, call the /// method to refresh the matrix. /// public MatrixHeader Columns { get { return columns; } } /// /// Gets a collection of row descriptors. /// /// /// Note: after you change something in this collection, call the /// method to refresh the matrix. /// public MatrixHeader Rows { get { return rows; } } /// /// Gets a collection of data cell descriptors. /// /// /// Note: after you change something in this collection, call the /// method to refresh the matrix. /// public MatrixCells Cells { get { return cells; } } internal bool IsEmpty { get { return Cells.IsEmpty; } } #endregion #region Public Methods /// /// Clears all descriptors. /// public void Clear() { Columns.Reset(); Rows.Reset(); Cells.Reset(); } /// /// Adds a value in the matrix. /// /// Array of column values. /// Array of row values. /// Array of data values. /// /// The number of elements in an array passed to this method must be the same as /// a number of descriptors in the appropriate collection. That is, if your matrix /// has one column, two row and one cell descriptors (in Columns, Rows and /// Cells collections respectively), you have to pass one-element array for the /// columnValues param, two-element array for the rowValues and one-element /// array for the cellValues. /// /// This example demonstrates how to fill a simple matrix that contains one column, /// row and cell. /// /// MatrixObject matrix; /// matrix.Data.AddValue( /// new object[] { 1996 }, /// new object[] { "Andrew Fuller" }, /// new object[] { 123.45f }); /// /// // this will produce the following result: /// // | 1996 | /// // --------------+----------+ /// // Andrew Fuller | 123.45| /// // --------------+----------+ /// /// public void AddValue(object[] columnValues, object[] rowValues, object[] cellValues) { AddValue(columnValues, rowValues, cellValues, 0); } /// /// Adds a value in the matrix. /// /// Array of column values. /// Array of row values. /// Array of data values. /// Datasource row index. /// /// See the method for more details. /// public void AddValue(object[] columnValues, object[] rowValues, object[] cellValues, int dataRowNo) { MatrixHeaderItem column = Columns.Find(columnValues, true, dataRowNo); MatrixHeaderItem row = Rows.Find(rowValues, true, dataRowNo); Cells.AddValue(column.Index, row.Index, cellValues); } internal ArrayList GetValues(int columnIndex, int rowIndex, int cellIndex) { return Cells.GetValues(columnIndex, rowIndex, cellIndex); } internal void SetValues(int columnIndex, int rowIndex, object[] cellValues) { Cells.SetValues(columnIndex, rowIndex, cellValues); } /// /// Gets a value with specified column, row and cell indicies. /// /// Index of a column. /// Index of a row. /// Index of a cell. /// The value of a cell. public object GetValue(int columnIndex, int rowIndex, int cellIndex) { return Cells.GetValue(columnIndex, rowIndex, cellIndex); } /// /// Sets the cell's value. /// /// Index of a column. /// Index of a row. /// The new value. public void SetValue(int columnIndex, int rowIndex, object cellValue) { SetValues(columnIndex, rowIndex, new object[] { cellValue }); } #endregion internal MatrixData() { columns = new MatrixHeader(); columns.Name = "MatrixColumns"; rows = new MatrixHeader(); rows.Name = "MatrixRows"; cells = new MatrixCells(); cells.Name = "MatrixCells"; } } }