From 5ba88811e68bd97bca3ea47ba153ddc9b58a3d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B8=D1=88=D0=B5=D1=80=20=D0=91=D1=83=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Sun, 9 Apr 2023 01:35:16 +0400 Subject: [PATCH] First Labs Hard --- FishFactory/FishFactory.sln | 35 ++++ .../BusinessLogics/ShopLogic.cs | 152 ++++++++++++++ .../BindingModels/ShopBindingModel.cs | 20 ++ .../BusinessLogicsContracts/IShopLogic.cs | 17 ++ .../SearchModels/ShopSearchModel.cs | 8 + .../StoragesContracts/IShopStorage.cs | 16 ++ .../ViewModels/ShopViewModel.cs | 24 +++ .../Models/IShopModel.cs | 10 + .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 102 ++++++++++ .../FishFactoryListImplement/Models/Shop.cs | 53 +++++ .../FishFactoryView/FormMain.Designer.cs | 42 +++- FishFactory/FishFactoryView/FormMain.cs | 16 ++ .../FishFactoryView/FormShop.Designer.cs | 188 ++++++++++++++++++ FishFactory/FishFactoryView/FormShop.cs | 121 +++++++++++ FishFactory/FishFactoryView/FormShop.resx | 69 +++++++ .../FormShopCanned.Designer.cs | 151 ++++++++++++++ FishFactory/FishFactoryView/FormShopCanned.cs | 90 +++++++++ .../FishFactoryView/FormShopCanned.resx | 60 ++++++ .../FishFactoryView/FormShops.Designer.cs | 122 ++++++++++++ FishFactory/FishFactoryView/FormShops.cs | 102 ++++++++++ FishFactory/FishFactoryView/FormShops.resx | 60 ++++++ FishFactory/FishFactoryView/Program.cs | 15 ++ 23 files changed, 1469 insertions(+), 6 deletions(-) create mode 100644 FishFactory/FishFactoryBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs create mode 100644 FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 FishFactory/FishFactoryContracts/SearchModels/ShopSearchModel.cs create mode 100644 FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs create mode 100644 FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs create mode 100644 FishFactory/FishFactoryDataModels/Models/IShopModel.cs create mode 100644 FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs create mode 100644 FishFactory/FishFactoryListImplement/Models/Shop.cs create mode 100644 FishFactory/FishFactoryView/FormShop.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormShop.cs create mode 100644 FishFactory/FishFactoryView/FormShop.resx create mode 100644 FishFactory/FishFactoryView/FormShopCanned.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormShopCanned.cs create mode 100644 FishFactory/FishFactoryView/FormShopCanned.resx create mode 100644 FishFactory/FishFactoryView/FormShops.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormShops.cs create mode 100644 FishFactory/FishFactoryView/FormShops.resx diff --git a/FishFactory/FishFactory.sln b/FishFactory/FishFactory.sln index aeb1db6..6eedca2 100644 --- a/FishFactory/FishFactory.sln +++ b/FishFactory/FishFactory.sln @@ -3,6 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 +<<<<<<< Updated upstream Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDataModels", "FishFactoryDataModels\FishFactoryDataModels.csproj", "{D3365297-DF47-4830-BF3C-A24EE3E62B15}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryView", "FishFactoryView\FishFactoryView.csproj", "{2304F79F-E763-44E3-8CF6-50CFC3BDC288}" @@ -12,6 +13,17 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryBusinessLogic", "FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj", "{AC755273-7FEE-42B5-9BA1-5D17FF559C37}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryListImplement", "FishFactoryListImplement\FishFactoryListImplement.csproj", "{923C2993-D4F1-4480-B31C-B80F16575603}" +======= +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDataModels", "FishFactoryDataModels\FishFactoryDataModels.csproj", "{ABEC1828-156D-4B7F-927B-2495A2D8B660}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryContracts", "FishFactoryContracts\FishFactoryContracts.csproj", "{2CA5AB11-8934-4ACD-B600-FE4E3C6A0C5E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryBusinessLogic", "FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj", "{C2D0F702-2D82-4446-A6C4-DC296D915076}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryListImplement", "FishFactoryListImplement\FishFactoryListImplement.csproj", "{877A969D-0983-4044-8AB5-42EE3D7B22DF}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryView", "FishFactoryView\FishFactoryView.csproj", "{B25E8CDF-D3CC-4476-A213-2FC35EDFF4AC}" +>>>>>>> Stashed changes EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -19,6 +31,7 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution +<<<<<<< Updated upstream {D3365297-DF47-4830-BF3C-A24EE3E62B15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D3365297-DF47-4830-BF3C-A24EE3E62B15}.Debug|Any CPU.Build.0 = Debug|Any CPU {D3365297-DF47-4830-BF3C-A24EE3E62B15}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -39,6 +52,28 @@ Global {923C2993-D4F1-4480-B31C-B80F16575603}.Debug|Any CPU.Build.0 = Debug|Any CPU {923C2993-D4F1-4480-B31C-B80F16575603}.Release|Any CPU.ActiveCfg = Release|Any CPU {923C2993-D4F1-4480-B31C-B80F16575603}.Release|Any CPU.Build.0 = Release|Any CPU +======= + {ABEC1828-156D-4B7F-927B-2495A2D8B660}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ABEC1828-156D-4B7F-927B-2495A2D8B660}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ABEC1828-156D-4B7F-927B-2495A2D8B660}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ABEC1828-156D-4B7F-927B-2495A2D8B660}.Release|Any CPU.Build.0 = Release|Any CPU + {2CA5AB11-8934-4ACD-B600-FE4E3C6A0C5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2CA5AB11-8934-4ACD-B600-FE4E3C6A0C5E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2CA5AB11-8934-4ACD-B600-FE4E3C6A0C5E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2CA5AB11-8934-4ACD-B600-FE4E3C6A0C5E}.Release|Any CPU.Build.0 = Release|Any CPU + {C2D0F702-2D82-4446-A6C4-DC296D915076}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C2D0F702-2D82-4446-A6C4-DC296D915076}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C2D0F702-2D82-4446-A6C4-DC296D915076}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C2D0F702-2D82-4446-A6C4-DC296D915076}.Release|Any CPU.Build.0 = Release|Any CPU + {877A969D-0983-4044-8AB5-42EE3D7B22DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {877A969D-0983-4044-8AB5-42EE3D7B22DF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {877A969D-0983-4044-8AB5-42EE3D7B22DF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {877A969D-0983-4044-8AB5-42EE3D7B22DF}.Release|Any CPU.Build.0 = Release|Any CPU + {B25E8CDF-D3CC-4476-A213-2FC35EDFF4AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B25E8CDF-D3CC-4476-A213-2FC35EDFF4AC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B25E8CDF-D3CC-4476-A213-2FC35EDFF4AC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B25E8CDF-D3CC-4476-A213-2FC35EDFF4AC}.Release|Any CPU.Build.0 = Release|Any CPU +>>>>>>> Stashed changes EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ShopLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..f70e75f --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,152 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; + +namespace CannedBusinessLogic +{ + 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); + var list = model == null ? _shopStorage.GetFullList() : + _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName: {ShopName}. Id: {Id}", + model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + public bool Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + 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)); + } + _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", + model.ShopName, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id && element.ShopName == model.ShopName) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + public bool AddCannedInShop(ShopSearchModel model, ICannedModel Canned, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (count <= 0) + { + throw new ArgumentException("Количество консерв должно быть больше 0", nameof(count)); + } + _logger.LogInformation("AddCannedInShop. ShopName:{ShopName}.Id:{ Id}", + model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("AddCannedInShop element not found"); + return false; + } + _logger.LogInformation("AddCannedInShop find. Id:{Id}", element.Id); + + if (element.ListCanned.TryGetValue(Canned.Id, out var pair)) + { + element.ListCanned[Canned.Id] = (Canned, count + pair.Item2); + _logger.LogInformation( + "AddCannedInShop. Added {count} {Canned} to '{ShopName}' shop", + count, Canned.CannedName, element.ShopName); + } + else + { + element.ListCanned[Canned.Id] = (Canned, count); + _logger.LogInformation( + "AddCannedInShop. Added {count} new Canned {Canned} to '{ShopName}' shop", + count, Canned.CannedName, element.ShopName); + } + _shopStorage.Update(new() { + Id = element.Id, + Address = element.Address, + ShopName = element.ShopName, + DateOpening = element.DateOpening, + ListCanned = element.ListCanned + }); + return true; + } + } +} diff --git a/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..f705760 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,20 @@ +using FishFactoryDataModels.Models; + +namespace FishFactoryContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ListCanned + { + get; + set; + } = new(); + } +} diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..57a066c --- /dev/null +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,17 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; + +namespace FishFactoryContracts.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 AddCannedInShop(ShopSearchModel model, ICannedModel canned, int count); + } +} diff --git a/FishFactory/FishFactoryContracts/SearchModels/ShopSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..01ebb7b --- /dev/null +++ b/FishFactory/FishFactoryContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,8 @@ +namespace FishFactoryContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} diff --git a/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs b/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..7497bfb --- /dev/null +++ b/FishFactory/FishFactoryContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,16 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..16a158e --- /dev/null +++ b/FishFactory/FishFactoryContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,24 @@ +using FishFactoryDataModels.Models; +using System.ComponentModel; + +namespace FishFactoryContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ListCanned + { + get; + set; + } = new(); + } +} diff --git a/FishFactory/FishFactoryDataModels/Models/IShopModel.cs b/FishFactory/FishFactoryDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..595bb36 --- /dev/null +++ b/FishFactory/FishFactoryDataModels/Models/IShopModel.cs @@ -0,0 +1,10 @@ +namespace FishFactoryDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Address { get; } + DateTime DateOpening { get; } + Dictionary ListCanned { get; } + } +} diff --git a/FishFactory/FishFactoryListImplement/DataListSingleton.cs b/FishFactory/FishFactoryListImplement/DataListSingleton.cs index cd30178..2240543 100644 --- a/FishFactory/FishFactoryListImplement/DataListSingleton.cs +++ b/FishFactory/FishFactoryListImplement/DataListSingleton.cs @@ -8,12 +8,14 @@ namespace FishFactoryListImplement public List Ingredients { get; set; } public List Orders { get; set; } public List ListCanned { get; set; } + public List Shops { get; set; } private DataListSingleton() { Ingredients = new List(); Orders = new List(); ListCanned = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() diff --git a/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs b/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..2a7b6ec --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Implements/ShopStorage.cs @@ -0,0 +1,102 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryListImplement.Models; + +namespace FishFactoryListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName ?? string.Empty)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && + shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FishFactory/FishFactoryListImplement/Models/Shop.cs b/FishFactory/FishFactoryListImplement/Models/Shop.cs new file mode 100644 index 0000000..80f590e --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Models/Shop.cs @@ -0,0 +1,53 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; + +namespace FishFactoryListImplement.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 ListCanned + { + 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, + DateOpening = model.DateOpening, + ListCanned = new() + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + ListCanned = model.ListCanned; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + ListCanned = ListCanned, + DateOpening = DateOpening, + }; + } +} diff --git a/FishFactory/FishFactoryView/FormMain.Designer.cs b/FishFactory/FishFactoryView/FormMain.Designer.cs index 416d7bb..81efd5b 100644 --- a/FishFactory/FishFactoryView/FormMain.Designer.cs +++ b/FishFactory/FishFactoryView/FormMain.Designer.cs @@ -32,11 +32,16 @@ this.reference_booksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ingredientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.cannedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); +<<<<<<< Updated upstream +======= + this.shopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); +>>>>>>> Stashed changes this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonSetToDone = new System.Windows.Forms.Button(); this.buttonSetToWork = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonAddCannedInShop = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); @@ -56,7 +61,8 @@ // this.reference_booksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ingredientsToolStripMenuItem, - this.cannedToolStripMenuItem}); + this.cannedToolStripMenuItem, + this.shopsToolStripMenuItem}); this.reference_booksToolStripMenuItem.Name = "reference_booksToolStripMenuItem"; this.reference_booksToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.reference_booksToolStripMenuItem.Text = "Справочники"; @@ -75,9 +81,19 @@ this.cannedToolStripMenuItem.Text = "Консервы"; this.cannedToolStripMenuItem.Click += new System.EventHandler(this.CannedToolStripMenuItem_Click); // +<<<<<<< Updated upstream +======= + // shopsToolStripMenuItem + // + this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; + this.shopsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.shopsToolStripMenuItem.Text = "Магазины"; + this.shopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); + // +>>>>>>> Stashed changes // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(780, 314); + this.buttonUpdate.Location = new System.Drawing.Point(781, 299); this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonUpdate.Name = "buttonUpdate"; this.buttonUpdate.Size = new System.Drawing.Size(170, 58); @@ -88,7 +104,7 @@ // // buttonSetToFinish // - this.buttonSetToFinish.Location = new System.Drawing.Point(780, 252); + this.buttonSetToFinish.Location = new System.Drawing.Point(781, 237); this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToFinish.Name = "buttonSetToFinish"; this.buttonSetToFinish.Size = new System.Drawing.Size(170, 58); @@ -99,7 +115,7 @@ // // buttonSetToDone // - this.buttonSetToDone.Location = new System.Drawing.Point(780, 190); + this.buttonSetToDone.Location = new System.Drawing.Point(781, 175); this.buttonSetToDone.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToDone.Name = "buttonSetToDone"; this.buttonSetToDone.Size = new System.Drawing.Size(170, 58); @@ -110,7 +126,7 @@ // // buttonSetToWork // - this.buttonSetToWork.Location = new System.Drawing.Point(780, 128); + this.buttonSetToWork.Location = new System.Drawing.Point(781, 113); this.buttonSetToWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToWork.Name = "buttonSetToWork"; this.buttonSetToWork.Size = new System.Drawing.Size(170, 58); @@ -121,7 +137,7 @@ // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(780, 66); + this.buttonCreateOrder.Location = new System.Drawing.Point(781, 51); this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreateOrder.Name = "buttonCreateOrder"; this.buttonCreateOrder.Size = new System.Drawing.Size(170, 58); @@ -142,6 +158,17 @@ this.dataGridView.Size = new System.Drawing.Size(755, 426); this.dataGridView.TabIndex = 7; // + // buttonAddCannedInShop + // + this.buttonAddCannedInShop.Location = new System.Drawing.Point(781, 361); + this.buttonAddCannedInShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAddCannedInShop.Name = "buttonAddCannedInShop"; + this.buttonAddCannedInShop.Size = new System.Drawing.Size(170, 58); + this.buttonAddCannedInShop.TabIndex = 13; + this.buttonAddCannedInShop.Text = "Добавить консерву в магазин"; + this.buttonAddCannedInShop.UseVisualStyleBackColor = true; + this.buttonAddCannedInShop.Click += new System.EventHandler(this.ButtonAddCannedInShop_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -152,6 +179,7 @@ this.Controls.Add(this.buttonSetToDone); this.Controls.Add(this.buttonSetToWork); this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.buttonAddCannedInShop); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip); this.MainMenuStrip = this.menuStrip; @@ -172,11 +200,13 @@ private ToolStripMenuItem reference_booksToolStripMenuItem; private ToolStripMenuItem ingredientsToolStripMenuItem; private ToolStripMenuItem cannedToolStripMenuItem; + private ToolStripMenuItem shopsToolStripMenuItem; private Button buttonUpdate; private Button buttonSetToFinish; private Button buttonSetToDone; private Button buttonSetToWork; private Button buttonCreateOrder; + private Button buttonAddCannedInShop; private DataGridView dataGridView; } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormMain.cs b/FishFactory/FishFactoryView/FormMain.cs index 9ee7eeb..730bf94 100644 --- a/FishFactory/FishFactoryView/FormMain.cs +++ b/FishFactory/FishFactoryView/FormMain.cs @@ -53,6 +53,22 @@ namespace FishFactoryView { form.ShowDialog(); } + } + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void ButtonAddCannedInShop_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopCanned)); + if (service is FormShopCanned form) + { + form.ShowDialog(); + } } private void ButtonCreateOrder_Click(object sender, EventArgs e) { diff --git a/FishFactory/FishFactoryView/FormShop.Designer.cs b/FishFactory/FishFactoryView/FormShop.Designer.cs new file mode 100644 index 0000000..73ec9d7 --- /dev/null +++ b/FishFactory/FishFactoryView/FormShop.Designer.cs @@ -0,0 +1,188 @@ +namespace FishFactoryView +{ + 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.labelTime = new System.Windows.Forms.Label(); + this.labelAddress = new System.Windows.Forms.Label(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.labelShop = new System.Windows.Forms.Label(); + this.textBoxShop = new System.Windows.Forms.TextBox(); + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.ColumnID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCannedName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(364, 303); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(120, 22); + this.buttonSave.TabIndex = 17; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(490, 302); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(103, 23); + this.buttonCancel.TabIndex = 16; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(159, 27); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(221, 23); + this.textBoxAddress.TabIndex = 14; + // + // labelTime + // + this.labelTime.AutoSize = true; + this.labelTime.Location = new System.Drawing.Point(386, 9); + this.labelTime.Name = "labelTime"; + this.labelTime.Size = new System.Drawing.Size(87, 15); + this.labelTime.TabIndex = 13; + this.labelTime.Text = "Дата открытия"; + // + // labelAddress + // + this.labelAddress.AutoSize = true; + this.labelAddress.Location = new System.Drawing.Point(159, 9); + this.labelAddress.Name = "labelAddress"; + this.labelAddress.Size = new System.Drawing.Size(40, 15); + this.labelAddress.TabIndex = 12; + this.labelAddress.Text = "Адрес"; + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnID, + this.ColumnCannedName, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(12, 56); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(581, 240); + this.dataGridView.TabIndex = 11; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(12, 9); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(54, 15); + this.labelShop.TabIndex = 9; + this.labelShop.Text = "Магазин"; + // + // textBoxShop + // + this.textBoxShop.Location = new System.Drawing.Point(12, 27); + this.textBoxShop.Name = "textBoxShop"; + this.textBoxShop.Size = new System.Drawing.Size(141, 23); + this.textBoxShop.TabIndex = 18; + // + // dateTimePicker + // + this.dateTimePicker.Location = new System.Drawing.Point(386, 27); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(207, 23); + this.dateTimePicker.TabIndex = 19; + // + // ColumnID + // + this.ColumnID.HeaderText = "ID"; + this.ColumnID.Name = "ColumnID"; + this.ColumnID.Visible = false; + // + // ColumnCannedName + // + this.ColumnCannedName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnCannedName.HeaderText = "Консерва"; + this.ColumnCannedName.Name = "ColumnCannedName"; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.Name = "ColumnCount"; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(605, 337); + this.Controls.Add(this.dateTimePicker); + this.Controls.Add(this.textBoxShop); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.labelTime); + this.Controls.Add(this.labelAddress); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.labelShop); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); + this.Click += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxAddress; + private Label labelTime; + private Label labelAddress; + private DataGridView dataGridView; + private Label labelShop; + private TextBox textBoxShop; + private DateTimePicker dateTimePicker; + private DataGridViewTextBoxColumn ColumnID; + private DataGridViewTextBoxColumn ColumnCannedName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormShop.cs b/FishFactory/FishFactoryView/FormShop.cs new file mode 100644 index 0000000..8c47d0a --- /dev/null +++ b/FishFactory/FishFactoryView/FormShop.cs @@ -0,0 +1,121 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryDataModels.Models; + +namespace FishFactoryView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + private Dictionary _shopListCanned; + public int Id { set { _id = value; } } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopListCanned = new(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxShop.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Text = view.DateOpening.ToString(); + _shopListCanned = view.ListCanned ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка консервы магазина"); + try + { + if (_shopListCanned != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in _shopListCanned) + { + dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.CannedName, elem.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки консерв магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxShop.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxShop.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value.Date, + ListCanned = _shopListCanned + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FishFactory/FishFactoryView/FormShop.resx b/FishFactory/FishFactoryView/FormShop.resx new file mode 100644 index 0000000..aa7de0d --- /dev/null +++ b/FishFactory/FishFactoryView/FormShop.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormShopCanned.Designer.cs b/FishFactory/FishFactoryView/FormShopCanned.Designer.cs new file mode 100644 index 0000000..68b1379 --- /dev/null +++ b/FishFactory/FishFactoryView/FormShopCanned.Designer.cs @@ -0,0 +1,151 @@ +namespace FishFactoryView +{ + partial class FormShopCanned + { + /// + /// 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.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); + this.comboBoxCanned = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelCanned = new System.Windows.Forms.Label(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelShop = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); + this.SuspendLayout(); + // + // numericUpDownCount + // + this.numericUpDownCount.Location = new System.Drawing.Point(87, 62); + this.numericUpDownCount.Maximum = new decimal(new int[] { + 1410065408, + 2, + 0, + 0}); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.Size = new System.Drawing.Size(344, 23); + this.numericUpDownCount.TabIndex = 13; + // + // comboBoxCanned + // + this.comboBoxCanned.FormattingEnabled = true; + this.comboBoxCanned.Location = new System.Drawing.Point(86, 35); + this.comboBoxCanned.Name = "comboBoxCanned"; + this.comboBoxCanned.Size = new System.Drawing.Size(345, 23); + this.comboBoxCanned.TabIndex = 12; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(9, 64); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(72, 15); + this.labelCount.TabIndex = 11; + this.labelCount.Text = "Количество"; + // + // labelCanned + // + this.labelCanned.AutoSize = true; + this.labelCanned.Location = new System.Drawing.Point(21, 38); + this.labelCanned.Name = "labelCanned"; + this.labelCanned.Size = new System.Drawing.Size(59, 15); + this.labelCanned.TabIndex = 10; + this.labelCanned.Text = "Консерва"; + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(86, 8); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(345, 23); + this.comboBoxShop.TabIndex = 9; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(26, 11); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(54, 15); + this.labelShop.TabIndex = 8; + this.labelShop.Text = "Магазин"; + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(356, 94); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(275, 94); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 14; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormShopCanned + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(443, 129); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.numericUpDownCount); + this.Controls.Add(this.comboBoxCanned); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelCanned); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.labelShop); + this.Name = "FormShopCanned"; + this.Text = "Поступление консервы в рыбный завод"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private NumericUpDown numericUpDownCount; + private ComboBox comboBoxCanned; + private Label labelCount; + private Label labelCanned; + private ComboBox comboBoxShop; + private Label labelShop; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormShopCanned.cs b/FishFactory/FishFactoryView/FormShopCanned.cs new file mode 100644 index 0000000..a1173bc --- /dev/null +++ b/FishFactory/FishFactoryView/FormShopCanned.cs @@ -0,0 +1,90 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryView +{ + public partial class FormShopCanned : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + private readonly ICannedLogic _CannedLogic; + private readonly List? _listShops; + private readonly List? _listCanned; + + public FormShopCanned(ILogger logger, IShopLogic shopLogic, ICannedLogic CannedLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _CannedLogic = CannedLogic; + _logger = logger; + _listShops = shopLogic.ReadList(null); + if (_listShops != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _listShops; + comboBoxShop.SelectedItem = null; + } + + _listCanned = CannedLogic.ReadList(null); + if (_listCanned != null) + { + comboBoxCanned.DisplayMember = "CannedName"; + comboBoxCanned.ValueMember = "Id"; + comboBoxCanned.DataSource = _listCanned; + comboBoxCanned.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxCanned.SelectedValue == null) + { + MessageBox.Show("Выберите консерву", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Добавление консервы в магазин"); + try + { + var сanned = _CannedLogic.ReadElement(new() + { + Id = (int)comboBoxCanned.SelectedValue + }); + if (сanned == null) + { + throw new Exception("Не найдено консерва. Дополнительная информация в логах."); + } + var resultOperation = _shopLogic.AddCannedInShop( + model: new() { Id = (int)comboBoxShop.SelectedValue }, + canned: сanned, + count: (int)numericUpDownCount.Value + ); + if (!resultOperation) + { + 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/FishFactory/FishFactoryView/FormShopCanned.resx b/FishFactory/FishFactoryView/FormShopCanned.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactoryView/FormShopCanned.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/FishFactory/FishFactoryView/FormShops.Designer.cs b/FishFactory/FishFactoryView/FormShops.Designer.cs new file mode 100644 index 0000000..e147e03 --- /dev/null +++ b/FishFactory/FishFactoryView/FormShops.Designer.cs @@ -0,0 +1,122 @@ +namespace FishFactoryView +{ + 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(426, 333); + this.dataGridView.TabIndex = 10; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(432, 175); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 14; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(432, 149); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 13; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(432, 123); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 12; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(432, 97); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(566, 333); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormShops.cs b/FishFactory/FishFactoryView/FormShops.cs new file mode 100644 index 0000000..20350cf --- /dev/null +++ b/FishFactory/FishFactoryView/FormShops.cs @@ -0,0 +1,102 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; + +namespace FishFactoryView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ListCanned"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FishFactory/FishFactoryView/FormShops.resx b/FishFactory/FishFactoryView/FormShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactoryView/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/FishFactory/FishFactoryView/Program.cs b/FishFactory/FishFactoryView/Program.cs index 1356160..803a597 100644 --- a/FishFactory/FishFactoryView/Program.cs +++ b/FishFactory/FishFactoryView/Program.cs @@ -5,7 +5,11 @@ using FishFactoryBusinessLogic.BusinessLogics; using FishFactoryContracts.BusinessLogicsContracts; using FishFactoryContracts.StoragesContracts; using FishFactoryListImplement.Implements; +<<<<<<< Updated upstream using FishFactoryView; +======= +using CannedBusinessLogic; +>>>>>>> Stashed changes namespace FishFactoryView { @@ -40,9 +44,14 @@ namespace FishFactoryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); +<<<<<<< Updated upstream +======= + services.AddTransient(); +>>>>>>> Stashed changes services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -50,6 +59,12 @@ namespace FishFactoryView services.AddTransient(); services.AddTransient(); services.AddTransient(); +<<<<<<< Updated upstream +======= + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); +>>>>>>> Stashed changes } } } -- 2.25.1