using System;
using System.Collections.Generic;
using System.Text;
using FastReport.Table;
using FastReport.Utils;
namespace FastReport.Matrix
{
///
/// The descriptor that is used to describe one element of the matrix header.
///
///
/// The class is used to define one header element of the matrix
/// (either the column element or row element). The key properties are
/// , and .
/// To set visual appearance of the element, use the
/// property. To set visual appearance of the "total" element, use the
/// property.
/// The collection of descriptors used to represent the matrix header is stored
/// in the MatrixObject.Data.Columns and MatrixObject.Data.Rows properties.
///
public class MatrixHeaderDescriptor : MatrixDescriptor
{
#region Fields
private SortOrder sort;
private bool totals;
private bool totalsFirst;
private bool pageBreak;
private bool suppressTotals;
private TableColumn templateTotalColumn;
private TableRow templateTotalRow;
private TableCell templateTotalCell;
#endregion
#region Properties
///
/// Gets or sets the sort order of header values.
///
///
/// This property determines how the values displayed in this element are sorted. The default sort
/// is ascending.
///
public SortOrder Sort
{
get { return sort; }
set { sort = value; }
}
///
/// Gets or sets a value indicating that this element has associated "total" element.
///
///
/// To access the matrix cell that is bound to the "Total" element, use the
/// property. It may be useful to change the
/// "Total" text by something else.
///
/// This example shows how to change the "Total" text of the total element.
///
/// MatrixObject matrix;
/// matrix.Data.Rows[0].TemplateTotalCell.Text = "Grand Total";
///
///
public bool Totals
{
get { return totals; }
set { totals = value; }
}
///
/// Gets or sets the value indicating whether the total values must be printed before the data.
///
public bool TotalsFirst
{
get { return totalsFirst; }
set { totalsFirst = value; }
}
///
/// Gets or sets a value indicating that the page break must be printed before this element.
///
///
/// Page break is not printed before the very first element.
///
public bool PageBreak
{
get { return pageBreak; }
set { pageBreak = value; }
}
///
/// Gets or sets a value that determines whether it is necessary to suppress totals
/// if there is only one value in a group.
///
public bool SuppressTotals
{
get { return suppressTotals; }
set { suppressTotals = value; }
}
///
/// Gets or sets the template column bound to the "total" element of this descriptor.
///
///
/// This property is for internal use; usually you don't need to use it.
///
public TableColumn TemplateTotalColumn
{
get { return templateTotalColumn; }
set { templateTotalColumn = value; }
}
///
/// Gets or sets the template row bound to the "total" element of this descriptor.
///
///
/// This property is for internal use; usually you don't need to use it.
///
public TableRow TemplateTotalRow
{
get { return templateTotalRow; }
set { templateTotalRow = value; }
}
///
/// Gets or sets the template cell bound to the "total" element of this descriptor.
///
///
/// This property may be useful to change the "Total" text by something else.
///
/// Before using this property, you must initialize the matrix descriptors by
/// calling the method.
///
///
/// This example shows how to change the "Total" element.
///
/// MatrixObject matrix;
/// matrix.Data.Rows[0].TemplateTotalCell.Text = "Grand Total";
/// matrix.Data.Rows[0].TemplateTotalCell.Fill = new SolidFill(Color.Green);
///
///
public TableCell TemplateTotalCell
{
get { return templateTotalCell; }
set { templateTotalCell = value; }
}
#endregion
#region Public Methods
///
public override void Assign(MatrixDescriptor source)
{
base.Assign(source);
MatrixHeaderDescriptor src = source as MatrixHeaderDescriptor;
if (src != null)
{
Sort = src.Sort;
Totals = src.Totals;
TotalsFirst = src.TotalsFirst;
PageBreak = src.PageBreak;
SuppressTotals = src.SuppressTotals;
TemplateTotalCell = src.TemplateTotalCell;
}
}
///
public override void Serialize(FRWriter writer)
{
MatrixHeaderDescriptor c = writer.DiffObject as MatrixHeaderDescriptor;
base.Serialize(writer);
writer.ItemName = "Header";
if (Sort != c.Sort)
writer.WriteValue("Sort", Sort);
if (Totals != c.Totals)
writer.WriteBool("Totals", Totals);
if (TotalsFirst != c.TotalsFirst)
writer.WriteBool("TotalsFirst", TotalsFirst);
if (PageBreak != c.PageBreak)
writer.WriteBool("PageBreak", PageBreak);
if (SuppressTotals != c.SuppressTotals)
writer.WriteBool("SuppressTotals", SuppressTotals);
}
#endregion
///
/// Initializes a new instance of the class with
/// default settings.
///
public MatrixHeaderDescriptor()
: this("", SortOrder.Ascending, true)
{
}
///
/// Initializes a new instance of the class with
/// specified expression.
///
/// The descriptor's expression.
public MatrixHeaderDescriptor(string expression)
: this(expression, SortOrder.Ascending, true)
{
}
///
/// Initializes a new instance of the class with
/// specified expression and totals.
///
/// The descriptor's expression.
/// Indicates whether to show the "total" element.
public MatrixHeaderDescriptor(string expression, bool totals)
: this(expression, SortOrder.Ascending, totals)
{
}
///
/// Initializes a new instance of the class with
/// specified expression, sort order and totals.
///
/// The descriptor's expression.
/// Sort order used to sort header values.
/// Indicates whether to show the "total" element.
public MatrixHeaderDescriptor(string expression, SortOrder sort, bool totals)
{
Expression = expression;
this.sort = sort;
this.totals = totals;
}
}
}