Пример #1
0
        public static void WriteSellsJournal(int Rows, IEnumerable <Продажа_Поля> Ebumba)
        {
            string path = Environment.CurrentDirectory + "\\Отчет о продажах.docx";
            List <Продажа_Поля> list = Ebumba.ToList();

            using (DocX document = DocX.Create("Отчет о продажах.docx"))
            {
                document.InsertParagraph("Отчет о продажах").FontSize(15d);
                document.InsertParagraph($"Дата создания: \"{DateTime.Now}\"");

                #region WriteTable
                Xceed.Document.NET.Table table = document.AddTable(Rows, 4);
                for (int i = 0; i < list.Count + 1; i++)
                {
                    if (i == 0)
                    {
                        table.Rows[i].Cells[0].Paragraphs[0].Append("Клиент").Bold().Alignment            = Xceed.Document.NET.Alignment.center;
                        table.Rows[i].Cells[1].Paragraphs[0].Append("Модель").Bold().Alignment            = Xceed.Document.NET.Alignment.center;
                        table.Rows[i].Cells[2].Paragraphs[0].Append("Дата приобретения").Bold().Alignment = Xceed.Document.NET.Alignment.center;
                        table.Rows[i].Cells[3].Paragraphs[0].Append("Стоимость").Bold().Alignment         = Xceed.Document.NET.Alignment.center;
                    }
                    else
                    {
                        table.InsertRow();
                        table.Rows[i].Cells[0].Paragraphs[0].Append(list[i - 1].ID_Клиента.ToString());
                        table.Rows[i].Cells[1].Paragraphs[0].Append(list[i - 1].ID_Модели.ToString());
                        table.Rows[i].Cells[2].Paragraphs[0].Append(list[i - 1].Дата_продажи_DataGridView.ToString());
                        table.Rows[i].Cells[3].Paragraphs[0].Append(list[i - 1].Сумма_продажи.ToString());
                    }
                }
                document.InsertParagraph().InsertTableAfterSelf(table);
                #endregion

                document.Save();
            }
            System.Diagnostics.Process.Start(path);
        }
