Ejemplo n.º 1
0
        private void WriteTable(IMultipleRowsProducer rp, Table table, IGenerationContext context)
        {
            DataRow[] rows = rp.GetValue(context).ToArray();
            if (rows.Length > 0)
            {
                DataTable ptab = rows.First().Table;

                for (int iCol = 0; iCol < ptab.Columns.Count; iCol++)
                {
                    table.ColumnCollection.Add(new Column(table, string.Empty));
                }

                for (int iRow = -1; iRow < rows.Length; iRow++)
                {
                    Row row = new Row(table);
                    table.RowCollection.Add(row);

                    for (int iCol = 0; iCol < ptab.Columns.Count; iCol++)
                    {
                        Cell   cell  = new Cell(table);
                        object value = (iRow == -1) ? ptab.Columns[iCol].ColumnName : rows[iRow][iCol];

                        CreateAddSimpleText(table.Document, cell.Content, value);

                        row.CellCollection.Add(cell);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void ExportSection(TextWriter writer, IReportTemplateSection section, IGenerationContext context)
        {
            /* This searches for the first occurrence of a multiple rows producer.
             * CSV format is very limited and it makes no sense to export more tables or just a single value.
             */

            IMultipleRowsProducer producer = section.RootElement.FindFirstMultipleRowsProducer();

            if (producer != null)
            {
                DataRow[] rows = producer.GetValue(context).ToArray();

                if (rows.Length > 0)
                {
                    /* Write header row.
                     */
                    writer.WriteLine(string.Join(";", rows.First().Table.Columns.Cast <DataColumn>().Select(_ => _.ColumnName)));

                    /* Write data.
                     */
                    foreach (DataRow row in rows)
                    {
                        writer.WriteLine(string.Join(";", row.ItemArray));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void WriteTable(IMultipleRowsProducer rp, IGenerationContext context, IDocument doc)
        {
            DataRow[] rows = rp.GetValue(context).ToArray();
            if (rows.Length > 0)
            {
                DataTable ptab = rows.First().Table;

                Table          table      = TableBuilder.CreateTextDocumentTable((TextDocument)doc, ptab.TableName, string.Empty, rows.Length + 1, ptab.Columns.Count, 0d, true, true);
                CellCollection tableCells = table.RowHeader.RowCollection[0].CellCollection;

                for (int i = 0; i < tableCells.Count; i++)
                {
                    CreateAddSimpleText(doc, tableCells[i].Content, ptab.Columns[i].ColumnName);
                }

                for (int i = 0; i < table.RowCollection.Count; i++)
                {
                    tableCells = table.RowCollection[i].CellCollection;

                    for (int j = 0; j < tableCells.Count; j++)
                    {
                        CreateAddSimpleText(doc, tableCells[j].Content, rows[i][j]);
                    }
                }

                doc.Content.Add(table);
            }
        }
        private void WriteTable(IMultipleRowsProducer rp, Table table, IGenerationContext context)
        {
            DataRow[] rows = rp.GetValue(context).ToArray();
            if (rows.Length > 0)
            {
                DataTable ptab = rows.First().Table;

                for (int iCol = 0; iCol < ptab.Columns.Count; iCol++)
                {
                    table.ColumnCollection.Add(new Column(table, string.Empty));
                }

                for (int iRow = -1; iRow < rows.Length; iRow++)
                {
                    Row row = new Row(table);
                    table.RowCollection.Add(row);

                    for (int iCol = 0; iCol < ptab.Columns.Count; iCol++)
                    {
                        Cell cell = new Cell(table);
                        object value = (iRow == -1) ? ptab.Columns[iCol].ColumnName : rows[iRow][iCol];

                        CreateAddSimpleText(table.Document, cell.Content, value);

                        row.CellCollection.Add(cell);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void WriteElement(ICompositionElement element, XElement parent, IGenerationContext context)
        {
            XElement el = CreateTag(TagType.Div);

            if (element.ChildrenSupported)
            {
                foreach (ICompositionElement child in element.Children)
                {
                    WriteElement(child, el, context);
                }
            }

            IScalarValueProducer singleValue = element as IScalarValueProducer;

            if (singleValue != null)
            {
                XElement elValue = CreateTag(TagType.Span);
                elValue.Add(new XAttribute("class", "value"));
                elValue.Add(singleValue.GetValue(context));

                el.Add(elValue);
            }
            else
            {
                IMultipleRowsProducer rows = element as IMultipleRowsProducer;
                if (rows != null)
                {
                    XElement elTable       = CreateTag(TagType.Table);
                    XElement elTableHeader = null;

                    foreach (DataRow row in rows.GetValue(context))
                    {
                        if (elTableHeader == null)
                        {
                            elTableHeader = CreateTag(TagType.TableHeader);
                            XElement elTableHeaderRow = CreateTag(TagType.TableRow);

                            foreach (DataColumn col in row.Table.Columns)
                            {
                                elTableHeaderRow.Add(new XElement(GetTagName(TagType.TableColumn), new XText(col.ColumnName)));
                            }

                            elTableHeader.Add(elTableHeaderRow);

                            elTable.Add(elTableHeader);
                        }

                        XElement elRow = CreateTag(TagType.TableRow);

                        foreach (object colValue in row.ItemArray)
                        {
                            XElement elColValue = CreateTag(TagType.Span);
                            elColValue.Add(new XAttribute("class", "value"));
                            elColValue.Add(colValue);

                            elRow.Add(new XElement(GetTagName(TagType.TableColumn), elColValue));
                        }

                        elTable.Add(elRow);
                    }

                    el.Add(elTable);
                }
                else
                {
                    if (element.Classification.HasFlag(ElementClassifications.Separator))
                    {
                        el.Name = GetTagName(TagType.HorizontalRule);
                    }

                    double height = element.GetProperty("height", double.NaN);
                    if (!double.IsNaN(height))
                    {
                        ApplyClass(el, "height-" + height.ToString());
                    }
                }
            }

            parent.Add(el);
        }
        private void WriteTable(IMultipleRowsProducer rp, IGenerationContext context, IDocument doc)
        {
            DataRow[] rows = rp.GetValue(context).ToArray();
            if (rows.Length > 0)
            {
                DataTable ptab = rows.First().Table;

                Table table = TableBuilder.CreateTextDocumentTable((TextDocument)doc, ptab.TableName, string.Empty, rows.Length + 1, ptab.Columns.Count, 0d, true, true);
                CellCollection tableCells = table.RowHeader.RowCollection[0].CellCollection;

                for (int i = 0; i < tableCells.Count; i++)
                {
                    CreateAddSimpleText(doc, tableCells[i].Content, ptab.Columns[i].ColumnName);
                }

                for (int i = 0; i < table.RowCollection.Count; i++)
                {
                    tableCells = table.RowCollection[i].CellCollection;

                    for (int j = 0; j < tableCells.Count; j++)
                    {
                        CreateAddSimpleText(doc, tableCells[j].Content, rows[i][j]);
                    }
                }

                doc.Content.Add(table);
            }
        }