From 501aa55c6326101aa11d06966959a3571f9b99b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Thu, 18 Apr 2024 18:01:18 +0400 Subject: [PATCH] Base.06 --- .../Implements/OrderStorage.cs | 13 ++++++++--- Diner/DinerView/FormReportOrders.Designer.cs | 10 +++++++++ Diner/DinerView/FormReportOrders.cs | 7 ++++-- Diner/DinerView/FormReportOrders.resx | 3 +++ .../BusinessLogic/ReportLogic.cs | 22 +++++++++---------- .../OfficePackage/AbstractSaveToWord.cs | 1 + .../OfficePackage/Implements/SaveToExcel.cs | 2 +- .../OfficePackage/Implements/SaveToWord.cs | 2 +- 8 files changed, 42 insertions(+), 18 deletions(-) diff --git a/Diner/DinerDataBaseImplement/Implements/OrderStorage.cs b/Diner/DinerDataBaseImplement/Implements/OrderStorage.cs index 07e2653..bd979cc 100644 --- a/Diner/DinerDataBaseImplement/Implements/OrderStorage.cs +++ b/Diner/DinerDataBaseImplement/Implements/OrderStorage.cs @@ -3,6 +3,7 @@ using DinerContracts.SearchModels; using DinerContracts.StoragesContracts; using DinerContracts.ViewModels; using DinerDataBaseImplement.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -38,11 +39,17 @@ namespace DinerDataBaseImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.ID.HasValue) { + using var context = new DinerDataBase(); + if (!model.ID.HasValue && (model.DateFrom == null || model.DateTo == null)) { return new(); } - using var context = new DinerDataBase(); - return context.Orders.Where(x => x.ID == model.ID).Select(GetViewModel).ToList(); + else { + return context.Orders + .Include(x => x.Snack) + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } } public List GetFullList() diff --git a/Diner/DinerView/FormReportOrders.Designer.cs b/Diner/DinerView/FormReportOrders.Designer.cs index ef9a494..288ea56 100644 --- a/Diner/DinerView/FormReportOrders.Designer.cs +++ b/Diner/DinerView/FormReportOrders.Designer.cs @@ -35,6 +35,7 @@ labelTo = new Label(); dateTimePickerFrom = new DateTimePicker(); labelFrom = new Label(); + reportViewer1 = new Microsoft.Reporting.WinForms.ReportViewer(); panel.SuspendLayout(); SuspendLayout(); // @@ -104,6 +105,14 @@ labelFrom.TabIndex = 0; labelFrom.Text = "С"; // + // reportViewer1 + // + reportViewer1.Location = new Point(0, 0); + reportViewer1.Name = "ReportViewer"; + reportViewer1.ServerReport.BearerToken = null; + reportViewer1.Size = new Size(396, 246); + reportViewer1.TabIndex = 0; + // // FormReportOrders // AutoScaleDimensions = new SizeF(7F, 15F); @@ -126,5 +135,6 @@ private DateTimePicker dateTimePickerFrom; private Label labelFrom; private Button buttonToPdf; + private Microsoft.Reporting.WinForms.ReportViewer reportViewer1; } } \ No newline at end of file diff --git a/Diner/DinerView/FormReportOrders.cs b/Diner/DinerView/FormReportOrders.cs index 4cf3b46..0e8628f 100644 --- a/Diner/DinerView/FormReportOrders.cs +++ b/Diner/DinerView/FormReportOrders.cs @@ -29,7 +29,7 @@ namespace DinerView { Dock = DockStyle.Fill }; - reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrders.rdlc", FileMode.Open)); + reportViewer.LocalReport.LoadReportDefinition(new FileStream("C:\\Users\\fedot\\source\\repos\\ISEbd-21.Fedotov.I.A.Diner\\Diner\\DinerView\\ReportOrders.rdlc", FileMode.Open)); Controls.Clear(); Controls.Add(reportViewer); Controls.Add(panel); @@ -49,13 +49,16 @@ namespace DinerView DateFrom = dateTimePickerFrom.Value, DateTo = dateTimePickerTo.Value }); - var source = new ReportDataSource("DataSerOrders", dataSource); + var source = new ReportDataSource("DataSetOrders", dataSource); reportViewer.LocalReport.DataSources.Clear(); reportViewer.LocalReport.DataSources.Add(source); var parameters = new[] { new ReportParameter("ReportParameterPeriod", $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value .ToShortDateString()}")}; reportViewer.LocalReport.SetParameters(parameters); + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), + dateTimePickerTo.Value.ToShortDateString()); } catch (Exception ex) { diff --git a/Diner/DinerView/FormReportOrders.resx b/Diner/DinerView/FormReportOrders.resx index af32865..fbd1d64 100644 --- a/Diner/DinerView/FormReportOrders.resx +++ b/Diner/DinerView/FormReportOrders.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/Diner/DineryBusinessLogic/BusinessLogic/ReportLogic.cs b/Diner/DineryBusinessLogic/BusinessLogic/ReportLogic.cs index ac0a93e..c05e2f6 100644 --- a/Diner/DineryBusinessLogic/BusinessLogic/ReportLogic.cs +++ b/Diner/DineryBusinessLogic/BusinessLogic/ReportLogic.cs @@ -37,7 +37,7 @@ namespace DineryBusinessLogic.BusinessLogic { return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = model.DateFrom, - DateTo = model.DateTo, + DateTo = model.DateTo }).Select(x => new ReportOrdersViewModel { ID = x.ID, @@ -82,16 +82,6 @@ namespace DineryBusinessLogic.BusinessLogic } public void SaveOrdersToPdfFile(ReportBindingModel model) - { - _saveToExcel.CreateReport(new ExcelInfo - { - FileName = model.FileName, - Title = "Список еды", - ProductComponents = GetProductComponent() - }); - } - - public void SaveProductComponentToExcelFile(ReportBindingModel model) { _saveToPdf.CreateDoc(new PdfInfo { @@ -102,5 +92,15 @@ namespace DineryBusinessLogic.BusinessLogic Orders = GetOrders(model) }); } + + public void SaveProductComponentToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Список еды", + ProductComponents = GetProductComponent() + }); + } } } diff --git a/Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 6ebc4d4..1cc1fdc 100644 --- a/Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -32,6 +32,7 @@ namespace DineryBusinessLogic.OfficePackage } }); } + SaveWord(info); } // Создание doc-файла protected abstract void CreateWord(WordInfo info); diff --git a/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index 6072906..15b89fd 100644 --- a/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -180,7 +180,7 @@ namespace DineryBusinessLogic.OfficePackage.Implements var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); var sheet = new Sheet() { - Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(workbookpart), + Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "Лист" }; diff --git a/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 0aebc33..98885f9 100644 --- a/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -104,7 +104,7 @@ namespace DineryBusinessLogic.OfficePackage.Implements } _docBody.AppendChild(CreateSectionProperties()); _wordDocument.MainDocumentPart!.Document.Save(); - _wordDocument.Clone(); + _wordDocument.Close(); } } }