예제 #1
0
        /// <summary>
        /// Builds a table of contents, based on the content
        /// </summary>
        /// <param name="doc">The document to define for</param>
        /// <param name="contents">The content</param>
        private void DefineTableOfContents(Document doc, IEnumerable <FaseType> contents)
        {
            Section sect = doc.LastSection;

            sect.AddPageBreak();
            Paragraph p = sect.AddParagraph("Inhoudsopgave", "Heading1");

            p.Format.SpaceAfter   = 24;
            p.Format.OutlineLevel = OutlineLevel.Level1;

            foreach (FaseType ft in contents)
            {
                Paragraph p2 = sect.AddParagraph();
                p2.Style = "TOC";

                if (ft.Type != null)
                {
                    Hyperlink hyperlink = p2.AddHyperlink(ft.Type);
                    hyperlink.AddText(ft.Type + "\t");
                    hyperlink.AddPageRefField(ft.Type);
                }
                else
                {
                    p2.AddFormattedText("Critical data incomplete", "error");
                }
            }
        }
예제 #2
0
        public static void DefineTableOfContents(Document document)
        {
            Section section = document.LastSection;

            section.AddPageBreak();
            Paragraph paragraph = section.AddParagraph("Table of Contents");

            paragraph.Format.Font.Size    = 14;
            paragraph.Format.Font.Bold    = true;
            paragraph.Format.SpaceAfter   = 24;
            paragraph.Format.OutlineLevel = OutlineLevel.Level1;

            paragraph       = section.AddParagraph();
            paragraph.Style = "TOC";
            Hyperlink hyperlink = paragraph.AddHyperlink("Paragraphs");

            hyperlink.AddText("Paragraphs\t");
            hyperlink.AddPageRefField("Paragraphs");

            paragraph       = section.AddParagraph();
            paragraph.Style = "TOC";
            hyperlink       = paragraph.AddHyperlink("Tables");
            hyperlink.AddText("Tables\t");
            hyperlink.AddPageRefField("Tables");

            paragraph       = section.AddParagraph();
            paragraph.Style = "TOC";
            hyperlink       = paragraph.AddHyperlink("Charts");
            hyperlink.AddText("Charts\t");
            hyperlink.AddPageRefField("Charts");
        }
        /// <summary>
        /// Builds a table of contents, based on the content
        /// </summary>
        /// <param name="doc">The document to define for</param>
        /// <param name="contents">The content</param>
        private void DefineTableOfContents(Document doc, IEnumerable <Module> contents)
        {
            Section sect = doc.LastSection;

            sect.AddPageBreak();
            Paragraph p = sect.AddParagraph("Inhoudsopgave", "Heading1");

            p.Format.SpaceAfter   = 24;
            p.Format.OutlineLevel = OutlineLevel.Level1;

            foreach (Module m in contents)
            {
                Paragraph p2 = sect.AddParagraph();
                p2.Style = "TOC";
                if (m.Naam != null && m.Schooljaar != null)
                {
                    Hyperlink hyperlink = p2.AddHyperlink(m.Naam + " - " + m.Schooljaar);
                    hyperlink.AddText(m.Naam + "\t");
                    hyperlink.AddPageRefField(m.Naam + " - " + m.Schooljaar);
                }
                else
                {
                    p2.AddFormattedText("Critical data incomplete", "error");
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Creates the initial sample document.
        /// </summary>
        public static Document CreateSample1()
        {
            // Create a new MigraDoc document
            Document document = new Document();

            // Add a section to the document
            Section section = document.AddSection();

            // Add a paragraph to the section
            Paragraph paragraph = section.AddParagraph();

            // Add some text to the paragraph
            paragraph.AddFormattedText("Hi!");

            paragraph = section.AddParagraph();
            paragraph.AddText("This is a MigraDoc document created for the DocumentViewer sample application.");
            paragraph.AddText("The DocumentViewer demonstrates all techniques you need to preview and print a MigraDoc document, and convert it to a PDF, RTF, or image file.");

            section.AddParagraph();
            section.AddParagraph();
            paragraph = section.AddParagraph("A4 portrait");
            paragraph.Format.Font.Size = "1.5cm";

            section.AddPageBreak();
            section.AddParagraph().AddText("Page 2");

            section = document.AddSection();
            section.PageSetup.Orientation = Orientation.Landscape;

            paragraph = section.AddParagraph("A4 landscape");
            paragraph.Format.Font.Size = "1.5cm";

            section.AddPageBreak();
            section.AddParagraph().AddText("Page 4");

            section = document.AddSection();
            section.PageSetup.Orientation = Orientation.Portrait;
            section.PageSetup.PageFormat  = PageFormat.A5;

            paragraph = section.AddParagraph("A5 portrait");
            paragraph.Format.Font.Size = "1.5cm";

            section.AddPageBreak();
            section.AddParagraph().AddText("Page 6");

            return(document);
        }
예제 #5
0
        public void AddImage(string filePath)
        {
            var image = _section.AddImage(filePath);

            image.Height = _doc.DefaultPageSetup.PageHeight;
            image.Width  = _doc.DefaultPageSetup.PageWidth;
            _section.AddPageBreak();
        }
        public void AddPage(string filePath)
        {
            var page = pdfSection.AddImage(filePath);

            page.Width  = resultPdfDocument.DefaultPageSetup.PageWidth;
            page.Height = resultPdfDocument.DefaultPageSetup.PageHeight;

            pdfSection.AddPageBreak();
        }
예제 #7
0
        public void AddImage(string filePath)
        {
            var image = _currentSection.AddImage(filePath);

            image.Height = _currentDocument.DefaultPageSetup.PageHeight;
            image.Width  = _currentDocument.DefaultPageSetup.PageWidth;
            _currentSection.AddPageBreak();
            Images.Add(filePath);
        }
예제 #8
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="result">LearnResult - learning result</param>
        /// <param name="chartFilename">string - char filename</param>
        /// <param name="includeDataTable">bool - true id learning data should be included</param>
        public HistoryPDF(LearnByErrorLibrary.LearnResult result, String chartFilename, bool includeDataTable = false)
        {
            this.result        = result;
            this.chartFilename = chartFilename;

            document               = new Document();
            document.Info.Title    = "NBN C# - wynik uczenia sieci neuronowej";
            document.Info.Subject  = "Uczenie sieci neuronowej za pomocą algorytmu NBN C#";
            document.Info.Author   = "Marek Bar 33808";
            document.Info.Comment  = "...ponieważ tylko dobry kod się liczy.";
            document.Info.Keywords = "C#, NBN, neuron, uczenie, sieć, nbn c#";

            DefineStyles(document);
            DefineCover(document);
            DefineInfo(document, result);
            DefineChartArea(document, chartFilename, Path.GetFileNameWithoutExtension(result.Filename));
            DefineWeightsSection(document, result);

            if (includeDataTable)
            {
                MatrixMB mat = MatrixMB.Load(result.Filename);
                AddMatrixTable(document, mat);
            }

            Section section = document.LastSection;

            section.AddPageBreak();//index of pages
            Paragraph paragraph = section.AddParagraph("Spis treści");

            paragraph.Format.Font.Size    = 14;
            paragraph.Format.Font.Bold    = true;
            paragraph.Format.SpaceAfter   = 24;
            paragraph.Format.OutlineLevel = OutlineLevel.Level1;

            paragraph       = section.AddParagraph();
            paragraph.Style = "TOC";

            //first link
            Hyperlink hyperlink = paragraph.AddHyperlink("Informacje na temat sieci neuronowej");

            hyperlink.AddText("\r\n" + "Informacje na temat sieci neuronowej" + "\t");
            hyperlink.AddPageRefField("Informacje na temat sieci neuronowej");

            hyperlink = paragraph.AddHyperlink("Wykres przebiegu uczenia");
            hyperlink.AddText("\r\n" + "Wykres przebiegu uczenia" + "\t");
            hyperlink.AddPageRefField("Wykres przebiegu uczenia");

            hyperlink = paragraph.AddHyperlink("Wagi otrzymane w procesie uczenia");
            hyperlink.AddText("\r\n" + "Wagi otrzymane w procesie uczenia" + "\t");
            hyperlink.AddPageRefField("Wagi otrzymane w procesie uczenia");
            if (includeDataTable)
            {
                hyperlink = paragraph.AddHyperlink("Dane wejściowe");
                hyperlink.AddText("\r\n" + "Dane wejściowe" + "\t");
                hyperlink.AddPageRefField("Dane wejściowe");
            }
        }
예제 #9
0
        private void DefineTableOfContentsProvinces(Document document)
        {
            Section section = document.LastSection;

            section.AddPageBreak();
            Paragraph paragraph = section.AddParagraph("Table of Contents");

            paragraph.Format.Font.Size    = 14;
            paragraph.Format.Font.Bold    = true;
            paragraph.Format.SpaceAfter   = 24;
            paragraph.Format.OutlineLevel = OutlineLevel.Level1;

            paragraph       = section.AddParagraph();
            paragraph.Style = "TOC";
            Hyperlink hyperlink = paragraph.AddHyperlink("All Provinces");

            hyperlink.AddText("All Provinces\t");
            hyperlink.AddPageRefField("All Provinces");

            paragraph       = section.AddParagraph();
            paragraph.Style = "TOC";
            hyperlink       = paragraph.AddHyperlink("Provinces");
            hyperlink.AddText("Provinces\t");
            hyperlink.AddPageRefField("Provinces");

            paragraph       = section.AddParagraph();
            paragraph.Style = "TOC";
            hyperlink       = paragraph.AddHyperlink("Province");
            hyperlink.AddText("Province\t");
            hyperlink.AddPageRefField("Province");

            paragraph       = section.AddParagraph();
            paragraph.Style = "TOC";
            hyperlink       = paragraph.AddHyperlink("Male Players");
            hyperlink.AddText("Male Players\t");
            hyperlink.AddPageRefField("Male Players");

            paragraph       = section.AddParagraph();
            paragraph.Style = "TOC";
            hyperlink       = paragraph.AddHyperlink("Female Players");
            hyperlink.AddText("Female Players\t");
            hyperlink.AddPageRefField("Female Players");

            paragraph       = section.AddParagraph();
            paragraph.Style = "TOC";
            hyperlink       = paragraph.AddHyperlink("Events");
            hyperlink.AddText("Events\t");
            hyperlink.AddPageRefField("Events");

            paragraph       = section.AddParagraph();
            paragraph.Style = "TOC";
            hyperlink       = paragraph.AddHyperlink("Charts");
            hyperlink.AddText("Charts\t");
            hyperlink.AddPageRefField("Charts");
        }
예제 #10
0
        protected void CreatePage()
        {
            // Each MigraDoc document needs at least one section.
            Section currentSection = this._document.LastSection;

            if (currentSection == null)
            {
                currentSection = this._document.AddSection();
            }
            else
            {
                currentSection.AddPageBreak();
            }

            this._pageNumber += 1;

            // Put a logo in the header
            Image image = currentSection.Headers.Primary.AddImage(this._info.LogoPath);

            image.Height             = "2.5cm";
            image.LockAspectRatio    = true;
            image.RelativeVertical   = RelativeVertical.Line;
            image.RelativeHorizontal = RelativeHorizontal.Margin;
            image.Top              = ShapePosition.Top;
            image.Left             = ShapePosition.Left;
            image.WrapFormat.Style = WrapStyle.Through;

            // Create footer
            Paragraph paragraph = currentSection.Footers.Primary.AddParagraph();

            paragraph.AddText(CompanyABC.Utility.PDFReportGeneration.Constants.CompanyInfo.COMPANY_FOOTER);
            paragraph.Format.Font.Size = 9;
            paragraph.Format.Alignment = ParagraphAlignment.Center;

            // Add the print date field
            paragraph = currentSection.AddParagraph();
            paragraph.Format.SpaceBefore = "2cm";
            paragraph.Style = "Reference";
            paragraph.AddFormattedText("EXPORTED RESULTS", TextFormat.Bold);
            paragraph.AddTab();
            paragraph.AddTab();
            paragraph.AddTab();
            paragraph.AddTab();
            paragraph.AddText("Date Generated: ");
            paragraph.AddDateField("MM-dd-yyyy");

            // Create the item table
            this._table                     = currentSection.AddTable();
            this._table.Style               = "Table";
            this._table.Borders.Color       = CompanyABC.Utility.PDFReportGeneration.Constants.ColorScheme.TableBorder;
            this._table.Borders.Width       = 0.25;
            this._table.Borders.Left.Width  = 0.5;
            this._table.Borders.Right.Width = 0.5;
            this._table.Rows.LeftIndent     = 0;
        }
예제 #11
0
        private void AddImage(string file)
        {
            Image image = _section.AddImage(file);

            image.Height      = _document.DefaultPageSetup.PageHeight;
            image.Width       = _document.DefaultPageSetup.PageWidth;
            image.ScaleHeight = 0.7;
            image.ScaleWidth  = 0.7;

            _section.AddPageBreak();
        }
예제 #12
0
        public void AddImage(string path)
        {
            Image image = _documentSection.AddImage(path);

            image.Height      = _document.DefaultPageSetup.PageHeight;
            image.Width       = _document.DefaultPageSetup.PageWidth;
            image.ScaleHeight = 0.7;
            image.ScaleWidth  = 0.7;

            _documentSection.AddPageBreak();
        }
        private void AddImageToDocument(string file)
        {
            var image = section.AddImage(file);

            image.Height      = document.DefaultPageSetup.PageHeight;
            image.Width       = document.DefaultPageSetup.PageWidth;
            image.ScaleHeight = 0.75;
            image.ScaleWidth  = 0.75;

            section.AddPageBreak();
        }
예제 #14
0
 private static void CreateWineMakerSection(Section section, Trip trip, Event evnt)
 {
     section.AddPageBreak();
     AddParagraph(section, "", $"{trip.startDate.AddDays(evnt.day).ToLongDateString()} start: {evnt.startString} duration {evnt.duration}minutes", 10);
     AddParagraph(section, "", $"{evnt.name}", 16);
     AddParagraph(section, "", $"{evnt.address}", 16);
     AddParagraph(section, "", $"{evnt.description}", 10);
     AddParagraph(section, "GPS location: ", $"{evnt.GPSLocation}", 10);
     AddParagraph(section, "eMail: ", $"{evnt.eMail}", 10);
     AddParagraph(section, "Web site: ", $"{evnt.webSite}", 10);
     AddImage(section, evnt.transferFrom?.map);
     AddRuler(section);
 }
예제 #15
0
        private void AddFileToDoc(string file)
        {
            _section.AddPageBreak();
            var img = _section.AddImage(file);

            img.Top                = 0;
            img.Left               = 0;
            img.Height             = _document.DefaultPageSetup.PageHeight;
            img.Width              = _document.DefaultPageSetup.PageWidth;
            img.RelativeHorizontal = RelativeHorizontal.Page;
            img.RelativeVertical   = RelativeVertical.Page;
            _usedFiles.Add(file);
        }
예제 #16
0
        public void AddImage(string filePath)
        {
            var img = _currentSection.AddImage(filePath);

            img.RelativeHorizontal = RelativeHorizontal.Page;
            img.RelativeVertical   = RelativeVertical.Page;

            img.Top  = 0;
            img.Left = 0;

            img.Height = _currentDocument.DefaultPageSetup.PageHeight;
            img.Width  = _currentDocument.DefaultPageSetup.PageWidth;

            _currentSection.AddPageBreak();

            Images.Add(filePath);
        }
예제 #17
0
        public static void DefineTableOfContents(FinalDocument model)
        {
            if (!model.TOC)
            {
                return;
            }
            Section section = model.Document.AddSection();

            section.PageSetup.LeftMargin  = 40;
            section.PageSetup.RightMargin = 40;
            section.AddPageBreak();
            Paragraph paragraph = section.AddParagraph("Contents");

            paragraph.Format.Font.Size    = 20;
            paragraph.Format.Font.Bold    = true;
            paragraph.Format.SpaceAfter   = 24;
            paragraph.Format.OutlineLevel = OutlineLevel.Level1;
            paragraph.Format.SpaceAfter   = "2cm";

            // Main title
            model.MainTitle.ToList().ForEach(x =>
            {
                paragraph               = section.AddParagraph();
                paragraph.Style         = "TOC 1";
                Hyperlink hyperlinkLvl1 = null;

                // Sub title
                x.SubTitle.ToList().ForEach(u =>
                {
                    if (hyperlinkLvl1 == null)
                    {
                        hyperlinkLvl1 = paragraph.AddHyperlink(u.Id);
                        hyperlinkLvl1.AddText($"{x.Title}\t");
                        hyperlinkLvl1.AddPageRefField(u.Id);
                        paragraph.Format.SpaceAfter = "0.25cm";
                    }
                    paragraph               = section.AddParagraph();
                    paragraph.Style         = "TOC 2";
                    Hyperlink hyperlinkLvl2 = paragraph.AddHyperlink(u.Id);
                    hyperlinkLvl2.AddText($"{(char)160}{(char)160}{(char)160}{(char)160}{u.Title}\t");
                    hyperlinkLvl2.AddPageRefField(u.Id);
                });

                paragraph.Format.SpaceAfter = "1cm";
            });
        }
예제 #18
0
        /// <summary>Writes PDF for specified auto-doc commands.</summary>
        /// <param name="section">The writer to write to.</param>
        /// <param name="tags">The autodoc tags.</param>
        private void TagsToMigraDoc(Section section, List <AutoDocumentation.ITag> tags)
        {
            int figureNumber = 0;

            foreach (AutoDocumentation.ITag tag in tags)
            {
                if (tag is AutoDocumentation.Heading)
                {
                    AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading;
                    if (heading.headingLevel > 0 && heading.headingLevel <= 6)
                    {
                        Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel);
                        para.Format.KeepWithNext = true;
                        int posSpace = heading.text.IndexOf(' ');
                        if (posSpace > 0)
                        {
                            para.AddBookmark(heading.text.Substring(posSpace + 1));
                        }
                        if (heading.headingLevel == 1)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level1;
                        }
                        else if (heading.headingLevel == 2)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level2;
                        }
                        else if (heading.headingLevel == 3)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level3;
                        }
                        else if (heading.headingLevel == 4)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level4;
                        }
                        else if (heading.headingLevel == 5)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level5;
                        }
                        else if (heading.headingLevel == 6)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level6;
                        }
                    }
                }
                else if (tag is AutoDocumentation.Paragraph)
                {
                    AutoDocumentation.Paragraph paragraph = tag as AutoDocumentation.Paragraph;
                    if (paragraph.text.Contains("![Alt Text]"))
                    {
                        figureNumber++;
                    }
                    paragraph.text = paragraph.text.Replace("[FigureNumber]", figureNumber.ToString());
                    AddFormattedParagraphToSection(section, paragraph);
                }
                else if (tag is AutoDocumentation.GraphAndTable)
                {
                    CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable);
                }
                else if (tag is GraphPage)
                {
                    CreateGraphPage(section, tag as GraphPage);
                }
                else if (tag is AutoDocumentation.NewPage)
                {
                    section.AddPageBreak();
                }
                else if (tag is AutoDocumentation.Table)
                {
                    CreateTable(section, tag as AutoDocumentation.Table);
                }
                else if (tag is Graph)
                {
                    GraphPresenter graphPresenter = new GraphPresenter();
                    explorerPresenter.ApsimXFile.Links.Resolve(graphPresenter);
                    GraphView graphView = new GraphView();
                    graphView.BackColor        = OxyPlot.OxyColors.White;
                    graphView.ForegroundColour = OxyPlot.OxyColors.Black;
                    graphView.FontSize         = 12;
                    graphView.Width            = 500;
                    graphView.Height           = 500;
                    graphPresenter.Attach(tag, graphView, explorerPresenter);
                    string pngFileName = graphPresenter.ExportToPNG(WorkingDirectory);
                    section.AddImage(pngFileName);
                    string caption = (tag as Graph).Caption;
                    if (caption != null)
                    {
                        section.AddParagraph(caption);
                    }
                    graphPresenter.Detach();
                    graphView.MainWidget.Destroy();
                }
                else if (tag is Map && (tag as Map).GetCoordinates().Count > 0)
                {
                    MapPresenter mapPresenter = new MapPresenter();
                    MapView      mapView      = new MapView(null);
                    mapPresenter.Attach(tag, mapView, explorerPresenter);
                    string pngFileName = mapPresenter.ExportToPNG(WorkingDirectory);
                    if (!String.IsNullOrEmpty(pngFileName))
                    {
                        section.AddImage(pngFileName);
                    }
                    mapPresenter.Detach();
                    mapView.MainWidget.Destroy();
                }
                else if (tag is AutoDocumentation.Image)
                {
                    AutoDocumentation.Image imageTag = tag as AutoDocumentation.Image;
                    if (imageTag.image.Width > 700)
                    {
                        imageTag.image = ImageUtilities.ResizeImage(imageTag.image, 700, 500);
                    }
                    string pngFileName = Path.Combine(WorkingDirectory, imageTag.name);
                    imageTag.image.Save(pngFileName, System.Drawing.Imaging.ImageFormat.Png);
                    section.AddImage(pngFileName);
                    figureNumber++;
                }
                else if (tag is AutoDocumentation.ModelView)
                {
                    AutoDocumentation.ModelView modelView     = tag as AutoDocumentation.ModelView;
                    ViewNameAttribute           viewName      = ReflectionUtilities.GetAttribute(modelView.model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute;
                    PresenterNameAttribute      presenterName = ReflectionUtilities.GetAttribute(modelView.model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute;
                    if (viewName != null && presenterName != null)
                    {
                        ViewBase owner = ViewBase.MasterView as ViewBase;
                        if (viewName.ToString() == "UserInterface.Views.MapView")
                        {
                            owner = null;
                        }

                        ViewBase   view      = Assembly.GetExecutingAssembly().CreateInstance(viewName.ToString(), false, BindingFlags.Default, null, new object[] { owner }, null, null) as ViewBase;
                        IPresenter presenter = Assembly.GetExecutingAssembly().CreateInstance(presenterName.ToString()) as IPresenter;

                        if (view != null && presenter != null)
                        {
                            explorerPresenter.ApsimXFile.Links.Resolve(presenter);
                            presenter.Attach(modelView.model, view, explorerPresenter);

                            Gtk.Window popupWin = new Gtk.Window(Gtk.WindowType.Popup);
                            popupWin.SetSizeRequest(800, 800);
                            popupWin.Add(view.MainWidget);

                            if (view is IMapView map)
                            {
                                map.HideZoomControls();
                            }

                            popupWin.ShowAll();

                            while (Gtk.Application.EventsPending())
                            {
                                Gtk.Application.RunIteration();
                            }

                            // From MapView:
                            // With WebKit, it appears we need to give it time to actually update the display
                            // Really only a problem with the temporary windows used for generating documentation
                            if (view is MapView)
                            {
                                var watch = new System.Diagnostics.Stopwatch();
                                watch.Start();
                                while (watch.ElapsedMilliseconds < 1000)
                                {
                                    Gtk.Application.RunIteration();
                                }
                            }

                            string pngFileName = (presenter as IExportable).ExportToPNG(WorkingDirectory);
                            section.AddImage(pngFileName);
                            presenter.Detach();
                            view.MainWidget.Destroy();
                            popupWin.Destroy();
                        }
                    }
                }
            }
        }
        private void BtnPrintVouchersAndTickets_Click(object sender, EventArgs e)
        {
            Button button    = sender as Button;
            bool   closeForm = true;

            if ((button == BtnPrintHotelVouchers) || (button == BtnPrintBoth))
            {
                //MessageBox.Show("Button pressed = " + button.Text, "PRINTING HOTEL VOUCHERS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                /* open connection */
                try
                {
                    mySqlConnection.Open();
                }
                catch (Exception errConnOpen)
                {
                    MessageBox.Show("Error in opening mysql connection because : " + errConnOpen.Message);
                    return;
                }

                /* now execute query to obtain data from hotel booking table
                 * and fill t in dataset
                 */
                string           mySqlQueryString = "SELECT DISTINCT `idhotelinfo` FROM `hotelbookinginfo` WHERE `queryid` = '" + queryId + "' ORDER BY `idhotelinfo`";
                DataSet          dataset          = new DataSet();
                MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter(mySqlQueryString, mySqlConnection);
                mySqlDataAdapter.Fill(dataset, "TABLE_HOTEL_ID");
                if ((dataset == null) || (dataset.Tables["TABLE_HOTEL_ID"].Rows.Count < 1))
                {
                    MessageBox.Show("No Hotel information present for QueryId = " + queryId, "No Data Present", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    try
                    {
                        mySqlConnection.Close();
                    }
                    catch (Exception errConnClose)
                    {
                        MessageBox.Show("Error in opening mysql connection because : " + errConnClose.Message);
                    }
                    return;
                }
                saveFileDialogItinerary.Title = "HOTEL VOUCHER FILE NAME";
                if (saveFileDialogItinerary.ShowDialog() == DialogResult.OK)
                {
                    /* file selected */
                    Debug.WriteLine("OUT FILE SELECTED : " + saveFileDialogItinerary.FileName);
                }
                else
                {
                    Debug.WriteLine("File not selected thus returning");
                    try
                    {
                        mySqlConnection.Close();
                    }
                    catch (Exception errConnClose)
                    {
                        MessageBox.Show("Error in opening mysql connection because : " + errConnClose.Message);
                    }
                    return;
                }
                string imagePath = saveFileDialogItinerary.FileName + "logo.png";
                Properties.Resources.ExcursionHolidaysSmallLogo.Save(imagePath);

                Document document = new Document();
                document.Info.Title = "HOTEL VOUCHER FOR " + queryId;

                /* now cange the style of the document */
                MyPdfDocuments.DefineStyles(document);

                /* add section to document */
                Section section = document.AddSection();

                /* add hotel booking details.
                 * add different page for different hotel
                 */
                for (int pageNumber = 0; pageNumber < dataset.Tables["TABLE_HOTEL_ID"].Rows.Count; pageNumber++)
                {
                    mySqlQueryString = "SELECT * FROM `hotelbookinginfo` WHERE `queryid` = '" + queryId + "' AND idhotelinfo = " + dataset.Tables["TABLE_HOTEL_ID"].Rows[pageNumber]["idhotelinfo"].ToString();
                    mySqlDataAdapter = new MySqlDataAdapter(mySqlQueryString, mySqlConnection);
                    string tableNameHotelRates = "TABLE_HOTEL_ID_" + pageNumber.ToString();
                    mySqlDataAdapter.Fill(dataset, tableNameHotelRates);
                    mySqlQueryString = "SELECT `hoteladdress`, `hotelname` FROM `hotelinfo` WHERE `idhotelinfo` = " + dataset.Tables["TABLE_HOTEL_ID"].Rows[pageNumber]["idhotelinfo"].ToString();
                    mySqlDataAdapter = new MySqlDataAdapter(mySqlQueryString, mySqlConnection);
                    string tableNameHotelAddress = "HOTEL_ADDRESS_" + pageNumber.ToString();
                    mySqlDataAdapter.Fill(dataset, tableNameHotelAddress);
                    if (dataset.Tables[tableNameHotelRates].Rows.Count < 1)
                    {
                        continue;
                    }
                    if (pageNumber > 0)
                    {
                        section.AddPageBreak();
                    }
                    Paragraph paragraph = section.AddParagraph("HOTEL VOUCHER", "Heading1");
                    /* enter reference details in tabular form */
                    Table  table       = null;
                    Column column      = null;
                    int    columnCount = 0; // 1;
                    double columnWidth = 0; // (21.0 - 2.0) / columnCount;
                    Row    row         = null;
                    int    rowsCount   = 0;

                    table = section.AddTable();
                    table.Borders.Visible = true;
                    table.Borders.Width   = 0.75;
                    table.Borders.Color   = Colors.SkyBlue;
                    columnCount           = 3;
                    columnWidth           = (21.0 - 2.0) / columnCount;
                    for (int index = 0; index < columnCount; index++)
                    {
                        column = table.AddColumn(Unit.FromCentimeter(columnWidth));
                        column.Format.Alignment = ParagraphAlignment.Center;
                    }
                    row = table.AddRow();
                    rowsCount++;
                    paragraph = row.Cells[0].AddParagraph();
                    paragraph.AddFormattedText("Reference No", "Heading2");
                    paragraph = row.Cells[1].AddParagraph();
                    paragraph.AddFormattedText("Confirmed By", "Heading2");
                    paragraph = row.Cells[2].AddParagraph();
                    paragraph.AddFormattedText("Hotel Confirmation No", "Heading2");

                    row = table.AddRow();
                    rowsCount++;
                    paragraph = row.Cells[0].AddParagraph();
                    paragraph.AddFormattedText(queryId, "Heading3");
                    paragraph = row.Cells[1].AddParagraph();
                    paragraph.AddFormattedText(dataset.Tables[tableNameHotelRates].Rows[0]["confirmby"].ToString(), "Heading3");
                    paragraph = row.Cells[2].AddParagraph();
                    paragraph.AddFormattedText(dataset.Tables[tableNameHotelRates].Rows[0]["idconfirmation"].ToString(), "Heading3");
                    /* Add contant for the table information */
                    table.SetEdge(0, 0, columnCount, rowsCount, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1.5, Colors.SkyBlue);
                    rowsCount = columnCount = 0;
                    section.AddParagraph("\n", "Normal");
                    /* add hotel address and agency address in table */
                    table = section.AddTable();
                    table.Borders.Visible = false;
                    table.Borders.Width   = 0.75;
                    columnCount           = 2;
                    columnWidth           = (21.0 - 2.0) / columnCount;
                    column = table.AddColumn(Unit.FromCentimeter(columnWidth));
                    column.Format.Alignment = ParagraphAlignment.Left;
                    column = table.AddColumn(Unit.FromCentimeter(1.2));
                    column.Format.Alignment = ParagraphAlignment.Left;
                    columnCount++;
                    column = table.AddColumn(Unit.FromCentimeter(columnWidth - 1.2));
                    column.Format.Alignment = ParagraphAlignment.Left;
                    row = table.AddRow();
                    rowsCount++;
                    paragraph = row.Cells[0].AddParagraph();
                    paragraph.AddFormattedText("Hotel Address Details", "Heading2");
                    paragraph = row.Cells[1].AddParagraph();
                    paragraph.AddFormattedText("Agency Address Details", "Heading2");
                    row.Cells[1].MergeRight = 1;

                    row = table.AddRow();
                    rowsCount++;
                    //MyPdfDocuments.WriteHdrContentParagraph(row.Cells[0], dataset.Tables[tableNameHotelAddress].Rows[0]["hotelname"].ToString(), dataset.Tables[tableNameHotelAddress].Rows[0]["hoteladdress"].ToString());
                    paragraph = row.Cells[0].AddParagraph();
                    paragraph.Format.RightIndent = "1.5cm";
                    paragraph.AddFormattedText(dataset.Tables[tableNameHotelAddress].Rows[0]["hotelname"].ToString() + "\n", "Heading3");
                    paragraph.AddFormattedText(dataset.Tables[tableNameHotelAddress].Rows[0]["hoteladdress"].ToString());

                    MigraDoc.DocumentObjectModel.Shapes.Image image = row.Cells[1].AddImage(imagePath);
                    image.Width = "1cm";
                    //image.Left = "-2.4cm";

                    MyPdfDocuments.WriteAgencyAddressDetails(row.Cells[2]);
                    /* Add contant for the table information */
                    table.SetEdge(0, 0, columnCount, rowsCount, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1.5, Colors.SkyBlue);
                    rowsCount = columnCount = 0;
                    section.AddParagraph("\n", "Normal");

                    table = section.AddTable();
                    table.Borders.Visible = true;
                    table.Borders.Width   = 0.75;
                    table.Borders.Color   = Colors.SkyBlue;
                    columnCount           = 6;
                    columnWidth           = (21.0 - 2.0) / columnCount;
                    for (int index = 1; index < columnCount; index++)
                    {
                        column = table.AddColumn(Unit.FromCentimeter(columnWidth + 0.45));
                        column.Format.Alignment = ParagraphAlignment.Left;
                    }
                    column = table.AddColumn(Unit.FromCentimeter(columnWidth - (0.45 * 5)));
                    column.Format.Alignment = ParagraphAlignment.Left;
                    row = table.AddRow();
                    rowsCount++;
                    row.VerticalAlignment = VerticalAlignment.Center;
                    paragraph             = row.Cells[0].AddParagraph();
                    paragraph.AddFormattedText("Lead Passenger Name", "Heading2");
                    row.Cells[0].MergeRight = 1;
                    paragraph = row.Cells[2].AddParagraph();
                    paragraph.AddFormattedText(dataset.Tables[tableNameHotelRates].Rows[0]["leadpassangername"].ToString(), "Heading3");
                    row.Cells[2].MergeRight = 3;
                    row = table.AddRow();
                    rowsCount++;
                    row.VerticalAlignment = VerticalAlignment.Center;
                    paragraph             = row.Cells[0].AddParagraph();
                    paragraph.AddFormattedText("Check In Date", "Heading2");
                    paragraph = row.Cells[1].AddParagraph();
                    //paragraph.AddFormattedText(dataset.Tables[tableNameHotelRates].Rows[0]["checkindate"].ToString(), "Heading3");
                    paragraph.AddFormattedText(DateTime.Parse(dataset.Tables[tableNameHotelRates].Rows[0]["checkindate"].ToString()).ToString("yyyy - MM - dd"), "Heading3");
                    paragraph = row.Cells[2].AddParagraph();
                    paragraph.AddFormattedText("Check Out Date", "Heading2");
                    paragraph = row.Cells[3].AddParagraph();
                    //paragraph.AddFormattedText(dataset.Tables[tableNameHotelRates].Rows[0]["checkoutdate"].ToString(), "Heading3");
                    paragraph.AddFormattedText(DateTime.Parse(dataset.Tables[tableNameHotelRates].Rows[0]["checkoutdate"].ToString()).ToString("yyyy - MM - dd"), "Heading3");
                    paragraph = row.Cells[4].AddParagraph();
                    paragraph.AddFormattedText("No of Nights", "Heading2");
                    paragraph = row.Cells[5].AddParagraph();
                    double noOfnights = (DateTime.Parse(dataset.Tables[tableNameHotelRates].Rows[0]["checkoutdate"].ToString()) -
                                         DateTime.Parse(dataset.Tables[tableNameHotelRates].Rows[0]["checkindate"].ToString())).TotalDays;
                    paragraph.AddFormattedText(Convert.ToInt32(noOfnights).ToString(), "Heading3");
                    row = table.AddRow();
                    rowsCount++;
                    row.VerticalAlignment = VerticalAlignment.Center;
                    paragraph             = row.Cells[0].AddParagraph();
                    paragraph.AddFormattedText("Pick Time", "Heading2");
                    paragraph = row.Cells[1].AddParagraph();
                    //paragraph.AddFormattedText(dataset.Tables[tableNameHotelRates].Rows[0]["checkindate"].ToString(), "Heading3");
                    paragraph.AddFormattedText(DateTime.Parse(dataset.Tables[tableNameHotelRates].Rows[0]["checkindate"].ToString()).ToString("HH:mm"), "Heading3");
                    paragraph = row.Cells[2].AddParagraph();
                    paragraph.AddFormattedText("Drop Time", "Heading2");
                    paragraph = row.Cells[3].AddParagraph();
                    //paragraph.AddFormattedText(dataset.Tables[tableNameHotelRates].Rows[0]["checkoutdate"].ToString(), "Heading3");
                    paragraph.AddFormattedText(DateTime.Parse(dataset.Tables[tableNameHotelRates].Rows[0]["checkoutdate"].ToString()).ToString("HH:mm"), "Heading3");
                    row.Cells[4].MergeRight = 1;


                    table.SetEdge(0, 0, columnCount, rowsCount, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1.5, Colors.SkyBlue);
                    rowsCount = columnCount = 0;
                    section.AddParagraph("\n", "Normal");

                    table = section.AddTable();
                    table.Borders.Visible = true;
                    table.Borders.Width   = 0.75;
                    table.Borders.Color   = Colors.SkyBlue;
                    columnCount           = 6;
                    columnWidth           = (21.0 - 2.0) / columnCount;
                    column = table.AddColumn(Unit.FromCentimeter(1.5));
                    column.Format.Alignment = ParagraphAlignment.Center;
                    column = table.AddColumn(Unit.FromCentimeter(2 * columnWidth - 1.5));
                    column.Format.Alignment = ParagraphAlignment.Center;
                    for (int index = 2; index < columnCount; index++)
                    {
                        column = table.AddColumn(Unit.FromCentimeter(columnWidth));
                        column.Format.Alignment = ParagraphAlignment.Center;
                    }
                    row = table.AddRow();
                    rowsCount++;
                    row.VerticalAlignment = VerticalAlignment.Center;
                    //row.Shading.Color = Colors.LightSlateGray;
                    paragraph = row.Cells[0].AddParagraph();
                    paragraph.AddFormattedText("S. No", "Heading2");
                    paragraph = row.Cells[1].AddParagraph();
                    paragraph.AddFormattedText("Room Type", "Heading2");
                    paragraph = row.Cells[2].AddParagraph();
                    paragraph.AddFormattedText("Meal Plan", "Heading2");
                    paragraph = row.Cells[3].AddParagraph();
                    paragraph.AddFormattedText("No of Rooms", "Heading2");
                    paragraph = row.Cells[4].AddParagraph();
                    paragraph.AddFormattedText("No of Guests", "Heading2");
                    paragraph = row.Cells[5].AddParagraph();
                    paragraph.AddFormattedText("Guests Type", "Heading2");
                    for (int roomCounter = 0; roomCounter < dataset.Tables[tableNameHotelRates].Rows.Count; roomCounter++)
                    {
                        row = table.AddRow();
                        rowsCount++;
                        row.VerticalAlignment = VerticalAlignment.Center;
                        paragraph             = row.Cells[0].AddParagraph();
                        paragraph.AddFormattedText((roomCounter + 1).ToString(), "Heading3");
                        paragraph = row.Cells[1].AddParagraph();
                        paragraph.AddFormattedText(dataset.Tables[tableNameHotelRates].Rows[roomCounter]["roomtype"].ToString(), "Heading3");
                        paragraph = row.Cells[2].AddParagraph();
                        paragraph.AddFormattedText(dataset.Tables[tableNameHotelRates].Rows[roomCounter]["mealplan"].ToString(), "Heading3");
                        paragraph = row.Cells[3].AddParagraph();
                        paragraph.AddFormattedText(dataset.Tables[tableNameHotelRates].Rows[roomCounter]["countroom"].ToString(), "Heading3");
                        paragraph = row.Cells[4].AddParagraph();
                        int numberOfGuest = Convert.ToInt32(dataset.Tables[tableNameHotelRates].Rows[roomCounter]["countadults"]) + Convert.ToInt32(dataset.Tables[tableNameHotelRates].Rows[roomCounter]["countchildren"]);
                        paragraph.AddFormattedText(numberOfGuest.ToString(), "Heading3");
                        paragraph = row.Cells[5].AddParagraph();
                        string guestType = "Adults(" + dataset.Tables[tableNameHotelRates].Rows[roomCounter]["countadults"].ToString() + ")";
                        if (Convert.ToInt32(dataset.Tables[tableNameHotelRates].Rows[roomCounter]["countchildren"]) > 0)
                        {
                            guestType = guestType + "\nChildren(" + dataset.Tables[tableNameHotelRates].Rows[roomCounter]["countchildren"].ToString() + ")";
                        }
                        if (Convert.ToInt32(dataset.Tables[tableNameHotelRates].Rows[roomCounter]["countinfants"]) > 0)
                        {
                            guestType = guestType + "\nBabies(" + dataset.Tables[tableNameHotelRates].Rows[roomCounter]["countinfants"].ToString() + ")";
                        }
                        paragraph.AddFormattedText(guestType, "Heading3");
                    }

                    table.SetEdge(0, 0, columnCount, rowsCount, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1.5, Colors.SkyBlue);
                    rowsCount = columnCount = 0;
                    section.AddParagraph("\n", "Normal");

                    MyPdfDocuments.WriteHotelVoucherStaticDetails(section);
                }

                PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
                try
                {
                    /* try to save file */
                    renderer.Document = document;
                    renderer.RenderDocument();
                    renderer.PdfDocument.Save(saveFileDialogItinerary.FileName);
                    renderer.PdfDocument.Close();
                    Process.Start(saveFileDialogItinerary.FileName);
                }
                catch (Exception errSave)
                {
                    MessageBox.Show("Error in saving file " + saveFileDialogItinerary.FileName + " because " + errSave.Message);
                    Debug.WriteLine("Error in saving file " + saveFileDialogItinerary.FileName + " because " + errSave.Message);
                    closeForm = false;
                }
                finally
                {
                    System.IO.File.Delete(imagePath);
                }
                /* now close connection */
                try
                {
                    mySqlConnection.Close();
                }
                catch (Exception errConnClose)
                {
                    MessageBox.Show("Error in opening mysql connection because : " + errConnClose.Message);
                }

                if (closeForm)
                {
                    Debug.WriteLine("File saved: " + saveFileDialogItinerary.FileName);
                }
                else
                {
                    return;
                }
            }

            if ((button == BtnPrintFlightTickets) || (button == BtnPrintBoth))
            {
                //MessageBox.Show("Button pressed = " + button.Text, "PRINTING FLIGHT TICKETS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                /* open connection */
                try
                {
                    mySqlConnection.Open();
                }
                catch (Exception errConnOpen)
                {
                    MessageBox.Show("Error in opening mysql connection because : " + errConnOpen.Message);
                    return;
                }

                /* now execute query to obtain data from hotel booking table
                 * and fill t in dataset
                 */
                string           mySqlQueryString = "SELECT DISTINCT `pnr` FROM `flightbookinginfo` WHERE `queryid` = '" + queryId + "' ORDER BY `pnr`";
                DataSet          dataset          = new DataSet();
                MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter(mySqlQueryString, mySqlConnection);
                mySqlDataAdapter.Fill(dataset, "TABLE_FLIGHT_PNR");
                if ((dataset == null) || (dataset.Tables["TABLE_FLIGHT_PNR"].Rows.Count < 1))
                {
                    MessageBox.Show("No Flight information present for QueryId = " + queryId, "No Data Present", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    try
                    {
                        mySqlConnection.Close();
                    }
                    catch (Exception errConnClose)
                    {
                        MessageBox.Show("Error in opening mysql connection because : " + errConnClose.Message);
                    }
                    return;
                }
                saveFileDialogItinerary.Title = "FLIGHT TICKET FILE NAME";
                if (saveFileDialogItinerary.ShowDialog() == DialogResult.OK)
                {
                    /* file selected */
                    Debug.WriteLine("OUT FILE SELECTED : " + saveFileDialogItinerary.FileName);
                }
                else
                {
                    Debug.WriteLine("File not selected thus returning");
                    try
                    {
                        mySqlConnection.Close();
                    }
                    catch (Exception errConnClose)
                    {
                        MessageBox.Show("Error in opening mysql connection because : " + errConnClose.Message);
                    }
                    return;
                }
                string imagePath = saveFileDialogItinerary.FileName + "logo.png";
                Properties.Resources.ExcursionHolidaysSmallLogo.Save(imagePath);

                Document document = new Document();
                document.Info.Title = "FLIGHT TICKET FOR " + queryId;

                /* Ask for printing price on ticket */
                bool         printPrice   = false;
                DialogResult dialogResult = MessageBox.Show("Flight price details needs to be printed in the flight voucher?", "PRINT PRICE ON VOUCHER", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    printPrice = true;
                }
                else
                {
                    Debug.WriteLine("Price not printing in the ticket");
                }

                /* now cange the style of the document */
                MyPdfDocuments.DefineStyles(document);

                /* add section to document */
                Section section = document.AddSection();
                for (int pageNumber = 0; pageNumber < dataset.Tables["TABLE_FLIGHT_PNR"].Rows.Count; pageNumber++)
                {
                    mySqlQueryString = "SELECT * FROM `flightbookinginfo` WHERE `queryid` = '" + queryId + "' AND `pnr` = '" + dataset.Tables["TABLE_FLIGHT_PNR"].Rows[pageNumber]["pnr"].ToString() + "'";
                    mySqlDataAdapter = new MySqlDataAdapter(mySqlQueryString, mySqlConnection);
                    string tableFlightInfo = "TABLE_FLIGHT_ID_" + pageNumber.ToString();
                    mySqlDataAdapter.Fill(dataset, tableFlightInfo);
                    if (dataset.Tables[tableFlightInfo].Rows.Count < 1)
                    {
                        continue;
                    }
                    if (pageNumber > 0)
                    {
                        section.AddPageBreak();
                    }
                    Paragraph paragraph;
                    Table     table       = null;
                    Column    column      = null;
                    int       columnCount = 0; // 1;
                    double    columnWidth = 0; // (21.0 - 2.0) / columnCount;
                    Row       row         = null;
                    int       rowsCount   = 0;

                    table = section.AddTable();
                    table.Borders.Visible = false;
                    table.Borders.Width   = 0.75;
                    table.Borders.Color   = Colors.SkyBlue;
                    columnCount           = 3;
                    columnWidth           = (21.0 - 2.0) / columnCount;
                    column = table.AddColumn(Unit.FromCentimeter(1.2));
                    column.Format.Alignment = ParagraphAlignment.Left;
                    columnCount++;
                    column = table.AddColumn(Unit.FromCentimeter(columnWidth - 1.2));
                    column.Format.Alignment = ParagraphAlignment.Left;
                    column = table.AddColumn(Unit.FromCentimeter(columnWidth));
                    column.Format.Alignment = ParagraphAlignment.Center;
                    column = table.AddColumn(Unit.FromCentimeter(columnWidth));
                    column.Format.Alignment = ParagraphAlignment.Right;
                    row = table.AddRow();
                    rowsCount++;
                    MigraDoc.DocumentObjectModel.Shapes.Image image = row.Cells[0].AddImage(imagePath);
                    image.Width = "1cm";
                    MyPdfDocuments.WriteAgencyAddressDetails(row.Cells[1]);
                    paragraph = row.Cells[2].AddParagraph();
                    paragraph.AddFormattedText("E - Ticket\nTICKETED", "Heading2");
                    paragraph = row.Cells[3].AddParagraph();
                    paragraph.AddFormattedText("PNR: " + dataset.Tables[tableFlightInfo].Rows[0]["pnr"].ToString() +
                                               " \nIssued Date: " + DateTime.Parse(dataset.Tables[tableFlightInfo].Rows[0]["issuedate"].ToString()).ToString("ddd dd MM yyyy") +
                                               "", "Normal");

                    table.SetEdge(0, 0, columnCount, rowsCount, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.None, 0, Colors.SkyBlue);
                    rowsCount = columnCount = 0;
                    section.AddParagraph("\n", "Normal");

                    table = section.AddTable();
                    table.Borders.Visible = false;
                    table.Borders.Width   = 0.75;
                    table.Borders.Color   = Colors.SkyBlue;
                    columnCount           = 3;
                    columnWidth           = (21.0 - 2.0) / columnCount;
                    column = table.AddColumn(Unit.FromCentimeter(columnWidth));
                    column.Format.Alignment = ParagraphAlignment.Left;
                    column = table.AddColumn(Unit.FromCentimeter(columnWidth));
                    column.Format.Alignment = ParagraphAlignment.Center;
                    column = table.AddColumn(Unit.FromCentimeter(columnWidth));
                    column.Format.Alignment = ParagraphAlignment.Right;
                    row = table.AddRow();
                    rowsCount++;
                    row.Shading.Color = Colors.AliceBlue;
                    paragraph         = row.Cells[0].AddParagraph();
                    paragraph.AddFormattedText("Passanger Name", "Heading3");
                    paragraph = row.Cells[1].AddParagraph();
                    paragraph.AddFormattedText("Ticket Number", "Heading3");
                    paragraph = row.Cells[2].AddParagraph();
                    paragraph.AddFormattedText("Frequent flyer no.", "Heading3");
                    string[] persons = dataset.Tables[tableFlightInfo].Rows[0]["passangername"].ToString().Split(',');
                    string[] tickets = dataset.Tables[tableFlightInfo].Rows[0]["ticketnumber"].ToString().Split(',');
                    string[] ffys    = dataset.Tables[tableFlightInfo].Rows[0]["ffy"].ToString().Split(',');
                    for (int index = 0; index < persons.Length; index++)
                    {
                        if (string.Equals(persons[index], ""))
                        {
                            continue;
                        }
                        row = table.AddRow();
                        rowsCount++;
                        paragraph = row.Cells[0].AddParagraph();
                        paragraph.AddFormattedText(persons[index]);
                        paragraph = row.Cells[1].AddParagraph();
                        try
                        {
                            paragraph.AddFormattedText(tickets[index]);
                        }
                        catch (Exception errindex)
                        {
                            MessageBox.Show("Error : " + errindex.Message, "Error in index", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            paragraph.AddFormattedText("");
                        }
                        paragraph = row.Cells[2].AddParagraph();
                        try
                        {
                            paragraph.AddFormattedText(ffys[index]);
                        }
                        catch (Exception errindex)
                        {
                            MessageBox.Show("Error : " + errindex.Message, "Error in index", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            paragraph.AddFormattedText("-");
                        }
                    }

                    table.SetEdge(0, 0, columnCount, rowsCount, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.None, 0.75, Colors.SkyBlue);
                    rowsCount = columnCount = 0;
                    section.AddParagraph("\n", "Normal");

                    table = section.AddTable();
                    table.Borders.Visible = false;
                    table.Borders.Width   = 0.75;
                    table.Borders.Color   = Colors.SkyBlue;
                    columnCount           = 4;
                    columnWidth           = (21.0 - 2.0) / columnCount;
                    for (int index = 0; index < columnCount; index++)
                    {
                        column = table.AddColumn(Unit.FromCentimeter(columnWidth));
                        column.Format.Alignment = ParagraphAlignment.Left;
                    }
                    row = table.AddRow();
                    row.Shading.Color = Colors.AliceBlue;
                    rowsCount++;
                    paragraph = row.Cells[0].AddParagraph();
                    paragraph.AddFormattedText("Flight", "Heading3");
                    paragraph = row.Cells[1].AddParagraph();
                    paragraph.AddFormattedText("Departure", "Heading3");
                    paragraph = row.Cells[2].AddParagraph();
                    paragraph.AddFormattedText("Arrival", "Heading3");
                    paragraph = row.Cells[3].AddParagraph();
                    paragraph.AddFormattedText("Status", "Heading3");
                    for (int flightCounter = 0; flightCounter < dataset.Tables[tableFlightInfo].Rows.Count; flightCounter++)
                    {
                        row = table.AddRow();
                        rowsCount++;
                        paragraph = row.Cells[0].AddParagraph();
                        paragraph.AddFormattedText(dataset.Tables[tableFlightInfo].Rows[flightCounter]["flightinfo"].ToString());
                        paragraph = row.Cells[1].AddParagraph();
                        paragraph.AddFormattedText(dataset.Tables[tableFlightInfo].Rows[flightCounter]["departureinfo"].ToString());
                        paragraph = row.Cells[2].AddParagraph();
                        paragraph.AddFormattedText(dataset.Tables[tableFlightInfo].Rows[flightCounter]["arrivalinfo"].ToString());
                        paragraph = row.Cells[3].AddParagraph();
                        paragraph.AddFormattedText(dataset.Tables[tableFlightInfo].Rows[flightCounter]["statusinfo"].ToString());
                    }
                    table.SetEdge(0, 0, columnCount, rowsCount, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.None, 0.75, Colors.SkyBlue);
                    rowsCount = columnCount = 0;
                    section.AddParagraph("\n", "Normal");

                    table = section.AddTable();
                    table.Borders.Visible = false;
                    table.Borders.Width   = 0.75;
                    table.Borders.Color   = Colors.SkyBlue;
                    columnCount           = 4;
                    columnWidth           = (21.0 - 2.0) / columnCount;
                    for (int index = 0; index < 2; index++)
                    {
                        column = table.AddColumn(Unit.FromCentimeter(columnWidth + 1.0));
                        column.Format.Alignment = ParagraphAlignment.Left;
                    }
                    for (int index = 2; index < 4; index++)
                    {
                        column = table.AddColumn(Unit.FromCentimeter(columnWidth - 1.0));
                        column.Format.Alignment = ParagraphAlignment.Right;
                    }
                    if (printPrice)
                    {
                        row = table.AddRow();
                        rowsCount++;
                        row.Shading.Color = Colors.AliceBlue;
                        paragraph         = row.Cells[0].AddParagraph();
                        paragraph.AddFormattedText("Payment Details", "Heading3");
                        row.Cells[0].MergeRight = 3;
                    }
                    row = table.AddRow();
                    rowsCount++;
                    paragraph = row.Cells[0].AddParagraph();
                    paragraph.AddFormattedText("This is an Electronic ticket. Please carry a positive identification for Check in.");
                    paragraph.Format.Font.Bold = true;
                    row.Cells[0].MergeRight    = 1;
                    if (printPrice)
                    {
                        int totalPrice = Convert.ToInt32(dataset.Tables[tableFlightInfo].Rows[0]["amountfare"]) +
                                         Convert.ToInt32(dataset.Tables[tableFlightInfo].Rows[0]["amountgst"]) +
                                         Convert.ToInt32(dataset.Tables[tableFlightInfo].Rows[0]["amountsurcharge"]);
                        row.Cells[0].MergeDown = 3;
                        paragraph = row.Cells[2].AddParagraph();
                        paragraph.AddFormattedText("Fare", "Normal");
                        paragraph = row.Cells[3].AddParagraph();
                        paragraph.AddFormattedText(dataset.Tables[tableFlightInfo].Rows[0]["amountfare"].ToString(), "Normal");
                        row = table.AddRow();
                        rowsCount++;
                        paragraph = row.Cells[2].AddParagraph();
                        paragraph.AddFormattedText("K3/GST", "Normal");
                        paragraph = row.Cells[3].AddParagraph();
                        paragraph.AddFormattedText(dataset.Tables[tableFlightInfo].Rows[0]["amountgst"].ToString(), "Normal");
                        row = table.AddRow();
                        rowsCount++;
                        paragraph = row.Cells[2].AddParagraph();
                        paragraph.AddFormattedText("Fee & Surcharge", "Normal");
                        paragraph = row.Cells[3].AddParagraph();
                        paragraph.AddFormattedText(dataset.Tables[tableFlightInfo].Rows[0]["amountsurcharge"].ToString(), "Normal");
                        row = table.AddRow();
                        rowsCount++;
                        paragraph = row.Cells[2].AddParagraph();
                        paragraph.AddFormattedText("Total Amount");
                        paragraph.Format.Font.Bold = true;
                        paragraph = row.Cells[3].AddParagraph();
                        paragraph.AddFormattedText(totalPrice.ToString());
                        paragraph.Format.Font.Bold = true;
                    }
                    table.SetEdge(0, 0, columnCount, rowsCount, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.None, 0.5, Colors.SkyBlue);
                    rowsCount = columnCount = 0;
                    paragraph = section.AddParagraph("\n\n\n", "Normal");

                    /* ADD TERMINAL DETAILS HERE */
                    //paragraph = section.AddParagraph("<TERMINAL DETAILS TYPED HERE XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX>");
                    //paragraph.Format.Font.Color = Colors.Red;
                    table = section.AddTable();
                    table.Borders.Visible = false;
                    table.Borders.Width   = 0.75;
                    table.Borders.Color   = Colors.SkyBlue;
                    columnCount           = 1;
                    columnWidth           = (21.0 - 2.0) / columnCount;
                    column = table.AddColumn(Unit.FromCentimeter(columnWidth));
                    column.Format.Alignment = ParagraphAlignment.Left;
                    row = table.AddRow();
                    rowsCount++;
                    MyPdfDocuments.WriteFlightVoucherNote(row.Cells[0]);

                    table.SetEdge(0, 0, columnCount, rowsCount, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 0, Colors.SkyBlue);
                }

                PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);

                try
                {
                    /* try to save file */
                    renderer.Document = document;
                    renderer.RenderDocument();
                    renderer.PdfDocument.Save(saveFileDialogItinerary.FileName);
                    renderer.PdfDocument.Close();
                    Process.Start(saveFileDialogItinerary.FileName);
                    Debug.WriteLine("File saved: " + saveFileDialogItinerary.FileName);
                }
                catch (Exception errSave)
                {
                    MessageBox.Show("Error in saving file " + saveFileDialogItinerary.FileName + " because " + errSave.Message);
                    Debug.WriteLine("Error in saving file " + saveFileDialogItinerary.FileName + " because " + errSave.Message);
                    closeForm = false;
                }
                finally
                {
                    System.IO.File.Delete(imagePath);
                }
                try
                {
                    mySqlConnection.Close();
                }
                catch (Exception errConnClose)
                {
                    MessageBox.Show("Error in opening mysql connection because : " + errConnClose.Message);
                }
            }
            if (closeForm)
            {
                Close();
            }
        }
예제 #20
0
        /// <summary>Writes PDF for specified auto-doc commands.</summary>
        /// <param name="section">The writer to write to.</param>
        /// <param name="tags">The autodoc tags.</param>
        /// <param name="workingDirectory">The working directory.</param>
        private void TagsToMigraDoc(Section section, List <AutoDocumentation.ITag> tags, string workingDirectory)
        {
            int figureNumber = 0;

            foreach (AutoDocumentation.ITag tag in tags)
            {
                if (tag is AutoDocumentation.Heading)
                {
                    AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading;
                    if (heading.headingLevel > 0 && heading.headingLevel <= 6)
                    {
                        Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel);
                        para.Format.KeepWithNext = true;
                        if (heading.headingLevel == 1)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level1;
                        }
                        else if (heading.headingLevel == 2)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level2;
                        }
                        else if (heading.headingLevel == 3)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level3;
                        }
                        else if (heading.headingLevel == 4)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level4;
                        }
                        else if (heading.headingLevel == 5)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level5;
                        }
                        else if (heading.headingLevel == 6)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level6;
                        }
                    }
                }
                else if (tag is AutoDocumentation.Paragraph)
                {
                    AutoDocumentation.Paragraph paragraph = tag as AutoDocumentation.Paragraph;
                    if (paragraph.text.Contains("![Alt Text]"))
                    {
                        figureNumber++;
                    }
                    paragraph.text = paragraph.text.Replace("[FigureNumber]", figureNumber.ToString());
                    AddFormattedParagraphToSection(section, paragraph);
                }
                else if (tag is AutoDocumentation.GraphAndTable)
                {
                    CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory);
                }
                else if (tag is GraphPage)
                {
                    CreateGraphPage(section, tag as GraphPage, workingDirectory);
                }
                else if (tag is AutoDocumentation.NewPage)
                {
                    section.AddPageBreak();
                }
                else if (tag is AutoDocumentation.Table)
                {
                    CreateTable(section, tag as AutoDocumentation.Table, workingDirectory);
                }
                else if (tag is Graph)
                {
                    GraphPresenter graphPresenter = new GraphPresenter();
                    explorerPresenter.ApsimXFile.Links.Resolve(graphPresenter);
                    GraphView graphView = new GraphView();
                    graphView.BackColor        = OxyPlot.OxyColors.White;
                    graphView.ForegroundColour = OxyPlot.OxyColors.Black;
                    graphView.FontSize         = 12;
                    graphView.Width            = 500;
                    graphView.Height           = 500;
                    graphPresenter.Attach(tag, graphView, explorerPresenter);
                    string pngFileName = graphPresenter.ExportToPNG(workingDirectory);
                    section.AddImage(pngFileName);
                    string caption = (tag as Graph).Caption;
                    if (caption != null)
                    {
                        section.AddParagraph(caption);
                    }
                    graphPresenter.Detach();
                    graphView.MainWidget.Destroy();
                }
                else if (tag is Map && (tag as Map).GetCoordinates().Count > 0)
                {
                    MapPresenter mapPresenter = new MapPresenter();
                    MapView      mapView      = new MapView(null);
                    mapPresenter.Attach(tag, mapView, explorerPresenter);
                    string pngFileName = mapPresenter.ExportToPNG(workingDirectory);
                    if (!String.IsNullOrEmpty(pngFileName))
                    {
                        section.AddImage(pngFileName);
                    }
                    mapPresenter.Detach();
                    mapView.MainWidget.Destroy();
                }
                else if (tag is AutoDocumentation.Image)
                {
                    AutoDocumentation.Image imageTag = tag as AutoDocumentation.Image;
                    if (imageTag.image.Width > 700)
                    {
                        imageTag.image = ImageUtilities.ResizeImage(imageTag.image, 700, 500);
                    }
                    string pngFileName = Path.Combine(workingDirectory, imageTag.name);
                    imageTag.image.Save(pngFileName, System.Drawing.Imaging.ImageFormat.Png);
                    section.AddImage(pngFileName);
                    figureNumber++;
                }
                else if (tag is AutoDocumentation.ModelView)
                {
                    AutoDocumentation.ModelView modelView     = tag as AutoDocumentation.ModelView;
                    ViewNameAttribute           viewName      = ReflectionUtilities.GetAttribute(modelView.model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute;
                    PresenterNameAttribute      presenterName = ReflectionUtilities.GetAttribute(modelView.model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute;
                    if (viewName != null && presenterName != null)
                    {
                        ViewBase   view      = Assembly.GetExecutingAssembly().CreateInstance(viewName.ToString(), false, BindingFlags.Default, null, new object[] { ViewBase.MasterView }, null, null) as ViewBase;
                        IPresenter presenter = Assembly.GetExecutingAssembly().CreateInstance(presenterName.ToString()) as IPresenter;

                        if (view != null && presenter != null)
                        {
                            explorerPresenter.ApsimXFile.Links.Resolve(presenter);
                            presenter.Attach(modelView.model, view, explorerPresenter);

                            Gtk.Window popupWin = null;
                            if (view is MapView)
                            {
                                popupWin = (view as MapView)?.GetPopupWin();
                                popupWin?.SetSizeRequest(515, 500);
                            }
                            if (popupWin == null)
                            {
                                popupWin = new Gtk.Window(Gtk.WindowType.Popup);
                                popupWin.SetSizeRequest(800, 800);
                                popupWin.Add(view.MainWidget);
                            }
                            popupWin.ShowAll();
                            while (Gtk.Application.EventsPending())
                            {
                                Gtk.Application.RunIteration();
                            }

                            string pngFileName = (presenter as IExportable).ExportToPNG(workingDirectory);
                            section.AddImage(pngFileName);
                            presenter.Detach();
                            view.MainWidget.Destroy();
                            popupWin.Destroy();
                        }
                    }
                }
            }
        }
