From 3219dc28fe01dd23c113a9895f79287185c834fc Mon Sep 17 00:00:00 2001 From: ujijrujijr Date: Tue, 28 May 2024 15:31:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=91=D1=8B=D1=81=D1=82=D1=80=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractSaveToPdfImplementer.cs | 49 ++++++----- .../IReportImplementerLogic.cs | 7 +- .../Controllers/HomeController.cs | 52 ++++++++++-- .../Views/Home/ReportOrdersByDates.cshtml | 82 +++++++++++++++++++ .../Views/Shared/_Layout.cshtml | 4 +- .../Controllers/OrderController.cs | 15 ++++ 6 files changed, 181 insertions(+), 28 deletions(-) create mode 100644 ComputerShopImplementerApp/Views/Home/ReportOrdersByDates.cshtml diff --git a/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdfImplementer.cs b/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdfImplementer.cs index bdfe23e..a756ecd 100644 --- a/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdfImplementer.cs +++ b/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdfImplementer.cs @@ -12,31 +12,40 @@ namespace GarmentFactoryBusinessLogic.OfficePackage { public void CreateDoc(PdfInfoImplementer info) { - //CreatePdf(info); - //CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - //CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + CreatePdf(info); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + //!!!МБ ТУТ НЕЛЬЗЯ ДРОБНЫЕ ЧИСЛА ИЛИ МОЖНО С ТОЧКОЙ + CreateTable(new List { "1,5cm", "3cm", "3cm", "2,5cm", "1,5cm", "4cm", "3cm", "3cm", "3cm", "3cm" }); - //CreateTable(new List { "2cm", "3cm", "6cm", "3cm", "3cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "ID заказа", "Дата заказа", "Стоимость заказа", "Статус заказа", "ID заявки", "ФИО клиента", "Дата заявки", "Название сборки", "Каетегория сборки", "Цена сборки" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); - //CreateRow(new PdfRowParameters - //{ - // Texts = new List { "Номер", "Дата заказа", "Текстиль", "Статус", "Сумма" }, - // Style = "NormalTitle", - // ParagraphAlignment = PdfParagraphAlignmentType.Center - //}); + foreach (var order in info.Orders) + { + foreach (var request in order.RequestsAssemblies) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.OrderId.ToString(), order.DateCreateOrder.ToShortDateString(), order.OrderSum.ToString(), order.OrderStatus.ToString(), + request.RequestId.ToString(), request.ClientFIO, request.DateRequest.ToShortDateString(), + string.IsNullOrEmpty(request.AssemblyName) ? "Сборка не привязана" : request.AssemblyName, + string.IsNullOrEmpty(request.AssemblyCategory) ? "Неизвестная категория" : request.AssemblyCategory, + request.AssemblyPrice.ToString() + }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } - //foreach (var order in info.Orders) - //{ - // CreateRow(new PdfRowParameters - // { - // Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.TextileName, order.Status.ToString(), order.Sum.ToString() }, - // Style = "Normal", - // ParagraphAlignment = PdfParagraphAlignmentType.Left - // }); - //} + } //CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth }); - //SavePdf(info); + SavePdf(info); } protected abstract void CreatePdf(PdfInfoImplementer info); protected abstract void CreateParagraph(PdfParagraph paragraph); diff --git a/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs b/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs index 49eb950..9204433 100644 --- a/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs +++ b/ComputerShopContracts/BusinessLogicContracts/IReportImplementerLogic.cs @@ -21,9 +21,12 @@ namespace ComputerShopContracts.BusinessLogicContracts /// Получение отчёта для почты /// /// - List GetReportOrdersByDates(UserSearchModel currentUser, ReportBindingModel report); + List GetReportOrdersByDates(ReportBindingModel report); void SaveReportOrderAssembliesToWordFile(ReportBindingModel model); void SaveReportOrderAssembliesToExcelFile(ReportBindingModel model); - } + + void SaveReportOrdersByDatesToPdfFile(ReportBindingModel model); + + } } diff --git a/ComputerShopImplementerApp/Controllers/HomeController.cs b/ComputerShopImplementerApp/Controllers/HomeController.cs index 3d3a0f7..3a758f9 100644 --- a/ComputerShopImplementerApp/Controllers/HomeController.cs +++ b/ComputerShopImplementerApp/Controllers/HomeController.cs @@ -6,16 +6,19 @@ using System.Diagnostics; using ComputerShopDataModels.Enums; using ComputerShopDataModels.Models; using ComputerShopContracts.SearchModels; +using ComputerShopContracts.BusinessLogicContracts; namespace ComputerShopImplementerApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; + private readonly IReportImplementerLogic _logic; - public HomeController(ILogger logger) + public HomeController(ILogger logger, IReportImplementerLogic logic) { _logger = logger; + _logic = logic; } public IActionResult Index() @@ -539,7 +542,6 @@ namespace ComputerShopImplementerApp.Controllers APIUser.PostRequest("api/order/createreporttowordfile", new ReportBindingModel { Ids = ids, - //FileName = "C:\\ReportsCourseWork\\wordfile.docx" FileName = "C:\\!КУРСОВАЯ\\Сборки по выбранным заказам.docx" }); Response.Redirect("Index"); @@ -550,7 +552,6 @@ namespace ComputerShopImplementerApp.Controllers APIUser.PostRequest("api/order/createreporttoexcelfile", new ReportBindingModel { Ids = ids, - //FileName = "C:\\ReportsCourseWork\\wordfile.docx" FileName = "C:\\!КУРСОВАЯ\\Сборки по выбранным заказам.xlsx" }); Response.Redirect("Index"); @@ -558,9 +559,50 @@ namespace ComputerShopImplementerApp.Controllers } - // ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ - [HttpGet] + public IActionResult ReportOrdersByDates() + { + if (APIUser.User == null) + { + return Redirect("~/Home/Enter"); + } + //ViewBag.Orders = APIUser.GetRequest>($"api/order/getorders?userId={APIUser.User.Id}"); + //ViewBag.Statuses = + return View(); + } + + [HttpGet] + public string GetOrdersReportByDates(DateTime dateFrom, DateTime dateTo) + { + if (APIUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + List result; + try + { + result = _logic.GetReportOrdersByDates(new ReportBindingModel + { + UserId = APIUser.User.Id, + DateFrom = dateFrom, + DateTo = dateTo + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + string table = ""; + return table; + } + + + + + // ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ + + [HttpGet] public IActionResult Privacy() { if (APIUser.User == null) diff --git a/ComputerShopImplementerApp/Views/Home/ReportOrdersByDates.cshtml b/ComputerShopImplementerApp/Views/Home/ReportOrdersByDates.cshtml new file mode 100644 index 0000000..7a9864a --- /dev/null +++ b/ComputerShopImplementerApp/Views/Home/ReportOrdersByDates.cshtml @@ -0,0 +1,82 @@ +@using ComputerShopContracts.ViewModels +@{ + ViewData["Title"] = "Report by dates"; +} + +
+
+

Отчёт за период по заказам

+
+
+ + +
+
+ + +
+
+ + @* *@ + +
+
+ +
+
+
+
+
+ + + diff --git a/ComputerShopImplementerApp/Views/Shared/_Layout.cshtml b/ComputerShopImplementerApp/Views/Shared/_Layout.cshtml index 88b0f27..3f2fb05 100644 --- a/ComputerShopImplementerApp/Views/Shared/_Layout.cshtml +++ b/ComputerShopImplementerApp/Views/Shared/_Layout.cshtml @@ -38,7 +38,9 @@ - + diff --git a/ComputerShopRestApi/Controllers/OrderController.cs b/ComputerShopRestApi/Controllers/OrderController.cs index c56d65f..01ecdad 100644 --- a/ComputerShopRestApi/Controllers/OrderController.cs +++ b/ComputerShopRestApi/Controllers/OrderController.cs @@ -89,6 +89,21 @@ namespace ComputerShopRestApi.Controllers } } + + [HttpPost] + public void CreateReportToPDFFile(ReportBindingModel model) + { + try + { + _reportLogic.SaveReportOrdersByDatesToPdfFile(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + //МБ ИЗМЕНИТЬ IEnumerable на List //!!!ПОТОМ УДАЛИТЬ //[HttpGet]