Exemple #1
0
        private void AddTotalItems(MatrixHeaderItem rootItem, int descriptorIndex, bool isTemplate)
        {
            if (descriptorIndex >= Count)
            {
                return;
            }

            foreach (MatrixHeaderItem item in rootItem.Items)
            {
                AddTotalItems(item, descriptorIndex + 1, isTemplate);
            }

            if (this[descriptorIndex].Totals &&
                (isTemplate || !this[descriptorIndex].SuppressTotals || rootItem.Items.Count > 1))
            {
                MatrixHeaderItem totalItem = new MatrixHeaderItem(rootItem);
                totalItem.IsTotal        = true;
                totalItem.Value          = rootItem.Value;
                totalItem.DataRowNo      = rootItem.DataRowNo;
                totalItem.TemplateColumn = this[descriptorIndex].TemplateTotalColumn;
                totalItem.TemplateRow    = this[descriptorIndex].TemplateTotalRow;
                totalItem.TemplateCell   = this[descriptorIndex].TemplateTotalCell;
                totalItem.Index          = FNextIndex;
                FNextIndex++;

                if (this[descriptorIndex].TotalsFirst && !isTemplate)
                {
                    rootItem.Items.Insert(0, totalItem);
                }
                else
                {
                    rootItem.Items.Add(totalItem);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Adds a value in the matrix.
        /// </summary>
        /// <param name="columnValues">Array of column values.</param>
        /// <param name="rowValues">Array of row values.</param>
        /// <param name="cellValues">Array of data values.</param>
        /// <param name="dataRowNo">Datasource row index.</param>
        /// <remarks>
        /// See the <see cref="AddValue(object[],object[],object[])"/> method for more details.
        /// </remarks>
        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);
        }
Exemple #3
0
        /// <summary>
        /// Removes a header item with the address specified.
        /// </summary>
        /// <param name="address">The address of a header.</param>
        public void RemoveItem(object[] address)
        {
            MatrixHeaderItem item = Find(address, false, 0);

            if (item != null)
            {
                item.Parent.Items.Remove(item);
            }
        }
Exemple #4
0
        /// <summary>
        /// Gets an index of header with the address specified. If there is no such header item, it will be created.
        /// </summary>
        /// <param name="address">The address of a header.</param>
        /// <returns>The index of header.</returns>
        public int FindOrCreate(object[] address)
        {
            MatrixHeaderItem item = Find(address, true, 0);

            if (item != null)
            {
                return(item.Index);
            }
            return(-1);
        }
Exemple #5
0
 private object GetCellValue(MatrixHeaderItem columnItem, MatrixHeaderItem rowItem, int cellIndex)
 {
     if (columnItem.IsTotal || rowItem.IsTotal)
     {
         return(GetAggregatedTotalValue(columnItem, rowItem, cellIndex));
     }
     else
     {
         return(GetAggregatedValue(Matrix.Data.GetValues(columnItem.Index, rowItem.Index, cellIndex), cellIndex));
     }
 }
Exemple #6
0
        private int[] GetTerminalIndices(MatrixHeaderItem rootItem)
        {
            List <MatrixHeaderItem> terminalItems = rootItem.GetTerminalItems();

            int[] result = new int[terminalItems.Count];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = terminalItems[i].Index;
            }
            return(result);
        }
Exemple #7
0
        private void PrintHeaderCell(MatrixHeaderItem item, TableCellData resultCell, bool isEven)
        {
            TableCell templateCell = item.TemplateCell;

            if (templateCell != null)
            {
                if (FDesignTime)
                {
                    if (!item.IsTotal)
                    {
                        templateCell.Text = item.Value.ToString();
                    }
                    resultCell.RunTimeAssign(templateCell, true);
                }
                else
                {
                    if (Matrix.DataSource != null)
                    {
                        Matrix.DataSource.CurrentRowNo = item.DataRowNo;
                    }

                    templateCell.SetValue(item.Value);
                    if (!item.IsTotal)
                    {
                        templateCell.Text = templateCell.Format.FormatValue(item.Value);
                    }
                    templateCell.SaveState();
                    templateCell.GetData();
                    if (String.IsNullOrEmpty(templateCell.Hyperlink.Expression) &&
                        (templateCell.Hyperlink.Kind == HyperlinkKind.DetailReport ||
                         templateCell.Hyperlink.Kind == HyperlinkKind.DetailPage ||
                         templateCell.Hyperlink.Kind == HyperlinkKind.Custom))
                    {
                        templateCell.Hyperlink.Value = templateCell.Text;
                    }

                    if (isEven)
                    {
                        templateCell.ApplyEvenStyle();
                    }
                    resultCell.RunTimeAssign(templateCell, true);
                    templateCell.RestoreState();
                }
            }
            else
            {
                templateCell = CreateCell(item.IsTotal ? Res.Get("ComponentsMisc,Matrix,Total") : item.Value.ToString());
                resultCell.RunTimeAssign(templateCell, true);
            }
        }
