diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs index 677fa4a..fb5f831 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs @@ -73,7 +73,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic return list; } - public byte[] SavePaymeantToExcelFile(ReportBindingModel? model, int _clientID) + public byte[] SavePaymeantToExcelFile(int _clientID) { var document = _saveToExcel.CreateReport(new ExcelInfoClient { @@ -83,14 +83,13 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic return document; } - public void SavePaymeantToWordFile(ReportBindingModel model) + public byte[] SavePaymeantToWordFile(int _clientID) { - _saveToWord.CreateDoc(new WordInfoClient - { - //FileName = model.ProductName, + var document = _saveToWord.CreateDoc(new WordInfoClient { Title = "Список оплат", - ListPaymeant = _paymeantstorage.GetFullList(), - }) ; + ListPaymeant = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID }), + }); + return document; } } } \ No newline at end of file diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs index 7a4c20f..b13ae29 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToExcelClient.cs @@ -7,7 +7,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage { public abstract class AbstractSaveToExcelClient { - public byte[] CreateReport(ExcelInfoClient info) { + public byte[]? CreateReport(ExcelInfoClient info) { CreateExcel(info); InsertCellInWorksheet(new ExcelCellParameters { @@ -76,6 +76,6 @@ namespace ElectronicsShopBusinessLogic.OfficePackage protected abstract void MergeCells(ExcelMergeParameters excelParams); // Сохранение файла - protected abstract byte[] SaveExcel(ExcelInfoClient info); + protected abstract byte[]? SaveExcel(ExcelInfoClient info); } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToWordClient.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToWordClient.cs index d390f0a..0e2b0bd 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToWordClient.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/AbstractSaveToWordClient.cs @@ -10,7 +10,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage { public abstract class AbstractSaveToWordClient { - public void CreateDoc(WordInfoClient info) + public byte[]? CreateDoc(WordInfoClient info) { CreateWord(info); @@ -49,26 +49,17 @@ namespace ElectronicsShopBusinessLogic.OfficePackage }); } - SaveWord(info); + var document = SaveWord(info); + return document; } - /// - /// Создание doc-файла - /// - /// + // Создание doc-файла protected abstract void CreateWord(WordInfoClient info); - /// - /// Создание абзаца с текстом - /// - /// - /// + // Создание абзаца с текстом protected abstract void CreateParagraph(WordParagraph paragraph); - /// - /// Сохранение файла - /// - /// - protected abstract void SaveWord(WordInfoClient info); + // Сохранение файла + protected abstract byte[]? SaveWord(WordInfoClient info); } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/Implements/SaveToExcelClient.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/Implements/SaveToExcelClient.cs index c3d4cd2..d00382c 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/Implements/SaveToExcelClient.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/Implements/SaveToExcelClient.cs @@ -275,7 +275,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements mergeCells.Append(mergeCell); } - protected override byte[] SaveExcel(ExcelInfoClient info) + protected override byte[]? SaveExcel(ExcelInfoClient info) { if (_spreadsheetDocument == null) { diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/Implements/SaveToWordClient.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/Implements/SaveToWordClient.cs index c741531..d474f15 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/Implements/SaveToWordClient.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/OfficePackage/Implements/SaveToWordClient.cs @@ -12,11 +12,9 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements private Body? _docBody; - /// - /// Получение типа выравнивания - /// - /// - /// + private MemoryStream _mem = new MemoryStream(); + + // Получение типа выравнивания private static JustificationValues GetJustificationValues(WordJustificationType type) { return type switch @@ -27,10 +25,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements }; } - /// - /// Настройки страницы - /// - /// + // Настройки страницы private static SectionProperties CreateSectionProperties() { var properties = new SectionProperties(); @@ -45,11 +40,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements return properties; } - /// - /// Задание форматирования для абзаца - /// - /// - /// + // Задание форматирования для абзаца private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) { if (paragraphProperties == null) @@ -83,7 +74,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements protected override void CreateWord(WordInfoClient info) { - _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); + _wordDocument = WordprocessingDocument.Create(_mem, WordprocessingDocumentType.Document); MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); mainPart.Document = new Document(); _docBody = mainPart.Document.AppendChild(new Body()); @@ -119,17 +110,19 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements _docBody.AppendChild(docParagraph); } - protected override void SaveWord(WordInfoClient info) + protected override byte[]? SaveWord(WordInfoClient info) { if (_docBody == null || _wordDocument == null) { - return; + return null; } _docBody.AppendChild(CreateSectionProperties()); _wordDocument.MainDocumentPart!.Document.Save(); _wordDocument.Dispose(); + + return _mem.ToArray(); } } } diff --git a/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IReportClientLogic.cs b/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IReportClientLogic.cs index 39f65f6..b3b8662 100644 --- a/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IReportClientLogic.cs +++ b/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IReportClientLogic.cs @@ -15,9 +15,9 @@ namespace ElectronicsShopContracts.BusinessLogicContracts List GetPaymeantProducts(int _clientID); // получения списка оплат List GetPaymeants(ReportBindingModel model); - void SavePaymeantToWordFile(ReportBindingModel model); + byte[] SavePaymeantToWordFile(int _clientID); // Сохранение компонент с указанием отчета в .excel - byte[] SavePaymeantToExcelFile(ReportBindingModel? model, int _clientID); + byte[] SavePaymeantToExcelFile(int _clientID); } } diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs index d3901d5..8bce23e 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs @@ -98,7 +98,19 @@ namespace ElectronicsShopRestAPI.Controllers { [HttpGet] public byte[] CreateXlsxReport (int _clientID) { try { - var document = _reportLogic.SavePaymeantToExcelFile (null, _clientID); + var document = _reportLogic.SavePaymeantToExcelFile (_clientID); + return document; + } + catch (Exception ex) { + _logger.LogError(ex, $"Ошибка создания файла"); + throw; + } + } + + [HttpGet] + public byte[] CreateDocxReport (int _clientID) { + try { + var document = _reportLogic.SavePaymeantToWordFile (_clientID); return document; } catch (Exception ex) { diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs index 9cdde4c..2e8edd4 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs @@ -313,7 +313,23 @@ namespace ElectronicsShopUserApp.Controllers { [HttpGet] public IActionResult CreateExcelReport() { var fileMemStream = APIClient.GetRequset($"api/Client/CreateXlsxReport?_clientID={APIClient.Client.ID}"); + + if (fileMemStream == null) { + throw new Exception(" "); + } + return File(fileMemStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Report.xlsx"); } + + [HttpGet] + public IActionResult CreateWordReport() { + var fileMemStream = APIClient.GetRequset($"api/client/CreateDocxReport?_clientID={APIClient.Client.ID}"); + + if (fileMemStream == null) { + throw new Exception(" "); + } + + return File(fileMemStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Report.docx"); + } } } \ No newline at end of file diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/ReportSearch.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/ReportSearch.cshtml index 20fe908..2d5f000 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/ReportSearch.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/ReportSearch.cshtml @@ -25,9 +25,9 @@