Пример #2
0
        //##############################################################################################################################################################################################

        /// <summary>
        /// Convert the .csv files to documents
        /// </summary>
        private async void ConvertCsvToDoc()
        {
            // Check if template file exists
            if (!System.IO.File.Exists(TemplatePath))
            {
                await _dialogCoordinator.ShowMessageAsync(this, "Fehler", "Das Template wurde nicht gefunden: " + Environment.NewLine + TemplatePath);

                return;
            }
            if (System.IO.Path.GetExtension(TemplatePath).ToLower() != ".docx")
            {
                await _dialogCoordinator.ShowMessageAsync(this, "Fehler", "Das Template hat das falsche Format (nur *.docx erlaubt): " + Environment.NewLine + TemplatePath);

                return;
            }
            if (!System.IO.File.Exists(MappingCsvFilePath))
            {
                await _dialogCoordinator.ShowMessageAsync(this, "Fehler", "Die Mapping Datei wurde nicht gefunden: " + Environment.NewLine + TemplatePath);

                return;
            }

            int convertedFilesCnt = 0;

            // Loop over all .csv files
            foreach (string csvFilePath in CsvFilePaths)
            {
                // Check if .csv file exists
                if (!System.IO.File.Exists(csvFilePath))
                {
                    await _dialogCoordinator.ShowMessageAsync(this, "Fehler", "Die CSV Datei wurde nicht gefunden: " + Environment.NewLine + csvFilePath);

                    continue;
                }

                CsvFile csv_file = new CsvFile(csvFilePath, DelimiterCharacter);

                // Accept all .csv file header names as placeholders
                CsvMappingFile MappingFile = new CsvMappingFile(MappingCsvFilePath, DelimiterCharacter);
                if (MappingFile.Mappings == null)
                {
                    await _dialogCoordinator.ShowMessageAsync(this, "Fehler", "Es gibt Fehler in der Mapping Datei.");

                    return;
                }
                MappingFile.AddMappingsForDataCsvHeader(csv_file);

                using (DocX templateDoc = DocX.Load(TemplatePath))
                {
                    Xceed.Document.NET.Table templateDocTable = templateDoc.Tables.FirstOrDefault();
                    if (templateDocTable == null)
                    {
                        await _dialogCoordinator.ShowMessageAsync(this, "Fehler", "Im Template wurde keine Tabelle gefunden.");

                        return;
                    }
                    if (templateDocTable.RowCount <= 1)
                    {
                        await _dialogCoordinator.ShowMessageAsync(this, "Fehler", "Die Tabelle im Template muss 2 Zeilen haben.");

                        return;
                    }
                    Xceed.Document.NET.Row rowPattern = templateDocTable.Rows[1];       // Get the row pattern of the second row (the first row contains the headers).

                    // Add the general informations to the document. This are the rows above the real CSV table.
                    foreach (KeyValuePair <string, string> generalInfoMapping in MappingFile.Mappings.Where(m => m.Value.StartsWith(CsvMappingFile.GENERAL_INFOS_MARKER_PART)))
                    {
                        string replacementText     = "";
                        string generalInfoIndexStr = generalInfoMapping.Value.Replace(CsvMappingFile.GENERAL_INFOS_MARKER_PART, "").Replace("%", "");
                        if (string.IsNullOrEmpty(generalInfoIndexStr))
                        {
                            replacementText = csv_file.AllCsvFileDescriptionRows;
                        }
                        else
                        {
                            int generalInfoIndex = -1;
                            if (!int.TryParse(generalInfoIndexStr, out generalInfoIndex))
                            {
                                await _dialogCoordinator.ShowMessageAsync(this, "Fehler", "Der Index (\"" + generalInfoIndexStr + "\") für die Beschreibungszeilen kann nicht geparst werden.");

                                continue;
                            }
                            if (generalInfoIndex <= 0 || generalInfoIndex > csv_file.CsvFileDescriptionRows.Count)
                            {
                                await _dialogCoordinator.ShowMessageAsync(this, "Fehler", "Der Index (" + generalInfoIndex.ToString() + ") für die Beschreibungszeilen ist außerhalb des gültigen Bereiches (1.." + csv_file.CsvFileDescriptionRows.Count.ToString() + ").");

                                continue;
                            }

                            replacementText = csv_file.CsvFileDescriptionRows[generalInfoIndex - 1];
                        }
                        templateDoc.ReplaceText(generalInfoMapping.Key, replacementText);
                    }

                    // Insert csv content to table
                    foreach (CsvFileLine fileLine in csv_file.CsvFileLines)
                    {
                        Xceed.Document.NET.Row newRow = templateDocTable.InsertRow(rowPattern, templateDocTable.RowCount - 1);      // Insert new row at the end of the table
                        foreach (KeyValuePair <string, string> mappingPair in MappingFile.Mappings)
                        {
                            if (!mappingPair.Value.StartsWith(CsvMappingFile.GENERAL_INFOS_MARKER_PART))
                            {
                                CsvFileLineElement lineElement = fileLine?.LineElements?.Where(element => element.CorrespondingHeader == mappingPair.Value)?.FirstOrDefault();
                                newRow.ReplaceText(mappingPair.Key, lineElement == null ? "" : lineElement.Value);
                            }
                        }
                    }

                    // Remove the pattern row.
                    rowPattern.Remove();

                    templateDoc.SaveAs(System.IO.Path.ChangeExtension(csv_file.FilePath, null) + System.IO.Path.GetExtension(TemplatePath));
                    convertedFilesCnt++;
                }
            }
            await _dialogCoordinator.ShowMessageAsync(this, "Fertig", convertedFilesCnt.ToString() + " von " + CsvFilePaths.Count.ToString() + " CSV Datei(en) wurde(n) erfolgreich in Dokument(e) umgewandelt.");
        }
Пример #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;
        }