From d747d797fc8b66a16556a0ffaeb5bbf7c276f27c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sun, 5 Feb 2023 14:44:03 +0400 Subject: [PATCH 01/15] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20"=D0=9C=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/ShopBindingModel.cs | 12 ++++++++++++ .../SearchModels/ShopSearchModel.cs | 9 +++++++++ .../StoragesContract/IShopStorage.cs | 12 ++++++++++++ ConfectioneryContracts/ViewModels/ShopViewModel.cs | 12 ++++++++++++ ConfectioneryDataModels/IShopModel.cs | 12 ++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 ConfectioneryContracts/BindingModels/ShopBindingModel.cs create mode 100644 ConfectioneryContracts/SearchModels/ShopSearchModel.cs create mode 100644 ConfectioneryContracts/StoragesContract/IShopStorage.cs create mode 100644 ConfectioneryContracts/ViewModels/ShopViewModel.cs create mode 100644 ConfectioneryDataModels/IShopModel.cs diff --git a/ConfectioneryContracts/BindingModels/ShopBindingModel.cs b/ConfectioneryContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..764dc63 --- /dev/null +++ b/ConfectioneryContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BindingModels +{ + internal interface ShopBindingModel + { + } +} diff --git a/ConfectioneryContracts/SearchModels/ShopSearchModel.cs b/ConfectioneryContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..d3c5547 --- /dev/null +++ b/ConfectioneryContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,9 @@ + +namespace ConfectioneryContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/ConfectioneryContracts/StoragesContract/IShopStorage.cs b/ConfectioneryContracts/StoragesContract/IShopStorage.cs new file mode 100644 index 0000000..27ad4f6 --- /dev/null +++ b/ConfectioneryContracts/StoragesContract/IShopStorage.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContract +{ + internal interface IShopStorage + { + } +} diff --git a/ConfectioneryContracts/ViewModels/ShopViewModel.cs b/ConfectioneryContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..dbfc7c6 --- /dev/null +++ b/ConfectioneryContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.ViewModels +{ + internal class ShopViewModel + { + } +} diff --git a/ConfectioneryDataModels/IShopModel.cs b/ConfectioneryDataModels/IShopModel.cs new file mode 100644 index 0000000..7315e2f --- /dev/null +++ b/ConfectioneryDataModels/IShopModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels +{ + internal interface IShopModel + { + } +} -- 2.25.1 From 2aa903dd99bc82c707817f60891dd2adf560e768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sun, 5 Feb 2023 14:55:50 +0400 Subject: [PATCH 02/15] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20"?= =?UTF-8?q?=D0=9C=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryBusinessLogic/ShopLogic.cs | 12 ++++++++++++ .../BusinessLogicsContracts/IShopLogic.cs | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 ConfectionaryBusinessLogic/ShopLogic.cs create mode 100644 ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs diff --git a/ConfectionaryBusinessLogic/ShopLogic.cs b/ConfectionaryBusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..235b2b4 --- /dev/null +++ b/ConfectionaryBusinessLogic/ShopLogic.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic +{ + internal class ShopLogic + { + } +} diff --git a/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs b/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..41a4e0e --- /dev/null +++ b/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + internal interface IShopLogic + { + } +} -- 2.25.1 From 873df1007e9248ea3ca74aa70c8f2c0d67be3189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sun, 5 Feb 2023 15:14:18 +0400 Subject: [PATCH 03/15] fix --- .../BindingModels/ShopBindingModel.cs | 22 +++++++++++----- .../ViewModels/ShopViewModel.cs | 26 ++++++++++++++----- ConfectioneryDataModels/IShopModel.cs | 12 ++++----- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/ConfectioneryContracts/BindingModels/ShopBindingModel.cs b/ConfectioneryContracts/BindingModels/ShopBindingModel.cs index 764dc63..991d04b 100644 --- a/ConfectioneryContracts/BindingModels/ShopBindingModel.cs +++ b/ConfectioneryContracts/BindingModels/ShopBindingModel.cs @@ -1,12 +1,22 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using ConfectioneryDataModels; +using ConfectioneryDataModels.Models; namespace ConfectioneryContracts.BindingModels { - internal interface ShopBindingModel + public class ShopBindingModel : IShopModel { + public string Name { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary Pastries + { + get; + set; + } = new(); + + public int Id { get; set; } } } diff --git a/ConfectioneryContracts/ViewModels/ShopViewModel.cs b/ConfectioneryContracts/ViewModels/ShopViewModel.cs index dbfc7c6..dd01f43 100644 --- a/ConfectioneryContracts/ViewModels/ShopViewModel.cs +++ b/ConfectioneryContracts/ViewModels/ShopViewModel.cs @@ -1,12 +1,26 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using ConfectioneryDataModels; +using ConfectioneryDataModels.Models; +using System.ComponentModel; namespace ConfectioneryContracts.ViewModels { - internal class ShopViewModel + public class ShopViewModel : IShopModel { + [DisplayName("Название магазина")] + public string Name { get; set; } = string.Empty; + + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Время открытия")] + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary Pastries + { + get; + set; + } = new(); + + public int Id { get; set; } } } diff --git a/ConfectioneryDataModels/IShopModel.cs b/ConfectioneryDataModels/IShopModel.cs index 7315e2f..1f1e07f 100644 --- a/ConfectioneryDataModels/IShopModel.cs +++ b/ConfectioneryDataModels/IShopModel.cs @@ -1,12 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using ConfectioneryDataModels.Models; namespace ConfectioneryDataModels { - internal interface IShopModel + public interface IShopModel : IId { + string Name { get; } + string Address { get; } + DateTime DateOpening { get; } + Dictionary Pastries { get; } } } -- 2.25.1 From ed54dc6fbe58f5646476284689a061ba10df086d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sun, 5 Feb 2023 15:15:38 +0400 Subject: [PATCH 04/15] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20"?= =?UTF-8?q?=D0=9C=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryBusinessLogic/ShopLogic.cs | 131 +++++++++++++++++- .../DataListSingleton.cs | 2 + ConfectionaryListImplement/Shop.cs | 58 ++++++++ ConfectionaryListImplement/ShopStorage.cs | 46 ++++++ .../BindingModels/ShopBindingModel.cs | 2 +- .../BusinessLogicsContracts/IShopLogic.cs | 17 ++- .../StoragesContract/IShopStorage.cs | 16 ++- .../ViewModels/ShopViewModel.cs | 2 +- ConfectioneryDataModels/IShopModel.cs | 2 +- 9 files changed, 254 insertions(+), 22 deletions(-) create mode 100644 ConfectionaryListImplement/Shop.cs create mode 100644 ConfectionaryListImplement/ShopStorage.cs diff --git a/ConfectionaryBusinessLogic/ShopLogic.cs b/ConfectionaryBusinessLogic/ShopLogic.cs index 235b2b4..c32a715 100644 --- a/ConfectionaryBusinessLogic/ShopLogic.cs +++ b/ConfectionaryBusinessLogic/ShopLogic.cs @@ -1,12 +1,129 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using ConfectioneryBusinessLogic.BusinessLogics; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContract; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using Microsoft.Extensions.Logging; namespace ConfectioneryBusinessLogic { - internal class ShopLogic - { + 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?.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 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.Name)) + { + throw new ArgumentNullException("Нет названия магазина", + nameof(model.Name)); + } + _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", + model.Name, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + public bool AddPastry(ShopSearchModel model, IPastryModel pastry, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("AddPastryInShop. ShopName:{ShopName}.Id:{ Id}", + model.Name, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("AddPastryInShop element not found"); + return false; + } + _logger.LogInformation("AddPastryInShop find. Id:{Id}", element.Id); + + return element.Pastries.TryAdd(pastry.Id, (pastry, count)); + } } } diff --git a/ConfectionaryListImplement/DataListSingleton.cs b/ConfectionaryListImplement/DataListSingleton.cs index 24ae616..dab3ef1 100644 --- a/ConfectionaryListImplement/DataListSingleton.cs +++ b/ConfectionaryListImplement/DataListSingleton.cs @@ -8,11 +8,13 @@ namespace ConfectioneryListImplement public List Components { get; set; } public List Orders { get; set; } public List Pastry { get; set; } + public List Shop { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Pastry = new List(); + Shop = new List(); } public static DataListSingleton GetInstance() { diff --git a/ConfectionaryListImplement/Shop.cs b/ConfectionaryListImplement/Shop.cs new file mode 100644 index 0000000..c1a7630 --- /dev/null +++ b/ConfectionaryListImplement/Shop.cs @@ -0,0 +1,58 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels; +using ConfectioneryDataModels.Models; + +namespace ConfectioneryListImplement +{ + public class Shop : IShopModel + { + public string Name { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + + public Dictionary Pastries + { + get; + private set; + } = new(); + + public int Id { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + DateOpening = model.DateOpening, + Pastries = model.Pastries + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + Address = model.Address; + DateOpening = model.DateOpening; + Pastries = model.Pastries; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + Pastries = Pastries + }; + } +} diff --git a/ConfectionaryListImplement/ShopStorage.cs b/ConfectionaryListImplement/ShopStorage.cs new file mode 100644 index 0000000..d7c3547 --- /dev/null +++ b/ConfectionaryListImplement/ShopStorage.cs @@ -0,0 +1,46 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContract; +using ConfectioneryContracts.ViewModels; + +namespace ConfectioneryListImplement +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + throw new NotImplementedException(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFilteredList(ShopSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFullList() + { + throw new NotImplementedException(); + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + throw new NotImplementedException(); + } + + public ShopViewModel? Update(ShopBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/ConfectioneryContracts/BindingModels/ShopBindingModel.cs b/ConfectioneryContracts/BindingModels/ShopBindingModel.cs index 991d04b..38d8750 100644 --- a/ConfectioneryContracts/BindingModels/ShopBindingModel.cs +++ b/ConfectioneryContracts/BindingModels/ShopBindingModel.cs @@ -11,7 +11,7 @@ namespace ConfectioneryContracts.BindingModels public DateTime DateOpening { get; set; } = DateTime.Now; - public Dictionary Pastries + public Dictionary Pastries { get; set; diff --git a/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs b/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs index 41a4e0e..3ba0749 100644 --- a/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/ConfectioneryContracts/BusinessLogicsContracts/IShopLogic.cs @@ -1,12 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; namespace ConfectioneryContracts.BusinessLogicsContracts { - internal interface IShopLogic + public interface IShopLogic { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool AddPastry(ShopSearchModel model, IPastryModel pastry, int count); } } diff --git a/ConfectioneryContracts/StoragesContract/IShopStorage.cs b/ConfectioneryContracts/StoragesContract/IShopStorage.cs index 27ad4f6..4276f2d 100644 --- a/ConfectioneryContracts/StoragesContract/IShopStorage.cs +++ b/ConfectioneryContracts/StoragesContract/IShopStorage.cs @@ -1,12 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; namespace ConfectioneryContracts.StoragesContract { - internal interface IShopStorage + 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/ConfectioneryContracts/ViewModels/ShopViewModel.cs b/ConfectioneryContracts/ViewModels/ShopViewModel.cs index dd01f43..a87ca8d 100644 --- a/ConfectioneryContracts/ViewModels/ShopViewModel.cs +++ b/ConfectioneryContracts/ViewModels/ShopViewModel.cs @@ -15,7 +15,7 @@ namespace ConfectioneryContracts.ViewModels [DisplayName("Время открытия")] public DateTime DateOpening { get; set; } = DateTime.Now; - public Dictionary Pastries + public Dictionary Pastries { get; set; diff --git a/ConfectioneryDataModels/IShopModel.cs b/ConfectioneryDataModels/IShopModel.cs index 1f1e07f..c0883e9 100644 --- a/ConfectioneryDataModels/IShopModel.cs +++ b/ConfectioneryDataModels/IShopModel.cs @@ -7,6 +7,6 @@ namespace ConfectioneryDataModels string Name { get; } string Address { get; } DateTime DateOpening { get; } - Dictionary Pastries { get; } + Dictionary Pastries { get; } } } -- 2.25.1 From d86f89eca47f3b9eadae62ec9c3248f07a2dd285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sun, 5 Feb 2023 17:05:49 +0400 Subject: [PATCH 05/15] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20"=D0=9C?= =?UTF-8?q?=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryBusinessLogic/ShopLogic.cs | 2 + .../DataListSingleton.cs | 4 +- ConfectionaryListImplement/ShopStorage.cs | 73 +++++++++++++++++-- 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/ConfectionaryBusinessLogic/ShopLogic.cs b/ConfectionaryBusinessLogic/ShopLogic.cs index c32a715..920f493 100644 --- a/ConfectionaryBusinessLogic/ShopLogic.cs +++ b/ConfectionaryBusinessLogic/ShopLogic.cs @@ -52,6 +52,7 @@ namespace ConfectioneryBusinessLogic public bool Create(ShopBindingModel model) { CheckModel(model); + model.Pastries = new(); if (_shopStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -62,6 +63,7 @@ namespace ConfectioneryBusinessLogic public bool Update(ShopBindingModel model) { CheckModel(model); + model.Pastries = new(); if (_shopStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); diff --git a/ConfectionaryListImplement/DataListSingleton.cs b/ConfectionaryListImplement/DataListSingleton.cs index dab3ef1..b34de5e 100644 --- a/ConfectionaryListImplement/DataListSingleton.cs +++ b/ConfectionaryListImplement/DataListSingleton.cs @@ -8,13 +8,13 @@ namespace ConfectioneryListImplement public List Components { get; set; } public List Orders { get; set; } public List Pastry { get; set; } - public List Shop { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Pastry = new List(); - Shop = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/ConfectionaryListImplement/ShopStorage.cs b/ConfectionaryListImplement/ShopStorage.cs index d7c3547..893b6ad 100644 --- a/ConfectionaryListImplement/ShopStorage.cs +++ b/ConfectionaryListImplement/ShopStorage.cs @@ -15,32 +15,93 @@ namespace ConfectioneryListImplement public ShopViewModel? Delete(ShopBindingModel model) { - throw new NotImplementedException(); + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; } public ShopViewModel? GetElement(ShopSearchModel model) { - throw new NotImplementedException(); + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.Name) && + shop.Name == model.Name) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; } public List GetFilteredList(ShopSearchModel model) { - throw new NotImplementedException(); + var result = new List(); + if (string.IsNullOrEmpty(model.Name)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.Name.Contains(model.Name ?? string.Empty)) + { + result.Add(shop.GetViewModel); + } + } + return result; } public List GetFullList() { - throw new NotImplementedException(); + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; } public ShopViewModel? Insert(ShopBindingModel model) { - throw new NotImplementedException(); + 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) { - throw new NotImplementedException(); + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; } } } -- 2.25.1 From b4673cefc0308faada2d8779d5315cb8709c34c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sun, 5 Feb 2023 17:13:36 +0400 Subject: [PATCH 06/15] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Confectionery/FormComponents.cs | 19 +--- Confectionery/FormViewShops.Designer.cs | 120 ++++++++++++++++++++++++ Confectionery/FormViewShops.cs | 116 +++++++++++++++++++++++ Confectionery/FormViewShops.resx | 60 ++++++++++++ 4 files changed, 301 insertions(+), 14 deletions(-) create mode 100644 Confectionery/FormViewShops.Designer.cs create mode 100644 Confectionery/FormViewShops.cs create mode 100644 Confectionery/FormViewShops.resx diff --git a/Confectionery/FormComponents.cs b/Confectionery/FormComponents.cs index c93c9ed..b869d81 100644 --- a/Confectionery/FormComponents.cs +++ b/Confectionery/FormComponents.cs @@ -1,15 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.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 ConfectioneryView { @@ -36,14 +27,14 @@ namespace ConfectioneryView { dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } - _logger.LogInformation("Загрузка компонентов"); + _logger.LogInformation("Загрузка магазинов"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонентов"); + _logger.LogError(ex, "Ошибка загрузки магазинов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -87,7 +78,7 @@ namespace ConfectioneryView { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление компонента"); + _logger.LogInformation("Удаление магазина"); try { if (!_logic.Delete(new ComponentBindingModel @@ -101,7 +92,7 @@ namespace ConfectioneryView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления компонента"); + _logger.LogError(ex, "Ошибка удаления магазина"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } diff --git a/Confectionery/FormViewShops.Designer.cs b/Confectionery/FormViewShops.Designer.cs new file mode 100644 index 0000000..82f254a --- /dev/null +++ b/Confectionery/FormViewShops.Designer.cs @@ -0,0 +1,120 @@ +namespace ConfectioneryView +{ + partial class FormViewShops + { + /// + /// 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.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRef.Location = new System.Drawing.Point(685, 202); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(90, 37); + this.buttonRef.TabIndex = 14; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDel.Location = new System.Drawing.Point(685, 151); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(90, 33); + this.buttonDel.TabIndex = 13; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUpd.Location = new System.Drawing.Point(685, 102); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(90, 34); + this.buttonUpd.TabIndex = 12; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonAdd.Location = new System.Drawing.Point(685, 57); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(90, 30); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // 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.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(540, 379); + this.dataGridView.TabIndex = 10; + // + // FormViewShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(787, 403); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormViewShops"; + this.Text = "Просмотр магазинов"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Confectionery/FormViewShops.cs b/Confectionery/FormViewShops.cs new file mode 100644 index 0000000..6c443d2 --- /dev/null +++ b/Confectionery/FormViewShops.cs @@ -0,0 +1,116 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.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 ConfectioneryView +{ + public partial class FormViewShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormViewShops(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["Name"].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(FormComponent)); + if (service is FormComponent 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(FormComponent)); + if (service is FormComponent 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/Confectionery/FormViewShops.resx b/Confectionery/FormViewShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/FormViewShops.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 -- 2.25.1 From fccf69ebd23e733ff6ccec4597cd79923a0ec4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sun, 5 Feb 2023 17:33:20 +0400 Subject: [PATCH 07/15] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D1=81=D0=BC=D0=BE=D1=82=D1=80=D0=B0=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D0=BA=D1=80=D0=B5=D1=82=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BC?= =?UTF-8?q?=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Confectionery/FormShop.Designer.cs | 89 ++++++++++++++++++++++++++++++ Confectionery/FormShop.cs | 65 ++++++++++++++++++++++ Confectionery/FormShop.resx | 60 ++++++++++++++++++++ 3 files changed, 214 insertions(+) create mode 100644 Confectionery/FormShop.Designer.cs create mode 100644 Confectionery/FormShop.cs create mode 100644 Confectionery/FormShop.resx diff --git a/Confectionery/FormShop.Designer.cs b/Confectionery/FormShop.Designer.cs new file mode 100644 index 0000000..da10c27 --- /dev/null +++ b/Confectionery/FormShop.Designer.cs @@ -0,0 +1,89 @@ +namespace ConfectioneryView +{ + 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.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(124, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Выбранный магазин:"; + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(142, 9); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(121, 23); + this.comboBoxShop.TabIndex = 1; + this.comboBoxShop.SelectedIndexChanged += new System.EventHandler(this.ComboBoxShop_SelectedIndexChanged); + // + // 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.Location = new System.Drawing.Point(12, 38); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(583, 242); + this.dataGridView.TabIndex = 2; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(607, 292); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.comboBoxShop); + 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 ComboBox comboBoxShop; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Confectionery/FormShop.cs b/Confectionery/FormShop.cs new file mode 100644 index 0000000..f677a26 --- /dev/null +++ b/Confectionery/FormShop.cs @@ -0,0 +1,65 @@ +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormShop : Form + { + private readonly List? _list; + private readonly IShopLogic _logic; + private readonly ILogger _logger; + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _list = logic.ReadList(null); + _logic = logic; + if (_list != null) + { + comboBoxShop.DisplayMember = "ComponentName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _list; + comboBoxShop.SelectedItem = null; + } + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ComboBoxShop_SelectedIndexChanged(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Confectionery/FormShop.resx b/Confectionery/FormShop.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/FormShop.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 -- 2.25.1 From 475face56324153f962da7753a0ce7ae9baf7066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sun, 5 Feb 2023 17:44:00 +0400 Subject: [PATCH 08/15] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D1=82=D1=8C=20=D0=B8=D0=B7=D0=B4=D0=B5=D0=BB=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B2=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryBusinessLogic/ShopLogic.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ConfectionaryBusinessLogic/ShopLogic.cs b/ConfectionaryBusinessLogic/ShopLogic.cs index 920f493..cf9663c 100644 --- a/ConfectionaryBusinessLogic/ShopLogic.cs +++ b/ConfectionaryBusinessLogic/ShopLogic.cs @@ -115,6 +115,10 @@ namespace ConfectioneryBusinessLogic { throw new ArgumentNullException(nameof(model)); } + if (count <= 0) + { + throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count)); + } _logger.LogInformation("AddPastryInShop. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id); var element = _shopStorage.GetElement(model); @@ -125,7 +129,22 @@ namespace ConfectioneryBusinessLogic } _logger.LogInformation("AddPastryInShop find. Id:{Id}", element.Id); - return element.Pastries.TryAdd(pastry.Id, (pastry, count)); + + if (element.Pastries.TryGetValue(pastry.Id, out var pair)) + { + pair.Item2 += count; + _logger.LogInformation( + "AddPastryInShop. Has been added {count} {pastry} in {ShopName}", + count, pastry.PastryName, element.Name); + } + else + { + element.Pastries[pastry.Id] = (pastry, count); + _logger.LogInformation( + "AddPastryInShop. Has been added {count} new Pastry {pastry} in {ShopName}", + count, pastry.PastryName, element.Name); + } + return true; } } } -- 2.25.1 From 6ea2ac3a753ab0e696b378edd1c9bd075c1858fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sun, 5 Feb 2023 19:37:08 +0400 Subject: [PATCH 09/15] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=B4=D0=B5=D0=BB=D0=B8=D0=B9=20=D0=B2=20=D0=BC?= =?UTF-8?q?=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Confectionery/FormAddPastryInShop.Designer.cs | 151 ++++++++++++++++++ Confectionery/FormAddPastryInShop.cs | 49 ++++++ Confectionery/FormAddPastryInShop.resx | 60 +++++++ Confectionery/FormMain.Designer.cs | 16 +- Confectionery/FormMain.cs | 13 +- Confectionery/FormShop.cs | 2 +- 6 files changed, 285 insertions(+), 6 deletions(-) create mode 100644 Confectionery/FormAddPastryInShop.Designer.cs create mode 100644 Confectionery/FormAddPastryInShop.cs create mode 100644 Confectionery/FormAddPastryInShop.resx diff --git a/Confectionery/FormAddPastryInShop.Designer.cs b/Confectionery/FormAddPastryInShop.Designer.cs new file mode 100644 index 0000000..76738b9 --- /dev/null +++ b/Confectionery/FormAddPastryInShop.Designer.cs @@ -0,0 +1,151 @@ +namespace ConfectioneryView +{ + partial class FormAddPastryInShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.comboBoxPastry = new System.Windows.Forms.ComboBox(); + this.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); + this.SuspendLayout(); + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(214, 17); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(222, 23); + this.comboBoxShop.TabIndex = 3; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(84, 20); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(124, 15); + this.label1.TabIndex = 2; + this.label1.Text = "Выбранный магазин:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 47); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(196, 15); + this.label2.TabIndex = 4; + this.label2.Text = "Изделие которое нужно добавить:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(133, 73); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(75, 15); + this.label3.TabIndex = 5; + this.label3.Text = "Количество:"; + // + // comboBoxPastry + // + this.comboBoxPastry.FormattingEnabled = true; + this.comboBoxPastry.Location = new System.Drawing.Point(214, 44); + this.comboBoxPastry.Name = "comboBoxPastry"; + this.comboBoxPastry.Size = new System.Drawing.Size(222, 23); + this.comboBoxPastry.TabIndex = 6; + // + // numericUpDownCount + // + this.numericUpDownCount.Location = new System.Drawing.Point(215, 71); + this.numericUpDownCount.Maximum = new decimal(new int[] { + 1410065408, + 2, + 0, + 0}); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.Size = new System.Drawing.Size(221, 23); + this.numericUpDownCount.TabIndex = 7; + // + // 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(280, 123); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 8; + 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(361, 123); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 9; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormAddPastryInShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(448, 158); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.numericUpDownCount); + this.Controls.Add(this.comboBoxPastry); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.label1); + this.Name = "FormAddPastryInShop"; + this.Text = "FormAddPastryInShop"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxShop; + private Label label1; + private Label label2; + private Label label3; + private ComboBox comboBoxPastry; + private NumericUpDown numericUpDownCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Confectionery/FormAddPastryInShop.cs b/Confectionery/FormAddPastryInShop.cs new file mode 100644 index 0000000..e5c786b --- /dev/null +++ b/Confectionery/FormAddPastryInShop.cs @@ -0,0 +1,49 @@ +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormAddPastryInShop : Form + { + private readonly ILogger _logger; + private readonly List? _listShops; + private readonly List? _listPastries; + + public FormAddPastryInShop(ILogger logger, IShopLogic shopLogic, IPastryLogic pastryLogic) + { + InitializeComponent(); + _logger = logger; + _listShops = shopLogic.ReadList(null); + if (_listShops != null) + { + comboBoxShop.DisplayMember = "ComponentName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _listShops; + comboBoxShop.SelectedItem = null; + } + + _listPastries + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + + } + } +} diff --git a/Confectionery/FormAddPastryInShop.resx b/Confectionery/FormAddPastryInShop.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/FormAddPastryInShop.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/Confectionery/FormMain.Designer.cs b/Confectionery/FormMain.Designer.cs index 3522d86..190dc44 100644 --- a/Confectionery/FormMain.Designer.cs +++ b/Confectionery/FormMain.Designer.cs @@ -38,6 +38,7 @@ this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); + this.ShopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -56,7 +57,8 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.pastryToolStripMenuItem, - this.componentToolStripMenuItem}); + this.componentToolStripMenuItem, + this.ShopsToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -64,14 +66,14 @@ // pastryToolStripMenuItem // this.pastryToolStripMenuItem.Name = "pastryToolStripMenuItem"; - this.pastryToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.pastryToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.pastryToolStripMenuItem.Text = "Изделия"; this.pastryToolStripMenuItem.Click += new System.EventHandler(this.PastryToolStripMenuItem_Click); // // componentToolStripMenuItem // this.componentToolStripMenuItem.Name = "componentToolStripMenuItem"; - this.componentToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.componentToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.componentToolStripMenuItem.Text = "Компоненты"; this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); // @@ -142,6 +144,13 @@ this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.ButtonRef_Click); // + // ShopsToolStripMenuItem + // + this.ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; + this.ShopsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ShopsToolStripMenuItem.Text = "Магазины"; + this.ShopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -177,5 +186,6 @@ private Button button4; private ToolStripMenuItem pastryToolStripMenuItem; private ToolStripMenuItem componentToolStripMenuItem; + private ToolStripMenuItem ShopsToolStripMenuItem; } } \ No newline at end of file diff --git a/Confectionery/FormMain.cs b/Confectionery/FormMain.cs index 628ea63..489ec5c 100644 --- a/Confectionery/FormMain.cs +++ b/Confectionery/FormMain.cs @@ -62,8 +62,7 @@ namespace ConfectioneryView private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); if (service is FormCreateOrder form) { form.ShowDialog(); @@ -152,5 +151,15 @@ namespace ConfectioneryView { LoadData(); } + + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormViewShops)); + if (service is FormViewShops form) + { + form.ShowDialog(); + LoadData(); + } + } } } \ No newline at end of file diff --git a/Confectionery/FormShop.cs b/Confectionery/FormShop.cs index f677a26..5026ff8 100644 --- a/Confectionery/FormShop.cs +++ b/Confectionery/FormShop.cs @@ -28,7 +28,7 @@ namespace ConfectioneryView _logic = logic; if (_list != null) { - comboBoxShop.DisplayMember = "ComponentName"; + comboBoxShop.DisplayMember = "Name"; comboBoxShop.ValueMember = "Id"; comboBoxShop.DataSource = _list; comboBoxShop.SelectedItem = null; -- 2.25.1 From 78a3293bb54dbfadad8d7d62aeb40dfcf0831127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sun, 5 Feb 2023 19:51:51 +0400 Subject: [PATCH 10/15] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B2=20=D0=B3=D0=BB=D0=B0=D0=B2=D0=BD=D1=83=D1=8E=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D1=83=20=D0=B8=20=D0=B2=D0=BD=D0=B5?= =?UTF-8?q?=D0=B4=D1=80=D0=B5=D0=BD=D1=8B=20=D0=B2=D1=81=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D1=8B=D0=B5=20=D0=B7=D0=B0=D0=B2=D0=B8=D1=81=D0=B8?= =?UTF-8?q?=D0=BC=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Confectionery/FormAddPastryInShop.cs | 62 +++++++++++++++++++++++++--- Confectionery/FormMain.Designer.cs | 25 ++++++++--- Confectionery/FormMain.cs | 14 +++++-- Confectionery/Program.cs | 5 +++ 4 files changed, 92 insertions(+), 14 deletions(-) diff --git a/Confectionery/FormAddPastryInShop.cs b/Confectionery/FormAddPastryInShop.cs index e5c786b..362584b 100644 --- a/Confectionery/FormAddPastryInShop.cs +++ b/Confectionery/FormAddPastryInShop.cs @@ -1,4 +1,5 @@ -using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; using ConfectioneryContracts.ViewModels; using Microsoft.Extensions.Logging; using System; @@ -17,33 +18,84 @@ namespace ConfectioneryView public partial class FormAddPastryInShop : Form { private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + private readonly IPastryLogic _pastryLogic; private readonly List? _listShops; private readonly List? _listPastries; public FormAddPastryInShop(ILogger logger, IShopLogic shopLogic, IPastryLogic pastryLogic) { InitializeComponent(); + _shopLogic = shopLogic; + _pastryLogic = pastryLogic; _logger = logger; _listShops = shopLogic.ReadList(null); if (_listShops != null) { - comboBoxShop.DisplayMember = "ComponentName"; + comboBoxShop.DisplayMember = "Name"; comboBoxShop.ValueMember = "Id"; comboBoxShop.DataSource = _listShops; comboBoxShop.SelectedItem = null; } - _listPastries + _listPastries = pastryLogic.ReadList(null); + if (_listPastries != null) + { + comboBoxPastry.DisplayMember = "PastryName"; + comboBoxPastry.ValueMember= "Id"; + comboBoxPastry.DataSource = _listPastries; + comboBoxPastry.SelectedItem = null; + } } private void ButtonSave_Click(object sender, EventArgs e) { - + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPastry.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Добавление изделия в магазин"); + try + { + var pastry = _pastryLogic.ReadElement(new() + { + Id = (int)comboBoxPastry.SelectedValue + }); + if (pastry == null) + { + throw new Exception("Не найдено изделие. Дополнительная информация в логах."); + } + var resultOperation = _shopLogic.AddPastry( + model: new() { Id = (int)comboBoxShop.SelectedValue }, + pastry: pastry, + 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/Confectionery/FormMain.Designer.cs b/Confectionery/FormMain.Designer.cs index 190dc44..ca969bd 100644 --- a/Confectionery/FormMain.Designer.cs +++ b/Confectionery/FormMain.Designer.cs @@ -32,13 +32,14 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pastryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ShopsToolStripMenuItem = 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.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); - this.ShopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonAddPastryInShop = new System.Windows.Forms.Button(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -77,6 +78,13 @@ this.componentToolStripMenuItem.Text = "Компоненты"; this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); // + // ShopsToolStripMenuItem + // + this.ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; + this.ShopsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ShopsToolStripMenuItem.Text = "Магазины"; + this.ShopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -144,18 +152,22 @@ this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.ButtonRef_Click); // - // ShopsToolStripMenuItem + // buttonAddPastryInShop // - this.ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; - this.ShopsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.ShopsToolStripMenuItem.Text = "Магазины"; - this.ShopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); + this.buttonAddPastryInShop.Location = new System.Drawing.Point(624, 326); + this.buttonAddPastryInShop.Name = "buttonAddPastryInShop"; + this.buttonAddPastryInShop.Size = new System.Drawing.Size(147, 31); + this.buttonAddPastryInShop.TabIndex = 7; + this.buttonAddPastryInShop.Text = "Пополнение магазина"; + this.buttonAddPastryInShop.UseVisualStyleBackColor = true; + this.buttonAddPastryInShop.Click += new System.EventHandler(this.ButtonAddPastryInShop_Click); // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(783, 380); + this.Controls.Add(this.buttonAddPastryInShop); this.Controls.Add(this.button4); this.Controls.Add(this.button3); this.Controls.Add(this.button2); @@ -187,5 +199,6 @@ private ToolStripMenuItem pastryToolStripMenuItem; private ToolStripMenuItem componentToolStripMenuItem; private ToolStripMenuItem ShopsToolStripMenuItem; + private Button buttonAddPastryInShop; } } \ No newline at end of file diff --git a/Confectionery/FormMain.cs b/Confectionery/FormMain.cs index 489ec5c..92e771a 100644 --- a/Confectionery/FormMain.cs +++ b/Confectionery/FormMain.cs @@ -30,8 +30,8 @@ namespace ConfectioneryView { dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - /*dataGridView.Columns["PastryName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill;*/ + dataGridView.Columns["PastryName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation(" "); } @@ -158,7 +158,15 @@ namespace ConfectioneryView if (service is FormViewShops form) { form.ShowDialog(); - LoadData(); + } + } + + private void ButtonAddPastryInShop_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddPastryInShop)); + if (service is FormAddPastryInShop form) + { + form.ShowDialog(); } } } diff --git a/Confectionery/Program.cs b/Confectionery/Program.cs index d3d5709..645885a 100644 --- a/Confectionery/Program.cs +++ b/Confectionery/Program.cs @@ -1,4 +1,5 @@ using AbstractShopListImplement.Implements; +using ConfectioneryBusinessLogic; using ConfectioneryBusinessLogic.BusinessLogics; using ConfectioneryContracts.BusinessLogicsContracts; using ConfectioneryContracts.StoragesContract; @@ -38,9 +39,11 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -48,6 +51,8 @@ namespace ConfectioneryView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file -- 2.25.1 From d43db88851998d36872fabd5d41e374def9e6966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sun, 5 Feb 2023 19:54:17 +0400 Subject: [PATCH 11/15] fix --- Confectionery/FormComponents.cs | 10 +++++----- Confectionery/FormViewShops.cs | 17 ++++------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/Confectionery/FormComponents.cs b/Confectionery/FormComponents.cs index b869d81..b9600b5 100644 --- a/Confectionery/FormComponents.cs +++ b/Confectionery/FormComponents.cs @@ -27,14 +27,14 @@ namespace ConfectioneryView { dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["Name"].AutoSizeMode = + dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } - _logger.LogInformation("Загрузка магазинов"); + _logger.LogInformation("Загрузка изделий"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки магазинов"); + _logger.LogError(ex, "Ошибка загрузки изделий"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -78,7 +78,7 @@ namespace ConfectioneryView { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление магазина"); + _logger.LogInformation("Удаление изделия"); try { if (!_logic.Delete(new ComponentBindingModel @@ -92,7 +92,7 @@ namespace ConfectioneryView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления магазина"); + _logger.LogError(ex, "Ошибка удаления изделия"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } diff --git a/Confectionery/FormViewShops.cs b/Confectionery/FormViewShops.cs index 6c443d2..4ff6fc5 100644 --- a/Confectionery/FormViewShops.cs +++ b/Confectionery/FormViewShops.cs @@ -1,15 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.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 ConfectioneryView { @@ -39,11 +30,11 @@ namespace ConfectioneryView dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } - _logger.LogInformation("Загрузка компонентов"); + _logger.LogInformation("Загрузка магазинов"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонентов"); + _logger.LogError(ex, "Ошибка загрузки магазинов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -87,7 +78,7 @@ namespace ConfectioneryView { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление компонента"); + _logger.LogInformation("Удаление магазина"); try { if (!_logic.Delete(new ShopBindingModel @@ -101,7 +92,7 @@ namespace ConfectioneryView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления компонента"); + _logger.LogError(ex, "Ошибка удаления магазина"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } -- 2.25.1 From 785d086b3f84d1e7b02faee1661ff53824d1ed79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Mon, 6 Feb 2023 01:31:42 +0400 Subject: [PATCH 12/15] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryListImplement/Shop.cs | 3 +- Confectionery/FormShop.Designer.cs | 1 + Confectionery/FormShop.cs | 67 +++++++++++++----------------- Confectionery/FormViewShops.cs | 18 ++------ 4 files changed, 36 insertions(+), 53 deletions(-) diff --git a/ConfectionaryListImplement/Shop.cs b/ConfectionaryListImplement/Shop.cs index c1a7630..fcce77b 100644 --- a/ConfectionaryListImplement/Shop.cs +++ b/ConfectionaryListImplement/Shop.cs @@ -52,7 +52,8 @@ namespace ConfectioneryListImplement Id = Id, Name = Name, Address = Address, - Pastries = Pastries + Pastries = Pastries, + DateOpening = DateOpening, }; } } diff --git a/Confectionery/FormShop.Designer.cs b/Confectionery/FormShop.Designer.cs index 15049d1..694a22f 100644 --- a/Confectionery/FormShop.Designer.cs +++ b/Confectionery/FormShop.Designer.cs @@ -163,6 +163,7 @@ this.Controls.Add(this.label1); this.Name = "FormShop"; this.Text = "Просмотр изделий магазина"; + this.Load += new System.EventHandler(this.FormShop_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Confectionery/FormShop.cs b/Confectionery/FormShop.cs index 1b2c9f9..9b640b0 100644 --- a/Confectionery/FormShop.cs +++ b/Confectionery/FormShop.cs @@ -23,34 +23,21 @@ namespace ConfectioneryView private readonly List? _listShops; private readonly IShopLogic _logic; private readonly ILogger _logger; - private IShopModel? _currentShopModel; public int Id { - get - { - return Convert.ToInt32(comboBoxShop.SelectedValue); - } - set - { - comboBoxShop.SelectedValue = value; - } - } - public IShopModel? ShopModel - { - get => _currentShopModel; + get; set; } private IShopModel? GetShop() { - var list = _logic.ReadList(null); - if (list == null) + if (_listShops == null) { return null; } - foreach (var elem in list) + foreach (var elem in _listShops) { - if (elem.Id == this.Id) + if (elem.Id == Id) { return elem; } @@ -77,22 +64,18 @@ namespace ConfectioneryView { try { - var currentShop = _logic.ReadElement(new() { Id = this.Id}); - if (currentShop != null) - { - var vmodel = GetShop(); - if (vmodel != null) - { - comboBoxShop.Text = vmodel.Name; - textBoxAddress.Text = vmodel.Address; - textBoxDateOpening.Text = Convert.ToString(vmodel.DateOpening); - } + var model = GetShop(); + if (model != null) + { + comboBoxShop.Text = model.Name; + textBoxAddress.Text = model.Address; + textBoxDateOpening.Text = Convert.ToString(model.DateOpening); + dataGridView.Rows.Clear(); - foreach (var el in currentShop.Pastries.Values) + foreach (var el in model.Pastries.Values) { dataGridView.Rows.Add(new object[]{el.Item1.PastryName, el.Item1.Price, el.Item2 }); } - } _logger.LogInformation("Загрузка магазинов"); } @@ -126,13 +109,6 @@ namespace ConfectioneryView _logger.LogInformation("Сохранение изделия"); try { - var vmodel = GetShop(); - if (vmodel != null) - { - _currentShopModel = vmodel; - return; - } - // Создаем новый магазин если не нашли такого DateTime.TryParse(textBoxDateOpening.Text, out var dateTime); ShopBindingModel model = new() { @@ -140,8 +116,18 @@ namespace ConfectioneryView Address = textBoxAddress.Text, DateOpening = dateTime }; - var operationResult = _logic.Create(model); - _currentShopModel = model; + var vmodel = GetShop(); + bool operationResult = false; + + if (vmodel != null) + { + model.Id = vmodel.Id; + operationResult = _logic.Update(model); + } + else + { + operationResult = _logic.Create(model); + } if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -163,5 +149,10 @@ namespace ConfectioneryView DialogResult = DialogResult.Cancel; Close(); } + + private void FormShop_Load(object sender, EventArgs e) + { + LoadData(); + } } } diff --git a/Confectionery/FormViewShops.cs b/Confectionery/FormViewShops.cs index d7fa00a..419130c 100644 --- a/Confectionery/FormViewShops.cs +++ b/Confectionery/FormViewShops.cs @@ -26,7 +26,9 @@ namespace ConfectioneryView if (list != null) { dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Pastries"].Visible = false; dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } @@ -57,24 +59,12 @@ namespace ConfectioneryView var service = Program.ServiceProvider?.GetService(typeof(FormShop)); if (service is FormShop form) { - var id = form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) { - var model = form.ShopModel; - if (model != null) - { - _logic.Update(new() - { - Id = id, - Address = model.Address, - Name = model.Name, - DateOpening= model.DateOpening, - }); - } - + LoadData(); } } - LoadData(); } } private void ButtonDel_Click(object sender, EventArgs e) -- 2.25.1 From 8bca5845e52a103474030b2312daf99009112e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Mon, 6 Feb 2023 01:31:42 +0400 Subject: [PATCH 13/15] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryListImplement/Shop.cs | 3 +- Confectionery/FormShop.Designer.cs | 1 + Confectionery/FormShop.cs | 73 +++++++++++-------------- Confectionery/FormViewShops.Designer.cs | 1 + Confectionery/FormViewShops.cs | 18 ++---- 5 files changed, 40 insertions(+), 56 deletions(-) diff --git a/ConfectionaryListImplement/Shop.cs b/ConfectionaryListImplement/Shop.cs index c1a7630..fcce77b 100644 --- a/ConfectionaryListImplement/Shop.cs +++ b/ConfectionaryListImplement/Shop.cs @@ -52,7 +52,8 @@ namespace ConfectioneryListImplement Id = Id, Name = Name, Address = Address, - Pastries = Pastries + Pastries = Pastries, + DateOpening = DateOpening, }; } } diff --git a/Confectionery/FormShop.Designer.cs b/Confectionery/FormShop.Designer.cs index 15049d1..694a22f 100644 --- a/Confectionery/FormShop.Designer.cs +++ b/Confectionery/FormShop.Designer.cs @@ -163,6 +163,7 @@ this.Controls.Add(this.label1); this.Name = "FormShop"; this.Text = "Просмотр изделий магазина"; + this.Load += new System.EventHandler(this.FormShop_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Confectionery/FormShop.cs b/Confectionery/FormShop.cs index 1b2c9f9..b29d8b4 100644 --- a/Confectionery/FormShop.cs +++ b/Confectionery/FormShop.cs @@ -23,34 +23,21 @@ namespace ConfectioneryView private readonly List? _listShops; private readonly IShopLogic _logic; private readonly ILogger _logger; - private IShopModel? _currentShopModel; public int Id { - get - { - return Convert.ToInt32(comboBoxShop.SelectedValue); - } - set - { - comboBoxShop.SelectedValue = value; - } - } - public IShopModel? ShopModel - { - get => _currentShopModel; + get; set; } - private IShopModel? GetShop() + private IShopModel? GetShop(int id) { - var list = _logic.ReadList(null); - if (list == null) + if (_listShops == null) { return null; } - foreach (var elem in list) + foreach (var elem in _listShops) { - if (elem.Id == this.Id) + if (elem.Id == id) { return elem; } @@ -73,26 +60,22 @@ namespace ConfectioneryView } } - private void LoadData() + private void LoadData(bool extendDate = true) { try { - var currentShop = _logic.ReadElement(new() { Id = this.Id}); - if (currentShop != null) - { - var vmodel = GetShop(); - if (vmodel != null) - { - comboBoxShop.Text = vmodel.Name; - textBoxAddress.Text = vmodel.Address; - textBoxDateOpening.Text = Convert.ToString(vmodel.DateOpening); - } + var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.SelectedValue)); + if (model != null) + { + comboBoxShop.Text = model.Name; + textBoxAddress.Text = model.Address; + textBoxDateOpening.Text = Convert.ToString(model.DateOpening); + dataGridView.Rows.Clear(); - foreach (var el in currentShop.Pastries.Values) + foreach (var el in model.Pastries.Values) { dataGridView.Rows.Add(new object[]{el.Item1.PastryName, el.Item1.Price, el.Item2 }); } - } _logger.LogInformation("Загрузка магазинов"); } @@ -106,7 +89,7 @@ namespace ConfectioneryView private void ComboBoxShop_SelectedIndexChanged(object sender, EventArgs e) { - LoadData(); + LoadData(false); } private void ButtonSave_Click(object sender, EventArgs e) @@ -126,13 +109,6 @@ namespace ConfectioneryView _logger.LogInformation("Сохранение изделия"); try { - var vmodel = GetShop(); - if (vmodel != null) - { - _currentShopModel = vmodel; - return; - } - // Создаем новый магазин если не нашли такого DateTime.TryParse(textBoxDateOpening.Text, out var dateTime); ShopBindingModel model = new() { @@ -140,8 +116,18 @@ namespace ConfectioneryView Address = textBoxAddress.Text, DateOpening = dateTime }; - var operationResult = _logic.Create(model); - _currentShopModel = model; + var vmodel = GetShop(Id); + bool operationResult = false; + + if (vmodel != null) + { + model.Id = vmodel.Id; + operationResult = _logic.Update(model); + } + else + { + operationResult = _logic.Create(model); + } if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -163,5 +149,10 @@ namespace ConfectioneryView DialogResult = DialogResult.Cancel; Close(); } + + private void FormShop_Load(object sender, EventArgs e) + { + LoadData(); + } } } diff --git a/Confectionery/FormViewShops.Designer.cs b/Confectionery/FormViewShops.Designer.cs index 82f254a..894b8f9 100644 --- a/Confectionery/FormViewShops.Designer.cs +++ b/Confectionery/FormViewShops.Designer.cs @@ -104,6 +104,7 @@ this.Controls.Add(this.dataGridView); this.Name = "FormViewShops"; this.Text = "Просмотр магазинов"; + this.Load += new System.EventHandler(this.FormShops_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); diff --git a/Confectionery/FormViewShops.cs b/Confectionery/FormViewShops.cs index d7fa00a..419130c 100644 --- a/Confectionery/FormViewShops.cs +++ b/Confectionery/FormViewShops.cs @@ -26,7 +26,9 @@ namespace ConfectioneryView if (list != null) { dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Pastries"].Visible = false; dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } @@ -57,24 +59,12 @@ namespace ConfectioneryView var service = Program.ServiceProvider?.GetService(typeof(FormShop)); if (service is FormShop form) { - var id = form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) { - var model = form.ShopModel; - if (model != null) - { - _logic.Update(new() - { - Id = id, - Address = model.Address, - Name = model.Name, - DateOpening= model.DateOpening, - }); - } - + LoadData(); } } - LoadData(); } } private void ButtonDel_Click(object sender, EventArgs e) -- 2.25.1 From 1262146e7aebef2f766b529676accf92b4cb27ed Mon Sep 17 00:00:00 2001 From: 1yuee Date: Tue, 7 Feb 2023 11:03:47 +0400 Subject: [PATCH 14/15] fix --- ConfectionaryBusinessLogic/ShopLogic.cs | 11 +++++++++-- ConfectionaryListImplement/Shop.cs | 2 +- Confectionery/FormComponents.Designer.cs | 1 + Confectionery/FormMain.Designer.cs | 1 + Confectionery/FormMain.cs | 3 ++- Confectionery/FormPastry.Designer.cs | 1 + Confectionery/FormShop.cs | 7 ------- Confectionery/FormViewPastry.Designer.cs | 1 + 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ConfectionaryBusinessLogic/ShopLogic.cs b/ConfectionaryBusinessLogic/ShopLogic.cs index 4c06d09..36d618a 100644 --- a/ConfectionaryBusinessLogic/ShopLogic.cs +++ b/ConfectionaryBusinessLogic/ShopLogic.cs @@ -68,7 +68,6 @@ namespace ConfectioneryBusinessLogic throw new ArgumentNullException("Нет названия магазина", nameof(model.Name)); } - model.Pastries = new(); if (_shopStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); @@ -137,7 +136,7 @@ namespace ConfectioneryBusinessLogic if (element.Pastries.TryGetValue(pastry.Id, out var pair)) { - pair.Item2 += count; + element.Pastries[pastry.Id] = (pastry, count + pair.Item2); _logger.LogInformation( "AddPastryInShop. Has been added {count} {pastry} in {ShopName}", count, pastry.PastryName, element.Name); @@ -149,6 +148,14 @@ namespace ConfectioneryBusinessLogic "AddPastryInShop. Has been added {count} new Pastry {pastry} in {ShopName}", count, pastry.PastryName, element.Name); } + _shopStorage.Update(new() + { + Id = element.Id, + Address = element.Address, + Name = element.Name, + DateOpening = element.DateOpening, + Pastries = element.Pastries + }); return true; } } diff --git a/ConfectionaryListImplement/Shop.cs b/ConfectionaryListImplement/Shop.cs index fcce77b..93e754c 100644 --- a/ConfectionaryListImplement/Shop.cs +++ b/ConfectionaryListImplement/Shop.cs @@ -33,7 +33,7 @@ namespace ConfectioneryListImplement Name = model.Name, Address = model.Address, DateOpening = model.DateOpening, - Pastries = model.Pastries + Pastries = new() }; } public void Update(ShopBindingModel? model) diff --git a/Confectionery/FormComponents.Designer.cs b/Confectionery/FormComponents.Designer.cs index dd31844..967f22a 100644 --- a/Confectionery/FormComponents.Designer.cs +++ b/Confectionery/FormComponents.Designer.cs @@ -104,6 +104,7 @@ this.Controls.Add(this.dataGridView); this.Name = "FormComponents"; this.Text = "Редактирование компонентов"; + this.Load += new System.EventHandler(this.FormComponents_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); diff --git a/Confectionery/FormMain.Designer.cs b/Confectionery/FormMain.Designer.cs index d43b97b..0710300 100644 --- a/Confectionery/FormMain.Designer.cs +++ b/Confectionery/FormMain.Designer.cs @@ -179,6 +179,7 @@ this.MainMenuStrip = this.menuStrip1; this.Name = "FormMain"; this.Text = "Кондитерская"; + this.Load += new System.EventHandler(this.FormMain_Load); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); diff --git a/Confectionery/FormMain.cs b/Confectionery/FormMain.cs index 92e771a..3c6c955 100644 --- a/Confectionery/FormMain.cs +++ b/Confectionery/FormMain.cs @@ -29,7 +29,8 @@ namespace ConfectioneryView if (list != null) { dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Id"].HeaderText = " "; + dataGridView.Columns["PastryId"].Visible = false; dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } diff --git a/Confectionery/FormPastry.Designer.cs b/Confectionery/FormPastry.Designer.cs index ba07aee..1c6ecaf 100644 --- a/Confectionery/FormPastry.Designer.cs +++ b/Confectionery/FormPastry.Designer.cs @@ -207,6 +207,7 @@ this.Controls.Add(this.label1); this.Name = "FormPastry"; this.Text = "Кондитерское изделие"; + this.Load += new System.EventHandler(this.FormPastry_Load); this.groupBox1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); diff --git a/Confectionery/FormShop.cs b/Confectionery/FormShop.cs index 4700625..c755270 100644 --- a/Confectionery/FormShop.cs +++ b/Confectionery/FormShop.cs @@ -70,13 +70,6 @@ namespace ConfectioneryView comboBoxShop.Text = model.Name; textBoxAddress.Text = model.Address; textBoxDateOpening.Text = Convert.ToString(model.DateOpening); - - textBoxAddress.Text = vmodel.Address; - textBoxDateOpening.Text = Convert.ToString(vmodel.DateOpening); - } - textBoxAddress.Text = vmodel.Address; - textBoxDateOpening.Text = Convert.ToString(vmodel.DateOpening); - } dataGridView.Rows.Clear(); foreach (var el in model.Pastries.Values) { diff --git a/Confectionery/FormViewPastry.Designer.cs b/Confectionery/FormViewPastry.Designer.cs index 3417617..67d3480 100644 --- a/Confectionery/FormViewPastry.Designer.cs +++ b/Confectionery/FormViewPastry.Designer.cs @@ -104,6 +104,7 @@ this.Controls.Add(this.dataGridView); this.Name = "FormViewPastry"; this.Text = "Редактирование изделий"; + this.Load += new System.EventHandler(this.FormViewPastry_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); -- 2.25.1 From 6bcbf619c0ac7ec82efa6faab0751519b51209c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Thu, 9 Feb 2023 16:13:08 +0400 Subject: [PATCH 15/15] fix --- Confectionery/FormComponents.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Confectionery/FormComponents.cs b/Confectionery/FormComponents.cs index 3368e14..2f20d12 100644 --- a/Confectionery/FormComponents.cs +++ b/Confectionery/FormComponents.cs @@ -30,11 +30,11 @@ namespace ConfectioneryView dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } - _logger.LogInformation("Загрузка изделий"); + _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки изделий"); + _logger.LogError(ex, "Ошибка загрузки компонентов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -75,7 +75,7 @@ namespace ConfectioneryView { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление изделия"); + _logger.LogInformation("Удаление компонента"); try { if (!_logic.Delete(new ComponentBindingModel @@ -89,7 +89,7 @@ namespace ConfectioneryView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления изделия"); + _logger.LogError(ex, "Ошибка удаления компонента"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } -- 2.25.1