Exemple #8
0
        internal MatrixHeaderItem Find(object[] address, bool create, int dataRowNo)
        {
            // Note that the top header itself does not contain a value.
            // It is used as a list of first-level headers only.
            MatrixHeaderItem rootItem = RootItem;

            for (int i = 0; i < address.Length; i++)
            {
                int index = rootItem.Find(address[i], this[i].Sort);

                if (matrix.SplitRows && address.Length == 1 && index >= 0)
                {
                    rootItem = rootItem.Items[index];
                }
                else if (!matrix.SplitRows && index >= 0)
                {
                    rootItem = rootItem.Items[index];
                }
                else if (create)
                {
                    // create new item if necessary.
                    MatrixHeaderItem newItem = new MatrixHeaderItem(rootItem);
                    newItem.Value          = address[i];
                    newItem.TemplateColumn = this[i].TemplateColumn;
                    newItem.TemplateRow    = this[i].TemplateRow;
                    newItem.TemplateCell   = this[i].TemplateCell;
                    newItem.DataRowNo      = dataRowNo;
                    newItem.PageBreak      = this[i].PageBreak;

                    // index is used as a cell address in a matrix
                    if (i == address.Length - 1)
                    {
                        // create index for bottom-level header
                        newItem.Index = nextIndex;
                        nextIndex++;
                    }

                    rootItem.Items.Insert(index >= 0 ? index : ~index, newItem);
                    rootItem = newItem;
                }
                else
                {
                    return(null);
                }
            }

            return(rootItem);
        }
Exemple #9
0
        private object GetAggregatedTotalValue(MatrixHeaderItem column, MatrixHeaderItem row, int cellIndex)
        {
            ArrayList list = new ArrayList();

            if (column.IsTotal)
            {
                column = column.Parent;
            }
            if (row.IsTotal)
            {
                row = row.Parent;
            }

            List <MatrixHeaderItem> columnTerminalItems = column.GetTerminalItems();
            List <MatrixHeaderItem> rowTerminalItems    = row.GetTerminalItems();

            // collect all values in the specified items
            foreach (MatrixHeaderItem rowItem in rowTerminalItems)
            {
                if (rowItem.IsTotal)
                {
                    continue;
                }

                foreach (MatrixHeaderItem columnItem in columnTerminalItems)
                {
                    if (columnItem.IsTotal)
                    {
                        continue;
                    }

                    ArrayList values = Matrix.Data.GetValues(columnItem.Index, rowItem.Index, cellIndex);
                    if (values != null)
                    {
                        list.AddRange(values);
                    }
                }
            }

            object value = GetAggregatedValue(list, cellIndex);

            // totals cannot be empty, return null values as 0
            return(value == null ? 0 : value);
        }
Exemple #10
0
        public int Find(object value, SortOrder sort)
        {
            if (Items.Count == 0)
            {
                return(-1);
            }

            if (sort == SortOrder.None)
            {
                for (int i = 0; i < Items.Count; i++)
                {
                    IComparable i1 = Items[i].Value as IComparable;

                    int result = 0;
                    if (i1 != null)
                    {
                        result = i1.CompareTo(value);
                    }
                    else if (value != null)
                    {
                        result = -1;
                    }

                    if (result == 0)
                    {
                        return(i);
                    }
                }
                return(~Items.Count);
            }
            else
            {
                MatrixHeaderItem header = new MatrixHeaderItem(null);
                header.Value = value;
                return(Items.BinarySearch(header, new HeaderComparer(sort)));
            }
        }