예제 #21
0
        /// <summary>Writes PDF for specified auto-doc commands.</summary>
        /// <param name="section">The writer to write to.</param>
        /// <param name="tags">The autodoc tags.</param>
        /// <param name="workingDirectory">The working directory.</param>
        private void TagsToMigraDoc(Section section, List <AutoDocumentation.ITag> tags, string workingDirectory)
        {
            int figureNumber = 0;

            foreach (AutoDocumentation.ITag tag in tags)
            {
                if (tag is AutoDocumentation.Heading)
                {
                    AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading;
                    if (heading.headingLevel > 0 && heading.headingLevel <= 6)
                    {
                        //if (heading.headingLevel == 1)
                        //    section.AddPageBreak();

                        Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel);
                        if (heading.headingLevel == 1)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level1;
                        }
                        else if (heading.headingLevel == 2)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level2;
                        }
                        else if (heading.headingLevel == 3)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level3;
                        }
                        else if (heading.headingLevel == 4)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level4;
                        }
                        else if (heading.headingLevel == 5)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level5;
                        }
                        else if (heading.headingLevel == 6)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level6;
                        }
                    }
                }
                else if (tag is AutoDocumentation.Paragraph)
                {
                    AutoDocumentation.Paragraph paragraph = tag as AutoDocumentation.Paragraph;
                    if (paragraph.text.Contains("![Alt Text]"))
                    {
                        figureNumber++;
                    }
                    paragraph.text = paragraph.text.Replace("[FigureNumber]", figureNumber.ToString());
                    AddFormattedParagraphToSection(section, paragraph);
                }
                else if (tag is AutoDocumentation.GraphAndTable)
                {
                    CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory);
                }
                else if (tag is GraphPage)
                {
                    CreateGraphPage(section, tag as GraphPage, workingDirectory);
                }
                else if (tag is AutoDocumentation.NewPage)
                {
                    section.AddPageBreak();
                }
                else if (tag is AutoDocumentation.Table)
                {
                    CreateTable(section, tag as AutoDocumentation.Table, workingDirectory);
                }
                else if (tag is Graph)
                {
                    GraphPresenter graphPresenter = new GraphPresenter();
                    ExplorerPresenter.ApsimXFile.Links.Resolve(graphPresenter);
                    GraphView graphView = new GraphView();
                    graphView.BackColor = OxyPlot.OxyColors.White;
                    graphView.FontSize  = 12;
                    graphView.Width     = 500;
                    graphView.Height    = 500;
                    graphPresenter.Attach(tag, graphView, ExplorerPresenter);
                    string PNGFileName = graphPresenter.ExportToPDF(workingDirectory);
                    section.AddImage(PNGFileName);
                    string caption = (tag as Graph).Caption;
                    if (caption != null)
                    {
                        section.AddParagraph(caption);
                    }
                    graphPresenter.Detach();
                    graphView.MainWidget.Destroy();
                }
                else if (tag is Map && (tag as Map).GetCoordinates().Count > 0)
                {
                    MapPresenter mapPresenter = new MapPresenter();
                    MapView      mapView      = new MapView(null);
                    mapPresenter.Attach(tag, mapView, ExplorerPresenter);
                    string PNGFileName = mapPresenter.ExportToPDF(workingDirectory);
                    if (!String.IsNullOrEmpty(PNGFileName))
                    {
                        section.AddImage(PNGFileName);
                    }
                    mapPresenter.Detach();
                    mapView.MainWidget.Destroy();
                }
                else if (tag is AutoDocumentation.Image)
                {
                    AutoDocumentation.Image imageTag = tag as AutoDocumentation.Image;
                    if (imageTag.image.Width > 700)
                    {
                        imageTag.image = ImageUtilities.ResizeImage(imageTag.image, 700, 500);
                    }
                    string PNGFileName = Path.Combine(workingDirectory, imageTag.name);
                    imageTag.image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png);
                    section.AddImage(PNGFileName);
                    figureNumber++;
                }
            }
        }
