From d51a55180c92b8f76e85d47425b43ae7dd53ea68 Mon Sep 17 00:00:00 2001 From: the Date: Fri, 19 May 2023 18:21:13 +0400 Subject: [PATCH] report grabbing logic --- .../BusinessLogics/ReportLogic.cs | 47 +++++++++-- .../OfficePackage/AbstractSaveToWord.cs | 82 +++++++++---------- .../HelperModels/WordInfoProvider.cs | 2 +- .../OfficePackage/Implements/SaveToWord.cs | 3 +- .../SearchModels/SupplySearchModel.cs | 1 + .../ViewModels/SupplyViewModel.cs | 2 + .../Implements/SupplyStorage.cs | 27 ++++-- 7 files changed, 104 insertions(+), 60 deletions(-) diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs index 2412ee0..6639d3b 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -37,15 +37,44 @@ namespace ComputerShopBusinessLogic.BusinessLogics public List GetComponentReceivings(List ids) { var result = new List(); - - List components = new List(); + foreach (int id in ids) { var component = _componentStorage.GetElement(new ComponentSearchModel() { Id = id, }); - if (component != null) components.Add(component); + var supplies = _supplyStorage.GetFilteredList(new() + { + ComponentId = id + }); + + var receivings = new List(); + + foreach(var supply in supplies) + { + if (supply.ReceivingId.HasValue) + { + var receiving = _receivingStorage.GetElement(new() { Id = supply.ReceivingId.Value }); + if (receiving != null && receivings.Contains(receiving)) + { + receivings.Add(receiving); + } + } + } + var receivingnames = new List(); + foreach (var receiving in receivings) + { + receivingnames.Add($"Id: {receiving.Id}. Date: {receiving.Status}."); + } + if(receivingnames.Count > 0 && component != null) + { + result.Add(new() + { + ComponentName = component.ComponentName, + Receivings = receivingnames + }); + } } @@ -54,12 +83,12 @@ namespace ComputerShopBusinessLogic.BusinessLogics public void SaveReceivingComponentsToWordFile(ReportBindingModel model) { - //_saveToWord.CreateDoc(new WordInfoProvider - //{ - // FileName = model.FileName, - // Title = "Список получений по компонентам", - // ComponentReceivings = GetComponentReceivings(model.Ids) - //}); + _saveToWord.CreateDoc(new WordInfoProvider + { + FileName = model.FileName, + Title = "Список получений по компонентам", + ComponentReceivings = GetComponentReceivings(model.Ids) + }); } public void SaveReceivingComponentsToXmlFile(ReportBindingModel mode) diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 2e8f9ec..9295bd4 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -12,51 +12,51 @@ namespace ComputerShopBusinessLogic.OfficePackage { public void CreateDoc(WordInfoProvider info) { - //CreateWord(info); + CreateWord(info); - //CreateParagraph(new WordParagraph - //{ - // Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, - // TextProperties = new WordTextProperties - // { - // Size = "24", - // JustificationType = WordJustificationType.Center - // } - //}); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); - //foreach (var mc in info.MemberConferences) - //{ - // CreateParagraph(new WordParagraph - // { - // Texts = new List<(string, WordTextProperties)> - // { (mc.MemberFIO, new WordTextProperties { Size = "20", Bold=true})}, - // TextProperties = new WordTextProperties - // { - // Size = "24", - // JustificationType = WordJustificationType.Both - // } - // }); + foreach (var mc in info.MemberConferences) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { (mc.MemberFIO, new WordTextProperties { Size = "20", Bold=true})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); - // foreach (var conference in mc.Conferences) - // { - // CreateParagraph(new WordParagraph - // { - // Texts = new List<(string, WordTextProperties)> - // { (conference.Item1 + " - ", new WordTextProperties { Size = "16", Bold=false}), - // (conference.Item2.ToShortDateString(), new WordTextProperties { Size = "16", Bold=false})}, - // TextProperties = new WordTextProperties - // { - // Size = "24", - // JustificationType = WordJustificationType.Both - // } - // }); - // } - //} - //SaveWord(info); + foreach (var conference in mc.Conferences) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { (conference.Item1 + " - ", new WordTextProperties { Size = "16", Bold=false}), + (conference.Item2.ToShortDateString(), new WordTextProperties { Size = "16", Bold=false})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + } + SaveWord(info); } - //protected abstract void CreateWord(WordInfoOrganiser info); - //protected abstract void CreateParagraph(WordParagraph paragraph); - //protected abstract void SaveWord(WordInfoOrganiser info); + protected abstract void CreateWord(WordInfoOrganiser info); + protected abstract void CreateParagraph(WordParagraph paragraph); + protected abstract void SaveWord(WordInfoOrganiser info); } } diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/WordInfoProvider.cs b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/WordInfoProvider.cs index fb69f23..31b5504 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/WordInfoProvider.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/WordInfoProvider.cs @@ -11,6 +11,6 @@ namespace ComputerShopBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public Dictionary> ComponentReceivings { get; set; } = new(); + public List ComponentReceivings { get; set; } = new(); } } diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs index e6c4067..dca87b5 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -6,7 +6,8 @@ using System.Threading.Tasks; namespace ComputerShopBusinessLogic.OfficePackage.Implements { - public class SaveToWord + public class SaveToWord : AbstractSaveToWord { + } } diff --git a/ComputerShopProvider/ComputerShopContracts/SearchModels/SupplySearchModel.cs b/ComputerShopProvider/ComputerShopContracts/SearchModels/SupplySearchModel.cs index f611347..74abc66 100644 --- a/ComputerShopProvider/ComputerShopContracts/SearchModels/SupplySearchModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/SearchModels/SupplySearchModel.cs @@ -12,5 +12,6 @@ namespace ComputerShopContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public ComponentSearchModel? Component { get; set; } + public int? ComponentId { get; set; } } } diff --git a/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs index 3687f9e..c94bc45 100644 --- a/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs @@ -28,6 +28,8 @@ namespace ComputerShopContracts.ViewModels set; } = new(); + public int? ReceivingId { get; set; } + diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/SupplyStorage.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/SupplyStorage.cs index 72825cd..f0df5da 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/SupplyStorage.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/SupplyStorage.cs @@ -47,18 +47,29 @@ namespace ComputerShopDatabaseImplement.Implements public List GetFilteredList(SupplySearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ComponentId.HasValue) { return new(); } using var context = new ComputerShopDatabase(); - return context.Supplies - .Include(x => x.Orders) - .ThenInclude(x => x.Order) - .Where(x => x.Id == model.Id) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); + if(model.ComponentId.HasValue) + return context.Supplies + .Include(x => x.Orders) + .ThenInclude(x => x.Order) + .Where(x => x.Id == model.Id) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + else + return context.Supplies + .Include(x => x.Orders) + .ThenInclude(x => x.Order) + .Include(x => x.ComponentSupplies) + .ThenInclude(x => x.Component) + .Where(x => x.ComponentSupplies.Any(x => x.ComponentId == model.ComponentId)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList()