Esempio n. 1
0
        private void AppendAsTable(DocumentListState dls, DtoTableViewModel dto)
        {
            dls.ForceOrientation(Orientation.Landscape);
            dls.AddHeading(dto.Title, dto.DebugInfo);

            dls.CurrentTable = dls.CurrentSection.AddTable();
            dls.CurrentTable.KeepTogether = true;

            var maxCol = dto.Columns.Count - 1;

            for (int i = 0; i <= maxCol; i++)
            {
                dls.CurrentTable.AddColumn();
            }
            dls.CurrentTable.Columns[0].Width = "4cm";

            var header = dls.CurrentTable.AddRow();

            for (int i = 0; i <= maxCol; i++)
            {
                header.Cells[i].AddParagraph(dto.Columns[i].Title);
                header.Cells[i].Format.Alignment = ParagraphAlignment.Center;
            }

            var maxRow = dto.Rows.Count - 1;

            for (int rowIdx = 0; rowIdx <= maxRow; rowIdx++)
            {
                var row = dls.CurrentTable.AddRow();
                if (rowIdx % 2 == 0)
                {
                    row.Format.Shading.Color = Colors.LightGray;
                }
                var myRow = dto.Rows[rowIdx];
                for (int colIdx = 0; colIdx <= maxCol; colIdx++)
                {
                    var myCol  = dto.Columns[colIdx];
                    var myCell = dto.Cells.SingleOrDefault(cell => cell.Row == myRow && cell.Column == myCol);
                    if (myCell != null)
                    {
                        row.Cells[colIdx].AddParagraph(myCell.Value.ToString());
                        if (myCell.Value is DtoValueViewModel)
                        {
                            row.Cells[colIdx].Format.Alignment = ConvertParagraphAlignment(((DtoValueViewModel)myCell.Value).ValueAlignment);
                        }
                    }
                }
            }

            dls.AddDescription(dto.Description);
            dls.CurrentTable = null;
        }
Esempio n. 2
0
        private void AppendAsList(DocumentListState dls, DtoBaseViewModel dto)
        {
            var dtoTable = dto as DtoTableViewModel;
            if (dtoTable != null)
            {
                if (dtoTable.IsDataTable)
                {
                    AppendAsTable(dls, dtoTable);
                }
                else // append contents of structural table as lists
                {
                    dls.ForceOrientation(Orientation.Portrait);
                    dls.AddHeading(dto.Title, dto.DebugInfo);
                    dls.AddDescription(dto.Description);
                    dls.CurrentHeadingLevel += 1;

                    foreach (var item in dtoTable.Cells)
                    {
                        var baseVM = item.Value as DtoBaseViewModel;
                        if (baseVM != null)
                        {
                            AppendAsList(dls, baseVM);
                        }
                        else if (item.Value != null)
                        {
                            throw new NotImplementedException(string.Format("Cannot print {0} ({1}) as cell contents", item.Value, item.Value.GetType()));
                        }
                    }
                    dls.CurrentHeadingLevel -= 1;
                }
            }
            else if (typeof(DtoGroupedViewModel).IsAssignableFrom(dto.GetType()))
            {
                dls.ForceOrientation(Orientation.Portrait);
                dls.AddHeading(dto.Title, dto.DebugInfo);

                dls.CurrentHeadingLevel += 1;
                foreach (var item in ((DtoGroupedViewModel)dto).Items)
                {
                    AppendAsList(dls, item);
                }
                dls.CurrentHeadingLevel -= 1;
            }
            else if (typeof(DtoValueViewModel).IsAssignableFrom(dto.GetType()))
            {
                var valVM = dto as DtoValueViewModel;
                if (dls.CurrentTable == null)
                {
                    dls.CurrentTable = dls.CurrentSection.AddTable();
                    dls.CurrentTable.AddColumn("8cm");  // title
                    dls.CurrentTable.AddColumn("4cm");  // value
                    dls.CurrentTable.AddColumn("4cm");  // alternate representation
                }
                var row = dls.CurrentTable.AddRow();
                row.Cells[0].AddParagraph(dto.Title);
                if (!string.IsNullOrEmpty(valVM.Value))
                    row.Cells[1].AddParagraph(valVM.Value).Format.Alignment = ConvertParagraphAlignment(valVM.ValueAlignment);
                if (!string.IsNullOrEmpty(valVM.AlternateRepresentation))
                    row.Cells[2].AddParagraph(valVM.AlternateRepresentation).Format.Alignment = ConvertParagraphAlignment(valVM.AlternateRepresentationAlignment);
                if (!string.IsNullOrEmpty(valVM.Description))
                {
                    dls.AddDescription(valVM.Description);
                    dls.CurrentTable = null; // reset table after description
                }
            }
            else if (dto != null)
            {
                throw new NotImplementedException(string.Format("Cannot print {0} ({1}) as list", dto, dto.GetType()));
            }
        }
