Exemplo n.º 1
0
        public static void GenerateSubject(WorkProgram wp)
        {
            foreach (var item in wp.bookmarks)
            {
                var format = new Xceed.Document.NET.Formatting();
                switch (item.Key)
                {
                case "Discipline":
                    format.Size = 14;
                    format.Bold = true;
                    break;

                case "Direction":
                    format.Size = 14;
                    break;

                case "Profile":
                    format.Size = 14;
                    break;

                default:
                    format.Size = 12;
                    break;
                }
                if (!string.IsNullOrEmpty(item.Value))
                {
                    template.Bookmarks[item.Key].SetText(item.Value, format);
                }
            }
            template.SaveAs(path);
        }
Exemplo n.º 2
0
        public static void AddInline(Inline inline, Xceed.Document.NET.Paragraph p, Xceed.Document.NET.Formatting inheritFormat = null)
        {
            if (inline is Run)
            {
                Run run = (Run)inline;
                Xceed.Document.NET.Formatting f = new Xceed.Document.NET.Formatting();
                Color c = (run.Foreground as SolidColorBrush).Color;
                f.FontColor  = System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B);
                f.FontFamily = new Xceed.Document.NET.Font(run.FontFamily.Source);
                if (run.FontWeight == FontWeights.Bold)
                {
                    f.Bold = true;
                }
                if (run.FontStyle == FontStyles.Italic)
                {
                    f.Italic = true;
                }
                foreach (var dec in run.TextDecorations)
                {
                    if (dec.Location == TextDecorationLocation.Underline)
                    {
                        f.UnderlineStyle = Xceed.Document.NET.UnderlineStyle.singleLine;
                        f.UnderlineColor = f.FontColor;
                    }
                }

                f.Size = run.FontSize;

                if (inheritFormat != null)
                {
                    f = inheritFormat;
                }

                p.Append(run.Text, f);
            }
            else if (inline is Span)
            {
                Span span = (Span)inline;

                Xceed.Document.NET.Formatting f = new Xceed.Document.NET.Formatting();
                Color c = (span.Foreground as SolidColorBrush).Color;
                f.FontColor  = System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B);
                f.FontFamily = new Xceed.Document.NET.Font(span.FontFamily.Source);
                if (span.FontWeight == FontWeights.Bold)
                {
                    f.Bold = true;
                }
                if (span.FontStyle == FontStyles.Italic)
                {
                    f.Italic = true;
                }
                foreach (var dec in span.TextDecorations)
                {
                    if (dec.Location == TextDecorationLocation.Underline)
                    {
                        f.UnderlineStyle = Xceed.Document.NET.UnderlineStyle.singleLine;
                        f.UnderlineColor = f.FontColor;
                    }
                }

                f.Size = span.FontSize;

                if (inheritFormat != null)
                {
                    f = inheritFormat;
                }

                foreach (var spanInline in span.Inlines)
                {
                    AddInline(spanInline, p, f);
                }
            }
        }
