From 973afb771a14e2a603478de4a1181ca1356d6c9e Mon Sep 17 00:00:00 2001 From: ekallin Date: Sun, 10 Mar 2024 17:20:17 +0400 Subject: [PATCH 1/8] =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BB=D0=B0=D0=B1=D1=8B=201=20=D1=83=D1=81=D0=BB?= =?UTF-8?q?=D0=BE=D0=B6=D0=BD=D0=B5=D0=BD=D0=BA=D0=B8,=20=D0=B8=D0=BD?= =?UTF-8?q?=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=D0=B0=20ShopModel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBarDataModels/IShopModel.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 SushiBarDataModels/IShopModel.cs diff --git a/SushiBarDataModels/IShopModel.cs b/SushiBarDataModels/IShopModel.cs new file mode 100644 index 0000000..d74165e --- /dev/null +++ b/SushiBarDataModels/IShopModel.cs @@ -0,0 +1,12 @@ +using SushiBarDataModels.Models; + +namespace SushiBarDataModels +{ + public interface IShopModel : IId + { + string Name { get; set; } + string Address { get; set; } + DateTime DateOpening { get; set; } + Dictionary ShopSushis{ get; set; } + } +} -- 2.25.1 From 745dbe385f6907bc709ee0a5a392dfb448950d02 Mon Sep 17 00:00:00 2001 From: ekallin Date: Sun, 10 Mar 2024 18:26:10 +0400 Subject: [PATCH 2/8] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B5=D0=BA=D1=82=20..Contracts=20=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=87=D0=B0=D1=82=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BC=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 --- SushiBarBusinessLogic/ShopLogic.cs | 70 +++++++++++++++++++ .../BindingModel/ShopBindingModel.cs | 14 ++++ .../BusinessLogicsContracts/IShopLogic.cs | 17 +++++ .../SearchModel/ShopSearchModel.cs | 8 +++ .../StoragesContracts/IShopStorage.cs | 16 +++++ SushiBarContracts/ViewModels/ShopViewModel.cs | 21 ++++++ SushiBarDataModels/IShopModel.cs | 8 +-- SushiBarDataModels/ShopBindingModel.cs | 6 ++ 8 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 SushiBarBusinessLogic/ShopLogic.cs create mode 100644 SushiBarContracts/BindingModel/ShopBindingModel.cs create mode 100644 SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 SushiBarContracts/SearchModel/ShopSearchModel.cs create mode 100644 SushiBarContracts/StoragesContracts/IShopStorage.cs create mode 100644 SushiBarContracts/ViewModels/ShopViewModel.cs create mode 100644 SushiBarDataModels/ShopBindingModel.cs diff --git a/SushiBarBusinessLogic/ShopLogic.cs b/SushiBarBusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..b4931b8 --- /dev/null +++ b/SushiBarBusinessLogic/ShopLogic.cs @@ -0,0 +1,70 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModel; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModel; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarDataModels; + +namespace SushiBarBusinessLogic +{ + 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. Id:{ Id}, ShopName:{ ShopName}", model?.Id, model?.Name); + 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("ReadList. Id:{ Id}, ShopName:{ ShopName}", model.Id, model.Name); + 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); + } + + private bool CheckModel(ShopBindingModel model, bool withParams = true) + { + if(model == null) + throw new ArgumentNullException($"{nameof(model)} is null"); + if (!withParams) return false; + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет такого магазина", nameof(model.Name)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{ Address}. Id:{ Id}", + model.ShopName, model.Address, model.Id); + } + } +} diff --git a/SushiBarContracts/BindingModel/ShopBindingModel.cs b/SushiBarContracts/BindingModel/ShopBindingModel.cs new file mode 100644 index 0000000..c27c14a --- /dev/null +++ b/SushiBarContracts/BindingModel/ShopBindingModel.cs @@ -0,0 +1,14 @@ +using SushiBarDataModels; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModel +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string Name { get; set; } + public string Address { get; set; } + public DateTime DateOpening { get; set; } = DateTime.Now; + public Dictionary ShopSushis { get; set; } = new(); + } +} diff --git a/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs b/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..cc71895 --- /dev/null +++ b/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,17 @@ +using SushiBarContracts.BindingModel; +using SushiBarContracts.SearchModel; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.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 AddSushiInShop(ShopSearchModel model, ISushiModel sushi, int count); + } +} diff --git a/SushiBarContracts/SearchModel/ShopSearchModel.cs b/SushiBarContracts/SearchModel/ShopSearchModel.cs new file mode 100644 index 0000000..f34d7e5 --- /dev/null +++ b/SushiBarContracts/SearchModel/ShopSearchModel.cs @@ -0,0 +1,8 @@ +namespace SushiBarContracts.SearchModel +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/SushiBarContracts/StoragesContracts/IShopStorage.cs b/SushiBarContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..dfa1b73 --- /dev/null +++ b/SushiBarContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,16 @@ +using SushiBarContracts.BindingModel; +using SushiBarContracts.SearchModel; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.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/SushiBarContracts/ViewModels/ShopViewModel.cs b/SushiBarContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..09b0864 --- /dev/null +++ b/SushiBarContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,21 @@ +using SushiBarDataModels; +using SushiBarDataModels.Models; +using System.ComponentModel; + +namespace SushiBarContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [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 ShopSushis { get; set; } = new(); + } +} diff --git a/SushiBarDataModels/IShopModel.cs b/SushiBarDataModels/IShopModel.cs index d74165e..cd01a16 100644 --- a/SushiBarDataModels/IShopModel.cs +++ b/SushiBarDataModels/IShopModel.cs @@ -4,9 +4,9 @@ namespace SushiBarDataModels { public interface IShopModel : IId { - string Name { get; set; } - string Address { get; set; } - DateTime DateOpening { get; set; } - Dictionary ShopSushis{ get; set; } + string Name { get; } + string Address { get; } + DateTime DateOpening { get; } + Dictionary ShopSushis{ get; } } } diff --git a/SushiBarDataModels/ShopBindingModel.cs b/SushiBarDataModels/ShopBindingModel.cs new file mode 100644 index 0000000..fab6768 --- /dev/null +++ b/SushiBarDataModels/ShopBindingModel.cs @@ -0,0 +1,6 @@ +namespace SushiBarDataModels +{ + public class ShopBindingModel : IShopModel + { + } +} -- 2.25.1 From 4c1af6acb56f31900f060b1475e75707686a1481 Mon Sep 17 00:00:00 2001 From: ekallin Date: Sun, 10 Mar 2024 22:35:26 +0400 Subject: [PATCH 3/8] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BD=D1=83=D0=B6=D0=BD=D1=8B=D0=B5=20=D1=84?= =?UTF-8?q?=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20...Implements,=20=D0=B0=20?= =?UTF-8?q?=D1=82=D0=B0=D0=BA=D0=B6=D0=B5=20=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0=20=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0.=20=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D1=81=D1=8C=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBarBusinessLogic/ShopLogic.cs | 81 ++++++++++++- SushiBarDataModels/ShopBindingModel.cs | 6 - SushiBarListImplements/DataListSingleton.cs | 3 + .../Implements/ShopStorage.cs | 108 ++++++++++++++++++ SushiBarListImplements/Models/Shop.cs | 56 +++++++++ 5 files changed, 244 insertions(+), 10 deletions(-) delete mode 100644 SushiBarDataModels/ShopBindingModel.cs create mode 100644 SushiBarListImplements/Implements/ShopStorage.cs create mode 100644 SushiBarListImplements/Models/Shop.cs diff --git a/SushiBarBusinessLogic/ShopLogic.cs b/SushiBarBusinessLogic/ShopLogic.cs index b4931b8..b0fb3bf 100644 --- a/SushiBarBusinessLogic/ShopLogic.cs +++ b/SushiBarBusinessLogic/ShopLogic.cs @@ -5,6 +5,7 @@ using SushiBarContracts.SearchModel; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using SushiBarDataModels; +using SushiBarDataModels.Models; namespace SushiBarBusinessLogic { @@ -52,19 +53,91 @@ namespace SushiBarBusinessLogic public bool Create(ShopBindingModel model) { CheckModel(model); + if(_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Вставка в хранилище прервана"); + return false; + } + return true; } - private bool CheckModel(ShopBindingModel model, bool withParams = true) + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if(_shopStorage.Update(model) == null) + { + _logger.LogWarning("Обновление прервано"); + return false; + } + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model); + if(_shopStorage?.Delete(model) == null) + { + _logger.LogWarning("Удаление прервано"); + return false; + } + return true; + } + + public bool AddSushiInShop(ShopSearchModel model, ISushiModel sushi, int count) + { + if (model == null) throw new ArgumentNullException(nameof(model)); + if(count <= 0) + throw new ArgumentException(nameof(count)); + _logger.LogInformation("AddSushiInShop. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id); + + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("Не добавлено"); + return false; + } + if (element.ShopSushis.TryGetValue(sushi.Id, out var samesushi)) + { + element.ShopSushis[sushi.Id] = (sushi, samesushi.Item2 + count); + _logger.LogInformation("Same sushi found by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.Name); + } + else + { + element.ShopSushis[sushi.Id] = (sushi, count); + _logger.LogInformation("New sushi added by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.Name); + } + + _shopStorage.Update(new() + { + Id = element.Id, + Name = element.Name, + Address = element.Address, + DateOpening = element.DateOpening, + ShopSushis = element.ShopSushis + }); + + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) { if(model == null) - throw new ArgumentNullException($"{nameof(model)} is null"); - if (!withParams) return false; + throw new ArgumentNullException($"{nameof(model)} является null"); + if (!withParams) return; if (string.IsNullOrEmpty(model.Name)) { throw new ArgumentNullException("Нет такого магазина", nameof(model.Name)); } _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{ Address}. Id:{ Id}", - model.ShopName, model.Address, model.Id); + model.Name, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.Name, + }); + if(element != null && element.Id != model.Id && element.Name == model.Name) + { + throw new InvalidOperationException("Такой магазин с таким названием уже есть"); + } } } } diff --git a/SushiBarDataModels/ShopBindingModel.cs b/SushiBarDataModels/ShopBindingModel.cs deleted file mode 100644 index fab6768..0000000 --- a/SushiBarDataModels/ShopBindingModel.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SushiBarDataModels -{ - public class ShopBindingModel : IShopModel - { - } -} diff --git a/SushiBarListImplements/DataListSingleton.cs b/SushiBarListImplements/DataListSingleton.cs index 309dfcd..58df67f 100644 --- a/SushiBarListImplements/DataListSingleton.cs +++ b/SushiBarListImplements/DataListSingleton.cs @@ -8,11 +8,14 @@ namespace SushiBarListImplement public List Components { get; set; } public List Orders { get; set; } public List Sushis { get; set; } + public List Shops { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Sushis = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBarListImplements/Implements/ShopStorage.cs b/SushiBarListImplements/Implements/ShopStorage.cs new file mode 100644 index 0000000..6320310 --- /dev/null +++ b/SushiBarListImplements/Implements/ShopStorage.cs @@ -0,0 +1,108 @@ +using SushiBarContracts.BindingModel; +using SushiBarContracts.SearchModel; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement; +using SushiBarListImplements.Models; + +namespace SushiBarListImplements.Implements +{ + public class ShopStorage : IShopStorage + { + private DataListSingleton _source; + public ShopStorage(DataListSingleton source) + { + _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 (model == null || !model.Id.HasValue) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if (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/SushiBarListImplements/Models/Shop.cs b/SushiBarListImplements/Models/Shop.cs new file mode 100644 index 0000000..2d034d3 --- /dev/null +++ b/SushiBarListImplements/Models/Shop.cs @@ -0,0 +1,56 @@ +using SushiBarContracts.BindingModel; +using SushiBarContracts.ViewModels; +using SushiBarDataModels; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplements.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string Name { get; private set; } + public string Address { get; private set; } + public DateTime DateOpening { get; private set; } = DateTime.Now; + public Dictionary ShopSushis + { + get; + private set; + } = new Dictionary(); + + 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, + ShopSushis = model.ShopSushis + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) return; + Name = model.Name; + Address = model.Address; + DateOpening = model.DateOpening; + ShopSushis = model.ShopSushis; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + DateOpening = DateOpening, + ShopSushis = ShopSushis + }; + } +} -- 2.25.1 From 85e2c1f027e4bf13900a173b2e41fb8b8a1ff94f Mon Sep 17 00:00:00 2001 From: ekallin Date: Sun, 10 Mar 2024 23:03:51 +0400 Subject: [PATCH 4/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20FormShop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/Shops/FormShop.Designer.cs | 150 +++++++++++++++++++++++++++ SushiBar/Shops/FormShop.cs | 20 ++++ SushiBar/Shops/FormShop.resx | 120 +++++++++++++++++++++ SushiBar/Shops/FormShops.Designer.cs | 39 +++++++ SushiBar/Shops/FormShops.cs | 20 ++++ SushiBar/Shops/FormShops.resx | 120 +++++++++++++++++++++ 6 files changed, 469 insertions(+) create mode 100644 SushiBar/Shops/FormShop.Designer.cs create mode 100644 SushiBar/Shops/FormShop.cs create mode 100644 SushiBar/Shops/FormShop.resx create mode 100644 SushiBar/Shops/FormShops.Designer.cs create mode 100644 SushiBar/Shops/FormShops.cs create mode 100644 SushiBar/Shops/FormShops.resx diff --git a/SushiBar/Shops/FormShop.Designer.cs b/SushiBar/Shops/FormShop.Designer.cs new file mode 100644 index 0000000..f597a2e --- /dev/null +++ b/SushiBar/Shops/FormShop.Designer.cs @@ -0,0 +1,150 @@ +namespace SushiBarView.Shops +{ + 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() + { + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxAddress = new TextBox(); + textBoxName = new TextBox(); + labelAddress = new Label(); + labelName = new Label(); + dateTimePickerDateOpening = new DateTimePicker(); + labelDateOpening = new Label(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.None; + buttonCancel.Location = new Point(421, 203); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(116, 39); + buttonCancel.TabIndex = 11; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.None; + buttonSave.Location = new Point(182, 203); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(116, 39); + buttonSave.TabIndex = 10; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + // + // textBoxAddress + // + textBoxAddress.Anchor = AnchorStyles.None; + textBoxAddress.Location = new Point(182, 86); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(355, 27); + textBoxAddress.TabIndex = 9; + // + // textBoxName + // + textBoxName.Anchor = AnchorStyles.None; + textBoxName.Location = new Point(182, 20); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(355, 27); + textBoxName.TabIndex = 8; + // + // labelAddress + // + labelAddress.Anchor = AnchorStyles.None; + labelAddress.AutoSize = true; + labelAddress.Font = new Font("Candara", 12F); + labelAddress.Location = new Point(34, 86); + labelAddress.Margin = new Padding(4, 0, 4, 0); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(63, 24); + labelAddress.TabIndex = 7; + labelAddress.Text = "Адрес"; + // + // labelName + // + labelName.Anchor = AnchorStyles.None; + labelName.AutoSize = true; + labelName.Font = new Font("Candara", 12F); + labelName.Location = new Point(18, 23); + labelName.Margin = new Padding(4, 0, 4, 0); + labelName.Name = "labelName"; + labelName.Size = new Size(93, 24); + labelName.TabIndex = 6; + labelName.Text = "Название"; + // + // dateTimePickerDateOpening + // + dateTimePickerDateOpening.Location = new Point(182, 152); + dateTimePickerDateOpening.Name = "dateTimePickerDateOpening"; + dateTimePickerDateOpening.Size = new Size(355, 27); + dateTimePickerDateOpening.TabIndex = 12; + // + // labelDateOpening + // + labelDateOpening.Anchor = AnchorStyles.None; + labelDateOpening.AutoSize = true; + labelDateOpening.Font = new Font("Candara", 12F); + labelDateOpening.Location = new Point(18, 155); + labelDateOpening.Margin = new Padding(4, 0, 4, 0); + labelDateOpening.Name = "labelDateOpening"; + labelDateOpening.Size = new Size(140, 24); + labelDateOpening.TabIndex = 13; + labelDateOpening.Text = "Дата открытия"; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(571, 273); + Controls.Add(labelDateOpening); + Controls.Add(dateTimePickerDateOpening); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Controls.Add(labelAddress); + Controls.Add(labelName); + Name = "FormShop"; + Text = "Магазин"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxAddress; + private TextBox textBoxName; + private Label labelAddress; + private Label labelName; + private DateTimePicker dateTimePickerDateOpening; + private Label labelDateOpening; + } +} \ No newline at end of file diff --git a/SushiBar/Shops/FormShop.cs b/SushiBar/Shops/FormShop.cs new file mode 100644 index 0000000..4a7a9be --- /dev/null +++ b/SushiBar/Shops/FormShop.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBarView.Shops +{ + public partial class FormShop : Form + { + public FormShop() + { + InitializeComponent(); + } + } +} diff --git a/SushiBar/Shops/FormShop.resx b/SushiBar/Shops/FormShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBar/Shops/FormShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/Shops/FormShops.Designer.cs b/SushiBar/Shops/FormShops.Designer.cs new file mode 100644 index 0000000..7afb1c7 --- /dev/null +++ b/SushiBar/Shops/FormShops.Designer.cs @@ -0,0 +1,39 @@ +namespace SushiBarView.Shops +{ + 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.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "FormShops"; + } + + #endregion + } +} \ No newline at end of file diff --git a/SushiBar/Shops/FormShops.cs b/SushiBar/Shops/FormShops.cs new file mode 100644 index 0000000..63dd50c --- /dev/null +++ b/SushiBar/Shops/FormShops.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBarView.Shops +{ + public partial class FormShops : Form + { + public FormShops() + { + InitializeComponent(); + } + } +} diff --git a/SushiBar/Shops/FormShops.resx b/SushiBar/Shops/FormShops.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SushiBar/Shops/FormShops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file -- 2.25.1 From 7f730736d91939117a11b6220a8ec9cd16e98125 Mon Sep 17 00:00:00 2001 From: ekallin Date: Sun, 10 Mar 2024 23:53:01 +0400 Subject: [PATCH 5/8] =?UTF-8?q?=D0=B2=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BD=D1=83=D0=B6=D0=BD=D1=8B=D0=B5=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B8,=20?= =?UTF-8?q?=D0=BD=D1=83=D0=B6=D0=BD=D0=BE=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D1=84=D0=BE=D1=80=D0=BC=D1=83=20=D0=BC?= =?UTF-8?q?=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0=20=D0=B8=20=D0=B2?= =?UTF-8?q?=D0=B5=D0=B7=D0=B4=D0=B5=20=D0=BF=D1=80=D0=BE=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/FormMain.Designer.cs | 15 ++++- SushiBar/FormMain.cs | 11 +++- SushiBar/Program.cs | 3 + SushiBar/Shops/FormShop.cs | 71 +++++++++++++++++++++- SushiBar/Shops/FormShops.Designer.cs | 90 ++++++++++++++++++++++++++-- SushiBar/Shops/FormShops.cs | 18 +++--- SushiBar/Shops/FormShops.resx | 50 ++++++++-------- 7 files changed, 211 insertions(+), 47 deletions(-) diff --git a/SushiBar/FormMain.Designer.cs b/SushiBar/FormMain.Designer.cs index f46a473..dc347ef 100644 --- a/SushiBar/FormMain.Designer.cs +++ b/SushiBar/FormMain.Designer.cs @@ -38,6 +38,7 @@ buttonOrderReady = new Button(); buttonOrderIssued = new Button(); buttonRefreshOrders = new Button(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -54,7 +55,7 @@ // // ToolStripMenuItemRef // - ToolStripMenuItemRef.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, сушиToolStripMenuItem }); + ToolStripMenuItemRef.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, сушиToolStripMenuItem, магазиныToolStripMenuItem }); ToolStripMenuItemRef.Name = "ToolStripMenuItemRef"; ToolStripMenuItemRef.Size = new Size(117, 24); ToolStripMenuItemRef.Text = "Справочники"; @@ -62,14 +63,14 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(182, 26); + компонентыToolStripMenuItem.Size = new Size(224, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; // // сушиToolStripMenuItem // сушиToolStripMenuItem.Name = "сушиToolStripMenuItem"; - сушиToolStripMenuItem.Size = new Size(182, 26); + сушиToolStripMenuItem.Size = new Size(224, 26); сушиToolStripMenuItem.Text = "Суши"; сушиToolStripMenuItem.Click += сушиToolStripMenuItem_Click; // @@ -134,6 +135,13 @@ buttonRefreshOrders.Text = "Обновить заказы"; buttonRefreshOrders.UseVisualStyleBackColor = true; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -170,5 +178,6 @@ private Button buttonRefreshOrders; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem сушиToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/FormMain.cs b/SushiBar/FormMain.cs index f7d20cc..b19cfd7 100644 --- a/SushiBar/FormMain.cs +++ b/SushiBar/FormMain.cs @@ -2,6 +2,7 @@ using SushiBar; using SushiBarContracts.BindingModel; using SushiBarContracts.BusinessLogicsContracts; +using SushiBarView.Shops; using System; using System.Collections.Generic; using System.ComponentModel; @@ -61,7 +62,13 @@ namespace SushiBarView private void сушиToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormSushis)); - if(service is FormSushis formSushis) { formSushis.ShowDialog(); } + if (service is FormSushis formSushis) { formSushis.ShowDialog(); } + } + + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if(service is FormShops formShops) { formShops.ShowDialog(); } } private void buttonCreateOrder_Click(object sender, EventArgs e) @@ -148,7 +155,5 @@ namespace SushiBarView { LoadData(); } - - } } diff --git a/SushiBar/Program.cs b/SushiBar/Program.cs index 6afbfbd..a973c59 100644 --- a/SushiBar/Program.cs +++ b/SushiBar/Program.cs @@ -6,6 +6,7 @@ using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.StoragesContracts; using SushiBarListImplements.Implements; using SushiBarView; +using SushiBarView.Shops; namespace SushiBar { @@ -51,6 +52,8 @@ namespace SushiBar services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SushiBar/Shops/FormShop.cs b/SushiBar/Shops/FormShop.cs index 4a7a9be..27d8ec2 100644 --- a/SushiBar/Shops/FormShop.cs +++ b/SushiBar/Shops/FormShop.cs @@ -1,4 +1,8 @@ -using System; +using Microsoft.Extensions.Logging; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModel; +using SushiBarDataModels.Models; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -7,14 +11,77 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace SushiBarView.Shops { public partial class FormShop : Form { - public FormShop() + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + public int Id { + set { _id = value; } + } + + private Dictionary _shopSushis; + public FormShop(ILogger logger, IShopLogic shopLogic) + { + _logger = logger; + _logic = shopLogic; + _shopSushis = new Dictionary(); InitializeComponent(); } + + 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) + { + textBoxName.Text = view.Name; + textBoxAddress.Text = view.Address; + dateTimePickerDateOpening.Text = view.DateOpening.ToString(); + _shopSushis = view.ShopSushis ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() { + _logger.LogInformation("Загрузка изделий магазина"); + try + { + if (_shopSushis != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in _shopPlanes) + { + dataGridView.Rows.Add(new object[] + { + elem.Key, + elem.Value.Item1.PlaneName, + elem.Value.Item2 + }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } } } diff --git a/SushiBar/Shops/FormShops.Designer.cs b/SushiBar/Shops/FormShops.Designer.cs index 7afb1c7..d30a5f3 100644 --- a/SushiBar/Shops/FormShops.Designer.cs +++ b/SushiBar/Shops/FormShops.Designer.cs @@ -28,12 +28,94 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormShops"; + dataGridView = new DataGridView(); + buttonRefresh = new Button(); + buttonRemove = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.BackgroundColor = Color.FromArgb(150, 190, 255); + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(566, 543); + dataGridView.TabIndex = 0; + // + // buttonRefresh + // + buttonRefresh.Font = new Font("Candara", 12F); + buttonRefresh.Location = new Point(626, 453); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(121, 46); + buttonRefresh.TabIndex = 8; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + // + // buttonRemove + // + buttonRemove.Font = new Font("Candara", 12F); + buttonRemove.Location = new Point(626, 316); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(121, 46); + buttonRemove.TabIndex = 7; + buttonRemove.Text = "Удалить"; + buttonRemove.UseVisualStyleBackColor = true; + // + // buttonUpdate + // + buttonUpdate.Font = new Font("Candara", 12F); + buttonUpdate.Location = new Point(626, 176); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(121, 46); + buttonUpdate.TabIndex = 6; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + // + // buttonAdd + // + buttonAdd.Font = new Font("Candara", 12F); + buttonAdd.Location = new Point(626, 44); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(121, 46); + buttonAdd.TabIndex = 5; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + BackColor = Color.FromArgb(190, 220, 255); + ClientSize = new Size(800, 543); + Controls.Add(buttonRefresh); + Controls.Add(buttonRemove); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + Text = "Магазины"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); } #endregion + + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonRemove; + private Button buttonUpdate; + private Button buttonAdd; } } \ No newline at end of file diff --git a/SushiBar/Shops/FormShops.cs b/SushiBar/Shops/FormShops.cs index 63dd50c..b0212ad 100644 --- a/SushiBar/Shops/FormShops.cs +++ b/SushiBar/Shops/FormShops.cs @@ -1,20 +1,18 @@ -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 Microsoft.Extensions.Logging; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModel; +using SushiBarDataModels.Models; using System.Windows.Forms; namespace SushiBarView.Shops { public partial class FormShops : Form { - public FormShops() + + + private void buttonAdd_Click(object sender, EventArgs e) { - InitializeComponent(); + } } } diff --git a/SushiBar/Shops/FormShops.resx b/SushiBar/Shops/FormShops.resx index 1af7de1..af32865 100644 --- a/SushiBar/Shops/FormShops.resx +++ b/SushiBar/Shops/FormShops.resx @@ -1,17 +1,17 @@  - -- 2.25.1 From 0abee5b276b3d57f0ed98972795a914c997d3514 Mon Sep 17 00:00:00 2001 From: ekallin Date: Mon, 11 Mar 2024 12:09:55 +0400 Subject: [PATCH 6/8] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8,=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D0=B0=2011=20(=D1=83=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BA=D0=B0),=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=20?= =?UTF-8?q?=D0=BA=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7=D1=83=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B5=D0=BF=D0=BE=D0=B4=D0=B0=D0=B2=D0=B0=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/FormMain.Designer.cs | 37 +++-- SushiBar/FormMain.cs | 11 +- SushiBar/Program.cs | 7 +- SushiBar/Shops/FormAddSushiInShop.Designer.cs | 149 +++++++++++++++++ SushiBar/Shops/FormAddSushiInShop.cs | 113 +++++++++++++ SushiBar/Shops/FormAddSushiInShop.resx | 120 +++++++++++++ SushiBar/Shops/FormShop.Designer.cs | 157 +++++++++++++++--- SushiBar/Shops/FormShop.cs | 67 ++++++-- SushiBar/Shops/FormShop.resx | 9 + SushiBar/Shops/FormShops.Designer.cs | 4 + SushiBar/Shops/FormShops.cs | 91 +++++++++- SushiBarBusinessLogic/ShopLogic.cs | 24 +-- .../BindingModel/ShopBindingModel.cs | 2 +- .../SearchModel/ShopSearchModel.cs | 2 +- SushiBarContracts/ViewModels/ShopViewModel.cs | 2 +- SushiBarDataModels/IShopModel.cs | 2 +- .../Implements/ShopStorage.cs | 12 +- SushiBarListImplements/Models/Shop.cs | 8 +- 18 files changed, 743 insertions(+), 74 deletions(-) create mode 100644 SushiBar/Shops/FormAddSushiInShop.Designer.cs create mode 100644 SushiBar/Shops/FormAddSushiInShop.cs create mode 100644 SushiBar/Shops/FormAddSushiInShop.resx diff --git a/SushiBar/FormMain.Designer.cs b/SushiBar/FormMain.Designer.cs index dc347ef..070b5ab 100644 --- a/SushiBar/FormMain.Designer.cs +++ b/SushiBar/FormMain.Designer.cs @@ -32,13 +32,14 @@ ToolStripMenuItemRef = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem(); сушиToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); buttonOrderIssued = new Button(); buttonRefreshOrders = new Button(); - магазиныToolStripMenuItem = new ToolStripMenuItem(); + buttonAddSushiInShop = new Button(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -63,17 +64,24 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(224, 26); + компонентыToolStripMenuItem.Size = new Size(182, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; // // сушиToolStripMenuItem // сушиToolStripMenuItem.Name = "сушиToolStripMenuItem"; - сушиToolStripMenuItem.Size = new Size(224, 26); + сушиToolStripMenuItem.Size = new Size(182, 26); сушиToolStripMenuItem.Text = "Суши"; сушиToolStripMenuItem.Click += сушиToolStripMenuItem_Click; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(182, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; + // // dataGridView // dataGridView.BackgroundColor = Color.White; @@ -88,7 +96,7 @@ // // buttonCreateOrder // - buttonCreateOrder.Location = new Point(923, 63); + buttonCreateOrder.Location = new Point(923, 43); buttonCreateOrder.Name = "buttonCreateOrder"; buttonCreateOrder.Size = new Size(171, 52); buttonCreateOrder.TabIndex = 2; @@ -98,7 +106,7 @@ // // buttonTakeOrderInWork // - buttonTakeOrderInWork.Location = new Point(923, 161); + buttonTakeOrderInWork.Location = new Point(923, 118); buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; buttonTakeOrderInWork.Size = new Size(171, 52); buttonTakeOrderInWork.TabIndex = 3; @@ -108,7 +116,7 @@ // // buttonOrderReady // - buttonOrderReady.Location = new Point(923, 253); + buttonOrderReady.Location = new Point(923, 191); buttonOrderReady.Name = "buttonOrderReady"; buttonOrderReady.Size = new Size(171, 52); buttonOrderReady.TabIndex = 4; @@ -118,7 +126,7 @@ // // buttonOrderIssued // - buttonOrderIssued.Location = new Point(923, 351); + buttonOrderIssued.Location = new Point(923, 264); buttonOrderIssued.Name = "buttonOrderIssued"; buttonOrderIssued.Size = new Size(171, 52); buttonOrderIssued.TabIndex = 5; @@ -135,12 +143,15 @@ buttonRefreshOrders.Text = "Обновить заказы"; buttonRefreshOrders.UseVisualStyleBackColor = true; // - // магазиныToolStripMenuItem + // buttonAddSushiInShop // - магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - магазиныToolStripMenuItem.Size = new Size(224, 26); - магазиныToolStripMenuItem.Text = "Магазины"; - магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; + buttonAddSushiInShop.Location = new Point(923, 359); + buttonAddSushiInShop.Name = "buttonAddSushiInShop"; + buttonAddSushiInShop.Size = new Size(171, 52); + buttonAddSushiInShop.TabIndex = 7; + buttonAddSushiInShop.Text = "Пополнить магазин"; + buttonAddSushiInShop.UseVisualStyleBackColor = true; + buttonAddSushiInShop.Click += buttonAddSushiInShop_Click; // // FormMain // @@ -148,6 +159,7 @@ AutoScaleMode = AutoScaleMode.Font; BackColor = Color.FromArgb(210, 255, 210); ClientSize = new Size(1140, 540); + Controls.Add(buttonAddSushiInShop); Controls.Add(buttonRefreshOrders); Controls.Add(buttonOrderIssued); Controls.Add(buttonOrderReady); @@ -179,5 +191,6 @@ private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem сушиToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem; + private Button buttonAddSushiInShop; } } \ No newline at end of file diff --git a/SushiBar/FormMain.cs b/SushiBar/FormMain.cs index b19cfd7..d6d9980 100644 --- a/SushiBar/FormMain.cs +++ b/SushiBar/FormMain.cs @@ -68,7 +68,7 @@ namespace SushiBarView private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if(service is FormShops formShops) { formShops.ShowDialog(); } + if (service is FormShops formShops) { formShops.ShowDialog(); } } private void buttonCreateOrder_Click(object sender, EventArgs e) @@ -155,5 +155,14 @@ namespace SushiBarView { LoadData(); } + + private void buttonAddSushiInShop_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddSushiInShop)); + if (service is FormAddSushiInShop form) + { + form.ShowDialog(); + } + } } } diff --git a/SushiBar/Program.cs b/SushiBar/Program.cs index a973c59..ece830d 100644 --- a/SushiBar/Program.cs +++ b/SushiBar/Program.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using SushiBarBusinessLogic; using SushiBarBusinessLogic.BusinessLogic; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.StoragesContracts; @@ -29,7 +30,6 @@ namespace SushiBar ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); Application.Run(_serviceProvider.GetRequiredService()); - //Application.Run(new Form1()); } private static void ConfigureServices(ServiceCollection services) @@ -42,9 +42,13 @@ namespace SushiBar services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -54,6 +58,7 @@ namespace SushiBar services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SushiBar/Shops/FormAddSushiInShop.Designer.cs b/SushiBar/Shops/FormAddSushiInShop.Designer.cs new file mode 100644 index 0000000..84dd31f --- /dev/null +++ b/SushiBar/Shops/FormAddSushiInShop.Designer.cs @@ -0,0 +1,149 @@ +namespace SushiBarView.Shops +{ + partial class FormAddSushiInShop + { + /// + /// 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() + { + comboBoxSushi = new ComboBox(); + labelSushi = new Label(); + labelShop = new Label(); + comboBoxShop = new ComboBox(); + textBoxCount = new TextBox(); + labelCount = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxSushi + // + comboBoxSushi.FormattingEnabled = true; + comboBoxSushi.Location = new Point(212, 49); + comboBoxSushi.Margin = new Padding(4); + comboBoxSushi.Name = "comboBoxSushi"; + comboBoxSushi.Size = new Size(188, 30); + comboBoxSushi.TabIndex = 0; + // + // labelSushi + // + labelSushi.AutoSize = true; + labelSushi.Location = new Point(42, 57); + labelSushi.Margin = new Padding(4, 0, 4, 0); + labelSushi.Name = "labelSushi"; + labelSushi.Size = new Size(60, 22); + labelSushi.TabIndex = 1; + labelSushi.Text = "Суши: "; + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(42, 188); + labelShop.Margin = new Padding(4, 0, 4, 0); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(86, 22); + labelShop.TabIndex = 3; + labelShop.Text = "Магазин: "; + // + // comboBoxShop + // + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(212, 188); + comboBoxShop.Margin = new Padding(4); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(188, 30); + comboBoxShop.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(212, 118); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(188, 29); + textBoxCount.TabIndex = 4; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(42, 121); + labelCount.Margin = new Padding(4, 0, 4, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(154, 22); + labelCount.TabIndex = 5; + labelCount.Text = "Количество суши: "; + // + // buttonSave + // + buttonSave.Location = new Point(471, 174); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(107, 44); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(617, 174); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(107, 44); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormAddSushiInShop + // + AutoScaleDimensions = new SizeF(10F, 22F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(762, 267); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCount); + Controls.Add(textBoxCount); + Controls.Add(labelShop); + Controls.Add(comboBoxShop); + Controls.Add(labelSushi); + Controls.Add(comboBoxSushi); + Font = new Font("Candara", 10.8F, FontStyle.Regular, GraphicsUnit.Point, 204); + Margin = new Padding(4); + Name = "FormAddSushiInShop"; + Text = "FormAddSushiInShop"; + Load += FormAddSushiInShop_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxSushi; + private Label labelSushi; + private Label labelShop; + private ComboBox comboBoxShop; + private TextBox textBoxCount; + private Label labelCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SushiBar/Shops/FormAddSushiInShop.cs b/SushiBar/Shops/FormAddSushiInShop.cs new file mode 100644 index 0000000..0ce25db --- /dev/null +++ b/SushiBar/Shops/FormAddSushiInShop.cs @@ -0,0 +1,113 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModel; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModel; + +namespace SushiBarView.Shops +{ + public partial class FormAddSushiInShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + private readonly ISushiLogic _sushiLogic; + + public FormAddSushiInShop(ILogger logger, IShopLogic shopLogic, ISushiLogic sushiLogic) + { + InitializeComponent(); + _logger = logger; + _shopLogic = shopLogic; + _sushiLogic = sushiLogic; + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSushi.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Введите количество изделий", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Добавление изделия в магазин"); + + try + { + var operationResult = _shopLogic.AddSushiInShop( + new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue), ShopName = comboBoxShop.Text }, + new SushiBindingModel { Id = Convert.ToInt32(comboBoxSushi.SelectedValue), SushiName = comboBoxSushi.Text }, + Convert.ToInt32(textBoxCount.Text) + ); + + if (!operationResult) + { + throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormAddSushiInShop_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка магазинов"); + try + { + var listShops = _shopLogic.ReadList(null); + if (listShops != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = listShops; + comboBoxShop.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка суши"); + try + { + var list = _sushiLogic.ReadList(null); + if (list != null) + { + comboBoxSushi.DisplayMember = "SushiName"; + comboBoxSushi.ValueMember = "Id"; + comboBoxSushi.DataSource = list; + comboBoxSushi.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка авто"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SushiBar/Shops/FormAddSushiInShop.resx b/SushiBar/Shops/FormAddSushiInShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBar/Shops/FormAddSushiInShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/Shops/FormShop.Designer.cs b/SushiBar/Shops/FormShop.Designer.cs index f597a2e..b5c8502 100644 --- a/SushiBar/Shops/FormShop.Designer.cs +++ b/SushiBar/Shops/FormShop.Designer.cs @@ -31,55 +31,60 @@ buttonCancel = new Button(); buttonSave = new Button(); textBoxAddress = new TextBox(); - textBoxName = new TextBox(); labelAddress = new Label(); labelName = new Label(); dateTimePickerDateOpening = new DateTimePicker(); labelDateOpening = new Label(); + groupBoxComponents = new GroupBox(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnSushiName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + textBoxName = new TextBox(); + groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // // buttonCancel // buttonCancel.Anchor = AnchorStyles.None; - buttonCancel.Location = new Point(421, 203); + buttonCancel.Location = new Point(710, 431); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(116, 39); buttonCancel.TabIndex = 11; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; // // buttonSave // buttonSave.Anchor = AnchorStyles.None; - buttonSave.Location = new Point(182, 203); + buttonSave.Location = new Point(471, 431); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(116, 39); buttonSave.TabIndex = 10; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; // // textBoxAddress // textBoxAddress.Anchor = AnchorStyles.None; - textBoxAddress.Location = new Point(182, 86); + textBoxAddress.Location = new Point(124, 46); textBoxAddress.Name = "textBoxAddress"; - textBoxAddress.Size = new Size(355, 27); + textBoxAddress.Size = new Size(330, 27); textBoxAddress.TabIndex = 9; // - // textBoxName - // - textBoxName.Anchor = AnchorStyles.None; - textBoxName.Location = new Point(182, 20); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(355, 27); - textBoxName.TabIndex = 8; - // // labelAddress // labelAddress.Anchor = AnchorStyles.None; labelAddress.AutoSize = true; labelAddress.Font = new Font("Candara", 12F); - labelAddress.Location = new Point(34, 86); + labelAddress.Location = new Point(24, 46); labelAddress.Margin = new Padding(4, 0, 4, 0); labelAddress.Name = "labelAddress"; labelAddress.Size = new Size(63, 24); @@ -91,7 +96,7 @@ labelName.Anchor = AnchorStyles.None; labelName.AutoSize = true; labelName.Font = new Font("Candara", 12F); - labelName.Location = new Point(18, 23); + labelName.Location = new Point(24, 9); labelName.Margin = new Padding(4, 0, 4, 0); labelName.Name = "labelName"; labelName.Size = new Size(93, 24); @@ -100,7 +105,7 @@ // // dateTimePickerDateOpening // - dateTimePickerDateOpening.Location = new Point(182, 152); + dateTimePickerDateOpening.Location = new Point(471, 46); dateTimePickerDateOpening.Name = "dateTimePickerDateOpening"; dateTimePickerDateOpening.Size = new Size(355, 27); dateTimePickerDateOpening.TabIndex = 12; @@ -110,28 +115,131 @@ labelDateOpening.Anchor = AnchorStyles.None; labelDateOpening.AutoSize = true; labelDateOpening.Font = new Font("Candara", 12F); - labelDateOpening.Location = new Point(18, 155); + labelDateOpening.Location = new Point(471, 6); labelDateOpening.Margin = new Padding(4, 0, 4, 0); labelDateOpening.Name = "labelDateOpening"; labelDateOpening.Size = new Size(140, 24); labelDateOpening.TabIndex = 13; labelDateOpening.Text = "Дата открытия"; // + // groupBoxComponents + // + groupBoxComponents.Controls.Add(buttonRefresh); + groupBoxComponents.Controls.Add(buttonDelete); + groupBoxComponents.Controls.Add(buttonUpdate); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Controls.Add(dataGridView); + groupBoxComponents.Location = new Point(11, 93); + groupBoxComponents.Margin = new Padding(2, 3, 2, 3); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Padding = new Padding(2, 3, 2, 3); + groupBoxComponents.Size = new Size(443, 396); + groupBoxComponents.TabIndex = 18; + groupBoxComponents.TabStop = false; + // + // buttonRefresh + // + buttonRefresh.BackColor = Color.FromArgb(255, 192, 192); + buttonRefresh.Location = new Point(483, 330); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(127, 47); + buttonRefresh.TabIndex = 9; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = false; + // + // buttonDelete + // + buttonDelete.BackColor = Color.FromArgb(255, 192, 192); + buttonDelete.Location = new Point(483, 228); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(127, 47); + buttonDelete.TabIndex = 8; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = false; + // + // buttonUpdate + // + buttonUpdate.BackColor = Color.FromArgb(255, 192, 192); + buttonUpdate.Location = new Point(483, 125); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(127, 47); + buttonUpdate.TabIndex = 7; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = false; + // + // buttonAdd + // + buttonAdd.BackColor = Color.FromArgb(255, 192, 192); + buttonAdd.Location = new Point(483, 27); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(127, 47); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = false; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.BackgroundColor = Color.FromArgb(255, 192, 192); + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnSushiName, ColumnCount }); + dataGridView.Location = new Point(13, 27); + dataGridView.Margin = new Padding(2, 3, 2, 3); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(419, 350); + dataGridView.TabIndex = 5; + // + // ColumnId + // + ColumnId.HeaderText = "id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + // + // ColumnSushiName + // + ColumnSushiName.HeaderText = "Название Суши"; + ColumnSushiName.MinimumWidth = 6; + ColumnSushiName.Name = "ColumnSushiName"; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + // + // textBoxName + // + textBoxName.Anchor = AnchorStyles.None; + textBoxName.Location = new Point(124, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(330, 27); + textBoxName.TabIndex = 19; + // // FormShop // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(571, 273); + ClientSize = new Size(849, 522); + Controls.Add(textBoxName); + Controls.Add(groupBoxComponents); Controls.Add(labelDateOpening); Controls.Add(dateTimePickerDateOpening); Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(textBoxAddress); - Controls.Add(textBoxName); Controls.Add(labelAddress); Controls.Add(labelName); Name = "FormShop"; Text = "Магазин"; + Load += FormShop_Load; + groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -141,10 +249,19 @@ private Button buttonCancel; private Button buttonSave; private TextBox textBoxAddress; - private TextBox textBoxName; private Label labelAddress; private Label labelName; private DateTimePicker dateTimePickerDateOpening; private Label labelDateOpening; + private GroupBox groupBoxComponents; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonAdd; + private DataGridView dataGridView; + private TextBox textBoxName; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnSushiName; + private DataGridViewTextBoxColumn ColumnCount; } } \ No newline at end of file diff --git a/SushiBar/Shops/FormShop.cs b/SushiBar/Shops/FormShop.cs index 27d8ec2..1cb7457 100644 --- a/SushiBar/Shops/FormShop.cs +++ b/SushiBar/Shops/FormShop.cs @@ -1,17 +1,9 @@ using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModel; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModel; using SushiBarDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; -using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace SushiBarView.Shops { @@ -26,7 +18,7 @@ namespace SushiBarView.Shops } private Dictionary _shopSushis; - public FormShop(ILogger logger, IShopLogic shopLogic) + public FormShop(ILogger logger, IShopLogic shopLogic) { _logger = logger; _logic = shopLogic; @@ -44,7 +36,7 @@ namespace SushiBarView.Shops var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); if (view != null) { - textBoxName.Text = view.Name; + textBoxName.Text = view.ShopName; textBoxAddress.Text = view.Address; dateTimePickerDateOpening.Text = view.DateOpening.ToString(); _shopSushis = view.ShopSushis ?? new Dictionary(); @@ -59,19 +51,20 @@ namespace SushiBarView.Shops } } - private void LoadData() { + private void LoadData() + { _logger.LogInformation("Загрузка изделий магазина"); try { if (_shopSushis != null) { dataGridView.Rows.Clear(); - foreach (var elem in _shopPlanes) + foreach (var elem in _shopSushis) { dataGridView.Rows.Add(new object[] { elem.Key, - elem.Value.Item1.PlaneName, + elem.Value.Item1.SushiName, elem.Value.Item2 }); } @@ -83,5 +76,51 @@ namespace SushiBarView.Shops MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Введите название магазина", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Введите название магазина", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation($"Сохранение магазина {textBoxName.Text}"); + + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePickerDateOpening.Value.Date, + ShopSushis = _shopSushis + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } } } diff --git a/SushiBar/Shops/FormShop.resx b/SushiBar/Shops/FormShop.resx index af32865..4d676b5 100644 --- a/SushiBar/Shops/FormShop.resx +++ b/SushiBar/Shops/FormShop.resx @@ -117,4 +117,13 @@ 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/SushiBar/Shops/FormShops.Designer.cs b/SushiBar/Shops/FormShops.Designer.cs index d30a5f3..924eb99 100644 --- a/SushiBar/Shops/FormShops.Designer.cs +++ b/SushiBar/Shops/FormShops.Designer.cs @@ -61,6 +61,7 @@ buttonRefresh.TabIndex = 8; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; // // buttonRemove // @@ -71,6 +72,7 @@ buttonRemove.TabIndex = 7; buttonRemove.Text = "Удалить"; buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; // // buttonUpdate // @@ -81,6 +83,7 @@ buttonUpdate.TabIndex = 6; buttonUpdate.Text = "Изменить"; buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; // // buttonAdd // @@ -106,6 +109,7 @@ Controls.Add(dataGridView); Name = "FormShops"; Text = "Магазины"; + Load += FormShops_LoadData; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); } diff --git a/SushiBar/Shops/FormShops.cs b/SushiBar/Shops/FormShops.cs index b0212ad..c8f893e 100644 --- a/SushiBar/Shops/FormShops.cs +++ b/SushiBar/Shops/FormShops.cs @@ -1,4 +1,6 @@ using Microsoft.Extensions.Logging; +using SushiBar; +using SushiBarContracts.BindingModel; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModel; using SushiBarDataModels.Models; @@ -8,11 +10,98 @@ namespace SushiBarView.Shops { public partial class FormShops : Form { - + private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + + public FormShops(ILogger logger, IShopLogic shopLogic) + { + InitializeComponent(); + _logger = logger; + _shopLogic = shopLogic; + } + + private void FormShops_LoadData(object sender, EventArgs e) + { + LoadData(); + } private void buttonAdd_Click(object sender, EventArgs e) { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void LoadData() + { + try + { + var list = _shopLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopSushis"].Visible = false; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonUpdate_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 buttonRemove_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 (!_shopLogic.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 buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); } } } diff --git a/SushiBarBusinessLogic/ShopLogic.cs b/SushiBarBusinessLogic/ShopLogic.cs index b0fb3bf..aa57ed7 100644 --- a/SushiBarBusinessLogic/ShopLogic.cs +++ b/SushiBarBusinessLogic/ShopLogic.cs @@ -14,7 +14,7 @@ namespace SushiBarBusinessLogic private readonly ILogger _logger; private readonly IShopStorage _shopStorage; - public ShopLogic(ILogger logger, IShopStorage shopStorage) + public ShopLogic(ILogger logger, IShopStorage shopStorage) { _logger = logger; _shopStorage = shopStorage; @@ -22,7 +22,7 @@ namespace SushiBarBusinessLogic public List? ReadList(ShopSearchModel? model) { - _logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model?.Id, model?.Name); + _logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model?.Id, model?.ShopName); var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); if (list == null) { @@ -39,7 +39,7 @@ namespace SushiBarBusinessLogic { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model.Id, model.Name); + _logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model.Id, model.ShopName); var element = _shopStorage.GetElement(model); if (element == null) { @@ -88,7 +88,7 @@ namespace SushiBarBusinessLogic if (model == null) throw new ArgumentNullException(nameof(model)); if(count <= 0) throw new ArgumentException(nameof(count)); - _logger.LogInformation("AddSushiInShop. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id); + _logger.LogInformation("AddSushiInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); var element = _shopStorage.GetElement(model); if (element == null) @@ -99,18 +99,18 @@ namespace SushiBarBusinessLogic if (element.ShopSushis.TryGetValue(sushi.Id, out var samesushi)) { element.ShopSushis[sushi.Id] = (sushi, samesushi.Item2 + count); - _logger.LogInformation("Same sushi found by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.Name); + _logger.LogInformation("Same sushi found by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.ShopName); } else { element.ShopSushis[sushi.Id] = (sushi, count); - _logger.LogInformation("New sushi added by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.Name); + _logger.LogInformation("New sushi added by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.ShopName); } _shopStorage.Update(new() { Id = element.Id, - Name = element.Name, + ShopName = element.ShopName, Address = element.Address, DateOpening = element.DateOpening, ShopSushis = element.ShopSushis @@ -124,17 +124,17 @@ namespace SushiBarBusinessLogic if(model == null) throw new ArgumentNullException($"{nameof(model)} является null"); if (!withParams) return; - if (string.IsNullOrEmpty(model.Name)) + if (string.IsNullOrEmpty(model.ShopName)) { - throw new ArgumentNullException("Нет такого магазина", nameof(model.Name)); + throw new ArgumentNullException("Нет такого магазина", nameof(model.ShopName)); } _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{ Address}. Id:{ Id}", - model.Name, model.Address, model.Id); + model.ShopName, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel { - Name = model.Name, + ShopName = model.ShopName, }); - if(element != null && element.Id != model.Id && element.Name == model.Name) + if(element != null && element.Id != model.Id && element.ShopName == model.ShopName) { throw new InvalidOperationException("Такой магазин с таким названием уже есть"); } diff --git a/SushiBarContracts/BindingModel/ShopBindingModel.cs b/SushiBarContracts/BindingModel/ShopBindingModel.cs index c27c14a..ce08d0a 100644 --- a/SushiBarContracts/BindingModel/ShopBindingModel.cs +++ b/SushiBarContracts/BindingModel/ShopBindingModel.cs @@ -6,7 +6,7 @@ namespace SushiBarContracts.BindingModel public class ShopBindingModel : IShopModel { public int Id { get; set; } - public string Name { get; set; } + public string ShopName { get; set; } public string Address { get; set; } public DateTime DateOpening { get; set; } = DateTime.Now; public Dictionary ShopSushis { get; set; } = new(); diff --git a/SushiBarContracts/SearchModel/ShopSearchModel.cs b/SushiBarContracts/SearchModel/ShopSearchModel.cs index f34d7e5..e725658 100644 --- a/SushiBarContracts/SearchModel/ShopSearchModel.cs +++ b/SushiBarContracts/SearchModel/ShopSearchModel.cs @@ -3,6 +3,6 @@ public class ShopSearchModel { public int? Id { get; set; } - public string? Name { get; set; } + public string? ShopName { get; set; } } } diff --git a/SushiBarContracts/ViewModels/ShopViewModel.cs b/SushiBarContracts/ViewModels/ShopViewModel.cs index 09b0864..65f7a65 100644 --- a/SushiBarContracts/ViewModels/ShopViewModel.cs +++ b/SushiBarContracts/ViewModels/ShopViewModel.cs @@ -9,7 +9,7 @@ namespace SushiBarContracts.ViewModels public int Id { get; set; } [DisplayName("Название магазина")] - public string Name { get; set; } = string.Empty; + public string ShopName { get; set; } = string.Empty; [DisplayName("Адрес")] public string Address { get; set; } = string.Empty; diff --git a/SushiBarDataModels/IShopModel.cs b/SushiBarDataModels/IShopModel.cs index cd01a16..50200b3 100644 --- a/SushiBarDataModels/IShopModel.cs +++ b/SushiBarDataModels/IShopModel.cs @@ -4,7 +4,7 @@ namespace SushiBarDataModels { public interface IShopModel : IId { - string Name { get; } + string ShopName { get; } string Address { get; } DateTime DateOpening { get; } Dictionary ShopSushis{ get; } diff --git a/SushiBarListImplements/Implements/ShopStorage.cs b/SushiBarListImplements/Implements/ShopStorage.cs index 6320310..93cedda 100644 --- a/SushiBarListImplements/Implements/ShopStorage.cs +++ b/SushiBarListImplements/Implements/ShopStorage.cs @@ -10,7 +10,7 @@ namespace SushiBarListImplements.Implements public class ShopStorage : IShopStorage { private DataListSingleton _source; - public ShopStorage(DataListSingleton source) + public ShopStorage() { _source = DataListSingleton.GetInstance(); } @@ -28,13 +28,14 @@ namespace SushiBarListImplements.Implements public List GetFilteredList(ShopSearchModel model) { var result = new List(); - if (model == null || !model.Id.HasValue) + if (string.IsNullOrEmpty(model.ShopName)) { return result; } + foreach (var shop in _source.Shops) { - if (shop.Id == model.Id) + if (shop.ShopName.Contains(model.ShopName)) { result.Add(shop.GetViewModel); } @@ -44,13 +45,14 @@ namespace SushiBarListImplements.Implements public ShopViewModel? GetElement(ShopSearchModel model) { - if (!model.Id.HasValue) + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) { return null; } + foreach (var shop in _source.Shops) { - if (shop.Id == model.Id) + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (model.Id.HasValue && shop.Id == model.Id)) { return shop.GetViewModel; } diff --git a/SushiBarListImplements/Models/Shop.cs b/SushiBarListImplements/Models/Shop.cs index 2d034d3..28152ec 100644 --- a/SushiBarListImplements/Models/Shop.cs +++ b/SushiBarListImplements/Models/Shop.cs @@ -13,7 +13,7 @@ namespace SushiBarListImplements.Models public class Shop : IShopModel { public int Id { get; private set; } - public string Name { get; private set; } + public string ShopName { get; private set; } public string Address { get; private set; } public DateTime DateOpening { get; private set; } = DateTime.Now; public Dictionary ShopSushis @@ -28,7 +28,7 @@ namespace SushiBarListImplements.Models return new Shop() { Id = model.Id, - Name = model.Name, + ShopName = model.ShopName, Address = model.Address, DateOpening = model.DateOpening, ShopSushis = model.ShopSushis @@ -38,7 +38,7 @@ namespace SushiBarListImplements.Models public void Update(ShopBindingModel? model) { if (model == null) return; - Name = model.Name; + ShopName = model.ShopName; Address = model.Address; DateOpening = model.DateOpening; ShopSushis = model.ShopSushis; @@ -47,7 +47,7 @@ namespace SushiBarListImplements.Models public ShopViewModel GetViewModel => new() { Id = Id, - Name = Name, + ShopName = ShopName, Address = Address, DateOpening = DateOpening, ShopSushis = ShopSushis -- 2.25.1 From 30b174f8a7d34a4501dc60d28e32bef23c2b85a6 Mon Sep 17 00:00:00 2001 From: ekallin Date: Mon, 8 Apr 2024 10:48:18 +0300 Subject: [PATCH 7/8] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/FormMain.Designer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/SushiBar/FormMain.Designer.cs b/SushiBar/FormMain.Designer.cs index 070b5ab..2368eae 100644 --- a/SushiBar/FormMain.Designer.cs +++ b/SushiBar/FormMain.Designer.cs @@ -142,6 +142,7 @@ buttonRefreshOrders.TabIndex = 6; buttonRefreshOrders.Text = "Обновить заказы"; buttonRefreshOrders.UseVisualStyleBackColor = true; + buttonRefreshOrders.Click += ButtonRef_Click; // // buttonAddSushiInShop // -- 2.25.1 From 8384d09202582e6fc3324d777b541ef6714c8e04 Mon Sep 17 00:00:00 2001 From: ekallin Date: Mon, 8 Apr 2024 11:07:36 +0300 Subject: [PATCH 8/8] =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BA=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D0=BE=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBarBusinessLogic/ShopLogic.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/SushiBarBusinessLogic/ShopLogic.cs b/SushiBarBusinessLogic/ShopLogic.cs index aa57ed7..aee1200 100644 --- a/SushiBarBusinessLogic/ShopLogic.cs +++ b/SushiBarBusinessLogic/ShopLogic.cs @@ -85,7 +85,8 @@ namespace SushiBarBusinessLogic public bool AddSushiInShop(ShopSearchModel model, ISushiModel sushi, int count) { - if (model == null) throw new ArgumentNullException(nameof(model)); + if (model == null) + throw new ArgumentNullException(nameof(model)); if(count <= 0) throw new ArgumentException(nameof(count)); _logger.LogInformation("AddSushiInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); @@ -93,18 +94,18 @@ namespace SushiBarBusinessLogic var element = _shopStorage.GetElement(model); if (element == null) { - _logger.LogWarning("Не добавлено"); + _logger.LogWarning("Не добавлено, такого магазина нет"); return false; } if (element.ShopSushis.TryGetValue(sushi.Id, out var samesushi)) { element.ShopSushis[sushi.Id] = (sushi, samesushi.Item2 + count); - _logger.LogInformation("Same sushi found by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.ShopName); + _logger.LogInformation("Такие суши есть, мы добавили {0} суши с названием {1} в магазин '{2}' ", count, sushi.SushiName, element.ShopName); } else { element.ShopSushis[sushi.Id] = (sushi, count); - _logger.LogInformation("New sushi added by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.ShopName); + _logger.LogInformation("мы добавили {0} суши с названием {1} в магазин '{2}' ", count, sushi.SushiName, element.ShopName); } _shopStorage.Update(new() -- 2.25.1