From 92e0198a9baa786e7a2a40711103234a9ce38e5e Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Tue, 7 Feb 2023 13:21:07 +0400 Subject: [PATCH 1/6] =?UTF-8?q?=D1=81=D0=B4=D0=B0=D0=BD=D0=BE!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JewelryStore/FormJewels.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/JewelryStore/FormJewels.cs b/JewelryStore/FormJewels.cs index bea74a4..5f5f06f 100644 --- a/JewelryStore/FormJewels.cs +++ b/JewelryStore/FormJewels.cs @@ -36,6 +36,8 @@ namespace JewelryStore DataGridView.DataSource = list; DataGridView.Columns["Id"].Visible = false; DataGridView.Columns["JewelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["JewelComponents"].Visible = false; + } _logger.LogInformation("Загрузка компонентов"); -- 2.25.1 From 5057ab29c60f83b7c523db63c89cf1b75e74f9ce Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 6 Mar 2023 16:34:47 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=B2=D1=81=D0=B5=20=D0=BA=D1=80=D0=BE?= =?UTF-8?q?=D0=BC=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/StoreLogic .cs | 181 ++++++++++++++++++ .../BindingModels/StoreBindingModel.cs | 21 ++ .../BusinessLogicsContracts/IStoreLogic.cs | 22 +++ .../SearchModels/StoreSearchModel.cs | 14 ++ .../StoragesContracts/IStoreStorage.cs | 21 ++ .../ViewModels/StoreViewModel.cs | 23 +++ JewelryStoreDataModels/Models/IStoreModel.cs | 16 ++ .../DataListSingleton.cs | 2 + .../Implements/StoreStorage.cs | 123 ++++++++++++ JewelryStoreListImplement/Models/Store.cs | 60 ++++++ 10 files changed, 483 insertions(+) create mode 100644 JewelryStoreBusinessLogic/BusinessLogics/StoreLogic .cs create mode 100644 JewelryStoreContracts/BindingModels/StoreBindingModel.cs create mode 100644 JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs create mode 100644 JewelryStoreContracts/SearchModels/StoreSearchModel.cs create mode 100644 JewelryStoreContracts/StoragesContracts/IStoreStorage.cs create mode 100644 JewelryStoreContracts/ViewModels/StoreViewModel.cs create mode 100644 JewelryStoreDataModels/Models/IStoreModel.cs create mode 100644 JewelryStoreListImplement/Implements/StoreStorage.cs create mode 100644 JewelryStoreListImplement/Models/Store.cs diff --git a/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic .cs b/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic .cs new file mode 100644 index 0000000..52e2036 --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic .cs @@ -0,0 +1,181 @@ +using Microsoft.Extensions.Logging; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreDataModels.Models; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + internal class StoreLogic : IStoreLogic + { + private readonly ILogger _logger; + private readonly IStoreStorage _storeStorage; + public StoreLogic(ILogger logger, IStoreStorage storeStorage) + { + _logger = logger; + _storeStorage = storeStorage; + } + public bool AddJewel(StoreSearchModel model, IJewelModel jewel, int quantity) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (quantity <= 0) + { + throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(quantity)); + } + + _logger.LogInformation("AddJewelInStore. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id); + var element = _storeStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("AddJewelInStore element not found"); + return false; + } + + _logger.LogInformation("AddJewelInStore find. Id:{Id}", element.Id); + + if (element.Jewels.TryGetValue(jewel.Id, out var pair)) + { + element.Jewels[jewel.Id] = (jewel, quantity + pair.Item2); + _logger.LogInformation("AddJewelInStore. Has been added {quantity} {jewel} in {StoreName}", quantity, jewel.JewelName, element.StoreName); + } + else + { + element.Jewels[jewel.Id] = (jewel, quantity); + _logger.LogInformation("AddPastryInShop. Has been added {quantity} new Jewel {jewel} in {StoreName}", quantity, jewel.JewelName, element.StoreName); + } + + _storeStorage.Update(new() + { + Id = element.Id, + StoreAdress = element.StoreAdress, + StoreName = element.StoreName, + OpeningDate = element.OpeningDate, + Jewels = element.Jewels + }); + return true; + } + + public bool Create(StoreBindingModel model) + { + CheckModel(model); + model.Jewels = new(); + + if (_storeStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Delete(StoreBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_storeStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + public StoreViewModel? ReadElement(StoreSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id); + var element = _storeStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(StoreSearchModel? model) + { + _logger.LogInformation("ReadList. StoreName:{StoreName}.Id:{ Id} ", model?.StoreName, model?.Id); + + var list = (model == null) ? _storeStorage.GetFullList() : _storeStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(StoreBindingModel model) + { + CheckModel(model, false); + + if (string.IsNullOrEmpty(model.StoreName)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.StoreName)); + } + + if (_storeStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(StoreBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.StoreName)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.StoreName)); + } + + _logger.LogInformation("Store. StoreName:{0}.StoreAdress:{1}. Id: {2}", model.StoreName, model.StoreAdress, model.Id); + var element = _storeStorage.GetElement(new StoreSearchModel + { + StoreName = model.StoreName + }); + + if (element != null && element.Id != model.Id && element.StoreName == model.StoreName) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + } +} diff --git a/JewelryStoreContracts/BindingModels/StoreBindingModel.cs b/JewelryStoreContracts/BindingModels/StoreBindingModel.cs new file mode 100644 index 0000000..9198ea6 --- /dev/null +++ b/JewelryStoreContracts/BindingModels/StoreBindingModel.cs @@ -0,0 +1,21 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.BindingModels +{ + public class StoreBindingModel: IStoreModel + { + public string StoreName { get; set; } = string.Empty; + public string StoreAdress { get; set; } = string.Empty; + + public DateTime OpeningDate { get; set; } = DateTime.Now; + + public Dictionary Jewels { get; set; } = new(); + + public int Id { get; set; } + } +} diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs new file mode 100644 index 0000000..4bf2807 --- /dev/null +++ b/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs @@ -0,0 +1,22 @@ +using JewelryStoreContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; + +namespace JewelryStoreContracts.BusinessLogicsContracts +{ + public interface IStoreLogic + { + List? ReadList(StoreSearchModel? model); + StoreViewModel? ReadElement(StoreSearchModel model); + bool Create(StoreBindingModel model); + bool Update(StoreBindingModel model); + bool Delete(StoreBindingModel model); + bool AddJewel(StoreSearchModel model, IJewelModel jewel, int quantity); + } +} diff --git a/JewelryStoreContracts/SearchModels/StoreSearchModel.cs b/JewelryStoreContracts/SearchModels/StoreSearchModel.cs new file mode 100644 index 0000000..1ffd758 --- /dev/null +++ b/JewelryStoreContracts/SearchModels/StoreSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.SearchModels +{ + public class StoreSearchModel + { + public int? Id { get; set; } + public string? StoreName { get; set; } + } +} diff --git a/JewelryStoreContracts/StoragesContracts/IStoreStorage.cs b/JewelryStoreContracts/StoragesContracts/IStoreStorage.cs new file mode 100644 index 0000000..ded1a42 --- /dev/null +++ b/JewelryStoreContracts/StoragesContracts/IStoreStorage.cs @@ -0,0 +1,21 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.StoragesContracts +{ + public interface IStoreStorage + { + List GetFullList(); + List GetFilteredList(StoreSearchModel model); + StoreViewModel? GetElement(StoreSearchModel model); + StoreViewModel? Insert(StoreBindingModel model); + StoreViewModel? Update(StoreBindingModel model); + StoreViewModel? Delete(StoreBindingModel model); + } +} diff --git a/JewelryStoreContracts/ViewModels/StoreViewModel.cs b/JewelryStoreContracts/ViewModels/StoreViewModel.cs new file mode 100644 index 0000000..3487455 --- /dev/null +++ b/JewelryStoreContracts/ViewModels/StoreViewModel.cs @@ -0,0 +1,23 @@ +using JewelryStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreContracts.ViewModels +{ + public class StoreViewModel : IStoreModel + { + public Dictionary Jewels { get; set; } = new(); + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string StoreName { get; set; } = string.Empty; + [DisplayName("Адрес магазина")] + public string StoreAdress { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } = DateTime.Now; + } +} diff --git a/JewelryStoreDataModels/Models/IStoreModel.cs b/JewelryStoreDataModels/Models/IStoreModel.cs new file mode 100644 index 0000000..b4c8b1b --- /dev/null +++ b/JewelryStoreDataModels/Models/IStoreModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreDataModels.Models +{ + public interface IStoreModel : IId + { + public string StoreName { get; } + public string StoreAdress { get; } + DateTime OpeningDate { get; } + Dictionary Jewels { get; } + } +} diff --git a/JewelryStoreListImplement/DataListSingleton.cs b/JewelryStoreListImplement/DataListSingleton.cs index 1b280c4..49ea268 100644 --- a/JewelryStoreListImplement/DataListSingleton.cs +++ b/JewelryStoreListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace JewelryStoreListImplement public List Components { get; set; } public List Orders { get; set; } public List Jewels { get; set; } + public List Stores { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Jewels = new List(); + Stores = new List(); } public static DataListSingleton GetInstance() { diff --git a/JewelryStoreListImplement/Implements/StoreStorage.cs b/JewelryStoreListImplement/Implements/StoreStorage.cs new file mode 100644 index 0000000..023c1ff --- /dev/null +++ b/JewelryStoreListImplement/Implements/StoreStorage.cs @@ -0,0 +1,123 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Implements +{ + public class StoreStorage: IStoreStorage + { + private readonly DataListSingleton _source; + public StoreStorage() + { + _source = DataListSingleton.GetInstance(); + } + public StoreViewModel? Delete(StoreBindingModel model) + { + for (int i = 0; i < _source.Stores.Count; ++i) + { + if (_source.Stores[i].Id == model.Id) + { + var element = _source.Stores[i]; + _source.Stores.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public StoreViewModel? GetElement(StoreSearchModel model) + { + if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue) + { + return null; + } + + foreach (var store in _source.Stores) + { + if ((!string.IsNullOrEmpty(model.StoreName) && store.StoreName == model.StoreName) || (model.Id.HasValue && store.Id == model.Id)) + { + return store.GetViewModel; + } + } + + return null; + } + + public List GetFilteredList(StoreSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.StoreName)) + { + return result; + } + + foreach (var store in _source.Stores) + { + if (store.StoreName.Contains(model.StoreName)) + { + result.Add(store.GetViewModel); + } + } + + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var store in _source.Stores) + { + result.Add(store.GetViewModel); + } + + return result; + } + + public StoreViewModel? Insert(StoreBindingModel model) + { + model.Id = 1; + + foreach (var store in _source.Stores) + { + if (model.Id <= store.Id) + { + model.Id = store.Id + 1; + } + } + + var newStore = Store.Create(model); + + if (newStore == null) + { + return null; + } + + _source.Stores.Add(newStore); + + return newStore.GetViewModel; + } + + public StoreViewModel? Update(StoreBindingModel model) + { + foreach (var store in _source.Stores) + { + if (store.Id == model.Id) + { + store.Update(model); + return store.GetViewModel; + } + } + + return null; + } + } +} diff --git a/JewelryStoreListImplement/Models/Store.cs b/JewelryStoreListImplement/Models/Store.cs new file mode 100644 index 0000000..e1b80f3 --- /dev/null +++ b/JewelryStoreListImplement/Models/Store.cs @@ -0,0 +1,60 @@ +using JewelryStoreDataModels.Models; +using JewelryStoreContracts.ViewModels; +using JewelryStoreContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreListImplement.Models +{ + public class Store : IStoreModel + { + public string StoreName { get; private set; } = string.Empty; + public string StoreAdress { get; private set; } = string.Empty; + + public DateTime OpeningDate { get; private set; } + + public Dictionary Jewels { get; private set; } = new(); + + public int Id { get; private set; } + + public static Store? Create(StoreBindingModel? model) + { + if (model == null) + { + return null; + } + return new Store() + { + Id = model.Id, + StoreName = model.StoreName, + StoreAdress = model.StoreAdress, + OpeningDate = model.OpeningDate, + Jewels = new() + }; + } + + public void Update(StoreBindingModel? model) + { + if (model == null) + { + return; + } + StoreName = model.StoreName; + StoreAdress = model.StoreAdress; + OpeningDate = model.OpeningDate; + Jewels = model.Jewels; + } + + public StoreViewModel GetViewModel => new() + { + Id = Id, + StoreName = StoreName, + StoreAdress = StoreAdress, + OpeningDate = OpeningDate, + Jewels = Jewels + }; + } +} -- 2.25.1 From f5f8ff1b12bf896d1e343c1dece7bcb2ca930a80 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 6 Mar 2023 22:54:15 +0400 Subject: [PATCH 3/6] full --- JewelryStore/FormJewels.cs | 4 +- JewelryStore/FormMain.Designer.cs | 33 +++- JewelryStore/FormMain.cs | 18 ++ JewelryStore/FormStore.Designer.cs | 183 ++++++++++++++++++ JewelryStore/FormStore.cs | 151 +++++++++++++++ JewelryStore/FormStore.resx | 120 ++++++++++++ .../FormStoreReplenishment.Designer.cs | 142 ++++++++++++++ JewelryStore/FormStoreReplenishment.cs | 104 ++++++++++ JewelryStore/FormStoreReplenishment.resx | 120 ++++++++++++ JewelryStore/FormStores.Designer.cs | 114 +++++++++++ JewelryStore/FormStores.cs | 122 ++++++++++++ JewelryStore/FormStores.resx | 120 ++++++++++++ JewelryStore/Program.cs | 5 + .../BusinessLogics/StoreLogic .cs | 2 +- 14 files changed, 1230 insertions(+), 8 deletions(-) create mode 100644 JewelryStore/FormStore.Designer.cs create mode 100644 JewelryStore/FormStore.cs create mode 100644 JewelryStore/FormStore.resx create mode 100644 JewelryStore/FormStoreReplenishment.Designer.cs create mode 100644 JewelryStore/FormStoreReplenishment.cs create mode 100644 JewelryStore/FormStoreReplenishment.resx create mode 100644 JewelryStore/FormStores.Designer.cs create mode 100644 JewelryStore/FormStores.cs create mode 100644 JewelryStore/FormStores.resx diff --git a/JewelryStore/FormJewels.cs b/JewelryStore/FormJewels.cs index 5f5f06f..5d0a48a 100644 --- a/JewelryStore/FormJewels.cs +++ b/JewelryStore/FormJewels.cs @@ -40,12 +40,12 @@ namespace JewelryStore } - _logger.LogInformation("Загрузка компонентов"); + _logger.LogInformation("Загрузка изделий"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонентов"); + _logger.LogError(ex, "Ошибка загрузки изделий"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/JewelryStore/FormMain.Designer.cs b/JewelryStore/FormMain.Designer.cs index 4988313..06bd776 100644 --- a/JewelryStore/FormMain.Designer.cs +++ b/JewelryStore/FormMain.Designer.cs @@ -34,10 +34,12 @@ this.buttonToWork = new System.Windows.Forms.Button(); this.buttonPut = new System.Windows.Forms.Button(); this.buttonRefresh = new System.Windows.Forms.Button(); + this.StoreReplenishment = new System.Windows.Forms.Button(); this.menuStrip = new System.Windows.Forms.MenuStrip(); this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.StoreToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip.SuspendLayout(); this.SuspendLayout(); @@ -94,7 +96,7 @@ // // buttonRefresh // - this.buttonRefresh.Location = new System.Drawing.Point(1273, 389); + this.buttonRefresh.Location = new System.Drawing.Point(1273, 395); this.buttonRefresh.Name = "buttonRefresh"; this.buttonRefresh.Size = new System.Drawing.Size(215, 34); this.buttonRefresh.TabIndex = 5; @@ -102,6 +104,16 @@ this.buttonRefresh.UseVisualStyleBackColor = true; this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click); // + // StoreReplenishment + // + this.StoreReplenishment.Location = new System.Drawing.Point(1273, 469); + this.StoreReplenishment.Name = "StoreReplenishment"; + this.StoreReplenishment.Size = new System.Drawing.Size(215, 31); + this.StoreReplenishment.TabIndex = 6; + this.StoreReplenishment.Text = "Пополнение магазина"; + this.StoreReplenishment.UseVisualStyleBackColor = true; + this.StoreReplenishment.Click += new System.EventHandler(this.StoreReplenishment_Click); + // // menuStrip // this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24); @@ -117,7 +129,8 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, - this.изделияToolStripMenuItem}); + this.изделияToolStripMenuItem, + this.StoreToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -125,22 +138,30 @@ // компонентыToolStripMenuItem // this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(240, 34); + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); // // изделияToolStripMenuItem // this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(240, 34); + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.изделияToolStripMenuItem.Text = "Драгоценности"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.драгоценностиToolStripMenuItem_Click); // + // StoreToolStripMenuItem + // + this.StoreToolStripMenuItem.Name = "StoreToolStripMenuItem"; + this.StoreToolStripMenuItem.Size = new System.Drawing.Size(270, 34); + this.StoreToolStripMenuItem.Text = "Магазины"; + this.StoreToolStripMenuItem.Click += new System.EventHandler(this.StoreToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1530, 450); + this.ClientSize = new System.Drawing.Size(1530, 599); + this.Controls.Add(this.StoreReplenishment); this.Controls.Add(this.buttonRefresh); this.Controls.Add(this.buttonPut); this.Controls.Add(this.buttonReady); @@ -171,6 +192,8 @@ private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem изделияToolStripMenuItem; + private ToolStripMenuItem StoreToolStripMenuItem; private Button buttonReady; + private Button StoreReplenishment; } } \ No newline at end of file diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs index 3baf773..73b03ea 100644 --- a/JewelryStore/FormMain.cs +++ b/JewelryStore/FormMain.cs @@ -189,5 +189,23 @@ namespace JewelryStore { LoadData(); } + private void StoreToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStores)); + + if (service is FormStores form) + { + form.ShowDialog(); + } + } + private void StoreReplenishment_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment)); + + if (service is FormStoreReplenishment form) + { + form.ShowDialog(); + } + } } } diff --git a/JewelryStore/FormStore.Designer.cs b/JewelryStore/FormStore.Designer.cs new file mode 100644 index 0000000..583d00c --- /dev/null +++ b/JewelryStore/FormStore.Designer.cs @@ -0,0 +1,183 @@ +namespace JewelryStore +{ + partial class FormStore + { + /// + /// 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.StoreNameLabel = new System.Windows.Forms.Label(); + this.StoreAdressLabel = new System.Windows.Forms.Label(); + this.OpeningDateLabel = new System.Windows.Forms.Label(); + this.NameComboBox = new System.Windows.Forms.ComboBox(); + this.AdressTextBox = new System.Windows.Forms.TextBox(); + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.JewelName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.JewelPrice = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.JewelCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.OpeningDatePicker = new System.Windows.Forms.DateTimePicker(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // StoreNameLabel + // + this.StoreNameLabel.AutoSize = true; + this.StoreNameLabel.Location = new System.Drawing.Point(12, 9); + this.StoreNameLabel.Name = "StoreNameLabel"; + this.StoreNameLabel.Size = new System.Drawing.Size(119, 15); + this.StoreNameLabel.TabIndex = 0; + this.StoreNameLabel.Text = "Название магазина: "; + // + // StoreAdressLabel + // + this.StoreAdressLabel.AutoSize = true; + this.StoreAdressLabel.Location = new System.Drawing.Point(12, 40); + this.StoreAdressLabel.Name = "StoreAdressLabel"; + this.StoreAdressLabel.Size = new System.Drawing.Size(100, 15); + this.StoreAdressLabel.TabIndex = 1; + this.StoreAdressLabel.Text = "Адрес магазина: "; + // + // OpeningDateLabel + // + this.OpeningDateLabel.AutoSize = true; + this.OpeningDateLabel.Location = new System.Drawing.Point(12, 72); + this.OpeningDateLabel.Name = "OpeningDateLabel"; + this.OpeningDateLabel.Size = new System.Drawing.Size(93, 15); + this.OpeningDateLabel.TabIndex = 2; + this.OpeningDateLabel.Text = "Дата открытия: "; + // + // NameComboBox + // + this.NameComboBox.FormattingEnabled = true; + this.NameComboBox.Location = new System.Drawing.Point(137, 6); + this.NameComboBox.Name = "NameComboBox"; + this.NameComboBox.Size = new System.Drawing.Size(174, 23); + this.NameComboBox.TabIndex = 3; + this.NameComboBox.SelectedIndexChanged += new System.EventHandler(this.NameComboBox_SelectedIndexChanged); + // + // AdressTextBox + // + this.AdressTextBox.Location = new System.Drawing.Point(137, 37); + this.AdressTextBox.Name = "AdressTextBox"; + this.AdressTextBox.Size = new System.Drawing.Size(174, 23); + this.AdressTextBox.TabIndex = 4; + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.JewelName, + this.JewelPrice, + this.JewelCount}); + this.DataGridView.Location = new System.Drawing.Point(12, 109); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(776, 288); + this.DataGridView.TabIndex = 6; + // + // JewelName + // + this.JewelName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.JewelName.HeaderText = "Название изделия"; + this.JewelName.Name = "JewelName"; + // + // JewelPrice + // + this.JewelPrice.HeaderText = "Цена"; + this.JewelPrice.Name = "JewelPrice"; + // + // JewelCount + // + this.JewelCount.HeaderText = "Количество"; + this.JewelCount.Name = "JewelCount"; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(552, 403); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(115, 35); + this.SaveButton.TabIndex = 7; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(673, 403); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(115, 35); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отменить"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // OpeningDatePicker + // + this.OpeningDatePicker.Location = new System.Drawing.Point(137, 66); + this.OpeningDatePicker.Name = "OpeningDatePicker"; + this.OpeningDatePicker.Size = new System.Drawing.Size(174, 23); + this.OpeningDatePicker.TabIndex = 9; + // + // FormStore + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.OpeningDatePicker); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.DataGridView); + this.Controls.Add(this.AdressTextBox); + this.Controls.Add(this.NameComboBox); + this.Controls.Add(this.OpeningDateLabel); + this.Controls.Add(this.StoreAdressLabel); + this.Controls.Add(this.StoreNameLabel); + this.Name = "FormStore"; + this.Text = "Изделия магазина"; + this.Load += new System.EventHandler(this.FormStore_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label StoreNameLabel; + private Label StoreAdressLabel; + private Label OpeningDateLabel; + private ComboBox NameComboBox; + private TextBox AdressTextBox; + private DataGridView DataGridView; + private Button SaveButton; + private Button ButtonCancel; + private DataGridViewTextBoxColumn JewelName; + private DataGridViewTextBoxColumn JewelPrice; + private DataGridViewTextBoxColumn JewelCount; + private DateTimePicker OpeningDatePicker; + } +} \ No newline at end of file diff --git a/JewelryStore/FormStore.cs b/JewelryStore/FormStore.cs new file mode 100644 index 0000000..042d003 --- /dev/null +++ b/JewelryStore/FormStore.cs @@ -0,0 +1,151 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.ViewModels; +using JewelryStoreDataModels.Models; +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 JewelryStore +{ + public partial class FormStore : Form + { + private readonly List? _listStores; + private readonly IStoreLogic _logic; + private readonly ILogger _logger; + public int Id { get; set; } + + public FormStore(ILogger logger, IStoreLogic logic) + { + InitializeComponent(); + _logger = logger; + _listStores = logic.ReadList(null); + _logic = logic; + if (_listStores != null) + { + NameComboBox.DisplayMember = "StoreName"; + NameComboBox.ValueMember = "Id"; + NameComboBox.DataSource = _listStores; + NameComboBox.SelectedItem = null; + } + } + + private IStoreModel? GetStore(int id) + { + if (_listStores == null) + { + return null; + } + foreach (var elem in _listStores) + { + if (elem.Id == id) + { + return elem; + } + } + return null; + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(NameComboBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(AdressTextBox.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение изделия"); + + try + { + DateTime.TryParse(OpeningDatePicker.Text, out var dateTime); + StoreBindingModel model = new() + { + StoreName = NameComboBox.Text, + StoreAdress = AdressTextBox.Text, + OpeningDate = dateTime + }; + var vmodel = GetStore(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("Ошибка при сохранении. Дополнительная информация в логах."); + } + + 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(); + } + + private void FormStore_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData(bool extendDate = true) + { + try + { + var model = GetStore(extendDate ? Id : Convert.ToInt32(NameComboBox.SelectedValue)); + if (model != null) + { + NameComboBox.Text = model.StoreName; + AdressTextBox.Text = model.StoreAdress; + OpeningDatePicker.Text = Convert.ToString(model.OpeningDate); + DataGridView.Rows.Clear(); + foreach (var el in model.Jewels.Values) + { + DataGridView.Rows.Add(new object[] { el.Item1.JewelName, el.Item1.Price, el.Item2 }); + } + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void NameComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + LoadData(false); + } + } +} diff --git a/JewelryStore/FormStore.resx b/JewelryStore/FormStore.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormStore.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/JewelryStore/FormStoreReplenishment.Designer.cs b/JewelryStore/FormStoreReplenishment.Designer.cs new file mode 100644 index 0000000..4399d2e --- /dev/null +++ b/JewelryStore/FormStoreReplenishment.Designer.cs @@ -0,0 +1,142 @@ +namespace JewelryStore +{ + partial class FormStoreReplenishment + { + /// + /// 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.StoreNameLabel = new System.Windows.Forms.Label(); + this.JewelNameLabel = new System.Windows.Forms.Label(); + this.CountLabel = new System.Windows.Forms.Label(); + this.StoreNameComboBox = new System.Windows.Forms.ComboBox(); + this.JewelNameComboBox = new System.Windows.Forms.ComboBox(); + this.CountTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // StoreNameLabel + // + this.StoreNameLabel.AutoSize = true; + this.StoreNameLabel.Location = new System.Drawing.Point(12, 9); + this.StoreNameLabel.Name = "StoreNameLabel"; + this.StoreNameLabel.Size = new System.Drawing.Size(119, 15); + this.StoreNameLabel.TabIndex = 0; + this.StoreNameLabel.Text = "Название магазина: "; + // + // JewelNameLabel + // + this.JewelNameLabel.AutoSize = true; + this.JewelNameLabel.Location = new System.Drawing.Point(12, 37); + this.JewelNameLabel.Name = "JewelNameLabel"; + this.JewelNameLabel.Size = new System.Drawing.Size(112, 15); + this.JewelNameLabel.TabIndex = 1; + this.JewelNameLabel.Text = "Название изделия: "; + // + // CountLabel + // + this.CountLabel.AutoSize = true; + this.CountLabel.Location = new System.Drawing.Point(12, 66); + this.CountLabel.Name = "CountLabel"; + this.CountLabel.Size = new System.Drawing.Size(78, 15); + this.CountLabel.TabIndex = 2; + this.CountLabel.Text = "Количество: "; + // + // StoreNameComboBox + // + this.StoreNameComboBox.FormattingEnabled = true; + this.StoreNameComboBox.Location = new System.Drawing.Point(137, 6); + this.StoreNameComboBox.Name = "StoreNameComboBox"; + this.StoreNameComboBox.Size = new System.Drawing.Size(149, 23); + this.StoreNameComboBox.TabIndex = 3; + // + // JewelNameComboBox + // + this.JewelNameComboBox.FormattingEnabled = true; + this.JewelNameComboBox.Location = new System.Drawing.Point(137, 35); + this.JewelNameComboBox.Name = "JewelNameComboBox"; + this.JewelNameComboBox.Size = new System.Drawing.Size(149, 23); + this.JewelNameComboBox.TabIndex = 4; + // + // CountTextBox + // + this.CountTextBox.Location = new System.Drawing.Point(137, 64); + this.CountTextBox.Name = "CountTextBox"; + this.CountTextBox.Size = new System.Drawing.Size(149, 23); + this.CountTextBox.TabIndex = 5; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(130, 108); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(75, 23); + this.SaveButton.TabIndex = 6; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(211, 108); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(75, 23); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormStoreReplenishment + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(300, 150); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.CountTextBox); + this.Controls.Add(this.JewelNameComboBox); + this.Controls.Add(this.StoreNameComboBox); + this.Controls.Add(this.CountLabel); + this.Controls.Add(this.JewelNameLabel); + this.Controls.Add(this.StoreNameLabel); + this.Name = "FormStoreReplenishment"; + this.Text = "Пополнение магазина"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label StoreNameLabel; + private Label JewelNameLabel; + private Label CountLabel; + private ComboBox StoreNameComboBox; + private ComboBox JewelNameComboBox; + private TextBox CountTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/JewelryStore/FormStoreReplenishment.cs b/JewelryStore/FormStoreReplenishment.cs new file mode 100644 index 0000000..b478d0f --- /dev/null +++ b/JewelryStore/FormStoreReplenishment.cs @@ -0,0 +1,104 @@ +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.ViewModels; +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 JewelryStore +{ + public partial class FormStoreReplenishment : Form + { + private readonly ILogger _logger; + private readonly IStoreLogic _storeLogic; + private readonly IJewelLogic _jewelLogic; + private readonly List? _listStores; + private readonly List? _listJewels; + public FormStoreReplenishment(ILogger logger, IStoreLogic storeLogic, IJewelLogic jewelLogic) + { + InitializeComponent(); + _storeLogic = storeLogic; + _jewelLogic = jewelLogic; + _logger = logger; + _listStores = storeLogic.ReadList(null); + if (_listStores != null) + { + StoreNameComboBox.DisplayMember = "StoreName"; + StoreNameComboBox.ValueMember = "Id"; + StoreNameComboBox.DataSource = _listStores; + StoreNameComboBox.SelectedItem = null; + } + + _listJewels = jewelLogic.ReadList(null); + if (_listJewels != null) + { + JewelNameComboBox.DisplayMember = "JewelName"; + JewelNameComboBox.ValueMember = "Id"; + JewelNameComboBox.DataSource = _listJewels; + JewelNameComboBox.SelectedItem = null; + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (StoreNameComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (JewelNameComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Добавление изделия в магазин"); + + try + { + var jewel = _jewelLogic.ReadElement(new() + { + Id = (int)JewelNameComboBox.SelectedValue + }); + + if (jewel == null) + { + throw new Exception("Не найдено изделие. Дополнительная информация в логах."); + } + + var resultOperation = _storeLogic.AddJewel( + model: new() { Id = (int)StoreNameComboBox.SelectedValue }, + jewel: jewel, + quantity: Convert.ToInt32(CountTextBox.Text) + ); + + 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/JewelryStore/FormStoreReplenishment.resx b/JewelryStore/FormStoreReplenishment.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormStoreReplenishment.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/JewelryStore/FormStores.Designer.cs b/JewelryStore/FormStores.Designer.cs new file mode 100644 index 0000000..56e0205 --- /dev/null +++ b/JewelryStore/FormStores.Designer.cs @@ -0,0 +1,114 @@ +namespace JewelryStore +{ + partial class FormStores + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 1); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(550, 447); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(585, 12); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(121, 40); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(585, 67); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(121, 40); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(585, 122); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(121, 40); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(585, 179); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(121, 40); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormStores + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(718, 450); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Name = "FormStores"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormStores_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/JewelryStore/FormStores.cs b/JewelryStore/FormStores.cs new file mode 100644 index 0000000..8c84e6e --- /dev/null +++ b/JewelryStore/FormStores.cs @@ -0,0 +1,122 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.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 JewelryStore +{ + public partial class FormStores : Form + { + private readonly ILogger _logger; + private readonly IStoreLogic _logic; + public FormStores(ILogger logger, IStoreLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormStores_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["StoreName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["Jewels"].Visible = false; + } + + _logger.LogInformation("Загрузка магазинов"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void DeleteButton_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 StoreBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStore)); + + if (service is FormStore form) + { + form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStore)); + + if (service is FormStore form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } +} diff --git a/JewelryStore/FormStores.resx b/JewelryStore/FormStores.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/JewelryStore/FormStores.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/JewelryStore/Program.cs b/JewelryStore/Program.cs index 4a4a47e..5abf0e6 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -40,9 +40,11 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -50,6 +52,9 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } diff --git a/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic .cs b/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic .cs index 52e2036..948122f 100644 --- a/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic .cs +++ b/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic .cs @@ -13,7 +13,7 @@ using System.Threading.Tasks; namespace JewelryStoreBusinessLogic.BusinessLogics { - internal class StoreLogic : IStoreLogic + public class StoreLogic : IStoreLogic { private readonly ILogger _logger; private readonly IStoreStorage _storeStorage; -- 2.25.1 From 244e5a811ff11885c76c6c1d957e1bff2ec77769 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Tue, 7 Mar 2023 13:56:31 +0400 Subject: [PATCH 4/6] full --- JewelryStore/FormStore.Designer.cs | 70 ++++++++++++++++++------------ JewelryStore/FormStore.cs | 20 +++------ JewelryStore/FormStore.resx | 62 +------------------------- 3 files changed, 48 insertions(+), 104 deletions(-) diff --git a/JewelryStore/FormStore.Designer.cs b/JewelryStore/FormStore.Designer.cs index 583d00c..6713844 100644 --- a/JewelryStore/FormStore.Designer.cs +++ b/JewelryStore/FormStore.Designer.cs @@ -31,7 +31,7 @@ this.StoreNameLabel = new System.Windows.Forms.Label(); this.StoreAdressLabel = new System.Windows.Forms.Label(); this.OpeningDateLabel = new System.Windows.Forms.Label(); - this.NameComboBox = new System.Windows.Forms.ComboBox(); + this.NameTextBox = new System.Windows.Forms.TextBox(); this.AdressTextBox = new System.Windows.Forms.TextBox(); this.DataGridView = new System.Windows.Forms.DataGridView(); this.JewelName = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -46,44 +46,47 @@ // StoreNameLabel // this.StoreNameLabel.AutoSize = true; - this.StoreNameLabel.Location = new System.Drawing.Point(12, 9); + this.StoreNameLabel.Location = new System.Drawing.Point(17, 15); + this.StoreNameLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.StoreNameLabel.Name = "StoreNameLabel"; - this.StoreNameLabel.Size = new System.Drawing.Size(119, 15); + this.StoreNameLabel.Size = new System.Drawing.Size(179, 25); this.StoreNameLabel.TabIndex = 0; this.StoreNameLabel.Text = "Название магазина: "; // // StoreAdressLabel // this.StoreAdressLabel.AutoSize = true; - this.StoreAdressLabel.Location = new System.Drawing.Point(12, 40); + this.StoreAdressLabel.Location = new System.Drawing.Point(17, 67); + this.StoreAdressLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.StoreAdressLabel.Name = "StoreAdressLabel"; - this.StoreAdressLabel.Size = new System.Drawing.Size(100, 15); + this.StoreAdressLabel.Size = new System.Drawing.Size(151, 25); this.StoreAdressLabel.TabIndex = 1; this.StoreAdressLabel.Text = "Адрес магазина: "; // // OpeningDateLabel // this.OpeningDateLabel.AutoSize = true; - this.OpeningDateLabel.Location = new System.Drawing.Point(12, 72); + this.OpeningDateLabel.Location = new System.Drawing.Point(17, 120); + this.OpeningDateLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.OpeningDateLabel.Name = "OpeningDateLabel"; - this.OpeningDateLabel.Size = new System.Drawing.Size(93, 15); + this.OpeningDateLabel.Size = new System.Drawing.Size(140, 25); this.OpeningDateLabel.TabIndex = 2; this.OpeningDateLabel.Text = "Дата открытия: "; // - // NameComboBox + // NameTextBox // - this.NameComboBox.FormattingEnabled = true; - this.NameComboBox.Location = new System.Drawing.Point(137, 6); - this.NameComboBox.Name = "NameComboBox"; - this.NameComboBox.Size = new System.Drawing.Size(174, 23); - this.NameComboBox.TabIndex = 3; - this.NameComboBox.SelectedIndexChanged += new System.EventHandler(this.NameComboBox_SelectedIndexChanged); + this.NameTextBox.Location = new System.Drawing.Point(196, 10); + this.NameTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.NameTextBox.Name = "NameTextBox"; + this.NameTextBox.Size = new System.Drawing.Size(247, 31); + this.NameTextBox.TabIndex = 3; // // AdressTextBox // - this.AdressTextBox.Location = new System.Drawing.Point(137, 37); + this.AdressTextBox.Location = new System.Drawing.Point(196, 62); + this.AdressTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.AdressTextBox.Name = "AdressTextBox"; - this.AdressTextBox.Size = new System.Drawing.Size(174, 23); + this.AdressTextBox.Size = new System.Drawing.Size(247, 31); this.AdressTextBox.TabIndex = 4; // // DataGridView @@ -93,33 +96,41 @@ this.JewelName, this.JewelPrice, this.JewelCount}); - this.DataGridView.Location = new System.Drawing.Point(12, 109); + this.DataGridView.Location = new System.Drawing.Point(17, 182); + this.DataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 62; this.DataGridView.RowTemplate.Height = 25; - this.DataGridView.Size = new System.Drawing.Size(776, 288); + this.DataGridView.Size = new System.Drawing.Size(1109, 480); this.DataGridView.TabIndex = 6; // // JewelName // this.JewelName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.JewelName.HeaderText = "Название изделия"; + this.JewelName.MinimumWidth = 8; this.JewelName.Name = "JewelName"; // // JewelPrice // this.JewelPrice.HeaderText = "Цена"; + this.JewelPrice.MinimumWidth = 8; this.JewelPrice.Name = "JewelPrice"; + this.JewelPrice.Width = 150; // // JewelCount // this.JewelCount.HeaderText = "Количество"; + this.JewelCount.MinimumWidth = 8; this.JewelCount.Name = "JewelCount"; + this.JewelCount.Width = 150; // // SaveButton // - this.SaveButton.Location = new System.Drawing.Point(552, 403); + this.SaveButton.Location = new System.Drawing.Point(789, 672); + this.SaveButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.SaveButton.Name = "SaveButton"; - this.SaveButton.Size = new System.Drawing.Size(115, 35); + this.SaveButton.Size = new System.Drawing.Size(164, 58); this.SaveButton.TabIndex = 7; this.SaveButton.Text = "Сохранить"; this.SaveButton.UseVisualStyleBackColor = true; @@ -127,9 +138,10 @@ // // ButtonCancel // - this.ButtonCancel.Location = new System.Drawing.Point(673, 403); + this.ButtonCancel.Location = new System.Drawing.Point(961, 672); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.ButtonCancel.Name = "ButtonCancel"; - this.ButtonCancel.Size = new System.Drawing.Size(115, 35); + this.ButtonCancel.Size = new System.Drawing.Size(164, 58); this.ButtonCancel.TabIndex = 8; this.ButtonCancel.Text = "Отменить"; this.ButtonCancel.UseVisualStyleBackColor = true; @@ -137,25 +149,27 @@ // // OpeningDatePicker // - this.OpeningDatePicker.Location = new System.Drawing.Point(137, 66); + this.OpeningDatePicker.Location = new System.Drawing.Point(196, 110); + this.OpeningDatePicker.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.OpeningDatePicker.Name = "OpeningDatePicker"; - this.OpeningDatePicker.Size = new System.Drawing.Size(174, 23); + this.OpeningDatePicker.Size = new System.Drawing.Size(247, 31); this.OpeningDatePicker.TabIndex = 9; // // FormStore // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(1143, 750); this.Controls.Add(this.OpeningDatePicker); this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.SaveButton); this.Controls.Add(this.DataGridView); this.Controls.Add(this.AdressTextBox); - this.Controls.Add(this.NameComboBox); + this.Controls.Add(this.NameTextBox); this.Controls.Add(this.OpeningDateLabel); this.Controls.Add(this.StoreAdressLabel); this.Controls.Add(this.StoreNameLabel); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.Name = "FormStore"; this.Text = "Изделия магазина"; this.Load += new System.EventHandler(this.FormStore_Load); @@ -170,7 +184,7 @@ private Label StoreNameLabel; private Label StoreAdressLabel; private Label OpeningDateLabel; - private ComboBox NameComboBox; + private TextBox NameTextBox; private TextBox AdressTextBox; private DataGridView DataGridView; private Button SaveButton; diff --git a/JewelryStore/FormStore.cs b/JewelryStore/FormStore.cs index 042d003..f42a421 100644 --- a/JewelryStore/FormStore.cs +++ b/JewelryStore/FormStore.cs @@ -28,13 +28,6 @@ namespace JewelryStore _logger = logger; _listStores = logic.ReadList(null); _logic = logic; - if (_listStores != null) - { - NameComboBox.DisplayMember = "StoreName"; - NameComboBox.ValueMember = "Id"; - NameComboBox.DataSource = _listStores; - NameComboBox.SelectedItem = null; - } } private IStoreModel? GetStore(int id) @@ -55,7 +48,7 @@ namespace JewelryStore private void SaveButton_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(NameComboBox.Text)) + if (string.IsNullOrEmpty(NameTextBox.Text)) { MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -74,7 +67,7 @@ namespace JewelryStore DateTime.TryParse(OpeningDatePicker.Text, out var dateTime); StoreBindingModel model = new() { - StoreName = NameComboBox.Text, + StoreName = NameTextBox.Text, StoreAdress = AdressTextBox.Text, OpeningDate = dateTime }; @@ -121,10 +114,10 @@ namespace JewelryStore { try { - var model = GetStore(extendDate ? Id : Convert.ToInt32(NameComboBox.SelectedValue)); + var model = GetStore(extendDate ? Id : Convert.ToInt32(NameTextBox.Text)); if (model != null) { - NameComboBox.Text = model.StoreName; + NameTextBox.Text = model.StoreName; AdressTextBox.Text = model.StoreAdress; OpeningDatePicker.Text = Convert.ToString(model.OpeningDate); DataGridView.Rows.Clear(); @@ -143,9 +136,6 @@ namespace JewelryStore } } - private void NameComboBox_SelectedIndexChanged(object sender, EventArgs e) - { - LoadData(false); - } + } } diff --git a/JewelryStore/FormStore.resx b/JewelryStore/FormStore.resx index 1af7de1..f298a7b 100644 --- a/JewelryStore/FormStore.resx +++ b/JewelryStore/FormStore.resx @@ -1,64 +1,4 @@ - - - + -- 2.25.1 From ddfa825b12fd2fa7e61f13115796c0aff1fd5f55 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 12 Mar 2023 22:35:17 +0400 Subject: [PATCH 5/6] all fixed --- JewelryStoreListImplement/Models/Store.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/JewelryStoreListImplement/Models/Store.cs b/JewelryStoreListImplement/Models/Store.cs index e1b80f3..c706e46 100644 --- a/JewelryStoreListImplement/Models/Store.cs +++ b/JewelryStoreListImplement/Models/Store.cs @@ -45,7 +45,6 @@ namespace JewelryStoreListImplement.Models StoreName = model.StoreName; StoreAdress = model.StoreAdress; OpeningDate = model.OpeningDate; - Jewels = model.Jewels; } public StoreViewModel GetViewModel => new() -- 2.25.1 From f2f7b803fdbe13979dfc82069a107fa3dc412c59 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Tue, 21 Mar 2023 13:37:57 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D1=81=D0=B4=D0=B0=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JewelryStore/FormStore.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/JewelryStore/FormStore.cs b/JewelryStore/FormStore.cs index f42a421..22411ea 100644 --- a/JewelryStore/FormStore.cs +++ b/JewelryStore/FormStore.cs @@ -60,7 +60,7 @@ namespace JewelryStore return; } - _logger.LogInformation("Сохранение изделия"); + _logger.LogInformation("Сохранение магазина"); try { @@ -95,7 +95,7 @@ namespace JewelryStore } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения изделия"); + _logger.LogError(ex, "Ошибка сохранения магазина"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } -- 2.25.1