Exemplo n.º 3
0
        private void SaveReport(object sender, EventArgs e)
        {
            Bitmap bmpStats = DrawControlToBitMap(cartesianChart1);
            Bitmap bmpBar   = DrawControlToBitMap(cartesianChart2);

            cartesianChart1.DrawToBitmap(bmpStats, new Rectangle(0, 0, bmpStats.Width, bmpStats.Height));
            cartesianChart2.DrawToBitmap(bmpBar, new Rectangle(0, 0, bmpBar.Width, bmpBar.Height));
            foreach (var country in countries)
            {
                if (countryBox.Text == country)
                {
                    int    fontSize      = 12;
                    int    fontTitleSize = 16;
                    string font          = "Calibri";
                    bmpStats.Save($"{picturePath}{country}_stats.png", ImageFormat.Png);
                    bmpBar.Save($"{picturePath}{country}_bar.png", ImageFormat.Png);
                    var    doc   = DocX.Create($"{reportsPath}\\{country} Report.docx");
                    string title = $"{country} Covid-19 Report from {startDateBox.Text} to {endDateBox.Text}";

                    Xceed.Document.NET.Formatting titleFormat = new Xceed.Document.NET.Formatting();
                    titleFormat.FontFamily = new Xceed.Document.NET.Font(font);
                    titleFormat.Size       = fontTitleSize;

                    Xceed.Document.NET.Paragraph repTitle = doc.InsertParagraph(title, false, titleFormat);
                    repTitle.Alignment = Xceed.Document.NET.Alignment.center;

                    Xceed.Document.NET.Image   imgStats = doc.AddImage($"{picturePath}{country}_stats.png");
                    Xceed.Document.NET.Picture statsPic = imgStats.CreatePicture();
                    statsPic.Width  = 500;
                    statsPic.Height = 200;

                    Xceed.Document.NET.Paragraph statsPar = doc.InsertParagraph();
                    statsPar.AppendPicture(statsPic);

                    Xceed.Document.NET.Table table1 = doc.AddTable(3, 2);
                    table1.Alignment = Xceed.Document.NET.Alignment.center;

                    Xceed.Document.NET.Formatting table1Format = new Xceed.Document.NET.Formatting();
                    table1Format.FontFamily = new Xceed.Document.NET.Font(font);
                    table1Format.Size       = fontTitleSize;
                    doc.InsertParagraph("General Stats ", false, table1Format).Alignment = Xceed.Document.NET.Alignment.center;

                    Xceed.Document.NET.Image   imgBar = doc.AddImage($"{picturePath}{country}_bar.png");
                    Xceed.Document.NET.Picture barPic = imgBar.CreatePicture();
                    barPic.Width  = 200;
                    barPic.Height = 200;

                    Xceed.Document.NET.Paragraph barPar = doc.InsertParagraph();
                    barPar.AppendPicture(barPic).Alignment = Xceed.Document.NET.Alignment.center;

                    table1.Rows[0].Cells[0].Paragraphs.First().Append("Confirmed Cases: ").Font(font).FontSize(fontSize);
                    table1.Rows[1].Cells[0].Paragraphs.First().Append("Number of Recoveries: ").Font(font).FontSize(fontSize);
                    table1.Rows[2].Cells[0].Paragraphs.First().Append("Number of Deaths: ").Font(font).FontSize(fontSize);
                    table1.Rows[0].Cells[1].Paragraphs.First().Append(numConfirmed.ToString()).Font(font).FontSize(fontSize);
                    table1.Rows[1].Cells[1].Paragraphs.First().Append(numRecoveries.ToString()).Font(font).FontSize(fontSize);
                    table1.Rows[2].Cells[1].Paragraphs.First().Append(deathCount.ToString()).Font(font).FontSize(fontSize);
                    doc.InsertTable(table1);
                    doc.InsertParagraph(" ");

                    Xceed.Document.NET.Formatting table2Format = new Xceed.Document.NET.Formatting();
                    table2Format.FontFamily = new Xceed.Document.NET.Font(font);
                    table2Format.Size       = fontTitleSize;
                    doc.InsertParagraph($"Complete Stats of Covid-19 in {country}", false, table2Format).Alignment = Xceed.Document.NET.Alignment.left;
                    doc.InsertParagraph(" ");

                    Xceed.Document.NET.Table table2 = doc.AddTable(numRows, 7);
                    table2.Alignment = Xceed.Document.NET.Alignment.left;
                    table2.Rows[0].Cells[0].Paragraphs.First().Append("Dates").Font(font).FontSize(fontSize);
                    table2.Rows[0].Cells[1].Paragraphs.First().Append("Confirmed Cases").Font(font).FontSize(fontSize);
                    table2.Rows[0].Cells[2].Paragraphs.First().Append("Recoveries").Font(font).FontSize(fontSize);
                    table2.Rows[0].Cells[3].Paragraphs.First().Append("Deaths").Font(font).FontSize(fontSize);
                    table2.Rows[0].Cells[4].Paragraphs.First().Append("Number of Increase in Confirmed Cases").Font(font).FontSize(fontSize);
                    table2.Rows[0].Cells[5].Paragraphs.First().Append("Number of Increase in Recoveries").Font(font).FontSize(fontSize);
                    table2.Rows[0].Cells[6].Paragraphs.First().Append("Number of Increase in Deaths").Font(font).FontSize(fontSize);

                    foreach (var data in confirmed)
                    {
                        if (country == data.Key)
                        {
                            int i = 1;
                            foreach (var day in data.Value)
                            {
                                if (DateTime.Parse(startDateBox.Text) <= day.Key && DateTime.Parse(endDateBox.Text) >= day.Key)
                                {
                                    table2.Rows[i].Cells[0].Paragraphs.First().Append(day.Key.ToShortDateString()).Font(font).FontSize(fontSize);
                                    table2.Rows[i].Cells[1].Paragraphs.First().Append(day.Value.ToString()).Font(font).FontSize(fontSize);
                                    i++;
                                }
                            }
                        }
                    }

                    foreach (var data in recoveries)
                    {
                        if (country == data.Key)
                        {
                            int i = 1;
                            foreach (var day in data.Value)
                            {
                                if (DateTime.Parse(startDateBox.Text) <= day.Key && DateTime.Parse(endDateBox.Text) >= day.Key)
                                {
                                    table2.Rows[i].Cells[2].Paragraphs.First().Append(day.Value.ToString()).Font(font).FontSize(fontSize);
                                    i++;
                                }
                            }
                        }
                    }

                    foreach (var data in deaths)
                    {
                        if (country == data.Key)
                        {
                            int i = 1;
                            foreach (var day in data.Value)
                            {
                                if (DateTime.Parse(startDateBox.Text) <= day.Key && DateTime.Parse(endDateBox.Text) >= day.Key)
                                {
                                    table2.Rows[i].Cells[3].Paragraphs.First().Append(day.Value.ToString()).Font(font).FontSize(fontSize);
                                    i++;
                                }
                            }
                        }
                    }

                    foreach (var data in incConfirmed)
                    {
                        if (country == data.Key)
                        {
                            int i = 1;
                            foreach (var day in data.Value)
                            {
                                if (DateTime.Parse(startDateBox.Text) <= day.Key && DateTime.Parse(endDateBox.Text) >= day.Key)
                                {
                                    table2.Rows[i].Cells[4].Paragraphs.First().Append(day.Value.ToString()).Font(font).FontSize(fontSize);
                                    i++;
                                }
                            }
                        }
                    }

                    foreach (var data in incRecoveries)
                    {
                        if (country == data.Key)
                        {
                            int i = 1;
                            foreach (var day in data.Value)
                            {
                                if (DateTime.Parse(startDateBox.Text) <= day.Key && DateTime.Parse(endDateBox.Text) >= day.Key)
                                {
                                    table2.Rows[i].Cells[5].Paragraphs.First().Append(day.Value.ToString()).Font(font).FontSize(fontSize);
                                    i++;
                                }
                            }
                        }
                    }

                    foreach (var data in incDeaths)
                    {
                        if (country == data.Key)
                        {
                            int i = 1;
                            foreach (var day in data.Value)
                            {
                                if (DateTime.Parse(startDateBox.Text) <= day.Key && DateTime.Parse(endDateBox.Text) >= day.Key)
                                {
                                    table2.Rows[i].Cells[6].Paragraphs.First().Append(day.Value.ToString()).Font(font).FontSize(fontSize);
                                    i++;
                                }
                            }
                        }
                    }
                    table2.Alignment = Xceed.Document.NET.Alignment.left;
                    doc.InsertTable(table2);

                    doc.Save();
                    MessageBox.Show($"File saved at {reportsPath}\\{country} Report.docx.\nChoose either to Upload or Reset the Report", "Save Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            processBtn.Enabled   = false;
            saveBtn.Enabled      = false;
            uploadBtn.Enabled    = true;
            resetBtn.Enabled     = true;
            countryBox.Enabled   = false;
            startDateBox.Enabled = false;
            endDateBox.Enabled   = false;
        }