Exemple #11
0
 public MatrixHeaderItem(MatrixHeaderItem parent)
 {
     FParent = parent;
     FItems  = new List <MatrixHeaderItem>();
 }
Exemple #12
0
 internal MatrixHeader()
 {
     FRootItem = new MatrixHeaderItem(null);
 }
 public MatrixHeaderItem(MatrixHeaderItem parent)
 {
     this.parent = parent;
     items       = new List <MatrixHeaderItem>();
 }
Exemple #14
0
        private void PrintRowHeader(MatrixHeaderItem root, int left, int top)
        {
            int dataHeight = 1;
            int width      = HeaderWidth;

            if (Matrix.Data.Cells.Count > 1 && !Matrix.CellsSideBySide)
            {
                dataHeight = Matrix.Data.Cells.Count;
                width--;
            }

            int index = 1;

            foreach (MatrixHeaderItem item in root.Items)
            {
                Matrix.RowValues = item.Values;
                TableCellData resultCell = ResultTable.GetCellData(left, top);
                int           span       = item.Span * dataHeight;
                resultCell.RowSpan = span;
                if (item.IsTotal)
                {
                    resultCell.ColSpan = width - left;
                }

                PrintHeaderCell(item, resultCell, index % 2 == 0);
                PrintRowHeader(item, left + resultCell.ColSpan, top);

                if (item.PageBreak && top > HeaderHeight)
                {
                    ResultTable.Rows[top].PageBreak = true;
                }

                top += span;
                index++;
            }

            // print cell header
            if (root.Items.Count == 0 && dataHeight > 1)
            {
                foreach (MatrixCellDescriptor descr in Matrix.Data.Cells)
                {
                    TableCell     templateCell = null;
                    TableCellData resultCell   = ResultTable.GetCellData(left, top);

                    if (root.TemplateRow != null && descr.TemplateRow != null &&
                        FCellHeaderDescriptor.TemplateColumn != null && FCellHeaderDescriptor.TemplateRow != null)
                    {
                        templateCell = Matrix[FCellHeaderDescriptor.TemplateColumn.Index,
                                              root.TemplateRow.Index + (descr.TemplateRow.Index - FCellHeaderDescriptor.TemplateRow.Index)];
                    }
                    else
                    {
                        templateCell = CreateCell(ExtractColumnName(descr.Expression));
                    }

                    templateCell.SaveState();
                    templateCell.GetData();
                    resultCell.RunTimeAssign(templateCell, true);
                    templateCell.RestoreState();
                    top++;
                }
            }
        }
Exemple #15
0
        /// <summary>
        /// Gets the list of indices of terminal items of the header with specified address.
        /// </summary>
        /// <param name="address">The address of a header.</param>
        /// <returns>The list of indices.</returns>
        public int[] GetTerminalIndices(object[] address)
        {
            MatrixHeaderItem rootItem = Find(address, false, 0);

            return(GetTerminalIndices(rootItem));
        }
Exemple #16
0
 internal MatrixHeader(MatrixObject matrix)
 {
     rootItem    = new MatrixHeaderItem(null);
     this.matrix = matrix;
 }
