diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs index f4f1705..663713d 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -1,4 +1,5 @@ -using FurnitureAssemblyBusinessLogic.OfficePackage.HelperEnums; +using DocumentFormat.OpenXml.EMMA; +using FurnitureAssemblyBusinessLogic.OfficePackage.HelperEnums; using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels; @@ -6,6 +7,28 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage { public abstract class AbstractSaveToWord { + public void CreateTableDoc(WordInfo wordInfo) { + CreateWord(wordInfo); + var list = new List(); + 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 + { + Headers = new List { + "Название", + "Адрес", + "Дата открытия"}, + Texts = list + }; + CreateTable(wordTable); + + SaveWord(wordInfo); + + } public void CreateDoc(WordInfo info) { CreateWord(info); @@ -38,6 +61,7 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage /// /// protected abstract void CreateWord(WordInfo info); + protected abstract void CreateTable(WordTable info); /// /// Создание абзаца с текстом /// diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index 73ebd4d..16bfb63 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -7,5 +7,6 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List Furnitures { get; set; } = new(); + public List Shops { get; set; } = new(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordTable.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordTable.cs new file mode 100644 index 0000000..d5f0c1a --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordTable.cs @@ -0,0 +1,12 @@ + + +using FurnitureAssemblyContracts.ViewModels; + +namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels +{ + public class WordTable + { + public List Headers { get; set; } = new(); + public List Texts { get; set; } = new (); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 51af240..6ad4043 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -3,6 +3,7 @@ using FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; +using System.Xml.Linq; namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements { @@ -122,5 +123,86 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements _wordDocument.MainDocumentPart!.Document.Save(); _wordDocument.Close(); } + + protected override void CreateTable(WordTable table) + { + if (_docBody == null || table == null) + { + return; + } + Table tab = new Table(); + TableProperties props = new TableProperties( + new TableBorders( + new TopBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + } + ) + ); + tab.AppendChild(props); + // разметка сетки таблицы + TableGrid tableGrid = new TableGrid(); + for (int i = 0; i < table.Headers.Count; i++) { + tableGrid.AppendChild(new GridColumn ()); + } + tab.AppendChild(tableGrid); + TableRow tableRow = new TableRow(); + // заполнение заголовков + foreach (var text in table.Headers) + { + tableRow.AppendChild(CreateTableCell(text)); + } + tab.AppendChild(tableRow); + // заполнение содержимым + int height = table.Texts.Count / table.Headers.Count; + int width = table.Headers.Count; + for (int i = 0; i < height; i++) { + tableRow = new TableRow(); + for (int j = 0; j < width; j++) { + var element = table.Texts[i * table.Headers.Count + j]; + tableRow.AppendChild(CreateTableCell(element)); + } + tab.AppendChild(tableRow); + } + + _docBody.AppendChild(tab); + + } + + private TableCell CreateTableCell(string element) { + var tableParagraph = new Paragraph(); + var run = new Run(); + run.AppendChild(new Text { Text = element }); + tableParagraph.AppendChild(run); + var tableCell = new TableCell(); + tableCell.AppendChild(tableParagraph); + return tableCell; + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/ReportLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/ReportLogic.cs index a995780..b93f9a6 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/ReportLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/ReportLogic.cs @@ -17,17 +17,19 @@ namespace FurnitureAssemblyBusinessLogic { private readonly IFurnitureStorage _furnitureStorage; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; public ReportLogic(IFurnitureStorage furnitureStorage, IOrderStorage orderStorage, - AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf, IShopStorage shopStorage) { _furnitureStorage = furnitureStorage; _orderStorage = orderStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; + _shopStorage = shopStorage; } /// /// Получение списка компонент с указанием, в каких изделиях используются @@ -88,7 +90,7 @@ namespace FurnitureAssemblyBusinessLogic Title = "Список изделий", Furnitures = _furnitureStorage.GetFullList() }); - } + } /// /// Сохранение компонент с указаеним продуктов в файл-Excel /// @@ -117,5 +119,18 @@ namespace FurnitureAssemblyBusinessLogic Orders = GetOrders(model) }); } + /// + /// Сохранение магазинов в файл-Word + /// + /// + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateTableDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IReportLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IReportLogic.cs index 45ec909..eff1f58 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IReportLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContarcts/IReportLogic.cs @@ -31,5 +31,6 @@ namespace FurnitureAssemblyContracts.BusinessLogicsContarcts /// /// void SaveOrdersToPdfFile(ReportBindingModel model); + void SaveShopsToWordFile(ReportBindingModel model); } }