From 5616f0eaa0b51c3ecc7efd00f13e99b597d0911d Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 29 May 2024 17:52:23 +0400 Subject: [PATCH 1/2] Done reports --- .../BusinessLogics/ReportGuarantorLogic.cs | 56 ++++- .../AbstractSaveToExcelGuarantor.cs | 47 ++-- .../AbstractSaveToPdfGuarantor.cs | 7 +- .../AbstractSaveToWordGuarantor.cs | 16 +- .../HelperModels/ExcelInfoGuarantor.cs | 14 +- .../Implements/SaveToExcelGuarantor.cs | 13 +- .../Implements/SaveToPdfGuarantor.cs | 10 +- .../Implements/SaveToWordGuarantor.cs | 5 +- .../IReportGuarantorLogic.cs | 7 +- .../StorageContracts/IComponentStorage.cs | 4 +- .../Implements/ComponentStorage.cs | 14 +- .../ComputerShopGuarantorApp.csproj | 2 + .../Controllers/HomeController.cs | 211 ++++++++++++++++-- ComputerShopGuarantorApp/Program.cs | 14 ++ .../Views/Home/Assembly.cshtml | 17 +- .../Views/Home/Component.cshtml | 11 +- .../Views/Home/Privacy.cshtml | 38 +++- .../Views/Home/Product.cshtml | 21 +- .../Home/ReportComponentsByRequestDate.cshtml | 54 +++++ .../Home/ReportComponentsWithShipments.cshtml | 43 ++++ .../Views/Shared/_Layout.cshtml | 8 +- .../Controllers/ComponentController.cs | 66 +++++- ComputerShopRestApi/Program.cs | 4 + 23 files changed, 546 insertions(+), 136 deletions(-) create mode 100644 ComputerShopGuarantorApp/Views/Home/ReportComponentsByRequestDate.cshtml create mode 100644 ComputerShopGuarantorApp/Views/Home/ReportComponentsWithShipments.cshtml diff --git a/ComputerShopBusinessLogic/BusinessLogics/ReportGuarantorLogic.cs b/ComputerShopBusinessLogic/BusinessLogics/ReportGuarantorLogic.cs index b8d9f81..f4fbb42 100644 --- a/ComputerShopBusinessLogic/BusinessLogics/ReportGuarantorLogic.cs +++ b/ComputerShopBusinessLogic/BusinessLogics/ReportGuarantorLogic.cs @@ -1,6 +1,7 @@ -using ComputerShopContracts.BindingModels; +using ComputerShopBusinessLogic.OfficePackage; +using ComputerShopBusinessLogic.OfficePackage.HelperModels; +using ComputerShopContracts.BindingModels; using ComputerShopContracts.BusinessLogicContracts; -using ComputerShopContracts.SearchModels; using ComputerShopContracts.StorageContracts; using ComputerShopContracts.ViewModels; @@ -10,35 +11,70 @@ namespace ComputerShopBusinessLogic.BusinessLogics { private readonly IComponentStorage _componentStorage; - public ReportGuarantorLogic(IComponentStorage ComponentStorage) + private readonly AbstractSaveToExcelGuarantor _saveToExcel; + private readonly AbstractSaveToWordGuarantor _saveToWord; + private readonly AbstractSaveToPdfGuarantor _saveToPdf; + + public ReportGuarantorLogic(IComponentStorage ComponentStorage, + AbstractSaveToExcelGuarantor SaveToExcel, AbstractSaveToWordGuarantor SaveToWord, AbstractSaveToPdfGuarantor SaveToPdf) { _componentStorage = ComponentStorage; + _saveToExcel = SaveToExcel; + _saveToWord = SaveToWord; + _saveToPdf = SaveToPdf; } /// /// Получение отчёта для Word или Excel /// - public List GetReportComponentsWithShipments(List SelectedComponents) + public List GetReportComponentsWithShipments(List SelectedComponentIds) { - return _componentStorage.GetComponentsWithShipments(SelectedComponents); + return _componentStorage.GetComponentsWithShipments(SelectedComponentIds); } /// /// Получение отчёта для отправки на почту /// - public List GetReportComponentsByRequestDate(UserSearchModel CurrentUser, ReportBindingModel Report) + public List GetReportComponentsByRequestDate(ReportBindingModel Model) { - return _componentStorage.GetComponentsByShipmentDate(Report, CurrentUser); + return _componentStorage.GetComponentsByShipmentDate(Model); } public void SaveReportToWordFile(ReportBindingModel Model) { - throw new NotImplementedException(); + _saveToWord.CreateDoc(new WordInfoGuarantor + { + Filename = Model.FileName, + Title = "Список сборок по выбранным заказам", + ShipmentComponents = GetReportComponentsWithShipments(Model.Ids!) + }); ; } - + public void SaveReportToExcelFile(ReportBindingModel Model) { - throw new NotImplementedException(); + _saveToExcel.CreateReport(new ExcelInfoGuarantor + { + Filename = Model.FileName, + ShipmentComponents = GetReportComponentsWithShipments(Model.Ids!) + }); + } + + public void SaveReportComponentsByRequestDateToPdfFile(ReportBindingModel Model) + { + if (Model.DateFrom == null) + throw new ArgumentException("Дата начала не задана"); + + if (Model.DateTo == null) + throw new ArgumentException("Дата окончания не задана"); + + _saveToPdf.CreateDoc(new PdfInfoGuarantor + { + Filename = Model.FileName, + Title = "Отчёт по комплектующим за период", + DateFrom = Model.DateFrom!.Value, + DateTo = Model.DateTo!.Value, + ComponentsByDate = GetReportComponentsByRequestDate(Model) + }); } } } diff --git a/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToExcelGuarantor.cs b/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToExcelGuarantor.cs index 010c213..0b0c912 100644 --- a/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToExcelGuarantor.cs +++ b/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToExcelGuarantor.cs @@ -1,6 +1,5 @@ -using ComputerShopBusinessLogic.OfficePackage.HelperModels; -using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums; -using GarmentFactoryBusinessLogic.OfficePackage.HelperModels; +using ComputerShopBusinessLogic.OfficePackage.HelperEnums; +using ComputerShopBusinessLogic.OfficePackage.HelperModels; namespace ComputerShopBusinessLogic.OfficePackage { @@ -98,20 +97,34 @@ namespace ComputerShopBusinessLogic.OfficePackage Text = ComponentWithShipments.ComponentCost.ToString(), StyleInfo = ExcelStyleInfoType.Text }); - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "D", - RowIndex = RowIndex, - Text = Shipment.ProviderName, - StyleInfo = ExcelStyleInfoType.Text - }); - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "E", - RowIndex = RowIndex, - Text = Shipment.ShipmentDate.ToShortDateString(), - StyleInfo = ExcelStyleInfoType.Text - }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "D", + RowIndex = RowIndex, + Text = Shipment.ProviderName, + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "E", + RowIndex = RowIndex, + Text = Shipment.ShipmentDate.ToShortDateString(), + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "F", + RowIndex = RowIndex, + Text = Shipment.ProductName, + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "G", + RowIndex = RowIndex, + Text = Shipment.ProductPrice.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); } ShipmentIndex++; if (ShipmentIndex < ShipmentsNum && !string.IsNullOrEmpty(Shipment.ProviderName)) diff --git a/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdfGuarantor.cs b/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdfGuarantor.cs index d9c131e..8f817fb 100644 --- a/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdfGuarantor.cs +++ b/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdfGuarantor.cs @@ -1,6 +1,5 @@ -using ComputerShopBusinessLogic.OfficePackage.HelperModels; -using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums; -using GarmentFactoryBusinessLogic.OfficePackage.HelperModels; +using ComputerShopBusinessLogic.OfficePackage.HelperEnums; +using ComputerShopBusinessLogic.OfficePackage.HelperModels; namespace ComputerShopBusinessLogic.OfficePackage { @@ -37,8 +36,6 @@ namespace ComputerShopBusinessLogic.OfficePackage ComponentByDate.DateRequest.ToShortDateString(), ComponentByDate.ClientFIO, }, - Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Left }); } diff --git a/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToWordGuarantor.cs b/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToWordGuarantor.cs index 86bd334..55593a5 100644 --- a/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToWordGuarantor.cs +++ b/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToWordGuarantor.cs @@ -1,6 +1,5 @@ -using ComputerShopBusinessLogic.OfficePackage.HelperModels; -using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums; -using GarmentFactoryBusinessLogic.OfficePackage.HelperModels; +using ComputerShopBusinessLogic.OfficePackage.HelperEnums; +using ComputerShopBusinessLogic.OfficePackage.HelperModels; namespace ComputerShopBusinessLogic.OfficePackage { @@ -26,9 +25,9 @@ namespace ComputerShopBusinessLogic.OfficePackage { Texts = new List<(string, WordTextProperties)> { - ("Комплектующая №" + ComponentWithShipments.ComponentId.ToString() + " - " + - ComponentWithShipments.ComponentName.ToString() + " - " + - ComponentWithShipments.ComponentCost.ToString() + " - ", new WordTextProperties {Size = "24", Bold=true}) + ("Комплектующая №" + ComponentWithShipments.ComponentId.ToString() + " - " + + ComponentWithShipments.ComponentName.ToString() + " - " + + ComponentWithShipments.ComponentCost.ToString() + ":", new WordTextProperties {Size = "24", Bold=true}) }, TextProperties = new WordTextProperties { @@ -45,7 +44,9 @@ namespace ComputerShopBusinessLogic.OfficePackage { Texts = new List<(string, WordTextProperties)> { (Shipment.ProviderName + " - ", new WordTextProperties { Size = "24" }), - (Shipment.ShipmentDate.ToShortDateString() + " - ", new WordTextProperties { Size = "24" }) + (Shipment.ShipmentDate.ToShortDateString() + " - ", new WordTextProperties { Size = "24" }), + (Shipment.ProductName + " - ", new WordTextProperties { Size = "24" }), + (Shipment.ProductPrice.ToString(), new WordTextProperties { Size = "24" }), }, TextProperties = new WordTextProperties { @@ -54,7 +55,6 @@ namespace ComputerShopBusinessLogic.OfficePackage } }); } - } } diff --git a/ComputerShopBusinessLogic/OfficePackage/HelperModels/ExcelInfoGuarantor.cs b/ComputerShopBusinessLogic/OfficePackage/HelperModels/ExcelInfoGuarantor.cs index b3d1fcb..723a38d 100644 --- a/ComputerShopBusinessLogic/OfficePackage/HelperModels/ExcelInfoGuarantor.cs +++ b/ComputerShopBusinessLogic/OfficePackage/HelperModels/ExcelInfoGuarantor.cs @@ -4,19 +4,19 @@ namespace ComputerShopBusinessLogic.OfficePackage.HelperModels { public class ExcelInfoGuarantor : DocumentInfo { - public string Title1 { get; set; } = "ID заказа"; + public string Title1 { get; set; } = "ID комплектующей"; - public string Title2 { get; set; } = "Дата заказа"; + public string Title2 { get; set; } = "Наименование"; - public string Title3 { get; set; } = "Стоимость заказа"; + public string Title3 { get; set; } = "Стоимость комплектующей"; - public string Title4 { get; set; } = "Статус заказа"; + public string Title4 { get; set; } = "Поставщик партии"; - public string Title5 { get; set; } = "Название сборки"; + public string Title5 { get; set; } = "Дата поставки"; - public string Title6 { get; set; } = "Категория сборки"; + public string Title6 { get; set; } = "Товар"; - public string Title7 { get; set; } = "Цена сборки"; + public string Title7 { get; set; } = "Цена товара"; public List ShipmentComponents { get; set; } = new(); } diff --git a/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToExcelGuarantor.cs b/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToExcelGuarantor.cs index a48eca0..d145655 100644 --- a/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToExcelGuarantor.cs +++ b/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToExcelGuarantor.cs @@ -1,11 +1,10 @@ -using ComputerShopBusinessLogic.OfficePackage.HelperModels; +using ComputerShopBusinessLogic.OfficePackage.HelperEnums; +using ComputerShopBusinessLogic.OfficePackage.HelperModels; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Office2010.Excel; using DocumentFormat.OpenXml.Office2013.Excel; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; -using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums; -using GarmentFactoryBusinessLogic.OfficePackage.HelperModels; namespace ComputerShopBusinessLogic.OfficePackage.Implements { @@ -171,12 +170,12 @@ namespace ComputerShopBusinessLogic.OfficePackage.Implements lstColumns = new Columns(); } - lstColumns.Append(new Column() { Min = 1, Max = 1, Width = 10, CustomWidth = true }); - lstColumns.Append(new Column() { Min = 2, Max = 2, Width = 10, CustomWidth = true }); + lstColumns.Append(new Column() { Min = 1, Max = 1, Width = 20, CustomWidth = true }); + lstColumns.Append(new Column() { Min = 2, Max = 2, Width = 20, CustomWidth = true }); lstColumns.Append(new Column() { Min = 3, Max = 3, Width = 20, CustomWidth = true }); - lstColumns.Append(new Column() { Min = 4, Max = 4, Width = 10, CustomWidth = true }); + lstColumns.Append(new Column() { Min = 4, Max = 4, Width = 20, CustomWidth = true }); lstColumns.Append(new Column() { Min = 5, Max = 5, Width = 20, CustomWidth = true }); - lstColumns.Append(new Column() { Min = 6, Max = 6, Width = 20, CustomWidth = true }); + lstColumns.Append(new Column() { Min = 6, Max = 6, Width = 25, CustomWidth = true }); lstColumns.Append(new Column() { Min = 7, Max = 7, Width = 20, CustomWidth = true }); worksheetPart.Worksheet.InsertAt(lstColumns, 0); diff --git a/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToPdfGuarantor.cs b/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToPdfGuarantor.cs index 9c21bdc..3211f51 100644 --- a/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToPdfGuarantor.cs +++ b/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToPdfGuarantor.cs @@ -1,6 +1,5 @@ -using ComputerShopBusinessLogic.OfficePackage.HelperModels; -using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums; -using GarmentFactoryBusinessLogic.OfficePackage.HelperModels; +using ComputerShopBusinessLogic.OfficePackage.HelperEnums; +using ComputerShopBusinessLogic.OfficePackage.HelperModels; using MigraDoc.DocumentObjectModel; using MigraDoc.DocumentObjectModel.Tables; using MigraDoc.Rendering; @@ -28,7 +27,7 @@ namespace ComputerShopBusinessLogic.OfficePackage.Implements { var style = document.Styles["Normal"]; style.Font.Name = "Times New Roman"; - style.Font.Size = 14; + style.Font.Size = 10; style = document.Styles.AddStyle("NormalTitle", "Normal"); style.Font.Bold = true; @@ -37,7 +36,8 @@ namespace ComputerShopBusinessLogic.OfficePackage.Implements protected override void CreatePdf(HelperModels.DocumentInfo Info) { _document = new Document(); - DefineStyles(_document); + _document.DefaultPageSetup.Orientation = Orientation.Landscape; + DefineStyles(_document); _section = _document.AddSection(); } diff --git a/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToWordGuarantor.cs b/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToWordGuarantor.cs index 842aa5e..43ee30e 100644 --- a/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToWordGuarantor.cs +++ b/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToWordGuarantor.cs @@ -1,9 +1,8 @@ -using ComputerShopBusinessLogic.OfficePackage.HelperModels; +using ComputerShopBusinessLogic.OfficePackage.HelperEnums; +using ComputerShopBusinessLogic.OfficePackage.HelperModels; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; -using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums; -using GarmentFactoryBusinessLogic.OfficePackage.HelperModels; namespace ComputerShopBusinessLogic.OfficePackage.Implements { diff --git a/ComputerShopContracts/BusinessLogicContracts/IReportGuarantorLogic.cs b/ComputerShopContracts/BusinessLogicContracts/IReportGuarantorLogic.cs index e68c6ab..1e70294 100644 --- a/ComputerShopContracts/BusinessLogicContracts/IReportGuarantorLogic.cs +++ b/ComputerShopContracts/BusinessLogicContracts/IReportGuarantorLogic.cs @@ -1,5 +1,4 @@ using ComputerShopContracts.BindingModels; -using ComputerShopContracts.SearchModels; using ComputerShopContracts.ViewModels; namespace ComputerShopContracts.BusinessLogicContracts @@ -9,15 +8,17 @@ namespace ComputerShopContracts.BusinessLogicContracts /// /// Получение отчёта для Word или Excel /// - List GetReportComponentsWithShipments(List SelectedComponents); + List GetReportComponentsWithShipments(List SelectedComponentIds); /// /// Получение отчёта для отправки на почту /// - List GetReportComponentsByRequestDate(UserSearchModel CurrentUser, ReportBindingModel Report); + List GetReportComponentsByRequestDate(ReportBindingModel Model); void SaveReportToWordFile(ReportBindingModel Model); void SaveReportToExcelFile(ReportBindingModel Model); + + void SaveReportComponentsByRequestDateToPdfFile(ReportBindingModel Model); } } diff --git a/ComputerShopContracts/StorageContracts/IComponentStorage.cs b/ComputerShopContracts/StorageContracts/IComponentStorage.cs index 89dc469..7047cb2 100644 --- a/ComputerShopContracts/StorageContracts/IComponentStorage.cs +++ b/ComputerShopContracts/StorageContracts/IComponentStorage.cs @@ -18,8 +18,8 @@ namespace ComputerShopContracts.StorageContracts ComponentViewModel? Delete(ComponentBindingModel Model); - List GetComponentsWithShipments(List Models); + List GetComponentsWithShipments(List ComponentIds); - List GetComponentsByShipmentDate(ReportBindingModel ReportModel, UserSearchModel UserModel); + List GetComponentsByShipmentDate(ReportBindingModel ReportModel); } } diff --git a/ComputerShopDatabaseImplement/Implements/ComponentStorage.cs b/ComputerShopDatabaseImplement/Implements/ComponentStorage.cs index 6a558b5..72b9c2f 100644 --- a/ComputerShopDatabaseImplement/Implements/ComponentStorage.cs +++ b/ComputerShopDatabaseImplement/Implements/ComponentStorage.cs @@ -88,7 +88,7 @@ namespace ComputerShopDatabaseImplement.Implements return ExistingComponent.ViewModel; } - public List GetComponentsWithShipments(List Models) + public List GetComponentsWithShipments(List ComponentIds) { using var Context = new ComputerShopDatabase(); @@ -96,8 +96,8 @@ namespace ComputerShopDatabaseImplement.Implements .Include(x => x.ProductComponents) .ThenInclude(x => x.Product) .ThenInclude(x => x.Shipment) - .Where(x => - Models.Select(x => x.Id).Contains(x.Id) // Компонент, указанный пользователем, + .Where(x => + ComponentIds.Contains(x.Id) // Компонент, указанный пользователем, && x.ProductComponents.Any(y => y.Product.Shipment != null)) // который содержится в товаре, имеющем партию товаров .ToList() .Select(x => new ReportComponentWithShipmentViewModel @@ -106,18 +106,18 @@ namespace ComputerShopDatabaseImplement.Implements ComponentName = x.ComponentName, ComponentCost = x.Cost, Shipments = x.ProductComponents - .Select(y => (0, y.Product.ProductName, y.Product.Price, y.Product.Shipment!.ProviderName, y.Product.Shipment.DateShipment)) + .Select(y => (y.Product.ProductName, y.Product.Price, y.Product.Shipment!.ProviderName, y.Product.Shipment.DateShipment)) .ToList(), }) - .ToList(); + .ToList(); } - public List GetComponentsByShipmentDate(ReportBindingModel ReportModel, UserSearchModel UserModel) + public List GetComponentsByShipmentDate(ReportBindingModel ReportModel) { using var Context = new ComputerShopDatabase(); return Context.Components - .Where(c => c.UserId == UserModel.Id) + .Where(c => c.UserId == ReportModel.UserId) .Include(c => c.AssemblyComponents) .ThenInclude(ac => ac.Assembly) .ThenInclude(a => a.Requests.Where(r => r.DateRequest >= ReportModel.DateFrom && r.DateRequest <= ReportModel.DateTo)) diff --git a/ComputerShopGuarantorApp/ComputerShopGuarantorApp.csproj b/ComputerShopGuarantorApp/ComputerShopGuarantorApp.csproj index ea3630b..a380be2 100644 --- a/ComputerShopGuarantorApp/ComputerShopGuarantorApp.csproj +++ b/ComputerShopGuarantorApp/ComputerShopGuarantorApp.csproj @@ -11,7 +11,9 @@ + + diff --git a/ComputerShopGuarantorApp/Controllers/HomeController.cs b/ComputerShopGuarantorApp/Controllers/HomeController.cs index e603287..c812877 100644 --- a/ComputerShopGuarantorApp/Controllers/HomeController.cs +++ b/ComputerShopGuarantorApp/Controllers/HomeController.cs @@ -1,4 +1,5 @@ using ComputerShopContracts.BindingModels; +using ComputerShopContracts.BusinessLogicContracts; using ComputerShopContracts.ViewModels; using ComputerShopGuarantorApp.Models; using Microsoft.AspNetCore.Mvc; @@ -9,10 +10,12 @@ namespace ComputerShopGuarantorApp.Controllers public class HomeController : Controller { private readonly ILogger _logger; + private readonly IReportGuarantorLogic _reportLogic; - public HomeController(ILogger logger) + public HomeController(ILogger logger, IReportGuarantorLogic ReportLogic) { _logger = logger; + _reportLogic = ReportLogic; } public IActionResult Index() @@ -89,7 +92,8 @@ namespace ComputerShopGuarantorApp.Controllers Response.Redirect("../Components"); } - public void DeleteComponent(int Id) + [HttpPost] + public void DeleteComponent(int Id) { ApiUser.PostRequest($"api/component/deletecomponent", new ComponentBindingModel { Id = Id }); Response.Redirect("../Components"); @@ -172,6 +176,7 @@ namespace ComputerShopGuarantorApp.Controllers Response.Redirect("../Assemblies"); } + [HttpPost] public void DeleteAssembly(int Id) { ApiUser.PostRequest($"api/assembly/deleteassembly", new AssemblyBindingModel { Id = Id }); @@ -259,6 +264,7 @@ namespace ComputerShopGuarantorApp.Controllers Response.Redirect("../Products"); } + [HttpPost] public void DeleteProduct(int Id) { ApiUser.PostRequest($"api/product/deleteproduct", new ProductBindingModel { Id = Id }); @@ -269,17 +275,180 @@ namespace ComputerShopGuarantorApp.Controllers * Отчеты *-----------------------------------------------------*/ + public IActionResult ReportComponentsWithShipments() + { + if (ApiUser.User == null) + return Redirect("~/Home/Enter"); + ViewBag.Components = ApiUser.GetRequest>($"api/component/getcomponents?userId={ApiUser.User.Id}"); + return View(); + } - // ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ + public IActionResult GetWordFile() + { + return PhysicalFile("C:\\!КУРСОВАЯ\\Партии товаров по выбранным компонентам.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Партии товаров по выбранным компонентам.docx"); + } + + public IActionResult GetExcelFile() + { + return PhysicalFile("C:\\!КУРСОВАЯ\\Партии товаров по выбранным компонентам.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Партии товаров по выбранным компонентам.xlsx"); + } + + [HttpPost] + public IActionResult ReportComponentsWithShipments(int[] ComponentIds, string Type) + { + if (ApiUser.User == null) + Redirect("Index"); + + if (ComponentIds.Length > 0 && !string.IsNullOrEmpty(Type)) + { + if (Type == "docx") + { + ApiUser.PostRequest("api/component/createreporttowordfile", new ReportBindingModel + { + Ids = ComponentIds.ToList(), + FileName = "C:\\!КУРСОВАЯ\\Партии товаров по выбранным компонентам.docx" + }); + return GetWordFile(); + } + + if (Type == "xlsx") + { + ApiUser.PostRequest("api/component/createreporttoexcelfile", new ReportBindingModel + { + Ids = ComponentIds.ToList(), + FileName = "C:\\!КУРСОВАЯ\\Партии товаров по выбранным компонентам.xlsx" + }); + return GetExcelFile(); + } + } + + return Redirect("Index"); + } + + public IActionResult ReportComponentsByRequestDate() + { + if (ApiUser.User == null) + return Redirect("~/Home/Enter"); + + return View(); + } + + [HttpGet] + public string GetComponentsByRequestDate(DateTime DateFrom, DateTime DateTo) + { + if (ApiUser.User == null) + throw new Exception("Вход только авторизованным"); + + if (DateFrom != DateTime.MinValue && DateTo != DateTime.MinValue) + { + List Result; + Result = _reportLogic.GetReportComponentsByRequestDate(new ReportBindingModel + { + UserId = ApiUser.User.Id, + DateFrom = DateFrom, + DateTo = DateTo + }); + string Table = string.Empty; + + Table += $""; + Table += ""; + + // ID комплектующей + Table += ""; + // Название + Table += ""; + // Стоимость + Table += ""; + // ID сборки + Table += ""; + // Название сборки + Table += ""; + // Цена сборки + Table += ""; + // Категория + Table += ""; + // ID заявки + Table += ""; + // Дата заявки + Table += ""; + // ФИО клиента + Table += ""; + + Table += ""; + Table += ""; + Table += ""; + + Table += $""; + Table += $""; + Table += $""; + Table += $""; + Table += $""; + Table += $""; + Table += $""; + Table += $""; + Table += $""; + Table += $""; + + Table += ""; + Table += ""; + Table += ""; + + foreach (var ComponentByDate in Result) + { + Table += ""; + Table += $""; + Table += $""; + Table += $""; + Table += $""; + Table += $""; + Table += $""; + Table += $""; + Table += $""; + Table += $""; + Table += $""; + + Table += ""; + } + Table += "
ID комплектующейНазваниеСтоимостьID сборкиНазвание сборкиЦена сборкиКатегорияID заявкиДата заявкиКлиент
{ComponentByDate.ComponentId}{ComponentByDate.ComponentName}{ComponentByDate.ComponentCost}{ComponentByDate.AssemblyId}{ComponentByDate.AssemblyName}{ComponentByDate.AssemblyPrice}{ComponentByDate.AssemblyCategory}{ComponentByDate.RequestId}{ComponentByDate.DateRequest.ToShortDateString()}{ComponentByDate.ClientFIO}
"; + return Table; + } + return ""; + } + + [HttpPost] + public void ReportComponentsByRequestDate(DateTime DateFrom, DateTime DateTo) + { + if (ApiUser.User == null) + { + throw new Exception("Вход только авторизованным"); + } + + if (DateFrom != DateTime.MinValue && DateTo != DateTime.MinValue) + { + ApiUser.PostRequest("api/component/createreporttopdffile", new ReportBindingModel + { + FileName = "C:\\!КУРСОВАЯ\\Отчёт за период.pdf", + DateFrom = DateFrom, + DateTo = DateTo, + UserId = ApiUser.User.Id + }); + ApiUser.PostRequest("api/component/sendpdftomail", new MailSendInfoBindingModel + { + MailAddress = ApiUser.User.Email, + Subject = "Отчет за период", + Text = "Отчет по компонентам с " + DateFrom.ToShortDateString() + " по " + DateTo.ToShortDateString() + }); + } + Response.Redirect("Index"); + } [HttpGet] public IActionResult Privacy() { if (ApiUser.User == null) - { return Redirect("~/Home/Enter"); - } + return View(ApiUser.User); } @@ -287,13 +456,11 @@ namespace ComputerShopGuarantorApp.Controllers public void Privacy(string Login, string Password, string Email) { if (ApiUser.User == null) - { throw new Exception("Вход только авторизованным"); - } + if (string.IsNullOrEmpty(Login) || string.IsNullOrEmpty(Password) || string.IsNullOrEmpty(Email)) - { throw new Exception("Введите логин, пароль и почту"); - } + ApiUser.PostRequest("api/user/updatedata", new UserBindingModel { Id = ApiUser.User.Id, @@ -305,6 +472,7 @@ namespace ComputerShopGuarantorApp.Controllers ApiUser.User.Login = Login; ApiUser.User.Password = Password; ApiUser.User.Email = Email; + Response.Redirect("Index"); } @@ -323,14 +491,12 @@ namespace ComputerShopGuarantorApp.Controllers public void Enter(string Login, string Password) { if (string.IsNullOrEmpty(Login) || string.IsNullOrEmpty(Password)) - { throw new Exception("Введите логин и пароль"); - } + ApiUser.User = ApiUser.GetRequest($"api/user/loginguarantor?login={Login}&password={Password}"); if (ApiUser.User == null) - { throw new Exception("Неверный логин или пароль"); - } + Response.Redirect("Index"); } @@ -343,9 +509,8 @@ namespace ComputerShopGuarantorApp.Controllers public void Register(string Login, string Password, string Email) { if (string.IsNullOrEmpty(Login) || string.IsNullOrEmpty(Password) || string.IsNullOrEmpty(Email)) - { throw new Exception("Введите логин, пароль и почту"); - } + ApiUser.PostRequest("api/user/registerguarantor", new UserBindingModel { Login = Login, @@ -353,12 +518,18 @@ namespace ComputerShopGuarantorApp.Controllers Email = Email }); ApiUser.User = ApiUser.GetRequest($"api/user/loginguarantor?login={Login}&password={Password}"); - if (ApiUser.User == null) - { - Response.Redirect("Enter"); - } - Response.Redirect("Index"); + + if (ApiUser.User == null) + Response.Redirect("Enter"); + + Response.Redirect("Index"); return; } + + public void Logout() + { + ApiUser.User = null; + Response.Redirect("Index"); + } } } diff --git a/ComputerShopGuarantorApp/Program.cs b/ComputerShopGuarantorApp/Program.cs index 81f11e0..353c49b 100644 --- a/ComputerShopGuarantorApp/Program.cs +++ b/ComputerShopGuarantorApp/Program.cs @@ -1,7 +1,21 @@ +using ComputerShopBusinessLogic.BusinessLogics; +using ComputerShopBusinessLogic.OfficePackage; +using ComputerShopBusinessLogic.OfficePackage.Implements; +using ComputerShopContracts.BusinessLogicContracts; +using ComputerShopContracts.StorageContracts; +using ComputerShopDatabaseImplement.Implements; using ComputerShopGuarantorApp; var Builder = WebApplication.CreateBuilder(args); +//Builder.Services.AddTransient(); +Builder.Services.AddTransient(); + +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); + // Add services to the container. Builder.Services.AddControllersWithViews(); diff --git a/ComputerShopGuarantorApp/Views/Home/Assembly.cshtml b/ComputerShopGuarantorApp/Views/Home/Assembly.cshtml index 95ef8f7..122c9f6 100644 --- a/ComputerShopGuarantorApp/Views/Home/Assembly.cshtml +++ b/ComputerShopGuarantorApp/Views/Home/Assembly.cshtml @@ -20,23 +20,23 @@
- +
- +
- +
- - @foreach (var Component in ViewBag.Components) { @if (Model != null && Model.AssemblyComponents.Values.Any(x => Component.Id == x.Id)) @@ -51,11 +51,6 @@
-
-
-
- -
-
+
diff --git a/ComputerShopGuarantorApp/Views/Home/Component.cshtml b/ComputerShopGuarantorApp/Views/Home/Component.cshtml index 48ede93..dd16f72 100644 --- a/ComputerShopGuarantorApp/Views/Home/Component.cshtml +++ b/ComputerShopGuarantorApp/Views/Home/Component.cshtml @@ -20,20 +20,15 @@
- +
- +
-
-
-
- -
-
+
diff --git a/ComputerShopGuarantorApp/Views/Home/Privacy.cshtml b/ComputerShopGuarantorApp/Views/Home/Privacy.cshtml index af4fb19..274c13e 100644 --- a/ComputerShopGuarantorApp/Views/Home/Privacy.cshtml +++ b/ComputerShopGuarantorApp/Views/Home/Privacy.cshtml @@ -1,6 +1,34 @@ -@{ - ViewData["Title"] = "Privacy Policy"; -} -

@ViewData["Title"]

+@using ComputerShopContracts.ViewModels -

Use this page to detail your site's privacy policy.

+@model UserViewModel + +@{ + ViewData["Title"] = "Профиль"; +} + +
+
+

Профиль поручителя

+

На этой странице можно изменить данные или выйти из аккаунта

+
+ +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + Выйти +
+
+
diff --git a/ComputerShopGuarantorApp/Views/Home/Product.cshtml b/ComputerShopGuarantorApp/Views/Home/Product.cshtml index 4515873..3f5a055 100644 --- a/ComputerShopGuarantorApp/Views/Home/Product.cshtml +++ b/ComputerShopGuarantorApp/Views/Home/Product.cshtml @@ -20,23 +20,23 @@
- +
- +
- +
- - @foreach (var Component in ViewBag.Components) { @if (Model != null && Model.ProductComponents.Values.Any(x => Component.Id == x.Id)) @@ -52,8 +52,8 @@
- - @foreach (var Shipment in ViewBag.Shipments) { @if (Model != null && Model.ShipmentId == Shipment.Id) @@ -68,11 +68,6 @@
-
-
-
- -
-
+
diff --git a/ComputerShopGuarantorApp/Views/Home/ReportComponentsByRequestDate.cshtml b/ComputerShopGuarantorApp/Views/Home/ReportComponentsByRequestDate.cshtml new file mode 100644 index 0000000..d3d379e --- /dev/null +++ b/ComputerShopGuarantorApp/Views/Home/ReportComponentsByRequestDate.cshtml @@ -0,0 +1,54 @@ +@using ComputerShopContracts.ViewModels +@{ + ViewData["Title"] = "Комплектующие по дате поставки"; +} + +
+
+

Получение сведений за период по комплектующим

+

Информация о комплектующих, которые указывались в сборках и заявках

+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
+ +
+ + + diff --git a/ComputerShopGuarantorApp/Views/Home/ReportComponentsWithShipments.cshtml b/ComputerShopGuarantorApp/Views/Home/ReportComponentsWithShipments.cshtml new file mode 100644 index 0000000..bf7e1e8 --- /dev/null +++ b/ComputerShopGuarantorApp/Views/Home/ReportComponentsWithShipments.cshtml @@ -0,0 +1,43 @@ +@using ComputerShopContracts.ViewModels +@{ + ViewData["Title"] = "Комплектующие"; +} + +
+
+

Получение списка партий товаров по выбранным комплектующим

+

Укажите комплектующие, для который вы хотите получить список партий товаров, и выберите тип файла для отчета

+
+ +
+
+ + +
+
+ +
+ + +
+
+ + +
+
+

+ +

+
+
diff --git a/ComputerShopGuarantorApp/Views/Shared/_Layout.cshtml b/ComputerShopGuarantorApp/Views/Shared/_Layout.cshtml index e3e9b14..f7eb086 100644 --- a/ComputerShopGuarantorApp/Views/Shared/_Layout.cshtml +++ b/ComputerShopGuarantorApp/Views/Shared/_Layout.cshtml @@ -8,6 +8,8 @@ + +
@@ -33,10 +35,10 @@ Товары @if (ApiUser.User == null) @@ -70,7 +72,7 @@
- © 2024 - "Ты ж программист" @* - Privacy *@ + © 2024 - "Ты ж программист"
diff --git a/ComputerShopRestApi/Controllers/ComponentController.cs b/ComputerShopRestApi/Controllers/ComponentController.cs index db1ddf0..eaadfd2 100644 --- a/ComputerShopRestApi/Controllers/ComponentController.cs +++ b/ComputerShopRestApi/Controllers/ComponentController.cs @@ -1,4 +1,5 @@ -using ComputerShopContracts.BindingModels; +using ComputerShopBusinessLogic.MailWorker; +using ComputerShopContracts.BindingModels; using ComputerShopContracts.BusinessLogicContracts; using ComputerShopContracts.SearchModels; using ComputerShopContracts.ViewModels; @@ -12,11 +13,15 @@ namespace ComputerShopRestApi.Controllers { private readonly ILogger _logger; private readonly IComponentLogic _componentLogic; + private readonly IReportGuarantorLogic _reportLogic; + private readonly AbstractMailWorker _mailWorker; - public ComponentController(IComponentLogic Logic, ILogger Logger) + public ComponentController(IComponentLogic Logic, ILogger Logger, IReportGuarantorLogic ReportLogic, AbstractMailWorker MailWorker) { _logger = Logger; _componentLogic = Logic; + _reportLogic = ReportLogic; + _mailWorker = MailWorker; } [HttpGet] @@ -94,5 +99,62 @@ namespace ComputerShopRestApi.Controllers throw; } } + + [HttpPost] + public void CreateReportToWordFile(ReportBindingModel Model) + { + try + { + _reportLogic.SaveReportToWordFile(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + + [HttpPost] + public void CreateReportToExcelFile(ReportBindingModel Model) + { + try + { + _reportLogic.SaveReportToExcelFile(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + + [HttpPost] + public void CreateReportToPdfFile(ReportBindingModel Model) + { + try + { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + _reportLogic.SaveReportComponentsByRequestDateToPdfFile(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + + [HttpPost] + public void SendPdfToMail(MailSendInfoBindingModel Model) + { + try + { + _mailWorker.MailSendAsync(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отправки письма"); + throw; + } + } } } diff --git a/ComputerShopRestApi/Program.cs b/ComputerShopRestApi/Program.cs index e0e3d6e..3fa155a 100644 --- a/ComputerShopRestApi/Program.cs +++ b/ComputerShopRestApi/Program.cs @@ -42,6 +42,10 @@ Builder.Services.AddTransient(); Builder.Services.AddTransient(); +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); +Builder.Services.AddTransient(); + Builder.Services.AddSingleton(); Builder.Services.AddControllers(); From c8b059545cd71e4d5b6ced157d25eae6f68fb5a5 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Wed, 29 May 2024 19:32:11 +0400 Subject: [PATCH 2/2] Edit pdf column widths --- .../OfficePackage/AbstractSaveToPdfGuarantor.cs | 2 +- .../OfficePackage/Implements/SaveToPdfGuarantor.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdfGuarantor.cs b/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdfGuarantor.cs index 8f817fb..fa625da 100644 --- a/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdfGuarantor.cs +++ b/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdfGuarantor.cs @@ -10,7 +10,7 @@ namespace ComputerShopBusinessLogic.OfficePackage 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 { "2cm", "2.5cm", "2cm", "2cm", "2cm", "4cm", "2.5cm", "3.5cm", "3.5cm", "2.5cm" }); + CreateTable(new List { "3cm", "2cm", "2cm", "2cm", "2cm", "2cm", "2.5cm", "2.5cm", "3cm", "4cm" }); CreateRow(new PdfRowParameters { diff --git a/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToPdfGuarantor.cs b/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToPdfGuarantor.cs index 3211f51..8505c13 100644 --- a/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToPdfGuarantor.cs +++ b/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToPdfGuarantor.cs @@ -49,7 +49,7 @@ namespace ComputerShopBusinessLogic.OfficePackage.Implements return; } var paragraph = _section.AddParagraph(pdfParagraph.Text); - paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.SpaceAfter = "0.5cm"; paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment); paragraph.Style = pdfParagraph.Style; }