From fe89fc9399ec693fcd331cdd33868e6254c334b3 Mon Sep 17 00:00:00 2001
From: prodigygirl <Prodigygirl1.0@yandex.ru>
Date: Sun, 26 Mar 2023 09:42:14 +0400
Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?=
 =?UTF-8?q?=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BF=D0=BE?=
 =?UTF-8?q?=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D0=BF=D0=B8?=
 =?UTF-8?q?=D1=81=D0=BA=D0=B0=20Word?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../OfficePackage/AbstractSaveToWord.cs       | 72 ++++++++++++-------
 .../OfficePackage/HelperModels/WordInfo.cs    |  4 +-
 .../HelperModels/WordInfoFurnitures.cs        | 14 ++++
 .../HelperModels/WordInfoShops.cs             | 14 ++++
 .../OfficePackage/Implements/SaveToWord.cs    |  2 +-
 5 files changed, 78 insertions(+), 28 deletions(-)
 create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfoFurnitures.cs
 create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfoShops.cs

diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs
index 663713d..557dce7 100644
--- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs
+++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs
@@ -9,26 +9,46 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage
     {
         public void CreateTableDoc(WordInfo wordInfo) {
             CreateWord(wordInfo);
-            var list = new List<string>();
-            foreach (var shop in wordInfo.Shops) {
-                list.Add(shop.ShopName);
-                list.Add(shop.Address);
-                list.Add(shop.DateOpening.ToString());
-            }
-            //list.AddRange(wordInfo.Shops.Select(x => (x.ShopName, new WordTextProperties { Bold = true, Size = "24" })));
-            var wordTable = new WordTable
+            CreateParagraph(new WordParagraph
             {
-                Headers = new List<string> { 
-                    "Название", 
-                    "Адрес", 
-                    "Дата открытия"},
-                Texts = list
-            };
+                Texts = new List<(string, WordTextProperties)> { (wordInfo.Title, new WordTextProperties { Bold = true, Size = "24", }) },
+                TextProperties = new WordTextProperties
+                {
+                    Size = "24",
+                    JustificationType = WordJustificationType.Center
+                }
+            });
+            WordTable wordTable = new();
+            if (wordInfo is WordInfoShops infoShops)
+            {
+                wordTable = CreateTableDocShops(infoShops);
+            }
             CreateTable(wordTable);
 
             SaveWord(wordInfo);
 
         }
+        private WordTable CreateTableDocShops(WordInfoShops wordInfo)
+        {
+            var list = new List<string>();
+            foreach (var shop in wordInfo.Shops)
+            {
+                list.Add(shop.ShopName);
+                list.Add(shop.Address);
+                list.Add(shop.DateOpening.ToString());
+            }
+
+            var wordTable = new WordTable
+            {
+                Headers = new List<string> {
+                    "Название",
+                    "Адрес",
+                    "Дата открытия"},
+                Texts = list
+            };
+            return wordTable;
+        }
+
         public void CreateDoc(WordInfo info)
         {
             CreateWord(info);
@@ -41,18 +61,22 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage
                     JustificationType = WordJustificationType.Center
                 }
             });
-            foreach (var furniture in info.Furnitures)
-            {
-                CreateParagraph(new WordParagraph
-                {
-                    Texts = new List<(string, WordTextProperties)> { (furniture.FurnitureName, new WordTextProperties { Size = "24", Bold=true}), (" - " + furniture.Price.ToString(), new WordTextProperties { Size = "24", }) },
-                    TextProperties = new WordTextProperties
+            if (info is WordInfoFurnitures infoFurnitures) { 
+                foreach (var furniture in infoFurnitures.Furnitures)
                     {
-                        Size = "24",
-                        JustificationType = WordJustificationType.Both
-                    }
-                });
+                        CreateParagraph(new WordParagraph
+                        {
+                            Texts = new List<(string, WordTextProperties)> { (furniture.FurnitureName, 
+                            new WordTextProperties { Size = "24", Bold=true}), (" - " + furniture.Price.ToString(), 
+                            new WordTextProperties { Size = "24", }) },
+                            TextProperties = new WordTextProperties
+                            {
+                                Size = "24",
+                                JustificationType = WordJustificationType.Both
+                            }
+                        });
                 
+                    }
             }
             SaveWord(info);
         }
diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs
index 16bfb63..828646f 100644
--- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs
+++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs
@@ -5,8 +5,6 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels
     public class WordInfo
     {
         public string FileName { get; set; } = string.Empty;
-        public string Title { get; set; } = string.Empty;
-        public List<FurnitureViewModel> Furnitures { get; set; } = new();
-        public List<ShopViewModel> Shops { get; set; } = new();
+        public string Title { get; set; } = string.Empty;        
     }
 }
diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfoFurnitures.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfoFurnitures.cs
new file mode 100644
index 0000000..7866136
--- /dev/null
+++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfoFurnitures.cs
@@ -0,0 +1,14 @@
+using FurnitureAssemblyContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels
+{
+    public class WordInfoFurnitures : WordInfo
+    {
+        public List<FurnitureViewModel> Furnitures { get; set; } = new();
+    }
+}
diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfoShops.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfoShops.cs
new file mode 100644
index 0000000..9deb087
--- /dev/null
+++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfoShops.cs
@@ -0,0 +1,14 @@
+using FurnitureAssemblyContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels
+{
+    public class WordInfoShops : WordInfo
+    {
+        public List<ShopViewModel> Shops { get; set; } = new();
+    }
+}
diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs
index 6ad4043..7b08741 100644
--- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs
+++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs
@@ -196,7 +196,7 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements
         }
 
         private TableCell CreateTableCell(string element) {
-            var tableParagraph = new Paragraph();
+            var tableParagraph = new Paragraph();           
             var run = new Run();
             run.AppendChild(new Text { Text = element });
             tableParagraph.AppendChild(run);