예제 #22
0
        /// <summary>
        /// Print packaging slips to PDF
        /// </summary>
        /// <param name="orderCollection">Order collection</param>
        /// <param name="filePath">File path</param>
        public static void PrintPackagingSlipsToPdf(List <Order> orderCollection,
                                                    string filePath)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            Document doc     = new Document();
            Section  section = doc.AddSection();

            int ordCount = orderCollection.Count;
            int ordNum   = 0;

            foreach (var order in orderCollection)
            {
                Paragraph p1 = section.AddParagraph(String.Format("{0} #{1}", LocalizationManager.GetLocaleResourceString("PdfPackagingSlip.Order"), order.OrderId));
                p1.Format.Font.Bold      = true;
                p1.Format.Font.Color     = Colors.Black;
                p1.Format.Font.Underline = Underline.None;
                section.AddParagraph();

                section.AddParagraph(order.ShippingFullName);
                section.AddParagraph(order.ShippingAddress1);
                section.AddParagraph(String.Format("{0}, {1}", order.ShippingCity, order.ShippingZipPostalCode));
                section.AddParagraph();

                section.AddParagraph(String.Format(LocalizationManager.GetLocaleResourceString("PDFInvoice.ShippingMethod"), order.ShippingMethod));
                section.AddParagraph();

                Table productTable = section.AddTable();
                productTable.Borders.Visible = true;
                productTable.AddColumn(Unit.FromCentimeter(4));
                productTable.AddColumn(Unit.FromCentimeter(10));
                productTable.AddColumn(Unit.FromCentimeter(4));

                Row header = productTable.AddRow();
                header.Shading.Color = Colors.LightGray;

                header.Cells[0].Format.Alignment = ParagraphAlignment.Center;
                header.Cells[0].AddParagraph(LocalizationManager.GetLocaleResourceString("PdfPackagingSlip.QTY"));

                header.Cells[1].Format.Alignment = ParagraphAlignment.Center;
                header.Cells[1].AddParagraph(LocalizationManager.GetLocaleResourceString("PdfPackagingSlip.ProductName"));

                header.Cells[2].Format.Alignment = ParagraphAlignment.Center;
                header.Cells[2].AddParagraph(LocalizationManager.GetLocaleResourceString("PdfPackagingSlip.SKU"));

                var opvc = order.OrderProductVariants;
                foreach (var orderProductVariant in opvc)
                {
                    Row row = productTable.AddRow();

                    row.Cells[0].Format.Alignment = ParagraphAlignment.Center;
                    row.Cells[0].AddParagraph(orderProductVariant.Quantity.ToString());

                    string name = String.Format("Not available. ID={0}", orderProductVariant.ProductVariantId);
                    var    pv   = ProductManager.GetProductVariantById(orderProductVariant.ProductVariantId);
                    if (pv != null)
                    {
                        name = pv.LocalizedFullProductName;
                    }
                    row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
                    row.Cells[1].AddParagraph(name);
                    Paragraph p2 = row.Cells[1].AddParagraph(HtmlHelper.ConvertHtmlToPlainText(orderProductVariant.AttributeDescription, true));
                    p2.Format.Font.Italic = true;

                    row.Cells[2].Format.Alignment = ParagraphAlignment.Center;
                    row.Cells[2].AddParagraph(orderProductVariant.ProductVariant.SKU);
                }

                ordNum++;

                if (ordNum < ordCount)
                {
                    section.AddPageBreak();
                }
            }

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);

            renderer.Document = doc;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(filePath);
        }
