From 12166ce6263fb77bdf9a6cfc27b62356b97ce7dd Mon Sep 17 00:00:00 2001 From: bekodeg Date: Fri, 9 Feb 2024 17:38:25 +0400 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D1=8B.=20=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B0=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar.sln | 20 +- .../{ProductLogic.cs => SushiLogic.cs} | 44 +-- .../BindingModels/OrderBindingModel.cs | 2 +- ...ctBindingModel.cs => SushiBindingModel.cs} | 6 +- .../BusinessLogicsContracts/IProductLogic.cs | 15 - .../BusinessLogicsContracts/ISushiLogic.cs | 15 + ...ductSearchModel.cs => SushiSearchModel.cs} | 4 +- .../StoragesContracts/IProductStorage.cs | 16 - .../StoragesContracts/ISushiStorage.cs | 16 + .../ViewModels/OrderViewModel.cs | 6 +- ...{ProductViewModel.cs => SushiViewModel.cs} | 8 +- .../SushiBarDataModels/Models/IOrderModel.cs | 2 +- .../{IProductModel.cs => ISushiModel.cs} | 6 +- .../DataListSingleton.cs | 27 ++ .../Implements/ComponentStorage.cs | 102 ++++++ .../Implements/OrderStorage.cs | 89 +++++ .../Implements/SushiStorage.cs | 102 ++++++ .../SushiBarListImplement/Models/Component.cs | 41 +++ .../SushiBarListImplement/Models/Order.cs | 61 ++++ .../SushiBarListImplement/Models/Sushi.cs | 54 ++++ .../SushiBarView/FormComponent.Designer.cs | 98 ++++++ SushiBar/SushiBarView/FormComponent.cs | 25 ++ SushiBar/SushiBarView/FormComponent.resx | 305 ++++++++++++++++++ SushiBar/SushiBarView/FormComponent.ru.resx | 183 +++++++++++ SushiBar/SushiBarView/FormComponentLogic.cs | 81 +++++ SushiBar/SushiBarView/Program.cs | 17 + 26 files changed, 1268 insertions(+), 77 deletions(-) rename SushiBar/SushiBarBusinessLogic/BusinessLogics/{ProductLogic.cs => SushiLogic.cs} (62%) rename SushiBar/SushiBarContracts/BindingModels/{ProductBindingModel.cs => SushiBindingModel.cs} (55%) delete mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IProductLogic.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs rename SushiBar/SushiBarContracts/SearchModels/{ProductSearchModel.cs => SushiSearchModel.cs} (53%) delete mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IProductStorage.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs rename SushiBar/SushiBarContracts/ViewModels/{ProductViewModel.cs => SushiViewModel.cs} (54%) rename SushiBar/SushiBarDataModels/Models/{IProductModel.cs => ISushiModel.cs} (50%) create mode 100644 SushiBar/SushiBarListImplement/DataListSingleton.cs create mode 100644 SushiBar/SushiBarListImplement/Implements/ComponentStorage.cs create mode 100644 SushiBar/SushiBarListImplement/Implements/OrderStorage.cs create mode 100644 SushiBar/SushiBarListImplement/Implements/SushiStorage.cs create mode 100644 SushiBar/SushiBarListImplement/Models/Component.cs create mode 100644 SushiBar/SushiBarListImplement/Models/Order.cs create mode 100644 SushiBar/SushiBarListImplement/Models/Sushi.cs create mode 100644 SushiBar/SushiBarView/FormComponent.Designer.cs create mode 100644 SushiBar/SushiBarView/FormComponent.cs create mode 100644 SushiBar/SushiBarView/FormComponent.resx create mode 100644 SushiBar/SushiBarView/FormComponent.ru.resx create mode 100644 SushiBar/SushiBarView/FormComponentLogic.cs create mode 100644 SushiBar/SushiBarView/Program.cs diff --git a/SushiBar/SushiBar.sln b/SushiBar/SushiBar.sln index 40fb127..588ef02 100644 --- a/SushiBar/SushiBar.sln +++ b/SushiBar/SushiBar.sln @@ -3,13 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.7.34031.279 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBar", "SushiBar\SushiBar.csproj", "{B9AC543F-20EE-47B1-9BC4-3F5DADAD931C}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDataModels", "SushiBarDataModels\SushiBarDataModels.csproj", "{968304F1-7A64-49F1-B27A-48AED7C7754D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{D3DDD3BE-863D-42E3-8CE7-FE527C5ADA13}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{CD8F84A5-5665-49EC-9630-F27A3176BA47}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{CD8F84A5-5665-49EC-9630-F27A3176BA47}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarListImplement", "SushiBarListImplement\SushiBarListImplement.csproj", "{A9E33D09-7C81-4D94-9A06-CF8A347D5740}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarView", "SushiBarView\SushiBarView.csproj", "{BCB90098-D537-4516-8DBA-450FEF6B479D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,10 +19,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B9AC543F-20EE-47B1-9BC4-3F5DADAD931C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B9AC543F-20EE-47B1-9BC4-3F5DADAD931C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B9AC543F-20EE-47B1-9BC4-3F5DADAD931C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B9AC543F-20EE-47B1-9BC4-3F5DADAD931C}.Release|Any CPU.Build.0 = Release|Any CPU {968304F1-7A64-49F1-B27A-48AED7C7754D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {968304F1-7A64-49F1-B27A-48AED7C7754D}.Debug|Any CPU.Build.0 = Debug|Any CPU {968304F1-7A64-49F1-B27A-48AED7C7754D}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -33,6 +31,14 @@ Global {CD8F84A5-5665-49EC-9630-F27A3176BA47}.Debug|Any CPU.Build.0 = Debug|Any CPU {CD8F84A5-5665-49EC-9630-F27A3176BA47}.Release|Any CPU.ActiveCfg = Release|Any CPU {CD8F84A5-5665-49EC-9630-F27A3176BA47}.Release|Any CPU.Build.0 = Release|Any CPU + {A9E33D09-7C81-4D94-9A06-CF8A347D5740}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A9E33D09-7C81-4D94-9A06-CF8A347D5740}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A9E33D09-7C81-4D94-9A06-CF8A347D5740}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A9E33D09-7C81-4D94-9A06-CF8A347D5740}.Release|Any CPU.Build.0 = Release|Any CPU + {BCB90098-D537-4516-8DBA-450FEF6B479D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BCB90098-D537-4516-8DBA-450FEF6B479D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BCB90098-D537-4516-8DBA-450FEF6B479D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BCB90098-D537-4516-8DBA-450FEF6B479D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ProductLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/SushiLogic.cs similarity index 62% rename from SushiBar/SushiBarBusinessLogic/BusinessLogics/ProductLogic.cs rename to SushiBar/SushiBarBusinessLogic/BusinessLogics/SushiLogic.cs index 6d62299..2cf5260 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/ProductLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/SushiLogic.cs @@ -7,20 +7,20 @@ using SushiBarContracts.ViewModels; namespace SushiBarBusinessLogic.BusinessLogics { - public class ProductLogic : IProductLogic + public class SushiLogic : ISushiLogic { private readonly ILogger _logger; - private readonly IProductStorage _productStorage; - public ProductLogic(ILogger logger, IProductStorage productStorage) + private readonly ISushiStorage _sushiStorage; + public SushiLogic(ILogger logger, ISushiStorage sushiStorage) { _logger = logger; - _productStorage = productStorage; + _sushiStorage = sushiStorage; } - public List? ReadList(ProductSearchModel? model) + public List? ReadList(SushiSearchModel? model) { - _logger.LogInformation("ReadList. ProductName:{ProductName}. Id:{ Id}", model?.ProductName, model?.Id); - var list = model == null ? _productStorage.GetFullList() : - _productStorage.GetFilteredList(model); + _logger.LogInformation("ReadList. SushiName:{SushiName}. Id:{ Id}", model?.SushiName, model?.Id); + var list = model == null ? _sushiStorage.GetFullList() : + _sushiStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -29,14 +29,14 @@ namespace SushiBarBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - public ProductViewModel? ReadElement(ProductSearchModel model) + public SushiViewModel? ReadElement(SushiSearchModel 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); + _logger.LogInformation("ReadElement. SushiName:{SushiName}. Id:{ Id}", model.SushiName, model.Id); + var element = _sushiStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); @@ -44,38 +44,38 @@ namespace SushiBarBusinessLogic.BusinessLogics } return element; } - public bool Create(ProductBindingModel model) + public bool Create(SushiBindingModel model) { CheckModel(model); - if (_productStorage.Insert(model) == null) + if (_sushiStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; } return true; } - public bool Update(ProductBindingModel model) + public bool Update(SushiBindingModel model) { CheckModel(model); - if (_productStorage.Update(model) == null) + if (_sushiStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; } return true; } - public bool Delete(ProductBindingModel model) + public bool Delete(SushiBindingModel model) { CheckModel(model, false); _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_productStorage.Delete(model) == null) + if (_sushiStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; } return true; } - private void CheckModel(ProductBindingModel model, bool withParams = true) + private void CheckModel(SushiBindingModel model, bool withParams = true) { if (model == null) { @@ -85,17 +85,17 @@ namespace SushiBarBusinessLogic.BusinessLogics { return; } - if (string.IsNullOrEmpty(model.ProductName)) + if (string.IsNullOrEmpty(model.SushiName)) { - throw new ArgumentException("Нет названия продукта", nameof(model.ProductName)); + throw new ArgumentException("Нет названия продукта", nameof(model.SushiName)); } if (model.Price <= 0) { throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price)); } - var element = _productStorage.GetElement(new ProductSearchModel + var element = _sushiStorage.GetElement(new SushiSearchModel { - ProductName = model.ProductName + SushiName = model.SushiName }); if (element != null && element.Id != model.Id) { diff --git a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs index 2625c77..04c26e9 100644 --- a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs @@ -6,7 +6,7 @@ namespace SushiBarContracts.BindingModels public class OrderBindingModel : IOrderModel { public int Id { get; set; } - public int ProductId { get; set; } + public int SushiId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/SushiBar/SushiBarContracts/BindingModels/ProductBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs similarity index 55% rename from SushiBar/SushiBarContracts/BindingModels/ProductBindingModel.cs rename to SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs index 13c12c0..2e10f06 100644 --- a/SushiBar/SushiBarContracts/BindingModels/ProductBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/SushiBindingModel.cs @@ -2,12 +2,12 @@ namespace SushiBarContracts.BindingModels { - public class ProductBindingModel : IProductModel + public class SushiBindingModel : ISushiModel { public int Id { get; set; } - public string ProductName { get; set; } = string.Empty; + public string SushiName { get; set; } = string.Empty; public double Price { get; set; } - public Dictionary ProductComponents + public Dictionary SushiComponents { get; set; diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IProductLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IProductLogic.cs deleted file mode 100644 index 96217a1..0000000 --- a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IProductLogic.cs +++ /dev/null @@ -1,15 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.ViewModels; - -namespace SushiBarContracts.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/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs new file mode 100644 index 0000000..ae5cbbb --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/ISushiLogic.cs @@ -0,0 +1,15 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface ISushiLogic + { + List? ReadList(SushiSearchModel? model); + SushiViewModel? ReadElement(SushiSearchModel model); + bool Create(SushiBindingModel model); + bool Update(SushiBindingModel model); + bool Delete(SushiBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/SearchModels/ProductSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs similarity index 53% rename from SushiBar/SushiBarContracts/SearchModels/ProductSearchModel.cs rename to SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs index 86bc1d7..55e424e 100644 --- a/SushiBar/SushiBarContracts/SearchModels/ProductSearchModel.cs +++ b/SushiBar/SushiBarContracts/SearchModels/SushiSearchModel.cs @@ -1,8 +1,8 @@ namespace SushiBarContracts.SearchModels { - public class ProductSearchModel + public class SushiSearchModel { public int? Id { get; set; } - public string? ProductName { get; set; } + public string? SushiName { get; set; } } } diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IProductStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IProductStorage.cs deleted file mode 100644 index 16e3db4..0000000 --- a/SushiBar/SushiBarContracts/StoragesContracts/IProductStorage.cs +++ /dev/null @@ -1,16 +0,0 @@ -using SushiBarContracts.BindingModels; -using SushiBarContracts.SearchModels; -using SushiBarContracts.ViewModels; - -namespace SushiBarContracts.StoragesContracts -{ - 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/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs new file mode 100644 index 0000000..ff49391 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/ISushiStorage.cs @@ -0,0 +1,16 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.StoragesContracts +{ + public interface ISushiStorage + { + List GetFullList(); + List GetFilteredList(SushiSearchModel model); + SushiViewModel? GetElement(SushiSearchModel model); + SushiViewModel? Insert(SushiBindingModel model); + SushiViewModel? Update(SushiBindingModel model); + SushiViewModel? Delete(SushiBindingModel model); + } +} diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs index 9988699..0d9b086 100644 --- a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -8,9 +8,9 @@ namespace SushiBarContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } - public int ProductId { get; set; } - [DisplayName("Изделие")] - public string ProductName { get; set; } = string.Empty; + public int SushiId { get; set; } + [DisplayName("Суши")] + public string SushiName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] diff --git a/SushiBar/SushiBarContracts/ViewModels/ProductViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs similarity index 54% rename from SushiBar/SushiBarContracts/ViewModels/ProductViewModel.cs rename to SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs index 67b02e2..73b3ae8 100644 --- a/SushiBar/SushiBarContracts/ViewModels/ProductViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/SushiViewModel.cs @@ -3,14 +3,14 @@ using System.ComponentModel; namespace SushiBarContracts.ViewModels { - public class ProductViewModel : IProductModel + public class SushiViewModel : ISushiModel { public int Id { get; set; } - [DisplayName("Название изделия")] - public string ProductName { get; set; } = string.Empty; + [DisplayName("Название суши")] + public string SushiName { get; set; } = string.Empty; [DisplayName("Цена")] public double Price { get; set; } - public Dictionary ProductComponents + public Dictionary SushiComponents { get; set; diff --git a/SushiBar/SushiBarDataModels/Models/IOrderModel.cs b/SushiBar/SushiBarDataModels/Models/IOrderModel.cs index 501a9dc..3770e12 100644 --- a/SushiBar/SushiBarDataModels/Models/IOrderModel.cs +++ b/SushiBar/SushiBarDataModels/Models/IOrderModel.cs @@ -4,7 +4,7 @@ namespace SushiBarDataModels.Models { public interface IOrderModel : IId { - int ProductId { get; } + int SushiId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/SushiBar/SushiBarDataModels/Models/IProductModel.cs b/SushiBar/SushiBarDataModels/Models/ISushiModel.cs similarity index 50% rename from SushiBar/SushiBarDataModels/Models/IProductModel.cs rename to SushiBar/SushiBarDataModels/Models/ISushiModel.cs index a28a0bc..d7257ad 100644 --- a/SushiBar/SushiBarDataModels/Models/IProductModel.cs +++ b/SushiBar/SushiBarDataModels/Models/ISushiModel.cs @@ -3,10 +3,10 @@ using System.Collections.Generic; using System.Linq; namespace SushiBarDataModels.Models { - public interface IProductModel : IId + public interface ISushiModel : IId { - string ProductName { get; } + string SushiName { get; } double Price { get; } - Dictionary ProductComponents { get; } + Dictionary SushiComponents { get; } } } diff --git a/SushiBar/SushiBarListImplement/DataListSingleton.cs b/SushiBar/SushiBarListImplement/DataListSingleton.cs new file mode 100644 index 0000000..c02c6c7 --- /dev/null +++ b/SushiBar/SushiBarListImplement/DataListSingleton.cs @@ -0,0 +1,27 @@ +using SushiBarListImplement.Models; + +namespace SushiBarListImplement +{ + public class DataListSingleton + { + private static DataListSingleton _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Sushis { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Sushis = new List(); + } + + public static DataListSingleton GetInsance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/SushiBar/SushiBarListImplement/Implements/ComponentStorage.cs b/SushiBar/SushiBarListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..e242577 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,102 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; + +namespace SushiBarListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInsance(); + } + 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/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..6635a4d --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs @@ -0,0 +1,89 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; + +namespace SushiBarListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInsance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + return result; + } + 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 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; + } + 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; + } + } +} diff --git a/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs new file mode 100644 index 0000000..7ed32ac --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/SushiStorage.cs @@ -0,0 +1,102 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; + +namespace SushiBarListImplement.Implements +{ + public class SushiStorage : ISushiStorage + { + private readonly DataListSingleton _source; + public SushiStorage() + { + _source = DataListSingleton.GetInsance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var sushi in _source.Sushis) + { + result.Add(sushi.GetViewModel); + } + return result; + } + public List GetFilteredList(SushiSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.SushiName)) + { + return result; + } + foreach (var sushi in _source.Sushis) + { + if (sushi.SushiName.Contains(model.SushiName)) + { + result.Add(sushi.GetViewModel); + } + } + return result; + } + public SushiViewModel? GetElement(SushiSearchModel model) + { + if (string.IsNullOrEmpty(model.SushiName) && !model.Id.HasValue) + { + return null; + } + foreach (var sushi in _source.Sushis) + { + if ((!string.IsNullOrEmpty(model.SushiName) && + sushi.SushiName == model.SushiName) || + (model.Id.HasValue && sushi.Id == model.Id)) + { + return sushi.GetViewModel; + } + } + return null; + } + public SushiViewModel? Insert(SushiBindingModel model) + { + model.Id = 1; + foreach (var sushi in _source.Sushis) + { + if (model.Id <= sushi.Id) + { + model.Id = sushi.Id + 1; + } + } + var newSushi = Sushi.Create(model); + if (newSushi == null) + { + return null; + } + _source.Sushis.Add(newSushi); + return newSushi.GetViewModel; + } + public SushiViewModel? Update(SushiBindingModel model) + { + foreach (var sushi in _source.Sushis) + { + if (sushi.Id == model.Id) + { + sushi.Update(model); + return sushi.GetViewModel; + } + } + return null; + } + public SushiViewModel? Delete(SushiBindingModel model) + { + for (int i = 0; i < _source.Sushis.Count; ++i) + { + if (_source.Sushis[i].Id == model.Id) + { + var element = _source.Sushis[i]; + _source.Sushis.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/SushiBar/SushiBarListImplement/Models/Component.cs b/SushiBar/SushiBarListImplement/Models/Component.cs new file mode 100644 index 0000000..b220453 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Models/Component.cs @@ -0,0 +1,41 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBarListImplement.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/SushiBar/SushiBarListImplement/Models/Order.cs b/SushiBar/SushiBarListImplement/Models/Order.cs new file mode 100644 index 0000000..5897bf7 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Models/Order.cs @@ -0,0 +1,61 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Enums; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int SushiId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + 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, + SushiId = model.SushiId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + SushiId = model.SushiId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + SushiId = SushiId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/SushiBar/SushiBarListImplement/Models/Sushi.cs b/SushiBar/SushiBarListImplement/Models/Sushi.cs new file mode 100644 index 0000000..a3656cd --- /dev/null +++ b/SushiBar/SushiBarListImplement/Models/Sushi.cs @@ -0,0 +1,54 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplement.Models +{ + public class Sushi : ISushiModel + { + public int Id { get; private set; } + public string SushiName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary SushiComponents + { + get; + private set; + } = new Dictionary(); + public static Sushi? Create(SushiBindingModel? model) + { + if (model == null) + { + return null; + } + return new Sushi() + { + Id = model.Id, + SushiName = model.SushiName, + Price = model.Price, + SushiComponents = model.SushiComponents + }; + } + public void Update(SushiBindingModel? model) + { + if (model == null) + { + return; + } + SushiName = model.SushiName; + Price = model.Price; + SushiComponents = model.SushiComponents; + } + public SushiViewModel GetViewModel => new() + { + Id = Id, + SushiName = SushiName, + Price = Price, + SushiComponents = SushiComponents + }; + } +} diff --git a/SushiBar/SushiBarView/FormComponent.Designer.cs b/SushiBar/SushiBarView/FormComponent.Designer.cs new file mode 100644 index 0000000..7c52e81 --- /dev/null +++ b/SushiBar/SushiBarView/FormComponent.Designer.cs @@ -0,0 +1,98 @@ +namespace SushiBarView +{ + 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() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormComponent)); + label1 = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + label2 = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // label1 + // + resources.ApplyResources(label1, "label1"); + label1.Name = "label1"; + // + // textBoxName + // + resources.ApplyResources(textBoxName, "textBoxName"); + textBoxName.Name = "textBoxName"; + // + // textBoxCost + // + resources.ApplyResources(textBoxCost, "textBoxCost"); + textBoxCost.Name = "textBoxCost"; + // + // label2 + // + resources.ApplyResources(label2, "label2"); + label2.Name = "label2"; + // + // buttonSave + // + resources.ApplyResources(buttonSave, "buttonSave"); + buttonSave.Name = "buttonSave"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + resources.ApplyResources(buttonCancel, "buttonCancel"); + buttonCancel.Name = "buttonCancel"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormComponent + // + resources.ApplyResources(this, "$this"); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCost); + Controls.Add(label2); + Controls.Add(textBoxName); + Controls.Add(label1); + Name = "FormComponent"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private TextBox textBoxName; + private TextBox textBoxCost; + private Label label2; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponent.cs b/SushiBar/SushiBarView/FormComponent.cs new file mode 100644 index 0000000..7ab25e2 --- /dev/null +++ b/SushiBar/SushiBarView/FormComponent.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBarView +{ + public partial class FormComponent + { + private void buttonSave_Click(object sender, EventArgs e) + { + + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/SushiBar/SushiBarView/FormComponent.resx b/SushiBar/SushiBarView/FormComponent.resx new file mode 100644 index 0000000..ac033b7 --- /dev/null +++ b/SushiBar/SushiBarView/FormComponent.resx @@ -0,0 +1,305 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + FormComponent + + + $this + + + $this + + + 4 + + + buttonCancel + + + + 800, 450 + + + + 3 + + + $this + + + System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 1 + + + textBoxCost + + + $this + + + $this + + + 8, 20 + + + 4 + + + System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + button1 + + + System.Windows.Forms.Form, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 0 + + + textBox1 + + + System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 95, 85 + + + 1 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 12, 42 + + + 3 + + + $this + + + $this + + + 0 + + + System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 68, 6 + + + 0 + + + 222, 85 + + + label1 + + + 4 + + + System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 5 + + + 1 + + + buttonSave + + + 222, 85 + + + FormComponent + + + 12, 9 + + + 95, 85 + + + label2 + + + 0 + + + 5 + + + 1 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 2 + + + 5 + + + textBoxName + + + $this + + + System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 95, 39 + + + 95, 6 + + + 2 + + + button2 + + + ru + + + True + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponent.ru.resx b/SushiBar/SushiBarView/FormComponent.ru.resx new file mode 100644 index 0000000..81e7eef --- /dev/null +++ b/SushiBar/SushiBarView/FormComponent.ru.resx @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + 77, 20 + + + Название + + + 246, 27 + + + 246, 27 + + + True + + + + NoControl + + + 45, 20 + + + Цена + + + 95, 85 + + + 121, 29 + + + 4 + + + Сохранить + + + NoControl + + + 222, 85 + + + 119, 29 + + + 5 + + + Отмена + + + 353, 126 + + + Компонент + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormComponentLogic.cs b/SushiBar/SushiBarView/FormComponentLogic.cs new file mode 100644 index 0000000..28ea2ba --- /dev/null +++ b/SushiBar/SushiBarView/FormComponentLogic.cs @@ -0,0 +1,81 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace SushiBarView +{ + 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/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs new file mode 100644 index 0000000..44ffd81 --- /dev/null +++ b/SushiBar/SushiBarView/Program.cs @@ -0,0 +1,17 @@ +namespace SushiBarView +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file