This commit is contained in:
Илья Федотов 2024-04-18 18:01:18 +04:00
parent db24ffdda3
commit 501aa55c63
8 changed files with 42 additions and 18 deletions

View File

@ -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<OrderViewModel> 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<OrderViewModel> GetFullList()

View File

@ -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;
}
}

View File

@ -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)
{

View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="reportViewer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -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()
});
}
}
}

View File

@ -32,6 +32,7 @@ namespace DineryBusinessLogic.OfficePackage
}
});
}
SaveWord(info);
}
// Создание doc-файла
protected abstract void CreateWord(WordInfo info);

View File

@ -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 = "Лист"
};

View File

@ -104,7 +104,7 @@ namespace DineryBusinessLogic.OfficePackage.Implements
}
_docBody.AppendChild(CreateSectionProperties());
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Clone();
_wordDocument.Close();
}
}
}