Example #1
0
        /// <summary>
        /// Converts the UI element into Table
        /// </summary>
        /// <param name="element">UI element</param>
        /// <returns>Table</returns>
        public static Table GenerateTable(UIElement element, String header = "")
        {
            Table           contentTbl  = new Table();
            TableRow        contentRow  = new TableRow();
            TableCell       contentCell = new TableCell();
            WriteableBitmap wb          = new WriteableBitmap(element, null);
            ImageInline     image       = new ImageInline(wb);

            Telerik.Windows.Documents.Model.Paragraph p = new Telerik.Windows.Documents.Model.Paragraph();
            p.Inlines.Add(image);
            contentCell.Blocks.Add(p);
            if (!String.IsNullOrEmpty(header))
            {
                TableRow  headerRow = new TableRow();
                TableCell cell      = new TableCell();
                cell.Background = Color.FromArgb(255, 228, 229, 229);
                AddCellValue(cell, header);
                cell.PreferredWidth = new TableWidthUnit((float)element.RenderSize.Width);
                headerRow.Cells.Add(cell);
                contentTbl.Rows.Add(headerRow);
            }

            contentRow.Cells.Add(contentCell);
            contentTbl.Rows.Add(contentRow);
            return(contentTbl);
        }
Example #2
0
        /// <summary>
        /// Generate Combined DCF tables
        /// </summary>
        /// <param name="tables">List of Tables</param>
        /// <returns>Combined Table</returns>
        private Table GenerateCombinedTable(List <Table> tables)
        {
            Table documentTable = new Table(tables.Count(), 3);

            for (int i = 0; i < tables.Count; i++)
            {
                if (i == 2 || i == 3)
                {
                    if (i == 2)
                    {
                        TableRow  row = GetTableRowForSingleTable(tables[i], 1);
                        TableCell cellEmptyParagraph = new TableCell();
                        cellEmptyParagraph.PreferredWidth = new TableWidthUnit(20);
                        Telerik.Windows.Documents.Model.Paragraph p1 = new Telerik.Windows.Documents.Model.Paragraph();
                        cellEmptyParagraph.Blocks.Add(p1);
                        row.Cells.Add(cellEmptyParagraph);
                        documentTable.Rows.Add(row);
                    }
                    else
                    {
                        TableRow row = documentTable.Rows.Last;
                        GetTableRowForMultipleTables(tables[i], ref row);
                    }
                }
                else
                {
                    TableRow row = GetTableRowForSingleTable(tables[i], 3);
                    documentTable.Rows.Add(row);
                }
            }
            documentTable.SetGridColumnWidth(0, new TableWidthUnit(10));
            documentTable.SetGridColumnWidth(1, new TableWidthUnit(1));
            documentTable.SetGridColumnWidth(2, new TableWidthUnit(10));
            return(documentTable);
        }
Example #3
0
        /// <summary>
        /// Create a Section
        /// </summary>
        /// <param name="tables"></param>
        /// <param name="startIndex"></param>
        /// <param name="endIndex"></param>
        /// <returns></returns>
        private Telerik.Windows.Documents.Model.Section GetSection(List <Table> tables, int startIndex, int endIndex)
        {
            Table    headerTable = new Table(1, 4);
            TableRow headerRow   = new TableRow();

            TableCell securityCell = new TableCell();

            Telerik.Windows.Documents.Model.Paragraph securityParagraph = new Telerik.Windows.Documents.Model.Paragraph();
            Telerik.Windows.Documents.Model.Span      securitySpan      = new Telerik.Windows.Documents.Model.Span("Security: " + SecurityName);
            securityParagraph.Inlines.Add(securitySpan);
            securityCell.Children.Add(securityParagraph);

            TableCell countryCell = new TableCell();

            Telerik.Windows.Documents.Model.Paragraph countryParagraph = new Telerik.Windows.Documents.Model.Paragraph();
            Telerik.Windows.Documents.Model.Span      countrySpan      = new Telerik.Windows.Documents.Model.Span("Country: " + CountryName);
            countryParagraph.Inlines.Add(countrySpan);
            countryCell.Children.Add(countryParagraph);

            TableCell createdByCell = new TableCell();

            Telerik.Windows.Documents.Model.Paragraph createdByParagraph = new Telerik.Windows.Documents.Model.Paragraph();
            Telerik.Windows.Documents.Model.Span      createdBySpan      = new Telerik.Windows.Documents.Model.Span("Created by: " + CreatedBy);
            createdByParagraph.Inlines.Add(createdBySpan);
            createdByCell.Children.Add(createdByParagraph);

            TableCell createdOn = new TableCell();

            Telerik.Windows.Documents.Model.Paragraph createdOnParagraph = new Telerik.Windows.Documents.Model.Paragraph();
            Telerik.Windows.Documents.Model.Span      createdOnSpan      = new Telerik.Windows.Documents.Model.Span("Created on: " + CreationDate);
            createdOnParagraph.Inlines.Add(createdOnSpan);
            createdOn.Children.Add(createdOnParagraph);

            headerRow.Cells.Add(securityCell);
            headerRow.Cells.AddAfter(securityCell, countryCell);
            headerRow.Cells.AddAfter(countryCell, createdByCell);
            headerRow.Cells.AddAfter(createdByCell, createdOn);
            headerTable.Rows.Add(headerRow);


            Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section();
            Table        documentTable     = new Table();
            List <Table> tablesToAddToPage = new List <Table>();

            for (int i = startIndex; i < endIndex; i++)
            {
                if (tables.Count >= i)
                {
                    tablesToAddToPage.Add(tables[i]);
                }
            }

            documentTable = GenerateCombinedTable(tablesToAddToPage);
            section.Blocks.Add(headerTable);
            section.Blocks.Add(documentTable);

            return(section);
        }
