Ejemplo n.º 1
0
        private float GeneratePage(int startColumn, int startRow, int columnsFit, int rowsFit,
                                   RectangleF bounds, List <Rectangle> spans)
        {
            // break spans
            foreach (Rectangle span in spans)
            {
                TableCellData spannedCell    = GetCellData(span.Left, span.Top);
                TableCellData newSpannedCell = null;
                if (span.Left < startColumn && span.Right > startColumn)
                {
                    if ((RepeatHeaders || RepeatRowHeaders) && span.Left < FixedColumns)
                    {
                        spannedCell.ColSpan = Math.Min(span.Right, startColumn + columnsFit) - startColumn + FixedColumns;
                    }
                    else
                    {
                        newSpannedCell = GetCellData(startColumn, span.Top);
                        newSpannedCell.RunTimeAssign(spannedCell.Cell, true);
                        newSpannedCell.ColSpan = Math.Min(span.Right, startColumn + columnsFit) - startColumn;
                        newSpannedCell.RowSpan = spannedCell.RowSpan;
                        AdjustSpannedCellWidth(newSpannedCell);
                    }
                }
                if (span.Left < startColumn + columnsFit && span.Right > startColumn + columnsFit)
                {
                    spannedCell.ColSpan = startColumn + columnsFit - span.Left;
                    AdjustSpannedCellWidth(spannedCell);
                }
                if (span.Top < startRow && span.Bottom > startRow)
                {
                    if ((RepeatHeaders || RepeatColumnHeaders) && span.Top < FixedRows)
                    {
                        spannedCell.RowSpan = Math.Min(span.Bottom, startRow + rowsFit) - startRow + FixedRows;
                    }
                }
                if (span.Top < startRow + rowsFit && span.Bottom > startRow + rowsFit)
                {
                    spannedCell.RowSpan = startRow + rowsFit - span.Top;

                    newSpannedCell = GetCellData(span.Left, startRow + rowsFit);
                    newSpannedCell.RunTimeAssign(spannedCell.Cell, true);
                    newSpannedCell.ColSpan = spannedCell.ColSpan;
                    newSpannedCell.RowSpan = span.Bottom - (startRow + rowsFit);

                    // break the cell text
                    TableCell cell = spannedCell.Cell;
                    using (TextObject tempObject = new TextObject())
                    {
                        if (!cell.Break(tempObject))
                        {
                            cell.Text = "";
                        }
                        if (cell.CanBreak)
                        {
                            newSpannedCell.Text = tempObject.Text;
                        }
                    }

                    // fix the row height
                    float textHeight = newSpannedCell.Cell.CalcHeight();
                    float rowsHeight = 0;
                    for (int i = 0; i < newSpannedCell.RowSpan; i++)
                    {
                        rowsHeight += Rows[i + startRow + rowsFit].Height;
                    }

                    if (rowsHeight < textHeight)
                    {
                        // fix the last row's height
                        Rows[startRow + rowsFit + newSpannedCell.RowSpan - 1].Height += textHeight - rowsHeight;
                    }
                }
            }

            // set visible columns
            ColumnsToSerialize.Clear();
            if (RepeatHeaders || RepeatRowHeaders)
            {
                for (int i = 0; i < FixedColumns; i++)
                {
                    if (Columns[i].Visible)
                    {
                        ColumnsToSerialize.Add(Columns[i]);
                    }
                }
                if (startColumn < FixedColumns)
                {
                    columnsFit -= FixedColumns - startColumn;
                    startColumn = FixedColumns;
                }
            }

            // calc visible columns and last X coordinate of table for unlimited page width
            float tableEndX = Columns[0].Width;

            for (int i = startColumn; i < startColumn + columnsFit; i++)
            {
                if (Columns[i].Visible)
                {
                    ColumnsToSerialize.Add(Columns[i]);
                    tableEndX += Columns[i].Width;
                }
            }

            // set visible rows
            RowsToSerialize.Clear();
            if (RepeatHeaders || RepeatColumnHeaders)
            {
                for (int i = 0; i < FixedRows; i++)
                {
                    if (Rows[i].Visible)
                    {
                        RowsToSerialize.Add(Rows[i]);
                    }
                }
                if (startRow < FixedRows)
                {
                    rowsFit -= FixedRows - startRow;
                    startRow = FixedRows;
                }
            }

            // calc visible rows and last Y coordinate of table for unlimited page height
            float tableEndY = Rows[0].Top;

            for (int i = startRow; i < startRow + rowsFit; i++)
            {
                if (Rows[i].Visible)
                {
                    RowsToSerialize.Add(Rows[i]);
                    tableEndY += Rows[i].Height;
                }
            }
            // include row header
            if (startRow != 0 && (RepeatHeaders || RepeatColumnHeaders))
            {
                for (int i = 0; i < FixedRows; i++)
                {
                    tableEndY += Rows[i].Height;
                }
            }


            // generate unlimited page
            if (Report.Engine.UnlimitedHeight || Report.Engine.UnlimitedWidth)
            {
                ReportPage page = Report.PreparedPages.GetPage(Report.Engine.CurPage);
                if (Report.Engine.UnlimitedHeight)
                {
                    bounds.Height = tableEndY;
                }
                if (Report.Engine.UnlimitedWidth)
                {
                    bounds.Width = tableEndX;
                }
                Report.PreparedPages.ModifyPage(Report.Engine.CurPage, page);
            }

            DataBand band = new DataBand();

            band.Bounds = bounds;
            band.Objects.Add(this);
            Report.Engine.AddToPreparedPages(band);

            return(GetRowsHeight(startRow, rowsFit));
        }