Exemple #17
0
        private void PrintRowHeader(MatrixHeaderItem root, int left, int top, int level)
        {
            int dataHeight = 1;
            int width      = HeaderWidth;

            if (Matrix.Data.Cells.Count > 1 && !Matrix.CellsSideBySide)
            {
                dataHeight = Matrix.Data.Cells.Count;
                width--;
            }

            for (int index = 0; index < root.Items.Count; index++)
            {
                MatrixHeaderItem item = root.Items[index];
                Matrix.RowValues = item.Values;
                TableCellData resultCell = ResultTable.GetCellData(left, top);
                int           span       = item.Span * dataHeight;
                if (Matrix.SplitRows)
                {
                    MatrixHeaderItem duplicate = new MatrixHeaderItem(root);
                    duplicate.IsSplitted     = true;
                    duplicate.Value          = item.Value;
                    duplicate.TemplateRow    = item.TemplateRow;
                    duplicate.TemplateCell   = item.TemplateCell;
                    duplicate.TemplateColumn = item.TemplateColumn;

                    for (int i = 1; i < span; i++)
                    {
                        root.Items.Insert(index + 1, duplicate);
                    }
                    span = 1;
                }
                resultCell.RowSpan = span;
                if (item.IsTotal)
                {
                    resultCell.ColSpan = width - left;
                    // correct FEvenStyleIndices
                    for (int i = level + 1; i < evenStyleIndices.Length; i++)
                    {
                        evenStyleIndices[i]++;
                    }
                }

                PrintHeaderCell(item, resultCell, evenStyleIndices[level] % 2 != 0);
                PrintRowHeader(item, left + resultCell.ColSpan, top, level + 1);

                if (item.PageBreak && top > HeaderHeight)
                {
                    ResultTable.Rows[top].PageBreak = true;
                }

                top += span;
                evenStyleIndices[level]++;
            }

            // print cell header
            if (root.Items.Count == 0 && dataHeight > 1)
            {
                foreach (MatrixCellDescriptor descr in Matrix.Data.Cells)
                {
                    TableCell     templateCell = null;
                    TableCellData resultCell   = ResultTable.GetCellData(left, top);

                    if (root.TemplateRow != null && descr.TemplateRow != null &&
                        cellHeaderDescriptor.TemplateColumn != null && cellHeaderDescriptor.TemplateRow != null)
                    {
                        templateCell = Matrix[cellHeaderDescriptor.TemplateColumn.Index,
                                              root.TemplateRow.Index + (descr.TemplateRow.Index - cellHeaderDescriptor.TemplateRow.Index)];
                    }
                    else
                    {
                        templateCell = CreateCell(ExtractColumnName(descr.Expression));
                    }

                    templateCell.SaveState();
                    templateCell.GetData();
                    resultCell.RunTimeAssign(templateCell, true);
                    templateCell.RestoreState();
                    top++;
                }
            }
        }
Exemple #18
0
        private void PrintColumnHeader(MatrixHeaderItem root, int left, int top, int level)
        {
            int dataWidth = 1;
            int height    = HeaderHeight;

            if (Matrix.Data.Cells.Count > 1 && Matrix.CellsSideBySide)
            {
                dataWidth = Matrix.Data.Cells.Count;
                height--;
            }

            foreach (MatrixHeaderItem item in root.Items)
            {
                Matrix.ColumnValues = item.Values;
                TableCellData resultCell = ResultTable.GetCellData(left, top);
                int           span       = item.Span * dataWidth;
                resultCell.ColSpan = span;
                if (item.IsTotal)
                {
                    resultCell.RowSpan = height - top;
                    // correct FEvenStyleIndices
                    for (int i = level + 1; i < evenStyleIndices.Length; i++)
                    {
                        evenStyleIndices[i]++;
                    }
                }

                PrintHeaderCell(item, resultCell, evenStyleIndices[level] % 2 != 0);
                PrintColumnHeader(item, left, top + resultCell.RowSpan, level + 1);

                if (item.PageBreak && left > HeaderWidth)
                {
                    ResultTable.Columns[left].PageBreak = true;
                }

                left += span;
                evenStyleIndices[level]++;
            }

            // print cell header
            if (root.Items.Count == 0 && dataWidth > 1)
            {
                foreach (MatrixCellDescriptor descr in Matrix.Data.Cells)
                {
                    TableCell     templateCell = null;
                    TableCellData resultCell   = ResultTable.GetCellData(left, top);

                    if (root.TemplateColumn != null && descr.TemplateColumn != null &&
                        cellHeaderDescriptor.TemplateColumn != null && cellHeaderDescriptor.TemplateRow != null)
                    {
                        templateCell = Matrix[
                            root.TemplateColumn.Index + (descr.TemplateColumn.Index - cellHeaderDescriptor.TemplateColumn.Index),
                            cellHeaderDescriptor.TemplateRow.Index];
                    }
                    else
                    {
                        templateCell = CreateCell(ExtractColumnName(descr.Expression));
                    }

                    templateCell.SaveState();
                    templateCell.GetData();
                    resultCell.RunTimeAssign(templateCell, true);
                    templateCell.RestoreState();
                    left++;
                }
            }
        }
 public MatrixHeaderItem(MatrixHeaderItem parent)
 {
     this.parent = parent;
     items       = new List <MatrixHeaderItem>();
     isSplitted  = false;
 }