From bef04e5d07e9e3fe2a0dd9cab86d033974cf6cfd Mon Sep 17 00:00:00 2001 From: revengel66 Date: Wed, 28 Feb 2024 01:32:56 +0400 Subject: [PATCH 01/21] com1 --- Pizzeria/Pizzeria.sln | 24 +++ Pizzeria/Pizzeria/Form1.Designer.cs | 39 ----- Pizzeria/Pizzeria/Form1.cs | 10 -- Pizzeria/Pizzeria/Form1.resx | 120 ------------- .../BusinessLogic/ComponentLogic.cs | 105 +++++++++++ .../BusinessLogic/OrderLogic.cs | 164 ++++++++++++++++++ .../BusinessLogic/ProductLogic.cs | 106 +++++++++++ .../PizzeriaBusinessLogic.csproj | 17 ++ .../BindingModels/ComponentBindingModel.cs | 12 ++ .../BindingModels/OrderBindingModel.cs | 17 ++ .../BindingModels/ProductBindingModel.cs | 12 ++ .../IComponentLogic.cs | 15 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 15 ++ .../BusinessLogicsContracts/IProductLogic.cs | 15 ++ .../PizzeriaContracts.csproj | 13 ++ .../SearchModels/ComponentSearchModel.cs | 9 + .../SearchModels/OrderSearchModel.cs | 7 + .../SearchModels/ProductSearchModel.cs | 8 + .../StorageContracts/IComponentStorage.cs | 17 ++ .../StorageContracts/IOrderStorage.cs | 17 ++ .../StorageContracts/IProductStorage.cs | 17 ++ .../ViewModels/ComponentViewModel.cs | 14 ++ .../ViewModels/OrderViewModel.cs | 31 ++++ .../ViewModels/ProductViewModel.cs | 15 ++ .../PizzeriaDataModels/Enums/OrderStatus.cs | 12 ++ Pizzeria/PizzeriaDataModels/IId.cs | 7 + .../Models/IComponentModel.cs | 8 + .../PizzeriaDataModels/Models/IOrderModel.cs | 15 ++ .../Models/IProductModel.cs | 9 + .../PizzeriaDataModels.csproj | 9 + .../DataListSingleton.cs | 26 +++ .../Implements/ComponentStorage.cs | 102 +++++++++++ .../Implements/OrderStorage.cs | 104 +++++++++++ .../Implements/ProductStorage.cs | 100 +++++++++++ .../PizzeriaListImplement/Models/Component.cs | 42 +++++ .../PizzeriaListImplement/Models/Order.cs | 70 ++++++++ .../PizzeriaListImplement/Models/Product.cs | 49 ++++++ .../PizzeriaListImplement.csproj | 14 ++ 38 files changed, 1217 insertions(+), 169 deletions(-) delete mode 100644 Pizzeria/Pizzeria/Form1.Designer.cs delete mode 100644 Pizzeria/Pizzeria/Form1.cs delete mode 100644 Pizzeria/Pizzeria/Form1.resx create mode 100644 Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs create mode 100644 Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs create mode 100644 Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs create mode 100644 Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj create mode 100644 Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs create mode 100644 Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs create mode 100644 Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs create mode 100644 Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs create mode 100644 Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj create mode 100644 Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs create mode 100644 Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs create mode 100644 Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs create mode 100644 Pizzeria/PizzeriaContracts/StorageContracts/IComponentStorage.cs create mode 100644 Pizzeria/PizzeriaContracts/StorageContracts/IOrderStorage.cs create mode 100644 Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs create mode 100644 Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs create mode 100644 Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs create mode 100644 Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs create mode 100644 Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs create mode 100644 Pizzeria/PizzeriaDataModels/IId.cs create mode 100644 Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs create mode 100644 Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs create mode 100644 Pizzeria/PizzeriaDataModels/Models/IProductModel.cs create mode 100644 Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj create mode 100644 Pizzeria/PizzeriaListImplement/DataListSingleton.cs create mode 100644 Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs create mode 100644 Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs create mode 100644 Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs create mode 100644 Pizzeria/PizzeriaListImplement/Models/Component.cs create mode 100644 Pizzeria/PizzeriaListImplement/Models/Order.cs create mode 100644 Pizzeria/PizzeriaListImplement/Models/Product.cs create mode 100644 Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj diff --git a/Pizzeria/Pizzeria.sln b/Pizzeria/Pizzeria.sln index 62334c7..5968640 100644 --- a/Pizzeria/Pizzeria.sln +++ b/Pizzeria/Pizzeria.sln @@ -5,6 +5,14 @@ VisualStudioVersion = 17.9.34616.47 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pizzeria", "Pizzeria\Pizzeria.csproj", "{FBB3868C-DAC0-4481-9E44-16F7AAE00141}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaDataModels", "PizzeriaDataModels\PizzeriaDataModels.csproj", "{CD0B496B-7660-4744-9F6E-2ACF483F0299}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaContracts", "PizzeriaContracts\PizzeriaContracts.csproj", "{F039417A-21F0-4947-9623-C89A755AB8DD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{6640B0DE-53D5-4DE7-909A-C8111D5347EA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaBusinessLogic", "PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj", "{16EC5652-8348-4520-9736-1889B2749416}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +23,22 @@ Global {FBB3868C-DAC0-4481-9E44-16F7AAE00141}.Debug|Any CPU.Build.0 = Debug|Any CPU {FBB3868C-DAC0-4481-9E44-16F7AAE00141}.Release|Any CPU.ActiveCfg = Release|Any CPU {FBB3868C-DAC0-4481-9E44-16F7AAE00141}.Release|Any CPU.Build.0 = Release|Any CPU + {CD0B496B-7660-4744-9F6E-2ACF483F0299}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD0B496B-7660-4744-9F6E-2ACF483F0299}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD0B496B-7660-4744-9F6E-2ACF483F0299}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD0B496B-7660-4744-9F6E-2ACF483F0299}.Release|Any CPU.Build.0 = Release|Any CPU + {F039417A-21F0-4947-9623-C89A755AB8DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F039417A-21F0-4947-9623-C89A755AB8DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F039417A-21F0-4947-9623-C89A755AB8DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F039417A-21F0-4947-9623-C89A755AB8DD}.Release|Any CPU.Build.0 = Release|Any CPU + {6640B0DE-53D5-4DE7-909A-C8111D5347EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6640B0DE-53D5-4DE7-909A-C8111D5347EA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6640B0DE-53D5-4DE7-909A-C8111D5347EA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6640B0DE-53D5-4DE7-909A-C8111D5347EA}.Release|Any CPU.Build.0 = Release|Any CPU + {16EC5652-8348-4520-9736-1889B2749416}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16EC5652-8348-4520-9736-1889B2749416}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16EC5652-8348-4520-9736-1889B2749416}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16EC5652-8348-4520-9736-1889B2749416}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Pizzeria/Pizzeria/Form1.Designer.cs b/Pizzeria/Pizzeria/Form1.Designer.cs deleted file mode 100644 index fa58a96..0000000 --- a/Pizzeria/Pizzeria/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace Pizzeria -{ - partial class Form1 - { - /// - /// 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.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/Pizzeria/Pizzeria/Form1.cs b/Pizzeria/Pizzeria/Form1.cs deleted file mode 100644 index 626b4fd..0000000 --- a/Pizzeria/Pizzeria/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Pizzeria -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/Pizzeria/Pizzeria/Form1.resx b/Pizzeria/Pizzeria/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/Pizzeria/Pizzeria/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..c00ad57 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -0,0 +1,105 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaBusinessLogic.BusinessLogic +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + //_logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : + _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id} ", model.ComponentName, model.Id); + var element = _componentStorage.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(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel{ ComponentName = model.ComponentName }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..87dd32e --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,164 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Enums; +using System.Xml.Linq; + +namespace PizzeriaBusinessLogic.BusinessLogic +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public bool CreateOrder(OrderBindingModel model) + { + + CheckModel(model); + + if (model.Status == OrderStatus.Неизвестен) + { + _logger.LogWarning("Order status unknown"); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId: {Id}.", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + public bool ChangeStatus(OrderBindingModel model, OrderStatus status) + { + /*Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3*/ + + CheckModel(model, false); + + var order = _orderStorage.GetElement(new OrderSearchModel { + Id = model.Id + }); + + if (order == null) + { + throw new ArgumentNullException(nameof(order)); + } + + model.ProductId = order.ProductId; + model.DateCreate = order.DateCreate; + model.DateImplement = order.DateImplement; + model.Status = order.Status; + model.Count = order.Count; + model.Sum = order.Sum; + return true; + /* + + if (model.Status != status - 1) + { + _logger.LogWarning("Status update to " + status + " operation failed"); + return false; + } + + model.Status = status; + + if (model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Changing status operation faled"); + return false; + } + */ + + /* + + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = order.DateImplement; + } + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + return true; + */ + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.ProductId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.ProductId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("В заказе должно быть хотя бы одно изделие", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. ProductId: {ProductId}. ReinforcedCount: {Count}", model.Id, model.Sum, model.ProductId, model.Count); + } + + + + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs new file mode 100644 index 0000000..2873f11 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; + + +namespace PizzeriaBusinessLogic.BusinessLogic +{ + public class ProductLogic : IProductLogic + { + private readonly ILogger _logger; + private readonly IProductStorage _productStorage; + public ProductLogic(ILogger logger, IProductStorage ProductStorage) + { + //_logger = logger; + _productStorage = ProductStorage; + } + public List? ReadList(ProductSearchModel? model) + { + _logger.LogInformation("ReadList. ProductName:{ProductName}.Id:{ Id}", model?.ProductName, model?.Id); + var list = model == null ? _productStorage.GetFullList() : + _productStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ProductViewModel? ReadElement(ProductSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ProductName:{ProductName}.Id:{ Id} ", model.ProductName, model.Id); + var element = _productStorage.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(ProductBindingModel model) + { + CheckModel(model); + if (_productStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ProductBindingModel model) + { + CheckModel(model); + if (_productStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ProductBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_productStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ProductBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ProductName)) + { + throw new ArgumentNullException("Нет названия продукта", nameof(model.ProductName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Product. ProductName:{ProductName}.Price:{ Price}. Id: { Id}", model.ProductName, model.Price, model.Id); + var element = _productStorage.GetElement(new ProductSearchModel { ProductName = model.ProductName }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Продукт с таким названием уже есть"); + } + } + } +} diff --git a/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj b/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj new file mode 100644 index 0000000..d899681 --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/PizzeriaBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..bdc7840 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,12 @@ +using PizzeriaDataModels.Models; + +namespace PizzeriaContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + + } +} diff --git a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..755f4bb --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,17 @@ +using PizzeriaDataModels.Enums; +using PizzeriaDataModels.Models; + +namespace PizzeriaContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int ProductId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + + } +} diff --git a/Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs new file mode 100644 index 0000000..9ff2ff5 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs @@ -0,0 +1,12 @@ +using PizzeriaDataModels.Models; +namespace PizzeriaContracts.BindingModels +{ + public class ProductBindingModel : IProductModel + { + public int Id { get; set; } + public string ProductName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary ProductComponents {get;set;} = new(); + + } +} diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..4f4412d --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,15 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..fda864a --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs new file mode 100644 index 0000000..a21bcfd --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs @@ -0,0 +1,15 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.BusinessLogicsContracts +{ + public interface IProductLogic + { + List? ReadList(ProductSearchModel? model); + ProductViewModel? ReadElement(ProductSearchModel model); + bool Create(ProductBindingModel model); + bool Update(ProductBindingModel model); + bool Delete(ProductBindingModel model); + } +} diff --git a/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj b/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj new file mode 100644 index 0000000..f8743a9 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/PizzeriaContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..f5684bb --- /dev/null +++ b/Pizzeria/PizzeriaContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,9 @@ +namespace PizzeriaContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + + } +} diff --git a/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..000683a --- /dev/null +++ b/Pizzeria/PizzeriaContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace PizzeriaContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs new file mode 100644 index 0000000..7c2d61a --- /dev/null +++ b/Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs @@ -0,0 +1,8 @@ +namespace PizzeriaContracts.SearchModels +{ + public class ProductSearchModel + { + public int? Id { get; set; } + public string? ProductName { get; set; } + } +} diff --git a/Pizzeria/PizzeriaContracts/StorageContracts/IComponentStorage.cs b/Pizzeria/PizzeriaContracts/StorageContracts/IComponentStorage.cs new file mode 100644 index 0000000..04baea2 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/StorageContracts/IComponentStorage.cs @@ -0,0 +1,17 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.StorageContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + + } +} diff --git a/Pizzeria/PizzeriaContracts/StorageContracts/IOrderStorage.cs b/Pizzeria/PizzeriaContracts/StorageContracts/IOrderStorage.cs new file mode 100644 index 0000000..e60b5dd --- /dev/null +++ b/Pizzeria/PizzeriaContracts/StorageContracts/IOrderStorage.cs @@ -0,0 +1,17 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.StorageContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + + } +} diff --git a/Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs b/Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs new file mode 100644 index 0000000..9b0bfb1 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs @@ -0,0 +1,17 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.StorageContracts +{ + public interface IProductStorage + { + List GetFullList(); + List GetFilteredList(ProductSearchModel model); + ProductViewModel? GetElement(ProductSearchModel model); + ProductViewModel? Insert(ProductBindingModel model); + ProductViewModel? Update(ProductBindingModel model); + ProductViewModel? Delete(ProductBindingModel model); + + } +} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..614f252 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,14 @@ +using PizzeriaDataModels.Models; +using System.ComponentModel; + +namespace PizzeriaContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..f5042cf --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,31 @@ +using PizzeriaDataModels.Enums; +using PizzeriaDataModels.Models; +using System.ComponentModel; + +namespace PizzeriaContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int ProductId { get; set; } + + [DisplayName("Изделие")] + public string ProductName { get; set; } = string.Empty; + + [DisplayName("Количество")] + public int Count { get; set; } + + [DisplayName("Сумма")] + public double Sum { get; set; } + + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs new file mode 100644 index 0000000..c15904f --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs @@ -0,0 +1,15 @@ +using PizzeriaDataModels.Models; +using System.ComponentModel; + +namespace PizzeriaContracts.ViewModels +{ + public class ProductViewModel : IProductModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string ProductName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary ProductComponents {get;set;} = new(); + } +} diff --git a/Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs b/Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..bc1856e --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Enums/OrderStatus.cs @@ -0,0 +1,12 @@ +namespace PizzeriaDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + + } +} diff --git a/Pizzeria/PizzeriaDataModels/IId.cs b/Pizzeria/PizzeriaDataModels/IId.cs new file mode 100644 index 0000000..7ce0d2f --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace PizzeriaDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs b/Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..001166c --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Models/IComponentModel.cs @@ -0,0 +1,8 @@ +namespace PizzeriaDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..11c9662 --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs @@ -0,0 +1,15 @@ +using PizzeriaDataModels.Enums; + +namespace PizzeriaDataModels.Models +{ + public interface IOrderModel : IId + { + int ProductId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + + } +} diff --git a/Pizzeria/PizzeriaDataModels/Models/IProductModel.cs b/Pizzeria/PizzeriaDataModels/Models/IProductModel.cs new file mode 100644 index 0000000..54548eb --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Models/IProductModel.cs @@ -0,0 +1,9 @@ +namespace PizzeriaDataModels.Models +{ + public interface IProductModel : IId + { + string ProductName { get; } + double Price { get; } + Dictionary ProductComponents { get; } + } +} diff --git a/Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj b/Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/PizzeriaDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs new file mode 100644 index 0000000..c8ac9b2 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs @@ -0,0 +1,26 @@ +using PizzeriaListImplement.Models; + +namespace PizzeriaListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Products { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Products = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..8591ad0 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,102 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaListImplement.Models; + + +namespace PizzeriaListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) || (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + } +} diff --git a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..0eff7eb --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs @@ -0,0 +1,104 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaListImplement.Models; + +namespace PizzeriaListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if ((model.Id.HasValue && order.Id == model.Id)) + { + return order.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + + } +} diff --git a/Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs new file mode 100644 index 0000000..56441b9 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs @@ -0,0 +1,100 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaListImplement.Models; + +namespace PizzeriaListImplement.Implements +{ + public class ProductStorage : IProductStorage + { + private readonly DataListSingleton _source; + public ProductStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var product in _source.Products) + { + result.Add(product.GetViewModel); + } + return result; + } + public List GetFilteredList(ProductSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ProductName)) + { + return result; + } + foreach (var product in _source.Products) + { + if (product.ProductName.Contains(model.ProductName)) + { + result.Add(product.GetViewModel); + } + } + return result; + } + public ProductViewModel? GetElement(ProductSearchModel model) + { + if (string.IsNullOrEmpty(model.ProductName) && !model.Id.HasValue) + { + return null; + } + foreach (var product in _source.Products) + { + if ((!string.IsNullOrEmpty(model.ProductName) && product.ProductName == model.ProductName) || (model.Id.HasValue && product.Id == model.Id)) + { + return product.GetViewModel; + } + } + return null; + } + public ProductViewModel? Insert(ProductBindingModel model) + { + model.Id = 1; + foreach (var product in _source.Products) + { + if (model.Id <= product.Id) + { + model.Id = product.Id + 1; + } + } + var newProduct = Product.Create(model); + if (newProduct == null) + { + return null; + } + _source.Products.Add(newProduct); + return newProduct.GetViewModel; + } + public ProductViewModel? Update(ProductBindingModel model) + { + foreach (var product in _source.Products) + { + if (product.Id == model.Id) + { + product.Update(model); + return product.GetViewModel; + } + } + return null; + } + public ProductViewModel? Delete(ProductBindingModel model) + { + for (int i = 0; i < _source.Products.Count; ++i) + { + if (_source.Products[i].Id == model.Id) + { + var element = _source.Products[i]; + _source.Products.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Models/Component.cs b/Pizzeria/PizzeriaListImplement/Models/Component.cs new file mode 100644 index 0000000..cbf80c4 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Models/Component.cs @@ -0,0 +1,42 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; + +namespace PizzeriaListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/Pizzeria/PizzeriaListImplement/Models/Order.cs b/Pizzeria/PizzeriaListImplement/Models/Order.cs new file mode 100644 index 0000000..93de7f0 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Models/Order.cs @@ -0,0 +1,70 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Enums; +using PizzeriaDataModels.Models; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace PizzeriaListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int ProductId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } + + public DateTime DateCreate { get; private set; } + + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ProductId = model.ProductId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + ProductId = ProductId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + } +} diff --git a/Pizzeria/PizzeriaListImplement/Models/Product.cs b/Pizzeria/PizzeriaListImplement/Models/Product.cs new file mode 100644 index 0000000..b17aeb7 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Models/Product.cs @@ -0,0 +1,49 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; + +namespace PizzeriaListImplement.Models +{ + public class Product : IProductModel + { + public int Id { get; private set; } + public string ProductName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary ProductComponents + { + get; + private set; + } = new Dictionary(); + public static Product? Create(ProductBindingModel? model) + { + if (model == null) + { + return null; + } + return new Product() + { + Id = model.Id, + ProductName = model.ProductName, + Price = model.Price, + ProductComponents = model.ProductComponents + }; + } + public void Update(ProductBindingModel? model) + { + if (model == null) + { + return; + } + ProductName = model.ProductName; + Price = model.Price; + ProductComponents = model.ProductComponents; + } + public ProductViewModel GetViewModel => new() + { + Id = Id, + ProductName = ProductName, + Price = Price, + ProductComponents = ProductComponents + }; + } +} diff --git a/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj b/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj new file mode 100644 index 0000000..b612a23 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/PizzeriaListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + -- 2.25.1 From 96f448d45b84a0d6c6c7b66edbd2745d564de2d6 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Sun, 10 Mar 2024 15:45:45 +0400 Subject: [PATCH 02/21] new --- Pizzeria/Pizzeria/FormComponents.Designer.cs | 120 +++++++++++++++++++ Pizzeria/Pizzeria/FormComponents.cs | 73 +++++++++++ Pizzeria/Pizzeria/FormComponents.resx | 120 +++++++++++++++++++ Pizzeria/Pizzeria/Program.cs | 40 ++++++- 4 files changed, 350 insertions(+), 3 deletions(-) create mode 100644 Pizzeria/Pizzeria/FormComponents.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormComponents.cs create mode 100644 Pizzeria/Pizzeria/FormComponents.resx diff --git a/Pizzeria/Pizzeria/FormComponents.Designer.cs b/Pizzeria/Pizzeria/FormComponents.Designer.cs new file mode 100644 index 0000000..0117f39 --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponents.Designer.cs @@ -0,0 +1,120 @@ +namespace Pizzeria +{ + partial class FormComponents + { + /// + /// 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() + { + dataGridView = new DataGridView(); + ButtonAdd = new Button(); + ButtonRef = new Button(); + ButtonDel = new Button(); + ButtonUpd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(628, 450); + dataGridView.TabIndex = 0; + dataGridView.CellContentClick += dataGridView_CellContentClick; + // + // ButtonAdd + // + ButtonAdd.Location = new Point(671, 47); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(94, 29); + ButtonAdd.TabIndex = 1; + ButtonAdd.Text = "Добавить"; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // ButtonRef + // + ButtonRef.Location = new Point(671, 94); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(94, 29); + ButtonRef.TabIndex = 2; + ButtonRef.Text = "Изменить"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; + // + // ButtonDel + // + ButtonDel.Location = new Point(671, 144); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(94, 29); + ButtonDel.TabIndex = 3; + ButtonDel.Text = "Удалить"; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonUpd + // + ButtonUpd.Location = new Point(671, 191); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(94, 29); + ButtonUpd.TabIndex = 4; + ButtonUpd.Text = "Обновить"; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(ButtonUpd); + Controls.Add(ButtonDel); + Controls.Add(ButtonRef); + Controls.Add(ButtonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Компоненты"; + Load += FormComponent_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonAdd; + private Button ButtonRef; + private Button ButtonDel; + private Button ButtonUpd; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormComponents.cs b/Pizzeria/Pizzeria/FormComponents.cs new file mode 100644 index 0000000..07c29bc --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponents.cs @@ -0,0 +1,73 @@ +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.Logging; +using PizzeriaContracts.BusinessLogicsContracts; + +namespace Pizzeria +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponent_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["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); + } + } + + private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + } + private void ButtonRef_Click(object sender, EventArgs e) + { + + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/Pizzeria/Pizzeria/FormComponents.resx b/Pizzeria/Pizzeria/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponents.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/Pizzeria/Program.cs b/Pizzeria/Pizzeria/Program.cs index 25f4942..88a8498 100644 --- a/Pizzeria/Pizzeria/Program.cs +++ b/Pizzeria/Pizzeria/Program.cs @@ -1,17 +1,51 @@ +using Microsoft.Extensions.DependencyInjection; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.StorageContracts; +using System.Drawing; +using System; + namespace Pizzeria { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, + /*/ To customize application configuration such as set high DPI + settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + */ + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + 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 -- 2.25.1 From 54d9e5e1f72a610f8d9e50ec7396ab24b553d8b8 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Sun, 10 Mar 2024 16:46:16 +0400 Subject: [PATCH 03/21] last --- ...mponent - Копировать.Designer.cs | 118 +++++++++++++++++ .../FormComponent - Копировать.resx | 120 ++++++++++++++++++ Pizzeria/Pizzeria/FormComponent.Designer.cs | 118 +++++++++++++++++ Pizzeria/Pizzeria/FormComponent.cs | 95 ++++++++++++++ Pizzeria/Pizzeria/FormComponent.resx | 120 ++++++++++++++++++ Pizzeria/Pizzeria/FormComponents.Designer.cs | 1 - Pizzeria/Pizzeria/FormComponents.cs | 50 +++++++- Pizzeria/Pizzeria/Pizzeria.csproj | 23 ++++ Pizzeria/Pizzeria/Program.cs | 4 + Pizzeria/Pizzeria/nlog.config | 15 +++ 10 files changed, 657 insertions(+), 7 deletions(-) create mode 100644 Pizzeria/Pizzeria/FormComponent - Копировать.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormComponent - Копировать.resx create mode 100644 Pizzeria/Pizzeria/FormComponent.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormComponent.cs create mode 100644 Pizzeria/Pizzeria/FormComponent.resx create mode 100644 Pizzeria/Pizzeria/nlog.config diff --git a/Pizzeria/Pizzeria/FormComponent - Копировать.Designer.cs b/Pizzeria/Pizzeria/FormComponent - Копировать.Designer.cs new file mode 100644 index 0000000..4d1d77a --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponent - Копировать.Designer.cs @@ -0,0 +1,118 @@ +namespace Pizzeria +{ + partial class FormComponent + { + /// + /// 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() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 21); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(12, 50); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(38, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена:"; + // + // textBoxName + // + textBoxName.Location = new Point(100, 18); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(233, 23); + textBoxName.TabIndex = 2; + // + // textBoxCost + // + textBoxCost.Location = new Point(100, 47); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(233, 23); + textBoxCost.TabIndex = 2; + // + // buttonSave + // + buttonSave.Location = new Point(177, 93); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 3; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(258, 93); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(345, 136); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormComponent"; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormComponent - Копировать.resx b/Pizzeria/Pizzeria/FormComponent - Копировать.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponent - Копировать.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/Pizzeria/FormComponent.Designer.cs b/Pizzeria/Pizzeria/FormComponent.Designer.cs new file mode 100644 index 0000000..4d1d77a --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace Pizzeria +{ + partial class FormComponent + { + /// + /// 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() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 21); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(12, 50); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(38, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена:"; + // + // textBoxName + // + textBoxName.Location = new Point(100, 18); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(233, 23); + textBoxName.TabIndex = 2; + // + // textBoxCost + // + textBoxCost.Location = new Point(100, 47); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(233, 23); + textBoxCost.TabIndex = 2; + // + // buttonSave + // + buttonSave.Location = new Point(177, 93); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 3; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(258, 93); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(345, 136); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormComponent"; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormComponent.cs b/Pizzeria/Pizzeria/FormComponent.cs new file mode 100644 index 0000000..1f694de --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponent.cs @@ -0,0 +1,95 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; + + +namespace Pizzeria +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + + } + + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + 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; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + 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/Pizzeria/FormComponent.resx b/Pizzeria/Pizzeria/FormComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Pizzeria/Pizzeria/FormComponent.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/Pizzeria/FormComponents.Designer.cs b/Pizzeria/Pizzeria/FormComponents.Designer.cs index 0117f39..dcc698e 100644 --- a/Pizzeria/Pizzeria/FormComponents.Designer.cs +++ b/Pizzeria/Pizzeria/FormComponents.Designer.cs @@ -50,7 +50,6 @@ dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.Size = new Size(628, 450); dataGridView.TabIndex = 0; - dataGridView.CellContentClick += dataGridView_CellContentClick; // // ButtonAdd // diff --git a/Pizzeria/Pizzeria/FormComponents.cs b/Pizzeria/Pizzeria/FormComponents.cs index 07c29bc..6684db0 100644 --- a/Pizzeria/Pizzeria/FormComponents.cs +++ b/Pizzeria/Pizzeria/FormComponents.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Logging; using Microsoft.VisualBasic.Logging; +using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts; namespace Pizzeria @@ -39,10 +40,6 @@ namespace Pizzeria } } - private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) - { - - } private void ButtonAdd_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); @@ -54,20 +51,61 @@ namespace Pizzeria } } + } private void ButtonRef_Click(object sender, EventArgs e) { - + 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 ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } private void ButtonUpd_Click(object sender, EventArgs e) { - + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } } } } diff --git a/Pizzeria/Pizzeria/Pizzeria.csproj b/Pizzeria/Pizzeria/Pizzeria.csproj index b57c89e..2da550f 100644 --- a/Pizzeria/Pizzeria/Pizzeria.csproj +++ b/Pizzeria/Pizzeria/Pizzeria.csproj @@ -8,4 +8,27 @@ enable + + + + + + + Always + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Pizzeria/Pizzeria/Program.cs b/Pizzeria/Pizzeria/Program.cs index 88a8498..7ca1d01 100644 --- a/Pizzeria/Pizzeria/Program.cs +++ b/Pizzeria/Pizzeria/Program.cs @@ -3,6 +3,10 @@ using PizzeriaContracts.BusinessLogicsContracts; using PizzeriaContracts.StorageContracts; using System.Drawing; using System; +using PizzeriaListImplement.Implements; +using PizzeriaBusinessLogic.BusinessLogic; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; namespace Pizzeria { diff --git a/Pizzeria/Pizzeria/nlog.config b/Pizzeria/Pizzeria/nlog.config new file mode 100644 index 0000000..85797a7 --- /dev/null +++ b/Pizzeria/Pizzeria/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file -- 2.25.1 From 10698313a9d593153ca5c1a714579ebb270bb74f Mon Sep 17 00:00:00 2001 From: revengel66 Date: Sun, 10 Mar 2024 16:49:40 +0400 Subject: [PATCH 04/21] vv --- ...mponent - Копировать.Designer.cs | 118 ----------------- .../FormComponent - Копировать.resx | 120 ------------------ 2 files changed, 238 deletions(-) delete mode 100644 Pizzeria/Pizzeria/FormComponent - Копировать.Designer.cs delete mode 100644 Pizzeria/Pizzeria/FormComponent - Копировать.resx diff --git a/Pizzeria/Pizzeria/FormComponent - Копировать.Designer.cs b/Pizzeria/Pizzeria/FormComponent - Копировать.Designer.cs deleted file mode 100644 index 4d1d77a..0000000 --- a/Pizzeria/Pizzeria/FormComponent - Копировать.Designer.cs +++ /dev/null @@ -1,118 +0,0 @@ -namespace Pizzeria -{ - partial class FormComponent - { - /// - /// 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() - { - labelName = new Label(); - labelPrice = new Label(); - textBoxName = new TextBox(); - textBoxCost = new TextBox(); - buttonSave = new Button(); - buttonCancel = new Button(); - SuspendLayout(); - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(12, 21); - labelName.Name = "labelName"; - labelName.Size = new Size(62, 15); - labelName.TabIndex = 0; - labelName.Text = "Название:"; - // - // labelPrice - // - labelPrice.AutoSize = true; - labelPrice.Location = new Point(12, 50); - labelPrice.Name = "labelPrice"; - labelPrice.Size = new Size(38, 15); - labelPrice.TabIndex = 1; - labelPrice.Text = "Цена:"; - // - // textBoxName - // - textBoxName.Location = new Point(100, 18); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(233, 23); - textBoxName.TabIndex = 2; - // - // textBoxCost - // - textBoxCost.Location = new Point(100, 47); - textBoxCost.Name = "textBoxCost"; - textBoxCost.Size = new Size(233, 23); - textBoxCost.TabIndex = 2; - // - // buttonSave - // - buttonSave.Location = new Point(177, 93); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(75, 23); - buttonSave.TabIndex = 3; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; - // - // buttonCancel - // - buttonCancel.Location = new Point(258, 93); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(75, 23); - buttonCancel.TabIndex = 3; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += buttonCancel_Click; - // - // FormComponent - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(345, 136); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(textBoxCost); - Controls.Add(textBoxName); - Controls.Add(labelPrice); - Controls.Add(labelName); - Name = "FormComponent"; - Text = "Компонент"; - Load += FormComponent_Load; - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Label labelName; - private Label labelPrice; - private TextBox textBoxName; - private TextBox textBoxCost; - private Button buttonSave; - private Button buttonCancel; - } -} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormComponent - Копировать.resx b/Pizzeria/Pizzeria/FormComponent - Копировать.resx deleted file mode 100644 index af32865..0000000 --- a/Pizzeria/Pizzeria/FormComponent - Копировать.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 -- 2.25.1 From 8eee668ae478625b939a2b098205f86d7f81635e Mon Sep 17 00:00:00 2001 From: revengel66 Date: Mon, 11 Mar 2024 00:29:19 +0400 Subject: [PATCH 05/21] end lab1 --- Pizzeria/Pizzeria/FormComponent.Designer.cs | 4 +- Pizzeria/Pizzeria/FormComponent.cs | 26 ++--- Pizzeria/Pizzeria/FormComponents.Designer.cs | 72 +++++++----- Pizzeria/Pizzeria/FormComponents.cs | 27 ++--- Pizzeria/Pizzeria/Program.cs | 15 +-- .../BusinessLogic/ComponentLogic.cs | 9 +- .../BusinessLogic/OrderLogic.cs | 66 ++++------- .../BusinessLogic/ProductLogic.cs | 106 ------------------ .../BindingModels/OrderBindingModel.cs | 2 +- .../BindingModels/ProductBindingModel.cs | 12 -- .../BusinessLogicsContracts/IProductLogic.cs | 15 --- .../SearchModels/ProductSearchModel.cs | 8 -- .../StorageContracts/IProductStorage.cs | 17 --- .../ViewModels/ComponentViewModel.cs | 2 +- .../ViewModels/OrderViewModel.cs | 6 +- .../ViewModels/ProductViewModel.cs | 15 --- .../PizzeriaDataModels/Models/IOrderModel.cs | 2 +- .../Models/IProductModel.cs | 9 -- .../DataListSingleton.cs | 4 +- .../Implements/OrderStorage.cs | 25 +++-- .../Implements/ProductStorage.cs | 100 ----------------- .../PizzeriaListImplement/Models/Order.cs | 6 +- .../PizzeriaListImplement/Models/Product.cs | 49 -------- 23 files changed, 123 insertions(+), 474 deletions(-) delete mode 100644 Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs delete mode 100644 Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs delete mode 100644 Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs delete mode 100644 Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs delete mode 100644 Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs delete mode 100644 Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs delete mode 100644 Pizzeria/PizzeriaDataModels/Models/IProductModel.cs delete mode 100644 Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs delete mode 100644 Pizzeria/PizzeriaListImplement/Models/Product.cs diff --git a/Pizzeria/Pizzeria/FormComponent.Designer.cs b/Pizzeria/Pizzeria/FormComponent.Designer.cs index 4d1d77a..1c685f0 100644 --- a/Pizzeria/Pizzeria/FormComponent.Designer.cs +++ b/Pizzeria/Pizzeria/FormComponent.Designer.cs @@ -70,6 +70,7 @@ // // buttonSave // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonSave.Location = new Point(177, 93); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(75, 23); @@ -80,6 +81,7 @@ // // buttonCancel // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonCancel.Location = new Point(258, 93); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(75, 23); @@ -100,7 +102,7 @@ Controls.Add(labelPrice); Controls.Add(labelName); Name = "FormComponent"; - Text = "Компонент"; + Text = "Ингредиент"; Load += FormComponent_Load; ResumeLayout(false); PerformLayout(); diff --git a/Pizzeria/Pizzeria/FormComponent.cs b/Pizzeria/Pizzeria/FormComponent.cs index 1f694de..e5ebb06 100644 --- a/Pizzeria/Pizzeria/FormComponent.cs +++ b/Pizzeria/Pizzeria/FormComponent.cs @@ -27,11 +27,10 @@ namespace Pizzeria { try { - _logger.LogInformation("Получение компонента"); + _logger.LogInformation("Получение ингредиента"); var view = _logic.ReadElement(new ComponentSearchModel { - Id = - _id.Value + Id =_id.Value }); if (view != null) { @@ -41,9 +40,8 @@ namespace Pizzeria } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения компонента"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка получения ингредиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -53,11 +51,10 @@ namespace Pizzeria { if (string.IsNullOrEmpty(textBoxName.Text)) { - MessageBox.Show("Заполните название", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Сохранение компонента"); + _logger.LogInformation("Сохранение ингредиента"); try { var model = new ComponentBindingModel @@ -66,22 +63,19 @@ namespace Pizzeria ComponentName = textBoxName.Text, Cost = Convert.ToDouble(textBoxCost.Text) }; - 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("Ошибка при сохранении. Дополнительная информация в логах."); } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", - MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения компонента"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка сохранения ингредиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/Pizzeria/Pizzeria/FormComponents.Designer.cs b/Pizzeria/Pizzeria/FormComponents.Designer.cs index dcc698e..73f5145 100644 --- a/Pizzeria/Pizzeria/FormComponents.Designer.cs +++ b/Pizzeria/Pizzeria/FormComponents.Designer.cs @@ -30,9 +30,9 @@ { dataGridView = new DataGridView(); ButtonAdd = new Button(); - ButtonRef = new Button(); - ButtonDel = new Button(); ButtonUpd = new Button(); + ButtonDel = new Button(); + ButtonRef = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // @@ -41,6 +41,7 @@ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Dock = DockStyle.Left; dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(3, 2, 3, 2); dataGridView.MultiSelect = false; dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; @@ -48,62 +49,71 @@ dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 29; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(628, 450); + dataGridView.Size = new Size(550, 338); dataGridView.TabIndex = 0; // // ButtonAdd // - ButtonAdd.Location = new Point(671, 47); + ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonAdd.Location = new Point(587, 35); + ButtonAdd.Margin = new Padding(3, 2, 3, 2); ButtonAdd.Name = "ButtonAdd"; - ButtonAdd.Size = new Size(94, 29); + ButtonAdd.Size = new Size(82, 22); ButtonAdd.TabIndex = 1; ButtonAdd.Text = "Добавить"; ButtonAdd.UseVisualStyleBackColor = true; ButtonAdd.Click += ButtonAdd_Click; // - // ButtonRef + // ButtonUpd // - ButtonRef.Location = new Point(671, 94); - ButtonRef.Name = "ButtonRef"; - ButtonRef.Size = new Size(94, 29); - ButtonRef.TabIndex = 2; - ButtonRef.Text = "Изменить"; - ButtonRef.UseVisualStyleBackColor = true; - ButtonRef.Click += ButtonRef_Click; + ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonUpd.Location = new Point(587, 70); + ButtonUpd.Margin = new Padding(3, 2, 3, 2); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(82, 22); + ButtonUpd.TabIndex = 2; + ButtonUpd.Text = "Изменить"; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; // // ButtonDel // - ButtonDel.Location = new Point(671, 144); + ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonDel.Location = new Point(587, 108); + ButtonDel.Margin = new Padding(3, 2, 3, 2); ButtonDel.Name = "ButtonDel"; - ButtonDel.Size = new Size(94, 29); + ButtonDel.Size = new Size(82, 22); ButtonDel.TabIndex = 3; ButtonDel.Text = "Удалить"; ButtonDel.UseVisualStyleBackColor = true; ButtonDel.Click += ButtonDel_Click; // - // ButtonUpd + // ButtonRef // - ButtonUpd.Location = new Point(671, 191); - ButtonUpd.Name = "ButtonUpd"; - ButtonUpd.Size = new Size(94, 29); - ButtonUpd.TabIndex = 4; - ButtonUpd.Text = "Обновить"; - ButtonUpd.UseVisualStyleBackColor = true; - ButtonUpd.Click += ButtonUpd_Click; + ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonRef.Location = new Point(587, 143); + ButtonRef.Margin = new Padding(3, 2, 3, 2); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(82, 22); + ButtonRef.TabIndex = 4; + ButtonRef.Text = "Обновить"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; // // FormComponents // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Controls.Add(ButtonUpd); - Controls.Add(ButtonDel); + ClientSize = new Size(700, 338); Controls.Add(ButtonRef); + Controls.Add(ButtonDel); + Controls.Add(ButtonUpd); Controls.Add(ButtonAdd); Controls.Add(dataGridView); + Margin = new Padding(3, 2, 3, 2); Name = "FormComponents"; - Text = "Компоненты"; - Load += FormComponent_Load; + Text = "Ингредиенты"; + Load += FormComponents_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); } @@ -112,8 +122,8 @@ private DataGridView dataGridView; private Button ButtonAdd; - private Button ButtonRef; - private Button ButtonDel; private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonRef; } } \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormComponents.cs b/Pizzeria/Pizzeria/FormComponents.cs index 6684db0..42ecb4b 100644 --- a/Pizzeria/Pizzeria/FormComponents.cs +++ b/Pizzeria/Pizzeria/FormComponents.cs @@ -1,8 +1,6 @@ using Microsoft.Extensions.Logging; -using Microsoft.VisualBasic.Logging; using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts; - namespace Pizzeria { public partial class FormComponents : Form @@ -16,7 +14,7 @@ namespace Pizzeria _logic = logic; } - private void FormComponent_Load(object sender, EventArgs e) + private void FormComponents_Load(object sender, EventArgs e) { LoadData(); } @@ -31,11 +29,11 @@ namespace Pizzeria dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } - _logger.LogInformation("Загрузка компонентов"); + _logger.LogInformation("Загрузка ингредиентов"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонентов"); + _logger.LogError(ex, "Ошибка загрузки ингредиентов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); } } @@ -62,12 +60,10 @@ namespace Pizzeria { if (dataGridView.SelectedRows.Count == 1) { - if (MessageBox.Show("Удалить запись?", "Вопрос", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление компонента"); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление ингредиента"); try { if (!_logic.Delete(new ComponentBindingModel @@ -81,9 +77,8 @@ namespace Pizzeria } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления компонента"); - MessageBox.Show(ex.Message, "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка удаления ингредиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } @@ -94,12 +89,10 @@ namespace Pizzeria { if (dataGridView.SelectedRows.Count == 1) { - var service = - Program.ServiceProvider?.GetService(typeof(FormComponent)); + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); if (service is FormComponent form) { - form.Id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) { LoadData(); diff --git a/Pizzeria/Pizzeria/Program.cs b/Pizzeria/Pizzeria/Program.cs index 7ca1d01..32150d8 100644 --- a/Pizzeria/Pizzeria/Program.cs +++ b/Pizzeria/Pizzeria/Program.cs @@ -20,15 +20,12 @@ namespace Pizzeria [STAThread] static void Main() { - /*/ To customize application configuration such as set high DPI - settings or default font, - // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); Application.Run(_serviceProvider.GetRequiredService()); - */ } private static void ConfigureServices(ServiceCollection services) { @@ -39,17 +36,17 @@ 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(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs index c00ad57..5f95a30 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -13,9 +13,10 @@ namespace PizzeriaBusinessLogic.BusinessLogic private readonly IComponentStorage _componentStorage; public ComponentLogic(ILogger logger, IComponentStorage componentStorage) { - //_logger = logger; + _logger = logger; _componentStorage = componentStorage; } + public List? ReadList(ComponentSearchModel? model) { _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); @@ -88,17 +89,17 @@ namespace PizzeriaBusinessLogic.BusinessLogic } if (string.IsNullOrEmpty(model.ComponentName)) { - throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + throw new ArgumentNullException("Нет названия ингредиента", nameof(model.ComponentName)); } if (model.Cost <= 0) { - throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + throw new ArgumentNullException("Цена ингредиента должна быть больше 0", nameof(model.Cost)); } _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id); var element = _componentStorage.GetElement(new ComponentSearchModel{ ComponentName = model.ComponentName }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Компонент с таким названием уже есть"); + throw new InvalidOperationException("ингредиент с таким названием уже есть"); } } } diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs index 87dd32e..6465b13 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs @@ -4,8 +4,7 @@ using PizzeriaContracts.BusinessLogicsContracts; using PizzeriaContracts.SearchModels; using PizzeriaContracts.StorageContracts; using PizzeriaContracts.ViewModels; -using PizzeriaDataModels.Enums; -using System.Xml.Linq; +using PizzeriaDataModels.Enums; namespace PizzeriaBusinessLogic.BusinessLogic { @@ -20,15 +19,15 @@ namespace PizzeriaBusinessLogic.BusinessLogic _logger = logger; _orderStorage = orderStorage; } - + public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - if (model.Status == OrderStatus.Неизвестен) + if (model.Status != OrderStatus.Неизвестен) { - _logger.LogWarning("Order status unknown"); + _logger.LogWarning("Invalid order status"); return false; } model.Status = OrderStatus.Принят; @@ -39,6 +38,8 @@ namespace PizzeriaBusinessLogic.BusinessLogic } return true; } + + public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. OrderId: {Id}.", model?.Id); @@ -68,73 +69,44 @@ namespace PizzeriaBusinessLogic.BusinessLogic } public bool ChangeStatus(OrderBindingModel model, OrderStatus status) { - /*Неизвестен = -1, - Принят = 0, - Выполняется = 1, - Готов = 2, - Выдан = 3*/ - CheckModel(model, false); - var order = _orderStorage.GetElement(new OrderSearchModel { - Id = model.Id - }); - + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (order == null) { throw new ArgumentNullException(nameof(order)); } - - model.ProductId = order.ProductId; + model.PizzaId = order.PizzaId; + model.Count = order.Count; + model.Sum = order.Count; model.DateCreate = order.DateCreate; model.DateImplement = order.DateImplement; model.Status = order.Status; - model.Count = order.Count; - model.Sum = order.Sum; - return true; - /* if (model.Status != status - 1) { _logger.LogWarning("Status update to " + status + " operation failed"); return false; } - model.Status = status; if (model.Status == OrderStatus.Выдан) { model.DateImplement = DateTime.Now; } - if (_orderStorage.Update(model) == null) { model.Status--; _logger.LogWarning("Changing status operation faled"); return false; } - */ - - /* - - if (model.Status == OrderStatus.Готов) - { - model.DateImplement = DateTime.Now; - } - else - { - model.DateImplement = order.DateImplement; - } - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Change status operation failed"); - return false; - } return true; - */ + } private void CheckModel(OrderBindingModel model, bool withParams = true) { + if (model == null) { throw new ArgumentNullException(nameof(model)); @@ -143,22 +115,22 @@ namespace PizzeriaBusinessLogic.BusinessLogic { return; } - if (model.ProductId <= 0) + if (model.PizzaId <= 0) { - throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.ProductId)); + throw new ArgumentNullException("Некорректный идентификатор пиццы", nameof(model.PizzaId)); } if (model.Count <= 0) { - throw new ArgumentNullException("В заказе должно быть хотя бы одно изделие", nameof(model.Count)); + throw new ArgumentNullException("В заказе должно быть хотя бы одно пицца", nameof(model.Count)); } if (model.Sum <= 0) { throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum)); } - _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. ProductId: {ProductId}. ReinforcedCount: {Count}", model.Id, model.Sum, model.ProductId, model.Count); + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. PizzaId: {PizzaId}. ReinforcedCount: {Count}", model.Id, model.Sum, model.PizzaId, model.Count); } - - + + } } diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs deleted file mode 100644 index 2873f11..0000000 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs +++ /dev/null @@ -1,106 +0,0 @@ -using Microsoft.Extensions.Logging; -using PizzeriaContracts.BindingModels; -using PizzeriaContracts.BusinessLogicsContracts; -using PizzeriaContracts.SearchModels; -using PizzeriaContracts.StorageContracts; -using PizzeriaContracts.ViewModels; - - -namespace PizzeriaBusinessLogic.BusinessLogic -{ - public class ProductLogic : IProductLogic - { - private readonly ILogger _logger; - private readonly IProductStorage _productStorage; - public ProductLogic(ILogger logger, IProductStorage ProductStorage) - { - //_logger = logger; - _productStorage = ProductStorage; - } - public List? ReadList(ProductSearchModel? model) - { - _logger.LogInformation("ReadList. ProductName:{ProductName}.Id:{ Id}", model?.ProductName, model?.Id); - var list = model == null ? _productStorage.GetFullList() : - _productStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - public ProductViewModel? ReadElement(ProductSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. ProductName:{ProductName}.Id:{ Id} ", model.ProductName, model.Id); - var element = _productStorage.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(ProductBindingModel model) - { - CheckModel(model); - if (_productStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(ProductBindingModel model) - { - CheckModel(model); - if (_productStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(ProductBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_productStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - private void CheckModel(ProductBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.ProductName)) - { - throw new ArgumentNullException("Нет названия продукта", nameof(model.ProductName)); - } - if (model.Price <= 0) - { - throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); - } - _logger.LogInformation("Product. ProductName:{ProductName}.Price:{ Price}. Id: { Id}", model.ProductName, model.Price, model.Id); - var element = _productStorage.GetElement(new ProductSearchModel { ProductName = model.ProductName }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Продукт с таким названием уже есть"); - } - } - } -} diff --git a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs index 755f4bb..575d717 100644 --- a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs +++ b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs @@ -6,7 +6,7 @@ namespace PizzeriaContracts.BindingModels public class OrderBindingModel : IOrderModel { public int Id { get; set; } - public int ProductId { get; set; } + public int PizzaId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs deleted file mode 100644 index 9ff2ff5..0000000 --- a/Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -using PizzeriaDataModels.Models; -namespace PizzeriaContracts.BindingModels -{ - public class ProductBindingModel : IProductModel - { - public int Id { get; set; } - public string ProductName { get; set; } = string.Empty; - public double Price { get; set; } - public Dictionary ProductComponents {get;set;} = new(); - - } -} diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs deleted file mode 100644 index a21bcfd..0000000 --- a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs +++ /dev/null @@ -1,15 +0,0 @@ -using PizzeriaContracts.BindingModels; -using PizzeriaContracts.SearchModels; -using PizzeriaContracts.ViewModels; - -namespace PizzeriaContracts.BusinessLogicsContracts -{ - public interface IProductLogic - { - List? ReadList(ProductSearchModel? model); - ProductViewModel? ReadElement(ProductSearchModel model); - bool Create(ProductBindingModel model); - bool Update(ProductBindingModel model); - bool Delete(ProductBindingModel model); - } -} diff --git a/Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs deleted file mode 100644 index 7c2d61a..0000000 --- a/Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace PizzeriaContracts.SearchModels -{ - public class ProductSearchModel - { - public int? Id { get; set; } - public string? ProductName { get; set; } - } -} diff --git a/Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs b/Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs deleted file mode 100644 index 9b0bfb1..0000000 --- a/Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs +++ /dev/null @@ -1,17 +0,0 @@ -using PizzeriaContracts.BindingModels; -using PizzeriaContracts.SearchModels; -using PizzeriaContracts.ViewModels; - -namespace PizzeriaContracts.StorageContracts -{ - public interface IProductStorage - { - List GetFullList(); - List GetFilteredList(ProductSearchModel model); - ProductViewModel? GetElement(ProductSearchModel model); - ProductViewModel? Insert(ProductBindingModel model); - ProductViewModel? Update(ProductBindingModel model); - ProductViewModel? Delete(ProductBindingModel model); - - } -} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs index 614f252..1844231 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs @@ -6,7 +6,7 @@ namespace PizzeriaContracts.ViewModels public class ComponentViewModel : IComponentModel { public int Id { get; set; } - [DisplayName("Название компонента")] + [DisplayName("Название ингредиента")] public string ComponentName { get; set; } = string.Empty; [DisplayName("Цена")] public double Cost { get; set; } diff --git a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs index f5042cf..1d71477 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs @@ -8,10 +8,10 @@ namespace PizzeriaContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } - public int ProductId { get; set; } + public int PizzaId { get; set; } - [DisplayName("Изделие")] - public string ProductName { get; set; } = string.Empty; + [DisplayName("Пицца")] + public string PizzaName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs deleted file mode 100644 index c15904f..0000000 --- a/Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using PizzeriaDataModels.Models; -using System.ComponentModel; - -namespace PizzeriaContracts.ViewModels -{ - public class ProductViewModel : IProductModel - { - public int Id { get; set; } - [DisplayName("Название изделия")] - public string ProductName { get; set; } = string.Empty; - [DisplayName("Цена")] - public double Price { get; set; } - public Dictionary ProductComponents {get;set;} = new(); - } -} diff --git a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs index 11c9662..ed9a65e 100644 --- a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs +++ b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs @@ -4,7 +4,7 @@ namespace PizzeriaDataModels.Models { public interface IOrderModel : IId { - int ProductId { get; } + int PizzaId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/Pizzeria/PizzeriaDataModels/Models/IProductModel.cs b/Pizzeria/PizzeriaDataModels/Models/IProductModel.cs deleted file mode 100644 index 54548eb..0000000 --- a/Pizzeria/PizzeriaDataModels/Models/IProductModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace PizzeriaDataModels.Models -{ - public interface IProductModel : IId - { - string ProductName { get; } - double Price { get; } - Dictionary ProductComponents { get; } - } -} diff --git a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs index c8ac9b2..f5047b2 100644 --- a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs +++ b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs @@ -7,12 +7,12 @@ namespace PizzeriaListImplement private static DataListSingleton? _instance; public List Components { get; set; } public List Orders { get; set; } - public List Products { get; set; } + public List Pizzas { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); - Products = new List(); + Pizzas = new List(); } public static DataListSingleton GetInstance() { diff --git a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs index 0eff7eb..24b9031 100644 --- a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs +++ b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs @@ -3,6 +3,7 @@ using PizzeriaContracts.SearchModels; using PizzeriaContracts.StorageContracts; using PizzeriaContracts.ViewModels; using PizzeriaListImplement.Models; +using System.Xml.Linq; namespace PizzeriaListImplement.Implements { @@ -22,7 +23,7 @@ namespace PizzeriaListImplement.Implements { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return element.GetViewModel; + return AddPizzaName(element.GetViewModel); } } return null; @@ -37,7 +38,7 @@ namespace PizzeriaListImplement.Implements { if ((model.Id.HasValue && order.Id == model.Id)) { - return order.GetViewModel; + return AddPizzaName(order.GetViewModel); } } return null; @@ -54,7 +55,7 @@ namespace PizzeriaListImplement.Implements { if (order.Id == model.Id) { - result.Add(order.GetViewModel); + result.Add(AddPizzaName(order.GetViewModel)); } } return result; @@ -65,7 +66,7 @@ namespace PizzeriaListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(AddPizzaName(order.GetViewModel)); } return result; } @@ -85,7 +86,7 @@ namespace PizzeriaListImplement.Implements return null; } _source.Orders.Add(newOrder); - return newOrder.GetViewModel; + return AddPizzaName(newOrder.GetViewModel); } public OrderViewModel? Update(OrderBindingModel model) { @@ -94,11 +95,21 @@ namespace PizzeriaListImplement.Implements if (order.Id == model.Id) { order.Update(model); - return order.GetViewModel; + return AddPizzaName(order.GetViewModel); } } return null; } - + + private OrderViewModel AddPizzaName(OrderViewModel model) + { + var selectedPizza = _source.Pizzas.Find(pizza => pizza.Id == model.PizzaId); + if (selectedPizza != null) + { + model.PizzaName = selectedPizza.PizzaName; + } + return model; + } + } } diff --git a/Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs deleted file mode 100644 index 56441b9..0000000 --- a/Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs +++ /dev/null @@ -1,100 +0,0 @@ -using PizzeriaContracts.BindingModels; -using PizzeriaContracts.SearchModels; -using PizzeriaContracts.StorageContracts; -using PizzeriaContracts.ViewModels; -using PizzeriaListImplement.Models; - -namespace PizzeriaListImplement.Implements -{ - public class ProductStorage : IProductStorage - { - private readonly DataListSingleton _source; - public ProductStorage() - { - _source = DataListSingleton.GetInstance(); - } - public List GetFullList() - { - var result = new List(); - foreach (var product in _source.Products) - { - result.Add(product.GetViewModel); - } - return result; - } - public List GetFilteredList(ProductSearchModel model) - { - var result = new List(); - if (string.IsNullOrEmpty(model.ProductName)) - { - return result; - } - foreach (var product in _source.Products) - { - if (product.ProductName.Contains(model.ProductName)) - { - result.Add(product.GetViewModel); - } - } - return result; - } - public ProductViewModel? GetElement(ProductSearchModel model) - { - if (string.IsNullOrEmpty(model.ProductName) && !model.Id.HasValue) - { - return null; - } - foreach (var product in _source.Products) - { - if ((!string.IsNullOrEmpty(model.ProductName) && product.ProductName == model.ProductName) || (model.Id.HasValue && product.Id == model.Id)) - { - return product.GetViewModel; - } - } - return null; - } - public ProductViewModel? Insert(ProductBindingModel model) - { - model.Id = 1; - foreach (var product in _source.Products) - { - if (model.Id <= product.Id) - { - model.Id = product.Id + 1; - } - } - var newProduct = Product.Create(model); - if (newProduct == null) - { - return null; - } - _source.Products.Add(newProduct); - return newProduct.GetViewModel; - } - public ProductViewModel? Update(ProductBindingModel model) - { - foreach (var product in _source.Products) - { - if (product.Id == model.Id) - { - product.Update(model); - return product.GetViewModel; - } - } - return null; - } - public ProductViewModel? Delete(ProductBindingModel model) - { - for (int i = 0; i < _source.Products.Count; ++i) - { - if (_source.Products[i].Id == model.Id) - { - var element = _source.Products[i]; - _source.Products.RemoveAt(i); - return element.GetViewModel; - } - } - return null; - } - } -} diff --git a/Pizzeria/PizzeriaListImplement/Models/Order.cs b/Pizzeria/PizzeriaListImplement/Models/Order.cs index 93de7f0..e0eb9c1 100644 --- a/Pizzeria/PizzeriaListImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaListImplement/Models/Order.cs @@ -16,7 +16,7 @@ namespace PizzeriaListImplement.Models { public int Id { get; private set; } - public int ProductId { get; private set; } + public int PizzaId { get; private set; } public int Count { get; private set; } @@ -37,7 +37,7 @@ namespace PizzeriaListImplement.Models return new Order() { Id = model.Id, - ProductId = model.ProductId, + PizzaId = model.PizzaId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -58,7 +58,7 @@ namespace PizzeriaListImplement.Models public OrderViewModel GetViewModel => new() { Id = Id, - ProductId = ProductId, + PizzaId = PizzaId, Count = Count, Sum = Sum, Status = Status, diff --git a/Pizzeria/PizzeriaListImplement/Models/Product.cs b/Pizzeria/PizzeriaListImplement/Models/Product.cs deleted file mode 100644 index b17aeb7..0000000 --- a/Pizzeria/PizzeriaListImplement/Models/Product.cs +++ /dev/null @@ -1,49 +0,0 @@ -using PizzeriaContracts.BindingModels; -using PizzeriaContracts.ViewModels; -using PizzeriaDataModels.Models; - -namespace PizzeriaListImplement.Models -{ - public class Product : IProductModel - { - public int Id { get; private set; } - public string ProductName { get; private set; } = string.Empty; - public double Price { get; private set; } - public Dictionary ProductComponents - { - get; - private set; - } = new Dictionary(); - public static Product? Create(ProductBindingModel? model) - { - if (model == null) - { - return null; - } - return new Product() - { - Id = model.Id, - ProductName = model.ProductName, - Price = model.Price, - ProductComponents = model.ProductComponents - }; - } - public void Update(ProductBindingModel? model) - { - if (model == null) - { - return; - } - ProductName = model.ProductName; - Price = model.Price; - ProductComponents = model.ProductComponents; - } - public ProductViewModel GetViewModel => new() - { - Id = Id, - ProductName = ProductName, - Price = Price, - ProductComponents = ProductComponents - }; - } -} -- 2.25.1 From 693f0ab646376bef8f891d4cebd5fd237f4862b7 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Mon, 11 Mar 2024 00:29:35 +0400 Subject: [PATCH 06/21] end lab1 --- Pizzeria/Pizzeria/FormCreateOrder.Designer.cs | 145 +++++++++++ Pizzeria/Pizzeria/FormCreateOrder.cs | 124 +++++++++ Pizzeria/Pizzeria/FormCreateOrder.resx | 120 +++++++++ Pizzeria/Pizzeria/FormMain.Designer.cs | 188 ++++++++++++++ Pizzeria/Pizzeria/FormMain.cs | 138 ++++++++++ Pizzeria/Pizzeria/FormMain.resx | 123 +++++++++ Pizzeria/Pizzeria/FormPizza.Designer.cs | 240 ++++++++++++++++++ Pizzeria/Pizzeria/FormPizza.cs | 204 +++++++++++++++ Pizzeria/Pizzeria/FormPizza.resx | 129 ++++++++++ Pizzeria/Pizzeria/FormPizzas.Designer.cs | 128 ++++++++++ Pizzeria/Pizzeria/FormPizzas.cs | 107 ++++++++ Pizzeria/Pizzeria/FormPizzas.resx | 120 +++++++++ .../Pizzeria/FormProductComponent.Designer.cs | 121 +++++++++ Pizzeria/Pizzeria/FormProductComponent.cs | 83 ++++++ Pizzeria/Pizzeria/FormProductComponent.resx | 120 +++++++++ .../BusinessLogic/PizzaLogic.cs | 106 ++++++++ .../BindingModels/PizzaBindingModel.cs | 12 + .../BusinessLogicsContracts/IPizzaLogic.cs | 15 ++ .../SearchModels/PizzaSearchModel.cs | 8 + .../StorageContracts/IPizzaStorage.cs | 17 ++ .../ViewModels/PizzaViewModel.cs | 18 ++ .../PizzeriaDataModels/Models/IPizzaModel.cs | 9 + .../Implements/PizzaStorage.cs | 100 ++++++++ .../PizzeriaListImplement/Models/Pizza.cs | 49 ++++ 24 files changed, 2424 insertions(+) create mode 100644 Pizzeria/Pizzeria/FormCreateOrder.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormCreateOrder.cs create mode 100644 Pizzeria/Pizzeria/FormCreateOrder.resx create mode 100644 Pizzeria/Pizzeria/FormMain.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormMain.cs create mode 100644 Pizzeria/Pizzeria/FormMain.resx create mode 100644 Pizzeria/Pizzeria/FormPizza.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormPizza.cs create mode 100644 Pizzeria/Pizzeria/FormPizza.resx create mode 100644 Pizzeria/Pizzeria/FormPizzas.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormPizzas.cs create mode 100644 Pizzeria/Pizzeria/FormPizzas.resx create mode 100644 Pizzeria/Pizzeria/FormProductComponent.Designer.cs create mode 100644 Pizzeria/Pizzeria/FormProductComponent.cs create mode 100644 Pizzeria/Pizzeria/FormProductComponent.resx create mode 100644 Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs create mode 100644 Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs create mode 100644 Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IPizzaLogic.cs create mode 100644 Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs create mode 100644 Pizzeria/PizzeriaContracts/StorageContracts/IPizzaStorage.cs create mode 100644 Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs create mode 100644 Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs create mode 100644 Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs create mode 100644 Pizzeria/PizzeriaListImplement/Models/Pizza.cs diff --git a/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs b/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..aaf6db8 --- /dev/null +++ b/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs @@ -0,0 +1,145 @@ +namespace Pizzeria +{ + partial class FormCreateOrder + { + /// + /// 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() + { + textBoxCount = new TextBox(); + labelCount = new Label(); + labelPizza = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + labelSum = new Label(); + textBoxSum = new TextBox(); + comboBoxPizza = new ComboBox(); + SuspendLayout(); + // + // textBoxCount + // + textBoxCount.Location = new Point(99, 41); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(233, 23); + textBoxCount.TabIndex = 13; + textBoxCount.TextChanged += textBoxCount_TextChanged; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(11, 44); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 12; + labelCount.Text = "Количество:"; + // + // labelPizza + // + labelPizza.AutoSize = true; + labelPizza.Location = new Point(11, 15); + labelPizza.Name = "labelPizza"; + labelPizza.Size = new Size(43, 15); + labelPizza.TabIndex = 11; + labelPizza.Text = "Пицца"; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(257, 109); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 15; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSave.Location = new Point(176, 109); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 16; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(11, 73); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(48, 15); + labelSum.TabIndex = 12; + labelSum.Text = "Сумма:"; + // + // textBoxSum + // + textBoxSum.Location = new Point(99, 70); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(233, 23); + textBoxSum.TabIndex = 13; + // + // comboBoxPizza + // + comboBoxPizza.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxPizza.FormattingEnabled = true; + comboBoxPizza.Location = new Point(99, 12); + comboBoxPizza.Name = "comboBoxPizza"; + comboBoxPizza.Size = new Size(233, 23); + comboBoxPizza.TabIndex = 17; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(351, 150); + Controls.Add(comboBoxPizza); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(labelSum); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(labelPizza); + Name = "FormCreateOrder"; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private TextBox textBoxCount; + private Label labelCount; + private Label labelPizza; + private Button buttonCancel; + private Button buttonSave; + private Label labelSum; + private TextBox textBoxSum; + private ComboBox comboBoxPizza; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormCreateOrder.cs b/Pizzeria/Pizzeria/FormCreateOrder.cs new file mode 100644 index 0000000..128684e --- /dev/null +++ b/Pizzeria/Pizzeria/FormCreateOrder.cs @@ -0,0 +1,124 @@ + +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; +using System.Windows.Forms; + +namespace Pizzeria +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IPizzaLogic _logicP; + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, IPizzaLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка пицц для заказа"); + try + { + var _list = _logicP.ReadList(null); + if (_list != null) + { + comboBoxPizza.DisplayMember = "PizzaName"; + comboBoxPizza.ValueMember = "Id"; + comboBoxPizza.DataSource = _list; + comboBoxPizza.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при загрузке пиццы для заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CalcSum() + { + if (comboBoxPizza.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxPizza.SelectedValue); + var Pizza = _logicP.ReadElement(new PizzaSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Pizza?.Price ?? 0),2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + 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(); + } + + private void textBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void comboBoxPizza_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPizza.SelectedValue == null) + { + MessageBox.Show("Выберите пицца", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.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); + } + + } + } +} diff --git a/Pizzeria/Pizzeria/FormCreateOrder.resx b/Pizzeria/Pizzeria/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Pizzeria/Pizzeria/FormCreateOrder.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/Pizzeria/FormMain.Designer.cs b/Pizzeria/Pizzeria/FormMain.Designer.cs new file mode 100644 index 0000000..51ab41d --- /dev/null +++ b/Pizzeria/Pizzeria/FormMain.Designer.cs @@ -0,0 +1,188 @@ +namespace Pizzeria +{ + partial class FormMain + { + /// + /// 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() + { + menuStrip = new MenuStrip(); + справочкиниToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + изделияToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + ButtonIssuedOrder = new Button(); + ButtonOrderReady = new Button(); + ButtonnTakeOrderInWork = new Button(); + ButtonCreateOrder = new Button(); + buttonRef_Click = new Button(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.Items.AddRange(new ToolStripItem[] { справочкиниToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(999, 24); + menuStrip.TabIndex = 0; + menuStrip.Text = "Справочники:"; + // + // справочкиниToolStripMenuItem + // + справочкиниToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem }); + справочкиниToolStripMenuItem.Name = "справочкиниToolStripMenuItem"; + справочкиниToolStripMenuItem.Size = new Size(97, 20); + справочкиниToolStripMenuItem.Text = "Справочники:"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(148, 22); + компонентыToolStripMenuItem.Text = "Ингредиенты"; + компонентыToolStripMenuItem.Click += ИнгредиентыToolStripMenuItem_Click; + // + // изделияToolStripMenuItem + // + изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + изделияToolStripMenuItem.Size = new Size(148, 22); + изделияToolStripMenuItem.Text = "Пиццы"; + изделияToolStripMenuItem.Click += ПиццыToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 27); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(773, 362); + dataGridView.TabIndex = 0; + // + // ButtonIssuedOrder + // + ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonIssuedOrder.Location = new Point(799, 185); + ButtonIssuedOrder.Margin = new Padding(3, 2, 3, 2); + ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + ButtonIssuedOrder.Size = new Size(179, 32); + ButtonIssuedOrder.TabIndex = 8; + ButtonIssuedOrder.Text = "Заказ выдан"; + ButtonIssuedOrder.UseVisualStyleBackColor = true; + ButtonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // ButtonOrderReady + // + ButtonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonOrderReady.Location = new Point(799, 139); + ButtonOrderReady.Margin = new Padding(3, 2, 3, 2); + ButtonOrderReady.Name = "ButtonOrderReady"; + ButtonOrderReady.Size = new Size(179, 32); + ButtonOrderReady.TabIndex = 7; + ButtonOrderReady.Text = "Заказ готов"; + ButtonOrderReady.UseVisualStyleBackColor = true; + ButtonOrderReady.Click += ButtonOrderReady_Click; + // + // ButtonnTakeOrderInWork + // + ButtonnTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonnTakeOrderInWork.Location = new Point(799, 93); + ButtonnTakeOrderInWork.Margin = new Padding(3, 2, 3, 2); + ButtonnTakeOrderInWork.Name = "ButtonnTakeOrderInWork"; + ButtonnTakeOrderInWork.Size = new Size(179, 32); + ButtonnTakeOrderInWork.TabIndex = 6; + ButtonnTakeOrderInWork.Text = "Отдать на выполнение"; + ButtonnTakeOrderInWork.UseVisualStyleBackColor = true; + ButtonnTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // ButtonCreateOrder + // + ButtonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonCreateOrder.Location = new Point(799, 47); + ButtonCreateOrder.Margin = new Padding(3, 2, 3, 2); + ButtonCreateOrder.Name = "ButtonCreateOrder"; + ButtonCreateOrder.Size = new Size(179, 32); + ButtonCreateOrder.TabIndex = 5; + ButtonCreateOrder.Text = "Создать заказ"; + ButtonCreateOrder.UseVisualStyleBackColor = true; + ButtonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonRef_Click + // + buttonRef_Click.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRef_Click.Location = new Point(799, 231); + buttonRef_Click.Margin = new Padding(3, 2, 3, 2); + buttonRef_Click.Name = "buttonRef_Click"; + buttonRef_Click.Size = new Size(179, 32); + buttonRef_Click.TabIndex = 8; + buttonRef_Click.Text = "Обновить список"; + buttonRef_Click.UseVisualStyleBackColor = true; + buttonRef_Click.Click += ButtonRef_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(999, 390); + Controls.Add(buttonRef_Click); + Controls.Add(ButtonIssuedOrder); + Controls.Add(ButtonOrderReady); + Controls.Add(ButtonnTakeOrderInWork); + Controls.Add(ButtonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + Text = "Пиццерия"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочкиниToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private DataGridView dataGridView; + private Button ButtonIssuedOrder; + private Button ButtonOrderReady; + private Button ButtonnTakeOrderInWork; + private Button ButtonCreateOrder; + private Button buttonRef_Click; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormMain.cs b/Pizzeria/Pizzeria/FormMain.cs new file mode 100644 index 0000000..fc01400 --- /dev/null +++ b/Pizzeria/Pizzeria/FormMain.cs @@ -0,0 +1,138 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +namespace Pizzeria +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["PizzaId"].Visible = false; + dataGridView.Columns["PizzaName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ИнгредиентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void ПиццыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPizzas)); + if (service is FormPizzas form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel{ Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + 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/Pizzeria/FormMain.resx b/Pizzeria/Pizzeria/FormMain.resx new file mode 100644 index 0000000..6c82d08 --- /dev/null +++ b/Pizzeria/Pizzeria/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormPizza.Designer.cs b/Pizzeria/Pizzeria/FormPizza.Designer.cs new file mode 100644 index 0000000..6453d21 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizza.Designer.cs @@ -0,0 +1,240 @@ +namespace Pizzeria +{ + partial class FormPizza + { + /// + /// 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() + { + textBoxPrice = new TextBox(); + textBoxName = new TextBox(); + labelPrice = new Label(); + labelName = new Label(); + ButtonUpd = new Button(); + ButtonDel = new Button(); + ButtonRef = new Button(); + ButtonAdd = new Button(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnComponent = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonCancel = new Button(); + buttonSave = new Button(); + groupBoxComponents = new GroupBox(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + groupBoxComponents.SuspendLayout(); + SuspendLayout(); + // + // textBoxPrice + // + textBoxPrice.Enabled = false; + textBoxPrice.Location = new Point(99, 41); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(233, 23); + textBoxPrice.TabIndex = 5; + // + // textBoxName + // + textBoxName.Location = new Point(99, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(233, 23); + textBoxName.TabIndex = 6; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(11, 44); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(70, 15); + labelPrice.TabIndex = 4; + labelPrice.Text = "Стоимость:"; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(11, 15); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 3; + labelName.Text = "Название:"; + // + // ButtonUpd + // + ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonUpd.Location = new Point(467, 135); + ButtonUpd.Margin = new Padding(3, 2, 3, 2); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(82, 22); + ButtonUpd.TabIndex = 10; + ButtonUpd.Text = "Обновить"; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonDel + // + ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonDel.Location = new Point(467, 100); + ButtonDel.Margin = new Padding(3, 2, 3, 2); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(82, 22); + ButtonDel.TabIndex = 9; + ButtonDel.Text = "Удалить"; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonRef + // + ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonRef.Location = new Point(467, 62); + ButtonRef.Margin = new Padding(3, 2, 3, 2); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(82, 22); + ButtonRef.TabIndex = 8; + ButtonRef.Text = "Изменить"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; + // + // ButtonAdd + // + ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonAdd.Location = new Point(467, 27); + ButtonAdd.Margin = new Padding(3, 2, 3, 2); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(82, 22); + ButtonAdd.TabIndex = 7; + ButtonAdd.Text = "Добавить"; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnComponent, ColumnCount }); + dataGridView.Location = new Point(6, 22); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowTemplate.Height = 25; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(429, 262); + dataGridView.TabIndex = 11; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + // + // ColumnComponent + // + ColumnComponent.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnComponent.HeaderText = "Ингредиент"; + ColumnComponent.Name = "ColumnComponent"; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(486, 386); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 12; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSave.Location = new Point(405, 386); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 13; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // groupBoxComponents + // + groupBoxComponents.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBoxComponents.Controls.Add(ButtonUpd); + groupBoxComponents.Controls.Add(ButtonDel); + groupBoxComponents.Controls.Add(ButtonRef); + groupBoxComponents.Controls.Add(dataGridView); + groupBoxComponents.Controls.Add(ButtonAdd); + groupBoxComponents.Location = new Point(12, 81); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Size = new Size(579, 287); + groupBoxComponents.TabIndex = 14; + groupBoxComponents.TabStop = false; + groupBoxComponents.Text = "Ингредиенты"; + // + // FormPizza + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(612, 430); + Controls.Add(groupBoxComponents); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormPizza"; + Text = "Пицца"; + Load += FormPizza_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + groupBoxComponents.ResumeLayout(false); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxPrice; + private TextBox textBoxName; + private Label labelPrice; + private Label labelName; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonRef; + private Button ButtonAdd; + private DataGridView dataGridView; + private Button buttonCancel; + private Button buttonSave; + private GroupBox groupBoxComponents; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnComponent; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormPizza.cs b/Pizzeria/Pizzeria/FormPizza.cs new file mode 100644 index 0000000..8ea52ab --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizza.cs @@ -0,0 +1,204 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaDataModels.Models; + +namespace Pizzeria +{ + public partial class FormPizza : Form + { + private readonly ILogger _logger; + private readonly IPizzaLogic _logic; + private int? _id; + private Dictionary _PizzaComponents; + public int Id { set { _id = value; } } + + public FormPizza(ILogger logger, IPizzaLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _PizzaComponents = new Dictionary(); + } + private void FormPizza_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка пиццы"); + try + { + var view = _logic.ReadElement(new PizzaSearchModel + { + Id =_id.Value + }); + if (view != null) + { + textBoxName.Text = view.PizzaName; + textBoxPrice.Text = view.Price.ToString(); + _PizzaComponents = view.PizzaComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки пиццы"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _PizzaComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка ингредиент пиццы"); + try + { + if (_PizzaComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _PizzaComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + 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(FormPizzaComponent)); + if (service is FormPizzaComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового ингредиента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_PizzaComponents.ContainsKey(form.Id)) + { + _PizzaComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _PizzaComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление ингредиента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); _PizzaComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPizzaComponent)); + if (service is FormPizzaComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _PizzaComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение ингредиента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); _PizzaComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_PizzaComponents == null || _PizzaComponents.Count == 0) + { + MessageBox.Show("Заполните ингредиенты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение пиццы"); + try + { + var model = new PizzaBindingModel + { + Id = _id ?? 0, + PizzaName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + PizzaComponents = _PizzaComponents + }; + 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); + } + + } + + } +} diff --git a/Pizzeria/Pizzeria/FormPizza.resx b/Pizzeria/Pizzeria/FormPizza.resx new file mode 100644 index 0000000..524a4e1 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizza.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormPizzas.Designer.cs b/Pizzeria/Pizzeria/FormPizzas.Designer.cs new file mode 100644 index 0000000..09e90e7 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzas.Designer.cs @@ -0,0 +1,128 @@ +namespace Pizzeria +{ + partial class FormPizzas + { + /// + /// 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() + { + ButtonUpd = new Button(); + ButtonDel = new Button(); + ButtonRef = new Button(); + ButtonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // ButtonUpd + // + ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonUpd.Location = new Point(584, 138); + ButtonUpd.Margin = new Padding(3, 2, 3, 2); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(82, 22); + ButtonUpd.TabIndex = 9; + ButtonUpd.Text = "Обновить"; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonRef_Click; + // + // ButtonDel + // + ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonDel.Location = new Point(584, 103); + ButtonDel.Margin = new Padding(3, 2, 3, 2); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(82, 22); + ButtonDel.TabIndex = 8; + ButtonDel.Text = "Удалить"; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; + // + // ButtonRef + // + ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonRef.Location = new Point(584, 65); + ButtonRef.Margin = new Padding(3, 2, 3, 2); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(82, 22); + ButtonRef.TabIndex = 7; + ButtonRef.Text = "Изменить"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonUpd_Click; + // + // ButtonAdd + // + ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + ButtonAdd.Location = new Point(584, 30); + ButtonAdd.Margin = new Padding(3, 2, 3, 2); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(82, 22); + ButtonAdd.TabIndex = 6; + ButtonAdd.Text = "Добавить"; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(550, 264); + dataGridView.TabIndex = 5; + // + // FormPizzas + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(702, 264); + Controls.Add(ButtonUpd); + Controls.Add(ButtonDel); + Controls.Add(ButtonRef); + Controls.Add(ButtonAdd); + Controls.Add(dataGridView); + Name = "FormPizzas"; + Text = "Пиццы"; + Load += FormPizzas_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonRef; + private Button ButtonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormPizzas.cs b/Pizzeria/Pizzeria/FormPizzas.cs new file mode 100644 index 0000000..cd5580e --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzas.cs @@ -0,0 +1,107 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; + +namespace Pizzeria +{ + public partial class FormPizzas : Form + { + private readonly ILogger _logger; + private readonly IPizzaLogic _logic; + public FormPizzas(ILogger logger, IPizzaLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormPizzas_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["PizzaName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["PizzaComponents"].Visible = false; + } + _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(FormPizza)); + if (service is FormPizza form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + + } + private void ButtonRef_Click(object sender, EventArgs e) + { + 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 PizzaBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления ингредиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPizza)); + if (service is FormPizza form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + + } +} diff --git a/Pizzeria/Pizzeria/FormPizzas.resx b/Pizzeria/Pizzeria/FormPizzas.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Pizzeria/Pizzeria/FormPizzas.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/Pizzeria/FormProductComponent.Designer.cs b/Pizzeria/Pizzeria/FormProductComponent.Designer.cs new file mode 100644 index 0000000..ba3570d --- /dev/null +++ b/Pizzeria/Pizzeria/FormProductComponent.Designer.cs @@ -0,0 +1,121 @@ +namespace Pizzeria +{ + partial class FormPizzaComponent + { + /// + /// 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() + { + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxCount = new TextBox(); + labelCount = new Label(); + labelComponent = new Label(); + comboBoxComponent = new ComboBox(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(259, 87); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSave.Location = new Point(178, 87); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 9; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // textBoxCount + // + textBoxCount.Location = new Point(101, 41); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(233, 23); + textBoxCount.TabIndex = 6; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(13, 44); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 5; + labelCount.Text = "Количество:"; + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(13, 15); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(75, 15); + labelComponent.TabIndex = 4; + labelComponent.Text = "Ингредиент:"; + // + // comboBoxComponent + // + comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(101, 12); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(233, 23); + comboBoxComponent.TabIndex = 10; + // + // FormPizzaComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(355, 125); + Controls.Add(comboBoxComponent); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormPizzaComponent"; + Text = "Ингредиент пиццы"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private Label labelCount; + private Label labelComponent; + private ComboBox comboBoxComponent; + } +} \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormProductComponent.cs b/Pizzeria/Pizzeria/FormProductComponent.cs new file mode 100644 index 0000000..92565f4 --- /dev/null +++ b/Pizzeria/Pizzeria/FormProductComponent.cs @@ -0,0 +1,83 @@ +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; + +namespace Pizzeria +{ + public partial class FormPizzaComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + public FormPizzaComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите ингредиент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + + } + } +} diff --git a/Pizzeria/Pizzeria/FormProductComponent.resx b/Pizzeria/Pizzeria/FormProductComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Pizzeria/Pizzeria/FormProductComponent.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/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs new file mode 100644 index 0000000..39cd57f --- /dev/null +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.Logging; +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.BusinessLogicsContracts; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; + + +namespace PizzeriaBusinessLogic.BusinessLogic +{ + public class PizzaLogic : IPizzaLogic + { + private readonly ILogger _logger; + private readonly IPizzaStorage _PizzaStorage; + public PizzaLogic(ILogger logger, IPizzaStorage PizzaStorage) + { + _logger = logger; + _PizzaStorage = PizzaStorage; + } + public List? ReadList(PizzaSearchModel? model) + { + _logger.LogInformation("ReadList. PizzaName:{PizzaName}.Id:{ Id}", model?.PizzaName, model?.Id); + var list = model == null ? _PizzaStorage.GetFullList() : + _PizzaStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public PizzaViewModel? ReadElement(PizzaSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. PizzaName:{PizzaName}.Id:{ Id} ", model.PizzaName, model.Id); + var element = _PizzaStorage.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(PizzaBindingModel model) + { + CheckModel(model); + if (_PizzaStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(PizzaBindingModel model) + { + CheckModel(model); + if (_PizzaStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(PizzaBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_PizzaStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(PizzaBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PizzaName)) + { + throw new ArgumentNullException("Нет названия продукта", nameof(model.PizzaName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Pizza. PizzaName:{PizzaName}.Price:{ Price}. Id: { Id}", model.PizzaName, model.Price, model.Id); + var element = _PizzaStorage.GetElement(new PizzaSearchModel { PizzaName = model.PizzaName }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Продукт с таким названием уже есть"); + } + } + } +} diff --git a/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs new file mode 100644 index 0000000..9905269 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BindingModels/PizzaBindingModel.cs @@ -0,0 +1,12 @@ +using PizzeriaDataModels.Models; +namespace PizzeriaContracts.BindingModels +{ + public class PizzaBindingModel : IPizzaModel + { + public int Id { get; set; } + public string PizzaName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary PizzaComponents {get;set;} = new(); + + } +} diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IPizzaLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IPizzaLogic.cs new file mode 100644 index 0000000..5ab632a --- /dev/null +++ b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IPizzaLogic.cs @@ -0,0 +1,15 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.BusinessLogicsContracts +{ + public interface IPizzaLogic + { + List? ReadList(PizzaSearchModel? model); + PizzaViewModel? ReadElement(PizzaSearchModel model); + bool Create(PizzaBindingModel model); + bool Update(PizzaBindingModel model); + bool Delete(PizzaBindingModel model); + } +} diff --git a/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs new file mode 100644 index 0000000..86ebea7 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/SearchModels/PizzaSearchModel.cs @@ -0,0 +1,8 @@ +namespace PizzeriaContracts.SearchModels +{ + public class PizzaSearchModel + { + public int? Id { get; set; } + public string? PizzaName { get; set; } + } +} diff --git a/Pizzeria/PizzeriaContracts/StorageContracts/IPizzaStorage.cs b/Pizzeria/PizzeriaContracts/StorageContracts/IPizzaStorage.cs new file mode 100644 index 0000000..4ec1629 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/StorageContracts/IPizzaStorage.cs @@ -0,0 +1,17 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.ViewModels; + +namespace PizzeriaContracts.StorageContracts +{ + public interface IPizzaStorage + { + List GetFullList(); + List GetFilteredList(PizzaSearchModel model); + PizzaViewModel? GetElement(PizzaSearchModel model); + PizzaViewModel? Insert(PizzaBindingModel model); + PizzaViewModel? Update(PizzaBindingModel model); + PizzaViewModel? Delete(PizzaBindingModel model); + + } +} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs new file mode 100644 index 0000000..4b85d07 --- /dev/null +++ b/Pizzeria/PizzeriaContracts/ViewModels/PizzaViewModel.cs @@ -0,0 +1,18 @@ +using PizzeriaDataModels.Models; +using System.ComponentModel; + +namespace PizzeriaContracts.ViewModels +{ + public class PizzaViewModel : IPizzaModel + { + public int Id { get; set; } + + [DisplayName("Название пиццы")] + public string PizzaName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + + public Dictionary PizzaComponents {get;set;} = new(); + } +} diff --git a/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs b/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs new file mode 100644 index 0000000..a490537 --- /dev/null +++ b/Pizzeria/PizzeriaDataModels/Models/IPizzaModel.cs @@ -0,0 +1,9 @@ +namespace PizzeriaDataModels.Models +{ + public interface IPizzaModel : IId + { + string PizzaName { get; } + double Price { get; } + Dictionary PizzaComponents { get; } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs new file mode 100644 index 0000000..271b0f7 --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Implements/PizzaStorage.cs @@ -0,0 +1,100 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.SearchModels; +using PizzeriaContracts.StorageContracts; +using PizzeriaContracts.ViewModels; +using PizzeriaListImplement.Models; + +namespace PizzeriaListImplement.Implements +{ + public class PizzaStorage : IPizzaStorage + { + private readonly DataListSingleton _source; + public PizzaStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var Pizza in _source.Pizzas) + { + result.Add(Pizza.GetViewModel); + } + return result; + } + public List GetFilteredList(PizzaSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.PizzaName)) + { + return result; + } + foreach (var Pizza in _source.Pizzas) + { + if (Pizza.PizzaName.Contains(model.PizzaName)) + { + result.Add(Pizza.GetViewModel); + } + } + return result; + } + public PizzaViewModel? GetElement(PizzaSearchModel model) + { + if (string.IsNullOrEmpty(model.PizzaName) && !model.Id.HasValue) + { + return null; + } + foreach (var Pizza in _source.Pizzas) + { + if ((!string.IsNullOrEmpty(model.PizzaName) && Pizza.PizzaName == model.PizzaName) || (model.Id.HasValue && Pizza.Id == model.Id)) + { + return Pizza.GetViewModel; + } + } + return null; + } + public PizzaViewModel? Insert(PizzaBindingModel model) + { + model.Id = 1; + foreach (var Pizza in _source.Pizzas) + { + if (model.Id <= Pizza.Id) + { + model.Id = Pizza.Id + 1; + } + } + var newPizza = Pizza.Create(model); + if (newPizza == null) + { + return null; + } + _source.Pizzas.Add(newPizza); + return newPizza.GetViewModel; + } + public PizzaViewModel? Update(PizzaBindingModel model) + { + foreach (var Pizza in _source.Pizzas) + { + if (Pizza.Id == model.Id) + { + Pizza.Update(model); + return Pizza.GetViewModel; + } + } + return null; + } + public PizzaViewModel? Delete(PizzaBindingModel model) + { + for (int i = 0; i < _source.Pizzas.Count; ++i) + { + if (_source.Pizzas[i].Id == model.Id) + { + var element = _source.Pizzas[i]; + _source.Pizzas.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/Pizzeria/PizzeriaListImplement/Models/Pizza.cs b/Pizzeria/PizzeriaListImplement/Models/Pizza.cs new file mode 100644 index 0000000..fbc61ee --- /dev/null +++ b/Pizzeria/PizzeriaListImplement/Models/Pizza.cs @@ -0,0 +1,49 @@ +using PizzeriaContracts.BindingModels; +using PizzeriaContracts.ViewModels; +using PizzeriaDataModels.Models; + +namespace PizzeriaListImplement.Models +{ + public class Pizza : IPizzaModel + { + public int Id { get; private set; } + public string PizzaName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary PizzaComponents + { + get; + private set; + } = new Dictionary(); + public static Pizza? Create(PizzaBindingModel? model) + { + if (model == null) + { + return null; + } + return new Pizza() + { + Id = model.Id, + PizzaName = model.PizzaName, + Price = model.Price, + PizzaComponents = model.PizzaComponents + }; + } + public void Update(PizzaBindingModel? model) + { + if (model == null) + { + return; + } + PizzaName = model.PizzaName; + Price = model.Price; + PizzaComponents = model.PizzaComponents; + } + public PizzaViewModel GetViewModel => new() + { + Id = Id, + PizzaName = PizzaName, + Price = Price, + PizzaComponents = PizzaComponents + }; + } +} -- 2.25.1 From be33d7b34b20d4d95fa8e7816b5acc1add4dc5a8 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Tue, 12 Mar 2024 19:51:37 +0400 Subject: [PATCH 07/21] =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs index 39cd57f..d6adc21 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs @@ -20,8 +20,7 @@ namespace PizzeriaBusinessLogic.BusinessLogic public List? ReadList(PizzaSearchModel? model) { _logger.LogInformation("ReadList. PizzaName:{PizzaName}.Id:{ Id}", model?.PizzaName, model?.Id); - var list = model == null ? _PizzaStorage.GetFullList() : - _PizzaStorage.GetFilteredList(model); + var list = model == null ? _PizzaStorage.GetFullList() : _PizzaStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); -- 2.25.1 From c9383db62933345720c60ac845b2026ff27f7746 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Tue, 12 Mar 2024 20:03:49 +0400 Subject: [PATCH 08/21] ss --- Pizzeria/Pizzeria/FormComponents.Designer.cs | 1 + Pizzeria/Pizzeria/FormPizzas.Designer.cs | 1 + Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Pizzeria/Pizzeria/FormComponents.Designer.cs b/Pizzeria/Pizzeria/FormComponents.Designer.cs index 73f5145..f9373b1 100644 --- a/Pizzeria/Pizzeria/FormComponents.Designer.cs +++ b/Pizzeria/Pizzeria/FormComponents.Designer.cs @@ -38,6 +38,7 @@ // // dataGridView // + dataGridView.BackgroundColor = SystemColors.ControlLightLight; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Dock = DockStyle.Left; dataGridView.Location = new Point(0, 0); diff --git a/Pizzeria/Pizzeria/FormPizzas.Designer.cs b/Pizzeria/Pizzeria/FormPizzas.Designer.cs index 09e90e7..478d7c9 100644 --- a/Pizzeria/Pizzeria/FormPizzas.Designer.cs +++ b/Pizzeria/Pizzeria/FormPizzas.Designer.cs @@ -86,6 +86,7 @@ // // dataGridView // + dataGridView.BackgroundColor = SystemColors.ControlLightLight; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Dock = DockStyle.Left; dataGridView.Location = new Point(0, 0); diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs index 6465b13..6e59690 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs @@ -70,8 +70,9 @@ namespace PizzeriaBusinessLogic.BusinessLogic public bool ChangeStatus(OrderBindingModel model, OrderStatus status) { CheckModel(model, false); - - var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + + var searchOrder = new OrderSearchModel { Id = model.Id }; + var order = _orderStorage.GetElement(searchOrder); if (order == null) { -- 2.25.1 From acab1402347ba87d52d1f0f830ef5e4450413f98 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Tue, 12 Mar 2024 21:42:28 +0400 Subject: [PATCH 09/21] end lab1 --- ...ductComponent.Designer.cs => FormPizzaComponent.Designer.cs} | 0 .../Pizzeria/{FormProductComponent.cs => FormPizzaComponent.cs} | 0 .../{FormProductComponent.resx => FormPizzaComponent.resx} | 0 Pizzeria/Pizzeria/Program.cs | 2 -- 4 files changed, 2 deletions(-) rename Pizzeria/Pizzeria/{FormProductComponent.Designer.cs => FormPizzaComponent.Designer.cs} (100%) rename Pizzeria/Pizzeria/{FormProductComponent.cs => FormPizzaComponent.cs} (100%) rename Pizzeria/Pizzeria/{FormProductComponent.resx => FormPizzaComponent.resx} (100%) diff --git a/Pizzeria/Pizzeria/FormProductComponent.Designer.cs b/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs similarity index 100% rename from Pizzeria/Pizzeria/FormProductComponent.Designer.cs rename to Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs diff --git a/Pizzeria/Pizzeria/FormProductComponent.cs b/Pizzeria/Pizzeria/FormPizzaComponent.cs similarity index 100% rename from Pizzeria/Pizzeria/FormProductComponent.cs rename to Pizzeria/Pizzeria/FormPizzaComponent.cs diff --git a/Pizzeria/Pizzeria/FormProductComponent.resx b/Pizzeria/Pizzeria/FormPizzaComponent.resx similarity index 100% rename from Pizzeria/Pizzeria/FormProductComponent.resx rename to Pizzeria/Pizzeria/FormPizzaComponent.resx diff --git a/Pizzeria/Pizzeria/Program.cs b/Pizzeria/Pizzeria/Program.cs index 32150d8..8ab0928 100644 --- a/Pizzeria/Pizzeria/Program.cs +++ b/Pizzeria/Pizzeria/Program.cs @@ -1,8 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using PizzeriaContracts.BusinessLogicsContracts; using PizzeriaContracts.StorageContracts; -using System.Drawing; -using System; using PizzeriaListImplement.Implements; using PizzeriaBusinessLogic.BusinessLogic; using Microsoft.Extensions.Logging; -- 2.25.1 From 8eb0bd1a2b5f91bad5f0ab081c190cbe3dd8c1bb Mon Sep 17 00:00:00 2001 From: revengel66 Date: Tue, 12 Mar 2024 21:53:26 +0400 Subject: [PATCH 10/21] 1 --- Pizzeria/PizzeriaListImplement/Models/Pizza.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Pizzeria/PizzeriaListImplement/Models/Pizza.cs b/Pizzeria/PizzeriaListImplement/Models/Pizza.cs index fbc61ee..510adc5 100644 --- a/Pizzeria/PizzeriaListImplement/Models/Pizza.cs +++ b/Pizzeria/PizzeriaListImplement/Models/Pizza.cs @@ -9,11 +9,7 @@ namespace PizzeriaListImplement.Models public int Id { get; private set; } public string PizzaName { get; private set; } = string.Empty; public double Price { get; private set; } - public Dictionary PizzaComponents - { - get; - private set; - } = new Dictionary(); + public Dictionary PizzaComponents { get; private set; } = new Dictionary(); public static Pizza? Create(PizzaBindingModel? model) { if (model == null) -- 2.25.1 From 286d3cccbf262c26d5cf883a39ff854d35bbc160 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Tue, 12 Mar 2024 22:05:43 +0400 Subject: [PATCH 11/21] 2 --- Pizzeria/PizzeriaListImplement/Models/Order.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Pizzeria/PizzeriaListImplement/Models/Order.cs b/Pizzeria/PizzeriaListImplement/Models/Order.cs index e0eb9c1..ec76f43 100644 --- a/Pizzeria/PizzeriaListImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaListImplement/Models/Order.cs @@ -2,13 +2,6 @@ using PizzeriaContracts.ViewModels; using PizzeriaDataModels.Enums; using PizzeriaDataModels.Models; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; namespace PizzeriaListImplement.Models { -- 2.25.1 From 658f5279de46bc614b5b15dc9a33226991f6c6b1 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Tue, 12 Mar 2024 23:48:02 +0400 Subject: [PATCH 12/21] 3 --- Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs index 6e59690..39a6fd4 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs @@ -92,7 +92,7 @@ namespace PizzeriaBusinessLogic.BusinessLogic } model.Status = status; - if (model.Status == OrderStatus.Выдан) + if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; } -- 2.25.1 From fd70baa849f90ad8ddc75efec92ccad1648e2efc Mon Sep 17 00:00:00 2001 From: revengel66 Date: Wed, 13 Mar 2024 10:52:15 +0300 Subject: [PATCH 13/21] 3 --- Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs index 39a6fd4..dc3adfe 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs @@ -130,8 +130,5 @@ namespace PizzeriaBusinessLogic.BusinessLogic } _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. PizzaId: {PizzaId}. ReinforcedCount: {Count}", model.Id, model.Sum, model.PizzaId, model.Count); } - - - } } -- 2.25.1 From b160dcaa36a979a74f0f9bcc2e507f92869740e0 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Wed, 13 Mar 2024 10:53:18 +0300 Subject: [PATCH 14/21] 5 --- Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs index 5f95a30..b5b4553 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -99,7 +99,7 @@ namespace PizzeriaBusinessLogic.BusinessLogic var element = _componentStorage.GetElement(new ComponentSearchModel{ ComponentName = model.ComponentName }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("ингредиент с таким названием уже есть"); + throw new InvalidOperationException("Ингредиент с таким названием уже есть"); } } } -- 2.25.1 From 96506f5cce4c853c059d441c108442bfe4943903 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Wed, 13 Mar 2024 10:55:17 +0300 Subject: [PATCH 15/21] 6 --- Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs index d6adc21..8e072cc 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/PizzaLogic.cs @@ -88,17 +88,17 @@ namespace PizzeriaBusinessLogic.BusinessLogic } if (string.IsNullOrEmpty(model.PizzaName)) { - throw new ArgumentNullException("Нет названия продукта", nameof(model.PizzaName)); + throw new ArgumentNullException("Нет названия пиццы", nameof(model.PizzaName)); } if (model.Price <= 0) { - throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); + throw new ArgumentNullException("Цена пиццы должна быть больше 0", nameof(model.Price)); } _logger.LogInformation("Pizza. PizzaName:{PizzaName}.Price:{ Price}. Id: { Id}", model.PizzaName, model.Price, model.Id); var element = _PizzaStorage.GetElement(new PizzaSearchModel { PizzaName = model.PizzaName }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Продукт с таким названием уже есть"); + throw new InvalidOperationException("Пицца с таким названием уже есть"); } } } -- 2.25.1 From e749b8c0ded4b3129ba2ded6b842c87ccb39d2ba Mon Sep 17 00:00:00 2001 From: revengel66 Date: Wed, 13 Mar 2024 10:57:18 +0300 Subject: [PATCH 16/21] 7 --- Pizzeria/Pizzeria/FormPizzas.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Pizzeria/Pizzeria/FormPizzas.cs b/Pizzeria/Pizzeria/FormPizzas.cs index cd5580e..abedea1 100644 --- a/Pizzeria/Pizzeria/FormPizzas.cs +++ b/Pizzeria/Pizzeria/FormPizzas.cs @@ -38,7 +38,6 @@ namespace Pizzeria MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ButtonAdd_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormPizza)); @@ -49,14 +48,11 @@ namespace Pizzeria LoadData(); } } - - } private void ButtonRef_Click(object sender, EventArgs e) { LoadData(); } - private void ButtonDel_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) @@ -83,9 +79,7 @@ namespace Pizzeria } } } - } - private void ButtonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) @@ -101,7 +95,5 @@ namespace Pizzeria } } } - - } } -- 2.25.1 From 03c2cbe8db67059f043bc0a043bc94577112d1f5 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Wed, 13 Mar 2024 10:58:49 +0300 Subject: [PATCH 17/21] 6 --- .../Pizzeria/FormPizzaComponent.Designer.cs | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs b/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs index ba3570d..a329de4 100644 --- a/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs +++ b/Pizzeria/Pizzeria/FormPizzaComponent.Designer.cs @@ -39,9 +39,10 @@ // buttonCancel // buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCancel.Location = new Point(259, 87); + buttonCancel.Location = new Point(296, 116); + buttonCancel.Margin = new Padding(3, 4, 3, 4); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(75, 23); + buttonCancel.Size = new Size(86, 31); buttonCancel.TabIndex = 8; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -50,9 +51,10 @@ // buttonSave // buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonSave.Location = new Point(178, 87); + buttonSave.Location = new Point(195, 116); + buttonSave.Margin = new Padding(3, 4, 3, 4); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(75, 23); + buttonSave.Size = new Size(94, 31); buttonSave.TabIndex = 9; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; @@ -60,26 +62,27 @@ // // textBoxCount // - textBoxCount.Location = new Point(101, 41); + textBoxCount.Location = new Point(115, 55); + textBoxCount.Margin = new Padding(3, 4, 3, 4); textBoxCount.Name = "textBoxCount"; - textBoxCount.Size = new Size(233, 23); + textBoxCount.Size = new Size(266, 27); textBoxCount.TabIndex = 6; // // labelCount // labelCount.AutoSize = true; - labelCount.Location = new Point(13, 44); + labelCount.Location = new Point(15, 59); labelCount.Name = "labelCount"; - labelCount.Size = new Size(75, 15); + labelCount.Size = new Size(93, 20); labelCount.TabIndex = 5; labelCount.Text = "Количество:"; // // labelComponent // labelComponent.AutoSize = true; - labelComponent.Location = new Point(13, 15); + labelComponent.Location = new Point(15, 20); labelComponent.Name = "labelComponent"; - labelComponent.Size = new Size(75, 15); + labelComponent.Size = new Size(95, 20); labelComponent.TabIndex = 4; labelComponent.Text = "Ингредиент:"; // @@ -87,22 +90,24 @@ // comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxComponent.FormattingEnabled = true; - comboBoxComponent.Location = new Point(101, 12); + comboBoxComponent.Location = new Point(115, 16); + comboBoxComponent.Margin = new Padding(3, 4, 3, 4); comboBoxComponent.Name = "comboBoxComponent"; - comboBoxComponent.Size = new Size(233, 23); + comboBoxComponent.Size = new Size(266, 28); comboBoxComponent.TabIndex = 10; // // FormPizzaComponent // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(355, 125); + ClientSize = new Size(406, 167); Controls.Add(comboBoxComponent); Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(textBoxCount); Controls.Add(labelCount); Controls.Add(labelComponent); + Margin = new Padding(3, 4, 3, 4); Name = "FormPizzaComponent"; Text = "Ингредиент пиццы"; ResumeLayout(false); -- 2.25.1 From 7033db0be5550ac51e6e8a67182c5d79ba4245c2 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Wed, 13 Mar 2024 11:01:17 +0300 Subject: [PATCH 18/21] 9 --- Pizzeria/Pizzeria/FormPizza.Designer.cs | 73 +++++++++++++++---------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/Pizzeria/Pizzeria/FormPizza.Designer.cs b/Pizzeria/Pizzeria/FormPizza.Designer.cs index 6453d21..9bdd3e3 100644 --- a/Pizzeria/Pizzeria/FormPizza.Designer.cs +++ b/Pizzeria/Pizzeria/FormPizza.Designer.cs @@ -50,43 +50,44 @@ // textBoxPrice // textBoxPrice.Enabled = false; - textBoxPrice.Location = new Point(99, 41); + textBoxPrice.Location = new Point(113, 55); + textBoxPrice.Margin = new Padding(3, 4, 3, 4); textBoxPrice.Name = "textBoxPrice"; - textBoxPrice.Size = new Size(233, 23); + textBoxPrice.Size = new Size(266, 27); textBoxPrice.TabIndex = 5; // // textBoxName // - textBoxName.Location = new Point(99, 12); + textBoxName.Location = new Point(113, 16); + textBoxName.Margin = new Padding(3, 4, 3, 4); textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(233, 23); + textBoxName.Size = new Size(266, 27); textBoxName.TabIndex = 6; // // labelPrice // labelPrice.AutoSize = true; - labelPrice.Location = new Point(11, 44); + labelPrice.Location = new Point(13, 59); labelPrice.Name = "labelPrice"; - labelPrice.Size = new Size(70, 15); + labelPrice.Size = new Size(86, 20); labelPrice.TabIndex = 4; labelPrice.Text = "Стоимость:"; // // labelName // labelName.AutoSize = true; - labelName.Location = new Point(11, 15); + labelName.Location = new Point(13, 20); labelName.Name = "labelName"; - labelName.Size = new Size(62, 15); + labelName.Size = new Size(80, 20); labelName.TabIndex = 3; labelName.Text = "Название:"; // // ButtonUpd // ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right; - ButtonUpd.Location = new Point(467, 135); - ButtonUpd.Margin = new Padding(3, 2, 3, 2); + ButtonUpd.Location = new Point(534, 180); ButtonUpd.Name = "ButtonUpd"; - ButtonUpd.Size = new Size(82, 22); + ButtonUpd.Size = new Size(94, 29); ButtonUpd.TabIndex = 10; ButtonUpd.Text = "Обновить"; ButtonUpd.UseVisualStyleBackColor = true; @@ -95,10 +96,9 @@ // ButtonDel // ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right; - ButtonDel.Location = new Point(467, 100); - ButtonDel.Margin = new Padding(3, 2, 3, 2); + ButtonDel.Location = new Point(534, 133); ButtonDel.Name = "ButtonDel"; - ButtonDel.Size = new Size(82, 22); + ButtonDel.Size = new Size(94, 29); ButtonDel.TabIndex = 9; ButtonDel.Text = "Удалить"; ButtonDel.UseVisualStyleBackColor = true; @@ -107,10 +107,9 @@ // ButtonRef // ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; - ButtonRef.Location = new Point(467, 62); - ButtonRef.Margin = new Padding(3, 2, 3, 2); + ButtonRef.Location = new Point(534, 83); ButtonRef.Name = "ButtonRef"; - ButtonRef.Size = new Size(82, 22); + ButtonRef.Size = new Size(94, 29); ButtonRef.TabIndex = 8; ButtonRef.Text = "Изменить"; ButtonRef.UseVisualStyleBackColor = true; @@ -119,10 +118,9 @@ // ButtonAdd // ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; - ButtonAdd.Location = new Point(467, 27); - ButtonAdd.Margin = new Padding(3, 2, 3, 2); + ButtonAdd.Location = new Point(534, 36); ButtonAdd.Name = "ButtonAdd"; - ButtonAdd.Size = new Size(82, 22); + ButtonAdd.Size = new Size(94, 29); ButtonAdd.TabIndex = 7; ButtonAdd.Text = "Добавить"; ButtonAdd.UseVisualStyleBackColor = true; @@ -135,38 +133,49 @@ dataGridView.BackgroundColor = SystemColors.ControlLightLight; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnComponent, ColumnCount }); - dataGridView.Location = new Point(6, 22); + dataGridView.Location = new Point(7, 29); + dataGridView.Margin = new Padding(3, 4, 3, 4); dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 25; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(429, 262); + dataGridView.Size = new Size(490, 349); dataGridView.TabIndex = 11; // // ColumnId // ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; ColumnId.Visible = false; + ColumnId.Width = 125; // // ColumnComponent // ColumnComponent.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; ColumnComponent.HeaderText = "Ингредиент"; + ColumnComponent.MinimumWidth = 6; ColumnComponent.Name = "ColumnComponent"; + ColumnComponent.ReadOnly = true; // // ColumnCount // ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 125; // // buttonCancel // buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCancel.Location = new Point(486, 386); + buttonCancel.Location = new Point(555, 515); + buttonCancel.Margin = new Padding(3, 4, 3, 4); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(75, 23); + buttonCancel.Size = new Size(86, 31); buttonCancel.TabIndex = 12; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -175,9 +184,10 @@ // buttonSave // buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonSave.Location = new Point(405, 386); + buttonSave.Location = new Point(455, 515); + buttonSave.Margin = new Padding(3, 4, 3, 4); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(75, 23); + buttonSave.Size = new Size(94, 31); buttonSave.TabIndex = 13; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; @@ -191,18 +201,20 @@ groupBoxComponents.Controls.Add(ButtonRef); groupBoxComponents.Controls.Add(dataGridView); groupBoxComponents.Controls.Add(ButtonAdd); - groupBoxComponents.Location = new Point(12, 81); + groupBoxComponents.Location = new Point(14, 108); + groupBoxComponents.Margin = new Padding(3, 4, 3, 4); groupBoxComponents.Name = "groupBoxComponents"; - groupBoxComponents.Size = new Size(579, 287); + groupBoxComponents.Padding = new Padding(3, 4, 3, 4); + groupBoxComponents.Size = new Size(662, 383); groupBoxComponents.TabIndex = 14; groupBoxComponents.TabStop = false; groupBoxComponents.Text = "Ингредиенты"; // // FormPizza // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(612, 430); + ClientSize = new Size(699, 573); Controls.Add(groupBoxComponents); Controls.Add(buttonCancel); Controls.Add(buttonSave); @@ -210,6 +222,7 @@ Controls.Add(textBoxName); Controls.Add(labelPrice); Controls.Add(labelName); + Margin = new Padding(3, 4, 3, 4); Name = "FormPizza"; Text = "Пицца"; Load += FormPizza_Load; -- 2.25.1 From 264c17ed08fb1502d49b8877a99bce6a986c16d1 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Wed, 13 Mar 2024 11:02:45 +0300 Subject: [PATCH 19/21] 10 --- Pizzeria/Pizzeria/FormCreateOrder.Designer.cs | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs b/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs index aaf6db8..f261442 100644 --- a/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs +++ b/Pizzeria/Pizzeria/FormCreateOrder.Designer.cs @@ -40,36 +40,38 @@ // // textBoxCount // - textBoxCount.Location = new Point(99, 41); + textBoxCount.Location = new Point(113, 55); + textBoxCount.Margin = new Padding(3, 4, 3, 4); textBoxCount.Name = "textBoxCount"; - textBoxCount.Size = new Size(233, 23); + textBoxCount.Size = new Size(266, 27); textBoxCount.TabIndex = 13; textBoxCount.TextChanged += textBoxCount_TextChanged; // // labelCount // labelCount.AutoSize = true; - labelCount.Location = new Point(11, 44); + labelCount.Location = new Point(13, 59); labelCount.Name = "labelCount"; - labelCount.Size = new Size(75, 15); + labelCount.Size = new Size(93, 20); labelCount.TabIndex = 12; labelCount.Text = "Количество:"; // // labelPizza // labelPizza.AutoSize = true; - labelPizza.Location = new Point(11, 15); + labelPizza.Location = new Point(13, 20); labelPizza.Name = "labelPizza"; - labelPizza.Size = new Size(43, 15); + labelPizza.Size = new Size(55, 20); labelPizza.TabIndex = 11; labelPizza.Text = "Пицца"; // // buttonCancel // buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCancel.Location = new Point(257, 109); + buttonCancel.Location = new Point(294, 145); + buttonCancel.Margin = new Padding(3, 4, 3, 4); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(75, 23); + buttonCancel.Size = new Size(86, 31); buttonCancel.TabIndex = 15; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -78,9 +80,10 @@ // buttonSave // buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonSave.Location = new Point(176, 109); + buttonSave.Location = new Point(193, 145); + buttonSave.Margin = new Padding(3, 4, 3, 4); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(75, 23); + buttonSave.Size = new Size(94, 31); buttonSave.TabIndex = 16; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; @@ -89,34 +92,36 @@ // labelSum // labelSum.AutoSize = true; - labelSum.Location = new Point(11, 73); + labelSum.Location = new Point(13, 97); labelSum.Name = "labelSum"; - labelSum.Size = new Size(48, 15); + labelSum.Size = new Size(58, 20); labelSum.TabIndex = 12; labelSum.Text = "Сумма:"; // // textBoxSum // - textBoxSum.Location = new Point(99, 70); + textBoxSum.Location = new Point(113, 93); + textBoxSum.Margin = new Padding(3, 4, 3, 4); textBoxSum.Name = "textBoxSum"; textBoxSum.ReadOnly = true; - textBoxSum.Size = new Size(233, 23); + textBoxSum.Size = new Size(266, 27); textBoxSum.TabIndex = 13; // // comboBoxPizza // comboBoxPizza.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxPizza.FormattingEnabled = true; - comboBoxPizza.Location = new Point(99, 12); + comboBoxPizza.Location = new Point(113, 16); + comboBoxPizza.Margin = new Padding(3, 4, 3, 4); comboBoxPizza.Name = "comboBoxPizza"; - comboBoxPizza.Size = new Size(233, 23); + comboBoxPizza.Size = new Size(266, 28); comboBoxPizza.TabIndex = 17; // // FormCreateOrder // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(351, 150); + ClientSize = new Size(401, 200); Controls.Add(comboBoxPizza); Controls.Add(buttonCancel); Controls.Add(buttonSave); @@ -125,6 +130,7 @@ Controls.Add(textBoxCount); Controls.Add(labelCount); Controls.Add(labelPizza); + Margin = new Padding(3, 4, 3, 4); Name = "FormCreateOrder"; Text = "Заказ"; Load += FormCreateOrder_Load; -- 2.25.1 From 50dc3f3313b1fb62a05ddaa4991963cb895bb70c Mon Sep 17 00:00:00 2001 From: revengel66 Date: Wed, 13 Mar 2024 11:03:33 +0300 Subject: [PATCH 20/21] 11 --- Pizzeria/Pizzeria/FormCreateOrder.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Pizzeria/Pizzeria/FormCreateOrder.cs b/Pizzeria/Pizzeria/FormCreateOrder.cs index 128684e..eb53204 100644 --- a/Pizzeria/Pizzeria/FormCreateOrder.cs +++ b/Pizzeria/Pizzeria/FormCreateOrder.cs @@ -1,12 +1,8 @@  using Microsoft.Extensions.Logging; -using Microsoft.VisualBasic.Logging; using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts; using PizzeriaContracts.SearchModels; -using PizzeriaContracts.ViewModels; -using PizzeriaDataModels.Models; -using System.Windows.Forms; namespace Pizzeria { -- 2.25.1 From f29db1718d0995d84bb9f18b8bb004b98f062be8 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Wed, 13 Mar 2024 11:04:26 +0300 Subject: [PATCH 21/21] 12 --- Pizzeria/Pizzeria/FormComponent.Designer.cs | 33 ++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Pizzeria/Pizzeria/FormComponent.Designer.cs b/Pizzeria/Pizzeria/FormComponent.Designer.cs index 1c685f0..4b18db0 100644 --- a/Pizzeria/Pizzeria/FormComponent.Designer.cs +++ b/Pizzeria/Pizzeria/FormComponent.Designer.cs @@ -39,41 +39,44 @@ // labelName // labelName.AutoSize = true; - labelName.Location = new Point(12, 21); + labelName.Location = new Point(14, 28); labelName.Name = "labelName"; - labelName.Size = new Size(62, 15); + labelName.Size = new Size(80, 20); labelName.TabIndex = 0; labelName.Text = "Название:"; // // labelPrice // labelPrice.AutoSize = true; - labelPrice.Location = new Point(12, 50); + labelPrice.Location = new Point(14, 67); labelPrice.Name = "labelPrice"; - labelPrice.Size = new Size(38, 15); + labelPrice.Size = new Size(48, 20); labelPrice.TabIndex = 1; labelPrice.Text = "Цена:"; // // textBoxName // - textBoxName.Location = new Point(100, 18); + textBoxName.Location = new Point(114, 24); + textBoxName.Margin = new Padding(3, 4, 3, 4); textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(233, 23); + textBoxName.Size = new Size(266, 27); textBoxName.TabIndex = 2; // // textBoxCost // - textBoxCost.Location = new Point(100, 47); + textBoxCost.Location = new Point(114, 63); + textBoxCost.Margin = new Padding(3, 4, 3, 4); textBoxCost.Name = "textBoxCost"; - textBoxCost.Size = new Size(233, 23); + textBoxCost.Size = new Size(266, 27); textBoxCost.TabIndex = 2; // // buttonSave // buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonSave.Location = new Point(177, 93); + buttonSave.Location = new Point(194, 124); + buttonSave.Margin = new Padding(3, 4, 3, 4); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(75, 23); + buttonSave.Size = new Size(94, 31); buttonSave.TabIndex = 3; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; @@ -82,9 +85,10 @@ // buttonCancel // buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCancel.Location = new Point(258, 93); + buttonCancel.Location = new Point(295, 124); + buttonCancel.Margin = new Padding(3, 4, 3, 4); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(75, 23); + buttonCancel.Size = new Size(86, 31); buttonCancel.TabIndex = 3; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -92,15 +96,16 @@ // // FormComponent // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(345, 136); + ClientSize = new Size(394, 181); Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(textBoxCost); Controls.Add(textBoxName); Controls.Add(labelPrice); Controls.Add(labelName); + Margin = new Padding(3, 4, 3, 4); Name = "FormComponent"; Text = "Ингредиент"; Load += FormComponent_Load; -- 2.25.1