переделано в List<Turple>, добавлен обработчик исключения на метод SavePdf
This commit is contained in:
parent
1aa25cc87c
commit
f45e4cfaee
1
SushiBar/FormReportOrders.Designer.cs
generated
1
SushiBar/FormReportOrders.Designer.cs
generated
@ -118,7 +118,6 @@
|
||||
}
|
||||
|
||||
#endregion
|
||||
private GroupBox groupBox1;
|
||||
private Panel panel;
|
||||
private DateTimePicker dateTimePickerDateTo;
|
||||
private DateTimePicker dateTimePickerDateFrom;
|
||||
|
@ -2,15 +2,6 @@
|
||||
using Microsoft.Reporting.WinForms;
|
||||
using SushiBarContracts.BindingModel;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SushiBarView.Reports
|
||||
{
|
||||
@ -53,9 +44,9 @@ namespace SushiBarView.Reports
|
||||
var source = new ReportDataSource("DataSetOrders", dataSource);
|
||||
reportViewer.LocalReport.DataSources.Clear();
|
||||
reportViewer.LocalReport.DataSources.Add(source);
|
||||
var parameters = new[] { new ReportParameter("ReportParameterPeriod",
|
||||
$"c {dateTimePickerDateFrom.Value.ToShortDateString()} по {dateTimePickerDateTo.Value.ToShortDateString()}")
|
||||
};
|
||||
var parameters = new[] { new ReportParameter("ReportParameterPeriod", $"c {dateTimePickerDateFrom.Value.ToShortDateString()} по {dateTimePickerDateTo.Value.ToShortDateString()}") };
|
||||
|
||||
// ЗДЕСЬ ПРОИСХОДИТ ОШИБКА И ВЫБРАСЫВАЕТСЯ ИСКЛЮЧЕНИЕ
|
||||
reportViewer.LocalReport.SetParameters(parameters);
|
||||
reportViewer.RefreshReport();
|
||||
_logger.LogInformation("Загрузка списка заказов на период {From}-{To}",
|
||||
@ -82,6 +73,7 @@ namespace SushiBarView.Reports
|
||||
{
|
||||
try
|
||||
{
|
||||
// ВОТ ЗДЕСЬ ТОЖЕ СРАЗУ ИСКЛЮЧЕНИЕ
|
||||
_logic.SaveOrdersToPdfFile(new ReportBindingModel
|
||||
{
|
||||
FileName = dialog.FileName,
|
||||
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.9.2" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
@ -11,8 +11,7 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
||||
private Document? _document;
|
||||
private Section? _section;
|
||||
private Table? _table;
|
||||
private static ParagraphAlignment
|
||||
GetParagraphAlignment(PdfParagraphAlignmentType type)
|
||||
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
@ -87,13 +86,29 @@ namespace SushiBarBusinessLogic.OfficePackage.Implements
|
||||
}
|
||||
}
|
||||
protected override void SavePdf(PdfInfo info)
|
||||
{
|
||||
if (_document != null)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,14 +41,14 @@ namespace SushiBarBusinessLogic
|
||||
var record = new ReportSushisComponentViewModel
|
||||
{
|
||||
ComponentName = component.ComponentName,
|
||||
Sushis = new List<(string, int)>(),
|
||||
Sushis = new List<Tuple<string, int>>(),
|
||||
TotalCount = 0
|
||||
};
|
||||
foreach (var sushi in sushis)
|
||||
{
|
||||
if (sushi.SushiComponents.ContainsKey(component.Id))
|
||||
{
|
||||
record.Sushis.Add(new (sushi.SushiName, sushi.SushiComponents[component.Id].Item2));
|
||||
record.Sushis.Add(new Tuple<string, int>(sushi.SushiName, sushi.SushiComponents[component.Id].Item2));
|
||||
record.TotalCount += sushi.SushiComponents[component.Id].Item2;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
{
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
public int TotalCount { get; set; }
|
||||
public List<(string Sushi, int Count)> Sushis { get; set; } = new();
|
||||
public List<Tuple<string, int>> Sushis { get; set; } = new();
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user