diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index f9546ef..c09175f 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -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 logger, IOrderLogic orderLogic) + + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; + _reportLogic = reportLogic; } private void FormMain_Load(object sender, EventArgs e) { diff --git a/SushiBar/SushiBar/FormReportOrders.cs b/SushiBar/SushiBar/FormReportOrders.cs index f051362..25a462d 100644 --- a/SushiBar/SushiBar/FormReportOrders.cs +++ b/SushiBar/SushiBar/FormReportOrders.cs @@ -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); diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index fa3875e..b1eb43d 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -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(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -51,6 +55,11 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } diff --git a/SushiBar/SushiBar/SushiBarView.csproj b/SushiBar/SushiBar/SushiBarView.csproj index ccddc6d..f5411e8 100644 --- a/SushiBar/SushiBar/SushiBarView.csproj +++ b/SushiBar/SushiBar/SushiBarView.csproj @@ -9,13 +9,15 @@ + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ReportLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ReportLogic.cs new file mode 100644 index 0000000..4e63df3 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/ReportLogic.cs @@ -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; + } + + /// + /// Получение списка ингредиентов с указанием, в каких суши используются + /// + /// + public List GetSushiIngredient() + { + var ingredients = _ingredientStorage.GetFullList(); + + var sushiList = _sushiStorage.GetFullList(); + + var list = new List(); + + 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; + } + + /// + /// Получение списка заказов за определенный период + /// + /// + /// + public List 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(); + } + + /// + /// Сохранение суши в файл-Word + /// + /// + public void SaveListSushiToWordFile(ReportBindingModel model) + { + _saveToWord.CreateDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список суши", + ListSushi = _sushiStorage.GetFullList() + }); + } + + /// + /// Сохранение ингредиентов с указаеним суши в файл-Excel + /// + /// + public void SaveSushiIngredientToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Список суши", + SushiIngredients = GetSushiIngredient() + }); + } + + /// + /// Сохранение заказов в файл-Pdf + /// + /// + public void SaveOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Список заказов", + DateFrom = model.DateFrom!.Value, + DateTo = model.DateTo!.Value, + Orders = GetOrders(model) + }); + } + } +} diff --git a/SushiBar/SushiBarBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/SushiBar/SushiBarBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index ced3d3b..e78c5e1 100644 --- a/SushiBar/SushiBarBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/SushiBar/SushiBarBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -1,4 +1,5 @@ -using DocumentFormat.OpenXml; + +using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Office2010.Excel; using DocumentFormat.OpenXml.Office2013.Excel; using DocumentFormat.OpenXml.Packaging; diff --git a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs index 63214df..83bad5f 100644 --- a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs +++ b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs @@ -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; } } } diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs index 61dac62..a288b77 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs @@ -39,16 +39,19 @@ namespace SushiBarDatabaseImplement.Implements public List 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(); - return context.Orders - .Include(x => x.Sushi) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + else + { + return context.Orders + .Include(x => x.Sushi) + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } } public List GetFullList() {