Example #4
0
        /// <summary>
        /// Create Emoty Row
        /// </summary>
        /// <param name="colSpan"></param>
        /// <returns></returns>
        private TableRow GetEmptyRow(int colSpan)
        {
            TableRow  emptyRow           = new TableRow();
            TableCell cellEmptyParagraph = new TableCell();

            cellEmptyParagraph.ColumnSpan = colSpan;
            Telerik.Windows.Documents.Model.Paragraph p1 = new Telerik.Windows.Documents.Model.Paragraph();
            cellEmptyParagraph.Blocks.Add(p1);

            return(emptyRow);
        }
Example #5
0
        /// <summary>
        /// Helper Method for PDF Export
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="value"></param>
        private static void AddCellValue(TableCell cell, string value)
        {
            Telerik.Windows.Documents.Model.Paragraph paragraph = new Telerik.Windows.Documents.Model.Paragraph();
            Telerik.Windows.Documents.Model.Span      span      = new Telerik.Windows.Documents.Model.Span();

            if (value != null && value != "")
            {
                span.Text       = value;
                span.FontFamily = new System.Windows.Media.FontFamily("Arial");
                span.FontSize   = fontSizePDF;
                paragraph.Inlines.Add(span);
            }
            cell.Blocks.Add(paragraph);
        }
Example #6
0
        /// <summary>
        /// Helper Method for printing Chart
        /// </summary>
        /// <param name="chart">The Chart to be Printed</param>
        private static RadDocument CreateChartDocumentPart(RadChart chart)
        {
            try
            {
                RadDocument document = new RadDocument();
                Telerik.Windows.Documents.Model.Section   section   = new Telerik.Windows.Documents.Model.Section();
                Telerik.Windows.Documents.Model.Paragraph paragraph = new Telerik.Windows.Documents.Model.Paragraph();
                BitmapImage bi = new BitmapImage();

                using (MemoryStream ms = new MemoryStream())
                {
                    chart.ExportToImage(ms, new PngBitmapEncoder());
                    bi.SetSource(ms);
                }

                double imageWidth  = chart.ActualWidth;
                double imageHeight = chart.ActualHeight;

                if (imageWidth > 625)
                {
                    imageWidth  = 625;
                    imageHeight = chart.ActualHeight * imageWidth / chart.ActualWidth;
                }

                ImageInline image = new ImageInline(new WriteableBitmap(bi))
                {
                    Width = imageWidth, Height = imageHeight
                };
                paragraph.Inlines.Add(image);
                section.Blocks.Add(paragraph);
                document.Sections.Add(section);
                return(document);
            }
            catch (Exception ex)
            {
                Prompt.ShowDialog("Message: " + ex.Message + "\nStackTrace: " + Logging.StackTraceToString(ex), "Exception", MessageBoxButton.OK);
                return(null);
            }
        }
Example #7
0
 private static void BuildDocument()
 {
     var section    = new Telerik.Windows.Documents.Model.Section();
     var paragraph  = new Telerik.Windows.Documents.Model.Paragraph();
     var paragraph1 = new Telerik.Windows.Documents.Model.Paragraph();
 }