From d27c4e7653f6fd280d88c3e87a8441e1183e94c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Sat, 17 Feb 2024 18:51:42 +0400 Subject: [PATCH 1/3] done hard 2 --- Pizzeria/Pizzeria.sln | 10 +- .../BusinessLogics/OrderLogic.cs | 22 +- .../BusinessLogics/ShopLogic.cs | 176 ++++++++++++++ .../BindingModels/ShopBindingModel.cs | 19 ++ .../BindingModels/SupplyBindingModel.cs | 16 ++ .../BusinessLogicsContracts/IShopLogic.cs | 22 ++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../SearchModels/SupplySearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 23 ++ .../ViewModels/ShopViewModel.cs | 24 ++ .../PizzeriaDataModels/Models/IShopModel.cs | 19 ++ .../PizzeriaDataModels/Models/ISupplyModel.cs | 15 ++ .../DataFileSingleton.cs | 13 +- .../Implements/ShopStorage.cs | 154 ++++++++++++ Pizzeria/PizzeriaFileImplement/Models/Shop.cs | 111 +++++++++ .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 123 ++++++++++ Pizzeria/PizzeriaListImplement/Models/Shop.cs | 59 +++++ .../PizzeriaView/FormCreateSupply.Designer.cs | 143 +++++++++++ Pizzeria/PizzeriaView/FormCreateSupply.cs | 99 ++++++++ Pizzeria/PizzeriaView/FormCreateSupply.resx | 120 ++++++++++ Pizzeria/PizzeriaView/FormMain.Designer.cs | 48 +++- Pizzeria/PizzeriaView/FormMain.cs | 27 +++ .../PizzeriaView/FormSellPizza.Designer.cs | 120 ++++++++++ Pizzeria/PizzeriaView/FormSellPizza.cs | 88 +++++++ Pizzeria/PizzeriaView/FormShop.Designer.cs | 222 ++++++++++++++++++ Pizzeria/PizzeriaView/FormShop.cs | 127 ++++++++++ Pizzeria/PizzeriaView/FormShop.resx | 120 ++++++++++ Pizzeria/PizzeriaView/FormShops.Designer.cs | 130 ++++++++++ Pizzeria/PizzeriaView/FormShops.cs | 117 +++++++++ Pizzeria/PizzeriaView/FormShops.resx | 120 ++++++++++ Pizzeria/PizzeriaView/Program.cs | 6 + 32 files changed, 2306 insertions(+), 17 deletions(-) create mode 100644 Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 Pizzeria/PizzeriaContracts/BindingModels/ShopBindingModel.cs create mode 100644 Pizzeria/PizzeriaContracts/BindingModels/SupplyBindingModel.cs create mode 100644 Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 Pizzeria/PizzeriaContracts/SearchModels/ShopSearchModel.cs create mode 100644 Pizzeria/PizzeriaContracts/SearchModels/SupplySearchModel.cs create mode 100644 Pizzeria/PizzeriaContracts/StoragesContracts/IShopStorage.cs create mode 100644 Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs create mode 100644 Pizzeria/PizzeriaDataModels/Models/IShopModel.cs create mode 100644 Pizzeria/PizzeriaDataModels/Models/ISupplyModel.cs create mode 100644 Pizzeria/PizzeriaFileImplement/Implements/ShopStorage.cs create mode 100644 Pizzeria/PizzeriaFileImplement/Models/Shop.cs create mode 100644 Pizzeria/PizzeriaListImplement/Implements/ShopStorage.cs create mode 100644 Pizzeria/PizzeriaListImplement/Models/Shop.cs create mode 100644 Pizzeria/PizzeriaView/FormCreateSupply.Designer.cs create mode 100644 Pizzeria/PizzeriaView/FormCreateSupply.cs create mode 100644 Pizzeria/PizzeriaView/FormCreateSupply.resx create mode 100644 Pizzeria/PizzeriaView/FormSellPizza.Designer.cs create mode 100644 Pizzeria/PizzeriaView/FormSellPizza.cs create mode 100644 Pizzeria/PizzeriaView/FormShop.Designer.cs create mode 100644 Pizzeria/PizzeriaView/FormShop.cs create mode 100644 Pizzeria/PizzeriaView/FormShop.resx create mode 100644 Pizzeria/PizzeriaView/FormShops.Designer.cs create mode 100644 Pizzeria/PizzeriaView/FormShops.cs create mode 100644 Pizzeria/PizzeriaView/FormShops.resx diff --git a/Pizzeria/Pizzeria.sln b/Pizzeria/Pizzeria.sln index af06c4b..3bb888e 100644 --- a/Pizzeria/Pizzeria.sln +++ b/Pizzeria/Pizzeria.sln @@ -13,7 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaDataModels", "Pizze EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{190E2EDD-BFA6-4213-9F8A-1B1D4FBBB8E4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaFileImplement", "PizzeriaFileImplement\PizzeriaFileImplement.csproj", "{357BD3B9-6100-469F-814F-7DABB2DDA33B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaFileImplement", "PizzeriaFileImplement\PizzeriaFileImplement.csproj", "{4B58D113-7C25-4795-8242-814C8288D30C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -41,10 +41,10 @@ Global {190E2EDD-BFA6-4213-9F8A-1B1D4FBBB8E4}.Debug|Any CPU.Build.0 = Debug|Any CPU {190E2EDD-BFA6-4213-9F8A-1B1D4FBBB8E4}.Release|Any CPU.ActiveCfg = Release|Any CPU {190E2EDD-BFA6-4213-9F8A-1B1D4FBBB8E4}.Release|Any CPU.Build.0 = Release|Any CPU - {357BD3B9-6100-469F-814F-7DABB2DDA33B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {357BD3B9-6100-469F-814F-7DABB2DDA33B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {357BD3B9-6100-469F-814F-7DABB2DDA33B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {357BD3B9-6100-469F-814F-7DABB2DDA33B}.Release|Any CPU.Build.0 = Release|Any CPU + {4B58D113-7C25-4795-8242-814C8288D30C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4B58D113-7C25-4795-8242-814C8288D30C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4B58D113-7C25-4795-8242-814C8288D30C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4B58D113-7C25-4795-8242-814C8288D30C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/OrderLogic.cs index 16d1722..d0991cd 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/OrderLogic.cs @@ -17,10 +17,13 @@ namespace PizzeriaBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IShopStorage _shopStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage) { _logger = logger; _orderStorage = orderStorage; + _shopStorage = shopStorage; } public List? ReadList(OrderSearchModel? model) { @@ -60,6 +63,23 @@ namespace PizzeriaBusinessLogic.BusinessLogics public bool DeliveryOrder(OrderBindingModel model) { + var order = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id, + }); + if (order == null) + { + throw new ArgumentNullException(nameof(order)); + } + if (!_shopStorage.RestockingShops(new SupplyBindingModel + { + PizzaId = order.PizzaId, + Count = order.Count + })) + { + throw new ArgumentException("Недостаточно места"); + } + return ChangeStatus(model, OrderStatus.Выдан); } diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ShopLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..5e2628e --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,176 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + private readonly IPizzaStorage _pizzaStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage, IPizzaStorage pizzaStorage) + { + _logger = logger; + _shopStorage = shopStorage; + _pizzaStorage = pizzaStorage; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool MakeSupply(SupplyBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий должно быть больше 0"); + } + var shop = _shopStorage.GetElement(new ShopSearchModel + { + Id = model.ShopId + }); + if (shop == null) + { + throw new ArgumentException("Магазина не существует"); + } + if (shop.ShopPizzas.ContainsKey(model.PizzaId)) + { + var oldValue = shop.ShopPizzas[model.PizzaId]; + oldValue.Item2 += model.Count; + shop.ShopPizzas[model.PizzaId] = oldValue; + } + else + { + var pizza = _pizzaStorage.GetElement(new PizzaSearchModel + { + Id = model.PizzaId + }); + if (pizza == null) + { + throw new ArgumentException($"Поставка: Товар с id:{model.PizzaId} не найденн"); + } + shop.ShopPizzas.Add(model.PizzaId, (pizza, model.Count)); + } + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Adress)) + { + throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress)); + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Adres:{Adres}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + public bool Sale(SupplySearchModel model) + { + if (!model.PizzaId.HasValue || !model.Count.HasValue) + { + return false; + } + _logger.LogInformation("Check pizza count in all shops"); + if (_shopStorage.Sale(model)) + { + _logger.LogInformation("Selling sucsess"); + return true; + } + _logger.LogInformation("Selling failed"); + return false; + } + } +} diff --git a/Pizzeria/PizzeriaContracts/BindingModels/ShopBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..0449b6b --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,19 @@ +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + public string Adress { get; set; } = string.Empty; + public DateTime OpeningDate { get; set; } = DateTime.Now; + public Dictionary ShopPizzas { get; set; } = new(); + public int PizzaMaxCount { get; set; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/BindingModels/SupplyBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/SupplyBindingModel.cs new file mode 100644 index 0000000..2a7b3c7 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/SupplyBindingModel.cs @@ -0,0 +1,16 @@ +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.BindingModels +{ + public class SupplyBindingModel : ISupplyModel + { + public int ShopId { get; set; } + public int PizzaId { get; set; } + public int Count { get; set; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IShopLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..962de76 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool MakeSupply(SupplyBindingModel model); + bool Sale(SupplySearchModel model); + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/SearchModels/ShopSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..cf9b916 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/SearchModels/SupplySearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/SupplySearchModel.cs new file mode 100644 index 0000000..4447a11 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/SearchModels/SupplySearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.SearchModels +{ + public class SupplySearchModel + { + public int? PizzaId { get; set; } + public int? Count { get; set; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/StoragesContracts/IShopStorage.cs b/Pizzeria/PizzeriaContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..e406dbe --- /dev/null +++ b/Pizzeria/PizzeriaContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,23 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? GetElement(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + bool Sale(SupplySearchModel model); + bool RestockingShops(SupplyBindingModel model); + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..7ae212a --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,24 @@ +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название")] + public string ShopName { get; set; } = string.Empty; + [DisplayName("Адрес")] + public string Adress { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } + public Dictionary ShopPizzas { get; set; } = new(); + [DisplayName("Вместимость")] + public int PizzaMaxCount { get; set; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaDataModels/Models/IShopModel.cs b/Pizzeria/PizzeriaDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..acb6305 --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Models/IShopModel.cs @@ -0,0 +1,19 @@ +using PizzeriaDataModels; +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Adress { get; } + DateTime OpeningDate { get; } + Dictionary ShopPizzas { get; } + public int PizzaMaxCount { get; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaDataModels/Models/ISupplyModel.cs b/Pizzeria/PizzeriaDataModels/Models/ISupplyModel.cs new file mode 100644 index 0000000..103ab7b --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Models/ISupplyModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaDataModels.Models +{ + public interface ISupplyModel + { + int ShopId { get; } + int PizzaId { get; } + int Count { get; } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaFileImplement/DataFileSingleton.cs b/Pizzeria/PizzeriaFileImplement/DataFileSingleton.cs index 91526a5..94ea476 100644 --- a/Pizzeria/PizzeriaFileImplement/DataFileSingleton.cs +++ b/Pizzeria/PizzeriaFileImplement/DataFileSingleton.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using PizzeriaFileImplement.Models; +using PizzeriaFileImplement.Models; using System.Xml.Linq; namespace PizzeriaFileImplement @@ -14,9 +9,11 @@ namespace PizzeriaFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string PizzaFileName = "Pizza.xml"; + private readonly string ShopFileName = "Shop.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Pizzas { get; private set; } + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { @@ -30,12 +27,14 @@ namespace PizzeriaFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SavePizzas() => SaveData(Pizzas, PizzaFileName, "Pizzas", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Pizzas = LoadData(PizzaFileName, "Pizza", x => Pizza.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) @@ -55,4 +54,4 @@ namespace PizzeriaFileImplement } } } -} +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaFileImplement/Implements/ShopStorage.cs b/Pizzeria/PizzeriaFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..743cfda --- /dev/null +++ b/Pizzeria/PizzeriaFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,154 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Shops.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + return source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + return source.Shops.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop != null) + { + source.Shops.Remove(shop); + source.SaveShops(); + return shop.GetViewModel; + } + return null; + } + + public bool Sale(SupplySearchModel model) + { + if (model == null || !model.PizzaId.HasValue || !model.Count.HasValue) + return false; + int remainingSpace = source.Shops.Select(x => x.Pizzas.ContainsKey(model.PizzaId.Value) ? x.Pizzas[model.PizzaId.Value] : 0).Sum(); + if (remainingSpace < model.Count) + { + return false; + } + var shops = source.Shops.Where(x => x.Pizzas.ContainsKey(model.PizzaId.Value)).OrderByDescending(x => x.Pizzas[model.PizzaId.Value]).ToList(); + foreach (var shop in shops) + { + int residue = model.Count.Value - shop.Pizzas[model.PizzaId.Value]; + if (residue > 0) + { + shop.Pizzas.Remove(model.PizzaId.Value); + shop.PizzasUpdate(); + model.Count = residue; + } + else + { + if (residue == 0) + { + shop.Pizzas.Remove(model.PizzaId.Value); + } + else + { + shop.Pizzas[model.PizzaId.Value] = -residue; + } + shop.PizzasUpdate(); + source.SaveShops(); + return true; + } + } + source.SaveShops(); + return false; + } + + public bool RestockingShops(SupplyBindingModel model) + { + if (model == null || source.Shops.Select(x => x.PizzaMaxCount - x.ShopPizzas.Select(y => y.Value.Item2).Sum()).Sum() < model.Count) + { + return false; + } + foreach (Shop shop in source.Shops) + { + int free_places = shop.PizzaMaxCount - shop.ShopPizzas.Select(x => x.Value.Item2).Sum(); + if (free_places <= 0) + continue; + free_places = Math.Min(free_places, model.Count); + model.Count -= free_places; + if (shop.Pizzas.ContainsKey(model.PizzaId)) + { + shop.Pizzas[model.PizzaId] += free_places; + } + else + { + shop.Pizzas.Add(model.PizzaId, free_places); + } + shop.PizzasUpdate(); + if (model.Count == 0) + { + source.SaveShops(); + return true; + } + } + return false; + } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaFileImplement/Models/Shop.cs b/Pizzeria/PizzeriaFileImplement/Models/Shop.cs new file mode 100644 index 0000000..ccf98b0 --- /dev/null +++ b/Pizzeria/PizzeriaFileImplement/Models/Shop.cs @@ -0,0 +1,111 @@ +using PizzeriaDataModels.Models; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PizzeriaFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Adress { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary Pizzas { get; private set; } = new(); + private Dictionary? _shopPizzas = null; + + public Dictionary ShopPizzas + { + get + { + if (_shopPizzas == null) + { + var source = DataFileSingleton.GetInstance(); + _shopPizzas = Pizzas.ToDictionary(x => x.Key, y => ((source.Pizzas.FirstOrDefault(z => z.Id == y.Key) as IPizzaModel)!, y.Value)); + } + return _shopPizzas; + } + } + + public int PizzaMaxCount { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate, + Pizzas = model.ShopPizzas.ToDictionary(x => x.Key, x => x.Value.Item2), + PizzaMaxCount = model.PizzaMaxCount + }; + } + + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Adress = element.Element("Adress")!.Value, + OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value), + Pizzas = element.Element("ShopPizzas")!.Elements("ShopPizza")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)), + PizzaMaxCount = Convert.ToInt32(element.Element("PizzaMaxCount")!.Value) + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + PizzaMaxCount = model.PizzaMaxCount; + Pizzas = model.ShopPizzas.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopPizzas = null; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopPizzas = ShopPizzas, + PizzaMaxCount = PizzaMaxCount + }; + + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Adress", Adress), + new XElement("OpeningDate", OpeningDate.ToString()), + new XElement("ShopPizzas", Pizzas.Select( + x => new XElement("ShopPizza", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()), + new XElement("PizzaMaxCount", PizzaMaxCount.ToString()) + ); + + public void PizzasUpdate() + { + _shopPizzas = null; + } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs index f61d7cd..06a7262 100644 --- a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs +++ b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs @@ -13,12 +13,14 @@ namespace PizzeriaListImplement public List Components { get; set; } public List Orders { get; set; } public List Pizzas { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Pizzas = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() diff --git a/Pizzeria/PizzeriaListImplement/Implements/ShopStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..5bbc4a5 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Implements/ShopStorage.cs @@ -0,0 +1,123 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public bool Sale(SupplySearchModel model) + { + throw new NotImplementedException(); + } + + public bool RestockingShops(SupplyBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Models/Shop.cs b/Pizzeria/PizzeriaListImplement/Models/Shop.cs new file mode 100644 index 0000000..c96863d --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Models/Shop.cs @@ -0,0 +1,59 @@ +using PizzeriaDataModels.Models; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Adress { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary ShopPizzas { get; private set; } = new(); + public int PizzaMaxCount { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate, + PizzaMaxCount = model.PizzaMaxCount, + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + PizzaMaxCount = model.PizzaMaxCount; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopPizzas = ShopPizzas, + PizzaMaxCount = PizzaMaxCount, + }; + } +} diff --git a/Pizzeria/PizzeriaView/FormCreateSupply.Designer.cs b/Pizzeria/PizzeriaView/FormCreateSupply.Designer.cs new file mode 100644 index 0000000..52fde78 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormCreateSupply.Designer.cs @@ -0,0 +1,143 @@ +namespace PizzeriaView +{ + partial class FormCreateSupply + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelShop = new System.Windows.Forms.Label(); + this.labelPizza = new System.Windows.Forms.Label(); + this.comboBoxPizza = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(115, 12); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(344, 28); + this.comboBoxShop.TabIndex = 0; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(12, 15); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(76, 20); + this.labelShop.TabIndex = 1; + this.labelShop.Text = "Магазин: "; + // + // labelPizza + // + this.labelPizza.AutoSize = true; + this.labelPizza.Location = new System.Drawing.Point(12, 49); + this.labelPizza.Name = "labelPizza"; + this.labelPizza.Size = new System.Drawing.Size(75, 20); + this.labelPizza.TabIndex = 2; + this.labelPizza.Text = "Изделие: "; + // + // comboBoxPizza + // + this.comboBoxPizza.FormattingEnabled = true; + this.comboBoxPizza.Location = new System.Drawing.Point(115, 46); + this.comboBoxPizza.Name = "comboBoxPizza"; + this.comboBoxPizza.Size = new System.Drawing.Size(344, 28); + this.comboBoxPizza.TabIndex = 3; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 83); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(97, 20); + this.labelCount.TabIndex = 4; + this.labelCount.Text = "Количество: "; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(115, 80); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(344, 27); + this.textBoxCount.TabIndex = 5; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(300, 113); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(116, 39); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(168, 113); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(116, 39); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormCreateSupply + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(471, 164); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxPizza); + this.Controls.Add(this.labelPizza); + this.Controls.Add(this.labelShop); + this.Controls.Add(this.comboBoxShop); + this.Name = "FormCreateSupply"; + this.Text = "Создание поставки"; + this.Load += new System.EventHandler(this.FormCreateSupply_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxShop; + private Label labelShop; + private Label labelPizza; + private ComboBox comboBoxPizza; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormCreateSupply.cs b/Pizzeria/PizzeriaView/FormCreateSupply.cs new file mode 100644 index 0000000..1ffd6a5 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormCreateSupply.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.ViewModels; +using System; +using System.Collections; +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; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace PizzeriaView +{ + public partial class FormCreateSupply : Form + { + private readonly ILogger _logger; + private readonly IPizzaLogic _logicP; + private readonly IShopLogic _logicS; + private List _shopList = new List(); + private List _pizzaList = new List(); + + public FormCreateSupply(ILogger logger, IPizzaLogic logicP, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + + private void FormCreateSupply_Load(object sender, EventArgs e) + { + _shopList = _logicS.ReadList(null); + _pizzaList = _logicP.ReadList(null); + if (_shopList != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _shopList; + comboBoxShop.SelectedItem = null; + _logger.LogInformation("Загрузка магазинов для поставок"); + } + if (_pizzaList != null) + { + comboBoxPizza.DisplayMember = "PizzaName"; + comboBoxPizza.ValueMember = "Id"; + comboBoxPizza.DataSource = _pizzaList; + comboBoxPizza.SelectedItem = null; + _logger.LogInformation("Загрузка пиццы для поставок"); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPizza.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание поставки"); + try + { + var operationResult = _logicS.MakeSupply(new SupplyBindingModel + { + ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), + PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Pizzeria/PizzeriaView/FormCreateSupply.resx b/Pizzeria/PizzeriaView/FormCreateSupply.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormCreateSupply.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormMain.Designer.cs b/Pizzeria/PizzeriaView/FormMain.Designer.cs index 572f0a2..be4bfc9 100644 --- a/Pizzeria/PizzeriaView/FormMain.Designer.cs +++ b/Pizzeria/PizzeriaView/FormMain.Designer.cs @@ -32,12 +32,16 @@ this.bookToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ingridientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pizzasToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.operationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.transactionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); + this.продажаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -46,7 +50,8 @@ // this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.bookToolStripMenuItem}); + this.bookToolStripMenuItem, + this.operationToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); @@ -58,7 +63,8 @@ // this.bookToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ingridientsToolStripMenuItem, - this.pizzasToolStripMenuItem}); + this.pizzasToolStripMenuItem, + this.shopsToolStripMenuItem}); this.bookToolStripMenuItem.Name = "bookToolStripMenuItem"; this.bookToolStripMenuItem.Size = new System.Drawing.Size(87, 20); this.bookToolStripMenuItem.Text = "Справочник"; @@ -66,17 +72,40 @@ // ingridientsToolStripMenuItem // this.ingridientsToolStripMenuItem.Name = "ingridientsToolStripMenuItem"; - this.ingridientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ingridientsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.ingridientsToolStripMenuItem.Text = "Ингредиенты"; this.ingridientsToolStripMenuItem.Click += new System.EventHandler(this.IngridentsToolStripMenuItem_Click); // // pizzasToolStripMenuItem // this.pizzasToolStripMenuItem.Name = "pizzasToolStripMenuItem"; - this.pizzasToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.pizzasToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.pizzasToolStripMenuItem.Text = "Пиццы"; this.pizzasToolStripMenuItem.Click += new System.EventHandler(this.PizzasToolStripMenuItem_Click); // + // shopsToolStripMenuItem + // + this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; + this.shopsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.shopsToolStripMenuItem.Text = "Магазины"; + this.shopsToolStripMenuItem.Click += new System.EventHandler(this.shopsToolStripMenuItem_Click); + // + // operationToolStripMenuItem + // + this.operationToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.transactionToolStripMenuItem, + this.продажаToolStripMenuItem}); + this.operationToolStripMenuItem.Name = "operationToolStripMenuItem"; + this.operationToolStripMenuItem.Size = new System.Drawing.Size(75, 20); + this.operationToolStripMenuItem.Text = "Операции"; + // + // transactionToolStripMenuItem + // + this.transactionToolStripMenuItem.Name = "transactionToolStripMenuItem"; + this.transactionToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.transactionToolStripMenuItem.Text = "Поставка"; + this.transactionToolStripMenuItem.Click += new System.EventHandler(this.transactionToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.AllowUserToAddRows = false; @@ -146,6 +175,13 @@ this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); // + // продажаToolStripMenuItem + // + this.продажаToolStripMenuItem.Name = "продажаToolStripMenuItem"; + this.продажаToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.продажаToolStripMenuItem.Text = "Продажа"; + this.продажаToolStripMenuItem.Click += new System.EventHandler(this.SellToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -183,5 +219,9 @@ private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; + private ToolStripMenuItem shopsToolStripMenuItem; + private ToolStripMenuItem operationToolStripMenuItem; + private ToolStripMenuItem transactionToolStripMenuItem; + private ToolStripMenuItem продажаToolStripMenuItem; } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormMain.cs b/Pizzeria/PizzeriaView/FormMain.cs index 02484c4..7535dfc 100644 --- a/Pizzeria/PizzeriaView/FormMain.cs +++ b/Pizzeria/PizzeriaView/FormMain.cs @@ -154,5 +154,32 @@ namespace PizzeriaView { LoadData(); } + + private void shopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void transactionToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); + if (service is FormCreateSupply form) + { + form.ShowDialog(); + } + } + + private void SellToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellPizza)); + if (service is FormSellPizza form) + { + form.ShowDialog(); + } + } } } diff --git a/Pizzeria/PizzeriaView/FormSellPizza.Designer.cs b/Pizzeria/PizzeriaView/FormSellPizza.Designer.cs new file mode 100644 index 0000000..2ef4ab2 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormSellPizza.Designer.cs @@ -0,0 +1,120 @@ +namespace PizzeriaView +{ + partial class FormSellPizza + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelPizza = new System.Windows.Forms.Label(); + this.comboBoxPizza = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSell = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelPizza + // + this.labelPizza.AutoSize = true; + this.labelPizza.Location = new System.Drawing.Point(12, 14); + this.labelPizza.Name = "labelPizza"; + this.labelPizza.Size = new System.Drawing.Size(75, 20); + this.labelPizza.TabIndex = 0; + this.labelPizza.Text = "Пицца: "; + // + // comboBoxPizza + // + this.comboBoxPizza.FormattingEnabled = true; + this.comboBoxPizza.Location = new System.Drawing.Point(115, 11); + this.comboBoxPizza.Name = "comboBoxPizza"; + this.comboBoxPizza.Size = new System.Drawing.Size(239, 28); + this.comboBoxPizza.TabIndex = 1; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 55); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(97, 20); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество: "; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(115, 52); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(239, 27); + this.textBoxCount.TabIndex = 3; + // + // buttonSell + // + this.buttonSell.Location = new System.Drawing.Point(128, 99); + this.buttonSell.Name = "buttonSell"; + this.buttonSell.Size = new System.Drawing.Size(94, 29); + this.buttonSell.TabIndex = 4; + this.buttonSell.Text = "Продать"; + this.buttonSell.UseVisualStyleBackColor = true; + this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(242, 99); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormSellPizza + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(366, 140); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSell); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxPizza); + this.Controls.Add(this.labelPizza); + this.Name = "FormSellPizza"; + this.Text = "Продажа пиццы"; + this.Load += new System.EventHandler(this.FormSellingPizza_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelPizza; + private ComboBox comboBoxPizza; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonSell; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormSellPizza.cs b/Pizzeria/PizzeriaView/FormSellPizza.cs new file mode 100644 index 0000000..98a6162 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormSellPizza.cs @@ -0,0 +1,88 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +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 PizzeriaView +{ + public partial class FormSellPizza : Form + { + private readonly ILogger _logger; + private readonly IPizzaLogic _logicP; + private readonly IShopLogic _logicS; + private List _pizzaList = new List(); + + public FormSellPizza(ILogger logger, IPizzaLogic logicP, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + + private void FormSellingPizza_Load(object sender, EventArgs e) + { + _pizzaList = _logicP.ReadList(null); + if (_pizzaList != null) + { + comboBoxPizza.DisplayMember = "PizzaName"; + comboBoxPizza.ValueMember = "Id"; + comboBoxPizza.DataSource = _pizzaList; + comboBoxPizza.SelectedItem = null; + _logger.LogInformation("Загрузка пиццы для продажи"); + } + } + + private void ButtonSell_Click(object sender, EventArgs e) + { + if (comboBoxPizza.SelectedValue == null) + { + MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание покупки"); + try + { + bool resout = _logicS.Sale(new SupplySearchModel + { + PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (resout) + { + _logger.LogInformation("Проверка пройдена, продажа проведена"); + MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + else + { + _logger.LogInformation("Проверка не пройдена"); + MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания покупки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormShop.Designer.cs b/Pizzeria/PizzeriaView/FormShop.Designer.cs new file mode 100644 index 0000000..1278e7e --- /dev/null +++ b/Pizzeria/PizzeriaView/FormShop.Designer.cs @@ -0,0 +1,222 @@ +namespace PizzeriaView +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxAdress = new System.Windows.Forms.TextBox(); + this.labelAdress = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.PizzaName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.label1 = new System.Windows.Forms.Label(); + this.dateTimeOpen = new System.Windows.Forms.DateTimePicker(); + this.label2 = new System.Windows.Forms.Label(); + this.numericUpPizzaMaxCount = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpPizzaMaxCount)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(11, 15); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(84, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название: "; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(102, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(276, 27); + this.textBoxName.TabIndex = 1; + // + // textBoxAdress + // + this.textBoxAdress.Location = new System.Drawing.Point(102, 59); + this.textBoxAdress.Name = "textBoxAdress"; + this.textBoxAdress.Size = new System.Drawing.Size(427, 27); + this.textBoxAdress.TabIndex = 3; + // + // labelAdress + // + this.labelAdress.AutoSize = true; + this.labelAdress.Location = new System.Drawing.Point(11, 61); + this.labelAdress.Name = "labelAdress"; + this.labelAdress.Size = new System.Drawing.Size(58, 20); + this.labelAdress.TabIndex = 2; + this.labelAdress.Text = "Адрес: "; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(451, 457); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(130, 44); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(315, 457); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(130, 44); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.id, + this.PizzaName, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(12, 185); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; + this.dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(569, 266); + this.dataGridView.TabIndex = 7; + // + // id + // + this.id.HeaderText = "id"; + this.id.MinimumWidth = 6; + this.id.Name = "id"; + this.id.ReadOnly = true; + this.id.Visible = false; + // + // PizzaName + // + this.PizzaName.HeaderText = "Пицца"; + this.PizzaName.MinimumWidth = 6; + this.PizzaName.Name = "PizzaName"; + this.PizzaName.ReadOnly = true; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.ReadOnly = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 103); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(110, 20); + this.label1.TabIndex = 8; + this.label1.Text = "Дата открытия"; + // + // dateTimeOpen + // + this.dateTimeOpen.Location = new System.Drawing.Point(128, 103); + this.dateTimeOpen.Name = "dateTimeOpen"; + this.dateTimeOpen.Size = new System.Drawing.Size(401, 27); + this.dateTimeOpen.TabIndex = 9; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 148); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(100, 20); + this.label2.TabIndex = 10; + this.label2.Text = "Вместимость"; + // + // numericUpPizzaMaxCount + // + this.numericUpPizzaMaxCount.Location = new System.Drawing.Point(128, 146); + this.numericUpPizzaMaxCount.Maximum = new decimal(new int[] { + 10000, + 0, + 0, + 0}); + this.numericUpPizzaMaxCount.Name = "numericUpPizzaMaxCount"; + this.numericUpPizzaMaxCount.Size = new System.Drawing.Size(401, 27); + this.numericUpPizzaMaxCount.TabIndex = 11; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(593, 513); + this.Controls.Add(this.numericUpPizzaMaxCount); + this.Controls.Add(this.label2); + this.Controls.Add(this.dateTimeOpen); + this.Controls.Add(this.label1); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxAdress); + this.Controls.Add(this.labelAdress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpPizzaMaxCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxAdress; + private Label labelAdress; + private Button buttonCancel; + private Button buttonSave; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn PizzaName; + private DataGridViewTextBoxColumn Count; + private Label label1; + private DateTimePicker dateTimeOpen; + private Label label2; + private NumericUpDown numericUpPizzaMaxCount; + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormShop.cs b/Pizzeria/PizzeriaView/FormShop.cs new file mode 100644 index 0000000..f77249b --- /dev/null +++ b/Pizzeria/PizzeriaView/FormShop.cs @@ -0,0 +1,127 @@ +using PizzeriaDataModels.Models; +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +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 PizzeriaView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + private Dictionary _ShopPizzas; + private DateTime? _openingDate = null; + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _ShopPizzas = new Dictionary(); + } + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAdress.Text = view.Adress; + dateTimeOpen.Value = view.OpeningDate; + numericUpPizzaMaxCount.Value = view.PizzaMaxCount; + _ShopPizzas = view.ShopPizzas ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий в магазине"); + try + { + if (_ShopPizzas != null) + { + dataGridView.Rows.Clear(); + foreach (var sr in _ShopPizzas) + { + dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.PizzaName, sr.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAdress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Adress = textBoxAdress.Text, + OpeningDate = dateTimeOpen.Value, + PizzaMaxCount = (int)numericUpPizzaMaxCount.Value + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Pizzeria/PizzeriaView/FormShop.resx b/Pizzeria/PizzeriaView/FormShop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormShops.Designer.cs b/Pizzeria/PizzeriaView/FormShops.Designer.cs new file mode 100644 index 0000000..3af7c45 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormShops.Designer.cs @@ -0,0 +1,130 @@ +namespace PizzeriaView +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(608, 12); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(180, 426); + this.ToolsPanel.TabIndex = 3; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(31, 206); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(126, 36); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(31, 142); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(126, 36); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(31, 76); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(126, 36); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(31, 16); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(126, 36); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(590, 426); + this.dataGridView.TabIndex = 2; + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + this.ToolsPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormShops.cs b/Pizzeria/PizzeriaView/FormShops.cs new file mode 100644 index 0000000..b1f946e --- /dev/null +++ b/Pizzeria/PizzeriaView/FormShops.cs @@ -0,0 +1,117 @@ +using Microsoft.Extensions.Logging; +using Pizzeria; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.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 PizzeriaView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ShopPizzas"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Pizzeria/PizzeriaView/FormShops.resx b/Pizzeria/PizzeriaView/FormShops.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormShops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/Program.cs b/Pizzeria/PizzeriaView/Program.cs index 5efa6c6..52acba0 100644 --- a/Pizzeria/PizzeriaView/Program.cs +++ b/Pizzeria/PizzeriaView/Program.cs @@ -49,6 +49,12 @@ namespace Pizzeria services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file From c135df7d52b601dce23726c10ff0e50b30247256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Tue, 5 Mar 2024 09:41:24 +0400 Subject: [PATCH 2/3] done hard 3 --- Pizzeria/Pizzeria.sln | 14 +- .../BusinessLogics/ShopLogic.cs | 11 + .../Implements/ShopStorage.cs | 185 +++++++++++++ .../20240305050232_Hard_init.Designer.cs | 248 ++++++++++++++++++ .../Migrations/20240305050232_Hard_init.cs | 78 ++++++ .../PizzeriaDatabaseModelSnapshot.cs | 77 ++++++ .../PizzeriaDatabaseImplement/Models/Pizza.cs | 3 + .../PizzeriaDatabaseImplement/Models/Shop.cs | 114 ++++++++ .../Models/ShopPizzas.cs | 22 ++ .../PizzeriaDatabase.cs | 10 +- 10 files changed, 753 insertions(+), 9 deletions(-) create mode 100644 Pizzeria/PizzeriaDatabaseImplement/Implements/ShopStorage.cs create mode 100644 Pizzeria/PizzeriaDatabaseImplement/Migrations/20240305050232_Hard_init.Designer.cs create mode 100644 Pizzeria/PizzeriaDatabaseImplement/Migrations/20240305050232_Hard_init.cs create mode 100644 Pizzeria/PizzeriaDatabaseImplement/Models/Shop.cs create mode 100644 Pizzeria/PizzeriaDatabaseImplement/Models/ShopPizzas.cs diff --git a/Pizzeria/Pizzeria.sln b/Pizzeria/Pizzeria.sln index e436b48..a525f7b 100644 --- a/Pizzeria/Pizzeria.sln +++ b/Pizzeria/Pizzeria.sln @@ -15,7 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaListImplement", "Pi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaFileImplement", "PizzeriaFileImplement\PizzeriaFileImplement.csproj", "{4B58D113-7C25-4795-8242-814C8288D30C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaDatabaseImplement", "PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj", "{DAE2ED2F-B064-40FA-B594-A360E041B485}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaDatabaseImplement", "PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj", "{DAE2ED2F-B064-40FA-B594-A360E041B485}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -43,10 +43,14 @@ Global {190E2EDD-BFA6-4213-9F8A-1B1D4FBBB8E4}.Debug|Any CPU.Build.0 = Debug|Any CPU {190E2EDD-BFA6-4213-9F8A-1B1D4FBBB8E4}.Release|Any CPU.ActiveCfg = Release|Any CPU {190E2EDD-BFA6-4213-9F8A-1B1D4FBBB8E4}.Release|Any CPU.Build.0 = Release|Any CPU - {357BD3B9-6100-469F-814F-7DABB2DDA33B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {357BD3B9-6100-469F-814F-7DABB2DDA33B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {357BD3B9-6100-469F-814F-7DABB2DDA33B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {357BD3B9-6100-469F-814F-7DABB2DDA33B}.Release|Any CPU.Build.0 = Release|Any CPU + {4B58D113-7C25-4795-8242-814C8288D30C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4B58D113-7C25-4795-8242-814C8288D30C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4B58D113-7C25-4795-8242-814C8288D30C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4B58D113-7C25-4795-8242-814C8288D30C}.Release|Any CPU.Build.0 = Release|Any CPU + {DAE2ED2F-B064-40FA-B594-A360E041B485}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DAE2ED2F-B064-40FA-B594-A360E041B485}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DAE2ED2F-B064-40FA-B594-A360E041B485}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DAE2ED2F-B064-40FA-B594-A360E041B485}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ShopLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ShopLogic.cs index 5e2628e..69784db 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ShopLogic.cs @@ -125,6 +125,17 @@ namespace PizzeriaBusinessLogic.BusinessLogics } shop.ShopPizzas.Add(model.PizzaId, (pizza, model.Count)); } + + _shopStorage.Update(new ShopBindingModel() + { + Id = shop.Id, + ShopName = shop.ShopName, + Adress = shop.Adress, + OpeningDate = shop.OpeningDate, + ShopPizzas = shop.ShopPizzas, + PizzaMaxCount = shop.PizzaMaxCount, + }); + return true; } diff --git a/Pizzeria/PizzeriaDatabaseImplement/Implements/ShopStorage.cs b/Pizzeria/PizzeriaDatabaseImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..b2aaacc --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Implements/ShopStorage.cs @@ -0,0 +1,185 @@ +using Microsoft.EntityFrameworkCore; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StoragesContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaDatabaseImplement.Models; + +namespace PizzeriaDatabaseImplement.Implements +{ + public class ShopStorage : IShopStorage + { + public List GetFullList() + { + using var context = new PizzeriaDatabase(); + return context.Shops.Include(x => x.Pizzas).ThenInclude(x => x.Pizza).ToList(). + Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + using var context = new PizzeriaDatabase(); + return context.Shops.Include(x => x.Pizzas).ThenInclude(x => x.Pizza).Where(x => x.ShopName.Contains(model.ShopName)). + ToList().Select(x => x.GetViewModel).ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return new(); + } + using var context = new PizzeriaDatabase(); + return context.Shops.Include(x => x.Pizzas).ThenInclude(x => x.Pizza) + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + using var context = new PizzeriaDatabase(); + var newShop = Shop.Create(context, model); + if (newShop == null) + { + return null; + } + context.Shops.Add(newShop); + context.SaveChanges(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + using var context = new PizzeriaDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var shop = context.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + context.SaveChanges(); + shop.UpdatePizzas(context, model); + transaction.Commit(); + return shop.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + using var context = new PizzeriaDatabase(); + var shop = context.Shops.Include(x => x.Pizzas).FirstOrDefault(x => x.Id == model.Id); + if (shop != null) + { + context.Shops.Remove(shop); + context.SaveChanges(); + return shop.GetViewModel; + } + return null; + } + + public bool RestockingShops(SupplyBindingModel model) + { + using var context = new PizzeriaDatabase(); + var transaction = context.Database.BeginTransaction(); + var Shops = context.Shops.Include(x => x.Pizzas).ThenInclude(x => x.Pizza).ToList(). + Where(x => x.PizzaMaxCount > x.ShopPizzas.Select(x => x.Value.Item2).Sum()).ToList(); + if (model == null) + { + return false; + } + try + { + foreach (Shop shop in Shops) + { + int difference = shop.PizzaMaxCount - shop.ShopPizzas.Select(x => x.Value.Item2).Sum(); + int refill = Math.Min(difference, model.Count); + model.Count -= refill; + if (shop.ShopPizzas.ContainsKey(model.PizzaId)) + { + var datePair = shop.ShopPizzas[model.PizzaId]; + datePair.Item2 += refill; + shop.ShopPizzas[model.PizzaId] = datePair; + } + else + { + var pizza = context.Pizzas.First(x => x.Id == model.PizzaId); + shop.ShopPizzas.Add(model.PizzaId, (pizza, refill)); + } + shop.PizzasDictionatyUpdate(context); + if (model.Count == 0) + { + transaction.Commit(); + return true; + } + } + transaction.Rollback(); + return false; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public bool Sale(SupplySearchModel model) + { + using var context = new PizzeriaDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + var shops = context.Shops.Include(x => x.Pizzas).ThenInclude(x => x.Pizza).ToList(). + Where(x => x.ShopPizzas.ContainsKey(model.PizzaId.Value)).OrderByDescending(x => x.ShopPizzas[model.PizzaId.Value].Item2).ToList(); + + foreach (var shop in shops) + { + int residue = model.Count.Value - shop.ShopPizzas[model.PizzaId.Value].Item2; + if (residue > 0) + { + shop.ShopPizzas.Remove(model.PizzaId.Value); + shop.PizzasDictionatyUpdate(context); + context.SaveChanges(); + model.Count = residue; + + } + else + { + if (residue == 0) + shop.ShopPizzas.Remove(model.PizzaId.Value); + else + { + var dataPair = shop.ShopPizzas[model.PizzaId.Value]; + dataPair.Item2 = -residue; + shop.ShopPizzas[model.PizzaId.Value] = dataPair; + } + + shop.PizzasDictionatyUpdate(context); + transaction.Commit(); + return true; + } + } + transaction.Rollback(); + return false; + } + catch + { + transaction.Rollback(); + throw; + } + } + + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240305050232_Hard_init.Designer.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240305050232_Hard_init.Designer.cs new file mode 100644 index 0000000..582e5e1 --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240305050232_Hard_init.Designer.cs @@ -0,0 +1,248 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using PizzeriaDatabaseImplement; + +#nullable disable + +namespace PizzeriaDatabaseImplement.Migrations +{ + [DbContext(typeof(PizzeriaDatabase))] + [Migration("20240305050232_Hard_init")] + partial class Hard_init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("PizzaId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("PizzaId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PizzaName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Pizzas"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.PizzaComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PizzaId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PizzaId"); + + b.ToTable("PizzaComponents"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Adress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("PizzaMaxCount") + .HasColumnType("int"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.ShopPizzas", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PizzaId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PizzaId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopPizzas"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b => + { + b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") + .WithMany("Orders") + .HasForeignKey("PizzaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Pizza"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.PizzaComponent", b => + { + b.HasOne("PizzeriaDatabaseImplement.Models.Component", "Component") + .WithMany("PizzaComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") + .WithMany("Components") + .HasForeignKey("PizzaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Pizza"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.ShopPizzas", b => + { + b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") + .WithMany("ShopPizzas") + .HasForeignKey("PizzaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PizzeriaDatabaseImplement.Models.Shop", "Shop") + .WithMany("Pizzas") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Pizza"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b => + { + b.Navigation("PizzaComponents"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Shop", b => + { + b.Navigation("Pizzas"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240305050232_Hard_init.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240305050232_Hard_init.cs new file mode 100644 index 0000000..a85816b --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240305050232_Hard_init.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PizzeriaDatabaseImplement.Migrations +{ + /// + public partial class Hard_init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopName = table.Column(type: "nvarchar(max)", nullable: false), + Adress = table.Column(type: "nvarchar(max)", nullable: false), + OpeningDate = table.Column(type: "datetime2", nullable: false), + PizzaMaxCount = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ShopPizzas", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PizzaId = table.Column(type: "int", nullable: false), + ShopId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopPizzas", x => x.Id); + table.ForeignKey( + name: "FK_ShopPizzas_Pizzas_PizzaId", + column: x => x.PizzaId, + principalTable: "Pizzas", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopPizzas_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ShopPizzas_PizzaId", + table: "ShopPizzas", + column: "PizzaId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopPizzas_ShopId", + table: "ShopPizzas", + column: "ShopId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ShopPizzas"); + + migrationBuilder.DropTable( + name: "Shops"); + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs index b5035a2..b8008e1 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/PizzeriaDatabaseModelSnapshot.cs @@ -121,6 +121,59 @@ namespace PizzeriaDatabaseImplement.Migrations b.ToTable("PizzaComponents"); }); + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Adress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("PizzaMaxCount") + .HasColumnType("int"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.ShopPizzas", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PizzaId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PizzaId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopPizzas"); + }); + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b => { b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") @@ -151,6 +204,25 @@ namespace PizzeriaDatabaseImplement.Migrations b.Navigation("Pizza"); }); + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.ShopPizzas", b => + { + b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") + .WithMany("ShopPizzas") + .HasForeignKey("PizzaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PizzeriaDatabaseImplement.Models.Shop", "Shop") + .WithMany("Pizzas") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Pizza"); + + b.Navigation("Shop"); + }); + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b => { b.Navigation("PizzaComponents"); @@ -162,6 +234,11 @@ namespace PizzeriaDatabaseImplement.Migrations b.Navigation("Orders"); }); + + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Shop", b => + { + b.Navigation("Pizzas"); + }); #pragma warning restore 612, 618 } } diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs index 55bb815..61bf1e9 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs @@ -33,6 +33,9 @@ namespace PizzeriaDatabaseImplement.Models [ForeignKey("PizzaId")] public virtual List Orders { get; set; } = new(); + [ForeignKey("PizzaId")] + public virtual List ShopPizzas { get; set; } = new(); + public static Pizza Create(PizzeriaDatabase context, PizzaBindingModel model) { diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/Shop.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/Shop.cs new file mode 100644 index 0000000..0b3f928 --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/Shop.cs @@ -0,0 +1,114 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; + +namespace PizzeriaDatabaseImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + + public string Adress { get; set; } = string.Empty; + + public DateTime OpeningDate { get; set; } + + public int PizzaMaxCount { get; set; } + + private Dictionary? _shopPizzas = null; + + public Dictionary ShopPizzas + { + get + { + if (_shopPizzas == null) + { + if (_shopPizzas == null) + { + _shopPizzas = Pizzas + .ToDictionary(recSP => recSP.PizzaId, recSP => (recSP.Pizza as IPizzaModel, recSP.Count)); + } + return _shopPizzas; + } + return _shopPizzas; + } + } + + [ForeignKey("ShopId")] + public List Pizzas { get; set; } = new(); + + public static Shop Create(PizzeriaDatabase context, ShopBindingModel model) + { + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate, + Pizzas = model.ShopPizzas.Select(x => new ShopPizzas + { + Pizza = context.Pizzas.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList(), + PizzaMaxCount = model.PizzaMaxCount + }; + } + + public void Update(ShopBindingModel model) + { + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + PizzaMaxCount = model.PizzaMaxCount; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopPizzas = ShopPizzas, + PizzaMaxCount = PizzaMaxCount + }; + + public void UpdatePizzas(PizzeriaDatabase context, ShopBindingModel model) + { + var ShopPizzas = context.ShopPizzas.Where(rec => rec.ShopId == model.Id).ToList(); + if (ShopPizzas != null && ShopPizzas.Count > 0) + { + context.ShopPizzas.RemoveRange(ShopPizzas.Where(rec => !model.ShopPizzas.ContainsKey(rec.PizzaId))); + context.SaveChanges(); + ShopPizzas = context.ShopPizzas.Where(rec => rec.ShopId == model.Id).ToList(); + foreach (var updatePizza in ShopPizzas) + { + updatePizza.Count = model.ShopPizzas[updatePizza.PizzaId].Item2; + model.ShopPizzas.Remove(updatePizza.PizzaId); + } + context.SaveChanges(); + } + var shop = context.Shops.First(x => x.Id == Id); + foreach (var ar in model.ShopPizzas) + { + context.ShopPizzas.Add(new ShopPizzas + { + Shop = shop, + Pizza = context.Pizzas.First(x => x.Id == ar.Key), + Count = ar.Value.Item2 + }); + context.SaveChanges(); + } + _shopPizzas = null; + } + + public void PizzasDictionatyUpdate(PizzeriaDatabase context) + { + UpdatePizzas(context, new ShopBindingModel + { + Id = Id, + ShopPizzas = ShopPizzas, + }); + } + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Models/ShopPizzas.cs b/Pizzeria/PizzeriaDatabaseImplement/Models/ShopPizzas.cs new file mode 100644 index 0000000..2d5a371 --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Models/ShopPizzas.cs @@ -0,0 +1,22 @@ +using System.ComponentModel.DataAnnotations; + +namespace PizzeriaDatabaseImplement.Models +{ + public class ShopPizzas + { + public int Id { get; set; } + + [Required] + public int PizzaId { get; set; } + + [Required] + public int ShopId { get; set; } + + [Required] + public int Count { get; set; } + + public virtual Shop Shop { get; set; } = new(); + + public virtual Pizza Pizza { get; set; } = new(); + } +} diff --git a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs index 2a77187..ee554df 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs @@ -14,9 +14,11 @@ namespace PizzeriaDatabaseImplement } base.OnConfiguring(optionsBuilder); } - public virtual DbSet Components { set; get; } - public virtual DbSet Pizzas { set; get; } - public virtual DbSet PizzaComponents { set; get; } - public virtual DbSet Orders { set; get; } + public virtual DbSet Components { get; set; } + public virtual DbSet Pizzas { get; set; } + public virtual DbSet PizzaComponents { get; set; } + public virtual DbSet Orders { get; set; } + public virtual DbSet Shops { get; set; } + public virtual DbSet ShopPizzas { get; set; } } } From 0d4e179a1fb1dff1a6ff592f249aed56a73cca7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Fri, 15 Mar 2024 02:21:13 +0400 Subject: [PATCH 3/3] done hard 4 --- .../BusinessLogics/ReportLogic.cs | 56 ++- .../BusinessLogics/ShopLogic.cs | 2 +- .../OfficePackage/AbstractSaveToExcel.cs | 77 ++- .../OfficePackage/AbstractSaveToPdf.cs | 34 +- .../OfficePackage/AbstractSaveToWord.cs | 50 +- .../OfficePackage/HelperModels/ExcelInfo.cs | 2 +- .../OfficePackage/HelperModels/ExcelShop.cs | 11 + .../HelperModels/PdfGroupedOrdersInfo.cs | 18 + .../OfficePackage/HelperModels/PdfInfo.cs | 2 +- .../OfficePackage/HelperModels/WordInfo.cs | 2 +- .../HelperModels/WordRowParameters.cs | 14 + .../HelperModels/WordShopInfo.cs | 16 + .../OfficePackage/IDocument.cs | 14 + .../OfficePackage/Implements/SaveToExcel.cs | 6 +- .../OfficePackage/Implements/SaveToPdf.cs | 4 +- .../OfficePackage/Implements/SaveToWord.cs | 81 +++- .../BusinessLogicsContracts/IReportLogic.cs | 5 + .../ViewModels/ReportGroupOrdersViewModel.cs | 15 + .../ViewModels/ReportShopsViewModel.cs | 15 + .../PizzeriaView/FormCreateSupply.Designer.cs | 2 +- Pizzeria/PizzeriaView/FormCreateSupply.cs | 2 +- Pizzeria/PizzeriaView/FormMain.Designer.cs | 131 ++++-- Pizzeria/PizzeriaView/FormMain.cs | 28 ++ Pizzeria/PizzeriaView/FormPizza.cs | 3 +- .../FormReportGroupedOrders.Designer.cs | 86 ++++ .../PizzeriaView/FormReportGroupedOrders.cs | 80 ++++ .../PizzeriaView/FormReportGroupedOrders.resx | 120 +++++ .../PizzeriaView/FormReportShop.Designer.cs | 116 +++++ Pizzeria/PizzeriaView/FormReportShop.cs | 78 ++++ Pizzeria/PizzeriaView/FormReportShop.resx | 120 +++++ Pizzeria/PizzeriaView/FormShop.cs | 4 +- Pizzeria/PizzeriaView/PizzeriaView.csproj | 9 +- Pizzeria/PizzeriaView/Program.cs | 8 +- .../PizzeriaView/ReportGroupedOrders.rdlc | 441 ++++++++++++++++++ 34 files changed, 1584 insertions(+), 68 deletions(-) create mode 100644 Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs create mode 100644 Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs create mode 100644 Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs create mode 100644 Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/WordShopInfo.cs create mode 100644 Pizzeria/PizzeriaBusinessLogic/OfficePackage/IDocument.cs create mode 100644 Pizzeria/PizzeriaContracts/ViewModels/ReportGroupOrdersViewModel.cs create mode 100644 Pizzeria/PizzeriaContracts/ViewModels/ReportShopsViewModel.cs create mode 100644 Pizzeria/PizzeriaView/FormReportGroupedOrders.Designer.cs create mode 100644 Pizzeria/PizzeriaView/FormReportGroupedOrders.cs create mode 100644 Pizzeria/PizzeriaView/FormReportGroupedOrders.resx create mode 100644 Pizzeria/PizzeriaView/FormReportShop.Designer.cs create mode 100644 Pizzeria/PizzeriaView/FormReportShop.cs create mode 100644 Pizzeria/PizzeriaView/FormReportShop.resx create mode 100644 Pizzeria/PizzeriaView/ReportGroupedOrders.rdlc diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ReportLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ReportLogic.cs index 3f0e36e..29118c8 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ReportLogic.cs @@ -13,16 +13,18 @@ namespace PizzeriaBusinessLogic.BusinessLogics private readonly IComponentStorage _componentStorage; private readonly IPizzaStorage _pizzaStorage; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(IPizzaStorage pizzaStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, + public ReportLogic(IPizzaStorage pizzaStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _pizzaStorage = pizzaStorage; _componentStorage = componentStorage; _orderStorage = orderStorage; + _shopStorage = shopStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; @@ -55,7 +57,7 @@ namespace PizzeriaBusinessLogic.BusinessLogics public void SavePizzasToWordFile(ReportBindingModel model) { - _saveToWord.CreateDoc(new WordInfo + _saveToWord.CreatePizzaDoc(new WordInfo { FileName = model.FileName, Title = "Список пицц", @@ -84,5 +86,55 @@ namespace PizzeriaBusinessLogic.BusinessLogics Orders = GetOrders(model) }); } + + public List GetShops() + { + return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel + { + ShopName = x.ShopName, + Pizzas = x.ShopPizzas.Select(x => (x.Value.Item1.PizzaName, x.Value.Item2)).ToList(), + TotalCount = x.ShopPizzas.Select(x => x.Value.Item2).Sum() + }).ToList(); + } + + public List GetGroupedOrders() + { + return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportGroupOrdersViewModel + { + Date = x.Key, + OrdersCount = x.Count(), + OrdersSum = x.Select(y => y.Sum).Sum() + }).ToList(); + } + + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateShopsDoc(new WordShopInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + + public void SaveShopsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopPizzasReport(new ExcelShop + { + FileName = model.FileName, + Title = "Наполненость магазинов", + ShopPizzas = GetShops() + }); + } + + public void SaveGroupedOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo + { + FileName = model.FileName, + Title = "Список заказов сгруппированных по дате заказов", + GroupedOrders = GetGroupedOrders() + }); + } } } diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ShopLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ShopLogic.cs index 69784db..b38b3eb 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogics/ShopLogic.cs @@ -97,7 +97,7 @@ namespace PizzeriaBusinessLogic.BusinessLogics } if (model.Count <= 0) { - throw new ArgumentException("Количество изделий должно быть больше 0"); + throw new ArgumentException("Количество пиццы должно быть больше 0"); } var shop = _shopStorage.GetElement(new ShopSearchModel { diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 7307037..1de1b1a 100644 --- a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -75,9 +75,82 @@ namespace PizzeriaBusinessLogic.OfficePackage SaveExcel(info); } - protected abstract void CreateExcel(ExcelInfo info); + + public void CreateShopPizzasReport(ExcelShop info) + { + CreateExcel(info); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + + uint rowIndex = 2; + foreach (var sr in info.ShopPizzas) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = sr.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var (Pizza, Count) in sr.Pizzas) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Pizza, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + rowIndex++; + } + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = sr.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + + SaveExcel(info); + } + + protected abstract void CreateExcel(IDocument info); protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); protected abstract void MergeCells(ExcelMergeParameters excelParams); - protected abstract void SaveExcel(ExcelInfo info); + protected abstract void SaveExcel(IDocument info); } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index ff2afbd..bcb4483 100644 --- a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -33,10 +33,40 @@ namespace PizzeriaBusinessLogic.OfficePackage SavePdf(info); } - protected abstract void CreatePdf(PdfInfo info); + + public void CreateGroupedOrdersDoc(PdfGroupedOrdersInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "4cm", "3cm", "2cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата заказа", "Кол-во", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + + foreach (var groupedOrder in info.GroupedOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { groupedOrder.Date.ToShortDateString(), groupedOrder.OrdersCount.ToString(), groupedOrder.OrdersSum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.GroupedOrders.Sum(x => x.OrdersSum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + SavePdf(info); + } + + protected abstract void CreatePdf(IDocument info); protected abstract void CreateParagraph(PdfParagraph paragraph); protected abstract void CreateTable(List columns); protected abstract void CreateRow(PdfRowParameters rowParameters); - protected abstract void SavePdf(PdfInfo info); + protected abstract void SavePdf(IDocument info); } } diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/AbstractSaveToWord.cs index d30faec..73320c8 100644 --- a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -10,7 +10,7 @@ namespace PizzeriaBusinessLogic.OfficePackage { public abstract class AbstractSaveToWord { - public void CreateDoc(WordInfo info) + public void CreatePizzaDoc(WordInfo info) { CreateWord(info); @@ -42,8 +42,52 @@ namespace PizzeriaBusinessLogic.OfficePackage SaveWord(info); } - protected abstract void CreateWord(WordInfo info); + + public void CreateShopsDoc(WordShopInfo info) + { + CreateWord(info); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + + CreateTable(new List { "3000", "3000", "3000" }); + CreateRow(new WordRowParameters + { + Texts = new List { "Название", "Адрес", "Дата открытия" }, + TextProperties = new WordTextProperties + { + Size = "24", + Bold = true, + JustificationType = WordJustificationType.Center + } + }); + + foreach (var shop in info.Shops) + { + CreateRow(new WordRowParameters + { + Texts = new List { shop.ShopName, shop.Adress, shop.OpeningDate.ToString() }, + TextProperties = new WordTextProperties + { + Size = "22", + JustificationType = WordJustificationType.Both + } + }); + } + + SaveWord(info); + } + + protected abstract void CreateWord(IDocument info); protected abstract void CreateParagraph(WordParagraph paragraph); - protected abstract void SaveWord(WordInfo info); + protected abstract void SaveWord(IDocument info); + protected abstract void CreateTable(List colums); + protected abstract void CreateRow(WordRowParameters rowParameters); } } diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index ed93d50..d845077 100644 --- a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -2,7 +2,7 @@ namespace PizzeriaBusinessLogic.OfficePackage.HelperModels { - public class ExcelInfo + public class ExcelInfo : IDocument { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs new file mode 100644 index 0000000..b4e783d --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/ExcelShop.cs @@ -0,0 +1,11 @@ +using PizzeriaContracts.ViewModels; + +namespace PizzeriaBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelShop : IDocument + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List ShopPizzas { get; set; } = new(); + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs new file mode 100644 index 0000000..219c679 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/PdfGroupedOrdersInfo.cs @@ -0,0 +1,18 @@ +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaBusinessLogic.OfficePackage.HelperModels +{ + public class PdfGroupedOrdersInfo : IDocument + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public List GroupedOrders { get; set; } = new(); + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index d5703c0..7676484 100644 --- a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -2,7 +2,7 @@ namespace PizzeriaBusinessLogic.OfficePackage.HelperModels { - public class PdfInfo + public class PdfInfo : IDocument { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index 7c5dd32..ce96003 100644 --- a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -2,7 +2,7 @@ namespace PizzeriaBusinessLogic.OfficePackage.HelperModels { - public class WordInfo + public class WordInfo : IDocument { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs new file mode 100644 index 0000000..61eb67c --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/WordRowParameters.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaBusinessLogic.OfficePackage.HelperModels +{ + public class WordRowParameters + { + public List Texts { get; set; } = new(); + public WordTextProperties TextProperties { get; set; } = new(); + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/WordShopInfo.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/WordShopInfo.cs new file mode 100644 index 0000000..0532e0b --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/HelperModels/WordShopInfo.cs @@ -0,0 +1,16 @@ +using PizzeriaContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaBusinessLogic.OfficePackage.HelperModels +{ + public class WordShopInfo : IDocument + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List Shops { get; set; } = new(); + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/IDocument.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/IDocument.cs new file mode 100644 index 0000000..0850379 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/IDocument.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaBusinessLogic.OfficePackage +{ + public interface IDocument + { + public string FileName { get; set; } + public string Title { get; set; } + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index 63d76fc..e0e39b7 100644 --- a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -3,9 +3,9 @@ using DocumentFormat.OpenXml.Office2013.Excel; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; using DocumentFormat.OpenXml; +using PizzeriaBusinessLogic.OfficePackage; using PizzeriaBusinessLogic.OfficePackage.HelperEnums; using PizzeriaBusinessLogic.OfficePackage.HelperModels; -using PizzeriaBusinessLogic.OfficePackage; namespace PizzeriaBusinessLogic.OfficePackage.Implements { @@ -140,7 +140,7 @@ namespace PizzeriaBusinessLogic.OfficePackage.Implements }; } - protected override void CreateExcel(ExcelInfo info) + protected override void CreateExcel(IDocument info) { _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook); // Создаем книгу (в ней хранятся листы) @@ -269,7 +269,7 @@ namespace PizzeriaBusinessLogic.OfficePackage.Implements mergeCells.Append(mergeCell); } - protected override void SaveExcel(ExcelInfo info) + protected override void SaveExcel(IDocument info) { if (_spreadsheetDocument == null) { diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/Implements/SaveToPdf.cs index 3524435..de8cc36 100644 --- a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -34,7 +34,7 @@ namespace PizzeriaBusinessLogic.OfficePackage.Implements style.Font.Bold = true; } - protected override void CreatePdf(PdfInfo info) + protected override void CreatePdf(IDocument info) { _document = new Document(); DefineStyles(_document); @@ -96,7 +96,7 @@ namespace PizzeriaBusinessLogic.OfficePackage.Implements } } - protected override void SavePdf(PdfInfo info) + protected override void SavePdf(IDocument info) { var renderer = new PdfDocumentRenderer(true) { diff --git a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 2d1eb19..d2cc25e 100644 --- a/Pizzeria/PizzeriaBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/Pizzeria/PizzeriaBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -21,6 +21,7 @@ namespace PizzeriaBusinessLogic.OfficePackage.Implements _ => JustificationValues.Left, }; } + private static SectionProperties CreateSectionProperties() { var properties = new SectionProperties(); @@ -34,6 +35,7 @@ namespace PizzeriaBusinessLogic.OfficePackage.Implements return properties; } + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) { if (paragraphProperties == null) @@ -64,13 +66,15 @@ namespace PizzeriaBusinessLogic.OfficePackage.Implements return properties; } - protected override void CreateWord(WordInfo info) + + protected override void CreateWord(IDocument info) { _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); mainPart.Document = new Document(); _docBody = mainPart.Document.AppendChild(new Body()); } + protected override void CreateParagraph(WordParagraph paragraph) { if (_docBody == null || paragraph == null) @@ -100,7 +104,8 @@ namespace PizzeriaBusinessLogic.OfficePackage.Implements _docBody.AppendChild(docParagraph); } - protected override void SaveWord(WordInfo info) + + protected override void SaveWord(IDocument info) { if (_docBody == null || _wordDocument == null) { @@ -112,5 +117,77 @@ namespace PizzeriaBusinessLogic.OfficePackage.Implements _wordDocument.Close(); } + + private Table? _lastTable; + protected override void CreateTable(List columns) + { + if (_docBody == null) + return; + + _lastTable = new Table(); + + var tableProp = new TableProperties(); + tableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed }); + tableProp.AppendChild(new TableBorders( + new TopBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new LeftBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new RightBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new BottomBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new InsideHorizontalBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 }, + new InsideVerticalBorder() { Val = new EnumValue(BorderValues.Single), Size = 4 } + )); + tableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto }); + _lastTable.AppendChild(tableProp); + + TableGrid tableGrid = new TableGrid(); + foreach (var column in columns) + { + tableGrid.AppendChild(new GridColumn() { Width = column }); + } + _lastTable.AppendChild(tableGrid); + + _docBody.AppendChild(_lastTable); + } + + protected override void CreateRow(WordRowParameters rowParameters) + { + if (_docBody == null || _lastTable == null) + return; + + TableRow docRow = new TableRow(); + foreach (var column in rowParameters.Texts) + { + var docParagraph = new Paragraph(); + WordParagraph paragraph = new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (column, rowParameters.TextProperties) }, + TextProperties = rowParameters.TextProperties + }; + + docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + + foreach (var run in paragraph.Texts) + { + var docRun = new Run(); + + var properties = new RunProperties(); + properties.AppendChild(new FontSize { Val = run.Item2.Size }); + if (run.Item2.Bold) + { + properties.AppendChild(new Bold()); + } + docRun.AppendChild(properties); + + docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve }); + + docParagraph.AppendChild(docRun); + } + + TableCell docCell = new TableCell(); + docCell.AppendChild(docParagraph); + docRow.AppendChild(docCell); + } + _lastTable.AppendChild(docRow); + } } } diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IReportLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IReportLogic.cs index 7364f3a..7d94760 100644 --- a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IReportLogic.cs @@ -7,8 +7,13 @@ namespace PizzeriaContracts.BusinessLogicsContracts { List GetPizzaComponents(); List GetOrders(ReportBindingModel model); + List GetShops(); + List GetGroupedOrders(); void SavePizzasToWordFile(ReportBindingModel model); void SavePizzaComponentToExcelFile(ReportBindingModel model); void SaveOrdersToPdfFile(ReportBindingModel model); + void SaveShopsToWordFile(ReportBindingModel model); + void SaveShopsToExcelFile(ReportBindingModel model); + void SaveGroupedOrdersToPdfFile(ReportBindingModel model); } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ReportGroupOrdersViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ReportGroupOrdersViewModel.cs new file mode 100644 index 0000000..ac03315 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/ReportGroupOrdersViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.ViewModels +{ + public class ReportGroupOrdersViewModel + { + public DateTime Date { get; set; } = DateTime.Now; + public int OrdersCount { get; set; } + public double OrdersSum { get; set; } + } +} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ReportShopsViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ReportShopsViewModel.cs new file mode 100644 index 0000000..5f5965c --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/ReportShopsViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaContracts.ViewModels +{ + public class ReportShopsViewModel + { + public string ShopName { get; set; } = string.Empty; + public int TotalCount { get; set; } + public List<(string Pizza, int count)> Pizzas { get; set; } = new(); + } +} diff --git a/Pizzeria/PizzeriaView/FormCreateSupply.Designer.cs b/Pizzeria/PizzeriaView/FormCreateSupply.Designer.cs index 52fde78..389ed8d 100644 --- a/Pizzeria/PizzeriaView/FormCreateSupply.Designer.cs +++ b/Pizzeria/PizzeriaView/FormCreateSupply.Designer.cs @@ -62,7 +62,7 @@ this.labelPizza.Name = "labelPizza"; this.labelPizza.Size = new System.Drawing.Size(75, 20); this.labelPizza.TabIndex = 2; - this.labelPizza.Text = "Изделие: "; + this.labelPizza.Text = "Пицца: "; // // comboBoxPizza // diff --git a/Pizzeria/PizzeriaView/FormCreateSupply.cs b/Pizzeria/PizzeriaView/FormCreateSupply.cs index 1ffd6a5..94311dd 100644 --- a/Pizzeria/PizzeriaView/FormCreateSupply.cs +++ b/Pizzeria/PizzeriaView/FormCreateSupply.cs @@ -63,7 +63,7 @@ namespace PizzeriaView } if (comboBoxPizza.SelectedValue == null) { - MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Создание поставки"); diff --git a/Pizzeria/PizzeriaView/FormMain.Designer.cs b/Pizzeria/PizzeriaView/FormMain.Designer.cs index e726faf..a933606 100644 --- a/Pizzeria/PizzeriaView/FormMain.Designer.cs +++ b/Pizzeria/PizzeriaView/FormMain.Designer.cs @@ -35,17 +35,23 @@ this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.operationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.transactionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.продажаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.componentsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.componentPizzaToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокИзделийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.пиццаСИнгридиентамиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазинToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.информацияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.загруженностьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.заказыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.заказыToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.заказыПоГруппамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); - this.продажаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -55,8 +61,7 @@ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.bookToolStripMenuItem, - this.operationToolStripMenuItem}); - this.bookToolStripMenuItem, + this.operationToolStripMenuItem, this.отчётыToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; @@ -108,40 +113,95 @@ // transactionToolStripMenuItem // this.transactionToolStripMenuItem.Name = "transactionToolStripMenuItem"; - this.transactionToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.transactionToolStripMenuItem.Size = new System.Drawing.Size(125, 22); this.transactionToolStripMenuItem.Text = "Поставка"; this.transactionToolStripMenuItem.Click += new System.EventHandler(this.transactionToolStripMenuItem_Click); // + // продажаToolStripMenuItem + // + this.продажаToolStripMenuItem.Name = "продажаToolStripMenuItem"; + this.продажаToolStripMenuItem.Size = new System.Drawing.Size(125, 22); + this.продажаToolStripMenuItem.Text = "Продажа"; + this.продажаToolStripMenuItem.Click += new System.EventHandler(this.SellToolStripMenuItem_Click); + // // отчётыToolStripMenuItem // this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.componentsToolStripMenuItem1, - this.componentPizzaToolStripMenuItem1, - this.ordersToolStripMenuItem}); + this.изделияToolStripMenuItem, + this.магазинToolStripMenuItem, + this.заказыToolStripMenuItem}); this.отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; this.отчётыToolStripMenuItem.Size = new System.Drawing.Size(60, 20); this.отчётыToolStripMenuItem.Text = "Отчёты"; // - // componentsToolStripMenuItem1 + // изделияToolStripMenuItem // - this.componentsToolStripMenuItem1.Name = "componentsToolStripMenuItem1"; - this.componentsToolStripMenuItem1.Size = new System.Drawing.Size(205, 22); - this.componentsToolStripMenuItem1.Text = "Пиццы"; - this.componentsToolStripMenuItem1.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); + this.изделияToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.списокИзделийToolStripMenuItem, + this.пиццаСИнгридиентамиToolStripMenuItem}); + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.изделияToolStripMenuItem.Text = "Пицца"; // - // componentPizzaToolStripMenuItem1 + // списокИзделийToolStripMenuItem // - this.componentPizzaToolStripMenuItem1.Name = "componentPizzaToolStripMenuItem1"; - this.componentPizzaToolStripMenuItem1.Size = new System.Drawing.Size(205, 22); - this.componentPizzaToolStripMenuItem1.Text = "Пицца с компонентами"; - this.componentPizzaToolStripMenuItem1.Click += new System.EventHandler(this.ComponentPizzaToolStripMenuItem_Click); + this.списокИзделийToolStripMenuItem.Name = "списокИзделийToolStripMenuItem"; + this.списокИзделийToolStripMenuItem.Size = new System.Drawing.Size(208, 22); + this.списокИзделийToolStripMenuItem.Text = "Список пицц"; + this.списокИзделийToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); // - // ordersToolStripMenuItem + // пиццаСИнгридиентамиToolStripMenuItem // - this.ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; - this.ordersToolStripMenuItem.Size = new System.Drawing.Size(205, 22); - this.ordersToolStripMenuItem.Text = "Заказы"; - this.ordersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); + this.пиццаСИнгридиентамиToolStripMenuItem.Name = "пиццаСИнгридиентамиToolStripMenuItem"; + this.пиццаСИнгридиентамиToolStripMenuItem.Size = new System.Drawing.Size(208, 22); + this.пиццаСИнгридиентамиToolStripMenuItem.Text = "Пицца с ингридиентами"; + this.пиццаСИнгридиентамиToolStripMenuItem.Click += new System.EventHandler(this.ComponentPizzaToolStripMenuItem_Click); + // + // магазинToolStripMenuItem + // + this.магазинToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.информацияToolStripMenuItem, + this.загруженностьToolStripMenuItem}); + this.магазинToolStripMenuItem.Name = "магазинToolStripMenuItem"; + this.магазинToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.магазинToolStripMenuItem.Text = "Магазин"; + // + // информацияToolStripMenuItem + // + this.информацияToolStripMenuItem.Name = "информацияToolStripMenuItem"; + this.информацияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.информацияToolStripMenuItem.Text = "Информация"; + this.информацияToolStripMenuItem.Click += new System.EventHandler(this.InfoToolStripMenuItem_Click); + // + // загруженностьToolStripMenuItem + // + this.загруженностьToolStripMenuItem.Name = "загруженностьToolStripMenuItem"; + this.загруженностьToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.загруженностьToolStripMenuItem.Text = "Загруженность"; + this.загруженностьToolStripMenuItem.Click += new System.EventHandler(this.BusyShopsToolStripMenuItem_Click); + // + // заказыToolStripMenuItem + // + this.заказыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.заказыToolStripMenuItem1, + this.заказыПоГруппамToolStripMenuItem}); + this.заказыToolStripMenuItem.Name = "заказыToolStripMenuItem"; + this.заказыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.заказыToolStripMenuItem.Text = "Заказы"; + // + // заказыToolStripMenuItem1 + // + this.заказыToolStripMenuItem1.Name = "заказыToolStripMenuItem1"; + this.заказыToolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + this.заказыToolStripMenuItem1.Text = "Заказы"; + this.заказыToolStripMenuItem1.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); + // + // заказыПоГруппамToolStripMenuItem + // + this.заказыПоГруппамToolStripMenuItem.Name = "заказыПоГруппамToolStripMenuItem"; + this.заказыПоГруппамToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.заказыПоГруппамToolStripMenuItem.Text = "Заказы по группам"; + this.заказыПоГруппамToolStripMenuItem.Click += new System.EventHandler(this.GroupOrdersToolStripMenuItem_Click); // // dataGridView // @@ -212,13 +272,6 @@ this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); // - // продажаToolStripMenuItem - // - this.продажаToolStripMenuItem.Name = "продажаToolStripMenuItem"; - this.продажаToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.продажаToolStripMenuItem.Text = "Продажа"; - this.продажаToolStripMenuItem.Click += new System.EventHandler(this.SellToolStripMenuItem_Click); - // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -256,13 +309,19 @@ private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; + private ToolStripMenuItem отчётыToolStripMenuItem; private ToolStripMenuItem shopsToolStripMenuItem; private ToolStripMenuItem operationToolStripMenuItem; private ToolStripMenuItem transactionToolStripMenuItem; private ToolStripMenuItem продажаToolStripMenuItem; - private ToolStripMenuItem отчётыToolStripMenuItem; - private ToolStripMenuItem componentsToolStripMenuItem1; - private ToolStripMenuItem componentPizzaToolStripMenuItem1; - private ToolStripMenuItem ordersToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private ToolStripMenuItem списокИзделийToolStripMenuItem; + private ToolStripMenuItem пиццаСИнгридиентамиToolStripMenuItem; + private ToolStripMenuItem магазинToolStripMenuItem; + private ToolStripMenuItem информацияToolStripMenuItem; + private ToolStripMenuItem загруженностьToolStripMenuItem; + private ToolStripMenuItem заказыToolStripMenuItem; + private ToolStripMenuItem заказыToolStripMenuItem1; + private ToolStripMenuItem заказыПоГруппамToolStripMenuItem; } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormMain.cs b/Pizzeria/PizzeriaView/FormMain.cs index 3160d39..1c486c4 100644 --- a/Pizzeria/PizzeriaView/FormMain.cs +++ b/Pizzeria/PizzeriaView/FormMain.cs @@ -211,5 +211,33 @@ namespace PizzeriaView form.ShowDialog(); } } + + private void InfoToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveShopsToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void BusyShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShop)); + if (service is FormReportShop form) + { + form.ShowDialog(); + } + } + + private void GroupOrdersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportGroupedOrders)); + if (service is FormReportGroupedOrders form) + { + form.ShowDialog(); + } + } } } diff --git a/Pizzeria/PizzeriaView/FormPizza.cs b/Pizzeria/PizzeriaView/FormPizza.cs index 1191b4d..e43c4f9 100644 --- a/Pizzeria/PizzeriaView/FormPizza.cs +++ b/Pizzeria/PizzeriaView/FormPizza.cs @@ -179,8 +179,7 @@ namespace PizzeriaView Price = Convert.ToDouble(textBoxPrice.Text), PizzaComponents = _PizzaComponents }; - var operationResult = _id.HasValue ? _logic.Update(model) : - _logic.Create(model); + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); diff --git a/Pizzeria/PizzeriaView/FormReportGroupedOrders.Designer.cs b/Pizzeria/PizzeriaView/FormReportGroupedOrders.Designer.cs new file mode 100644 index 0000000..f79dd7a --- /dev/null +++ b/Pizzeria/PizzeriaView/FormReportGroupedOrders.Designer.cs @@ -0,0 +1,86 @@ +namespace PizzeriaView +{ + partial class FormReportGroupedOrders + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panel = new System.Windows.Forms.Panel(); + this.buttonToPDF = new System.Windows.Forms.Button(); + this.buttonMake = new System.Windows.Forms.Button(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonToPDF); + this.panel.Controls.Add(this.buttonMake); + this.panel.Dock = System.Windows.Forms.DockStyle.Top; + this.panel.Location = new System.Drawing.Point(0, 0); + this.panel.Name = "panel"; + this.panel.Size = new System.Drawing.Size(970, 52); + this.panel.TabIndex = 1; + // + // buttonToPDF + // + this.buttonToPDF.Location = new System.Drawing.Point(486, 12); + this.buttonToPDF.Name = "buttonToPDF"; + this.buttonToPDF.Size = new System.Drawing.Size(411, 29); + this.buttonToPDF.TabIndex = 5; + this.buttonToPDF.Text = "В PDF"; + this.buttonToPDF.UseVisualStyleBackColor = true; + this.buttonToPDF.Click += new System.EventHandler(this.buttonToPDF_Click); + // + // buttonMake + // + this.buttonMake.Location = new System.Drawing.Point(49, 12); + this.buttonMake.Name = "buttonMake"; + this.buttonMake.Size = new System.Drawing.Size(377, 29); + this.buttonMake.TabIndex = 4; + this.buttonMake.Text = "Сформировать"; + this.buttonMake.UseVisualStyleBackColor = true; + this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click); + // + // FormReportGroupedOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(970, 450); + this.Controls.Add(this.panel); + this.Name = "FormReportGroupedOrders"; + this.Text = "Отчёт по группированным заказам "; + this.panel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private Panel panel; + private Button buttonToPDF; + private Button buttonMake; + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormReportGroupedOrders.cs b/Pizzeria/PizzeriaView/FormReportGroupedOrders.cs new file mode 100644 index 0000000..a343e24 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormReportGroupedOrders.cs @@ -0,0 +1,80 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.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 PizzeriaView +{ + public partial class FormReportGroupedOrders : Form + { + private readonly ReportViewer reportViewer; + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportGroupedOrders(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportGroupedOrders.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void ButtonMake_Click(object sender, EventArgs e) + { + try + { + var dataSource = _logic.GetGroupedOrders(); + var source = new ReportDataSource("DataSetGroupedOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка группированных заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка группированных заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + + private void buttonToPDF_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveGroupedOrdersToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName, + }); + _logger.LogInformation("Сохранение списка группированных заказов"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка группированных заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/Pizzeria/PizzeriaView/FormReportGroupedOrders.resx b/Pizzeria/PizzeriaView/FormReportGroupedOrders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormReportGroupedOrders.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormReportShop.Designer.cs b/Pizzeria/PizzeriaView/FormReportShop.Designer.cs new file mode 100644 index 0000000..fbde795 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormReportShop.Designer.cs @@ -0,0 +1,116 @@ +namespace PizzeriaView +{ + partial class FormReportShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonSaveToExcel = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnShop = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnPizza = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(0, 6); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(223, 29); + this.buttonSaveToExcel.TabIndex = 3; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.ButtonSaveToExcel_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AllowUserToOrderColumns = true; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnShop, + this.ColumnPizza, + this.ColumnCount}); + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom; + this.dataGridView.Location = new System.Drawing.Point(0, 47); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(598, 403); + this.dataGridView.TabIndex = 2; + // + // ColumnShop + // + this.ColumnShop.FillWeight = 130F; + this.ColumnShop.HeaderText = "Магазин"; + this.ColumnShop.MinimumWidth = 6; + this.ColumnShop.Name = "ColumnShop"; + this.ColumnShop.ReadOnly = true; + // + // ColumnPizza + // + this.ColumnPizza.FillWeight = 140F; + this.ColumnPizza.HeaderText = "Пицца"; + this.ColumnPizza.MinimumWidth = 6; + this.ColumnPizza.Name = "ColumnPizza"; + this.ColumnPizza.ReadOnly = true; + // + // ColumnCount + // + this.ColumnCount.FillWeight = 90F; + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.ReadOnly = true; + // + // FormReportShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(598, 450); + this.Controls.Add(this.buttonSaveToExcel); + this.Controls.Add(this.dataGridView); + this.Name = "FormReportShop"; + this.Text = "Наполненость магазинов"; + this.Load += new System.EventHandler(this.FormReportShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnShop; + private DataGridViewTextBoxColumn ColumnPizza; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormReportShop.cs b/Pizzeria/PizzeriaView/FormReportShop.cs new file mode 100644 index 0000000..99daae2 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormReportShop.cs @@ -0,0 +1,78 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.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 PizzeriaView +{ + public partial class FormReportShop : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + + public FormReportShop(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportShop_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShops(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Pizzas) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + dataGridView.Rows.Add(Array.Empty()); + } + } + _logger.LogInformation("Загрузка списка пицц по магазинам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка пицц по магазинам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveShopsToExcelFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + _logger.LogInformation("Сохранение списка пицц по магазинам"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка пицц по магазинам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/Pizzeria/PizzeriaView/FormReportShop.resx b/Pizzeria/PizzeriaView/FormReportShop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Pizzeria/PizzeriaView/FormReportShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/FormShop.cs b/Pizzeria/PizzeriaView/FormShop.cs index f77249b..766b8d2 100644 --- a/Pizzeria/PizzeriaView/FormShop.cs +++ b/Pizzeria/PizzeriaView/FormShop.cs @@ -61,7 +61,7 @@ namespace PizzeriaView private void LoadData() { - _logger.LogInformation("Загрузка изделий в магазине"); + _logger.LogInformation("Загрузка пиццы в магазине"); try { if (_ShopPizzas != null) @@ -75,7 +75,7 @@ namespace PizzeriaView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + _logger.LogError(ex, "Ошибка загрузки пиццы магазина"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/Pizzeria/PizzeriaView/PizzeriaView.csproj b/Pizzeria/PizzeriaView/PizzeriaView.csproj index 58c5621..910b6ac 100644 --- a/Pizzeria/PizzeriaView/PizzeriaView.csproj +++ b/Pizzeria/PizzeriaView/PizzeriaView.csproj @@ -39,9 +39,12 @@ - - Always - + + Always + + + Always + \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/Program.cs b/Pizzeria/PizzeriaView/Program.cs index e600090..bc79d04 100644 --- a/Pizzeria/PizzeriaView/Program.cs +++ b/Pizzeria/PizzeriaView/Program.cs @@ -41,11 +41,13 @@ namespace Pizzeria services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -58,14 +60,14 @@ namespace Pizzeria services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaView/ReportGroupedOrders.rdlc b/Pizzeria/PizzeriaView/ReportGroupedOrders.rdlc new file mode 100644 index 0000000..2ef2b88 --- /dev/null +++ b/Pizzeria/PizzeriaView/ReportGroupedOrders.rdlc @@ -0,0 +1,441 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 20791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + PrecastConcretePlantContractsViewModels + /* Local Query */ + + + + Date + System.DateTime + + + OrdersCount + System.Int32 + + + OrdersSum + System.Decimal + + + + PrecastConcretePlantContracts.ViewModels + ReportGroupOrdersViewModel + PrecastConcretePlantContracts.ViewModels.ReportGroupOrdersViewModel, PrecastConcretePlantContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + Отчёт по заказам + + + + 0.6cm + 16.51cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + + + + ReportParameterPeriod + 0.6cm + 0.6cm + 16.51cm + 1 + + + 2pt + 2pt + 2pt + 2pt + + + + + + + 3.90406cm + + + 3.97461cm + + + 3.65711cm + + + + + 0.6cm + + + + + true + true + + + + + Дата создания + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Количество заказов + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Общая сумма заказов + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!Date.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!OrdersCount.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!OrdersSum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetGroupedOrders + 1.88242cm + 2.68676cm + 1.2cm + 11.53578cm + 2 + + + + + + true + true + + + + + Итого: + + + + 3.29409cm + 8.06542cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!OrdersSum.Value, "DataSetGroupedOrders") + + + + + + + 3.29409cm + 10.70653cm + 0.6cm + 3.48072cm + 4 + + + 2pt + 2pt + 2pt + 2pt + + + + 2in +