From d80e620e9a1a2420b99a1d6e25096e56fd2f6803 Mon Sep 17 00:00:00 2001 From: Yourdax Date: Tue, 27 Aug 2024 16:30:25 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BE=D1=82=D1=87=D0=B5=D1=82=D1=8B=20=D0=B2=20Word\Excel,=20?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B0=D0=BB=D1=81=D1=8F=20pdf=20=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=BF=D0=BE=D1=87=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ReportLogic.cs | 8 +-- .../OfficePackage/AbstractSaveToExcel.cs | 16 ----- .../OfficePackage/AbstractSaveToWord.cs | 3 +- .../BindingModels/ReportBindingModel.cs | 7 +- .../BusinessLogicContracts/IReportLogic.cs | 4 +- .../SearchModels/ComponentSearchModel.cs | 2 +- .../Controllers/MainController.cs | 35 +++++++++- .../Controllers/HomeController.cs | 69 ++++++++++--------- 8 files changed, 80 insertions(+), 64 deletions(-) diff --git a/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/ReportLogic.cs b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/ReportLogic.cs index 3493045..31caa04 100644 --- a/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/ReportLogic.cs +++ b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/ReportLogic.cs @@ -49,23 +49,23 @@ namespace DiningRoomBusinessLogic.BusinessLogic }); } - public void SaveReportToWordFile(ReportBindingModel Model, List selectedComponents) + public void SaveReportToWordFile(ReportBindingModel Model) { _saveToWord.CreateDoc(new WordInfo { FileName = Model.FileName, Title = "Список изделий", - ProductComponents = GetReportComponentsWithOrders(selectedComponents) + ProductComponents = GetReportComponentsWithOrders(Model.selectedComponents) }); } - public void SaveReportToExcelFile(ReportBindingModel Model, List selectedComponents) + public void SaveReportToExcelFile(ReportBindingModel Model) { _saveToExcel.CreateReport(new ExcelInfo { FileName = Model.FileName, Title = "Список изделий", - ProductComponents = GetReportComponentsWithOrders(selectedComponents) + ProductComponents = GetReportComponentsWithOrders(Model.selectedComponents) }); } } diff --git a/DiningRoom/DiningRoomBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/DiningRoom/DiningRoomBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index b2908c4..25de5b3 100644 --- a/DiningRoom/DiningRoomBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/DiningRoom/DiningRoomBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -32,14 +32,6 @@ namespace DiningRoomBusinessLogic.OfficePackage StyleInfo = ExcelStyleInfoType.Title }); - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "C", - RowIndex = 1, - Text = "Количество блюд в заказе", - StyleInfo = ExcelStyleInfoType.Title - }); - uint rowIndex = 2; // Группируем компоненты по названию @@ -71,14 +63,6 @@ namespace DiningRoomBusinessLogic.OfficePackage StyleInfo = ExcelStyleInfoType.TextWithBroder }); - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "C", - RowIndex = rowIndex, - Text = item.ProductCount.ToString(), - StyleInfo = ExcelStyleInfoType.TextWithBroder - }); - rowIndex++; } diff --git a/DiningRoom/DiningRoomBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/DiningRoom/DiningRoomBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 6e6d25d..faba2a0 100644 --- a/DiningRoom/DiningRoomBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/DiningRoom/DiningRoomBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -46,8 +46,7 @@ namespace DiningRoomBusinessLogic.OfficePackage CreateParagraph(new WordParagraph { Texts = new List<(string, WordTextProperties)> { - ("Количество блюд в заказе - "+Convert.ToInt32(product.ProductCount).ToString() + " ", new WordTextProperties { Size = "24" }), - ("Название заказа - "+product.OrderName, new WordTextProperties { Size = "24"}) + ("Присутствует в заказе - "+product.OrderName, new WordTextProperties { Size = "24"}) }, TextProperties = new WordTextProperties { diff --git a/DiningRoom/DiningRoomContracts/BindingModels/ReportBindingModel.cs b/DiningRoom/DiningRoomContracts/BindingModels/ReportBindingModel.cs index 59db86e..35f3b9b 100644 --- a/DiningRoom/DiningRoomContracts/BindingModels/ReportBindingModel.cs +++ b/DiningRoom/DiningRoomContracts/BindingModels/ReportBindingModel.cs @@ -1,4 +1,5 @@ -using System; +using DiningRoomContracts.SearchModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -11,5 +12,7 @@ namespace DiningRoomContracts.BindingModels public string FileName { get; set; } = string.Empty; public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } - } + public List? selectedComponents { get; set; } + + } } diff --git a/DiningRoom/DiningRoomContracts/BusinessLogicContracts/IReportLogic.cs b/DiningRoom/DiningRoomContracts/BusinessLogicContracts/IReportLogic.cs index e468c42..23fd9d4 100644 --- a/DiningRoom/DiningRoomContracts/BusinessLogicContracts/IReportLogic.cs +++ b/DiningRoom/DiningRoomContracts/BusinessLogicContracts/IReportLogic.cs @@ -16,9 +16,9 @@ namespace DiningRoomContracts.BusinessLogicContracts /// List GetReportComponentsByCardDate(ReportBindingModel Report); - void SaveReportToWordFile(ReportBindingModel Model, List selectedComponents); + void SaveReportToWordFile(ReportBindingModel Model); - void SaveReportToExcelFile(ReportBindingModel Model, List selectedComponents); + void SaveReportToExcelFile(ReportBindingModel Model); void SaveComponentsToPdfFile(ReportBindingModel model); } } diff --git a/DiningRoom/DiningRoomContracts/SearchModels/ComponentSearchModel.cs b/DiningRoom/DiningRoomContracts/SearchModels/ComponentSearchModel.cs index 6d0f2a1..0afa773 100644 --- a/DiningRoom/DiningRoomContracts/SearchModels/ComponentSearchModel.cs +++ b/DiningRoom/DiningRoomContracts/SearchModels/ComponentSearchModel.cs @@ -4,7 +4,7 @@ { public int? Id { get; set; } public int? UserId { get; set; } - public string ComponentName { get; set; } + public string? ComponentName { get; set; } public DateTime DateComponentCreate { get; set; } } } diff --git a/DiningRoom/DiningRoomRestApi/Controllers/MainController.cs b/DiningRoom/DiningRoomRestApi/Controllers/MainController.cs index 01266e8..913cae8 100644 --- a/DiningRoom/DiningRoomRestApi/Controllers/MainController.cs +++ b/DiningRoom/DiningRoomRestApi/Controllers/MainController.cs @@ -1,4 +1,5 @@ -using DiningRoomContracts.BindingModels; +using DiningRoomBusinessLogic.MailWorker; +using DiningRoomContracts.BindingModels; using DiningRoomContracts.BusinessLogicContracts; using DiningRoomContracts.SearchModels; using DiningRoomContracts.ViewModels; @@ -19,7 +20,9 @@ namespace DiningRoomRestApi.Controllers private readonly IProductLogic _product; private readonly IComponentLogic _component; private readonly IDrinkLogic _drink; - public MainController(ILogger logger, ICardLogic card, IOrderLogic order, IProductLogic product, IComponentLogic component, IDrinkLogic drink) + private readonly IReportLogic _report; + private readonly AbstractMailWorker _mailWorker; + public MainController(ILogger logger, ICardLogic card, IOrderLogic order, IProductLogic product, IComponentLogic component, IDrinkLogic drink, IReportLogic report, AbstractMailWorker mailWorker) { _logger = logger; _card = card; @@ -27,7 +30,9 @@ namespace DiningRoomRestApi.Controllers _product = product; _component = component; _drink = drink; - } + _report = report; + _mailWorker = mailWorker; + } [HttpGet] public List? GetCardList(int Id) { @@ -413,5 +418,29 @@ namespace DiningRoomRestApi.Controllers throw; } } + [HttpPost] + public void CreateComponentsWordFile(ReportBindingModel model) + { + try + { + _report.SaveReportToWordFile(model); + } + catch (Exception ex) + { + throw; + } + } + [HttpPost] + public void CreateComponentsExcelFile(ReportBindingModel model) + { + try + { + _report.SaveReportToExcelFile(model); + } + catch (Exception ex) + { + throw; + } + } } } diff --git a/DiningRoom/DiningRoomUserApp/Controllers/HomeController.cs b/DiningRoom/DiningRoomUserApp/Controllers/HomeController.cs index bf638e2..4b75d1e 100644 --- a/DiningRoom/DiningRoomUserApp/Controllers/HomeController.cs +++ b/DiningRoom/DiningRoomUserApp/Controllers/HomeController.cs @@ -397,43 +397,44 @@ namespace DiningRoomUserApp.Controllers return View(); } - //[HttpPost] - //public void ComponentOrderReport(List components, string type) - //{ - // if (APIClient.User == null) - // { - // throw new Exception("Вы как суда попали? Суда вход только авторизованным"); - // } + [HttpPost] + public void ComponentOrderReport(List components, string type) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } - // if (components.Count <= 0) - // { - // throw new Exception("Количество должно быть больше 0"); - // } + if (components.Count <= 0) + { + throw new Exception("Количество должно быть больше 0"); + } - // if (string.IsNullOrEmpty(type)) - // { - // throw new Exception("Неверный тип отчета"); - // } + if (string.IsNullOrEmpty(type)) + { + throw new Exception("Неверный тип отчета"); + } + List selComp = components.Select(id => new ComponentSearchModel { Id = id }).ToList(); - // if (type == "docx") - // { - // APIClient.PostRequest("api/reportadministrator/createmealplanlistwordfile", new ReportComponentsBindingModel - // { - // Dinners = dinners, - // FileName = "C:\\wordfile.docx" - // }); - // Response.Redirect("GetWordFile"); - // } - // else - // { - // APIClient.PostRequest("api/reportadministrator/createmealplanlistexcelfile", new ReportComponentsBindingModel - // { - // Dinners = dinners, - // FileName = "C:\\exelfile.xlsx" - // }); - // Response.Redirect("GetExcelFile"); - // } - //} + if (type == "docx") + { + APIClient.PostRequest("api/main/createcomponentswordfile", (new ReportBindingModel + { + FileName = "C:\\wordfile.docx", + selectedComponents = selComp + })); + Response.Redirect("GetWordFile"); + } + else + { + APIClient.PostRequest("api/main/createcomponentsexcelfile", (new ReportBindingModel + { + FileName = "C:\\exelfile.xlsx", + selectedComponents = selComp + })); + Response.Redirect("GetExcelFile"); + } + } [HttpGet] public IActionResult GetWordFile()