Esempio n. 3
0
        private void AppendAsList(DocumentListState dls, DtoBaseViewModel dto)
        {
            var dtoTable = dto as DtoTableViewModel;

            if (dtoTable != null)
            {
                if (dtoTable.IsDataTable)
                {
                    AppendAsTable(dls, dtoTable);
                }
                else // append contents of structural table as lists
                {
                    dls.ForceOrientation(Orientation.Portrait);
                    dls.AddHeading(dto.Title, dto.DebugInfo);
                    dls.AddDescription(dto.Description);
                    dls.CurrentHeadingLevel += 1;

                    foreach (var item in dtoTable.Cells)
                    {
                        var baseVM = item.Value as DtoBaseViewModel;
                        if (baseVM != null)
                        {
                            AppendAsList(dls, baseVM);
                        }
                        else if (item.Value != null)
                        {
                            throw new NotImplementedException(string.Format("Cannot print {0} ({1}) as cell contents", item.Value, item.Value.GetType()));
                        }
                    }
                    dls.CurrentHeadingLevel -= 1;
                }
            }
            else if (typeof(DtoGroupedViewModel).IsAssignableFrom(dto.GetType()))
            {
                dls.ForceOrientation(Orientation.Portrait);
                dls.AddHeading(dto.Title, dto.DebugInfo);

                dls.CurrentHeadingLevel += 1;
                foreach (var item in ((DtoGroupedViewModel)dto).Items)
                {
                    AppendAsList(dls, item);
                }
                dls.CurrentHeadingLevel -= 1;
            }
            else if (typeof(DtoValueViewModel).IsAssignableFrom(dto.GetType()))
            {
                var valVM = dto as DtoValueViewModel;
                if (dls.CurrentTable == null)
                {
                    dls.CurrentTable = dls.CurrentSection.AddTable();
                    dls.CurrentTable.AddColumn("8cm");  // title
                    dls.CurrentTable.AddColumn("4cm");  // value
                    dls.CurrentTable.AddColumn("4cm");  // alternate representation
                }
                var row = dls.CurrentTable.AddRow();
                row.Cells[0].AddParagraph(dto.Title);
                if (!string.IsNullOrEmpty(valVM.Value))
                {
                    row.Cells[1].AddParagraph(valVM.Value).Format.Alignment = ConvertParagraphAlignment(valVM.ValueAlignment);
                }
                if (!string.IsNullOrEmpty(valVM.AlternateRepresentation))
                {
                    row.Cells[2].AddParagraph(valVM.AlternateRepresentation).Format.Alignment = ConvertParagraphAlignment(valVM.AlternateRepresentationAlignment);
                }
                if (!string.IsNullOrEmpty(valVM.Description))
                {
                    dls.AddDescription(valVM.Description);
                    dls.CurrentTable = null; // reset table after description
                }
            }
            else if (dto != null)
            {
                throw new NotImplementedException(string.Format("Cannot print {0} ({1}) as list", dto, dto.GetType()));
            }
        }
Esempio n. 4
0
        private void AppendAsTable(DocumentListState dls, DtoTableViewModel dto)
        {
            dls.ForceOrientation(Orientation.Landscape);
            dls.AddHeading(dto.Title, dto.DebugInfo);

            dls.CurrentTable = dls.CurrentSection.AddTable();
            dls.CurrentTable.KeepTogether = true;

            var maxCol = dto.Columns.Count - 1;
            for (int i = 0; i <= maxCol; i++)
            {
                dls.CurrentTable.AddColumn();
            }
            dls.CurrentTable.Columns[0].Width = "4cm";

            var header = dls.CurrentTable.AddRow();
            for (int i = 0; i <= maxCol; i++)
            {
                header.Cells[i].AddParagraph(dto.Columns[i].Title);
                header.Cells[i].Format.Alignment = ParagraphAlignment.Center;
            }

            var maxRow = dto.Rows.Count - 1;
            for (int rowIdx = 0; rowIdx <= maxRow; rowIdx++)
            {
                var row = dls.CurrentTable.AddRow();
                if (rowIdx % 2 == 0)
                    row.Format.Shading.Color = Colors.LightGray;
                var myRow = dto.Rows[rowIdx];
                for (int colIdx = 0; colIdx <= maxCol; colIdx++)
                {
                    var myCol = dto.Columns[colIdx];
                    var myCell = dto.Cells.SingleOrDefault(cell => cell.Row == myRow && cell.Column == myCol);
                    if (myCell != null)
                    {
                        row.Cells[colIdx].AddParagraph(myCell.Value.ToString());
                        if (myCell.Value is DtoValueViewModel)
                            row.Cells[colIdx].Format.Alignment = ConvertParagraphAlignment(((DtoValueViewModel)myCell.Value).ValueAlignment);
                    }
                }
            }

            dls.AddDescription(dto.Description);
            dls.CurrentTable = null;
        }