diff --git a/AircraftPlant/AbstractShopListImplement/DataListSingleton.cs b/AircraftPlant/AbstractShopListImplement/DataListSingleton.cs index 7754b68..d931deb 100644 --- a/AircraftPlant/AbstractShopListImplement/DataListSingleton.cs +++ b/AircraftPlant/AbstractShopListImplement/DataListSingleton.cs @@ -31,6 +31,10 @@ namespace AircraftPlantListImplement /// Список классов-моделей изделий /// public List Planes { get; set; } + /// + /// Список классов-моделей магазинов + /// + public List Shops { get; set; } /// /// Конструктор @@ -40,6 +44,7 @@ namespace AircraftPlantListImplement Components = new List(); Orders = new List(); Planes = new List(); + Shops = new List(); } /// /// Получить ссылку на класс diff --git a/AircraftPlant/AbstractShopListImplement/Shop.cs b/AircraftPlant/AbstractShopListImplement/Shop.cs new file mode 100644 index 0000000..5e3481e --- /dev/null +++ b/AircraftPlant/AbstractShopListImplement/Shop.cs @@ -0,0 +1,90 @@ +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/AbstractShopListImplement/ShopStorage.cs b/AircraftPlant/AbstractShopListImplement/ShopStorage.cs new file mode 100644 index 0000000..3d60ed6 --- /dev/null +++ b/AircraftPlant/AbstractShopListImplement/ShopStorage.cs @@ -0,0 +1,147 @@ +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/AircraftPlantBusinessLogic/OrderLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/OrderLogic.cs index f496482..eb94058 100644 --- a/AircraftPlant/AircraftPlantBusinessLogic/OrderLogic.cs +++ b/AircraftPlant/AircraftPlantBusinessLogic/OrderLogic.cs @@ -13,36 +13,15 @@ using System.Threading.Tasks; namespace AircraftPlantBusinessLogic.BusinessLogics { - /// - /// Реализация интерфейса бизнес-логики для заказов - /// public class OrderLogic : IOrderLogic { - /// - /// Логгер - /// private readonly ILogger _logger; - - /// - /// Взаимодействие с хранилищем заказов - /// private readonly IOrderStorage _orderStorage; - - /// - /// Конструктор - /// - /// - /// public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; _orderStorage = orderStorage; } - /// - /// Получение списка - /// - /// - /// public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. Order.Id:{ Id}", model?.Id); @@ -57,11 +36,6 @@ namespace AircraftPlantBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - /// - /// Создание заказа - /// - /// - /// public bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -80,38 +54,18 @@ namespace AircraftPlantBusinessLogic.BusinessLogics } return true; } - /// - /// Смена статуса заказа (Выполняется) - /// - /// - /// public bool TakeOrderInWork(OrderBindingModel model) { return StatusUpdate(model, OrderStatus.Выполняется); } - /// - /// Смена статуса заказа (Выдан) - /// - /// - /// public bool FinishOrder(OrderBindingModel model) { return StatusUpdate(model, OrderStatus.Выдан); } - /// - /// Смена статуса заказа (Готов) - /// - /// - /// public bool DeliveryOrder(OrderBindingModel model) { return StatusUpdate(model, OrderStatus.Готов); } - /// - /// Проверка модели заказа - /// - /// - /// private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) @@ -136,12 +90,6 @@ namespace AircraftPlantBusinessLogic.BusinessLogics } _logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. PlaneId: { PlaneId}", model.Id, model.Sum, model.PlaneId); } - /// - /// Смена статуса заказа - /// - /// - /// - /// private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) { var element = _orderStorage.GetElement(new OrderSearchModel diff --git a/AircraftPlant/AircraftPlantBusinessLogic/PlaneLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/PlaneLogic.cs index 1ee8908..f322f6e 100644 --- a/AircraftPlant/AircraftPlantBusinessLogic/PlaneLogic.cs +++ b/AircraftPlant/AircraftPlantBusinessLogic/PlaneLogic.cs @@ -12,36 +12,15 @@ using System.Threading.Tasks; namespace AircraftPlantBusinessLogic.BusinessLogics { - /// - /// Реализация интерфейса бизнес-логики для изделия - /// public class PlaneLogic : IPlaneLogic { - /// - /// Логгер - /// private readonly ILogger _logger; - - /// - /// Взаимодействие с хранилищем изделий - /// private readonly IPlaneStorage _planeStorage; - - /// - /// Конструктор - /// - /// - /// public PlaneLogic(ILogger logger, IPlaneStorage planeStorage) { _logger = logger; _planeStorage = planeStorage; } - /// - /// Получение списка - /// - /// - /// public List? ReadList(PlaneSearchModel? model) { _logger.LogInformation("ReadList. PlaneName:{PlaneName}.Id:{ Id}", model?.PlaneName, model?.Id); @@ -56,12 +35,6 @@ namespace AircraftPlantBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - /// - /// Получение отдельной записи - /// - /// - /// - /// public PlaneViewModel? ReadElement(PlaneSearchModel model) { if (model == null) @@ -81,11 +54,6 @@ namespace AircraftPlantBusinessLogic.BusinessLogics _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } - /// - /// Создание записи - /// - /// - /// public bool Create(PlaneBindingModel model) { CheckModel(model); @@ -97,11 +65,6 @@ namespace AircraftPlantBusinessLogic.BusinessLogics } return true; } - /// - /// Изменение записи - /// - /// - /// public bool Update(PlaneBindingModel model) { CheckModel(model); @@ -113,11 +76,6 @@ namespace AircraftPlantBusinessLogic.BusinessLogics } return true; } - /// - /// Удаление записи - /// - /// - /// public bool Delete(PlaneBindingModel model) { CheckModel(model, false); @@ -130,11 +88,6 @@ namespace AircraftPlantBusinessLogic.BusinessLogics } return true; } - /// - /// Проверка модели изделия - /// - /// - /// private void CheckModel(PlaneBindingModel model, bool withParams = true) { if (model == null) diff --git a/AircraftPlant/AircraftPlantBusinessLogic/ShopLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..f9db95b --- /dev/null +++ b/AircraftPlant/AircraftPlantBusinessLogic/ShopLogic.cs @@ -0,0 +1,157 @@ +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("Магазин с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantContracts»/BindingModels/ShopBindingModel.cs b/AircraftPlant/AircraftPlantContracts»/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..f371e22 --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/BindingModels/ShopBindingModel.cs @@ -0,0 +1,22 @@ +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..3c8ce2b --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantDataModels.Models; +using AircraftPlantContracts.SearchModels; +using AircraftPlantContracts.ViewModels; +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..836093b --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +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..47b0af4 --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +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..b65d879 --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/ViewModels/ShopViewModel.cs @@ -0,0 +1,26 @@ +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/IShopModel.cs b/AircraftPlant/AircraftPlantDataModels/IShopModel.cs new file mode 100644 index 0000000..43e1362 --- /dev/null +++ b/AircraftPlant/AircraftPlantDataModels/IShopModel.cs @@ -0,0 +1,16 @@ +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/AircraftPlantView/FormMain.Designer.cs b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs index 5fec25f..e9b4f04 100644 --- a/AircraftPlant/AircraftPlantView/FormMain.Designer.cs +++ b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs @@ -38,6 +38,7 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -124,7 +125,8 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, - this.изделияToolStripMenuItem}); + this.изделияToolStripMenuItem, + this.магазиныToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -132,17 +134,23 @@ // компонентыToolStripMenuItem // this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // // изделияToolStripMenuItem // this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.изделияToolStripMenuItem.Text = "Изделия"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.магазиныToolStripMenuItem.Text = "Магазины"; + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -179,5 +187,6 @@ private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem изделияToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; } } \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormShop.Designer.cs b/AircraftPlant/AircraftPlantView/FormShop.Designer.cs new file mode 100644 index 0000000..d741c4d --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormShop.Designer.cs @@ -0,0 +1,173 @@ +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() + { + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.Plane = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(62, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 39); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(43, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Адрес:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 74); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(90, 15); + this.label3.TabIndex = 2; + this.label3.Text = "Дата открытия:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(116, 6); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(200, 23); + this.textBoxName.TabIndex = 3; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(116, 39); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(200, 23); + this.textBoxAddress.TabIndex = 4; + // + // dateTimePicker + // + this.dateTimePicker.Location = new System.Drawing.Point(116, 74); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(200, 23); + this.dateTimePicker.TabIndex = 5; + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Plane, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(26, 118); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(446, 325); + this.dataGridView.TabIndex = 6; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(316, 444); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(397, 444); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 8; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // Plane + // + this.Plane.HeaderText = "Изделие"; + this.Plane.Name = "Plane"; + this.Plane.Width = 300; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.Name = "Count"; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(481, 470); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.dateTimePicker); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private TextBox textBoxName; + private TextBox textBoxAddress; + private DateTimePicker dateTimePicker; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Plane; + private DataGridViewTextBoxColumn Count; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormShop.cs b/AircraftPlant/AircraftPlantView/FormShop.cs new file mode 100644 index 0000000..0c74932 --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormShop.cs @@ -0,0 +1,163 @@ +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, + ShopPlanes = _shopPlanes + }; + 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..05b9989 --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormShop.resx @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormSupply.Designer.cs b/AircraftPlant/AircraftPlantView/FormSupply.Designer.cs new file mode 100644 index 0000000..c24306a --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormSupply.Designer.cs @@ -0,0 +1,145 @@ +namespace AircraftPlantView +{ + partial class FormSupply + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelShop = new System.Windows.Forms.Label(); + this.labelPlane = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.comboBoxPlane = new System.Windows.Forms.ComboBox(); + this.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); + this.SuspendLayout(); + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(12, 9); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(57, 15); + this.labelShop.TabIndex = 0; + this.labelShop.Text = "Магазин:"; + // + // labelPlane + // + this.labelPlane.AutoSize = true; + this.labelPlane.Location = new System.Drawing.Point(12, 44); + this.labelPlane.Name = "labelPlane"; + this.labelPlane.Size = new System.Drawing.Size(56, 15); + this.labelPlane.TabIndex = 1; + this.labelPlane.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 81); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество:"; + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(97, 9); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(229, 23); + this.comboBoxShop.TabIndex = 3; + // + // comboBoxPlane + // + this.comboBoxPlane.FormattingEnabled = true; + this.comboBoxPlane.Location = new System.Drawing.Point(97, 44); + this.comboBoxPlane.Name = "comboBoxPlane"; + this.comboBoxPlane.Size = new System.Drawing.Size(229, 23); + this.comboBoxPlane.TabIndex = 4; + // + // numericUpDownCount + // + this.numericUpDownCount.Location = new System.Drawing.Point(98, 79); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.Size = new System.Drawing.Size(228, 23); + this.numericUpDownCount.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(170, 108); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(251, 108); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormSupply + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(341, 140); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.numericUpDownCount); + this.Controls.Add(this.comboBoxPlane); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelPlane); + this.Controls.Add(this.labelShop); + this.Name = "FormSupply"; + this.Text = "Поступление"; + this.Load += new System.EventHandler(this.FormSupply_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelShop; + private Label labelPlane; + private Label labelCount; + private ComboBox comboBoxShop; + private ComboBox comboBoxPlane; + private NumericUpDown numericUpDownCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormSupply.cs b/AircraftPlant/AircraftPlantView/FormSupply.cs new file mode 100644 index 0000000..069f9c8 --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormSupply.cs @@ -0,0 +1,145 @@ +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 FormSupply : Form + { + private readonly ILogger _logger; + /// + /// Бизнес-логика для магазина + /// + private readonly IShopLogic _logicS; + /// + /// Бизнес-логика для изделий + /// + private readonly IPlaneLogic _logicP; + /// + /// Конструктор + /// + /// + /// + /// + public FormSupply(ILogger logger, IShopLogic logicS, IPlaneLogic logicP) + { + InitializeComponent(); + _logger = logger; + _logicS = logicS; + _logicP = logicP; + } + /// + /// Загрузка списиков магазинов и изделий + /// + /// + /// + private void FormSupply_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/FormSupply.resx b/AircraftPlant/AircraftPlantView/FormSupply.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormSupply.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file