예제 #23
0
        /// <summary>
        /// Print product collection to PDF
        /// </summary>
        /// <param name="productCollection"></param>
        /// <param name="filePath"></param>
        public static void PrintProductsToPdf(List <Product> productCollection, string filePath)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            Document doc     = new Document();
            Section  section = doc.AddSection();

            int productNumber = 1;
            int prodCount     = productCollection.Count;

            foreach (var product in productCollection)
            {
                Paragraph p1 = section.AddParagraph(String.Format("{0}. {1}", productNumber, product.LocalizedName));
                p1.Format.Font.Bold  = true;
                p1.Format.Font.Color = Colors.Black;

                section.AddParagraph();

                section.AddParagraph(HtmlHelper.StripTags(HtmlHelper.ConvertHtmlToPlainText(product.LocalizedFullDescription)));

                section.AddParagraph();

                var pictures = PictureManager.GetPicturesByProductId(product.ProductId);
                if (pictures.Count > 0)
                {
                    Table table = section.AddTable();
                    table.Borders.Visible = false;

                    table.AddColumn(Unit.FromCentimeter(10));
                    table.AddColumn(Unit.FromCentimeter(10));

                    Row row = table.AddRow();
                    for (int i = 0; i < pictures.Count; i++)
                    {
                        int cellNum = i % 2;
                        var pic     = pictures[i];

                        if (pic != null && pic.LoadPictureBinary() != null && pic.LoadPictureBinary().Length > 0)
                        {
                            row.Cells[cellNum].AddImage(PictureManager.GetPictureLocalPath(pic, 200, true));
                        }

                        if (i != 0 && i % 2 == 0)
                        {
                            row = table.AddRow();
                        }
                    }

                    section.AddParagraph();
                }

                int pvNum = 1;

                foreach (var productVariant in product.ProductVariants)
                {
                    string pvName = String.IsNullOrEmpty(productVariant.LocalizedName) ? LocalizationManager.GetLocaleResourceString("PDFProductCatalog.UnnamedProductVariant") : productVariant.LocalizedName;
                    section.AddParagraph(String.Format("{0}.{1}. {2}", productNumber, pvNum, pvName));

                    section.AddParagraph();

                    if (!String.IsNullOrEmpty(productVariant.LocalizedDescription))
                    {
                        section.AddParagraph(HtmlHelper.StripTags(HtmlHelper.ConvertHtmlToPlainText(productVariant.LocalizedDescription)));
                        section.AddParagraph();
                    }

                    var pic = productVariant.Picture;
                    if (pic != null && pic.LoadPictureBinary() != null && pic.LoadPictureBinary().Length > 0)
                    {
                        section.AddImage(PictureManager.GetPictureLocalPath(pic, 200, true));
                    }

                    section.AddParagraph(String.Format("{0}: {1} {2}", LocalizationManager.GetLocaleResourceString("PDFProductCatalog.Price"), productVariant.Price, CurrencyManager.PrimaryStoreCurrency.CurrencyCode));
                    section.AddParagraph(String.Format("{0}: {1}", LocalizationManager.GetLocaleResourceString("PDFProductCatalog.SKU"), productVariant.SKU));

                    if (productVariant.Weight > Decimal.Zero)
                    {
                        section.AddParagraph(String.Format("{0}: {1} {2}", LocalizationManager.GetLocaleResourceString("PDFProductCatalog.Weight"), productVariant.Weight, MeasureManager.BaseWeightIn.Name));
                    }

                    if (productVariant.ManageInventory == (int)ManageInventoryMethodEnum.ManageStock)
                    {
                        section.AddParagraph(String.Format("{0}: {1}", LocalizationManager.GetLocaleResourceString("PDFProductCatalog.StockQuantity"), productVariant.StockQuantity));
                    }

                    section.AddParagraph();

                    pvNum++;
                }

                productNumber++;

                if (productNumber <= prodCount)
                {
                    section.AddPageBreak();
                }
            }

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);

            renderer.Document = doc;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(filePath);
        }
