From 793a09fb2cd661709b903a702b505c695d9ebf32 Mon Sep 17 00:00:00 2001 From: bulatova_karina Date: Tue, 26 Mar 2024 20:07:16 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=BD=D0=B0=D0=B4=D0=B5=D1=8E=D1=81=D1=8C?= =?UTF-8?q?=20=D1=8D=D1=82=D0=BE=20=D0=B2=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ComponentLogic.cs | 2 +- .../BusinessLogics/ComputerLogic.cs | 2 +- .../BusinessLogics/OrderLogic.cs | 2 +- .../BusinessLogics/ShopLogic.cs | 172 +++++++++++++++ .../BindingModels/ShopBindingModel.cs | 19 ++ .../IComponentLogic.cs | 2 +- .../BusinessLogicsContracts/IComputerLogic.cs | 2 +- .../BusinessLogicsContracts/IOrderLogic.cs | 2 +- .../BusinessLogicsContracts/IShopLogic.cs | 23 ++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 22 ++ .../ViewModels/ShopViewModel.cs | 23 ++ .../Models/IShopModel.cs | 16 ++ .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 109 ++++++++++ .../ComputersShopListImplement/Models/Shop.cs | 56 +++++ .../ComputersShopView/FormComponent.cs | 2 +- .../ComputersShopView/FormComponents.cs | 2 +- .../ComputersShopView/FormComputer.cs | 2 +- .../FormComputerComponent.cs | 2 +- .../ComputersShopView/FormComputers.cs | 2 +- .../ComputersShopView/FormCreateOrder.cs | 2 +- .../ComputersShopView/FormMain.Designer.cs | 26 ++- ComputersShop/ComputersShopView/FormMain.cs | 18 +- .../ComputersShopView/FormShop.Designer.cs | 198 ++++++++++++++++++ ComputersShop/ComputersShopView/FormShop.cs | 123 +++++++++++ ComputersShop/ComputersShopView/FormShop.resx | 84 ++++++++ .../ComputersShopView/FormShops.Designer.cs | 115 ++++++++++ ComputersShop/ComputersShopView/FormShops.cs | 113 ++++++++++ .../ComputersShopView/FormShops.resx | 60 ++++++ .../ComputersShopView/FormSupply.Designer.cs | 142 +++++++++++++ ComputersShop/ComputersShopView/FormSupply.cs | 151 +++++++++++++ .../ComputersShopView/FormSupply.resx | 60 ++++++ ComputersShop/ComputersShopView/Program.cs | 12 +- 34 files changed, 1562 insertions(+), 20 deletions(-) create mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs create mode 100644 ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/SearchModels/ShopSearchModel.cs create mode 100644 ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs create mode 100644 ComputersShop/ComputersShopDataModels/Models/IShopModel.cs create mode 100644 ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs create mode 100644 ComputersShop/ComputersShopListImplement/Models/Shop.cs create mode 100644 ComputersShop/ComputersShopView/FormShop.Designer.cs create mode 100644 ComputersShop/ComputersShopView/FormShop.cs create mode 100644 ComputersShop/ComputersShopView/FormShop.resx create mode 100644 ComputersShop/ComputersShopView/FormShops.Designer.cs create mode 100644 ComputersShop/ComputersShopView/FormShops.cs create mode 100644 ComputersShop/ComputersShopView/FormShops.resx create mode 100644 ComputersShop/ComputersShopView/FormSupply.Designer.cs create mode 100644 ComputersShop/ComputersShopView/FormSupply.cs create mode 100644 ComputersShop/ComputersShopView/FormSupply.resx diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs index 35a0d59..37626aa 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.BusinessLogicsContracts; using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; using ComputersShopContracts.StoragesContracts; diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs index 36a308c..75d2a93 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using ComputersShopContracts.BindingModels; -using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.BusinessLogicsContracts; using ComputersShopContracts.SearchModels; using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.ViewModels; diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs index 0070a56..b21f70a 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using ComputersShopContracts.BindingModels; -using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.BusinessLogicsContracts; using ComputersShopContracts.SearchModels; using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.ViewModels; diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..c6ee924 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; +using ComputersShopDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace ComputersShopBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + public List ReadList(ShopSearchModel model) + { + _logger.LogInformation("ReadList. ShopName:{Name}. Id:{ Id}", model?.Name, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + + } + + public bool MakeSupply(ShopSearchModel model, IComputerModel Computer, int count) + { + _logger.LogInformation("Try to supply shop. ShopName:{ShopName}. Id:{Id}", model.Name, model.Id); + if (model == null) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(model)); + } + if (Computer == null) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(Computer)); + } + if (count <= 0) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException("Количество должно быть положительным числом"); + } + ShopViewModel curModel = ReadElement(model); + if (curModel == null) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(curModel)); + } + if (curModel.ShopComputers.TryGetValue(Computer.Id, out var pair)) + { + curModel.ShopComputers[Computer.Id] = (pair.Item1, pair.Item2 + count); + } + else + { + curModel.ShopComputers.Add(Computer.Id, (Computer, count)); + } + Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + DateOpen = curModel.DateOpen, + Address = curModel.Address, + ShopComputers = curModel.ShopComputers, + }); + _logger.LogInformation("Success. ComputerName:{ComputerName}. Id:{Id}. Supply:{count}", Computer.ComputerName, Computer.Id, count); + return true; + } + + public ShopViewModel ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Нет названия магазина", + nameof(model.ShopName)); + } + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Нет адресса магазина", + nameof(model.Address)); + } + if (model.DateOpen == null) + { + throw new ArgumentNullException("Нет даты открытия магазина", + nameof(model.DateOpen)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}", model.ShopName, model.Address, model.DateOpen, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..cbb3518 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels; +using ComputersShopDataModels.Models; + +namespace ComputersShopContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } + public string Address { get; set; } + public DateTime DateOpen { get; set; } + public Dictionary ShopComputers { get; set; } = new(); + } +} diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComponentLogic.cs index 42896d2..817e191 100644 --- a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComponentLogic.cs +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopContracts.BuisnessLogicsContracts +namespace ComputersShopContracts.BusinessLogicsContracts { public interface IComponentLogic { diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComputerLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComputerLogic.cs index f2cd941..6a80a33 100644 --- a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComputerLogic.cs +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IComputerLogic.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopContracts.BuisnessLogicsContracts +namespace ComputersShopContracts.BusinessLogicsContracts { public interface IComputerLogic { diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs index 54f9079..8c8da36 100644 --- a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ComputersShopContracts.BuisnessLogicsContracts +namespace ComputersShopContracts.BusinessLogicsContracts { public interface IOrderLogic { diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IShopLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..85bc165 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; +using ComputersShopDataModels.Models; + +namespace ComputersShopContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool MakeSupply(ShopSearchModel model, IComputerModel computer, int count); + } +} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/ShopSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..228bd84 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..9d10aa7 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? GetElement(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..cf398a8 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels; +using ComputersShopDataModels.Models; + +namespace ComputersShopContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название магазина")] + public string ShopName { get; set; } + [DisplayName("Адрес магазина")] + public string Address { get; set; } + [DisplayName("Дата открытия")] + public DateTime DateOpen { get; set; } + public Dictionary ShopComputers { get; set; } = new(); + } +} diff --git a/ComputersShop/ComputersShopDataModels/Models/IShopModel.cs b/ComputersShop/ComputersShopDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..ab57ac3 --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/Models/IShopModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Address { get; } + DateTime DateOpen { get; } + Dictionary ShopComputers { get; } + } +} diff --git a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs index 3337082..e413d1f 100644 --- a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs +++ b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace AbstractShopListImplement public List Components { get; set; } public List Orders { get; set; } public List Computers { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Computers = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..93ed65f --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AbstractShopListImplement; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; +using ComputersShopListImplement.Models; + +namespace ComputersShopListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.Name)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.Name)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.Name) && + shop.ShopName == model.Name) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/ComputersShop/ComputersShopListImplement/Models/Shop.cs b/ComputersShop/ComputersShopListImplement/Models/Shop.cs new file mode 100644 index 0000000..7aa9430 --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Models/Shop.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; +using ComputersShopDataModels.Models; + +namespace ComputersShopListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } + public string Address { get; private set; } + public DateTime DateOpen { get; private set; } + public Dictionary ShopComputers { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + return null; + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + ShopComputers = new() + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + ShopComputers = model.ShopComputers; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + ShopComputers = ShopComputers + }; + } +} diff --git a/ComputersShop/ComputersShopView/FormComponent.cs b/ComputersShop/ComputersShopView/FormComponent.cs index 70045f5..14fee43 100644 --- a/ComputersShop/ComputersShopView/FormComponent.cs +++ b/ComputersShop/ComputersShopView/FormComponent.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ComputersShopContracts.BindingModels; -using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.BusinessLogicsContracts; using ComputersShopContracts.SearchModels; using Microsoft.Extensions.Logging; diff --git a/ComputersShop/ComputersShopView/FormComponents.cs b/ComputersShop/ComputersShopView/FormComponents.cs index d8a97c4..5dd3e12 100644 --- a/ComputersShop/ComputersShopView/FormComponents.cs +++ b/ComputersShop/ComputersShopView/FormComponents.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ComputersShopContracts.BindingModels; -using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; diff --git a/ComputersShop/ComputersShopView/FormComputer.cs b/ComputersShop/ComputersShopView/FormComputer.cs index 3633451..eec94a6 100644 --- a/ComputersShop/ComputersShopView/FormComputer.cs +++ b/ComputersShop/ComputersShopView/FormComputer.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ComputersShopContracts.BindingModels; -using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.BusinessLogicsContracts; using ComputersShopContracts.SearchModels; using ComputersShopDataModels.Models; using Microsoft.Extensions.Logging; diff --git a/ComputersShop/ComputersShopView/FormComputerComponent.cs b/ComputersShop/ComputersShopView/FormComputerComponent.cs index 595a604..b87b816 100644 --- a/ComputersShop/ComputersShopView/FormComputerComponent.cs +++ b/ComputersShop/ComputersShopView/FormComputerComponent.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.BusinessLogicsContracts; using ComputersShopContracts.ViewModels; using ComputersShopDataModels.Models; diff --git a/ComputersShop/ComputersShopView/FormComputers.cs b/ComputersShop/ComputersShopView/FormComputers.cs index f481724..835777d 100644 --- a/ComputersShop/ComputersShopView/FormComputers.cs +++ b/ComputersShop/ComputersShopView/FormComputers.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using Microsoft.Extensions.Logging; using ComputersShopContracts.BindingModels; -using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.BusinessLogicsContracts; namespace ComputersShopView { diff --git a/ComputersShop/ComputersShopView/FormCreateOrder.cs b/ComputersShop/ComputersShopView/FormCreateOrder.cs index 6734fa3..e61c225 100644 --- a/ComputersShop/ComputersShopView/FormCreateOrder.cs +++ b/ComputersShop/ComputersShopView/FormCreateOrder.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ComputersShopContracts.BindingModels; -using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.BusinessLogicsContracts; using ComputersShopContracts.SearchModels; using Microsoft.Extensions.Logging; diff --git a/ComputersShop/ComputersShopView/FormMain.Designer.cs b/ComputersShop/ComputersShopView/FormMain.Designer.cs index 72c4b76..3511353 100644 --- a/ComputersShop/ComputersShopView/FormMain.Designer.cs +++ b/ComputersShop/ComputersShopView/FormMain.Designer.cs @@ -32,6 +32,8 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.поставкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); @@ -57,7 +59,9 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, - this.изделияToolStripMenuItem}); + this.изделияToolStripMenuItem, + this.магазиныToolStripMenuItem, + this.поставкиToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -65,17 +69,31 @@ // компонентыToolStripMenuItem // this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26); + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // // изделияToolStripMenuItem // this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(182, 26); + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.изделияToolStripMenuItem.Text = "Изделия"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.МагазиныToolStripMenuItem_Click); + // + // поставкиToolStripMenuItem + // + this.поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem"; + this.поставкиToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.поставкиToolStripMenuItem.Text = "Поставки"; + this.поставкиToolStripMenuItem.Click += new System.EventHandler(this.ПоставкиToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -175,5 +193,7 @@ private Button buttonRef; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem изделияToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem поставкиToolStripMenuItem; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormMain.cs b/ComputersShop/ComputersShopView/FormMain.cs index dbaadbf..f9ed2e6 100644 --- a/ComputersShop/ComputersShopView/FormMain.cs +++ b/ComputersShop/ComputersShopView/FormMain.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using ComputersShopBusinessLogic.BusinessLogics; using ComputersShopContracts.BindingModels; -using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; namespace ComputersShopView @@ -64,6 +64,22 @@ namespace ComputersShopView form.ShowDialog(); } } + private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void ПоставкиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); + if (service is FormSupply form) + { + form.ShowDialog(); + } + } private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = diff --git a/ComputersShop/ComputersShopView/FormShop.Designer.cs b/ComputersShop/ComputersShopView/FormShop.Designer.cs new file mode 100644 index 0000000..26688e2 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormShop.Designer.cs @@ -0,0 +1,198 @@ +namespace ComputersShopView +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.textBoxAdress = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ComputerName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 22); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(80, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 61); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(54, 20); + this.label2.TabIndex = 1; + this.label2.Text = "Адрес:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 102); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(44, 20); + this.label3.TabIndex = 2; + this.label3.Text = "Дата:"; + // + // dateTimePicker + // + this.dateTimePicker.Location = new System.Drawing.Point(104, 97); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(403, 27); + this.dateTimePicker.TabIndex = 3; + // + // textBoxAdress + // + this.textBoxAdress.Location = new System.Drawing.Point(104, 61); + this.textBoxAdress.Name = "textBoxAdress"; + this.textBoxAdress.Size = new System.Drawing.Size(403, 27); + this.textBoxAdress.TabIndex = 4; + this.textBoxAdress.TextChanged += new System.EventHandler(this.FormShop_Load); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(104, 22); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(403, 27); + this.textBoxName.TabIndex = 5; + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.id, + this.ComputerName, + this.Price, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(23, 156); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(507, 173); + this.dataGridView.TabIndex = 6; + // + // id + // + this.id.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.id.HeaderText = "Id"; + this.id.MinimumWidth = 6; + this.id.Name = "id"; + this.id.Visible = false; + // + // ComputerName + // + this.ComputerName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ComputerName.HeaderText = "Название"; + this.ComputerName.MinimumWidth = 6; + this.ComputerName.Name = "ComputerName"; + // + // Price + // + this.Price.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Price.HeaderText = "Цена"; + this.Price.MinimumWidth = 6; + this.Price.Name = "Price"; + // + // Count + // + this.Count.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(319, 354); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(436, 354); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 8; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(546, 395); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.textBoxAdress); + this.Controls.Add(this.dateTimePicker); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormShop"; + this.Text = "Магазин"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private DateTimePicker dateTimePicker; + private TextBox textBoxAdress; + private TextBox textBoxName; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn ComputerName; + private DataGridViewTextBoxColumn Price; + private DataGridViewTextBoxColumn Count; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormShop.cs b/ComputersShop/ComputersShopView/FormShop.cs new file mode 100644 index 0000000..6b9788c --- /dev/null +++ b/ComputersShop/ComputersShopView/FormShop.cs @@ -0,0 +1,123 @@ +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; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopDataModels; +using ComputersShopDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace ComputersShopView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public int? _id; + private Dictionary _Computers; + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); + if (shop != null) + { + textBoxName.Text = shop.ShopName; + textBoxAdress.Text = shop.Address; + dateTimePicker.Text = shop.DateOpen.ToString(); + _Computers = shop.ShopComputers; + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка товаров магазина"); + try + { + if (_Computers != null) + { + foreach (var Computer in _Computers) + { + dataGridView.Rows.Add(new object[] { Computer.Key, Computer.Value.Item1.ComputerName, Computer.Value.Item1.Price, Computer.Value.Item2 }); + } + } + } + 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 ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAdress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAdress.Text, + DateOpen = dateTimePicker.Value.Date, + ShopComputers = _Computers + }; + 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/ComputersShop/ComputersShopView/FormShop.resx b/ComputersShop/ComputersShopView/FormShop.resx new file mode 100644 index 0000000..14c1c77 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormShop.resx @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormShops.Designer.cs b/ComputersShop/ComputersShopView/FormShops.Designer.cs new file mode 100644 index 0000000..e8fdfde --- /dev/null +++ b/ComputersShop/ComputersShopView/FormShops.Designer.cs @@ -0,0 +1,115 @@ +namespace ComputersShopView +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridViewShops = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonRefresh = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewShops)).BeginInit(); + this.SuspendLayout(); + // + // dataGridViewShops + // + this.dataGridViewShops.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridViewShops.Location = new System.Drawing.Point(1, 0); + this.dataGridViewShops.Name = "dataGridViewShops"; + this.dataGridViewShops.RowHeadersWidth = 51; + this.dataGridViewShops.RowTemplate.Height = 29; + this.dataGridViewShops.Size = new System.Drawing.Size(415, 453); + this.dataGridViewShops.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(434, 39); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(434, 94); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(94, 29); + this.buttonUpdate.TabIndex = 2; + this.buttonUpdate.Text = "Изменить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(434, 143); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(94, 29); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(434, 195); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(94, 29); + this.buttonRefresh.TabIndex = 4; + this.buttonRefresh.Text = "Обновить"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.ButtonRefresh_Click); + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(554, 450); + this.Controls.Add(this.buttonRefresh); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridViewShops); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewShops)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridViewShops; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormShops.cs b/ComputersShop/ComputersShopView/FormShops.cs new file mode 100644 index 0000000..a84cfb8 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormShops.cs @@ -0,0 +1,113 @@ +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; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace ComputersShopView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridViewShops.DataSource = list; + dataGridViewShops.Columns["Id"].Visible = false; + dataGridViewShops.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridViewShops.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridViewShops.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridViewShops.Columns["ShopComputers"].Visible = false; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + if (dataGridViewShops.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + var tmp = Convert.ToInt32(dataGridViewShops.SelectedRows[0].Cells["Id"].Value); + form._id = Convert.ToInt32(dataGridViewShops.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridViewShops.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridViewShops.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} diff --git a/ComputersShop/ComputersShopView/FormShops.resx b/ComputersShop/ComputersShopView/FormShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShopView/FormShops.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/ComputersShop/ComputersShopView/FormSupply.Designer.cs b/ComputersShop/ComputersShopView/FormSupply.Designer.cs new file mode 100644 index 0000000..238a7ad --- /dev/null +++ b/ComputersShop/ComputersShopView/FormSupply.Designer.cs @@ -0,0 +1,142 @@ +namespace ComputersShopView +{ + partial class FormSupply + { + /// + /// 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.labelShop = new System.Windows.Forms.Label(); + this.labelComputer = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxComputer = new System.Windows.Forms.ComboBox(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(28, 46); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(72, 20); + this.labelShop.TabIndex = 0; + this.labelShop.Text = "Магазин:"; + // + // labelComputer + // + this.labelComputer.AutoSize = true; + this.labelComputer.Location = new System.Drawing.Point(28, 96); + this.labelComputer.Name = "labelComputer"; + this.labelComputer.Size = new System.Drawing.Size(93, 20); + this.labelComputer.TabIndex = 1; + this.labelComputer.Text = "Компьютер:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(28, 146); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество:"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(142, 139); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(349, 27); + this.textBoxCount.TabIndex = 3; + // + // comboBoxComputer + // + this.comboBoxComputer.FormattingEnabled = true; + this.comboBoxComputer.Location = new System.Drawing.Point(142, 88); + this.comboBoxComputer.Name = "comboBoxComputer"; + this.comboBoxComputer.Size = new System.Drawing.Size(349, 28); + this.comboBoxComputer.TabIndex = 4; + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(142, 38); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(349, 28); + this.comboBoxShop.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(328, 186); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(446, 186); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormSupply + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(552, 227); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.comboBoxComputer); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelComputer); + this.Controls.Add(this.labelShop); + this.Name = "FormSupply"; + this.Text = "Поставки"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelShop; + private Label labelComputer; + private Label labelCount; + private TextBox textBoxCount; + private ComboBox comboBoxComputer; + private ComboBox comboBoxShop; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormSupply.cs b/ComputersShop/ComputersShopView/FormSupply.cs new file mode 100644 index 0000000..855b76c --- /dev/null +++ b/ComputersShop/ComputersShopView/FormSupply.cs @@ -0,0 +1,151 @@ +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; +using ComputersShopBusinessLogic.BusinessLogics; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; +using ComputersShopDataModels.Models; + +namespace ComputersShopView +{ + public partial class FormSupply : Form + { + private readonly List? _ComputerList; + private readonly List? _shopsList; + IShopLogic _shopLogic; + IComputerLogic _ComputerLogic; + public int ShopId + { + get + { + return Convert.ToInt32(comboBoxShop.SelectedValue); + } + set + { + comboBoxShop.SelectedValue = value; + } + } + public int ComputerId + { + get + { + return + Convert.ToInt32(comboBoxComputer.SelectedValue); + } + set + { + comboBoxComputer.SelectedValue = value; + } + } + + public IComputerModel? ComputerModel + { + get + { + if (_ComputerList == null) + { + return null; + } + foreach (var elem in _ComputerList) + { + if (elem.Id == ComputerId) + { + return elem; + } + } + return null; + } + } + + + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set + { textBoxCount.Text = value.ToString(); } + } + public FormSupply(IComputerLogic ComputerLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _ComputerLogic = ComputerLogic; + _ComputerList = ComputerLogic.ReadList(null); + _shopsList = shopLogic.ReadList(null); + if (_ComputerList != null) + { + comboBoxComputer.DisplayMember = "ComputerName"; + comboBoxComputer.ValueMember = "Id"; + comboBoxComputer.DataSource = _ComputerList; + comboBoxComputer.SelectedItem = null; + } + if (_shopsList != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _shopsList; + comboBoxShop.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComputer.SelectedValue == null) + { + MessageBox.Show("Выберите компьютер", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + int count = Convert.ToInt32(textBoxCount.Text); + + bool res = _shopLogic.MakeSupply( + new ShopSearchModel() { Id = Convert.ToInt32(comboBoxShop.SelectedValue) }, + _ComputerLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxComputer.SelectedValue) }), + count + ); + + if (!res) + { + throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); + } + + MessageBox.Show("Пополнение прошло успешно"); + DialogResult = DialogResult.OK; + Close(); + + } + catch (Exception err) + { + MessageBox.Show("Ошибка пополнения"); + return; + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/ComputersShop/ComputersShopView/FormSupply.resx b/ComputersShop/ComputersShopView/FormSupply.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShopView/FormSupply.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/ComputersShop/ComputersShopView/Program.cs b/ComputersShop/ComputersShopView/Program.cs index 6e41552..53aab15 100644 --- a/ComputersShop/ComputersShopView/Program.cs +++ b/ComputersShop/ComputersShopView/Program.cs @@ -1,5 +1,5 @@ using ComputersShopBusinessLogic.BusinessLogics; -using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.BusinessLogicsContracts; using ComputersShopContracts.StoragesContracts; using ComputersShopListImplement.Implements; using Microsoft.Extensions.DependencyInjection; @@ -14,7 +14,7 @@ namespace ComputersShopView 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() @@ -37,11 +37,11 @@ namespace ComputersShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); - + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -49,6 +49,10 @@ namespace ComputersShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } + } } \ No newline at end of file -- 2.25.1 From b6dc101d9c397592f2566f539d0ae722ef3e37b9 Mon Sep 17 00:00:00 2001 From: bulatova_karina Date: Mon, 8 Apr 2024 21:11:09 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D0=B8=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20(=D0=BD=D0=B5=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B8=D1=82=20=D1=86=D0=B5=D0=BD?= =?UTF-8?q?=D1=83=20=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D1=83)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ShopLogic.cs | 125 ++++++------- .../BindingModels/ShopBindingModel.cs | 12 +- .../BusinessLogicsContracts/IShopLogic.cs | 3 +- .../SearchModels/ShopSearchModel.cs | 2 +- .../ViewModels/ShopViewModel.cs | 12 +- .../Models/IShopModel.cs | 2 +- .../DataListSingleton.cs | 1 + .../Implements/ShopStorage.cs | 14 +- .../ComputersShopListImplement/Models/Shop.cs | 29 +-- .../ComputersShopView/FormShop.Designer.cs | 47 ++--- ComputersShop/ComputersShopView/FormShop.cs | 52 +++--- ComputersShop/ComputersShopView/FormShops.cs | 5 +- .../ComputersShopView/FormSupply.Designer.cs | 23 +-- ComputersShop/ComputersShopView/FormSupply.cs | 165 ++++++++---------- ComputersShop/ComputersShopView/Program.cs | 24 ++- 15 files changed, 255 insertions(+), 261 deletions(-) diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs index c6ee924..47bbef5 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -8,7 +8,6 @@ using ComputersShopContracts.BusinessLogicsContracts; using ComputersShopContracts.SearchModels; using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.ViewModels; -using ComputersShopDataModels; using ComputersShopDataModels.Models; using Microsoft.Extensions.Logging; @@ -18,91 +17,48 @@ namespace ComputersShopBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IShopStorage _shopStorage; - public ShopLogic(ILogger logger, IShopStorage shopStorage) { _logger = logger; _shopStorage = shopStorage; } - - public List ReadList(ShopSearchModel model) + public List? ReadList(ShopSearchModel? model) { - _logger.LogInformation("ReadList. ShopName:{Name}. Id:{ Id}", model?.Name, model?.Id); + _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); return null; } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; - } - - public bool MakeSupply(ShopSearchModel model, IComputerModel Computer, int count) - { - _logger.LogInformation("Try to supply shop. ShopName:{ShopName}. Id:{Id}", model.Name, model.Id); - if (model == null) - { - _logger.LogWarning("Read operation failed"); - throw new ArgumentNullException(nameof(model)); - } - if (Computer == null) - { - _logger.LogWarning("Read operation failed"); - throw new ArgumentNullException(nameof(Computer)); - } - if (count <= 0) - { - _logger.LogWarning("Read operation failed"); - throw new ArgumentNullException("Количество должно быть положительным числом"); - } - ShopViewModel curModel = ReadElement(model); - if (curModel == null) - { - _logger.LogWarning("Read operation failed"); - throw new ArgumentNullException(nameof(curModel)); - } - if (curModel.ShopComputers.TryGetValue(Computer.Id, out var pair)) - { - curModel.ShopComputers[Computer.Id] = (pair.Item1, pair.Item2 + count); - } - else - { - curModel.ShopComputers.Add(Computer.Id, (Computer, count)); - } - Update(new() - { - Id = curModel.Id, - ShopName = curModel.ShopName, - DateOpen = curModel.DateOpen, - Address = curModel.Address, - ShopComputers = curModel.ShopComputers, - }); - _logger.LogInformation("Success. ComputerName:{ComputerName}. Id:{Id}. Supply:{count}", Computer.ComputerName, Computer.Id, count); - return true; - } - - public ShopViewModel ReadElement(ShopSearchModel model) + public ShopViewModel? ReadElement(ShopSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id); + + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); return null; } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } - public bool Create(ShopBindingModel model) { CheckModel(model); + if (_shopStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -110,10 +66,10 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } - public bool Update(ShopBindingModel model) { CheckModel(model); + if (_shopStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); @@ -125,6 +81,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics { CheckModel(model, false); _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shopStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); @@ -132,7 +89,46 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } + public bool AddComputerInShop(ShopSearchModel model, IComputerModel computer, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (count <= 0) + { + throw new ArgumentException("Кол-во изделий должно быть больше 0", nameof(count)); + } + _logger.LogInformation("AddComputerInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("AddComputerInShop element not found"); + return false; + } + _logger.LogInformation("AddComputerInShop find. Id:{Id}", element.Id); + if (element.ShopComputers.TryGetValue(computer.Id, out var pair)) + { + element.ShopComputers[computer.Id] = (computer, count + pair.Item2); + _logger.LogInformation("AddComputerInShop. Added {count} {computer} to '{ShopName}' shop", count, computer.ComputerName, element.ShopName); + } + else + { + element.ShopComputers[computer.Id] = (computer, count); + _logger.LogInformation("AddComputerInShop. Added {count} new computer {computer} to '{ShopName}' shop", count, computer.ComputerName, element.ShopName); + } + + _shopStorage.Update(new() + { + Id = element.Id, + Address = element.Address, + ShopName = element.ShopName, + DateOpening = element.DateOpening, + ShopComputers = element.ShopComputers + }); + return true; + } private void CheckModel(ShopBindingModel model, bool withParams = true) { if (model == null) @@ -145,25 +141,14 @@ namespace ComputersShopBusinessLogic.BusinessLogics } if (string.IsNullOrEmpty(model.ShopName)) { - throw new ArgumentNullException("Нет названия магазина", - nameof(model.ShopName)); + throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName)); } - if (string.IsNullOrEmpty(model.Address)) - { - throw new ArgumentNullException("Нет адресса магазина", - nameof(model.Address)); - } - if (model.DateOpen == null) - { - throw new ArgumentNullException("Нет даты открытия магазина", - nameof(model.DateOpen)); - } - _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}", model.ShopName, model.Address, model.DateOpen, model.Id); + _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{ Address}. Id:{ Id}", model.ShopName, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel { - Name = model.ShopName + ShopName = model.ShopName }); - if (element != null && element.Id != model.Id) + if (element != null && element.Id != model.Id && element.ShopName == model.ShopName) { throw new InvalidOperationException("Магазин с таким названием уже есть"); } diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs index cbb3518..a284603 100644 --- a/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs +++ b/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs @@ -11,9 +11,13 @@ namespace ComputersShopContracts.BindingModels public class ShopBindingModel : IShopModel { public int Id { get; set; } - public string ShopName { get; set; } - public string Address { get; set; } - public DateTime DateOpen { get; set; } - public Dictionary ShopComputers { get; set; } = new(); + public string ShopName { get; set; } = string.Empty; + public string Address { get; set; } = string.Empty; + public DateTime DateOpening { get; set; } = DateTime.Now; + public Dictionary ShopComputers + { + get; + set; + } = new(); } } diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IShopLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IShopLogic.cs index 85bc165..d17e847 100644 --- a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IShopLogic.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; using ComputersShopContracts.ViewModels; -using ComputersShopDataModels; using ComputersShopDataModels.Models; namespace ComputersShopContracts.BusinessLogicsContracts @@ -18,6 +17,6 @@ namespace ComputersShopContracts.BusinessLogicsContracts bool Create(ShopBindingModel model); bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); - bool MakeSupply(ShopSearchModel model, IComputerModel computer, int count); + bool AddComputerInShop(ShopSearchModel model, IComputerModel computer, int count); } } diff --git a/ComputersShop/ComputersShopContracts/SearchModels/ShopSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/ShopSearchModel.cs index 228bd84..1c39237 100644 --- a/ComputersShop/ComputersShopContracts/SearchModels/ShopSearchModel.cs +++ b/ComputersShop/ComputersShopContracts/SearchModels/ShopSearchModel.cs @@ -9,6 +9,6 @@ namespace ComputersShopContracts.SearchModels public class ShopSearchModel { public int? Id { get; set; } - public string? Name { get; set; } + public string? ShopName { get; set; } } } diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs index cf398a8..0dfb1e6 100644 --- a/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs +++ b/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs @@ -13,11 +13,15 @@ namespace ComputersShopContracts.ViewModels { public int Id { get; set; } [DisplayName("Название магазина")] - public string ShopName { get; set; } + public string ShopName { get; set; } = string.Empty; [DisplayName("Адрес магазина")] - public string Address { get; set; } + public string Address { get; set; } = string.Empty; [DisplayName("Дата открытия")] - public DateTime DateOpen { get; set; } - public Dictionary ShopComputers { get; set; } = new(); + public DateTime DateOpening { get; set; } = DateTime.Now; + public Dictionary ShopComputers + { + get; + set; + } = new(); } } diff --git a/ComputersShop/ComputersShopDataModels/Models/IShopModel.cs b/ComputersShop/ComputersShopDataModels/Models/IShopModel.cs index ab57ac3..a76615d 100644 --- a/ComputersShop/ComputersShopDataModels/Models/IShopModel.cs +++ b/ComputersShop/ComputersShopDataModels/Models/IShopModel.cs @@ -10,7 +10,7 @@ namespace ComputersShopDataModels.Models { string ShopName { get; } string Address { get; } - DateTime DateOpen { get; } + DateTime DateOpening { get; } Dictionary ShopComputers { get; } } } diff --git a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs index e413d1f..834470f 100644 --- a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs +++ b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; using System.Text; using System.Threading.Tasks; using ComputersShopListImplement.Models; diff --git a/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs index 93ed65f..272a04c 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs @@ -32,13 +32,14 @@ namespace ComputersShopListImplement.Implements public List GetFilteredList(ShopSearchModel model) { var result = new List(); - if (string.IsNullOrEmpty(model.Name)) + if (string.IsNullOrEmpty(model.ShopName)) { return result; } + foreach (var shop in _source.Shops) { - if (shop.ShopName.Contains(model.Name)) + if (shop.ShopName.Contains(model.ShopName)) { result.Add(shop.GetViewModel); } @@ -47,15 +48,14 @@ namespace ComputersShopListImplement.Implements } public ShopViewModel? GetElement(ShopSearchModel model) { - if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) { return null; } + foreach (var shop in _source.Shops) { - if ((!string.IsNullOrEmpty(model.Name) && - shop.ShopName == model.Name) || - (model.Id.HasValue && shop.Id == model.Id)) + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (model.Id.HasValue && shop.Id == model.Id)) { return shop.GetViewModel; } @@ -72,11 +72,13 @@ namespace ComputersShopListImplement.Implements model.Id = shop.Id + 1; } } + var newShop = Shop.Create(model); if (newShop == null) { return null; } + _source.Shops.Add(newShop); return newShop.GetViewModel; } diff --git a/ComputersShop/ComputersShopListImplement/Models/Shop.cs b/ComputersShop/ComputersShopListImplement/Models/Shop.cs index 7aa9430..7263885 100644 --- a/ComputersShop/ComputersShopListImplement/Models/Shop.cs +++ b/ComputersShop/ComputersShopListImplement/Models/Shop.cs @@ -13,43 +13,48 @@ namespace ComputersShopListImplement.Models public class Shop : IShopModel { public int Id { get; private set; } - public string ShopName { get; private set; } - public string Address { get; private set; } - public DateTime DateOpen { get; private set; } - public Dictionary ShopComputers { get; private set; } = new(); - - public static Shop? Create(ShopBindingModel model) + public string ShopName { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public DateTime DateOpening { get; private set; } + public Dictionary ShopComputers + { + get; + private set; + } = new Dictionary(); + public static Shop? Create(ShopBindingModel? model) { if (model == null) + { return null; + } + return new Shop() { Id = model.Id, ShopName = model.ShopName, Address = model.Address, - DateOpen = model.DateOpen, - ShopComputers = new() + DateOpening = model.DateOpening, + ShopComputers = model.ShopComputers }; } - public void Update(ShopBindingModel? model) { if (model == null) { return; } + ShopName = model.ShopName; Address = model.Address; - DateOpen = model.DateOpen; + DateOpening = model.DateOpening; ShopComputers = model.ShopComputers; } - public ShopViewModel GetViewModel => new() { Id = Id, ShopName = ShopName, Address = Address, - DateOpen = DateOpen, + DateOpening = DateOpening, ShopComputers = ShopComputers }; } diff --git a/ComputersShop/ComputersShopView/FormShop.Designer.cs b/ComputersShop/ComputersShopView/FormShop.Designer.cs index 26688e2..90d9bcd 100644 --- a/ComputersShop/ComputersShopView/FormShop.Designer.cs +++ b/ComputersShop/ComputersShopView/FormShop.Designer.cs @@ -32,16 +32,16 @@ this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); - this.textBoxAdress = new System.Windows.Forms.TextBox(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); this.textBoxName = new System.Windows.Forms.TextBox(); - this.dataGridView = new System.Windows.Forms.DataGridView(); + this.dataGridViewShop = new System.Windows.Forms.DataGridView(); this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ComputerName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewShop)).BeginInit(); this.SuspendLayout(); // // label1 @@ -78,13 +78,13 @@ this.dateTimePicker.Size = new System.Drawing.Size(403, 27); this.dateTimePicker.TabIndex = 3; // - // textBoxAdress + // textBoxAddress // - this.textBoxAdress.Location = new System.Drawing.Point(104, 61); - this.textBoxAdress.Name = "textBoxAdress"; - this.textBoxAdress.Size = new System.Drawing.Size(403, 27); - this.textBoxAdress.TabIndex = 4; - this.textBoxAdress.TextChanged += new System.EventHandler(this.FormShop_Load); + this.textBoxAddress.Location = new System.Drawing.Point(104, 61); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(403, 27); + this.textBoxAddress.TabIndex = 4; + this.textBoxAddress.TextChanged += new System.EventHandler(this.FormShop_Load); // // textBoxName // @@ -93,20 +93,20 @@ this.textBoxName.Size = new System.Drawing.Size(403, 27); this.textBoxName.TabIndex = 5; // - // dataGridView + // dataGridViewShop // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.dataGridViewShop.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridViewShop.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.id, this.ComputerName, this.Price, this.Count}); - this.dataGridView.Location = new System.Drawing.Point(23, 156); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 51; - this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(507, 173); - this.dataGridView.TabIndex = 6; + this.dataGridViewShop.Location = new System.Drawing.Point(23, 156); + this.dataGridViewShop.Name = "dataGridViewShop"; + this.dataGridViewShop.RowHeadersWidth = 51; + this.dataGridViewShop.RowTemplate.Height = 29; + this.dataGridViewShop.Size = new System.Drawing.Size(507, 173); + this.dataGridViewShop.TabIndex = 6; // // id // @@ -164,16 +164,17 @@ this.ClientSize = new System.Drawing.Size(546, 395); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonSave); - this.Controls.Add(this.dataGridView); + this.Controls.Add(this.dataGridViewShop); this.Controls.Add(this.textBoxName); - this.Controls.Add(this.textBoxAdress); + this.Controls.Add(this.textBoxAddress); this.Controls.Add(this.dateTimePicker); this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Name = "FormShop"; this.Text = "Магазин"; - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewShop)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -185,9 +186,9 @@ private Label label2; private Label label3; private DateTimePicker dateTimePicker; - private TextBox textBoxAdress; + private TextBox textBoxAddress; private TextBox textBoxName; - private DataGridView dataGridView; + private DataGridView dataGridViewShop; private DataGridViewTextBoxColumn id; private DataGridViewTextBoxColumn ComputerName; private DataGridViewTextBoxColumn Price; diff --git a/ComputersShop/ComputersShopView/FormShop.cs b/ComputersShop/ComputersShopView/FormShop.cs index 6b9788c..1cec395 100644 --- a/ComputersShop/ComputersShopView/FormShop.cs +++ b/ComputersShop/ComputersShopView/FormShop.cs @@ -10,7 +10,6 @@ using System.Windows.Forms; using ComputersShopContracts.BindingModels; using ComputersShopContracts.BusinessLogicsContracts; using ComputersShopContracts.SearchModels; -using ComputersShopDataModels; using ComputersShopDataModels.Models; using Microsoft.Extensions.Logging; @@ -20,13 +19,16 @@ namespace ComputersShopView { private readonly ILogger _logger; private readonly IShopLogic _logic; - public int? _id; - private Dictionary _Computers; + private int? _id; + public int Id { set { _id = value; } } + private Dictionary _shopComputers; public FormShop(ILogger logger, IShopLogic logic) { InitializeComponent(); _logger = logger; _logic = logic; + _shopComputers = new Dictionary(); + } private void FormShop_Load(object sender, EventArgs e) { @@ -35,43 +37,47 @@ namespace ComputersShopView _logger.LogInformation("Загрузка магазина"); try { - var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); - if (shop != null) + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + if (view != null) { - textBoxName.Text = shop.ShopName; - textBoxAdress.Text = shop.Address; - dateTimePicker.Text = shop.DateOpen.ToString(); - _Computers = shop.ShopComputers; + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Text = view.DateOpening.ToString(); + _shopComputers = view.ShopComputers ?? new Dictionary(); + LoadData(); } - LoadData(); } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void LoadData() { - _logger.LogInformation("Загрузка товаров магазина"); + _logger.LogInformation("Загрузка изделий магазина"); try { - if (_Computers != null) + if (_shopComputers != null) { - foreach (var Computer in _Computers) + dataGridViewShop.Rows.Clear(); + foreach (var elem in _shopComputers) { - dataGridView.Rows.Add(new object[] { Computer.Key, Computer.Value.Item1.ComputerName, Computer.Value.Item1.Price, Computer.Value.Item2 }); + dataGridViewShop.Rows.Add(new object[] + { + elem.Key, + elem.Value.Item1.ComputerName, + elem.Value.Item2 + }); } } } 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); } } @@ -88,7 +94,7 @@ namespace ComputersShopView MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (string.IsNullOrEmpty(textBoxAdress.Text)) + if (string.IsNullOrEmpty(textBoxAddress.Text)) { MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -100,9 +106,9 @@ namespace ComputersShopView { Id = _id ?? 0, ShopName = textBoxName.Text, - Address = textBoxAdress.Text, - DateOpen = dateTimePicker.Value.Date, - ShopComputers = _Computers + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value.Date, + ShopComputers = _shopComputers }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) diff --git a/ComputersShop/ComputersShopView/FormShops.cs b/ComputersShop/ComputersShopView/FormShops.cs index a84cfb8..e508fef 100644 --- a/ComputersShop/ComputersShopView/FormShops.cs +++ b/ComputersShop/ComputersShopView/FormShops.cs @@ -33,8 +33,6 @@ namespace ComputersShopView dataGridViewShops.DataSource = list; dataGridViewShops.Columns["Id"].Visible = false; dataGridViewShops.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridViewShops.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridViewShops.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridViewShops.Columns["ShopComputers"].Visible = false; } _logger.LogInformation("Загрузка магазинов"); @@ -70,8 +68,7 @@ namespace ComputersShopView var service = Program.ServiceProvider?.GetService(typeof(FormShop)); if (service is FormShop form) { - var tmp = Convert.ToInt32(dataGridViewShops.SelectedRows[0].Cells["Id"].Value); - form._id = Convert.ToInt32(dataGridViewShops.SelectedRows[0].Cells["Id"].Value); + form.Id = Convert.ToInt32(dataGridViewShops.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) { LoadData(); diff --git a/ComputersShop/ComputersShopView/FormSupply.Designer.cs b/ComputersShop/ComputersShopView/FormSupply.Designer.cs index 238a7ad..220fd24 100644 --- a/ComputersShop/ComputersShopView/FormSupply.Designer.cs +++ b/ComputersShop/ComputersShopView/FormSupply.Designer.cs @@ -31,11 +31,12 @@ this.labelShop = new System.Windows.Forms.Label(); this.labelComputer = new System.Windows.Forms.Label(); this.labelCount = new System.Windows.Forms.Label(); - this.textBoxCount = new System.Windows.Forms.TextBox(); this.comboBoxComputer = new System.Windows.Forms.ComboBox(); this.comboBoxShop = new System.Windows.Forms.ComboBox(); this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); + this.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); this.SuspendLayout(); // // labelShop @@ -65,13 +66,6 @@ this.labelCount.TabIndex = 2; this.labelCount.Text = "Количество:"; // - // textBoxCount - // - this.textBoxCount.Location = new System.Drawing.Point(142, 139); - this.textBoxCount.Name = "textBoxCount"; - this.textBoxCount.Size = new System.Drawing.Size(349, 27); - this.textBoxCount.TabIndex = 3; - // // comboBoxComputer // this.comboBoxComputer.FormattingEnabled = true; @@ -108,21 +102,30 @@ this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // + // numericUpDownCount + // + this.numericUpDownCount.Location = new System.Drawing.Point(142, 139); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.Size = new System.Drawing.Size(348, 27); + this.numericUpDownCount.TabIndex = 8; + // // FormSupply // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(552, 227); + this.Controls.Add(this.numericUpDownCount); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonSave); this.Controls.Add(this.comboBoxShop); this.Controls.Add(this.comboBoxComputer); - this.Controls.Add(this.textBoxCount); this.Controls.Add(this.labelCount); this.Controls.Add(this.labelComputer); this.Controls.Add(this.labelShop); this.Name = "FormSupply"; this.Text = "Поставки"; + this.Load += new System.EventHandler(this.FormSupply_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -133,10 +136,10 @@ private Label labelShop; private Label labelComputer; private Label labelCount; - private TextBox textBoxCount; private ComboBox comboBoxComputer; private ComboBox comboBoxShop; private Button buttonSave; private Button buttonCancel; + private NumericUpDown numericUpDownCount; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormSupply.cs b/ComputersShop/ComputersShopView/FormSupply.cs index 855b76c..5c58220 100644 --- a/ComputersShop/ComputersShopView/FormSupply.cs +++ b/ComputersShop/ComputersShopView/FormSupply.cs @@ -13,132 +13,105 @@ using ComputersShopContracts.SearchModels; using ComputersShopContracts.ViewModels; using ComputersShopDataModels; using ComputersShopDataModels.Models; +using Microsoft.Extensions.Logging; namespace ComputersShopView { public partial class FormSupply : Form { - private readonly List? _ComputerList; - private readonly List? _shopsList; - IShopLogic _shopLogic; - IComputerLogic _ComputerLogic; - public int ShopId - { - get - { - return Convert.ToInt32(comboBoxShop.SelectedValue); - } - set - { - comboBoxShop.SelectedValue = value; - } - } - public int ComputerId - { - get - { - return - Convert.ToInt32(comboBoxComputer.SelectedValue); - } - set - { - comboBoxComputer.SelectedValue = value; - } - } + private readonly ILogger _logger; + private readonly IShopLogic _logicS; + private readonly IComputerLogic _logicC; - public IComputerModel? ComputerModel - { - get - { - if (_ComputerList == null) - { - return null; - } - foreach (var elem in _ComputerList) - { - if (elem.Id == ComputerId) - { - return elem; - } - } - return null; - } - } - - - public int Count - { - get { return Convert.ToInt32(textBoxCount.Text); } - set - { textBoxCount.Text = value.ToString(); } - } - public FormSupply(IComputerLogic ComputerLogic, IShopLogic shopLogic) + public FormSupply(ILogger logger, IShopLogic logicS, IComputerLogic logicC) { InitializeComponent(); - _shopLogic = shopLogic; - _ComputerLogic = ComputerLogic; - _ComputerList = ComputerLogic.ReadList(null); - _shopsList = shopLogic.ReadList(null); - if (_ComputerList != null) + _logger = logger; + _logicS = logicS; + _logicC = logicC; + } + private void FormSupply_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка магазинов"); + try { - comboBoxComputer.DisplayMember = "ComputerName"; - comboBoxComputer.ValueMember = "Id"; - comboBoxComputer.DataSource = _ComputerList; - comboBoxComputer.SelectedItem = null; + var listShops = _logicS.ReadList(null); + if (listShops != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = listShops; + comboBoxShop.SelectedItem = null; + } + } - if (_shopsList != null) + catch (Exception ex) { - comboBoxShop.DisplayMember = "ShopName"; - comboBoxShop.ValueMember = "Id"; - comboBoxShop.DataSource = _shopsList; - comboBoxShop.SelectedItem = null; + _logger.LogError(ex, "Ошибка загрузки списка магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + _logger.LogInformation("Загрузка изделий"); + try + { + var listComputers = _logicC.ReadList(null); + if (listComputers != null) + { + comboBoxComputer.DisplayMember = "ComputerName"; + comboBoxComputer.ValueMember = "Id"; + comboBoxComputer.DataSource = listComputers; + comboBoxComputer.SelectedItem = null; + } + + } + 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(textBoxCount.Text)) + if (comboBoxShop.SelectedValue == null) { - MessageBox.Show("Заполните поле Количество", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBoxComputer.SelectedValue == null) { - MessageBox.Show("Выберите компьютер", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (comboBoxShop.SelectedValue == null) - { - MessageBox.Show("Выберите магазин", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - + _logger.LogInformation("Добавление изделия в магазин"); try { - int count = Convert.ToInt32(textBoxCount.Text); - - bool res = _shopLogic.MakeSupply( - new ShopSearchModel() { Id = Convert.ToInt32(comboBoxShop.SelectedValue) }, - _ComputerLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxComputer.SelectedValue) }), - count - ); - - if (!res) + var computer = _logicC.ReadElement(new() { - throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); + Id = (int)comboBoxComputer.SelectedValue + }); + if (computer == null) + { + throw new Exception("Не найдено изделие. Дополнительная информация в логах."); } - - MessageBox.Show("Пополнение прошло успешно"); + var resultOperation = _logicS.AddComputerInShop( + new ShopSearchModel + { + Id = (int)comboBoxShop.SelectedValue + }, + computer, + (int)numericUpDownCount.Value + ); + if (!resultOperation) + { + throw new Exception("Ошибка при добавлении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); - } - catch (Exception err) + catch (Exception ex) { - MessageBox.Show("Ошибка пополнения"); - return; + _logger.LogError(ex, "Ошибка добавления поступления"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/ComputersShop/ComputersShopView/Program.cs b/ComputersShop/ComputersShopView/Program.cs index 53aab15..bcdd41f 100644 --- a/ComputersShop/ComputersShopView/Program.cs +++ b/ComputersShop/ComputersShopView/Program.cs @@ -1,7 +1,8 @@ -using ComputersShopBusinessLogic.BusinessLogics; +using ComputersShopBusinessLogic.BusinessLogics; using ComputersShopContracts.BusinessLogicsContracts; using ComputersShopContracts.StoragesContracts; using ComputersShopListImplement.Implements; +using ComputersShopView; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; @@ -11,10 +12,14 @@ namespace ComputersShopView { internal static class Program { + /// + /// IoC-êîíòåéíåð + /// 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() @@ -22,11 +27,18 @@ namespace ComputersShopView // 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()); } + + /// + /// Íàñòðîéêà IoC-êîíòåéíåðà è ëîããåðà + /// + /// private static void ConfigureServices(ServiceCollection services) { services.AddLogging(option => @@ -34,14 +46,17 @@ namespace ComputersShopView 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(); @@ -49,10 +64,9 @@ namespace ComputersShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); } - } } \ No newline at end of file -- 2.25.1 From e12423c8c79689bf87d104546100072b13e4c69d Mon Sep 17 00:00:00 2001 From: bulatova_karina Date: Mon, 8 Apr 2024 22:06:35 +0400 Subject: [PATCH 3/5] full 1 lab hard --- .../ComputersShopView/FormShop.Designer.cs | 66 ++++++++----------- ComputersShop/ComputersShopView/FormShop.resx | 15 ----- 2 files changed, 28 insertions(+), 53 deletions(-) diff --git a/ComputersShop/ComputersShopView/FormShop.Designer.cs b/ComputersShop/ComputersShopView/FormShop.Designer.cs index 90d9bcd..a1c7aa7 100644 --- a/ComputersShop/ComputersShopView/FormShop.Designer.cs +++ b/ComputersShop/ComputersShopView/FormShop.Designer.cs @@ -35,12 +35,11 @@ this.textBoxAddress = new System.Windows.Forms.TextBox(); this.textBoxName = new System.Windows.Forms.TextBox(); this.dataGridViewShop = new System.Windows.Forms.DataGridView(); - this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ComputerName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); + this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ComputerName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewShop)).BeginInit(); this.SuspendLayout(); // @@ -99,7 +98,6 @@ this.dataGridViewShop.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.id, this.ComputerName, - this.Price, this.Count}); this.dataGridViewShop.Location = new System.Drawing.Point(23, 156); this.dataGridViewShop.Name = "dataGridViewShop"; @@ -108,35 +106,6 @@ this.dataGridViewShop.Size = new System.Drawing.Size(507, 173); this.dataGridViewShop.TabIndex = 6; // - // id - // - this.id.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.id.HeaderText = "Id"; - this.id.MinimumWidth = 6; - this.id.Name = "id"; - this.id.Visible = false; - // - // ComputerName - // - this.ComputerName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.ComputerName.HeaderText = "Название"; - this.ComputerName.MinimumWidth = 6; - this.ComputerName.Name = "ComputerName"; - // - // Price - // - this.Price.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.Price.HeaderText = "Цена"; - this.Price.MinimumWidth = 6; - this.Price.Name = "Price"; - // - // Count - // - this.Count.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.Count.HeaderText = "Количество"; - this.Count.MinimumWidth = 6; - this.Count.Name = "Count"; - // // buttonSave // this.buttonSave.Location = new System.Drawing.Point(319, 354); @@ -157,6 +126,28 @@ this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // + // id + // + this.id.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.id.HeaderText = "Id"; + this.id.MinimumWidth = 6; + this.id.Name = "id"; + this.id.Visible = false; + // + // ComputerName + // + this.ComputerName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ComputerName.HeaderText = "Название"; + this.ComputerName.MinimumWidth = 6; + this.ComputerName.Name = "ComputerName"; + // + // Count + // + this.Count.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -189,11 +180,10 @@ private TextBox textBoxAddress; private TextBox textBoxName; private DataGridView dataGridViewShop; - private DataGridViewTextBoxColumn id; - private DataGridViewTextBoxColumn ComputerName; - private DataGridViewTextBoxColumn Price; - private DataGridViewTextBoxColumn Count; private Button buttonSave; private Button buttonCancel; + private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn ComputerName; + private DataGridViewTextBoxColumn Count; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormShop.resx b/ComputersShop/ComputersShopView/FormShop.resx index 14c1c77..e510a0c 100644 --- a/ComputersShop/ComputersShopView/FormShop.resx +++ b/ComputersShop/ComputersShopView/FormShop.resx @@ -63,21 +63,6 @@ True - - True - - - True - - - True - - - True - - - True - True -- 2.25.1 From 5ac66dc71be0dde9865927d98531bec21d74e47d Mon Sep 17 00:00:00 2001 From: bulatova_karina Date: Sun, 5 May 2024 16:09:41 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=BD=D0=B8=D1=87=D0=B5=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D1=8F=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20:(?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ComputerLogic.cs | 67 ++++- .../BusinessLogics/OrderLogic.cs | 257 ++++++++++++++---- .../BusinessLogics/ShopLogic.cs | 99 ++++++- .../BindingModels/ShopBindingModel.cs | 1 + .../BusinessLogicsContracts/IShopLogic.cs | 1 + .../StoragesContracts/IOrderStorage.cs | 32 ++- .../StoragesContracts/IShopStorage.cs | 3 + .../ViewModels/ShopViewModel.cs | 2 + .../Models/IShopModel.cs | 1 + .../DataFileSingleton.cs | 124 +++++++-- .../Implements/OrderStorage.cs | 111 ++++++-- .../Implements/ShopStorage.cs | 193 +++++++++++++ .../ComputersShopFileImplement/Models/Shop.cs | 155 +++++++++++ .../DataListSingleton.cs | 25 ++ .../Implements/OrderStorage.cs | 68 +++-- .../Implements/ShopStorage.cs | 64 +++++ .../ComputersShopListImplement/Models/Shop.cs | 43 ++- .../ComputersShopView/FormMain.Designer.cs | 11 +- ComputersShop/ComputersShopView/FormMain.cs | 9 + .../ComputersShopView/FormSell.Designer.cs | 120 ++++++++ ComputersShop/ComputersShopView/FormSell.cs | 107 ++++++++ ComputersShop/ComputersShopView/FormSell.resx | 60 ++++ .../ComputersShopView/FormShop.Designer.cs | 82 ++++-- ComputersShop/ComputersShopView/FormShop.cs | 4 +- .../ComputersShopView/FormSupply.Designer.cs | 5 + ComputersShop/ComputersShopView/FormSupply.cs | 1 + ComputersShop/ComputersShopView/Program.cs | 1 + 27 files changed, 1489 insertions(+), 157 deletions(-) create mode 100644 ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs create mode 100644 ComputersShop/ComputersShopFileImplement/Models/Shop.cs create mode 100644 ComputersShop/ComputersShopView/FormSell.Designer.cs create mode 100644 ComputersShop/ComputersShopView/FormSell.cs create mode 100644 ComputersShop/ComputersShopView/FormSell.resx diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs index 75d2a93..3c77dda 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs @@ -15,43 +15,78 @@ namespace ComputersShopBusinessLogic.BusinessLogics public class ComputerLogic : IComputerLogic { private readonly ILogger _logger; + + /// + /// Взаимодействие с хранилищем изделий + /// private readonly IComputerStorage _computerStorage; + + /// + /// Конструктор + /// + /// + /// public ComputerLogic(ILogger logger, IComputerStorage computerStorage) { _logger = logger; _computerStorage = computerStorage; } + + /// + /// Получение списка + /// + /// + /// public List? ReadList(ComputerSearchModel? model) { - _logger.LogInformation("ReadList. ComputerName:{ComputerName}. Id:{Id}", model?.ComputerName, model?.Id); + _logger.LogInformation("ReadList. ComputerName:{ComputerName}.Id:{ Id}", model?.ComputerName, model?.Id); + var list = model == null ? _computerStorage.GetFullList() : _computerStorage.GetFiltredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); return null; } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } + + /// + /// Получение отдельной записи + /// + /// + /// + /// public ComputerViewModel? ReadElement(ComputerSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. ComputerName:{ComputerName}. Id:{Id}", model.ComputerName, model.Id); + + _logger.LogInformation("ReadElement. ComputerName:{ComputerName}.Id:{ Id}", model.ComputerName, model.Id); + var element = _computerStorage.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(ComputerBindingModel model) { CheckModel(model); + if (_computerStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -59,9 +94,16 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } + + /// + /// Изменение записи + /// + /// + /// public bool Update(ComputerBindingModel model) { CheckModel(model); + if (_computerStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); @@ -69,10 +111,17 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } + + /// + /// Удаление записи + /// + /// + /// public bool Delete(ComputerBindingModel model) { CheckModel(model, false); _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_computerStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); @@ -80,6 +129,12 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } + + /// + /// Проверка модели изделия + /// + /// + /// private void CheckModel(ComputerBindingModel model, bool withParams = true) { if (model == null) @@ -92,20 +147,20 @@ namespace ComputersShopBusinessLogic.BusinessLogics } if (string.IsNullOrEmpty(model.ComputerName)) { - throw new ArgumentNullException("Нет названия компьютера", nameof(model.ComputerName)); + throw new ArgumentNullException("Нет названия изделия", nameof(model.ComputerName)); } if (model.Price <= 0) { - throw new ArgumentNullException("Цена должна быть больше 0", nameof(model.Price)); + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); } - _logger.LogInformation("Computer. ComputerName:{ComputerName}. Cost:{Cost}. Id:{Id}", model.ComputerName, model.Price, model.Id); + _logger.LogInformation("Computer. ComputerName:{ComputerName}.Price:{ Price}. Id: { Id}", model.ComputerName, model.Price, model.Id); var element = _computerStorage.GetElement(new ComputerSearchModel { ComputerName = model.ComputerName }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Компьютер с таким названием уже есть"); + throw new InvalidOperationException("Изделие с таким названием уже есть"); } } } diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs index b21f70a..37e534f 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -9,6 +9,7 @@ using ComputersShopContracts.SearchModels; using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.ViewModels; using ComputersShopDataModels.Enums; +using ComputersShopDataModels.Models; using Microsoft.Extensions.Logging; namespace ComputersShopBusinessLogic.BusinessLogics @@ -16,33 +17,77 @@ namespace ComputersShopBusinessLogic.BusinessLogics public class OrderLogic : IOrderLogic { private readonly ILogger _logger; + + /// + /// Взаимодействие с хранилищем заказов + /// private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + + /// + /// Взаимодействие с хранилищем магазинов + /// + private IShopStorage _shopStorage; + + /// + /// Бизнес-логика магазинов + /// + private IShopLogic _shopLogic; + + /// + /// Взаимодействие с хранилищем изделий + /// + private IComputerStorage _computerStorage; + + /// + /// Конструктор + /// + /// + /// + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IComputerStorage computerStorage) { _logger = logger; _orderStorage = orderStorage; + _shopStorage = shopStorage; + _shopLogic = shopLogic; + _computerStorage = computerStorage; } + + /// + /// Получение списка + /// + /// + /// public List? ReadList(OrderSearchModel? model) { - _logger.LogInformation("ReadList. Id:{Id}", model?.Id); - var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFiltredList(model); + _logger.LogInformation("ReadList. Order.Id:{ 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 CreateOrder(OrderBindingModel model) { CheckModel(model); if (model.Status != OrderStatus.Неизвестен) { - _logger.LogWarning("Wrong order status. Insert operation failed"); + _logger.LogWarning("Insert operation failed. Order status incorrect."); return false; } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -50,52 +95,42 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } - public bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus) - { - var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - if (viewModel == null) - { - throw new ArgumentNullException(nameof(viewModel)); - } - if (viewModel.Status + 1 != newStatus) - { - _logger.LogWarning("Status change operation failed"); - return false; - } - model.Status = newStatus; - model.ComputerId = viewModel.ComputerId; - model.Count = viewModel.Count; - model.Sum = viewModel.Sum; - model.DateCreate = viewModel.DateCreate; - if (model.Status == OrderStatus.Готов) - { - model.DateImplement = DateTime.Now; - } - else - { - model.DateImplement = viewModel.DateImplement; - } - CheckModel(model, false); - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Status change operation failed"); - return false; - } - return true; - } + /// + /// Смена статуса заказа (Выполняется) + /// + /// + /// public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); + return StatusUpdate(model, OrderStatus.Выполняется); } + + /// + /// Смена статуса заказа (Выдан) + /// + /// + /// public bool FinishOrder(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Готов); + return StatusUpdate(model, OrderStatus.Выдан); } + + /// + /// Смена статуса заказа (Готов) + /// + /// + /// public bool DeliveryOrder(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выдан); + return StatusUpdate(model, OrderStatus.Готов); } + + /// + /// Проверка модели заказа + /// + /// + /// private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) @@ -106,19 +141,149 @@ namespace ComputersShopBusinessLogic.BusinessLogics { return; } - if (model.Sum <= 0) + if (model.ComputerId < 0) { - throw new ArgumentNullException("Цена должна быть больше 0", nameof(model.Sum)); + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.ComputerId)); } if (model.Count <= 0) { - throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); + throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); } - if (model.DateImplement != null && model.DateImplement < model.DateCreate) + if (model.Sum <= 0) { - throw new ArithmeticException("Дата завершения не может быть раньше даты начала"); + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); } - _logger.LogInformation("Order. Id:{Id}. Sum:{Sum}. ComputerId:{ComputerId}", model.Id, model.Sum, model.ComputerId); + _logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. ComputerId: { ComputerId}", model.Id, model.Sum, model.ComputerId); + } + + /// + /// Смена статуса заказа + /// + /// + /// + /// + private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (element.Status + 1 != newStatus) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + + model.Status = newStatus; + + if (newStatus == OrderStatus.Выдан) + { + var computer = _computerStorage.GetElement(new ComputerSearchModel { Id = element.ComputerId }); + if (computer == null) + { + _logger.LogWarning("Status change error. Computer not found"); + return false; + } + if (!CheckSupply(computer, element.Count)) + { + _logger.LogWarning("Status change error. Shop is overflowed"); + return false; + } + } + + if (model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = element.DateImplement; + } + CheckModel(model, false); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + return true; + } + + /// + /// Проверка заказа + /// + /// + /// + /// + public bool CheckSupply(IComputerModel model, int count) + { + if (count <= 0) + { + _logger.LogWarning("Check supply operation error. Computers count < 0"); + return false; + } + + int sumCapacity = _shopStorage.GetFullList().Select(x => x.MaxComputers).Sum(); + int sumCount = _shopStorage.GetFullList().Select(x => x.ShopComputers.Select(y => y.Value.Item2).Sum()).Sum(); + int free = sumCapacity - sumCount; + if (free < count) + { + _logger.LogWarning("Check supply error. No place for new computers"); + return false; + } + + foreach (var shop in _shopStorage.GetFullList()) + { + free = shop.MaxComputers; + foreach (var computer in shop.ShopComputers) + { + free -= computer.Value.Item2; + } + + if (free == 0) + { + continue; + } + + if (free >= count) + { + if (_shopLogic.AddComputerInShop(new() + { + Id = shop.Id + }, model, count)) + { + count = 0; + } + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + else + { + if (_shopLogic.AddComputerInShop(new() + { + Id = shop.Id + }, model, free)) + { + count -= free; + } + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + if (count <= 0) + { + return true; + } + } + return false; } } } diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs index 47bbef5..cf5f308 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -16,12 +16,28 @@ namespace ComputersShopBusinessLogic.BusinessLogics public class ShopLogic : IShopLogic { private readonly ILogger _logger; + + /// + /// Взаимодействие с хранилищем магазинов + /// private readonly IShopStorage _shopStorage; + + /// + /// Конструктор + /// + /// + /// public ShopLogic(ILogger logger, IShopStorage shopStorage) { _logger = logger; _shopStorage = shopStorage; } + + /// + /// Получение списка + /// + /// + /// public List? ReadList(ShopSearchModel? model) { _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); @@ -36,6 +52,13 @@ namespace ComputersShopBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } + + /// + /// Получение отдельной записи + /// + /// + /// + /// public ShopViewModel? ReadElement(ShopSearchModel model) { if (model == null) @@ -55,6 +78,12 @@ namespace ComputersShopBusinessLogic.BusinessLogics _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } + + /// + /// Создание записи + /// + /// + /// public bool Create(ShopBindingModel model) { CheckModel(model); @@ -66,6 +95,12 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } + + /// + /// Изменение записи + /// + /// + /// public bool Update(ShopBindingModel model) { CheckModel(model); @@ -77,6 +112,12 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } + + /// + /// Удаление записи + /// + /// + /// public bool Delete(ShopBindingModel model) { CheckModel(model, false); @@ -89,6 +130,16 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } + + /// + /// Добавление изделия в магазин + /// + /// + /// + /// + /// + /// + /// public bool AddComputerInShop(ShopSearchModel model, IComputerModel computer, int count) { if (model == null) @@ -97,7 +148,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics } if (count <= 0) { - throw new ArgumentException("Кол-во изделий должно быть больше 0", nameof(count)); + throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count)); } _logger.LogInformation("AddComputerInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); var element = _shopStorage.GetElement(model); @@ -108,6 +159,13 @@ namespace ComputersShopBusinessLogic.BusinessLogics } _logger.LogInformation("AddComputerInShop find. Id:{Id}", element.Id); + var countComputers = element.ShopComputers.Select(x => x.Value.Item2).Sum(); + if (element.MaxComputers - countComputers < count) + { + _logger.LogWarning("Shop is overflowed"); + return false; + } + if (element.ShopComputers.TryGetValue(computer.Id, out var pair)) { element.ShopComputers[computer.Id] = (computer, count + pair.Item2); @@ -125,10 +183,47 @@ namespace ComputersShopBusinessLogic.BusinessLogics Address = element.Address, ShopName = element.ShopName, DateOpening = element.DateOpening, - ShopComputers = element.ShopComputers + ShopComputers = element.ShopComputers, + MaxComputers = element.MaxComputers }); return true; } + + /// + /// Продажа изделий + /// + /// + /// + /// + /// + /// + public bool SellComputers(IComputerModel computer, int count) + { + if (computer == null) + { + throw new ArgumentNullException(nameof(computer)); + } + if (count <= 0) + { + throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count)); + } + + if (_shopStorage.SellComputers(computer, count)) + { + _logger.LogInformation("Selling sucsess"); + return true; + } + _logger.LogInformation("Selling failed"); + return false; + } + + /// + /// Проверка модели магазина + /// + /// + /// + /// + /// private void CheckModel(ShopBindingModel model, bool withParams = true) { if (model == null) diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs index a284603..f3ede09 100644 --- a/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs +++ b/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs @@ -19,5 +19,6 @@ namespace ComputersShopContracts.BindingModels get; set; } = new(); + public int MaxComputers { get; set; } } } diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IShopLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IShopLogic.cs index d17e847..e7aeda7 100644 --- a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IShopLogic.cs @@ -18,5 +18,6 @@ namespace ComputersShopContracts.BusinessLogicsContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool AddComputerInShop(ShopSearchModel model, IComputerModel computer, int count); + bool SellComputers(IComputerModel computer, int count); } } diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs index c986423..7b156ec 100644 --- a/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs @@ -12,10 +12,40 @@ namespace ComputersShopContracts.StoragesContracts public interface IOrderStorage { List GetFullList(); - List GetFiltredList(OrderSearchModel model); + + /// + /// Получение фильтрованного списка + /// + /// + /// + List GetFilteredList(OrderSearchModel model); + + /// + /// Получение элемента + /// + /// + /// OrderViewModel? GetElement(OrderSearchModel model); + + /// + /// Добавление элемента + /// + /// + /// OrderViewModel? Insert(OrderBindingModel model); + + /// + /// Редактирование элемента + /// + /// + /// OrderViewModel? Update(OrderBindingModel model); + + /// + /// Удаление элемента + /// + /// + /// OrderViewModel? Delete(OrderBindingModel model); } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs index 9d10aa7..0a27290 100644 --- a/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs @@ -7,6 +7,7 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.SearchModels; using ComputersShopContracts.ViewModels; using ComputersShopDataModels; +using ComputersShopDataModels.Models; namespace ComputersShopContracts.StoragesContracts { @@ -18,5 +19,7 @@ namespace ComputersShopContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool SellComputers(IComputerModel model, int count); + bool CheckCount(IComputerModel model, int count); } } diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs index 0dfb1e6..04150fc 100644 --- a/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs +++ b/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs @@ -23,5 +23,7 @@ namespace ComputersShopContracts.ViewModels get; set; } = new(); + [DisplayName("Максимальное количество изделий")] + public int MaxComputers { get; set; } } } diff --git a/ComputersShop/ComputersShopDataModels/Models/IShopModel.cs b/ComputersShop/ComputersShopDataModels/Models/IShopModel.cs index a76615d..d039166 100644 --- a/ComputersShop/ComputersShopDataModels/Models/IShopModel.cs +++ b/ComputersShop/ComputersShopDataModels/Models/IShopModel.cs @@ -12,5 +12,6 @@ namespace ComputersShopDataModels.Models string Address { get; } DateTime DateOpening { get; } Dictionary ShopComputers { get; } + int MaxComputers { get; } } } diff --git a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs index ad0d7de..72d3979 100644 --- a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs +++ b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs @@ -11,35 +11,101 @@ namespace ComputersShopFileImplement { internal class DataFileSingleton { - private static DataFileSingleton? instance; - public readonly string ComponentFileName = "Component.xml"; - public readonly string OrderFileName = "Order.xml"; - public readonly string ComputerFileName = "Computer.xml"; - public List Components { get; private set; } - public List Orders { get; private set; } - public List Computers { get; private set; } - public static DataFileSingleton GetInstance() - { - if (instance == null) - { - instance = new DataFileSingleton(); - } - return instance; - } - public void SaveComponents() => SaveData(Components, ComponentFileName, - "Components", x => x.GetXElement); - public void SaveComputers() => SaveData(Computers, ComputerFileName, - "Computers", x => x.GetXElement); - public void SaveOrders() => SaveData(Orders, OrderFileName, - "Orders", x => x.GetXElement); + private static DataFileSingleton? _instance; + + /// + /// Название файла для хранения информации о компонентах + /// + private readonly string ComponentFileName = "Component.xml"; + + /// + /// Название файла для хранения информации о заказах + /// + private readonly string OrderFileName = "Order.xml"; + + /// + /// Название файла для хранения информации о изделиях + /// + private readonly string ComputerFileName = "Computer.xml"; + + /// + /// Название файла для хранения информации о магазинах + /// + private readonly string ShopFileName = "Shop.xml"; + + /// + /// Список классов-моделей компонентов + /// + public List Components { get; set; } + + /// + /// Список классов-моделей заказов + /// + public List Orders { get; set; } + + /// + /// Список классов-моделей изделий + /// + public List Computers { get; set; } + + /// + /// Список классов-моделей магазина + /// + public List Shops { get; set; } + + /// + /// Конструктор + /// private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Computers = LoadData(ComputerFileName, "Computer", x => Computer.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } - private static List? LoadData(string filename, string xmlNodeName, - Func selectFunction) + + /// + /// Получить ссылку на класс + /// + /// + public static DataFileSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataFileSingleton(); + } + return _instance; + } + + /// + /// Сохранение компонентов + /// + public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); + + /// + /// Сохранение изделий + /// + public void SaveComputers() => SaveData(Computers, ComputerFileName, "Computers", x => x.GetXElement); + + /// + /// Сохранение заказов + /// + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + + /// + /// Сохранение магазинов + /// + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); + + /// + /// Метод для загрузки данных из xml-файла + /// + /// + /// + /// + /// + /// + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { if (File.Exists(filename)) { @@ -47,8 +113,16 @@ namespace ComputersShopFileImplement } return new List(); } - private static void SaveData(List data, string filename, - string xmlNodeName, Func selectFunction) + + /// + /// Метод для сохранения данных в xml-файл + /// + /// + /// + /// + /// + /// + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) { if (data != null) { diff --git a/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs index 3317c1c..5e187e9 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs @@ -13,70 +13,129 @@ namespace ComputersShopFileImplement.Implements { public class OrderStorage : IOrderStorage { - private readonly DataFileSingleton source; + private readonly DataFileSingleton _source; + + /// + /// Конструктор + /// public OrderStorage() { - source = DataFileSingleton.GetInstance(); + _source = DataFileSingleton.GetInstance(); } + + /// + /// Получение полного списка + /// + /// public List GetFullList() { - return source.Orders.Select(x => GetViewModel(x)).ToList(); + return _source.Orders + .Select(x => GetViewModel(x)) + .ToList(); } - public List GetFiltredList(OrderSearchModel model) + + /// + /// Получение фильтрованного списка + /// + /// + /// + public List GetFilteredList(OrderSearchModel model) { if (!model.Id.HasValue) { return new(); } - return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); + + return _source.Orders + .Where(x => x.Id.Equals(model.Id)) + .Select(x => GetViewModel(x)) + .ToList(); } + + /// + /// Получение элемента + /// + /// + /// public OrderViewModel? GetElement(OrderSearchModel model) { if (!model.Id.HasValue) { return null; } - return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)); - } - public OrderViewModel? Update(OrderBindingModel model) - { - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - order.Update(model); - source.SaveOrders(); - return GetViewModel(order); + + return GetViewModel(_source.Orders + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); } + + /// + /// Добавление элемента + /// + /// + /// public OrderViewModel? Insert(OrderBindingModel model) { - model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); if (newOrder == null) { return null; } - source.Orders.Add(newOrder); - source.SaveOrders(); + + _source.Orders.Add(newOrder); + _source.SaveOrders(); return GetViewModel(newOrder); } - public OrderViewModel? Delete(OrderBindingModel model) + + /// + /// Редактирование элемента + /// + /// + /// + public OrderViewModel? Update(OrderBindingModel model) { - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + var order = _source.Orders.FirstOrDefault(x => x.Id == model.Id); if (order == null) { return null; } - source.Orders.Remove(order); - source.SaveOrders(); + + order.Update(model); + _source.SaveOrders(); return GetViewModel(order); } + + /// + /// Удаление элемента + /// + /// + /// + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = _source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + _source.Orders.Remove(element); + _source.SaveOrders(); + return GetViewModel(element); + } + return null; + } + + /// + /// Получение модели заказа + /// + /// + /// private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - var computer = source.Computers.FirstOrDefault(x => x.Id == order.ComputerId); - viewModel.ComputerName = computer?.ComputerName; + var computer = _source.Computers.FirstOrDefault(x => x.Id == order.ComputerId); + if (computer != null) + { + viewModel.ComputerName = computer.ComputerName; + } return viewModel; } } diff --git a/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..ebd3b0e --- /dev/null +++ b/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,193 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Models; +using ComputersShopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + /// + /// Хранилище + /// + private readonly DataFileSingleton _source; + + /// + /// Конструктор + /// + public ShopStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + /// + /// Получение полного списка + /// + /// + public List GetFullList() + { + return _source.Shops + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получение фильтрованного списка + /// + /// + /// + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + + return _source.Shops + .Where(x => x.ShopName.Contains(model.ShopName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + /// + /// Получение элемента + /// + /// + /// + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + + return _source.Shops + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ShopName) && + x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + /// + /// Добавление элемента + /// + /// + /// + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = _source.Shops.Count > 0 ? _source.Shops.Max(x => x.Id) + 1 : 1; + + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + + _source.Shops.Add(newShop); + _source.SaveShops(); + return newShop.GetViewModel; + } + + /// + /// Редактирование элемента + /// + /// + /// + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = _source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + + shop.Update(model); + _source.SaveShops(); + return shop.GetViewModel; + } + + /// + /// Удаление элемента + /// + /// + /// + public ShopViewModel? Delete(ShopBindingModel model) + { + var element = _source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + _source.Shops.Remove(element); + _source.SaveShops(); + return element.GetViewModel; + } + return null; + } + + /// + /// Продажа изделий + /// + /// + /// + /// + public bool SellComputers(IComputerModel model, int count) + { + var computer = _source.Computers.FirstOrDefault(x => x.Id == model.Id); + if (computer == null || !CheckCount(model, count)) + { + return false; + } + + foreach (var shop in _source.Shops) + { + var computers = shop.ShopComputers; + foreach (var elem in computers.Where(x => x.Value.Item1.Id == computer.Id)) + { + var selling = Math.Min(elem.Value.Item2, count); + computers[elem.Value.Item1.Id] = (elem.Value.Item1, elem.Value.Item2 - selling); + count -= selling; + + if (count <= 0) + { + break; + } + } + + shop.Update(new ShopBindingModel + { + Id = model.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpening = shop.DateOpening, + ShopComputers = computers, + MaxComputers = shop.MaxComputers + }); + } + + _source.SaveShops(); + return true; + } + + /// + /// Проверка наличия в нужном количестве + /// + /// + /// + /// + public bool CheckCount(IComputerModel model, int count) + { + int store = _source.Shops + .Select(x => x.ShopComputers + .Select(y => (y.Value.Item1.Id == model.Id ? y.Value.Item2 : 0)) + .Sum()).Sum(); + return store >= count; + } + } +} diff --git a/ComputersShop/ComputersShopFileImplement/Models/Shop.cs b/ComputersShop/ComputersShopFileImplement/Models/Shop.cs new file mode 100644 index 0000000..a09d81f --- /dev/null +++ b/ComputersShop/ComputersShopFileImplement/Models/Shop.cs @@ -0,0 +1,155 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ComputersShopFileImplement.Models +{ + public class Shop : IShopModel + { + /// + /// Идентификатор + /// + public int Id { get; private set; } + + /// + /// Название магазина + /// + public string ShopName { get; private set; } = string.Empty; + + /// + /// Адрес магазина + /// + public string Address { get; private set; } = string.Empty; + + /// + /// Дата открытия магазина + /// + public DateTime DateOpening { get; private set; } + + /// + /// Коллекция изделий магазина в виде + /// «идентификатор изделия – количество изделий» + /// + public Dictionary Computers { get; private set; } = new(); + + /// + /// Коллекция изделий в магазине + /// + private Dictionary? _shopComputers = null; + public Dictionary ShopComputers + { + get + { + if (_shopComputers == null) + { + var source = DataFileSingleton.GetInstance(); + _shopComputers = Computers.ToDictionary(x => x.Key, y => ((source.Computers.FirstOrDefault(z => z.Id == y.Key) as IComputerModel)!, y.Value)); + } + return _shopComputers; + } + } + + /// + /// Максимальное количество изделий + /// + public int MaxComputers { get; private set; } + + /// + /// Создание модели магазина из данных файла + /// + /// + /// + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), + Computers = element.Element("ShopComputers")!.Elements("ShopComputers")! + .ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)), + MaxComputers = Convert.ToInt32(element.Element("MaxComputers")!.Value) + }; + } + + /// + /// Создание модели магазина + /// + /// + /// + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + Computers = model.ShopComputers.ToDictionary(x => x.Key, x => x.Value.Item2), + MaxComputers = model.MaxComputers + }; + } + + /// + /// Изменение модели магазина + /// + /// + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + Computers = model.ShopComputers.ToDictionary(x => x.Key, x => x.Value.Item2); + MaxComputers = model.MaxComputers; + _shopComputers = null; + } + + /// + /// Получение модели магазина + /// + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + ShopComputers = ShopComputers, + MaxComputers = MaxComputers + }; + + /// + /// Запись данных о модели магазина в файл + /// + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpening", DateOpening.ToString()), + new XElement("ShopComputers", Computers.Select(x => + new XElement("ShopComputers", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray()), + new XElement("MaxComputers", MaxComputers.ToString())); + } +} diff --git a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs index 834470f..3b494bf 100644 --- a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs +++ b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs @@ -11,10 +11,30 @@ namespace AbstractShopListImplement public class DataListSingleton { private static DataListSingleton? _instance; + + /// + /// Список классов-моделей компонентов + /// public List Components { get; set; } + + /// + /// Список классов-моделей заказов + /// public List Orders { get; set; } + + /// + /// Список классов-моделей изделий + /// public List Computers { get; set; } + + /// + /// Список классов-моделей магазинов + /// public List Shops { get; set; } + + /// + /// Конструктор + /// private DataListSingleton() { Components = new List(); @@ -22,6 +42,11 @@ namespace AbstractShopListImplement Computers = new List(); Shops = new List(); } + + /// + /// Получить ссылку на класс + /// + /// public static DataListSingleton GetInstance() { if (_instance == null) diff --git a/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs index 56af78b..2b2be2d 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs @@ -15,50 +15,79 @@ namespace ComputersShopListImplement.Implements public class OrderStorage : IOrderStorage { private readonly DataListSingleton _source; + + /// + /// Конструктор + /// public OrderStorage() { _source = DataListSingleton.GetInstance(); } + + /// + /// Получение полного списка + /// + /// public List GetFullList() { var result = new List(); foreach (var order in _source.Orders) { - result.Add(AddComputerName(order.GetViewModel)); + result.Add(order.GetViewModel); } return result; } - public List GetFiltredList(OrderSearchModel model) + + /// + /// Получение фильтрованного списка + /// + /// + /// + public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if (model == null || !model.Id.HasValue) + if (!model.Id.HasValue) { return result; } + foreach (var order in _source.Orders) { if (order.Id == model.Id) { - result.Add(AddComputerName(order.GetViewModel)); + result.Add(order.GetViewModel); } } 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 AddComputerName(order.GetViewModel); + return order.GetViewModel; } } return null; } + + /// + /// Добавление элемента + /// + /// + /// public OrderViewModel? Insert(OrderBindingModel model) { model.Id = 1; @@ -69,14 +98,22 @@ namespace ComputersShopListImplement.Implements model.Id = order.Id + 1; } } + var newOrder = Order.Create(model); if (newOrder == null) { return null; } + _source.Orders.Add(newOrder); - return AddComputerName(newOrder.GetViewModel); + return newOrder.GetViewModel; } + + /// + /// Редактирование элемента + /// + /// + /// public OrderViewModel? Update(OrderBindingModel model) { foreach (var order in _source.Orders) @@ -84,11 +121,17 @@ namespace ComputersShopListImplement.Implements if (order.Id == model.Id) { order.Update(model); - return AddComputerName(order.GetViewModel); + return order.GetViewModel; } } return null; } + + /// + /// Удаление элемента + /// + /// + /// public OrderViewModel? Delete(OrderBindingModel model) { for (int i = 0; i < _source.Orders.Count; ++i) @@ -97,20 +140,11 @@ namespace ComputersShopListImplement.Implements { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return AddComputerName(element.GetViewModel); + return element.GetViewModel; } } return null; } - private OrderViewModel AddComputerName(OrderViewModel model) - { - var selectedComputer = _source.Computers.Find(computer => computer.Id == model.ComputerId); - if (selectedComputer != null) - { - model.ComputerName = selectedComputer.ComputerName; - } - return model; - } } } diff --git a/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs index 272a04c..8eaadc0 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs @@ -9,6 +9,7 @@ using ComputersShopContracts.SearchModels; using ComputersShopContracts.StoragesContracts; using ComputersShopContracts.ViewModels; using ComputersShopDataModels; +using ComputersShopDataModels.Models; using ComputersShopListImplement.Models; namespace ComputersShopListImplement.Implements @@ -16,10 +17,19 @@ namespace ComputersShopListImplement.Implements public class ShopStorage : IShopStorage { private readonly DataListSingleton _source; + + /// + /// Конструктор + /// public ShopStorage() { _source = DataListSingleton.GetInstance(); } + + /// + /// Получение полного списка + /// + /// public List GetFullList() { var result = new List(); @@ -29,6 +39,12 @@ namespace ComputersShopListImplement.Implements } return result; } + + /// + /// Получение фильтрованного списка + /// + /// + /// public List GetFilteredList(ShopSearchModel model) { var result = new List(); @@ -46,6 +62,12 @@ namespace ComputersShopListImplement.Implements } return result; } + + /// + /// Получение элемента + /// + /// + /// public ShopViewModel? GetElement(ShopSearchModel model) { if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) @@ -62,6 +84,12 @@ namespace ComputersShopListImplement.Implements } return null; } + + /// + /// Добавление элемента + /// + /// + /// public ShopViewModel? Insert(ShopBindingModel model) { model.Id = 1; @@ -82,6 +110,12 @@ namespace ComputersShopListImplement.Implements _source.Shops.Add(newShop); return newShop.GetViewModel; } + + /// + /// Редактирование элемента + /// + /// + /// public ShopViewModel? Update(ShopBindingModel model) { foreach (var shop in _source.Shops) @@ -94,6 +128,12 @@ namespace ComputersShopListImplement.Implements } return null; } + + /// + /// Удаление элемента + /// + /// + /// public ShopViewModel? Delete(ShopBindingModel model) { for (int i = 0; i < _source.Shops.Count; ++i) @@ -107,5 +147,29 @@ namespace ComputersShopListImplement.Implements } return null; } + + /// + /// Продажа изделий + /// + /// + /// + /// + /// + public bool SellComputers(IComputerModel model, int count) + { + throw new NotImplementedException(); + } + + /// + /// Проверка наличия в нужном количестве + /// + /// + /// + /// + /// + public bool CheckCount(IComputerModel model, int count) + { + throw new NotImplementedException(); + } } } diff --git a/ComputersShop/ComputersShopListImplement/Models/Shop.cs b/ComputersShop/ComputersShopListImplement/Models/Shop.cs index 7263885..44c0c7e 100644 --- a/ComputersShop/ComputersShopListImplement/Models/Shop.cs +++ b/ComputersShop/ComputersShopListImplement/Models/Shop.cs @@ -13,14 +13,41 @@ namespace ComputersShopListImplement.Models public class Shop : IShopModel { public int Id { get; private set; } + + /// + /// Название магазина + /// public string ShopName { get; private set; } = string.Empty; + + /// + /// Адрес магазина + /// public string Address { get; private set; } = string.Empty; + + /// + /// Дата открытия магазина + /// public DateTime DateOpening { get; private set; } + + /// + /// Коллекция изделий в магазине + /// public Dictionary ShopComputers { get; private set; } = new Dictionary(); + + /// + /// Максимальное количество изделий + /// + public int MaxComputers { get; private set; } + + /// + /// Создание модели магазина + /// + /// + /// public static Shop? Create(ShopBindingModel? model) { if (model == null) @@ -34,9 +61,15 @@ namespace ComputersShopListImplement.Models ShopName = model.ShopName, Address = model.Address, DateOpening = model.DateOpening, - ShopComputers = model.ShopComputers + ShopComputers = model.ShopComputers, + MaxComputers = model.MaxComputers }; } + + /// + /// Изменение модели магазина + /// + /// public void Update(ShopBindingModel? model) { if (model == null) @@ -48,14 +81,20 @@ namespace ComputersShopListImplement.Models Address = model.Address; DateOpening = model.DateOpening; ShopComputers = model.ShopComputers; + MaxComputers = model.MaxComputers; } + + /// + /// Получение модели магазина + /// public ShopViewModel GetViewModel => new() { Id = Id, ShopName = ShopName, Address = Address, DateOpening = DateOpening, - ShopComputers = ShopComputers + ShopComputers = ShopComputers, + MaxComputers = MaxComputers }; } } diff --git a/ComputersShop/ComputersShopView/FormMain.Designer.cs b/ComputersShop/ComputersShopView/FormMain.Designer.cs index 3511353..a6f14b8 100644 --- a/ComputersShop/ComputersShopView/FormMain.Designer.cs +++ b/ComputersShop/ComputersShopView/FormMain.Designer.cs @@ -40,6 +40,7 @@ this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); + this.продажаИзделийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -61,7 +62,8 @@ this.компонентыToolStripMenuItem, this.изделияToolStripMenuItem, this.магазиныToolStripMenuItem, - this.поставкиToolStripMenuItem}); + this.поставкиToolStripMenuItem, + this.продажаИзделийToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -157,6 +159,12 @@ this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); // + // продажаИзделийToolStripMenuItem + // + this.продажаИзделийToolStripMenuItem.Name = "продажаИзделийToolStripMenuItem"; + this.продажаИзделийToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.продажаИзделийToolStripMenuItem.Text = "Продажа изделий"; + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -195,5 +203,6 @@ private ToolStripMenuItem изделияToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem; private ToolStripMenuItem поставкиToolStripMenuItem; + private ToolStripMenuItem продажаИзделийToolStripMenuItem; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormMain.cs b/ComputersShop/ComputersShopView/FormMain.cs index f9ed2e6..bf14e37 100644 --- a/ComputersShop/ComputersShopView/FormMain.cs +++ b/ComputersShop/ComputersShopView/FormMain.cs @@ -80,6 +80,15 @@ namespace ComputersShopView form.ShowDialog(); } } + private void ПродажаизделийToolStripMenuItem_Click(object sender, EventArgs + e) + { + var services = Program.ServiceProvider?.GetService(typeof(FormSell)); + if (services is FormSell form) + { + form.ShowDialog(); + } + } private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = diff --git a/ComputersShop/ComputersShopView/FormSell.Designer.cs b/ComputersShop/ComputersShopView/FormSell.Designer.cs new file mode 100644 index 0000000..052f8bc --- /dev/null +++ b/ComputersShop/ComputersShopView/FormSell.Designer.cs @@ -0,0 +1,120 @@ +namespace ComputersShopView +{ + partial class FormSell + { + /// + /// 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.labelComputer = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxComputer = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelComputer + // + this.labelComputer.AutoSize = true; + this.labelComputer.Location = new System.Drawing.Point(12, 50); + this.labelComputer.Name = "labelComputer"; + this.labelComputer.Size = new System.Drawing.Size(71, 20); + this.labelComputer.TabIndex = 0; + this.labelComputer.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 106); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // comboBoxComputer + // + this.comboBoxComputer.FormattingEnabled = true; + this.comboBoxComputer.Location = new System.Drawing.Point(137, 42); + this.comboBoxComputer.Name = "comboBoxComputer"; + this.comboBoxComputer.Size = new System.Drawing.Size(267, 28); + this.comboBoxComputer.TabIndex = 2; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(137, 99); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(267, 27); + this.textBoxCount.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(244, 154); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(368, 154); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormSell + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(474, 199); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxComputer); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelComputer); + this.Name = "FormSell"; + this.Text = "Продажа"; + this.Load += new System.EventHandler(this.FormSell_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelComputer; + private Label labelCount; + private ComboBox comboBoxComputer; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormSell.cs b/ComputersShop/ComputersShopView/FormSell.cs new file mode 100644 index 0000000..5de3f68 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormSell.cs @@ -0,0 +1,107 @@ +using ComputersShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +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 ComputersShopView +{ + public partial class FormSell : Form + { + private readonly ILogger _logger; + + /// + /// Бизнес-логика для изделий + /// + private readonly IComputerLogic _logicC; + + /// + /// Бизнес-логика для магазинов + /// + private readonly IShopLogic _logicS; + public FormSell(ILogger logger, IComputerLogic planeLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _logger = logger; + _logicC = planeLogic; + _logicS = shopLogic; + } + private void FormSell_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для продажи"); + try + { + var list = _logicC.ReadList(null); + if (list != null) + { + comboBoxComputer.DisplayMember = "ComputerName"; + comboBoxComputer.ValueMember = "Id"; + comboBoxComputer.DataSource = list; + comboBoxComputer.SelectedItem = null; + } + } + 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(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComputer.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Продажа изделий"); + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicS.SellComputers( + _logicC.ReadElement(new() { Id = Convert.ToInt32(comboBoxComputer.SelectedValue) }), + Convert.ToInt32(textBoxCount.Text) + ); + if (!operationResult) + { + throw new Exception("Ошибка при продаже изделий. Дополнительная информация в логах."); + } + MessageBox.Show("Продажа прошла успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка продажи изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Отмена" + /// + /// + /// + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/ComputersShop/ComputersShopView/FormSell.resx b/ComputersShop/ComputersShopView/FormSell.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ComputersShop/ComputersShopView/FormSell.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/ComputersShop/ComputersShopView/FormShop.Designer.cs b/ComputersShop/ComputersShopView/FormShop.Designer.cs index a1c7aa7..342d030 100644 --- a/ComputersShop/ComputersShopView/FormShop.Designer.cs +++ b/ComputersShop/ComputersShopView/FormShop.Designer.cs @@ -35,11 +35,13 @@ this.textBoxAddress = new System.Windows.Forms.TextBox(); this.textBoxName = new System.Windows.Forms.TextBox(); this.dataGridViewShop = new System.Windows.Forms.DataGridView(); - this.buttonSave = new System.Windows.Forms.Button(); - this.buttonCancel = new System.Windows.Forms.Button(); this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ComputerName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelMaxComputers = new System.Windows.Forms.Label(); + this.textBoxMaxComputers = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewShop)).BeginInit(); this.SuspendLayout(); // @@ -72,24 +74,24 @@ // // dateTimePicker // - this.dateTimePicker.Location = new System.Drawing.Point(104, 97); + this.dateTimePicker.Location = new System.Drawing.Point(121, 97); this.dateTimePicker.Name = "dateTimePicker"; - this.dateTimePicker.Size = new System.Drawing.Size(403, 27); + this.dateTimePicker.Size = new System.Drawing.Size(386, 27); this.dateTimePicker.TabIndex = 3; // // textBoxAddress // - this.textBoxAddress.Location = new System.Drawing.Point(104, 61); + this.textBoxAddress.Location = new System.Drawing.Point(121, 61); this.textBoxAddress.Name = "textBoxAddress"; - this.textBoxAddress.Size = new System.Drawing.Size(403, 27); + this.textBoxAddress.Size = new System.Drawing.Size(386, 27); this.textBoxAddress.TabIndex = 4; this.textBoxAddress.TextChanged += new System.EventHandler(this.FormShop_Load); // // textBoxName // - this.textBoxName.Location = new System.Drawing.Point(104, 22); + this.textBoxName.Location = new System.Drawing.Point(121, 22); this.textBoxName.Name = "textBoxName"; - this.textBoxName.Size = new System.Drawing.Size(403, 27); + this.textBoxName.Size = new System.Drawing.Size(386, 27); this.textBoxName.TabIndex = 5; // // dataGridViewShop @@ -99,33 +101,13 @@ this.id, this.ComputerName, this.Count}); - this.dataGridViewShop.Location = new System.Drawing.Point(23, 156); + this.dataGridViewShop.Location = new System.Drawing.Point(23, 197); this.dataGridViewShop.Name = "dataGridViewShop"; this.dataGridViewShop.RowHeadersWidth = 51; this.dataGridViewShop.RowTemplate.Height = 29; this.dataGridViewShop.Size = new System.Drawing.Size(507, 173); this.dataGridViewShop.TabIndex = 6; // - // buttonSave - // - this.buttonSave.Location = new System.Drawing.Point(319, 354); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(94, 29); - this.buttonSave.TabIndex = 7; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // - // buttonCancel - // - this.buttonCancel.Location = new System.Drawing.Point(436, 354); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(94, 29); - this.buttonCancel.TabIndex = 8; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // // id // this.id.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; @@ -148,11 +130,49 @@ this.Count.MinimumWidth = 6; this.Count.Name = "Count"; // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(319, 376); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(436, 376); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 8; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // labelMaxComputers + // + this.labelMaxComputers.AutoSize = true; + this.labelMaxComputers.Location = new System.Drawing.Point(12, 150); + this.labelMaxComputers.Name = "labelMaxComputers"; + this.labelMaxComputers.Size = new System.Drawing.Size(103, 20); + this.labelMaxComputers.TabIndex = 9; + this.labelMaxComputers.Text = "Вместимость:"; + // + // textBoxMaxComputers + // + this.textBoxMaxComputers.Location = new System.Drawing.Point(121, 147); + this.textBoxMaxComputers.Name = "textBoxMaxComputers"; + this.textBoxMaxComputers.Size = new System.Drawing.Size(386, 27); + this.textBoxMaxComputers.TabIndex = 10; + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(546, 395); + this.ClientSize = new System.Drawing.Size(546, 417); + this.Controls.Add(this.textBoxMaxComputers); + this.Controls.Add(this.labelMaxComputers); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonSave); this.Controls.Add(this.dataGridViewShop); @@ -185,5 +205,7 @@ private DataGridViewTextBoxColumn id; private DataGridViewTextBoxColumn ComputerName; private DataGridViewTextBoxColumn Count; + private Label labelMaxComputers; + private TextBox textBoxMaxComputers; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormShop.cs b/ComputersShop/ComputersShopView/FormShop.cs index 1cec395..272fa46 100644 --- a/ComputersShop/ComputersShopView/FormShop.cs +++ b/ComputersShop/ComputersShopView/FormShop.cs @@ -43,6 +43,7 @@ namespace ComputersShopView textBoxName.Text = view.ShopName; textBoxAddress.Text = view.Address; dateTimePicker.Text = view.DateOpening.ToString(); + textBoxMaxComputers.Text = view.MaxComputers.ToString(); _shopComputers = view.ShopComputers ?? new Dictionary(); LoadData(); } @@ -108,7 +109,8 @@ namespace ComputersShopView ShopName = textBoxName.Text, Address = textBoxAddress.Text, DateOpening = dateTimePicker.Value.Date, - ShopComputers = _shopComputers + ShopComputers = _shopComputers, + MaxComputers = Convert.ToInt32(textBoxMaxComputers.Text) }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) diff --git a/ComputersShop/ComputersShopView/FormSupply.Designer.cs b/ComputersShop/ComputersShopView/FormSupply.Designer.cs index 220fd24..74d893d 100644 --- a/ComputersShop/ComputersShopView/FormSupply.Designer.cs +++ b/ComputersShop/ComputersShopView/FormSupply.Designer.cs @@ -105,6 +105,11 @@ // numericUpDownCount // this.numericUpDownCount.Location = new System.Drawing.Point(142, 139); + this.numericUpDownCount.Maximum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); this.numericUpDownCount.Name = "numericUpDownCount"; this.numericUpDownCount.Size = new System.Drawing.Size(348, 27); this.numericUpDownCount.TabIndex = 8; diff --git a/ComputersShop/ComputersShopView/FormSupply.cs b/ComputersShop/ComputersShopView/FormSupply.cs index 5c58220..cbd8e91 100644 --- a/ComputersShop/ComputersShopView/FormSupply.cs +++ b/ComputersShop/ComputersShopView/FormSupply.cs @@ -50,6 +50,7 @@ namespace ComputersShopView _logger.LogError(ex, "Ошибка загрузки списка магазинов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } + _logger.LogInformation("Загрузка изделий"); try { diff --git a/ComputersShop/ComputersShopView/Program.cs b/ComputersShop/ComputersShopView/Program.cs index bcdd41f..c0d885b 100644 --- a/ComputersShop/ComputersShopView/Program.cs +++ b/ComputersShop/ComputersShopView/Program.cs @@ -67,6 +67,7 @@ namespace ComputersShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file -- 2.25.1 From 5d93cf4a7f01474d3ab4d4146607b419c933df82 Mon Sep 17 00:00:00 2001 From: bulatova_karina Date: Sun, 5 May 2024 16:59:47 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B7?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=BB=D0=B0=20=D0=B2?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D1=83=D1=81=D0=BB=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ComponentLogic.cs | 2 +- .../BusinessLogics/ComputerLogic.cs | 49 +----------- .../BusinessLogics/OrderLogic.cs | 72 ------------------ .../BusinessLogics/ShopLogic.cs | 68 ----------------- .../StoragesContracts/IComponentStorage.cs | 2 +- .../StoragesContracts/IComputerStorage.cs | 2 +- .../StoragesContracts/IOrderStorage.cs | 30 -------- .../DataFileSingleton.cs | 75 ------------------- .../Implements/ComponentStorage.cs | 45 ++++++----- .../Implements/ComputerStorage.cs | 46 +++++++----- .../Implements/OrderStorage.cs | 51 +------------ .../Implements/ShopStorage.cs | 56 -------------- .../Models/Component.cs | 13 ++-- .../Models/Computer.cs | 25 ++++--- .../ComputersShopFileImplement/Models/Shop.cs | 53 ------------- .../DataListSingleton.cs | 25 ------- .../Implements/ComponentStorage.cs | 2 +- .../Implements/ComputerStorage.cs | 2 +- .../Implements/OrderStorage.cs | 39 ---------- .../Implements/ShopStorage.cs | 55 -------------- .../ComputersShopListImplement/Models/Shop.cs | 35 --------- .../ComputersShopView/FormMain.Designer.cs | 15 ++-- .../ComputersShopView/FormShops.Designer.cs | 14 ++-- ComputersShop/ComputersShopView/Program.cs | 2 +- 24 files changed, 101 insertions(+), 677 deletions(-) diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs index 37626aa..d8ce116 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -24,7 +24,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics public List? ReadList(ComponentSearchModel? model) { _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{Id}", model?.ComponentName, model?.Id); - var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFiltredList(model); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs index 3c77dda..b50fc43 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs @@ -15,33 +15,17 @@ namespace ComputersShopBusinessLogic.BusinessLogics public class ComputerLogic : IComputerLogic { private readonly ILogger _logger; - - /// - /// Взаимодействие с хранилищем изделий - /// private readonly IComputerStorage _computerStorage; - - /// - /// Конструктор - /// - /// - /// public ComputerLogic(ILogger logger, IComputerStorage computerStorage) { _logger = logger; _computerStorage = computerStorage; } - - /// - /// Получение списка - /// - /// - /// public List? ReadList(ComputerSearchModel? model) { _logger.LogInformation("ReadList. ComputerName:{ComputerName}.Id:{ Id}", model?.ComputerName, model?.Id); - var list = model == null ? _computerStorage.GetFullList() : _computerStorage.GetFiltredList(model); + var list = model == null ? _computerStorage.GetFullList() : _computerStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -51,13 +35,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - - /// - /// Получение отдельной записи - /// - /// - /// - /// public ComputerViewModel? ReadElement(ComputerSearchModel model) { if (model == null) @@ -77,12 +54,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } - - /// - /// Создание записи - /// - /// - /// public bool Create(ComputerBindingModel model) { CheckModel(model); @@ -94,12 +65,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } - - /// - /// Изменение записи - /// - /// - /// public bool Update(ComputerBindingModel model) { CheckModel(model); @@ -111,12 +76,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } - - /// - /// Удаление записи - /// - /// - /// public bool Delete(ComputerBindingModel model) { CheckModel(model, false); @@ -129,12 +88,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } - - /// - /// Проверка модели изделия - /// - /// - /// private void CheckModel(ComputerBindingModel model, bool withParams = true) { if (model == null) diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs index 37e534f..1027921 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -17,32 +17,10 @@ namespace ComputersShopBusinessLogic.BusinessLogics public class OrderLogic : IOrderLogic { private readonly ILogger _logger; - - /// - /// Взаимодействие с хранилищем заказов - /// private readonly IOrderStorage _orderStorage; - - /// - /// Взаимодействие с хранилищем магазинов - /// private IShopStorage _shopStorage; - - /// - /// Бизнес-логика магазинов - /// private IShopLogic _shopLogic; - - /// - /// Взаимодействие с хранилищем изделий - /// private IComputerStorage _computerStorage; - - /// - /// Конструктор - /// - /// - /// public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IComputerStorage computerStorage) { _logger = logger; @@ -51,12 +29,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics _shopLogic = shopLogic; _computerStorage = computerStorage; } - - /// - /// Получение списка - /// - /// - /// public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. Order.Id:{ Id}", model?.Id); @@ -71,12 +43,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - - /// - /// Создание заказа - /// - /// - /// public bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -95,42 +61,18 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } - - /// - /// Смена статуса заказа (Выполняется) - /// - /// - /// public bool TakeOrderInWork(OrderBindingModel model) { return StatusUpdate(model, OrderStatus.Выполняется); } - - /// - /// Смена статуса заказа (Выдан) - /// - /// - /// public bool FinishOrder(OrderBindingModel model) { return StatusUpdate(model, OrderStatus.Выдан); } - - /// - /// Смена статуса заказа (Готов) - /// - /// - /// public bool DeliveryOrder(OrderBindingModel model) { return StatusUpdate(model, OrderStatus.Готов); } - - /// - /// Проверка модели заказа - /// - /// - /// private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) @@ -155,13 +97,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics } _logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. ComputerId: { ComputerId}", model.Id, model.Sum, model.ComputerId); } - - /// - /// Смена статуса заказа - /// - /// - /// - /// private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) { var element = _orderStorage.GetElement(new OrderSearchModel @@ -211,13 +146,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } - - /// - /// Проверка заказа - /// - /// - /// - /// public bool CheckSupply(IComputerModel model, int count) { if (count <= 0) diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs index cf5f308..f5eba06 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -16,28 +16,12 @@ namespace ComputersShopBusinessLogic.BusinessLogics public class ShopLogic : IShopLogic { private readonly ILogger _logger; - - /// - /// Взаимодействие с хранилищем магазинов - /// private readonly IShopStorage _shopStorage; - - /// - /// Конструктор - /// - /// - /// public ShopLogic(ILogger logger, IShopStorage shopStorage) { _logger = logger; _shopStorage = shopStorage; } - - /// - /// Получение списка - /// - /// - /// public List? ReadList(ShopSearchModel? model) { _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); @@ -52,13 +36,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - - /// - /// Получение отдельной записи - /// - /// - /// - /// public ShopViewModel? ReadElement(ShopSearchModel model) { if (model == null) @@ -78,12 +55,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } - - /// - /// Создание записи - /// - /// - /// public bool Create(ShopBindingModel model) { CheckModel(model); @@ -95,12 +66,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } - - /// - /// Изменение записи - /// - /// - /// public bool Update(ShopBindingModel model) { CheckModel(model); @@ -112,12 +77,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } - - /// - /// Удаление записи - /// - /// - /// public bool Delete(ShopBindingModel model) { CheckModel(model, false); @@ -130,16 +89,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics } return true; } - - /// - /// Добавление изделия в магазин - /// - /// - /// - /// - /// - /// - /// public bool AddComputerInShop(ShopSearchModel model, IComputerModel computer, int count) { if (model == null) @@ -188,15 +137,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics }); return true; } - - /// - /// Продажа изделий - /// - /// - /// - /// - /// - /// public bool SellComputers(IComputerModel computer, int count) { if (computer == null) @@ -216,14 +156,6 @@ namespace ComputersShopBusinessLogic.BusinessLogics _logger.LogInformation("Selling failed"); return false; } - - /// - /// Проверка модели магазина - /// - /// - /// - /// - /// private void CheckModel(ShopBindingModel model, bool withParams = true) { if (model == null) diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs index d819f35..644ba85 100644 --- a/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs @@ -13,7 +13,7 @@ namespace ComputersShopContracts.StoragesContracts public interface IComponentStorage { List GetFullList(); - List GetFiltredList(ComponentSearchModel model); + List GetFilteredList(ComponentSearchModel model); ComponentViewModel? GetElement(ComponentSearchModel model); ComponentViewModel? Insert(ComponentBindingModel model); ComponentViewModel? Update(ComponentBindingModel model); diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs index 2dcf346..fd22441 100644 --- a/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs @@ -13,7 +13,7 @@ namespace ComputersShopContracts.StoragesContracts public interface IComputerStorage { List GetFullList(); - List GetFiltredList(ComputerSearchModel model); + List GetFilteredList(ComputerSearchModel model); ComputerViewModel? GetElement(ComputerSearchModel model); ComputerViewModel? Insert(ComputerBindingModel model); ComputerViewModel? Update(ComputerBindingModel model); diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs index 7b156ec..67d7e47 100644 --- a/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs @@ -12,40 +12,10 @@ namespace ComputersShopContracts.StoragesContracts 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); } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs index 72d3979..83a47b4 100644 --- a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs +++ b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs @@ -12,50 +12,14 @@ namespace ComputersShopFileImplement internal class DataFileSingleton { private static DataFileSingleton? _instance; - - /// - /// Название файла для хранения информации о компонентах - /// private readonly string ComponentFileName = "Component.xml"; - - /// - /// Название файла для хранения информации о заказах - /// private readonly string OrderFileName = "Order.xml"; - - /// - /// Название файла для хранения информации о изделиях - /// private readonly string ComputerFileName = "Computer.xml"; - - /// - /// Название файла для хранения информации о магазинах - /// private readonly string ShopFileName = "Shop.xml"; - - /// - /// Список классов-моделей компонентов - /// public List Components { get; set; } - - /// - /// Список классов-моделей заказов - /// public List Orders { get; set; } - - /// - /// Список классов-моделей изделий - /// public List Computers { get; set; } - - /// - /// Список классов-моделей магазина - /// public List Shops { get; set; } - - /// - /// Конструктор - /// private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; @@ -63,11 +27,6 @@ namespace ComputersShopFileImplement Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } - - /// - /// Получить ссылку на класс - /// - /// public static DataFileSingleton GetInstance() { if (_instance == null) @@ -76,35 +35,10 @@ namespace ComputersShopFileImplement } return _instance; } - - /// - /// Сохранение компонентов - /// public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); - - /// - /// Сохранение изделий - /// public void SaveComputers() => SaveData(Computers, ComputerFileName, "Computers", x => x.GetXElement); - - /// - /// Сохранение заказов - /// public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); - - /// - /// Сохранение магазинов - /// public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); - - /// - /// Метод для загрузки данных из xml-файла - /// - /// - /// - /// - /// - /// private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { if (File.Exists(filename)) @@ -113,15 +47,6 @@ namespace ComputersShopFileImplement } return new List(); } - - /// - /// Метод для сохранения данных в xml-файл - /// - /// - /// - /// - /// - /// private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) { if (data != null) diff --git a/ComputersShop/ComputersShopFileImplement/Implements/ComponentStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ComponentStorage.cs index f4613e8..a18d710 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/ComponentStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/ComponentStorage.cs @@ -14,67 +14,76 @@ namespace ComputersShopFileImplement.Implements { public class ComponentStorage : IComponentStorage { - private readonly DataFileSingleton source; + private readonly DataFileSingleton _source; public ComponentStorage() { - source = DataFileSingleton.GetInstance(); + _source = DataFileSingleton.GetInstance(); } public List GetFullList() { - return source.Components.Select(x => x.GetViewModel).ToList(); + return _source.Components + .Select(x => x.GetViewModel) + .ToList(); } - public List GetFiltredList(ComponentSearchModel model) + public List GetFilteredList(ComponentSearchModel model) { if (string.IsNullOrEmpty(model.ComponentName)) { return new(); } - return source.Components + + return _source.Components .Where(x => x.ComponentName.Contains(model.ComponentName)) .Select(x => x.GetViewModel) .ToList(); } public ComponentViewModel? GetElement(ComponentSearchModel model) { - if (!string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) { return null; } - return source.Components - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && - x.ComponentName == model.ComponentName) || (model.Id.HasValue && - x.Id == model.Id))?.GetViewModel; + + return _source.Components + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ComponentName) && + x.ComponentName == model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; } public ComponentViewModel? Insert(ComponentBindingModel model) { - model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; + model.Id = _source.Components.Count > 0 ? _source.Components.Max(x => x.Id) + 1 : 1; + var newComponent = Component.Create(model); if (newComponent == null) { return null; } - source.Components.Add(newComponent); - source.SaveComponents(); + + _source.Components.Add(newComponent); + _source.SaveComponents(); return newComponent.GetViewModel; } public ComponentViewModel? Update(ComponentBindingModel model) { - var component = source.Components.FirstOrDefault(x => x.Id == model.Id); + var component = _source.Components.FirstOrDefault(x => x.Id == model.Id); if (component == null) { return null; } + component.Update(model); - source.SaveComponents(); + _source.SaveComponents(); return component.GetViewModel; } public ComponentViewModel? Delete(ComponentBindingModel model) { - var element = source.Components.FirstOrDefault(x => x.Id == model.Id); + var element = _source.Components.FirstOrDefault(x => x.Id == model.Id); if (element != null) { - source.Components.Remove(element); - source.SaveComponents(); + _source.Components.Remove(element); + _source.SaveComponents(); return element.GetViewModel; } return null; diff --git a/ComputersShop/ComputersShopFileImplement/Implements/ComputerStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ComputerStorage.cs index c8278ac..e5eb667 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/ComputerStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/ComputerStorage.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; using System.Text; using System.Threading.Tasks; using ComputersShopContracts.BindingModels; @@ -13,67 +14,76 @@ namespace ComputersShopFileImplement.Implements { public class ComputerStorage : IComputerStorage { - private readonly DataFileSingleton source; + private readonly DataFileSingleton _source; public ComputerStorage() { - source = DataFileSingleton.GetInstance(); + _source = DataFileSingleton.GetInstance(); } public List GetFullList() { - return source.Computers.Select(x => x.GetViewModel).ToList(); + return _source.Computers + .Select(x => x.GetViewModel) + .ToList(); } - public List GetFiltredList(ComputerSearchModel model) + public List GetFilteredList(ComputerSearchModel model) { if (string.IsNullOrEmpty(model.ComputerName)) { return new(); } - return source.Computers + + return _source.Computers .Where(x => x.ComputerName.Contains(model.ComputerName)) .Select(x => x.GetViewModel) .ToList(); } public ComputerViewModel? GetElement(ComputerSearchModel model) { - if (!string.IsNullOrEmpty(model.ComputerName) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.ComputerName) && !model.Id.HasValue) { return null; } - return source.Computers - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComputerName) && - x.ComputerName == model.ComputerName) || (model.Id.HasValue && - x.Id == model.Id))?.GetViewModel; + + return _source.Computers + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ComputerName) && + x.ComputerName == model.ComputerName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; } public ComputerViewModel? Insert(ComputerBindingModel model) { - model.Id = source.Computers.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; + model.Id = _source.Computers.Count > 0 ? _source.Computers.Max(x => x.Id) + 1 : 1; + var newComputer = Computer.Create(model); if (newComputer == null) { return null; } - source.Computers.Add(newComputer); - source.SaveComputers(); + + _source.Computers.Add(newComputer); + _source.SaveComputers(); return newComputer.GetViewModel; } public ComputerViewModel? Update(ComputerBindingModel model) { - var computer = source.Computers.FirstOrDefault(x => x.Id == model.Id); + var computer = _source.Computers.FirstOrDefault(x => x.Id == model.Id); if (computer == null) { return null; } + computer.Update(model); - source.SaveComputers(); + _source.SaveComputers(); return computer.GetViewModel; } public ComputerViewModel? Delete(ComputerBindingModel model) { - var element = source.Computers.FirstOrDefault(x => x.Id == model.Id); + var element = _source.Computers.FirstOrDefault(x => x.Id == model.Id); if (element != null) { - source.Computers.Remove(element); - source.SaveComputers(); + _source.Computers.Remove(element); + _source.SaveComputers(); return element.GetViewModel; } return null; diff --git a/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs index 5e187e9..9be75ba 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs @@ -14,31 +14,16 @@ namespace ComputersShopFileImplement.Implements public class OrderStorage : IOrderStorage { private readonly DataFileSingleton _source; - - /// - /// Конструктор - /// public OrderStorage() { _source = DataFileSingleton.GetInstance(); } - - /// - /// Получение полного списка - /// - /// public List GetFullList() { return _source.Orders .Select(x => GetViewModel(x)) .ToList(); } - - /// - /// Получение фильтрованного списка - /// - /// - /// public List GetFilteredList(OrderSearchModel model) { if (!model.Id.HasValue) @@ -51,12 +36,6 @@ namespace ComputersShopFileImplement.Implements .Select(x => GetViewModel(x)) .ToList(); } - - /// - /// Получение элемента - /// - /// - /// public OrderViewModel? GetElement(OrderSearchModel model) { if (!model.Id.HasValue) @@ -67,12 +46,6 @@ namespace ComputersShopFileImplement.Implements return GetViewModel(_source.Orders .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); } - - /// - /// Добавление элемента - /// - /// - /// public OrderViewModel? Insert(OrderBindingModel model) { model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 1; @@ -87,12 +60,6 @@ namespace ComputersShopFileImplement.Implements _source.SaveOrders(); return GetViewModel(newOrder); } - - /// - /// Редактирование элемента - /// - /// - /// public OrderViewModel? Update(OrderBindingModel model) { var order = _source.Orders.FirstOrDefault(x => x.Id == model.Id); @@ -105,12 +72,6 @@ namespace ComputersShopFileImplement.Implements _source.SaveOrders(); return GetViewModel(order); } - - /// - /// Удаление элемента - /// - /// - /// public OrderViewModel? Delete(OrderBindingModel model) { var element = _source.Orders.FirstOrDefault(x => x.Id == model.Id); @@ -122,19 +83,13 @@ namespace ComputersShopFileImplement.Implements } return null; } - - /// - /// Получение модели заказа - /// - /// - /// private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - var computer = _source.Computers.FirstOrDefault(x => x.Id == order.ComputerId); - if (computer != null) + var plane = _source.Computers.FirstOrDefault(x => x.Id == order.ComputerId); + if (plane != null) { - viewModel.ComputerName = computer.ComputerName; + viewModel.ComputerName = plane.ComputerName; } return viewModel; } diff --git a/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs index ebd3b0e..2595569 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/ShopStorage.cs @@ -14,35 +14,17 @@ namespace ComputersShopFileImplement.Implements { public class ShopStorage : IShopStorage { - /// - /// Хранилище - /// private readonly DataFileSingleton _source; - - /// - /// Конструктор - /// public ShopStorage() { _source = DataFileSingleton.GetInstance(); } - - /// - /// Получение полного списка - /// - /// public List GetFullList() { return _source.Shops .Select(x => x.GetViewModel) .ToList(); } - - /// - /// Получение фильтрованного списка - /// - /// - /// public List GetFilteredList(ShopSearchModel model) { if (string.IsNullOrEmpty(model.ShopName)) @@ -55,12 +37,6 @@ namespace ComputersShopFileImplement.Implements .Select(x => x.GetViewModel) .ToList(); } - - /// - /// Получение элемента - /// - /// - /// public ShopViewModel? GetElement(ShopSearchModel model) { if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) @@ -75,12 +51,6 @@ namespace ComputersShopFileImplement.Implements (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; } - - /// - /// Добавление элемента - /// - /// - /// public ShopViewModel? Insert(ShopBindingModel model) { model.Id = _source.Shops.Count > 0 ? _source.Shops.Max(x => x.Id) + 1 : 1; @@ -95,12 +65,6 @@ namespace ComputersShopFileImplement.Implements _source.SaveShops(); return newShop.GetViewModel; } - - /// - /// Редактирование элемента - /// - /// - /// public ShopViewModel? Update(ShopBindingModel model) { var shop = _source.Shops.FirstOrDefault(x => x.Id == model.Id); @@ -113,12 +77,6 @@ namespace ComputersShopFileImplement.Implements _source.SaveShops(); return shop.GetViewModel; } - - /// - /// Удаление элемента - /// - /// - /// public ShopViewModel? Delete(ShopBindingModel model) { var element = _source.Shops.FirstOrDefault(x => x.Id == model.Id); @@ -130,13 +88,6 @@ namespace ComputersShopFileImplement.Implements } return null; } - - /// - /// Продажа изделий - /// - /// - /// - /// public bool SellComputers(IComputerModel model, int count) { var computer = _source.Computers.FirstOrDefault(x => x.Id == model.Id); @@ -174,13 +125,6 @@ namespace ComputersShopFileImplement.Implements _source.SaveShops(); return true; } - - /// - /// Проверка наличия в нужном количестве - /// - /// - /// - /// public bool CheckCount(IComputerModel model, int count) { int store = _source.Shops diff --git a/ComputersShop/ComputersShopFileImplement/Models/Component.cs b/ComputersShop/ComputersShopFileImplement/Models/Component.cs index 52a5e3c..73271e5 100644 --- a/ComputersShop/ComputersShopFileImplement/Models/Component.cs +++ b/ComputersShop/ComputersShopFileImplement/Models/Component.cs @@ -16,12 +16,13 @@ namespace ComputersShopFileImplement.Models 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) + public static Component? Create(ComponentBindingModel? model) { if (model == null) { return null; } + return new Component() { Id = model.Id, @@ -35,6 +36,7 @@ namespace ComputersShopFileImplement.Models { return null; } + return new Component() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), @@ -42,12 +44,13 @@ namespace ComputersShopFileImplement.Models Cost = Convert.ToDouble(element.Element("Cost")!.Value) }; } - public void Update(ComponentBindingModel model) + public void Update(ComponentBindingModel? model) { if (model == null) { return; } + ComponentName = model.ComponentName; Cost = model.Cost; } @@ -58,8 +61,8 @@ namespace ComputersShopFileImplement.Models Cost = Cost }; public XElement GetXElement => new("Component", - new XAttribute("Id", Id), - new XElement("ComponentName", ComponentName), - new XElement("Cost", Cost.ToString())); + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); } } diff --git a/ComputersShop/ComputersShopFileImplement/Models/Computer.cs b/ComputersShop/ComputersShopFileImplement/Models/Computer.cs index afaa4d9..8cb0cb3 100644 --- a/ComputersShop/ComputersShopFileImplement/Models/Computer.cs +++ b/ComputersShop/ComputersShopFileImplement/Models/Computer.cs @@ -7,6 +7,7 @@ using ComputersShopContracts.BindingModels; using ComputersShopContracts.ViewModels; using ComputersShopDataModels.Models; using System.Xml.Linq; +using System.Numerics; namespace ComputersShopFileImplement.Models { @@ -24,19 +25,18 @@ namespace ComputersShopFileImplement.Models if (_computerComponents == null) { var source = DataFileSingleton.GetInstance(); - _computerComponents = Components.ToDictionary(x => x.Key, y => - ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, - y.Value)); + _computerComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); } return _computerComponents; } } - public static Computer? Create(ComputerBindingModel model) + public static Computer? Create(ComputerBindingModel? model) { if (model == null) { return null; } + return new Computer() { Id = model.Id, @@ -51,24 +51,23 @@ namespace ComputersShopFileImplement.Models { return null; } + return new Computer() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), ComputerName = element.Element("ComputerName")!.Value, Price = Convert.ToDouble(element.Element("Price")!.Value), - Components = - element.Element("ComputerComponents")!.Elements("ComputerComponent") - .ToDictionary(x => - Convert.ToInt32(x.Element("Key")?.Value), x => - Convert.ToInt32(x.Element("Value")?.Value)) + Components = element.Element("ComputerComponents")!.Elements("ComputerComponent") + .ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) }; } - public void Update(ComputerBindingModel model) + public void Update(ComputerBindingModel? model) { if (model == null) { return; } + ComputerName = model.ComputerName; Price = model.Price; Components = model.ComputerComponents.ToDictionary(x => x.Key, x => x.Value.Item2); @@ -86,8 +85,10 @@ namespace ComputersShopFileImplement.Models new XElement("ComputerName", ComputerName), new XElement("Price", Price.ToString()), new XElement("ComputerComponents", Components.Select(x => - new XElement("ComputerComponent", new XElement("Key", x.Key), - new XElement("Value", x.Value))).ToArray())); + new XElement("ComputerComponent", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); } } diff --git a/ComputersShop/ComputersShopFileImplement/Models/Shop.cs b/ComputersShop/ComputersShopFileImplement/Models/Shop.cs index a09d81f..cf5e85a 100644 --- a/ComputersShop/ComputersShopFileImplement/Models/Shop.cs +++ b/ComputersShop/ComputersShopFileImplement/Models/Shop.cs @@ -12,35 +12,11 @@ namespace ComputersShopFileImplement.Models { public class Shop : IShopModel { - /// - /// Идентификатор - /// public int Id { get; private set; } - - /// - /// Название магазина - /// public string ShopName { get; private set; } = string.Empty; - - /// - /// Адрес магазина - /// public string Address { get; private set; } = string.Empty; - - /// - /// Дата открытия магазина - /// public DateTime DateOpening { get; private set; } - - /// - /// Коллекция изделий магазина в виде - /// «идентификатор изделия – количество изделий» - /// public Dictionary Computers { get; private set; } = new(); - - /// - /// Коллекция изделий в магазине - /// private Dictionary? _shopComputers = null; public Dictionary ShopComputers { @@ -54,17 +30,7 @@ namespace ComputersShopFileImplement.Models return _shopComputers; } } - - /// - /// Максимальное количество изделий - /// public int MaxComputers { get; private set; } - - /// - /// Создание модели магазина из данных файла - /// - /// - /// public static Shop? Create(XElement element) { if (element == null) @@ -82,12 +48,6 @@ namespace ComputersShopFileImplement.Models MaxComputers = Convert.ToInt32(element.Element("MaxComputers")!.Value) }; } - - /// - /// Создание модели магазина - /// - /// - /// public static Shop? Create(ShopBindingModel? model) { if (model == null) @@ -105,11 +65,6 @@ namespace ComputersShopFileImplement.Models MaxComputers = model.MaxComputers }; } - - /// - /// Изменение модели магазина - /// - /// public void Update(ShopBindingModel? model) { if (model == null) @@ -124,10 +79,6 @@ namespace ComputersShopFileImplement.Models MaxComputers = model.MaxComputers; _shopComputers = null; } - - /// - /// Получение модели магазина - /// public ShopViewModel GetViewModel => new() { Id = Id, @@ -137,10 +88,6 @@ namespace ComputersShopFileImplement.Models ShopComputers = ShopComputers, MaxComputers = MaxComputers }; - - /// - /// Запись данных о модели магазина в файл - /// public XElement GetXElement => new("Shop", new XAttribute("Id", Id), new XElement("ShopName", ShopName), diff --git a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs index 3b494bf..834470f 100644 --- a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs +++ b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs @@ -11,30 +11,10 @@ namespace AbstractShopListImplement public class DataListSingleton { private static DataListSingleton? _instance; - - /// - /// Список классов-моделей компонентов - /// public List Components { get; set; } - - /// - /// Список классов-моделей заказов - /// public List Orders { get; set; } - - /// - /// Список классов-моделей изделий - /// public List Computers { get; set; } - - /// - /// Список классов-моделей магазинов - /// public List Shops { get; set; } - - /// - /// Конструктор - /// private DataListSingleton() { Components = new List(); @@ -42,11 +22,6 @@ namespace AbstractShopListImplement Computers = new List(); Shops = new List(); } - - /// - /// Получить ссылку на класс - /// - /// public static DataListSingleton GetInstance() { if (_instance == null) diff --git a/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs index d9e9843..d2c1083 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/ComponentStorage.cs @@ -28,7 +28,7 @@ namespace ComputersShopListImplement.Implements } return result; } - public List GetFiltredList(ComponentSearchModel model) + public List GetFilteredList(ComponentSearchModel model) { var result = new List(); if (string.IsNullOrEmpty(model.ComponentName)) diff --git a/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs index df4ced8..ce9c38f 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/ComputerStorage.cs @@ -28,7 +28,7 @@ namespace ComputersShopListImplement.Implements } return result; } - public List GetFiltredList(ComputerSearchModel model) + public List GetFilteredList(ComputerSearchModel model) { var result = new List(); if (string.IsNullOrEmpty(model.ComputerName)) diff --git a/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs index 2b2be2d..a417571 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs @@ -15,19 +15,10 @@ namespace ComputersShopListImplement.Implements public class OrderStorage : IOrderStorage { private readonly DataListSingleton _source; - - /// - /// Конструктор - /// public OrderStorage() { _source = DataListSingleton.GetInstance(); } - - /// - /// Получение полного списка - /// - /// public List GetFullList() { var result = new List(); @@ -37,12 +28,6 @@ namespace ComputersShopListImplement.Implements } return result; } - - /// - /// Получение фильтрованного списка - /// - /// - /// public List GetFilteredList(OrderSearchModel model) { var result = new List(); @@ -60,12 +45,6 @@ namespace ComputersShopListImplement.Implements } return result; } - - /// - /// Получение элемента - /// - /// - /// public OrderViewModel? GetElement(OrderSearchModel model) { if (!model.Id.HasValue) @@ -82,12 +61,6 @@ namespace ComputersShopListImplement.Implements } return null; } - - /// - /// Добавление элемента - /// - /// - /// public OrderViewModel? Insert(OrderBindingModel model) { model.Id = 1; @@ -108,12 +81,6 @@ namespace ComputersShopListImplement.Implements _source.Orders.Add(newOrder); return newOrder.GetViewModel; } - - /// - /// Редактирование элемента - /// - /// - /// public OrderViewModel? Update(OrderBindingModel model) { foreach (var order in _source.Orders) @@ -126,12 +93,6 @@ namespace ComputersShopListImplement.Implements } return null; } - - /// - /// Удаление элемента - /// - /// - /// public OrderViewModel? Delete(OrderBindingModel model) { for (int i = 0; i < _source.Orders.Count; ++i) diff --git a/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs index 8eaadc0..a28d538 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs @@ -17,19 +17,10 @@ namespace ComputersShopListImplement.Implements public class ShopStorage : IShopStorage { private readonly DataListSingleton _source; - - /// - /// Конструктор - /// public ShopStorage() { _source = DataListSingleton.GetInstance(); } - - /// - /// Получение полного списка - /// - /// public List GetFullList() { var result = new List(); @@ -39,12 +30,6 @@ namespace ComputersShopListImplement.Implements } return result; } - - /// - /// Получение фильтрованного списка - /// - /// - /// public List GetFilteredList(ShopSearchModel model) { var result = new List(); @@ -62,12 +47,6 @@ namespace ComputersShopListImplement.Implements } return result; } - - /// - /// Получение элемента - /// - /// - /// public ShopViewModel? GetElement(ShopSearchModel model) { if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) @@ -84,12 +63,6 @@ namespace ComputersShopListImplement.Implements } return null; } - - /// - /// Добавление элемента - /// - /// - /// public ShopViewModel? Insert(ShopBindingModel model) { model.Id = 1; @@ -110,12 +83,6 @@ namespace ComputersShopListImplement.Implements _source.Shops.Add(newShop); return newShop.GetViewModel; } - - /// - /// Редактирование элемента - /// - /// - /// public ShopViewModel? Update(ShopBindingModel model) { foreach (var shop in _source.Shops) @@ -128,12 +95,6 @@ namespace ComputersShopListImplement.Implements } return null; } - - /// - /// Удаление элемента - /// - /// - /// public ShopViewModel? Delete(ShopBindingModel model) { for (int i = 0; i < _source.Shops.Count; ++i) @@ -147,26 +108,10 @@ namespace ComputersShopListImplement.Implements } return null; } - - /// - /// Продажа изделий - /// - /// - /// - /// - /// public bool SellComputers(IComputerModel model, int count) { throw new NotImplementedException(); } - - /// - /// Проверка наличия в нужном количестве - /// - /// - /// - /// - /// public bool CheckCount(IComputerModel model, int count) { throw new NotImplementedException(); diff --git a/ComputersShop/ComputersShopListImplement/Models/Shop.cs b/ComputersShop/ComputersShopListImplement/Models/Shop.cs index 44c0c7e..759d5e6 100644 --- a/ComputersShop/ComputersShopListImplement/Models/Shop.cs +++ b/ComputersShop/ComputersShopListImplement/Models/Shop.cs @@ -13,41 +13,15 @@ namespace ComputersShopListImplement.Models public class Shop : IShopModel { public int Id { get; private set; } - - /// - /// Название магазина - /// public string ShopName { get; private set; } = string.Empty; - - /// - /// Адрес магазина - /// public string Address { get; private set; } = string.Empty; - - /// - /// Дата открытия магазина - /// public DateTime DateOpening { get; private set; } - - /// - /// Коллекция изделий в магазине - /// public Dictionary ShopComputers { get; private set; } = new Dictionary(); - - /// - /// Максимальное количество изделий - /// public int MaxComputers { get; private set; } - - /// - /// Создание модели магазина - /// - /// - /// public static Shop? Create(ShopBindingModel? model) { if (model == null) @@ -65,11 +39,6 @@ namespace ComputersShopListImplement.Models MaxComputers = model.MaxComputers }; } - - /// - /// Изменение модели магазина - /// - /// public void Update(ShopBindingModel? model) { if (model == null) @@ -83,10 +52,6 @@ namespace ComputersShopListImplement.Models ShopComputers = model.ShopComputers; MaxComputers = model.MaxComputers; } - - /// - /// Получение модели магазина - /// public ShopViewModel GetViewModel => new() { Id = Id, diff --git a/ComputersShop/ComputersShopView/FormMain.Designer.cs b/ComputersShop/ComputersShopView/FormMain.Designer.cs index a6f14b8..0c656bf 100644 --- a/ComputersShop/ComputersShopView/FormMain.Designer.cs +++ b/ComputersShop/ComputersShopView/FormMain.Designer.cs @@ -34,13 +34,13 @@ this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.поставкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.продажаИзделийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); - this.продажаИзделийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -96,6 +96,13 @@ this.поставкиToolStripMenuItem.Text = "Поставки"; this.поставкиToolStripMenuItem.Click += new System.EventHandler(this.ПоставкиToolStripMenuItem_Click); // + // продажаИзделийToolStripMenuItem + // + this.продажаИзделийToolStripMenuItem.Name = "продажаИзделийToolStripMenuItem"; + this.продажаИзделийToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.продажаИзделийToolStripMenuItem.Text = "Продажа изделий"; + this.продажаИзделийToolStripMenuItem.Click += new System.EventHandler(this.ПродажаизделийToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -159,12 +166,6 @@ this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); // - // продажаИзделийToolStripMenuItem - // - this.продажаИзделийToolStripMenuItem.Name = "продажаИзделийToolStripMenuItem"; - this.продажаИзделийToolStripMenuItem.Size = new System.Drawing.Size(224, 26); - this.продажаИзделийToolStripMenuItem.Text = "Продажа изделий"; - // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); diff --git a/ComputersShop/ComputersShopView/FormShops.Designer.cs b/ComputersShop/ComputersShopView/FormShops.Designer.cs index e8fdfde..89b4bc9 100644 --- a/ComputersShop/ComputersShopView/FormShops.Designer.cs +++ b/ComputersShop/ComputersShopView/FormShops.Designer.cs @@ -39,16 +39,16 @@ // dataGridViewShops // this.dataGridViewShops.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridViewShops.Location = new System.Drawing.Point(1, 0); + this.dataGridViewShops.Location = new System.Drawing.Point(3, 1); this.dataGridViewShops.Name = "dataGridViewShops"; this.dataGridViewShops.RowHeadersWidth = 51; this.dataGridViewShops.RowTemplate.Height = 29; - this.dataGridViewShops.Size = new System.Drawing.Size(415, 453); + this.dataGridViewShops.Size = new System.Drawing.Size(572, 453); this.dataGridViewShops.TabIndex = 0; // // buttonAdd // - this.buttonAdd.Location = new System.Drawing.Point(434, 39); + this.buttonAdd.Location = new System.Drawing.Point(605, 41); this.buttonAdd.Name = "buttonAdd"; this.buttonAdd.Size = new System.Drawing.Size(94, 29); this.buttonAdd.TabIndex = 1; @@ -58,7 +58,7 @@ // // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(434, 94); + this.buttonUpdate.Location = new System.Drawing.Point(605, 96); this.buttonUpdate.Name = "buttonUpdate"; this.buttonUpdate.Size = new System.Drawing.Size(94, 29); this.buttonUpdate.TabIndex = 2; @@ -68,7 +68,7 @@ // // buttonDelete // - this.buttonDelete.Location = new System.Drawing.Point(434, 143); + this.buttonDelete.Location = new System.Drawing.Point(605, 145); this.buttonDelete.Name = "buttonDelete"; this.buttonDelete.Size = new System.Drawing.Size(94, 29); this.buttonDelete.TabIndex = 3; @@ -78,7 +78,7 @@ // // buttonRefresh // - this.buttonRefresh.Location = new System.Drawing.Point(434, 195); + this.buttonRefresh.Location = new System.Drawing.Point(605, 197); this.buttonRefresh.Name = "buttonRefresh"; this.buttonRefresh.Size = new System.Drawing.Size(94, 29); this.buttonRefresh.TabIndex = 4; @@ -90,7 +90,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(554, 450); + this.ClientSize = new System.Drawing.Size(733, 450); this.Controls.Add(this.buttonRefresh); this.Controls.Add(this.buttonDelete); this.Controls.Add(this.buttonUpdate); diff --git a/ComputersShop/ComputersShopView/Program.cs b/ComputersShop/ComputersShopView/Program.cs index c0d885b..8071061 100644 --- a/ComputersShop/ComputersShopView/Program.cs +++ b/ComputersShop/ComputersShopView/Program.cs @@ -1,7 +1,7 @@ using ComputersShopBusinessLogic.BusinessLogics; using ComputersShopContracts.BusinessLogicsContracts; using ComputersShopContracts.StoragesContracts; -using ComputersShopListImplement.Implements; +using ComputersShopFileImplement.Implements; using ComputersShopView; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -- 2.25.1