This commit is contained in:
Игорь Гордеев 2024-04-18 22:04:00 +04:00
parent 93a5ffc103
commit 86f99e2b55
8 changed files with 168 additions and 13 deletions

View File

@ -1,7 +1,6 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarDataModels.Enums;
namespace SushiBarView
{
@ -10,11 +9,13 @@ namespace SushiBarView
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{

View File

@ -23,7 +23,7 @@ namespace SushiBarView
{
Dock = DockStyle.Fill
};
reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrders.rdlc", FileMode.Open));
reportViewer.LocalReport.LoadReportDefinition(new FileStream("C:\\Poly\\RPP\\SushiBar\\SushiBar\\SushiBar\\ReportOrders.rdlc", FileMode.Open));
Controls.Clear();
Controls.Add(reportViewer);
Controls.Add(panel);

View File

@ -2,6 +2,8 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using SushiBarBusinessLogic.BusinessLogics;
using SushiBarBusinessLogic.OfficePackage.Implements;
using SushiBarBusinessLogic.OfficePackage;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.StoragesContracts;
using SushiBarDatabaseImplement.Implements;
@ -42,6 +44,8 @@ namespace SushiBarView
services.AddTransient<IIngredientLogic, IngredientLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ISushiLogic, SushiLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormIngredient>();
services.AddTransient<FormIngredients>();
@ -51,6 +55,11 @@ namespace SushiBarView
services.AddTransient<FormListSushi>();
services.AddTransient<FormReportSushiIngredients>();
services.AddTransient<FormReportOrders>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
}
}

View File

@ -9,13 +9,15 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="4.5.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.ReportViewer.WinForms" Version="10.0.40219.1" />
<PackageReference Include="ReportViewerCore.WinForms" Version="15.1.17" />
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,136 @@
using SushiBarBusinessLogic.OfficePackage.HelperModels;
using SushiBarBusinessLogic.OfficePackage;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
namespace SushiBarBusinessLogic.BusinessLogics
{
public class ReportLogic : IReportLogic
{
private readonly IIngredientStorage _ingredientStorage;
private readonly ISushiStorage _sushiStorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(ISushiStorage productStorage, IIngredientStorage ingredientStorage, IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{
_sushiStorage = productStorage;
_ingredientStorage = ingredientStorage;
_orderStorage = orderStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
/// <summary>
/// Получение списка ингредиентов с указанием, в каких суши используются
/// </summary>
/// <returns></returns>
public List<ReportSushiIngredientViewModel> GetSushiIngredient()
{
var ingredients = _ingredientStorage.GetFullList();
var sushiList = _sushiStorage.GetFullList();
var list = new List<ReportSushiIngredientViewModel>();
foreach (var sushi in sushiList)
{
var record = new ReportSushiIngredientViewModel
{
SushiName = sushi.SushiName,
Ingredients = new(),
TotalCount = 0
};
foreach (var ingredient in ingredients)
{
if (sushi.SushiIngredients.ContainsKey(ingredient.Id))
{
record.Ingredients.Add(new(ingredient.IngredientName,
sushi.SushiIngredients[ingredient.Id].Item2));
record.TotalCount += sushi.SushiIngredients[ingredient.Id].Item2;
}
}
list.Add(record);
}
return list;
}
/// <summary>
/// Получение списка заказов за определенный период
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
{
return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo })
.Select(x => new ReportOrdersViewModel
{
Id = x.Id,
DateCreate = x.DateCreate,
SushiName = x.SushiName,
OrderStatus = x.Status.ToString(),
Sum = x.Sum
})
.ToList();
}
/// <summary>
/// Сохранение суши в файл-Word
/// </summary>
/// <param name="model"></param>
public void SaveListSushiToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список суши",
ListSushi = _sushiStorage.GetFullList()
});
}
/// <summary>
/// Сохранение ингредиентов с указаеним суши в файл-Excel
/// </summary>
/// <param name="model"></param>
public void SaveSushiIngredientToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список суши",
SushiIngredients = GetSushiIngredient()
});
}
/// <summary>
/// Сохранение заказов в файл-Pdf
/// </summary>
/// <param name="model"></param>
public void SaveOrdersToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Список заказов",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
Orders = GetOrders(model)
});
}
}
}

View File

@ -1,4 +1,5 @@
using DocumentFormat.OpenXml;

using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Office2010.Excel;
using DocumentFormat.OpenXml.Office2013.Excel;
using DocumentFormat.OpenXml.Packaging;

View File

@ -1,8 +1,11 @@
namespace SushiBarContracts.SearchModels

namespace SushiBarContracts.SearchModels
{
public class OrderSearchModel
{
public int? Id { get; set; }
public DateTime? DateTo { get; set; }
public DateTime? DateFrom { get; set; }
}
}

View File

@ -39,17 +39,20 @@ namespace SushiBarDatabaseImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
using var context = new SushiBarDatabase();
if (!model.Id.HasValue && (model.DateFrom == null || model.DateTo == null))
{
return new();
}
using var context = new SushiBarDatabase();
else
{
return context.Orders
.Include(x => x.Sushi)
.Where(x => x.Id == model.Id)
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
}
public List<OrderViewModel> GetFullList()
{
using var context = new SushiBarDatabase();