예제 #24
0
        private void Estatisticas_Partida()
        {
            Document document = new Document();

            document.Info.Title   = DateTime.Now.ToString("dd-MM-yyyy") + "_" + eventoAtual["nome"].ToString() + "_" + duplaAtual["nomedupla"].ToString();
            document.Info.Subject = "Relatório da partida.";

            Style style = document.Styles["Normal"];

            style.Font.Name = "Helvetica";

            Section section = document.AddSection();

            Paragraph paragraph = new Paragraph();

            paragraph.Format.Alignment = ParagraphAlignment.Center;
            paragraph.AddText("Página ");
            paragraph.AddPageField();
            paragraph.AddText(" de ");
            paragraph.AddNumPagesField();

            section.Headers.Primary.Add(paragraph);

            Paragraph title = section.AddParagraph();

            title.Format.Alignment = ParagraphAlignment.Center;
            title.AddFormattedText(eventoAtual["nome"].ToString(), TextFormat.Bold);

            section.AddParagraph();

            title = section.AddParagraph();
            title.Format.Alignment = ParagraphAlignment.Center;

            title.AddFormattedText("Data: ", TextFormat.Bold);
            title.AddText(DateTime.Now.ToString("dd/MM/yyyy"));
            title.AddFormattedText("\t\tHora: ", TextFormat.Bold);
            title.AddText(DateTime.Now.ToString("HH:mm:ss"));
            title.AddFormattedText("\t\tCategoria: ", TextFormat.Bold);
            title.AddText(categoriaAtual["nome"].ToString());

            section.AddParagraph();

            #region tabela de cabeçalho
            //Tabela de Cabeçalho
            Table t = section.AddTable();
            t.Style            = "Normal";
            t.Borders.Width    = 0.25;
            t.Format.Font.Size = 10;
            t.Rows.Height      = 14;

            t.AddColumn("4cm").Format.Alignment = ParagraphAlignment.Center;
            t.AddColumn("4cm").Format.Alignment = ParagraphAlignment.Center;
            t.AddColumn("4cm").Format.Alignment = ParagraphAlignment.Center;
            t.AddColumn("4cm").Format.Alignment = ParagraphAlignment.Center;

            Row r1 = t.AddRow();

            r1.VerticalAlignment = VerticalAlignment.Center;

            r1.Cells[0].Format.Font.Color = Colors.Red;
            r1.Cells[0].AddParagraph("In: " + atleta1["apelido"].ToString());
            r1.Cells[1].AddParagraph("Out: " + atleta2["apelido"].ToString());
            r1.Cells[2].MergeRight = 1;
            r1.Cells[2].AddParagraph().AddFormattedText("Pontuação Total: " + string.Format("{0:0.00}", pontuacao));

            Row r2 = t.AddRow();

            r2.Cells[0].AddParagraph("Tempo de Jogo: " + label2.Text);
            r2.Cells[0].MergeRight = 1;
            r2.Cells[2].AddParagraph("Equilíbrio: " + string.Format("{0:0.00}", equilibrio));
            r2.Cells[3].AddParagraph("Pontos: " + string.Format("{0:0.00}", equilibrio));

            Row r3 = t.AddRow();

            r3.Cells[0].Format.Font.Color = Colors.Red;
            r3.Cells[0].AddParagraph("Ataques In: " + ataquesAtleta1);
            r3.Cells[1].AddParagraph("Ataques Out: " + ataquesAtleta2);
            r3.Cells[2].AddParagraph("Total de Ataques: " + ataquesTotal);
            r3.Cells[3].AddParagraph("Pontos: " + string.Format("{0:0.00}", pontosAtaques));

            Row r4 = t.AddRow();

            r4.Cells[0].Format.Font.Color = Colors.Red;
            r4.Cells[0].AddParagraph("Potência In: " + string.Format("{0:0.00}", potenciaAtleta1));
            r4.Cells[1].AddParagraph("Potência Out: " + string.Format("{0:0.00}", potenciaAtleta2));
            r4.Cells[2].AddParagraph("Potência Média: " + string.Format("{0:0.00}", potenciaTotalMedia));
            r4.Cells[3].AddParagraph("Pontos: " + string.Format("{0:0.00}", pontosPotencia));

            Row r5 = t.AddRow();

            r5.Cells[0].Format.Font.Color = Colors.Red;
            r5.Cells[0].AddParagraph("Nota Juiz In: " + notaJuizAtleta1);
            r5.Cells[1].AddParagraph("Nota Juiz Out: " + notaJuizAtleta2);
            r5.Cells[2].AddParagraph("Nota Juiz Total: " + (notaJuizAtleta1 + notaJuizAtleta2));
            r5.Cells[3].AddParagraph("Pontos: " + (notaJuizAtleta1 + notaJuizAtleta2));

            Row r6 = t.AddRow();

            r6.Cells[1].MergeRight = 1;
            r6.Cells[1].AddParagraph("Número de Sequências: " + sequencias);
            r6.Cells[3].AddParagraph("Pontos: " + pontosSequencias);

            section.AddParagraph();
            section.AddParagraph();

            #endregion

            #region tabela de registros
            //Tabela de registros
            t = section.AddTable();

            t.Style            = "Normal";
            t.Format.Font.Size = 10;
            t.Rows.Height      = 14;

            t.AddColumn("5.33cm").Format.Alignment = ParagraphAlignment.Center;
            t.AddColumn("5.33cm").Format.Alignment = ParagraphAlignment.Center;
            t.AddColumn("5.33cm").Format.Alignment = ParagraphAlignment.Center;

            Row   r  = t.AddRow();
            Table t1 = r.Cells[0].AddTextFrame().AddTable();
            Table t2 = r.Cells[1].AddTextFrame().AddTable();
            Table t3 = r.Cells[2].AddTextFrame().AddTable();

            Table[] tables = new Table[3] {
                t1, t2, t3
            };

            foreach (Table tab in tables)
            {
                tab.Borders.Width = 0.25;

                tab.AddColumn("1.77cm").Format.Alignment = ParagraphAlignment.Center;
                tab.AddColumn("1.77cm").Format.Alignment = ParagraphAlignment.Center;
                tab.AddColumn("1.77cm").Format.Alignment = ParagraphAlignment.Center;

                r = tab.AddRow();
                r.VerticalAlignment = VerticalAlignment.Center;

                r.Cells[0].AddParagraph("Tempo");
                r.Cells[1].AddParagraph("In/Out");
                r.Cells[2].AddParagraph("Km/h");
            }

            int  start         = 0;
            int  i             = 0;
            int  pagelimit     = 44;
            int  numberofpages = 0;
            bool newpage       = false;

            foreach (SpeedRecord s in registrosRadar)
            {
                if (i != 0 && i % pagelimit == 0)
                {
                    start++; newpage = true;
                }

                if (start != 0 && start % 3 == 0 && newpage == true)
                {
                    numberofpages++;
                    pagelimit = 55;
                    i         = (pagelimit * numberofpages);
                    newpage   = false;
                    section.AddPageBreak();

                    t = section.AddTable();

                    t.Style            = "Normal";
                    t.Format.Font.Size = 10;
                    t.Rows.Height      = 14;

                    t.AddColumn("5.33cm").Format.Alignment = ParagraphAlignment.Center;
                    t.AddColumn("5.33cm").Format.Alignment = ParagraphAlignment.Center;
                    t.AddColumn("5.33cm").Format.Alignment = ParagraphAlignment.Center;

                    r  = t.AddRow();
                    t1 = r.Cells[0].AddTextFrame().AddTable();
                    t2 = r.Cells[1].AddTextFrame().AddTable();
                    t3 = r.Cells[2].AddTextFrame().AddTable();

                    tables[0] = t1; tables[1] = t2; tables[2] = t3;

                    foreach (Table tab in tables)
                    {
                        tab.Borders.Width = 0.25;

                        tab.AddColumn("1.77cm").Format.Alignment = ParagraphAlignment.Center;
                        tab.AddColumn("1.77cm").Format.Alignment = ParagraphAlignment.Center;
                        tab.AddColumn("1.77cm").Format.Alignment = ParagraphAlignment.Center;

                        r = tab.AddRow();
                        r.VerticalAlignment = VerticalAlignment.Center;

                        r.Cells[0].AddParagraph("Tempo");
                        r.Cells[1].AddParagraph("In/Out");
                        r.Cells[2].AddParagraph("Km/h");
                    }
                }

                Row x = tables[start % 3].AddRow();

                if (s.IdEvento == -1)
                {
                    x.Cells[0].AddParagraph("---");
                    x.Cells[1].AddParagraph("---");
                    x.Cells[2].AddParagraph("---");
                }
                else
                {
                    if (s.Direcao == 0)
                    {
                        x.Cells[0].Format.Font.Color = Colors.Red;
                        x.Cells[1].Format.Font.Color = Colors.Red;
                        x.Cells[2].Format.Font.Color = Colors.Red;
                        x.Cells[1].AddParagraph("In");
                    }
                    else
                    {
                        x.Cells[1].AddParagraph("Out");
                    }

                    x.Cells[0].AddParagraph(new DateTime(s.Ticks).ToString("mm:ss.ff"));
                    x.Cells[2].AddParagraph(s.Velocidade.ToString());
                }

                i++;
            }

            #endregion

            //table.SetEdge(0, 0, 6, 2, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 0.75, MigraDoc.DocumentObjectModel.Color.Empty);

            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer();
            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();

            string fileName = "relatorios\\" + document.Info.Title + ".pdf";

            System.IO.Directory.CreateDirectory("relatorios");

            pdfRenderer.PdfDocument.Save(fileName);
            Process.Start(fileName);
        }
