diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ShopLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..e4ecee5 --- /dev/null +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,178 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Shop Name:{0}, ID:{1}", model.Name, model.Id); + + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement. element not found"); + return null; + } + + _logger.LogInformation("ReadElement found. Id:{Id}", element.Id); + + return element; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. Shop Name:{0}, ID:{1} ", model?.Name, model?.Id); + + var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + public bool SupplySecures(ShopSearchModel model, ISecureModel secure, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (secure == null) + { + throw new ArgumentNullException(nameof(secure)); + } + + if (count <= 0) + { + throw new ArgumentNullException("Count of secures in supply must be more than 0", nameof(count)); + } + + var shopElement = _shopStorage.GetElement(model); + if (shopElement == null) + { + _logger.LogWarning("Required shop element not found in storage"); + return false; + } + + _logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name); + + if (shopElement.ShopSecures.TryGetValue(secure.Id, out var sameSecure)) + { + shopElement.ShopSecures[secure.Id] = (secure, sameSecure.Item2 + count); + _logger.LogInformation("Same secure found by supply. Added {0} of {1} in {2} shop", count, secure.SecureName, shopElement.Name); + } + else + { + shopElement.ShopSecures[secure.Id] = (secure, count); + _logger.LogInformation("New secure added by supply. Added {0} of {1} in {2} shop", count, secure.SecureName, shopElement.Name); + } + + _shopStorage.Update(new() + { + Id = shopElement.Id, + Name = shopElement.Name, + Address = shopElement.Address, + OpeningDate = shopElement.OpeningDate, + ShopSecures = shopElement.ShopSecures + }); + + return true; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия магазина!", nameof(model.Name)); + } + + _logger.LogInformation("Shop. Name: {0}, Address: {1}, ID: {2}", model.Name, model.Address, model.Id); + + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.Name + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/SecuritySystem/SecuritySystemContracts/BindingModels/ShopBindingModel.cs b/SecuritySystem/SecuritySystemContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..caeb197 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,17 @@ +using SecuritySystemDataModels.Models; + +namespace SecuritySystemContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime OpeningDate { get; set; } + + public Dictionary ShopSecures { get; set; } = new(); + } +} diff --git a/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IShopLogic.cs b/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..44eb9d8 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,17 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + ShopViewModel? ReadElement(ShopSearchModel model); + List? ReadList(ShopSearchModel? model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool SupplySecures(ShopSearchModel model, ISecureModel secure, int count); + } +} diff --git a/SecuritySystem/SecuritySystemContracts/SearchModels/ShopSearchModel.cs b/SecuritySystem/SecuritySystemContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..103b5ef --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,8 @@ +namespace SecuritySystemContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/SecuritySystem/SecuritySystemContracts/StoragesContracts/IShopStorage.cs b/SecuritySystem/SecuritySystemContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..fcb9e2d --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,16 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemContracts.StoragesContracts +{ + public interface IShopStorage + { + ShopViewModel? GetElement(ShopSearchModel model); + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + } +} diff --git a/SecuritySystem/SecuritySystemContracts/ViewModels/ShopViewModel.cs b/SecuritySystem/SecuritySystemContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..d6923fc --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,17 @@ +using SecuritySystemDataModels.Models; +using System.ComponentModel; + +namespace SecuritySystemContracts.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 OpeningDate { get; set; } + public Dictionary ShopSecures { get; set; } = new(); + } +} diff --git a/SecuritySystem/SecuritySystemDataModels/Models/IShopModel.cs b/SecuritySystem/SecuritySystemDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..da3eecc --- /dev/null +++ b/SecuritySystem/SecuritySystemDataModels/Models/IShopModel.cs @@ -0,0 +1,10 @@ +namespace SecuritySystemDataModels.Models +{ + public interface IShopModel : IId + { + string Name { get; } + string Address { get; } + DateTime OpeningDate { get; } + Dictionary ShopSecures { get; } + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs index e173975..85dbcbf 100644 --- a/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs +++ b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs @@ -8,11 +8,13 @@ namespace SecuritySystemListImplement public List Components { get; set; } public List Orders { get; set; } public List Secures { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Secures = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/SecuritySystem/SecuritySystemListImplement/Implements/ShopStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..a46bcb6 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Implements/ShopStorage.cs @@ -0,0 +1,121 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemListImplement.Models; + +namespace SecuritySystemListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.Name) && shop.Name == model.Name) || (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + + return null; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.Name)) + { + return result; + } + + foreach (var shop in _source.Shops) + { + if (shop.Name.Contains(model.Name)) + { + result.Add(shop.GetViewModel); + } + } + + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + + return result; + } + + 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/SecuritySystem/SecuritySystemListImplement/Models/Shop.cs b/SecuritySystem/SecuritySystemListImplement/Models/Shop.cs new file mode 100644 index 0000000..dd5e4a5 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Models/Shop.cs @@ -0,0 +1,54 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string Name { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary ShopSecures { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + { + return null; + } + + return new Shop() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + OpeningDate = model.OpeningDate, + ShopSecures = new() + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + + Name = model.Name; + Address = model.Address; + OpeningDate = model.OpeningDate; + ShopSecures = model.ShopSecures; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + OpeningDate = OpeningDate, + ShopSecures = ShopSecures + }; + } +} diff --git a/SecuritySystem/SecuritySystemView/FormComponent.Designer.cs b/SecuritySystem/SecuritySystemView/Component/FormComponent.Designer.cs similarity index 95% rename from SecuritySystem/SecuritySystemView/FormComponent.Designer.cs rename to SecuritySystem/SecuritySystemView/Component/FormComponent.Designer.cs index ffb456e..17bf335 100644 --- a/SecuritySystem/SecuritySystemView/FormComponent.Designer.cs +++ b/SecuritySystem/SecuritySystemView/Component/FormComponent.Designer.cs @@ -41,14 +41,14 @@ textBoxComponentName.Location = new Point(98, 6); textBoxComponentName.Name = "textBoxComponentName"; textBoxComponentName.Size = new Size(372, 27); - textBoxComponentName.TabIndex = 0; + textBoxComponentName.TabIndex = 1; // // textBoxComponentCost // textBoxComponentCost.Location = new Point(98, 41); textBoxComponentCost.Name = "textBoxComponentCost"; textBoxComponentCost.Size = new Size(125, 27); - textBoxComponentCost.TabIndex = 1; + textBoxComponentCost.TabIndex = 2; // // labelComponentName // @@ -73,7 +73,7 @@ buttonSaveComponent.Location = new Point(211, 80); buttonSaveComponent.Name = "buttonSaveComponent"; buttonSaveComponent.Size = new Size(115, 29); - buttonSaveComponent.TabIndex = 1; + buttonSaveComponent.TabIndex = 3; buttonSaveComponent.Text = "Сохранить"; buttonSaveComponent.UseVisualStyleBackColor = true; buttonSaveComponent.Click += ButtonSaveComponent_Click; @@ -83,7 +83,7 @@ buttonCancel.Location = new Point(348, 80); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(122, 29); - buttonCancel.TabIndex = 5; + buttonCancel.TabIndex = 4; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; diff --git a/SecuritySystem/SecuritySystemView/FormComponent.cs b/SecuritySystem/SecuritySystemView/Component/FormComponent.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormComponent.cs rename to SecuritySystem/SecuritySystemView/Component/FormComponent.cs diff --git a/SecuritySystem/SecuritySystemView/FormComponent.resx b/SecuritySystem/SecuritySystemView/Component/FormComponent.resx similarity index 100% rename from SecuritySystem/SecuritySystemView/FormComponent.resx rename to SecuritySystem/SecuritySystemView/Component/FormComponent.resx diff --git a/SecuritySystem/SecuritySystemView/FormComponents.Designer.cs b/SecuritySystem/SecuritySystemView/Component/FormComponents.Designer.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormComponents.Designer.cs rename to SecuritySystem/SecuritySystemView/Component/FormComponents.Designer.cs diff --git a/SecuritySystem/SecuritySystemView/FormComponents.cs b/SecuritySystem/SecuritySystemView/Component/FormComponents.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormComponents.cs rename to SecuritySystem/SecuritySystemView/Component/FormComponents.cs diff --git a/SecuritySystem/SecuritySystemView/FormComponents.resx b/SecuritySystem/SecuritySystemView/Component/FormComponents.resx similarity index 100% rename from SecuritySystem/SecuritySystemView/FormComponents.resx rename to SecuritySystem/SecuritySystemView/Component/FormComponents.resx diff --git a/SecuritySystem/SecuritySystemView/FormMain.Designer.cs b/SecuritySystem/SecuritySystemView/FormMain.Designer.cs index 5ff6f2b..8177b93 100644 --- a/SecuritySystem/SecuritySystemView/FormMain.Designer.cs +++ b/SecuritySystem/SecuritySystemView/FormMain.Designer.cs @@ -32,12 +32,14 @@ справочникиToolStripMenuItem = new ToolStripMenuItem(); ComponentsToolStripMenuItem = new ToolStripMenuItem(); SecuresToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); button4 = new Button(); buttonRefresh = new Button(); + пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -45,7 +47,7 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1043, 28); @@ -54,7 +56,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, SecuresToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, SecuresToolStripMenuItem, магазиныToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -62,17 +64,24 @@ // ComponentsToolStripMenuItem // ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - ComponentsToolStripMenuItem.Size = new Size(182, 26); + ComponentsToolStripMenuItem.Size = new Size(224, 26); ComponentsToolStripMenuItem.Text = "Компоненты"; ComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; // // SecuresToolStripMenuItem // SecuresToolStripMenuItem.Name = "SecuresToolStripMenuItem"; - SecuresToolStripMenuItem.Size = new Size(182, 26); + SecuresToolStripMenuItem.Size = new Size(224, 26); SecuresToolStripMenuItem.Text = "Изделия"; SecuresToolStripMenuItem.Click += SecuresToolStripMenuItem_Click; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // // dataGridView // dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; @@ -142,6 +151,13 @@ buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += ButtonRefresh_Click; // + // пополнениеМагазинаToolStripMenuItem + // + пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24); + пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + пополнениеМагазинаToolStripMenuItem.Click += SupplyShopToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -177,5 +193,7 @@ private Button buttonOrderReady; private Button button4; private Button buttonRefresh; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; } } \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormMain.cs b/SecuritySystem/SecuritySystemView/FormMain.cs index 2fed95c..0e33e70 100644 --- a/SecuritySystem/SecuritySystemView/FormMain.cs +++ b/SecuritySystem/SecuritySystemView/FormMain.cs @@ -136,5 +136,23 @@ namespace SecuritySystemView { LoadData(); } + + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void SupplyShopToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply)); + if (service is FormShopSupply form) + { + form.ShowDialog(); + } + } } } diff --git a/SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs b/SecuritySystem/SecuritySystemView/Order/FormCreateOrder.Designer.cs similarity index 97% rename from SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs rename to SecuritySystem/SecuritySystemView/Order/FormCreateOrder.Designer.cs index d99f108..0c53ac2 100644 --- a/SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs +++ b/SecuritySystem/SecuritySystemView/Order/FormCreateOrder.Designer.cs @@ -72,7 +72,7 @@ comboBoxSecure.Location = new Point(110, 9); comboBoxSecure.Name = "comboBoxSecure"; comboBoxSecure.Size = new Size(462, 28); - comboBoxSecure.TabIndex = 3; + comboBoxSecure.TabIndex = 1; comboBoxSecure.SelectedIndexChanged += ComboBoxSecure_SelectedIndexChanged; // // textBoxCount @@ -80,7 +80,7 @@ textBoxCount.Location = new Point(110, 43); textBoxCount.Name = "textBoxCount"; textBoxCount.Size = new Size(462, 27); - textBoxCount.TabIndex = 4; + textBoxCount.TabIndex = 2; textBoxCount.TextChanged += TextBoxCount_TextChanged; // // textBoxSum @@ -96,7 +96,7 @@ buttonSave.Location = new Point(370, 118); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(94, 29); - buttonSave.TabIndex = 1; + buttonSave.TabIndex = 3; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; buttonSave.Click += ButtonSave_Click; @@ -106,7 +106,7 @@ buttonCancel.Location = new Point(478, 118); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(94, 29); - buttonCancel.TabIndex = 7; + buttonCancel.TabIndex = 4; buttonCancel.Text = "Отменить"; buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; diff --git a/SecuritySystem/SecuritySystemView/FormCreateOrder.cs b/SecuritySystem/SecuritySystemView/Order/FormCreateOrder.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormCreateOrder.cs rename to SecuritySystem/SecuritySystemView/Order/FormCreateOrder.cs diff --git a/SecuritySystem/SecuritySystemView/FormCreateOrder.resx b/SecuritySystem/SecuritySystemView/Order/FormCreateOrder.resx similarity index 100% rename from SecuritySystem/SecuritySystemView/FormCreateOrder.resx rename to SecuritySystem/SecuritySystemView/Order/FormCreateOrder.resx diff --git a/SecuritySystem/SecuritySystemView/Program.cs b/SecuritySystem/SecuritySystemView/Program.cs index 6757ecc..5a6e55a 100644 --- a/SecuritySystem/SecuritySystemView/Program.cs +++ b/SecuritySystem/SecuritySystemView/Program.cs @@ -39,6 +39,8 @@ namespace SecuritySystemView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -46,6 +48,9 @@ namespace SecuritySystemView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormSecure.Designer.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecure.Designer.cs similarity index 96% rename from SecuritySystem/SecuritySystemView/FormSecure.Designer.cs rename to SecuritySystem/SecuritySystemView/Secure/FormSecure.Designer.cs index d64046a..99d5de1 100644 --- a/SecuritySystem/SecuritySystemView/FormSecure.Designer.cs +++ b/SecuritySystem/SecuritySystemView/Secure/FormSecure.Designer.cs @@ -70,7 +70,7 @@ textBoxName.Location = new Point(108, 6); textBoxName.Name = "textBoxName"; textBoxName.Size = new Size(368, 27); - textBoxName.TabIndex = 2; + textBoxName.TabIndex = 1; // // textBoxPrice // @@ -78,7 +78,7 @@ textBoxPrice.Location = new Point(108, 43); textBoxPrice.Name = "textBoxPrice"; textBoxPrice.Size = new Size(143, 27); - textBoxPrice.TabIndex = 3; + textBoxPrice.TabIndex = 2; // // groupBoxComponentsControl // @@ -99,7 +99,7 @@ buttonRefresh.Location = new Point(668, 197); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(94, 29); - buttonRefresh.TabIndex = 4; + buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += ButtonRefresh_Click; @@ -109,7 +109,7 @@ buttonDelete.Location = new Point(668, 147); buttonDelete.Name = "buttonDelete"; buttonDelete.Size = new Size(94, 29); - buttonDelete.TabIndex = 3; + buttonDelete.TabIndex = 5; buttonDelete.Text = "Удалить"; buttonDelete.UseVisualStyleBackColor = true; buttonDelete.Click += ButtonDelete_Click; @@ -119,7 +119,7 @@ buttonEdit.Location = new Point(668, 99); buttonEdit.Name = "buttonEdit"; buttonEdit.Size = new Size(94, 29); - buttonEdit.TabIndex = 2; + buttonEdit.TabIndex = 4; buttonEdit.Text = "Изменить"; buttonEdit.UseVisualStyleBackColor = true; buttonEdit.Click += ButtonEdit_Click; @@ -129,7 +129,7 @@ buttonAdd.Location = new Point(668, 48); buttonAdd.Name = "buttonAdd"; buttonAdd.Size = new Size(94, 29); - buttonAdd.TabIndex = 1; + buttonAdd.TabIndex = 3; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; buttonAdd.Click += ButtonAdd_Click; @@ -173,7 +173,7 @@ buttonSave.Location = new Point(537, 409); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(108, 29); - buttonSave.TabIndex = 1; + buttonSave.TabIndex = 7; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; buttonSave.Click += ButtonSave_Click; @@ -183,7 +183,7 @@ buttonCancel.Location = new Point(665, 409); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(109, 29); - buttonCancel.TabIndex = 6; + buttonCancel.TabIndex = 8; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; diff --git a/SecuritySystem/SecuritySystemView/FormSecure.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecure.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormSecure.cs rename to SecuritySystem/SecuritySystemView/Secure/FormSecure.cs diff --git a/SecuritySystem/SecuritySystemView/FormSecure.resx b/SecuritySystem/SecuritySystemView/Secure/FormSecure.resx similarity index 100% rename from SecuritySystem/SecuritySystemView/FormSecure.resx rename to SecuritySystem/SecuritySystemView/Secure/FormSecure.resx diff --git a/SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.Designer.cs similarity index 96% rename from SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs rename to SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.Designer.cs index f49c86c..06d5749 100644 --- a/SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs +++ b/SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.Designer.cs @@ -61,21 +61,21 @@ comboBoxComponents.Location = new Point(109, 6); comboBoxComponents.Name = "comboBoxComponents"; comboBoxComponents.Size = new Size(315, 28); - comboBoxComponents.TabIndex = 2; + comboBoxComponents.TabIndex = 1; // // textBoxCount // textBoxCount.Location = new Point(109, 41); textBoxCount.Name = "textBoxCount"; textBoxCount.Size = new Size(315, 27); - textBoxCount.TabIndex = 3; + textBoxCount.TabIndex = 2; // // buttonSave // buttonSave.Location = new Point(230, 84); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(94, 29); - buttonSave.TabIndex = 1; + buttonSave.TabIndex = 3; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; buttonSave.Click += ButtonSave_Click; @@ -85,7 +85,7 @@ buttonCancel.Location = new Point(330, 84); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(94, 29); - buttonCancel.TabIndex = 5; + buttonCancel.TabIndex = 4; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; diff --git a/SecuritySystem/SecuritySystemView/FormSecureComponent.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormSecureComponent.cs rename to SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.cs diff --git a/SecuritySystem/SecuritySystemView/FormSecureComponent.resx b/SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.resx similarity index 100% rename from SecuritySystem/SecuritySystemView/FormSecureComponent.resx rename to SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.resx diff --git a/SecuritySystem/SecuritySystemView/FormSecures.Designer.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecures.Designer.cs similarity index 97% rename from SecuritySystem/SecuritySystemView/FormSecures.Designer.cs rename to SecuritySystem/SecuritySystemView/Secure/FormSecures.Designer.cs index b3ac3b4..06698ee 100644 --- a/SecuritySystem/SecuritySystemView/FormSecures.Designer.cs +++ b/SecuritySystem/SecuritySystemView/Secure/FormSecures.Designer.cs @@ -56,7 +56,7 @@ buttonRefresh.Location = new Point(739, 162); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(94, 29); - buttonRefresh.TabIndex = 8; + buttonRefresh.TabIndex = 4; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += ButtonRefreshSecures_Click; @@ -67,7 +67,7 @@ buttonDelete.Location = new Point(739, 114); buttonDelete.Name = "buttonDelete"; buttonDelete.Size = new Size(94, 29); - buttonDelete.TabIndex = 7; + buttonDelete.TabIndex = 3; buttonDelete.Text = "Удалить"; buttonDelete.UseVisualStyleBackColor = true; buttonDelete.Click += ButtonDeleteSecure_Click; @@ -78,7 +78,7 @@ buttonEdit.Location = new Point(739, 64); buttonEdit.Name = "buttonEdit"; buttonEdit.Size = new Size(94, 29); - buttonEdit.TabIndex = 6; + buttonEdit.TabIndex = 2; buttonEdit.Text = "Изменить"; buttonEdit.UseVisualStyleBackColor = true; buttonEdit.Click += ButtonEditSecure_Click; diff --git a/SecuritySystem/SecuritySystemView/FormSecures.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecures.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormSecures.cs rename to SecuritySystem/SecuritySystemView/Secure/FormSecures.cs diff --git a/SecuritySystem/SecuritySystemView/FormSecures.resx b/SecuritySystem/SecuritySystemView/Secure/FormSecures.resx similarity index 100% rename from SecuritySystem/SecuritySystemView/FormSecures.resx rename to SecuritySystem/SecuritySystemView/Secure/FormSecures.resx diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShop.Designer.cs b/SecuritySystem/SecuritySystemView/Shop/FormShop.Designer.cs new file mode 100644 index 0000000..cdaf9ef --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShop.Designer.cs @@ -0,0 +1,194 @@ +namespace SecuritySystemView +{ + 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() + { + labelName = new Label(); + labelAddress = new Label(); + labelOpeningDate = new Label(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + dateTimePickerOpeningDate = new DateTimePicker(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + colorDialog1 = new ColorDialog(); + buttonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(80, 20); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(12, 41); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(54, 20); + labelAddress.TabIndex = 1; + labelAddress.Text = "Адрес:"; + // + // labelOpeningDate + // + labelOpeningDate.AutoSize = true; + labelOpeningDate.Location = new Point(12, 75); + labelOpeningDate.Name = "labelOpeningDate"; + labelOpeningDate.Size = new Size(113, 20); + labelOpeningDate.TabIndex = 2; + labelOpeningDate.Text = "Дата открытия:"; + // + // textBoxName + // + textBoxName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxName.Location = new Point(98, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(562, 27); + textBoxName.TabIndex = 1; + // + // textBoxAddress + // + textBoxAddress.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxAddress.Location = new Point(98, 38); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(562, 27); + textBoxAddress.TabIndex = 2; + // + // dateTimePickerOpeningDate + // + dateTimePickerOpeningDate.Location = new Point(131, 71); + dateTimePickerOpeningDate.Name = "dateTimePickerOpeningDate"; + dateTimePickerOpeningDate.Size = new Size(185, 27); + dateTimePickerOpeningDate.TabIndex = 3; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Location = new Point(12, 104); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(517, 334); + dataGridView.TabIndex = 6; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Изделие"; + ColumnName.MinimumWidth = 6; + ColumnName.Name = "ColumnName"; + // + // ColumnCount + // + ColumnCount.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader; + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.Width = 119; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonSave.Location = new Point(549, 145); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonCancel.Location = new Point(549, 219); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Закрыть"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(672, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(dataGridView); + Controls.Add(dateTimePickerOpeningDate); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Controls.Add(labelOpeningDate); + Controls.Add(labelAddress); + Controls.Add(labelName); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelAddress; + private Label labelOpeningDate; + private TextBox textBoxName; + private TextBox textBoxAddress; + private DateTimePicker dateTimePickerOpeningDate; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + private ColorDialog colorDialog1; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShop.cs b/SecuritySystem/SecuritySystemView/Shop/FormShop.cs new file mode 100644 index 0000000..6ea11d3 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShop.cs @@ -0,0 +1,125 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemView +{ + public partial class FormShop : Form + { + private readonly IShopLogic _logic; + private readonly ILogger _logger; + private Dictionary _shopSecures; + private int? _id; + public int Id { set { _id = value; } } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopSecures = new(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Loading shop"); + + try + { + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + + if (view != null) + { + textBoxName.Text = view.Name; + textBoxAddress.Text = view.Address; + dateTimePickerOpeningDate.Value = view.OpeningDate; + _shopSecures = view.ShopSecures ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка магазина"); + + try + { + if (_shopSecures != null) + { + dataGridView.Rows.Clear(); + foreach (var secure in _shopSecures) + { + dataGridView.Rows.Add(new object[] { secure.Key, secure.Value.Item1.SecureName, secure.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение магазина"); + + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + Address = textBoxAddress.Text, + OpeningDate = dateTimePickerOpeningDate.Value.Date, + ShopSecures = _shopSecures + }; + + 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/SecuritySystem/SecuritySystemView/Shop/FormShop.resx b/SecuritySystem/SecuritySystemView/Shop/FormShop.resx new file mode 100644 index 0000000..09810c9 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShop.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + 17, 17 + + \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.Designer.cs b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.Designer.cs new file mode 100644 index 0000000..0a99cab --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.Designer.cs @@ -0,0 +1,148 @@ +namespace SecuritySystemView +{ + partial class FormShopSupply + { + /// + /// 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() + { + comboBoxShop = new ComboBox(); + comboBoxSecure = new ComboBox(); + labelShop = new Label(); + label2 = new Label(); + label3 = new Label(); + buttonSupply = new Button(); + buttonCancel = new Button(); + textBoxCount = new TextBox(); + SuspendLayout(); + // + // comboBoxShop + // + comboBoxShop.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxShop.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(125, 6); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(432, 28); + comboBoxShop.TabIndex = 1; + // + // comboBoxSecure + // + comboBoxSecure.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSecure.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSecure.FormattingEnabled = true; + comboBoxSecure.Location = new Point(125, 47); + comboBoxSecure.Name = "comboBoxSecure"; + comboBoxSecure.Size = new Size(432, 28); + comboBoxSecure.TabIndex = 2; + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(12, 9); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(72, 20); + labelShop.TabIndex = 3; + labelShop.Text = "Магазин:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 50); + label2.Name = "label2"; + label2.Size = new Size(71, 20); + label2.TabIndex = 4; + label2.Text = "Изделие:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 89); + label3.Name = "label3"; + label3.Size = new Size(93, 20); + label3.TabIndex = 5; + label3.Text = "Количество:"; + // + // buttonSupply + // + buttonSupply.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSupply.Location = new Point(342, 130); + buttonSupply.Name = "buttonSupply"; + buttonSupply.Size = new Size(94, 29); + buttonSupply.TabIndex = 4; + buttonSupply.Text = "Поставить"; + buttonSupply.UseVisualStyleBackColor = true; + buttonSupply.Click += buttonSupply_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(463, 130); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // textBoxCount + // + textBoxCount.Location = new Point(125, 89); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(167, 27); + textBoxCount.TabIndex = 3; + // + // FormShopSupply + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(569, 169); + Controls.Add(textBoxCount); + Controls.Add(buttonCancel); + Controls.Add(buttonSupply); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(labelShop); + Controls.Add(comboBoxSecure); + Controls.Add(comboBoxShop); + Name = "FormShopSupply"; + Text = "Поставка изделия"; + Load += FormShopSupply_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxShop; + private ComboBox comboBoxSecure; + private Label labelShop; + private Label label2; + private Label label3; + private Button buttonSupply; + private Button buttonCancel; + private TextBox textBoxCount; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.cs b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.cs new file mode 100644 index 0000000..ff14ef8 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.cs @@ -0,0 +1,117 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; + +namespace SecuritySystemView +{ + public partial class FormShopSupply : Form + { + private readonly ILogger _logger; + private readonly ISecureLogic _logicSecure; + private readonly IShopLogic _logicShop; + + public FormShopSupply(ILogger logger, ISecureLogic logicSecure, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicSecure = logicSecure; + _logicShop = logicShop; + } + + private void FormShopSupply_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка secure для пополнения"); + + try + { + var list = _logicSecure.ReadList(null); + if (list != null) + { + comboBoxSecure.DisplayMember = "SecureName"; + comboBoxSecure.ValueMember = "Id"; + comboBoxSecure.DataSource = list; + comboBoxSecure.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка secure"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка магазинов для пополнения"); + + try + { + var list = _logicShop.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "Name"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSupply_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxSecure.SelectedValue == null) + { + MessageBox.Show("Выберите secure", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Создание поставки"); + + try + { + var operationResult = _logicShop.SupplySecures( + new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue), Name = comboBoxShop.Text }, + new SecureBindingModel { Id = Convert.ToInt32(comboBoxSecure.SelectedValue), SecureName = comboBoxSecure.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 buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.resx b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.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/SecuritySystem/SecuritySystemView/Shop/FormShops.Designer.cs b/SecuritySystem/SecuritySystemView/Shop/FormShops.Designer.cs new file mode 100644 index 0000000..42e785c --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShops.Designer.cs @@ -0,0 +1,124 @@ +namespace SecuritySystemView +{ + 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() + { + dataGridView = new DataGridView(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + 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.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(716, 406); + dataGridView.TabIndex = 1; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRefresh.Location = new Point(735, 261); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(94, 29); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonDelete.Location = new Point(735, 213); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(94, 29); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonEdit + // + buttonEdit.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonEdit.Location = new Point(735, 163); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(94, 29); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += buttonEdit_Click; + // + // buttonAdd + // + buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonAdd.Location = new Point(735, 111); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(841, 406); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShops.cs b/SecuritySystem/SecuritySystemView/Shop/FormShops.cs new file mode 100644 index 0000000..4bff54b --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShops.cs @@ -0,0 +1,111 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; + +namespace SecuritySystemView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopSecures"].Visible = false; + } + + _logger.LogInformation("Загрузка магазинов"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonRefresh_Click(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 buttonEdit_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 buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить магазин?", "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + + try + { + if (!_logic.Delete(new ShopBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShops.resx b/SecuritySystem/SecuritySystemView/Shop/FormShops.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/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