Ejemplo n.º 2
0
        private void CopyCells(int originalColumnIndex, int originalRowIndex,
                               int resultColumnIndex, int resultRowIndex)
        {
            TableCell     cell   = sourceTable[originalColumnIndex, originalRowIndex];
            TableCellData cellTo = resultTable.GetCellData(resultColumnIndex, resultRowIndex);

            sourceTable.PrintingCell = cellTo;
            bool needData = true;

            if (AutoSpans)
            {
                if (rowsPriority)
                {
                    // We are printing columns inside a row. Check if we need to finish the column cell.
                    if (columnSpans.Count > 0)
                    {
                        SpanData spanData = columnSpans[0];

                        // check if we are printing the last column of the cell's span. From now, we will not accept
                        // the first column.
                        if (originalColumnIndex == spanData.originalCellOrigin.X + spanData.originalCell.ColSpan - 1)
                        {
                            spanData.finishFlag = true;
                        }

                        if ((spanData.finishFlag && originalColumnIndex == spanData.originalCellOrigin.X) ||
                            (originalColumnIndex < spanData.originalCellOrigin.X ||
                             originalColumnIndex > spanData.originalCellOrigin.X + spanData.originalCell.ColSpan - 1))
                        {
                            columnSpans.Clear();
                        }
                        else
                        {
                            spanData.resultCell.ColSpan++;
                            needData = false;
                        }
                    }

                    // add the column cell if it has ColSpan > 1
                    if (cell.ColSpan > 1 && columnSpans.Count == 0)
                    {
                        SpanData spanData = new SpanData();
                        columnSpans.Add(spanData);

                        spanData.originalCell       = cell;
                        spanData.resultCell         = cellTo;
                        spanData.originalCellOrigin = new Point(originalColumnIndex, originalRowIndex);
                        spanData.resultCellOrigin   = new Point(resultColumnIndex, resultRowIndex);
                    }

                    // now check the row cells. Do this once for each row.
                    if (printingColumnIndex == 0)
                    {
                        for (int i = 0; i < rowSpans.Count; i++)
                        {
                            SpanData spanData = rowSpans[i];

                            // check if we are printing the last row of the cell's span. From now, we will not accept
                            // the first row.
                            if (originalRowIndex == spanData.originalCellOrigin.Y + spanData.originalCell.RowSpan - 1)
                            {
                                spanData.finishFlag = true;
                            }

                            if ((spanData.finishFlag && originalRowIndex == spanData.originalCellOrigin.Y) ||
                                (originalRowIndex < spanData.originalCellOrigin.Y ||
                                 originalRowIndex > spanData.originalCellOrigin.Y + spanData.originalCell.RowSpan - 1))
                            {
                                rowSpans.RemoveAt(i);
                                i--;
                            }
                            else
                            {
                                spanData.resultCell.RowSpan++;
                            }
                        }
                    }

                    // check if we should skip current cell because it is inside a span
                    for (int i = 0; i < rowSpans.Count; i++)
                    {
                        SpanData spanData = rowSpans[i];

                        if (resultColumnIndex >= spanData.resultCellOrigin.X &&
                            resultColumnIndex <= spanData.resultCellOrigin.X + spanData.resultCell.ColSpan - 1 &&
                            resultRowIndex >= spanData.resultCellOrigin.Y &&
                            resultRowIndex <= spanData.resultCellOrigin.Y + spanData.resultCell.RowSpan)
                        {
                            needData = false;
                            break;
                        }
                    }

                    // add the row cell if it has RowSpan > 1 and not added yet
                    if (cell.RowSpan > 1 && needData)
                    {
                        SpanData spanData = new SpanData();
                        rowSpans.Add(spanData);

                        spanData.originalCell       = cell;
                        spanData.resultCell         = cellTo;
                        spanData.originalCellOrigin = new Point(originalColumnIndex, originalRowIndex);
                        spanData.resultCellOrigin   = new Point(resultColumnIndex, resultRowIndex);
                    }
                }
                else
                {
                    // We are printing rows inside a column. Check if we need to finish the row cell.
                    if (rowSpans.Count > 0)
                    {
                        SpanData spanData = rowSpans[0];

                        // check if we are printing the last row of the cell's span. From now, we will not accept
                        // the first row.
                        if (originalRowIndex == spanData.originalCellOrigin.Y + spanData.originalCell.RowSpan - 1)
                        {
                            spanData.finishFlag = true;
                        }

                        if ((spanData.finishFlag && originalRowIndex == spanData.originalCellOrigin.Y) ||
                            (originalRowIndex < spanData.originalCellOrigin.Y ||
                             originalRowIndex > spanData.originalCellOrigin.Y + spanData.originalCell.RowSpan - 1))
                        {
                            rowSpans.Clear();
                        }
                        else
                        {
                            spanData.resultCell.RowSpan++;
                            needData = false;
                        }
                    }

                    // add the row cell if it has RowSpan > 1
                    if (cell.RowSpan > 1 && rowSpans.Count == 0)
                    {
                        SpanData spanData = new SpanData();
                        rowSpans.Add(spanData);

                        spanData.originalCell       = cell;
                        spanData.resultCell         = cellTo;
                        spanData.originalCellOrigin = new Point(originalColumnIndex, originalRowIndex);
                        spanData.resultCellOrigin   = new Point(resultColumnIndex, resultRowIndex);
                    }

                    // now check the column cells. Do this once for each column.
                    if (printingRowIndex == 0)
                    {
                        for (int i = 0; i < columnSpans.Count; i++)
                        {
                            SpanData spanData = columnSpans[i];

                            // check if we are printing the last column of the cell's span. From now, we will not accept
                            // the first column.
                            if (originalColumnIndex == spanData.originalCellOrigin.X + spanData.originalCell.ColSpan - 1)
                            {
                                spanData.finishFlag = true;
                            }

                            if ((spanData.finishFlag && originalColumnIndex == spanData.originalCellOrigin.X) ||
                                (originalColumnIndex < spanData.originalCellOrigin.X ||
                                 originalColumnIndex > spanData.originalCellOrigin.X + spanData.originalCell.ColSpan - 1))
                            {
                                columnSpans.RemoveAt(i);
                                i--;
                            }
                            else
                            {
                                spanData.resultCell.ColSpan++;
                            }
                        }
                    }

                    // check if we should skip current cell because it is inside a span
                    for (int i = 0; i < columnSpans.Count; i++)
                    {
                        SpanData spanData = columnSpans[i];

                        if (resultColumnIndex >= spanData.resultCellOrigin.X &&
                            resultColumnIndex <= spanData.resultCellOrigin.X + spanData.resultCell.ColSpan - 1 &&
                            resultRowIndex >= spanData.resultCellOrigin.Y &&
                            resultRowIndex <= spanData.resultCellOrigin.Y + spanData.resultCell.RowSpan)
                        {
                            needData = false;
                            break;
                        }
                    }

                    // add the column cell if it has ColSpan > 1 and not added yet
                    if (cell.ColSpan > 1 && needData)
                    {
                        SpanData spanData = new SpanData();
                        columnSpans.Add(spanData);

                        spanData.originalCell       = cell;
                        spanData.resultCell         = cellTo;
                        spanData.originalCellOrigin = new Point(originalColumnIndex, originalRowIndex);
                        spanData.resultCellOrigin   = new Point(resultColumnIndex, resultRowIndex);
                    }
                }
            }
            else
            {
                cellTo.ColSpan = cell.ColSpan;
                cellTo.RowSpan = cell.RowSpan;
            }

            if (needData)
            {
                cell.SaveState();
                cell.GetData();
                cellTo.RunTimeAssign(cell, true);
                cell.RestoreState();
            }
        }