예제 #25
0
파일: PDFWriter.cs 프로젝트: ilhuber/ApsimX
        /// <summary>Writes PDF for specified auto-doc commands.</summary>
        /// <param name="section">The writer to write to.</param>
        /// <param name="tags">The autodoc tags.</param>
        private void TagsToMigraDoc(Section section, List <AutoDocumentation.ITag> tags)
        {
            int figureNumber = 0;

            foreach (AutoDocumentation.ITag tag in tags)
            {
                if (tag is AutoDocumentation.Heading)
                {
                    AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading;
                    if (heading.headingLevel > 0 && heading.headingLevel <= 6)
                    {
                        Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel);
                        para.Format.KeepWithNext = true;
                        int posSpace = heading.text.IndexOf(' ');
                        if (posSpace > 0)
                        {
                            para.AddBookmark(heading.text.Substring(posSpace + 1));
                        }
                        if (heading.headingLevel == 1)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level1;
                        }
                        else if (heading.headingLevel == 2)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level2;
                        }
                        else if (heading.headingLevel == 3)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level3;
                        }
                        else if (heading.headingLevel == 4)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level4;
                        }
                        else if (heading.headingLevel == 5)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level5;
                        }
                        else if (heading.headingLevel == 6)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level6;
                        }
                    }
                }
                else if (tag is AutoDocumentation.Paragraph)
                {
                    AutoDocumentation.Paragraph paragraph = tag as AutoDocumentation.Paragraph;
                    if (paragraph.text.Contains("![Alt Text]"))
                    {
                        figureNumber++;
                    }
                    paragraph.text = paragraph.text.Replace("[FigureNumber]", figureNumber.ToString());
                    AddFormattedParagraphToSection(section, paragraph);
                }
                else if (tag is AutoDocumentation.GraphAndTable)
                {
                    CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable);
                }
                else if (tag is GraphPage)
                {
                    CreateGraphPage(section, tag as GraphPage);
                }
                else if (tag is AutoDocumentation.NewPage)
                {
                    section.AddPageBreak();
                    if ((tag as AutoDocumentation.NewPage).Portrait)
                    {
                        section.PageSetup.Orientation = Orientation.Portrait;
                    }
                    else
                    {
                        section.PageSetup.Orientation = Orientation.Landscape;
                    }
                }
                else if (tag is AutoDocumentation.PageSetup)
                {
                    if ((tag as AutoDocumentation.PageSetup).Portrait)
                    {
                        section.PageSetup.Orientation = Orientation.Portrait;
                    }
                    else
                    {
                        section.PageSetup.Orientation = Orientation.Landscape;
                    }
                }
                else if (tag is AutoDocumentation.Table)
                {
                    CreateTable(section, tag as AutoDocumentation.Table);
                }
                else if (tag is Graph)
                {
                    GraphPresenter graphPresenter = new GraphPresenter();
                    explorerPresenter.ApsimXFile.Links.Resolve(graphPresenter);
                    GraphView graphView = new GraphView();
                    graphView.BackColor        = OxyPlot.OxyColors.White;
                    graphView.ForegroundColour = OxyPlot.OxyColors.Black;
                    graphView.FontSize         = 12;
                    graphView.Width            = 500;
                    graphView.Height           = 500;
                    graphPresenter.Attach(tag, graphView, explorerPresenter);
                    string pngFileName = graphPresenter.ExportToPNG(WorkingDirectory);
                    section.AddResizeImage(pngFileName);
                    string caption = (tag as Graph).Caption;
                    if (caption != null)
                    {
                        section.AddParagraph(caption);
                    }
                    graphPresenter.Detach();
                    graphView.MainWidget.Cleanup();
                }
                else if (tag is Map && (tag as Map).GetCoordinates().Count > 0)
                {
#if NETFRAMEWORK
                    MapPresenter mapPresenter = new MapPresenter();
                    MapView      mapView      = new MapView(null);
                    mapPresenter.Attach(tag, mapView, explorerPresenter);
                    var    map         = mapView.Export();
                    string pngFileName = Path.ChangeExtension(Path.GetTempFileName(), ".png");
                    if (map.Width > section.PageSetup.PageWidth)
                    {
                        map = ImageUtilities.ResizeImage(map, section.PageSetup.PageWidth, double.MaxValue);
                    }
                    map.Save(pngFileName);
                    if (!String.IsNullOrEmpty(pngFileName))
                    {
                        section.AddResizeImage(pngFileName);
                    }
                    mapPresenter.Detach();
                    mapView.MainWidget.Destroy();
#else
                    section.AddParagraph("MapView has not been implemented in gtk3. Use the framework/gtk2 build instead.");
#endif
                }
                else if (tag is AutoDocumentation.Image)
                {
                    AutoDocumentation.Image imageTag = tag as AutoDocumentation.Image;
                    string pngFileName = Path.Combine(WorkingDirectory, $"{imageTag.name}.png");
                    imageTag.image.Save(pngFileName, System.Drawing.Imaging.ImageFormat.Png);
                    section.AddResizeImage(pngFileName);
                    figureNumber++;
                }
                else if (tag is AutoDocumentation.ModelView)
                {
                    try
                    {
                        AutoDocumentation.ModelView modelView     = tag as AutoDocumentation.ModelView;
                        ViewNameAttribute           viewName      = ReflectionUtilities.GetAttribute(modelView.model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute;
                        PresenterNameAttribute      presenterName = ReflectionUtilities.GetAttribute(modelView.model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute;
                        if (viewName != null && presenterName != null)
                        {
                            ViewBase owner = ViewBase.MasterView as ViewBase;
                            if (viewName.ToString() == "UserInterface.Views.MapView")
                            {
                                owner = null;
                            }

                            ViewBase   view      = Assembly.GetExecutingAssembly().CreateInstance(viewName.ToString(), false, BindingFlags.Default, null, new object[] { owner }, null, null) as ViewBase;
                            IPresenter presenter = Assembly.GetExecutingAssembly().CreateInstance(presenterName.ToString()) as IPresenter;

                            if (view != null && presenter != null)
                            {
                                explorerPresenter.ApsimXFile.Links.Resolve(presenter);
                                presenter.Attach(modelView.model, view, explorerPresenter);

#if NETFRAMEWORK
                                Gtk.Window popupWin = new Gtk.Window(Gtk.WindowType.Popup);
#endif
                                try
                                {
#if NETFRAMEWORK
                                    popupWin.SetSizeRequest(700, 700);
                                    popupWin.Add(view.MainWidget);
#endif

                                    if (view is MapView map)
                                    {
                                        map.HideZoomControls();
                                    }
#if NETFRAMEWORK
                                    popupWin.ShowAll();
#endif
                                    while (Gtk.Application.EventsPending())
                                    {
                                        Gtk.Application.RunIteration();
                                    }

                                    // From MapView:
                                    // With WebKit, it appears we need to give it time to actually update the display
                                    // Really only a problem with the temporary windows used for generating documentation
                                    string pngFileName;
                                    if (view is MapView mapView)
                                    {
                                        var img = mapView.Export();
                                        pngFileName = Path.ChangeExtension(Path.GetTempFileName(), ".png");
                                        if (section.PageSetup.PageWidth > 0 && img.Width > section.PageSetup.PageWidth)
                                        {
                                            img = ImageUtilities.ResizeImage(img, section.PageSetup.PageWidth, double.MaxValue);
                                        }
                                        img.Save(pngFileName);
                                    }
                                    else
                                    {
                                        pngFileName = (presenter as IExportable).ExportToPNG(WorkingDirectory);
                                    }
                                    section.AddResizeImage(pngFileName);
                                    presenter.Detach();
                                    view.MainWidget.Cleanup();
                                }
                                finally
                                {
#if NETFRAMEWORK
                                    popupWin.Cleanup();
#endif
                                    while (GLib.MainContext.Iteration())
                                    {
                                        ;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception err)
                    {
                        Console.WriteLine(err);
                    }
                }
            }
        }
예제 #26
0
 public void AddPageBreak()
 {
     Section.AddPageBreak();
 }
예제 #27
0
        /// <summary>Writes PDF for specified auto-doc commands.</summary>
        /// <param name="section">The writer to write to.</param>
        /// <param name="tags">The autodoc tags.</param>
        /// <param name="workingDirectory">The working directory.</param>
        private void TagsToMigraDoc(Section section, List <AutoDocumentation.ITag> tags, string workingDirectory)
        {
            foreach (AutoDocumentation.ITag tag in tags)
            {
                if (tag is AutoDocumentation.Heading)
                {
                    AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading;
                    if (heading.headingLevel > 0 && heading.headingLevel <= 6)
                    {
                        if (heading.headingLevel == 1)
                        {
                            section.AddPageBreak();
                        }

                        Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel);
                        if (heading.headingLevel == 1)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level1;
                        }
                        else if (heading.headingLevel == 2)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level2;
                        }
                        else if (heading.headingLevel == 3)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level3;
                        }
                        else if (heading.headingLevel == 4)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level4;
                        }
                        else if (heading.headingLevel == 5)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level5;
                        }
                        else if (heading.headingLevel == 6)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level6;
                        }
                    }
                }
                else if (tag is AutoDocumentation.Paragraph)
                {
                    AddFormattedParagraphToSection(section, tag as AutoDocumentation.Paragraph);
                }
                else if (tag is AutoDocumentation.GraphAndTable)
                {
                    CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory);
                }
                else if (tag is AutoDocumentation.Table)
                {
                    CreateTable(section, tag as AutoDocumentation.Table, workingDirectory);
                }
                else if (tag is Graph)
                {
                    GraphPresenter graphPresenter = new GraphPresenter();
                    GraphView      graphView      = new GraphView(null);
                    graphView.BackColor = OxyPlot.OxyColors.White;
                    graphView.FontSize  = 12;
                    graphView.Width     = 500;
                    graphView.Height    = 500;
                    graphPresenter.Attach(tag, graphView, ExplorerPresenter);
                    string PNGFileName = graphPresenter.ExportToPDF(workingDirectory);
                    section.AddImage(PNGFileName);
                    string caption = (tag as Graph).Caption;
                    if (caption != null)
                    {
                        section.AddParagraph(caption);
                    }
                    graphPresenter.Detach();
                }
                else if (tag is Map)
                {
                    /* TBI
                     * Form f = new Form();
                     * f.Width = 700; // 1100;
                     * f.Height = 500; // 600;
                     * MapPresenter mapPresenter = new MapPresenter();
                     * MapView mapView = new MapView();
                     * mapView.BackColor = System.Drawing.Color.White;
                     * mapView.Parent = f;
                     * (mapView as Control).Dock = DockStyle.Fill;
                     * f.Show();
                     *
                     * mapPresenter.Attach(tag, mapView, ExplorerPresenter);
                     *
                     * Application.DoEvents();
                     * Thread.Sleep(2000);
                     * Application.DoEvents();
                     * string PNGFileName = mapPresenter.ExportToPDF(workingDirectory);
                     * section.AddImage(PNGFileName);
                     * mapPresenter.Detach();
                     *
                     * f.Close();
                     */
                }
            }
        }
