From 71bf37ebc836171372e6192cdc5376b7a1dc95c5 Mon Sep 17 00:00:00 2001
From: antoc0der <1@DESKTOP-K1L8ND3>
Date: Tue, 26 Mar 2024 17:10:28 +0400
Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?=
=?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8E=20?=
=?UTF-8?q?=D0=BF=D0=B4=D1=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../FlowerShopBusinessLogic.csproj | 1 +
.../HelperModels/PdfParagraph.cs | 1 +
.../HelperModels/PdfRowParametres.cs | 1 +
.../OfficePackage/Implements/SaveToPdf.cs | 107 ++++++++++++++++++
.../FlowerShopContracts.csproj | 1 +
.../FlowerShopDataModels.csproj | 1 +
.../FlowerShopDatabaseImplement.csproj | 1 +
.../FlowerShopFileImplement.csproj | 1 +
.../FlowerShopListImplement.csproj | 1 +
ProjectFlowerShop/ProjectFlowerShop.csproj | 1 +
10 files changed, 116 insertions(+)
create mode 100644 FlowerShopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs
diff --git a/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj b/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj
index 9edf3a6..762007e 100644
--- a/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj
+++ b/FlowerShopBusinessLogic/FlowerShopBusinessLogic.csproj
@@ -9,6 +9,7 @@
+
diff --git a/FlowerShopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/FlowerShopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs
index 33c0a55..a8a47bc 100644
--- a/FlowerShopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs
+++ b/FlowerShopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using FlowerShopBusinessLogic.OfficePackage.HelperEnums;
namespace FlowerShopBusinessLogic.OfficePackage.HelperModels
{
diff --git a/FlowerShopBusinessLogic/OfficePackage/HelperModels/PdfRowParametres.cs b/FlowerShopBusinessLogic/OfficePackage/HelperModels/PdfRowParametres.cs
index bfcbeff..be5e5e9 100644
--- a/FlowerShopBusinessLogic/OfficePackage/HelperModels/PdfRowParametres.cs
+++ b/FlowerShopBusinessLogic/OfficePackage/HelperModels/PdfRowParametres.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using FlowerShopBusinessLogic.OfficePackage.HelperEnums;
namespace FlowerShopBusinessLogic.OfficePackage.HelperModels
{
diff --git a/FlowerShopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/FlowerShopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs
new file mode 100644
index 0000000..23c13c3
--- /dev/null
+++ b/FlowerShopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs
@@ -0,0 +1,107 @@
+
+using FlowerShopBusinessLogic.OfficePackage.HelperEnums;
+using FlowerShopBusinessLogic.OfficePackage.HelperModels;
+using MigraDoc.DocumentObjectModel;
+using MigraDoc.DocumentObjectModel.Tables;
+using MigraDoc.Rendering;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FlowerShopBusinessLogic.OfficePackage.Implements
+{
+ public class SaveToPdf : AbstractSaveToPdf
+ {
+ private Document? _document;
+ private Section? _section;
+ private Table? _table;
+ private static ParagraphAlignment
+ GetParagraphAlignment(PdfParagraphAlignmentType type)
+ {
+ return type switch
+ {
+ PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
+ PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
+ PdfParagraphAlignmentType.Right => ParagraphAlignment.Right,
+ _ => ParagraphAlignment.Justify,
+ };
+ }
+ ///
+ /// Создание стилей для документа
+ ///
+ ///
+ private static void DefineStyles(Document document)
+ {
+ var style = document.Styles["Normal"];
+ style.Font.Name = "Times New Roman";
+ style.Font.Size = 14;
+ style = document.Styles.AddStyle("NormalTitle", "Normal");
+ style.Font.Bold = true;
+ }
+ protected override void CreatePdf(PdfInfo info)
+ {
+ _document = new Document();
+ DefineStyles(_document);
+ _section = _document.AddSection();
+ }
+ protected override void CreateParagraph(PdfParagraph pdfParagraph)
+ {
+ if (_section == null)
+ {
+ return;
+ }
+ var paragraph = _section.AddParagraph(pdfParagraph.Text);
+ paragraph.Format.SpaceAfter = "1cm";
+ paragraph.Format.Alignment =
+ GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
+ paragraph.Style = pdfParagraph.Style;
+ }
+ protected override void CreateTable(List columns)
+ {
+ if (_document == null)
+ {
+ return;
+ }
+ _table = _document.LastSection.AddTable();
+ foreach (var elem in columns)
+ {
+ _table.AddColumn(elem);
+ }
+ }
+ protected override void CreateRow(PdfRowParameters rowParameters)
+ {
+ if (_table == null)
+ {
+ return;
+ }
+ var row = _table.AddRow();
+ for (int i = 0; i < rowParameters.Texts.Count; ++i)
+ {
+ row.Cells[i].AddParagraph(rowParameters.Texts[i]);
+ if (!string.IsNullOrEmpty(rowParameters.Style))
+ {
+ row.Cells[i].Style = rowParameters.Style;
+ }
+ Unit borderWidth = 0.5;
+ row.Cells[i].Borders.Left.Width = borderWidth;
+ row.Cells[i].Borders.Right.Width = borderWidth;
+ row.Cells[i].Borders.Top.Width = borderWidth;
+ row.Cells[i].Borders.Bottom.Width = borderWidth;
+ row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
+ row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
+ }
+ }
+ protected override void SavePdf(PdfInfo info)
+ {
+ var renderer = new PdfDocumentRenderer(true)
+ {
+ Document = _document
+ };
+ renderer.RenderDocument();
+ renderer.PdfDocument.Save(info.FileName);
+ }
+ }
+
+}
diff --git a/FlowerShopContracts/FlowerShopContracts.csproj b/FlowerShopContracts/FlowerShopContracts.csproj
index 0da3f46..c4f7d06 100644
--- a/FlowerShopContracts/FlowerShopContracts.csproj
+++ b/FlowerShopContracts/FlowerShopContracts.csproj
@@ -9,6 +9,7 @@
+
diff --git a/FlowerShopDataModels/FlowerShopDataModels.csproj b/FlowerShopDataModels/FlowerShopDataModels.csproj
index da2f558..bf4416c 100644
--- a/FlowerShopDataModels/FlowerShopDataModels.csproj
+++ b/FlowerShopDataModels/FlowerShopDataModels.csproj
@@ -9,6 +9,7 @@
+
diff --git a/FlowerShopDatabaseImplement/FlowerShopDatabaseImplement.csproj b/FlowerShopDatabaseImplement/FlowerShopDatabaseImplement.csproj
index ba493d6..a09130b 100644
--- a/FlowerShopDatabaseImplement/FlowerShopDatabaseImplement.csproj
+++ b/FlowerShopDatabaseImplement/FlowerShopDatabaseImplement.csproj
@@ -14,6 +14,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/FlowerShopFileImplement/FlowerShopFileImplement.csproj b/FlowerShopFileImplement/FlowerShopFileImplement.csproj
index a2d5f45..c181cd2 100644
--- a/FlowerShopFileImplement/FlowerShopFileImplement.csproj
+++ b/FlowerShopFileImplement/FlowerShopFileImplement.csproj
@@ -8,6 +8,7 @@
+
diff --git a/FlowerShopListImplement/FlowerShopListImplement.csproj b/FlowerShopListImplement/FlowerShopListImplement.csproj
index a2d5f45..c181cd2 100644
--- a/FlowerShopListImplement/FlowerShopListImplement.csproj
+++ b/FlowerShopListImplement/FlowerShopListImplement.csproj
@@ -8,6 +8,7 @@
+
diff --git a/ProjectFlowerShop/ProjectFlowerShop.csproj b/ProjectFlowerShop/ProjectFlowerShop.csproj
index e7c6257..40c73e5 100644
--- a/ProjectFlowerShop/ProjectFlowerShop.csproj
+++ b/ProjectFlowerShop/ProjectFlowerShop.csproj
@@ -16,6 +16,7 @@
+