Ejemplo n.º 3
0
        private float GeneratePage(int startColumn, int startRow, int columnsFit, int rowsFit,
                                   RectangleF bounds, List <Rectangle> spans)
        {
            // break spans
            foreach (Rectangle span in spans)
            {
                TableCellData spannedCell    = GetCellData(span.Left, span.Top);
                TableCellData newSpannedCell = null;
                if (span.Left < startColumn && span.Right > startColumn)
                {
                    if (RepeatHeaders && span.Left < FixedColumns)
                    {
                        spannedCell.ColSpan = Math.Min(span.Right, startColumn + columnsFit) - startColumn + FixedColumns;
                    }
                    else
                    {
                        newSpannedCell = GetCellData(startColumn, span.Top);
                        newSpannedCell.RunTimeAssign(spannedCell.Cell, true);
                        newSpannedCell.ColSpan = Math.Min(span.Right, startColumn + columnsFit) - startColumn;
                        newSpannedCell.RowSpan = spannedCell.RowSpan;
                    }
                }
                if (span.Left < startColumn + columnsFit && span.Right > startColumn + columnsFit)
                {
                    spannedCell.ColSpan = startColumn + columnsFit - span.Left;
                }
                if (span.Top < startRow && span.Bottom > startRow)
                {
                    if (RepeatHeaders && span.Top < FixedRows)
                    {
                        spannedCell.RowSpan = Math.Min(span.Bottom, startRow + rowsFit) - startRow + FixedRows;
                    }
                }
                if (span.Top < startRow + rowsFit && span.Bottom > startRow + rowsFit)
                {
                    spannedCell.RowSpan = startRow + rowsFit - span.Top;

                    newSpannedCell = GetCellData(span.Left, startRow + rowsFit);
                    newSpannedCell.RunTimeAssign(spannedCell.Cell, true);
                    newSpannedCell.ColSpan = spannedCell.ColSpan;
                    newSpannedCell.RowSpan = span.Bottom - (startRow + rowsFit);

                    // break the cell text
                    TableCell cell = spannedCell.Cell;
                    using (TextObject tempObject = new TextObject())
                    {
                        if (!cell.Break(tempObject))
                        {
                            cell.Text = "";
                        }
                        if (cell.CanBreak)
                        {
                            newSpannedCell.Text = tempObject.Text;
                        }
                    }

                    // fix the row height
                    float textHeight = newSpannedCell.Cell.CalcHeight();
                    float rowsHeight = 0;
                    for (int i = 0; i < newSpannedCell.RowSpan; i++)
                    {
                        rowsHeight += Rows[i + startRow + rowsFit].Height;
                    }

                    if (rowsHeight < textHeight)
                    {
                        // fix the last row's height
                        Rows[startRow + rowsFit + newSpannedCell.RowSpan - 1].Height += textHeight - rowsHeight;
                    }
                }
            }

            // set visible columns
            for (int i = 0; i < Columns.Count; i++)
            {
                if (!RepeatHeaders || i >= FixedColumns)
                {
                    Columns[i].Visible = i >= startColumn && i < startColumn + columnsFit;
                }
            }

            // set visible rows
            for (int i = 0; i < Rows.Count; i++)
            {
                if (!RepeatHeaders || i >= FixedRows)
                {
                    Rows[i].Visible = i >= startRow && i < startRow + rowsFit;
                }
            }

            DataBand band = new DataBand();

            band.Bounds = bounds;
            band.Objects.Add(this);
            Report.Engine.AddToPreparedPages(band);

            return(GetRowsHeight(startRow, rowsFit));
        }