예제 #28
0
        /// <summary>Writes PDF for specified auto-doc commands.</summary>
        /// <param name="section">The writer to write to.</param>
        /// <param name="tags">The autodoc tags.</param>
        /// <param name="workingDirectory">The working directory.</param>
        private void TagsToMigraDoc(Section section, List <AutoDocumentation.ITag> tags, string workingDirectory)
        {
            int figureNumber = 0;

            foreach (AutoDocumentation.ITag tag in tags)
            {
                if (tag is AutoDocumentation.Heading)
                {
                    AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading;
                    if (heading.headingLevel > 0 && heading.headingLevel <= 6)
                    {
                        //if (heading.headingLevel == 1)
                        //    section.AddPageBreak();

                        Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel);
                        if (heading.headingLevel == 1)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level1;
                        }
                        else if (heading.headingLevel == 2)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level2;
                        }
                        else if (heading.headingLevel == 3)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level3;
                        }
                        else if (heading.headingLevel == 4)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level4;
                        }
                        else if (heading.headingLevel == 5)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level5;
                        }
                        else if (heading.headingLevel == 6)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level6;
                        }
                    }
                }
                else if (tag is AutoDocumentation.Paragraph)
                {
                    AutoDocumentation.Paragraph paragraph = tag as AutoDocumentation.Paragraph;
                    if (paragraph.text.Contains("![Alt Text]"))
                    {
                        figureNumber++;
                    }
                    paragraph.text = paragraph.text.Replace("[FigureNumber]", figureNumber.ToString());
                    AddFormattedParagraphToSection(section, paragraph);
                }
                else if (tag is AutoDocumentation.GraphAndTable)
                {
                    CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory);
                }
                else if (tag is GraphPage)
                {
                    CreateGraphPage(section, tag as GraphPage, workingDirectory);
                }
                else if (tag is AutoDocumentation.NewPage)
                {
                    section.AddPageBreak();
                }
                else if (tag is AutoDocumentation.Table)
                {
                    CreateTable(section, tag as AutoDocumentation.Table, workingDirectory);
                }
                else if (tag is Graph)
                {
                    GraphPresenter graphPresenter = new GraphPresenter();
                    ExplorerPresenter.ApsimXFile.Links.Resolve(graphPresenter);
                    GraphView graphView = new GraphView();
                    graphView.BackColor = OxyPlot.OxyColors.White;
                    graphView.FontSize  = 12;
                    graphView.Width     = 500;
                    graphView.Height    = 500;
                    graphPresenter.Attach(tag, graphView, ExplorerPresenter);
                    string PNGFileName = graphPresenter.ExportToPDF(workingDirectory);
                    section.AddImage(PNGFileName);
                    string caption = (tag as Graph).Caption;
                    if (caption != null)
                    {
                        section.AddParagraph(caption);
                    }
                    graphPresenter.Detach();
                    graphView.MainWidget.Destroy();
                }
                else if (tag is Map && (tag as Map).GetCoordinates().Count > 0)
                {
                    MapPresenter mapPresenter = new MapPresenter();
                    MapView      mapView      = new MapView(null);
                    mapPresenter.Attach(tag, mapView, ExplorerPresenter);
                    string PNGFileName = mapPresenter.ExportToPDF(workingDirectory);
                    if (!String.IsNullOrEmpty(PNGFileName))
                    {
                        section.AddImage(PNGFileName);
                    }
                    mapPresenter.Detach();
                    mapView.MainWidget.Destroy();
                }
                else if (tag is AutoDocumentation.Image)
                {
                    AutoDocumentation.Image imageTag = tag as AutoDocumentation.Image;
                    if (imageTag.image.Width > 700)
                    {
                        imageTag.image = ImageUtilities.ResizeImage(imageTag.image, 700, 500);
                    }
                    string PNGFileName = Path.Combine(workingDirectory, imageTag.name);
                    imageTag.image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png);
                    section.AddImage(PNGFileName);
                    figureNumber++;
                }
                else if (tag is DirectedGraph)
                {
                    DirectedGraphPresenter presenter = new DirectedGraphPresenter();
                    ExplorerPresenter.ApsimXFile.Links.Resolve(presenter);
                    DirectedGraphView view = new DirectedGraphView();
                    presenter.Attach(new DirectedGraphContainer(tag as DirectedGraph), view, ExplorerPresenter);

                    Gtk.Window popupWin = new Gtk.Window(Gtk.WindowType.Popup);
                    popupWin.SetSizeRequest(800, 800);
                    // Move the window offscreen; the user doesn't need to see it.
                    // This works with IE, but not with WebKit
                    // Not yet tested on OSX
                    if (ProcessUtilities.CurrentOS.IsWindows)
                    {
                        popupWin.Move(-10000, -10000);
                    }
                    popupWin.Add(view.MainWidget);
                    popupWin.ShowAll();
                    while (Gtk.Application.EventsPending())
                    {
                        Gtk.Application.RunIteration();
                    }

                    string PNGFileName = presenter.ExportToPNG(workingDirectory);
                    section.AddImage(PNGFileName);
                    presenter.Detach();
                    view.MainWidget.Destroy();
                }
            }
        }
