diff --git a/SushiBar/Program.cs b/SushiBar/Program.cs index 08d44e4..a86d1b0 100644 --- a/SushiBar/Program.cs +++ b/SushiBar/Program.cs @@ -7,9 +7,10 @@ using SushiBarBusinessLogic.OfficePackage; using SushiBarBusinessLogic.OfficePackage.Implements; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.StoragesContracts; -using SushiBarDatabaseImplement.Implements; +using SushiBarFileImplement.Implements; using SushiBarView; using SushiBarView.Reports; +using System.Text; namespace SushiBar { @@ -29,6 +30,9 @@ namespace SushiBar // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); var services = new ServiceCollection(); + // Добавлено для устранения ошибки с кодировкой при сохранении в PDF + // чтобы заработало нужно поставить NuGet пакет System.Text.Encoding.CodePages + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); Application.Run(_serviceProvider.GetRequiredService()); diff --git a/SushiBar/SushiBarView.csproj b/SushiBar/SushiBarView.csproj index 5a8e31d..1c49319 100644 --- a/SushiBar/SushiBarView.csproj +++ b/SushiBar/SushiBarView.csproj @@ -20,6 +20,7 @@ + diff --git a/SushiBarBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/SushiBarBusinessLogic/OfficePackage/Implements/SaveToPdf.cs index e9a7d3f..c18d035 100644 --- a/SushiBarBusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/SushiBarBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -1,8 +1,8 @@ п»їusing MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; using MigraDoc.Rendering; using SushiBarBusinessLogic.OfficePackage.HelperEnums; using SushiBarBusinessLogic.OfficePackage.HelperModels; -using MigraDoc.DocumentObjectModel.Tables; namespace SushiBarBusinessLogic.OfficePackage.Implements { @@ -87,28 +87,12 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements } protected override void SavePdf(PdfInfo info) { - if (_document != null) + var renderer = new PdfDocumentRenderer(true) { - var renderer = new PdfDocumentRenderer(true) - { - - Document = _document - }; - if (renderer.PdfDocument != null) - { - renderer.RenderDocument(); - renderer.PdfDocument.Save(info.FileName); - } - else - { - throw new NullReferenceException("renderer.RenderDocument is null"); - } - } - else - { - throw new NullReferenceException("_document is null"); - } - + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); } } } diff --git a/SushiBarDatabaseImplement/Implements/OrderStorage.cs b/SushiBarDatabaseImplement/Implements/OrderStorage.cs index e9e648f..e197396 100644 --- a/SushiBarDatabaseImplement/Implements/OrderStorage.cs +++ b/SushiBarDatabaseImplement/Implements/OrderStorage.cs @@ -17,15 +17,24 @@ namespace SushiBarDatabaseImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateTo.HasValue && !model.DateFrom.HasValue) - { - return new(); - } - using var context = new SushiBarDatabase(); + using var context = new SecuritySystemDatabase(); + var orders = context.Orders + .Include(x => x.Secure) + .Select(x => x.GetViewModel) + .ToList(); if (model.Id.HasValue) - return context.Orders.Where(x => x.Id == model.Id).Select(x => AccessViewModel(x.GetViewModel)).ToList(); - else - return context.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).Select(x => AccessViewModel(x.GetViewModel)).ToList(); + { + orders = orders.Where(x => x.Id == model.Id.Value).ToList(); + } + if (model.DateFrom.HasValue) + { + orders = orders.Where(x => x.DateCreate >= model.DateFrom.Value).ToList(); + } + if (model.DateTo.HasValue) + { + orders = orders.Where(x => x.DateCreate <= model.DateTo.Value).ToList(); + } + return orders; } public OrderViewModel? GetElement(OrderSearchModel model) { diff --git a/SushiBarFileImplement/Implements/OrderStorage.cs b/SushiBarFileImplement/Implements/OrderStorage.cs index d0cd47c..f31e443 100644 --- a/SushiBarFileImplement/Implements/OrderStorage.cs +++ b/SushiBarFileImplement/Implements/OrderStorage.cs @@ -20,11 +20,22 @@ namespace SushiBarFileImplement.Implements } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue) + var orders = source.Orders + .Select(x => x.GetViewModel) + .ToList(); + if (model.Id.HasValue) { - return new(); + orders = orders.Where(x => x.Id == model.Id.Value).ToList(); } - return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); + if (model.DateFrom.HasValue) + { + orders = orders.Where(x => x.DateCreate >= model.DateFrom.Value).ToList(); + } + if (model.DateTo.HasValue) + { + orders = orders.Where(x => x.DateCreate <= model.DateTo.Value).ToList(); + } + return orders; } public OrderViewModel? GetElement(OrderSearchModel model) { diff --git a/SushiBarListImplements/Implements/OrderStorage.cs b/SushiBarListImplements/Implements/OrderStorage.cs index 2f4337e..4e0a87d 100644 --- a/SushiBarListImplements/Implements/OrderStorage.cs +++ b/SushiBarListImplements/Implements/OrderStorage.cs @@ -28,19 +28,22 @@ namespace SushiBarListImplements.Implements public List GetFilteredList(OrderSearchModel model) { - var result = new List(); - if (model == null || !model.Id.HasValue) + var orders = _source.Orders + .Select(x => x.GetViewModel) + .ToList(); + if (model.Id.HasValue) { - return result; + orders = orders.Where(x => x.Id == model.Id.Value).ToList(); } - foreach (var order in _source.Orders) + if (model.DateFrom.HasValue) { - if (order.Id == model.Id) - { - result.Add(order.GetViewModel); - } + orders = orders.Where(x => x.DateCreate >= model.DateFrom.Value).ToList(); } - return result; + if (model.DateTo.HasValue) + { + orders = orders.Where(x => x.DateCreate <= model.DateTo.Value).ToList(); + } + return orders; } public OrderViewModel? GetElement(OrderSearchModel model)