diff --git a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/OrderLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/OrderLogic.cs
index c96ad04..ad4d0d4 100644
--- a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/OrderLogic.cs
+++ b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -33,8 +33,7 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
///
///
///
- public OrderLogic(ILogger logger, IOrderStorage
-orderStorage)
+ public OrderLogic(ILogger logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
diff --git a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/PlaneLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/PlaneLogic.cs
index 82de87f..17a7b74 100644
--- a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/PlaneLogic.cs
+++ b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/PlaneLogic.cs
@@ -32,8 +32,7 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
///
///
///
- public PlaneLogic(ILogger logger, IPlaneStorage
-planeStorage)
+ public PlaneLogic(ILogger logger, IPlaneStorage planeStorage)
{
_logger = logger;
_planeStorage = planeStorage;
diff --git a/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/ShopLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/ShopLogic.cs
new file mode 100644
index 0000000..7a6f6d3
--- /dev/null
+++ b/AircraftPlant/AircraftPlantBusinessLogic/BusinessLogics/ShopLogic.cs
@@ -0,0 +1,222 @@
+using AircraftPlantContracts.BindingModels;
+using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.SearchModels;
+using AircraftPlantContracts.StoragesContracts;
+using AircraftPlantContracts.ViewModels;
+using AircraftPlantDataModels.Models;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantBusinessLogic.BusinessLogics
+{
+ ///
+ /// Реализация интерфейса бизнес-логики для магазинов
+ ///
+ public class ShopLogic : IShopLogic
+ {
+ ///
+ /// Логгер
+ ///
+ private readonly ILogger _logger;
+
+ ///
+ /// Взаимодействие с хранилищем магазинов
+ ///
+ private readonly IShopStorage _shopStorage;
+
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public ShopLogic(ILogger logger, IShopStorage shopStorage)
+ {
+ _logger = logger;
+ _shopStorage = shopStorage;
+ }
+
+ ///
+ /// Получение списка
+ ///
+ ///
+ ///
+ public List? ReadList(ShopSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id);
+
+ var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ ///
+ /// Получение отдельной записи
+ ///
+ ///
+ ///
+ ///
+ public ShopViewModel? ReadElement(ShopSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
+
+ var element = _shopStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
+ ///
+ /// Создание записи
+ ///
+ ///
+ ///
+ public bool Create(ShopBindingModel model)
+ {
+ CheckModel(model);
+
+ if (_shopStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ ///
+ /// Изменение записи
+ ///
+ ///
+ ///
+ public bool Update(ShopBindingModel model)
+ {
+ CheckModel(model);
+
+ if (_shopStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ ///
+ /// Удаление записи
+ ///
+ ///
+ ///
+ public bool Delete(ShopBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+
+ if (_shopStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ ///
+ /// Добавление изделия в магазин
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public bool AddPlaneInShop(ShopSearchModel model, IPlaneModel plane, int count)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (count <= 0)
+ {
+ throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count));
+ }
+ _logger.LogInformation("AddPlaneInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
+ var element = _shopStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("AddPlaneInShop element not found");
+ return false;
+ }
+ _logger.LogInformation("AddPlaneInShop find. Id:{Id}", element.Id);
+
+ if (element.ShopPlanes.TryGetValue(plane.Id, out var pair))
+ {
+ element.ShopPlanes[plane.Id] = (plane, count + pair.Item2);
+ _logger.LogInformation("AddPlaneInShop. Added {count} {plane} to '{ShopName}' shop", count, plane.PlaneName, element.ShopName);
+ }
+ else
+ {
+ element.ShopPlanes[plane.Id] = (plane, count);
+ _logger.LogInformation("AddPlaneInShop. Added {count} new plane {plane} to '{ShopName}' shop", count, plane.PlaneName, element.ShopName);
+ }
+
+ _shopStorage.Update(new()
+ {
+ Id = element.Id,
+ Address = element.Address,
+ ShopName = element.ShopName,
+ DateOpening = element.DateOpening,
+ ShopPlanes = element.ShopPlanes
+ });
+ return true;
+ }
+
+ ///
+ /// Проверка модели магазина
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void CheckModel(ShopBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.ShopName))
+ {
+ throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName));
+ }
+ _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{ Address}. Id:{ Id}", model.ShopName, model.Address, model.Id);
+ var element = _shopStorage.GetElement(new ShopSearchModel
+ {
+ ShopName = model.ShopName
+ });
+ if (element != null && element.Id != model.Id && element.ShopName == model.ShopName)
+ {
+ throw new InvalidOperationException("Магазин с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/BindingModels/ShopBindingModel.cs b/AircraftPlant/AircraftPlantContracts/BindingModels/ShopBindingModel.cs
new file mode 100644
index 0000000..74d61f5
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/BindingModels/ShopBindingModel.cs
@@ -0,0 +1,45 @@
+using AircraftPlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.BindingModels
+{
+ ///
+ /// Модель для передачи данных пользователя
+ /// в методы для сохранения данных для магазинов
+ ///
+ public class ShopBindingModel : IShopModel
+ {
+ ///
+ /// Идентификатор
+ ///
+ public int Id { get; set; }
+
+ ///
+ /// Название магазина
+ ///
+ public string ShopName { get; set; } = string.Empty;
+
+ ///
+ /// Адрес магазина
+ ///
+ public string Address { get; set; } = string.Empty;
+
+ ///
+ /// Дата открытия магазина
+ ///
+ public DateTime DateOpening { get; set; } = DateTime.Now;
+
+ ///
+ /// Коллекция изделий в магазине
+ ///
+ public Dictionary ShopPlanes
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/BusinessLogicsContracts/IShopLogic.cs b/AircraftPlant/AircraftPlantContracts/BusinessLogicsContracts/IShopLogic.cs
new file mode 100644
index 0000000..f8bdb53
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/BusinessLogicsContracts/IShopLogic.cs
@@ -0,0 +1,62 @@
+using AircraftPlantContracts.BindingModels;
+using AircraftPlantContracts.SearchModels;
+using AircraftPlantContracts.ViewModels;
+using AircraftPlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.BusinessLogicsContracts
+{
+ ///
+ /// Интерфейс для описания работы бизнес-логики для магазинов
+ ///
+ public interface IShopLogic
+ {
+ ///
+ /// Получение списка
+ ///
+ ///
+ ///
+ List? ReadList(ShopSearchModel? model);
+
+ ///
+ /// Получение отдельной записи
+ ///
+ ///
+ ///
+ ShopViewModel? ReadElement(ShopSearchModel model);
+
+ ///
+ /// Создание записи
+ ///
+ ///
+ ///
+ bool Create(ShopBindingModel model);
+
+ ///
+ /// Изменение записи
+ ///
+ ///
+ ///
+ bool Update(ShopBindingModel model);
+
+ ///
+ /// Удаление записи
+ ///
+ ///
+ ///
+ bool Delete(ShopBindingModel model);
+
+ ///
+ /// Добавление изделия в магазин
+ ///
+ ///
+ ///
+ ///
+ ///
+ bool AddPlaneInShop(ShopSearchModel model, IPlaneModel plane, int count);
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/SearchModels/ShopSearchModel.cs b/AircraftPlant/AircraftPlantContracts/SearchModels/ShopSearchModel.cs
new file mode 100644
index 0000000..dec0ac8
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/SearchModels/ShopSearchModel.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.SearchModels
+{
+ ///
+ /// Модель для передачи данных пользователя
+ /// в методы для поиска данных для магазинов
+ ///
+ public class ShopSearchModel
+ {
+ ///
+ /// Идентификатор
+ ///
+ public int? Id { get; set; }
+
+ ///
+ /// Название магазина
+ ///
+ public string? ShopName { get; set; }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/StoragesContracts/IShopStorage.cs b/AircraftPlant/AircraftPlantContracts/StoragesContracts/IShopStorage.cs
new file mode 100644
index 0000000..9c89ffe
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/StoragesContracts/IShopStorage.cs
@@ -0,0 +1,58 @@
+using AircraftPlantContracts.BindingModels;
+using AircraftPlantContracts.SearchModels;
+using AircraftPlantContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.StoragesContracts
+{
+ ///
+ /// Интерфейс для описания работы с хранилищем для магазинов
+ ///
+ public interface IShopStorage
+ {
+ ///
+ /// Получение полного списка
+ ///
+ ///
+ List GetFullList();
+
+ ///
+ /// Получение фильтрованного списка
+ ///
+ ///
+ ///
+ List GetFilteredList(ShopSearchModel model);
+
+ ///
+ /// Получение элемента
+ ///
+ ///
+ ///
+ ShopViewModel? GetElement(ShopSearchModel model);
+
+ ///
+ /// Добавление элемента
+ ///
+ ///
+ ///
+ ShopViewModel? Insert(ShopBindingModel model);
+
+ ///
+ /// Редактирование элемента
+ ///
+ ///
+ ///
+ ShopViewModel? Update(ShopBindingModel model);
+
+ ///
+ /// Удаление элемента
+ ///
+ ///
+ ///
+ ShopViewModel? Delete(ShopBindingModel model);
+ }
+}
diff --git a/AircraftPlant/AircraftPlantContracts/ViewModels/ShopViewModel.cs b/AircraftPlant/AircraftPlantContracts/ViewModels/ShopViewModel.cs
new file mode 100644
index 0000000..7ca01d7
--- /dev/null
+++ b/AircraftPlant/AircraftPlantContracts/ViewModels/ShopViewModel.cs
@@ -0,0 +1,49 @@
+using AircraftPlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantContracts.ViewModels
+{
+ ///
+ /// Модель для передачи данных пользователю
+ /// для отображения для магазинов
+ ///
+ public class ShopViewModel : IShopModel
+ {
+ ///
+ /// Идентификатор
+ ///
+ public int Id { get; set; }
+
+ ///
+ /// Название магазина
+ ///
+ [DisplayName("Название магазина")]
+ public string ShopName { get; set; } = string.Empty;
+
+ ///
+ /// Адрес магазина
+ ///
+ [DisplayName("Адрес магазина")]
+ public string Address { get; set; } = string.Empty;
+
+ ///
+ /// Дата открытия магазина
+ ///
+ [DisplayName("Дата открытия")]
+ public DateTime DateOpening { get; set; } = DateTime.Now;
+
+ ///
+ /// Коллекция изделий в магазине
+ ///
+ public Dictionary ShopPlanes
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/AircraftPlant/AircraftPlantDataModels/Models/IShopModel.cs b/AircraftPlant/AircraftPlantDataModels/Models/IShopModel.cs
new file mode 100644
index 0000000..ca684fa
--- /dev/null
+++ b/AircraftPlant/AircraftPlantDataModels/Models/IShopModel.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantDataModels.Models
+{
+ ///
+ /// Интерфейс для модели магазина
+ ///
+ public interface IShopModel : IId
+ {
+ ///
+ /// Название магазина
+ ///
+ string ShopName { get; }
+
+ ///
+ /// Адрес магазина
+ ///
+ string Address { get; }
+
+ ///
+ /// Дата открытия магазина
+ ///
+ DateTime DateOpening { get; }
+
+ ///
+ /// Коллекция изделий в магазине
+ ///
+ Dictionary ShopPlanes { get; }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantListImplement/DataListSingleton.cs b/AircraftPlant/AircraftPlantListImplement/DataListSingleton.cs
index eb745b4..736bfee 100644
--- a/AircraftPlant/AircraftPlantListImplement/DataListSingleton.cs
+++ b/AircraftPlant/AircraftPlantListImplement/DataListSingleton.cs
@@ -32,6 +32,11 @@ namespace AircraftPlantListImplement
///
public List Planes { get; set; }
+ ///
+ /// Список классов-моделей магазинов
+ ///
+ public List Shops { get; set; }
+
///
/// Конструктор
///
@@ -40,6 +45,7 @@ namespace AircraftPlantListImplement
Components = new List();
Orders = new List();
Planes = new List();
+ Shops = new List();
}
///
diff --git a/AircraftPlant/AircraftPlantListImplement/Implements/ShopStorage.cs b/AircraftPlant/AircraftPlantListImplement/Implements/ShopStorage.cs
new file mode 100644
index 0000000..9ca1ff9
--- /dev/null
+++ b/AircraftPlant/AircraftPlantListImplement/Implements/ShopStorage.cs
@@ -0,0 +1,154 @@
+using AircraftPlantContracts.BindingModels;
+using AircraftPlantContracts.SearchModels;
+using AircraftPlantContracts.StoragesContracts;
+using AircraftPlantContracts.ViewModels;
+using AircraftPlantListImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantListImplement.Implements
+{
+ ///
+ /// Реализация интерфейса хранилища для магазина
+ ///
+ public class ShopStorage : IShopStorage
+ {
+ ///
+ /// Хранилище
+ ///
+ private readonly DataListSingleton _source;
+
+ ///
+ /// Конструктор
+ ///
+ public ShopStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ ///
+ /// Получение полного списка
+ ///
+ ///
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var shop in _source.Shops)
+ {
+ result.Add(shop.GetViewModel);
+ }
+ return result;
+ }
+
+ ///
+ /// Получение фильтрованного списка
+ ///
+ ///
+ ///
+ public List GetFilteredList(ShopSearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.ShopName))
+ {
+ return result;
+ }
+
+ foreach (var shop in _source.Shops)
+ {
+ if (shop.ShopName.Contains(model.ShopName))
+ {
+ result.Add(shop.GetViewModel);
+ }
+ }
+ return result;
+ }
+
+ ///
+ /// Получение элемента
+ ///
+ ///
+ ///
+ public ShopViewModel? GetElement(ShopSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+
+ foreach (var shop in _source.Shops)
+ {
+ if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (model.Id.HasValue && shop.Id == model.Id))
+ {
+ return shop.GetViewModel;
+ }
+ }
+ return null;
+ }
+
+ ///
+ /// Добавление элемента
+ ///
+ ///
+ ///
+ public ShopViewModel? Insert(ShopBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var shop in _source.Shops)
+ {
+ if (model.Id <= shop.Id)
+ {
+ model.Id = shop.Id + 1;
+ }
+ }
+
+ var newShop = Shop.Create(model);
+ if (newShop == null)
+ {
+ return null;
+ }
+
+ _source.Shops.Add(newShop);
+ return newShop.GetViewModel;
+ }
+
+ ///
+ /// Редактирование элемента
+ ///
+ ///
+ ///
+ public ShopViewModel? Update(ShopBindingModel model)
+ {
+ foreach (var shop in _source.Shops)
+ {
+ if (shop.Id == model.Id)
+ {
+ shop.Update(model);
+ return shop.GetViewModel;
+ }
+ }
+ return null;
+ }
+
+ ///
+ /// Удаление элемента
+ ///
+ ///
+ ///
+ public ShopViewModel? Delete(ShopBindingModel model)
+ {
+ for (int i = 0; i < _source.Shops.Count; ++i)
+ {
+ if (_source.Shops[i].Id == model.Id)
+ {
+ var element = _source.Shops[i];
+ _source.Shops.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantListImplement/Models/Shop.cs b/AircraftPlant/AircraftPlantListImplement/Models/Shop.cs
new file mode 100644
index 0000000..148979b
--- /dev/null
+++ b/AircraftPlant/AircraftPlantListImplement/Models/Shop.cs
@@ -0,0 +1,97 @@
+using AircraftPlantContracts.BindingModels;
+using AircraftPlantContracts.ViewModels;
+using AircraftPlantDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AircraftPlantListImplement.Models
+{
+ ///
+ /// Сущность "Магазин"
+ ///
+ public class Shop : IShopModel
+ {
+ ///
+ /// Идентификатор
+ ///
+ public int Id { get; private set; }
+
+ ///
+ /// Название магазина
+ ///
+ public string ShopName { get; private set; } = string.Empty;
+
+ ///
+ /// Адрес магазина
+ ///
+ public string Address { get; private set; } = string.Empty;
+
+ ///
+ /// Дата открытия магазина
+ ///
+ public DateTime DateOpening { get; private set; }
+
+ ///
+ /// Коллекция изделий в магазине
+ ///
+ public Dictionary ShopPlanes
+ {
+ get;
+ private set;
+ } = new Dictionary();
+
+ ///
+ /// Создание модели магазина
+ ///
+ ///
+ ///
+ public static Shop? Create(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+
+ return new Shop()
+ {
+ Id = model.Id,
+ ShopName = model.ShopName,
+ Address = model.Address,
+ DateOpening = model.DateOpening,
+ ShopPlanes = model.ShopPlanes
+ };
+ }
+
+ ///
+ /// Изменение модели магазина
+ ///
+ ///
+ public void Update(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+
+ ShopName = model.ShopName;
+ Address = model.Address;
+ DateOpening = model.DateOpening;
+ ShopPlanes = model.ShopPlanes;
+ }
+
+ ///
+ /// Получение модели магазина
+ ///
+ public ShopViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ShopName = ShopName,
+ Address = Address,
+ DateOpening = DateOpening,
+ ShopPlanes = ShopPlanes
+ };
+ }
+}
diff --git a/AircraftPlant/AircraftPlantView/FormCreateSupply.Designer.cs b/AircraftPlant/AircraftPlantView/FormCreateSupply.Designer.cs
new file mode 100644
index 0000000..7ca6ad4
--- /dev/null
+++ b/AircraftPlant/AircraftPlantView/FormCreateSupply.Designer.cs
@@ -0,0 +1,146 @@
+namespace AircraftPlantView
+{
+ partial class FormCreateSupply
+ {
+ ///
+ /// 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();
+ labelShop = new Label();
+ labelPlane = new Label();
+ comboBoxPlane = new ComboBox();
+ numericUpDownCount = new NumericUpDown();
+ labelCount = new Label();
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
+ SuspendLayout();
+ //
+ // comboBoxShop
+ //
+ comboBoxShop.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxShop.FormattingEnabled = true;
+ comboBoxShop.Location = new Point(90, 12);
+ comboBoxShop.Name = "comboBoxShop";
+ comboBoxShop.Size = new Size(282, 23);
+ comboBoxShop.TabIndex = 0;
+ //
+ // labelShop
+ //
+ labelShop.AutoSize = true;
+ labelShop.Location = new Point(12, 15);
+ labelShop.Name = "labelShop";
+ labelShop.Size = new Size(57, 15);
+ labelShop.TabIndex = 1;
+ labelShop.Text = "Магазин:";
+ //
+ // labelPlane
+ //
+ labelPlane.AutoSize = true;
+ labelPlane.Location = new Point(12, 44);
+ labelPlane.Name = "labelPlane";
+ labelPlane.Size = new Size(56, 15);
+ labelPlane.TabIndex = 2;
+ labelPlane.Text = "Изделие:";
+ //
+ // comboBoxPlane
+ //
+ comboBoxPlane.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxPlane.FormattingEnabled = true;
+ comboBoxPlane.Location = new Point(90, 41);
+ comboBoxPlane.Name = "comboBoxPlane";
+ comboBoxPlane.Size = new Size(282, 23);
+ comboBoxPlane.TabIndex = 3;
+ //
+ // numericUpDownCount
+ //
+ numericUpDownCount.Location = new Point(90, 70);
+ numericUpDownCount.Name = "numericUpDownCount";
+ numericUpDownCount.Size = new Size(282, 23);
+ numericUpDownCount.TabIndex = 4;
+ //
+ // labelCount
+ //
+ labelCount.AutoSize = true;
+ labelCount.Location = new Point(12, 72);
+ labelCount.Name = "labelCount";
+ labelCount.Size = new Size(75, 15);
+ labelCount.TabIndex = 5;
+ labelCount.Text = "Количество:";
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(297, 99);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 6;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(216, 99);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 7;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // FormCreateSupply
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(384, 131);
+ Controls.Add(buttonSave);
+ Controls.Add(buttonCancel);
+ Controls.Add(labelCount);
+ Controls.Add(numericUpDownCount);
+ Controls.Add(comboBoxPlane);
+ Controls.Add(labelPlane);
+ Controls.Add(labelShop);
+ Controls.Add(comboBoxShop);
+ Name = "FormCreateSupply";
+ Text = "Поступление";
+ Load += FormCreateSupply_Load;
+ ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private ComboBox comboBoxShop;
+ private Label labelShop;
+ private Label labelPlane;
+ private ComboBox comboBoxPlane;
+ private NumericUpDown numericUpDownCount;
+ private Label labelCount;
+ private Button buttonCancel;
+ private Button buttonSave;
+ }
+}
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlantView/FormCreateSupply.cs b/AircraftPlant/AircraftPlantView/FormCreateSupply.cs
new file mode 100644
index 0000000..b6b2fa0
--- /dev/null
+++ b/AircraftPlant/AircraftPlantView/FormCreateSupply.cs
@@ -0,0 +1,159 @@
+using AircraftPlantBusinessLogic.BusinessLogics;
+using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.SearchModels;
+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 AircraftPlantView
+{
+ ///
+ /// Форма для добавления поступления
+ ///
+ public partial class FormCreateSupply : Form
+ {
+ ///
+ /// Логгер
+ ///
+ private readonly ILogger _logger;
+
+ ///
+ /// Бизнес-логика для магазина
+ ///
+ private readonly IShopLogic _logicS;
+
+ ///
+ /// Бизнес-логика для изделий
+ ///
+ private readonly IPlaneLogic _logicP;
+
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public FormCreateSupply(ILogger logger, IShopLogic logicS, IPlaneLogic logicP)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicS = logicS;
+ _logicP = logicP;
+ }
+
+ ///
+ /// Загрузка списиков магазинов и изделий
+ ///
+ ///
+ ///
+ private void FormCreateSupply_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Загрузка магазинов");
+ try
+ {
+ var listShops = _logicS.ReadList(null);
+ if (listShops != null)
+ {
+ comboBoxShop.DisplayMember = "ShopName";
+ comboBoxShop.ValueMember = "Id";
+ comboBoxShop.DataSource = listShops;
+ comboBoxShop.SelectedItem = null;
+ }
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки списка магазинов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ _logger.LogInformation("Загрузка изделий");
+ try
+ {
+ var listPlanes = _logicP.ReadList(null);
+ if (listPlanes != null)
+ {
+ comboBoxPlane.DisplayMember = "PlaneName";
+ comboBoxPlane.ValueMember = "Id";
+ comboBoxPlane.DataSource = listPlanes;
+ comboBoxPlane.SelectedItem = null;
+ }
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки списка изделий");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ ///
+ /// Кнопка "Сохранить"
+ ///
+ ///
+ ///
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (comboBoxShop.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxPlane.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Добавление изделия в магазин");
+ try
+ {
+ var plane = _logicP.ReadElement(new()
+ {
+ Id = (int)comboBoxPlane.SelectedValue
+ });
+ if (plane == null)
+ {
+ throw new Exception("Не найдено изделие. Дополнительная информация в логах.");
+ }
+ var resultOperation = _logicS.AddPlaneInShop(
+ new ShopSearchModel
+ {
+ Id = (int)comboBoxShop.SelectedValue
+ },
+ plane,
+ (int)numericUpDownCount.Value
+ );
+ if (!resultOperation)
+ {
+ throw new Exception("Ошибка при добавлении. Дополнительная информация в логах.");
+ }
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка добавления поступления");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ ///
+ /// Кнопка "Отмена"
+ ///
+ ///
+ ///
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantView/FormCreateSupply.resx b/AircraftPlant/AircraftPlantView/FormCreateSupply.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/AircraftPlant/AircraftPlantView/FormCreateSupply.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/AircraftPlant/AircraftPlantView/FormMain.Designer.cs b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs
index a68fe27..8b19960 100644
--- a/AircraftPlant/AircraftPlantView/FormMain.Designer.cs
+++ b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs
@@ -38,6 +38,8 @@
справочникиToolStripMenuItem = new ToolStripMenuItem();
компонентыToolStripMenuItem = new ToolStripMenuItem();
изделияToolStripMenuItem = new ToolStripMenuItem();
+ магазиныToolStripMenuItem = new ToolStripMenuItem();
+ buttonAddPlaneInShop = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
menuStrip.SuspendLayout();
SuspendLayout();
@@ -121,7 +123,7 @@
//
// справочникиToolStripMenuItem
//
- справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem });
+ справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, магазиныToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(94, 20);
справочникиToolStripMenuItem.Text = "Справочники";
@@ -129,22 +131,40 @@
// компонентыToolStripMenuItem
//
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
- компонентыToolStripMenuItem.Size = new Size(145, 22);
+ компонентыToolStripMenuItem.Size = new Size(180, 22);
компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click;
//
// изделияToolStripMenuItem
//
изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
- изделияToolStripMenuItem.Size = new Size(145, 22);
+ изделияToolStripMenuItem.Size = new Size(180, 22);
изделияToolStripMenuItem.Text = "Изделия";
изделияToolStripMenuItem.Click += изделияToolStripMenuItem_Click;
//
+ // магазиныToolStripMenuItem
+ //
+ магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
+ магазиныToolStripMenuItem.Size = new Size(180, 22);
+ магазиныToolStripMenuItem.Text = "Магазины";
+ магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
+ //
+ // buttonAddPlaneInShop
+ //
+ buttonAddPlaneInShop.Location = new Point(822, 210);
+ buttonAddPlaneInShop.Name = "buttonAddPlaneInShop";
+ buttonAddPlaneInShop.Size = new Size(150, 50);
+ buttonAddPlaneInShop.TabIndex = 7;
+ buttonAddPlaneInShop.Text = "Добавить изделие\r\nв магазин";
+ buttonAddPlaneInShop.UseVisualStyleBackColor = true;
+ buttonAddPlaneInShop.Click += buttonAddPlaneInShop_Click;
+ //
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(984, 361);
+ Controls.Add(buttonAddPlaneInShop);
Controls.Add(buttonRefresh);
Controls.Add(buttonIssuedOrder);
Controls.Add(buttonOrderReady);
@@ -175,5 +195,7 @@
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem изделияToolStripMenuItem;
+ private ToolStripMenuItem магазиныToolStripMenuItem;
+ private Button buttonAddPlaneInShop;
}
}
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlantView/FormMain.cs b/AircraftPlant/AircraftPlantView/FormMain.cs
index 39a70bc..2006e9f 100644
--- a/AircraftPlant/AircraftPlantView/FormMain.cs
+++ b/AircraftPlant/AircraftPlantView/FormMain.cs
@@ -79,6 +79,20 @@ namespace AircraftPlantView
}
}
+ ///
+ /// Показать список всех магазинов
+ ///
+ ///
+ ///
+ private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShops));
+ if (service is FormShops form)
+ {
+ form.ShowDialog();
+ }
+ }
+
///
/// Кнопка "Создать заказ"
///
@@ -179,6 +193,20 @@ namespace AircraftPlantView
}
}
+ ///
+ /// Кнопка "Добавить изделие в магазин"
+ ///
+ ///
+ ///
+ private void buttonAddPlaneInShop_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply));
+ if (service is FormCreateSupply form)
+ {
+ form.ShowDialog();
+ }
+ }
+
///
/// Кнопка "Обновить список"
///
diff --git a/AircraftPlant/AircraftPlantView/FormShop.Designer.cs b/AircraftPlant/AircraftPlantView/FormShop.Designer.cs
new file mode 100644
index 0000000..22f85ea
--- /dev/null
+++ b/AircraftPlant/AircraftPlantView/FormShop.Designer.cs
@@ -0,0 +1,188 @@
+namespace AircraftPlantView
+{
+ 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();
+ textBoxName = new TextBox();
+ labelAddress = new Label();
+ textBoxAddress = new TextBox();
+ dateTimePicker = new DateTimePicker();
+ labelDateOpening = new Label();
+ dataGridView = new DataGridView();
+ ColumnID = new DataGridViewTextBoxColumn();
+ ColumnPlaneName = new DataGridViewTextBoxColumn();
+ ColumnCount = new DataGridViewTextBoxColumn();
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // labelName
+ //
+ labelName.AutoSize = true;
+ labelName.Location = new Point(12, 15);
+ labelName.Name = "labelName";
+ labelName.Size = new Size(62, 15);
+ labelName.TabIndex = 0;
+ labelName.Text = "Название:";
+ //
+ // textBoxName
+ //
+ textBoxName.Location = new Point(110, 12);
+ textBoxName.Name = "textBoxName";
+ textBoxName.Size = new Size(200, 23);
+ textBoxName.TabIndex = 1;
+ //
+ // labelAddress
+ //
+ labelAddress.AutoSize = true;
+ labelAddress.Location = new Point(12, 44);
+ labelAddress.Name = "labelAddress";
+ labelAddress.Size = new Size(43, 15);
+ labelAddress.TabIndex = 2;
+ labelAddress.Text = "Адрес:";
+ //
+ // textBoxAddress
+ //
+ textBoxAddress.Location = new Point(110, 41);
+ textBoxAddress.Name = "textBoxAddress";
+ textBoxAddress.Size = new Size(200, 23);
+ textBoxAddress.TabIndex = 3;
+ //
+ // dateTimePicker
+ //
+ dateTimePicker.Location = new Point(110, 70);
+ dateTimePicker.Name = "dateTimePicker";
+ dateTimePicker.Size = new Size(200, 23);
+ dateTimePicker.TabIndex = 4;
+ //
+ // labelDateOpening
+ //
+ labelDateOpening.AutoSize = true;
+ labelDateOpening.Location = new Point(12, 76);
+ labelDateOpening.Name = "labelDateOpening";
+ labelDateOpening.Size = new Size(90, 15);
+ labelDateOpening.TabIndex = 5;
+ labelDateOpening.Text = "Дата открытия:";
+ //
+ // dataGridView
+ //
+ dataGridView.AllowUserToAddRows = false;
+ dataGridView.AllowUserToDeleteRows = false;
+ dataGridView.BackgroundColor = Color.White;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnID, ColumnPlaneName, ColumnCount });
+ dataGridView.GridColor = Color.White;
+ dataGridView.Location = new Point(12, 99);
+ dataGridView.MultiSelect = false;
+ dataGridView.Name = "dataGridView";
+ dataGridView.ReadOnly = true;
+ dataGridView.RowTemplate.Height = 25;
+ dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridView.Size = new Size(560, 321);
+ dataGridView.TabIndex = 6;
+ //
+ // ColumnID
+ //
+ ColumnID.HeaderText = "ID";
+ ColumnID.Name = "ColumnID";
+ ColumnID.ReadOnly = true;
+ ColumnID.Visible = false;
+ //
+ // ColumnPlaneName
+ //
+ ColumnPlaneName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ ColumnPlaneName.HeaderText = "Изделие";
+ ColumnPlaneName.Name = "ColumnPlaneName";
+ ColumnPlaneName.ReadOnly = true;
+ //
+ // ColumnCount
+ //
+ ColumnCount.HeaderText = "Количнство";
+ ColumnCount.Name = "ColumnCount";
+ ColumnCount.ReadOnly = true;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(497, 426);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 7;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(416, 426);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 8;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // FormShop
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(584, 461);
+ Controls.Add(buttonSave);
+ Controls.Add(buttonCancel);
+ Controls.Add(dataGridView);
+ Controls.Add(labelDateOpening);
+ Controls.Add(dateTimePicker);
+ Controls.Add(textBoxAddress);
+ Controls.Add(labelAddress);
+ Controls.Add(textBoxName);
+ Controls.Add(labelName);
+ Name = "FormShop";
+ Text = "Магазин";
+ Load += FormShop_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelName;
+ private TextBox textBoxName;
+ private Label labelAddress;
+ private TextBox textBoxAddress;
+ private DateTimePicker dateTimePicker;
+ private Label labelDateOpening;
+ private DataGridView dataGridView;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private DataGridViewTextBoxColumn ColumnID;
+ private DataGridViewTextBoxColumn ColumnPlaneName;
+ private DataGridViewTextBoxColumn ColumnCount;
+ }
+}
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlantView/FormShop.cs b/AircraftPlant/AircraftPlantView/FormShop.cs
new file mode 100644
index 0000000..a5a414d
--- /dev/null
+++ b/AircraftPlant/AircraftPlantView/FormShop.cs
@@ -0,0 +1,170 @@
+using AircraftPlantContracts.BindingModels;
+using AircraftPlantContracts.BusinessLogicsContracts;
+using AircraftPlantContracts.SearchModels;
+using AircraftPlantDataModels.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 AircraftPlantView
+{
+ ///
+ /// Форма для магазина
+ ///
+ public partial class FormShop : Form
+ {
+ ///
+ /// Логгер
+ ///
+ private readonly ILogger _logger;
+
+ ///
+ /// Бизнес-логика для магазинов
+ ///
+ private readonly IShopLogic _logic;
+
+ ///
+ /// Идентификатор
+ ///
+ private int? _id;
+ public int Id { set { _id = value; } }
+
+ ///
+ /// Список изделий в магазине
+ ///
+ private Dictionary _shopPlanes;
+
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public FormShop(ILogger logger, IShopLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _shopPlanes = new Dictionary();
+ }
+
+ ///
+ /// Загрузка списка изделий в магазине
+ ///
+ ///
+ ///
+ private void FormShop_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ _logger.LogInformation("Загрузка магазина");
+ try
+ {
+ var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value });
+ if (view != null)
+ {
+ textBoxName.Text = view.ShopName;
+ textBoxAddress.Text = view.Address;
+ dateTimePicker.Text = view.DateOpening.ToString();
+ _shopPlanes = view.ShopPlanes ?? new Dictionary();
+ LoadData();
+ }
+ }
+ 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,
+ ShopName = textBoxName.Text,
+ Address = textBoxAddress.Text,
+ DateOpening = dateTimePicker.Value.Date
+ };
+ 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();
+ }
+
+ ///
+ /// Метод загрузки изделий магазина
+ ///
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка изделий магазина");
+ try
+ {
+ if (_shopPlanes != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var elem in _shopPlanes)
+ {
+ dataGridView.Rows.Add(new object[]
+ {
+ elem.Key,
+ elem.Value.Item1.PlaneName,
+ elem.Value.Item2
+ });
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки изделий магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantView/FormShop.resx b/AircraftPlant/AircraftPlantView/FormShop.resx
new file mode 100644
index 0000000..cfbf3c9
--- /dev/null
+++ b/AircraftPlant/AircraftPlantView/FormShop.resx
@@ -0,0 +1,129 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ True
+
+
+ True
+
+
+ True
+
+
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlantView/FormShops.Designer.cs b/AircraftPlant/AircraftPlantView/FormShops.Designer.cs
new file mode 100644
index 0000000..31965d2
--- /dev/null
+++ b/AircraftPlant/AircraftPlantView/FormShops.Designer.cs
@@ -0,0 +1,122 @@
+namespace AircraftPlantView
+{
+ 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();
+ buttonAdd = new Button();
+ buttonUpdate = new Button();
+ buttonDelete = new Button();
+ buttonRefresh = new Button();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // dataGridView
+ //
+ dataGridView.AllowUserToAddRows = false;
+ dataGridView.AllowUserToDeleteRows = false;
+ dataGridView.BackgroundColor = Color.White;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Dock = DockStyle.Left;
+ dataGridView.GridColor = Color.White;
+ dataGridView.Location = new Point(0, 0);
+ dataGridView.MultiSelect = false;
+ dataGridView.Name = "dataGridView";
+ dataGridView.ReadOnly = true;
+ dataGridView.RowHeadersVisible = false;
+ dataGridView.RowTemplate.Height = 25;
+ dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridView.Size = new Size(450, 361);
+ dataGridView.TabIndex = 0;
+ //
+ // buttonAdd
+ //
+ buttonAdd.Location = new Point(480, 15);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(75, 23);
+ buttonAdd.TabIndex = 1;
+ buttonAdd.Text = "Добавить";
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += buttonAdd_Click;
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.Location = new Point(480, 44);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(75, 23);
+ buttonUpdate.TabIndex = 2;
+ buttonUpdate.Text = "Изменить";
+ buttonUpdate.UseVisualStyleBackColor = true;
+ buttonUpdate.Click += buttonUpdate_Click;
+ //
+ // buttonDelete
+ //
+ buttonDelete.Location = new Point(480, 73);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(75, 23);
+ buttonDelete.TabIndex = 3;
+ buttonDelete.Text = "Удалить";
+ buttonDelete.UseVisualStyleBackColor = true;
+ buttonDelete.Click += buttonDelete_Click;
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Location = new Point(480, 102);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(75, 23);
+ buttonRefresh.TabIndex = 4;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += buttonRefresh_Click;
+ //
+ // FormShops
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(584, 361);
+ Controls.Add(buttonRefresh);
+ Controls.Add(buttonDelete);
+ Controls.Add(buttonUpdate);
+ 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 buttonAdd;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonRefresh;
+ }
+}
\ No newline at end of file
diff --git a/AircraftPlant/AircraftPlantView/FormShops.cs b/AircraftPlant/AircraftPlantView/FormShops.cs
new file mode 100644
index 0000000..c23ed43
--- /dev/null
+++ b/AircraftPlant/AircraftPlantView/FormShops.cs
@@ -0,0 +1,153 @@
+using AircraftPlantContracts.BindingModels;
+using AircraftPlantContracts.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 AircraftPlantView
+{
+ ///
+ /// Форма для вывода всех магазинов
+ ///
+ 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 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 buttonUpdate_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShop));
+ if (service is FormShop form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+
+ ///
+ /// Кнопка "Удалить"
+ ///
+ ///
+ ///
+ private void 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);
+ }
+ }
+ }
+ }
+
+ ///
+ /// Кнопка "Обновить"
+ ///
+ ///
+ ///
+ private void buttonRefresh_Click(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["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["ShopPlanes"].Visible = false;
+ }
+ _logger.LogInformation("Загрузка магазинов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки магазинов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+}
diff --git a/AircraftPlant/AircraftPlantView/FormShops.resx b/AircraftPlant/AircraftPlantView/FormShops.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/AircraftPlant/AircraftPlantView/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
diff --git a/AircraftPlant/AircraftPlantView/Program.cs b/AircraftPlant/AircraftPlantView/Program.cs
index 90280e1..d0b5b40 100644
--- a/AircraftPlant/AircraftPlantView/Program.cs
+++ b/AircraftPlant/AircraftPlantView/Program.cs
@@ -49,10 +49,12 @@ namespace AircraftPlantView
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -61,6 +63,9 @@ namespace AircraftPlantView
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file