예제 #29
0
        /// <summary>Writes PDF for specified auto-doc commands.</summary>
        /// <param name="section">The writer to write to.</param>
        /// <param name="tags">The autodoc tags.</param>
        /// <param name="workingDirectory">The working directory.</param>
        private void TagsToMigraDoc(Section section, List <AutoDocumentation.ITag> tags, string workingDirectory)
        {
            foreach (AutoDocumentation.ITag tag in tags)
            {
                if (tag is AutoDocumentation.Heading)
                {
                    AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading;
                    if (heading.headingLevel > 0 && heading.headingLevel <= 6)
                    {
                        if (heading.headingLevel == 1)
                        {
                            section.AddPageBreak();
                        }

                        Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel);
                        if (heading.headingLevel == 1)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level1;
                        }
                        else if (heading.headingLevel == 2)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level2;
                        }
                        else if (heading.headingLevel == 3)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level3;
                        }
                        else if (heading.headingLevel == 4)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level4;
                        }
                        else if (heading.headingLevel == 5)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level5;
                        }
                        else if (heading.headingLevel == 6)
                        {
                            para.Format.OutlineLevel = OutlineLevel.Level6;
                        }
                    }
                }
                else if (tag is AutoDocumentation.Paragraph)
                {
                    AddFormattedParagraphToSection(section, tag as AutoDocumentation.Paragraph);
                }
                else if (tag is AutoDocumentation.GraphAndTable)
                {
                    CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory);
                }
                else if (tag is GraphPage)
                {
                    CreateGraphPage(section, tag as GraphPage, workingDirectory);
                }
                else if (tag is AutoDocumentation.NewPage)
                {
                    section.AddPageBreak();
                }
                else if (tag is AutoDocumentation.Table)
                {
                    CreateTable(section, tag as AutoDocumentation.Table, workingDirectory);
                }
                else if (tag is Graph)
                {
                    GraphPresenter graphPresenter = new GraphPresenter();
                    GraphView      graphView      = new GraphView();
                    graphView.BackColor = System.Drawing.Color.White;
                    graphView.FontSize  = 12;
                    graphView.Width     = 500;
                    graphView.Height    = 500;
                    graphPresenter.Attach(tag, graphView, ExplorerPresenter);
                    string PNGFileName = graphPresenter.ExportToPDF(workingDirectory);
                    section.AddImage(PNGFileName);
                    string caption = (tag as Graph).Caption;
                    if (caption != null)
                    {
                        section.AddParagraph(caption);
                    }
                    graphPresenter.Detach();
                }
                else if (tag is Map)
                {
                    Form f = new Form();
                    f.FormBorderStyle = FormBorderStyle.None;
                    f.Width           = 650; // 1100;
                    f.Height          = 600; // 600;
                    MapPresenter mapPresenter = new MapPresenter();
                    MapView      mapView      = new MapView();
                    mapView.BackColor         = System.Drawing.Color.White;
                    mapView.Parent            = f;
                    (mapView as Control).Dock = DockStyle.Fill;
                    f.Show();
                    (tag as Map).Zoom = 1.4;
                    mapPresenter.Attach(tag, mapView, ExplorerPresenter);

                    Application.DoEvents();
                    Thread.Sleep(2000);
                    Application.DoEvents();

                    string PNGFileName = mapPresenter.ExportToPDF(workingDirectory);
                    var    Image       = new Bitmap(f.Width, f.Height);
                    f.DrawToBitmap(Image, new Rectangle(0, 0, f.Width, f.Height));
                    Image.Save(PNGFileName);
                    section.AddImage(PNGFileName);
                    mapPresenter.Detach();

                    f.Close();
                }
                else if (tag is AutoDocumentation.Image)
                {
                    AutoDocumentation.Image imageTag = tag as AutoDocumentation.Image;
                    if (imageTag.image.Width > 700)
                    {
                        imageTag.image = ImageUtilities.ResizeImage(imageTag.image, 700, 500);
                    }
                    string PNGFileName = Path.Combine(workingDirectory, imageTag.name);
                    imageTag.image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png);
                    section.AddImage(PNGFileName);
                }
            }
        }
예제 #30
0
        /// <summary>
        /// Renders the element.
        /// </summary>
        /// <param name="pdfStyling">The PDF styling.</param>
        /// <param name="section">The section.</param>
        public void Render(IPdfStyling pdfStyling, Section section)
        {
            RenderList(section, _bookmarks);

            section.AddPageBreak();
        }