From a6e97267aa0e2d8269097a222bd3885a8de877b1 Mon Sep 17 00:00:00 2001 From: FLARJ <122087628+FLARJ@users.noreply.github.com> Date: Thu, 18 May 2023 17:03:38 +0400 Subject: [PATCH] fix ReportLogic --- .../BusinessLogicsContracts/IReportLogic.cs | 13 +-- .../SearchModels/HeadsetSearchModel.cs | 5 +- .../ViewModel/HeadsetViewModel.cs | 4 +- .../ViewModel/OrdersViewModel.cs | 1 + .../ViewModel/ReportSalesSalonViewModel.cs | 3 +- .../BusinessLogic/ReportLogic.cs | 80 ++++++++++++++++--- .../BusinessLogic/SalesSalonLogic.cs | 2 +- .../OfficePackage/AbstractSaveToPdfManager.cs | 5 +- .../HelperModels/ExcelInfoMaster.cs | 2 +- .../HelperModels/PdfInfoManager.cs | 6 +- .../Implements/OrderStorage.cs | 2 +- .../Models/Orders.cs | 2 +- 12 files changed, 100 insertions(+), 25 deletions(-) diff --git a/FurnitureFactory/FurnitureContracts/BusinessLogicsContracts/IReportLogic.cs b/FurnitureFactory/FurnitureContracts/BusinessLogicsContracts/IReportLogic.cs index 8f3f597..9692527 100644 --- a/FurnitureFactory/FurnitureContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/FurnitureFactory/FurnitureContracts/BusinessLogicsContracts/IReportLogic.cs @@ -14,19 +14,20 @@ namespace FurnitureContracts.BusinessLogicsContracts List GetSalesSalons(ReportBindingModel model); + List GetHeadsetMaterial(ReportBindingModel model); - List GetLessonTask(ReportBindingModel model); + List GetHeadsetModuleTask(ReportBindingModel model); - void SaveInterestLessonToWordFile(ReportBindingModel model); + void SaveSalesSalonHeadsetModuleToWordFile(ReportBindingModel model); - void SaveInterestLessonToExcelFile(ReportBindingModel model); + void SaveSalesSalonHeadsetModuleToExcelFile(ReportBindingModel model); - void SaveInterestsToPdfFile(ReportBindingModel model); + void SaveSalesSalonsToPdfFile(ReportBindingModel model); void SaveHeadsetMaterialToWordFile(ReportBindingModel model); @@ -35,5 +36,7 @@ namespace FurnitureContracts.BusinessLogicsContracts void SaveFurnitureHeadsetModuleToPdfFile(ReportBindingModel model); - } + + void SaveOrdersHeadsetToPdfFile(ReportBindingModel model); + } } diff --git a/FurnitureFactory/FurnitureContracts/SearchModels/HeadsetSearchModel.cs b/FurnitureFactory/FurnitureContracts/SearchModels/HeadsetSearchModel.cs index 9e9d18a..e367760 100644 --- a/FurnitureFactory/FurnitureContracts/SearchModels/HeadsetSearchModel.cs +++ b/FurnitureFactory/FurnitureContracts/SearchModels/HeadsetSearchModel.cs @@ -12,5 +12,8 @@ namespace FurnitureContracts.SearchModels public int? Id { get; set; } public int? ManagerId { get; set; } public string? Size { get; set; } - } + public DateTime? DateFrom { get; set; } + + public DateTime? DateTo { get; set; } + } } diff --git a/FurnitureFactory/FurnitureContracts/ViewModel/HeadsetViewModel.cs b/FurnitureFactory/FurnitureContracts/ViewModel/HeadsetViewModel.cs index 2a543a9..64651f4 100644 --- a/FurnitureFactory/FurnitureContracts/ViewModel/HeadsetViewModel.cs +++ b/FurnitureFactory/FurnitureContracts/ViewModel/HeadsetViewModel.cs @@ -14,8 +14,10 @@ namespace FurnitureContracts.ViewModel public string? Title { get; set; } = string.Empty; [DisplayName("Цена")] public int Cost { get; set; } + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } - [DisplayName("Размер")] + [DisplayName("Размер")] public string Size { get; set; } = string.Empty; public int Id { get; set; } public int HeadsetModuleId { get; set; } diff --git a/FurnitureFactory/FurnitureContracts/ViewModel/OrdersViewModel.cs b/FurnitureFactory/FurnitureContracts/ViewModel/OrdersViewModel.cs index 2c72ba4..2bdf928 100644 --- a/FurnitureFactory/FurnitureContracts/ViewModel/OrdersViewModel.cs +++ b/FurnitureFactory/FurnitureContracts/ViewModel/OrdersViewModel.cs @@ -14,6 +14,7 @@ namespace FurnitureContracts.ViewModel [DisplayName("Название")] public string Title { get; set; } = string.Empty; + [DisplayName("Дата заказа")] public DateTime Date { get; set; } diff --git a/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonViewModel.cs b/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonViewModel.cs index fff3c88..2a7ed26 100644 --- a/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonViewModel.cs +++ b/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonViewModel.cs @@ -12,5 +12,6 @@ namespace FurnitureContracts.ViewModel public string OrderTitle { get; set; } = string.Empty; public DateTime DateCreateOrder { get; set; } public string HeadsetTitle { get; set; } = string.Empty; - } + public DateTime DateCreateHeadset { get; set; } + } } diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/ReportLogic.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/ReportLogic.cs index b4bc9c1..beaed94 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/ReportLogic.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/ReportLogic.cs @@ -16,7 +16,7 @@ namespace FurnitureFactoryBusinessLogic.BusinessLogic { public class ReportLogic : IReportLogic { - private readonly ISalesSalonsStorage _interestStorage; + private readonly ISalesSalonsStorage _salesSalonStorage; private readonly IMaterialStorage _materialStorage; private readonly IOrdersStorage _orderStorage; private readonly IHeadsetStorage _headsetStorage; @@ -37,7 +37,7 @@ namespace FurnitureFactoryBusinessLogic.BusinessLogic public ReportLogic(ISalesSalonsStorage salessalonStorage, IMaterialStorage materialStorage, IOrdersStorage orderStorage, IHeadsetStorage headsetStorage, IHeadsetModuleStorage headsetmoduleStorage, IFurnitureStorage furnitureStorage, AbstractSaveToExcelMaster saveToExcelMaster, AbstractSaveToWordMaster saveToWordMaster, AbstractSaveToPdfMaster saveToPdfMaster, AbstractSaveToExcelManager saveToExcelManager, AbstractSaveToWordManager saveToWordManager, AbstractSaveToPdfManager saveToPdfManager) { - _interestStorage = salessalonStorage; + _salesSalonStorage = salessalonStorage; _materialStorage = materialStorage; _orderStorage = orderStorage; _headsetStorage = headsetStorage; @@ -121,7 +121,7 @@ namespace FurnitureFactoryBusinessLogic.BusinessLogic public List GetSalesSalons(ReportBindingModel model) { - var salessalons = _interestStorage.GetFilteredList(new SalesSalonsSearchModel + var salessalons = _salesSalonStorage.GetFilteredList(new SalesSalonsSearchModel { ManagerId = model.ManagerId }); @@ -163,7 +163,55 @@ namespace FurnitureFactoryBusinessLogic.BusinessLogic return list; } - public List GetLessonTask(ReportBindingModel model) + public List GetSalesSalonsTask(ReportBindingModel model) + { + var interests = _salesSalonStorage.GetFilteredList(new SalesSalonsSearchModel + { + ManagerId = model.ManagerId + }); + var orders = _orderStorage.GetFilteredList(new OrderSearchModel + { + ManagerId = model.ManagerId, + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); + var headsets = _headsetStorage.GetFilteredList(new HeadsetSearchModel + { + ManagerId = model.ManagerId, + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); + var list = new List(); + foreach (OrdersViewModel order in orders) + { + + foreach (HeadsetViewModel headset in headsets) + { + + foreach (int interestOrder in order.OrdersSalesSalons.Keys) + { + if (headset.HeadsetSalesSalons.ContainsKey(interestOrder)) + { + list.Add(new ReportSalesSalonViewModel + { + SalesSalonTitle = interests.FirstOrDefault(x => x.Id == interestOrder).ToString(), + OrderTitle = order.Title, + DateCreateOrder = order.Date, + HeadsetTitle = headset.Title, + DateCreateHeadset = headset.DateCreate + }); + } + + } + } + + + } + + return list; + } + + public List GetHeadsetModuleTask(ReportBindingModel model) { var headsetmodules = _headsetmoduleStorage.GetFilteredList(new HeadsetModuleSearchModel @@ -206,6 +254,7 @@ namespace FurnitureFactoryBusinessLogic.BusinessLogic return list; } + public void SaveHeadsetMaterialToExcelFile(ReportBindingModel model) { _saveToExcelMaster.CreateReport(new ExcelInfoMaster @@ -226,7 +275,7 @@ namespace FurnitureFactoryBusinessLogic.BusinessLogic }); } - public void SaveInterestLessonToExcelFile(ReportBindingModel model) + public void SaveSalesSalonHeadsetModuleToExcelFile(ReportBindingModel model) { _saveToExcelManager.CreateReport(new ExcelInfoManager { @@ -236,7 +285,7 @@ namespace FurnitureFactoryBusinessLogic.BusinessLogic }); } - public void SaveInterestLessonToWordFile(ReportBindingModel model) + public void SaveSalesSalonHeadsetModuleToWordFile(ReportBindingModel model) { _saveToWordManager.CreateDoc(new WordInfoManager { @@ -246,7 +295,7 @@ namespace FurnitureFactoryBusinessLogic.BusinessLogic }); } - public void SaveInterestsToPdfFile(ReportBindingModel model) + public void SaveSalesSalonsToPdfFile(ReportBindingModel model) { _saveToPdfManager.CreateDoc(new PdfInfoManager { @@ -264,8 +313,21 @@ namespace FurnitureFactoryBusinessLogic.BusinessLogic Title = "Список модулей гарнитур и мебели со сохожими материалами", DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc), DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc), - FurnitureHeadsetModule = GetLessonTask(model) + FurnitureHeadsetModule = GetHeadsetModuleTask(model) }); } - } + + public void SaveOrdersHeadsetToPdfFile(ReportBindingModel model) + { + _saveToPdfManager.CreateDoc(new PdfInfoManager + { + FileName = model.FileName, + Title = "Список заказов и гарнитур со схожими материалами", + DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc), + DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc), + SalesSalons = GetSalesSalonsTask(model) + }); + } + + } } diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/SalesSalonLogic.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/SalesSalonLogic.cs index 9a265a3..520e171 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/SalesSalonLogic.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogic/SalesSalonLogic.cs @@ -104,7 +104,7 @@ namespace FurnitureFactoryBusinessLogic.BusinessLogic { throw new ArgumentNullException("Неверно задан идентификатор менеджера", nameof(model.ManagerId)); } - _logger.LogInformation("Interest. Name:{Name}.Address{Address}.ManagerId:{ManagerId}. Id: {Id}", model.Name, model.Address, model.ManagerId, model.Id); + _logger.LogInformation("SalesSalon. Name:{Name}.Address{Address}.ManagerId:{ManagerId}. Id: {Id}", model.Name, model.Address, model.ManagerId, model.Id); var element = _salesSalonStorage.GetElement(new SalesSalonsSearchModel { Name = model.Name, diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/AbstractSaveToPdfManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/AbstractSaveToPdfManager.cs index d622635..4c823d1 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/AbstractSaveToPdfManager.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/AbstractSaveToPdfManager.cs @@ -13,9 +13,10 @@ namespace FurnitureFactoryBusinessLogic.OfficePackage.Implements public void CreateDoc(PdfInfoManager info) { CreatePdf(info); - CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + 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", "3cm", "6cm", "3cm", "3cm", "6cm", "6cm" }); + CreateTable(new List { "2cm", "3cm", "6cm", "3cm", "3cm", "6cm", "6cm" }); CreateRow(new PdfRowParameters { diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfoMaster.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfoMaster.cs index fd694d1..20494ac 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfoMaster.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfoMaster.cs @@ -13,6 +13,6 @@ namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; - public List HeadsetMaterials { get; set; } + public List HeadsetMaterials { get; set; } = new(); } } diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/PdfInfoManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/PdfInfoManager.cs index 6c58c2a..984195d 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/PdfInfoManager.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/PdfInfoManager.cs @@ -13,9 +13,11 @@ namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; - public DateTime Date { get; set; } + public DateTime DateFrom { get; set; } - public List SalesSalons { get; set; } = new(); + public DateTime DateTo { get; set; } + + public List SalesSalons { get; set; } = new(); } } diff --git a/FurnitureFactory/FurnitureFactoryDataBaseImplement/Implements/OrderStorage.cs b/FurnitureFactory/FurnitureFactoryDataBaseImplement/Implements/OrderStorage.cs index 25d453e..c057a4c 100644 --- a/FurnitureFactory/FurnitureFactoryDataBaseImplement/Implements/OrderStorage.cs +++ b/FurnitureFactory/FurnitureFactoryDataBaseImplement/Implements/OrderStorage.cs @@ -95,7 +95,7 @@ namespace FurnitureFactoryDataBaseImplements.Implements } order.Update(model); context.SaveChanges(); - order.UpdateInterests(context, model); + order.UpdateSalesSalons(context, model); transaction.Commit(); return order.GetViewModel; } diff --git a/FurnitureFactory/FurnitureFactoryDataBaseImplement/Models/Orders.cs b/FurnitureFactory/FurnitureFactoryDataBaseImplement/Models/Orders.cs index 2f8755c..638fd5c 100644 --- a/FurnitureFactory/FurnitureFactoryDataBaseImplement/Models/Orders.cs +++ b/FurnitureFactory/FurnitureFactoryDataBaseImplement/Models/Orders.cs @@ -75,7 +75,7 @@ namespace FurnitureFactoryDataBaseImplement.Models OrdersSalesSalons = OrdersSalesSalons }; - public void UpdateInterests(FurnitureDataBase context, OrdersBindingModel model) + public void UpdateSalesSalons(FurnitureDataBase context, OrdersBindingModel model) { var ordersSalesSalons = context.OrdersSalesSalons.Where(rec => rec.OrdersId == model.Id).ToList(); if (ordersSalesSalons != null && OrdersSalesSalons.Count > 0)