diff --git a/CarpentryWorkshop/CarpentryWorkshop.sln b/CarpentryWorkshop/CarpentryWorkshop.sln index ae434c1..ce305a2 100644 --- a/CarpentryWorkshop/CarpentryWorkshop.sln +++ b/CarpentryWorkshop/CarpentryWorkshop.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarpentryWorkshopView", "CarpentryWorkshopView\CarpentryWorkshopView.csproj", "{43AFB0D7-3079-4A9D-9281-C7021D27E058}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarpentryWorkshopView", "CarpentryWorkshopView\CarpentryWorkshopView.csproj", "{43AFB0D7-3079-4A9D-9281-C7021D27E058}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarpentryWorkshopDataModels", "CarpentryWorkshopDataModels\CarpentryWorkshopDataModels.csproj", "{3E2B6F30-00E0-4593-9A0C-86E949FDEBFB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarpentryWorkshopContracts", "CarpentryWorkshopContracts\CarpentryWorkshopContracts.csproj", "{B9C39E74-DD6C-4503-B85C-2960E3DDA8AF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarpentryWorkshopListImplement", "CarpentryWorkshopListImplement\CarpentryWorkshopListImplement.csproj", "{F42723D6-5F7E-4956-B2F2-50353AF6D9BF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarpentryWorkshopBusinessLogic", "CarpentryWorkshopBusinessLogic\CarpentryWorkshopBusinessLogic.csproj", "{D550ED8D-31C0-42D2-A129-5BB96EDEBF3F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {43AFB0D7-3079-4A9D-9281-C7021D27E058}.Debug|Any CPU.Build.0 = Debug|Any CPU {43AFB0D7-3079-4A9D-9281-C7021D27E058}.Release|Any CPU.ActiveCfg = Release|Any CPU {43AFB0D7-3079-4A9D-9281-C7021D27E058}.Release|Any CPU.Build.0 = Release|Any CPU + {3E2B6F30-00E0-4593-9A0C-86E949FDEBFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E2B6F30-00E0-4593-9A0C-86E949FDEBFB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E2B6F30-00E0-4593-9A0C-86E949FDEBFB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E2B6F30-00E0-4593-9A0C-86E949FDEBFB}.Release|Any CPU.Build.0 = Release|Any CPU + {B9C39E74-DD6C-4503-B85C-2960E3DDA8AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B9C39E74-DD6C-4503-B85C-2960E3DDA8AF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B9C39E74-DD6C-4503-B85C-2960E3DDA8AF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B9C39E74-DD6C-4503-B85C-2960E3DDA8AF}.Release|Any CPU.Build.0 = Release|Any CPU + {F42723D6-5F7E-4956-B2F2-50353AF6D9BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F42723D6-5F7E-4956-B2F2-50353AF6D9BF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F42723D6-5F7E-4956-B2F2-50353AF6D9BF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F42723D6-5F7E-4956-B2F2-50353AF6D9BF}.Release|Any CPU.Build.0 = Release|Any CPU + {D550ED8D-31C0-42D2-A129-5BB96EDEBF3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D550ED8D-31C0-42D2-A129-5BB96EDEBF3F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D550ED8D-31C0-42D2-A129-5BB96EDEBF3F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D550ED8D-31C0-42D2-A129-5BB96EDEBF3F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..40c0155 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,114 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage + componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{Id}", model.ComponentName, model.Id); + var element = _componentStorage.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(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{Cost}. Id: {Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..6bd03d8 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,129 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + if (model.Status + 1 != newStatus) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + + model.Status = newStatus; + + if (model.Status == OrderStatus.Выдан) + model.DateImplement = DateTime.Now; + + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Order. OrderId:{Id}", model?.Id); + + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (model.WoodId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.WoodId)); + } + + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + + _logger.LogInformation("Order. OrderId:{Id}.Sum:{Sum}. WoodId: {WoodId}", model.Id, model.Sum, model.WoodId); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/WoodLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/WoodLogic.cs new file mode 100644 index 0000000..2d4e5fc --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/WoodLogic.cs @@ -0,0 +1,141 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopListImplement.Implements; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopBusinessLogic.BusinessLogics +{ + public class WoodLogic : IWoodLogic + { + private readonly ILogger _logger; + + private readonly IWoodStorage _woodStorage; + + public WoodLogic(ILogger logger, IWoodStorage woodStorage) + { + _logger = logger; + _woodStorage = woodStorage; + } + + public bool Create(WoodBindingModel model) + { + CheckModel(model); + + if (_woodStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + public bool Delete(WoodBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_woodStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + public WoodViewModel? ReadElement(WoodSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. WoodName:{WoodName}.Id:{Id}", model.WoodName, model.Id); + + var element = _woodStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + + public List? ReadList(WoodSearchModel? model) + { + _logger.LogInformation("ReadList. WoodName:{WoodName}.Id:{Id}", model?.WoodName, model?.Id); + + var list = model == null ? _woodStorage.GetFullList() : _woodStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + public bool Update(WoodBindingModel model) + { + CheckModel(model); + + if (_woodStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + private void CheckModel(WoodBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.WoodName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.WoodName)); + } + + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + + _logger.LogInformation("Wood. WoodName:{WoodName}.Price:{ Cost}. Id: {Id}", model.WoodName, model.Price, model.Id); + + var element = _woodStorage.GetElement(new WoodSearchModel + { + WoodName = model.WoodName + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/CarpentryWorkshopBusinessLogic.csproj b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/CarpentryWorkshopBusinessLogic.csproj new file mode 100644 index 0000000..89deb36 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/CarpentryWorkshopBusinessLogic.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ComponentBindingModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..3097d91 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,17 @@ +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..c44a424 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using CarpentryWorkshopDataModels.Enums; +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int WoodId { get; set; } + public string WoodName { get; set; } = string.Empty; + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/WoodBindingModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/WoodBindingModel.cs new file mode 100644 index 0000000..328fdbd --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/WoodBindingModel.cs @@ -0,0 +1,18 @@ +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.BindingModels +{ + public class WoodBindingModel : IWoodModel + { + public int Id { get; set; } + public string WoodName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary WoodComponents { get; set; } = new(); + + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..e4bd2c2 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..8ce823b --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IWoodLogic.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IWoodLogic.cs new file mode 100644 index 0000000..cd8851c --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IWoodLogic.cs @@ -0,0 +1,20 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.BusinessLogicsContracts +{ + public interface IWoodLogic + { + List? ReadList(WoodSearchModel? model); + WoodViewModel? ReadElement(WoodSearchModel model); + bool Create(WoodBindingModel model); + bool Update(WoodBindingModel model); + bool Delete(WoodBindingModel model); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/CarpentryWorkshopContracts.csproj b/CarpentryWorkshop/CarpentryWorkshopContracts/CarpentryWorkshopContracts.csproj new file mode 100644 index 0000000..6ef3d42 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/CarpentryWorkshopContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ComponentSearchModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..d9e1fe0 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/OrderSearchModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..3742a76 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/WoodSearchModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/WoodSearchModel.cs new file mode 100644 index 0000000..e1a1a65 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/WoodSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.SearchModels +{ + public class WoodSearchModel + { + public int? Id { get; set; } + public string? WoodName { get; set; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IComponentStorage.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..376e749 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IOrderStorage.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..46f834e --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IWoodStorage.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IWoodStorage.cs new file mode 100644 index 0000000..e1b6b93 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IWoodStorage.cs @@ -0,0 +1,22 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.StoragesContracts +{ + public interface IWoodStorage + { + List GetFullList(); + List GetFilteredList(WoodSearchModel model); + WoodViewModel? GetElement(WoodSearchModel model); + WoodViewModel? Insert(WoodBindingModel model); + WoodViewModel? Update(WoodBindingModel model); + WoodViewModel? Delete(WoodBindingModel model); + + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..31f15c0 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,19 @@ +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..c0f6467 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using CarpentryWorkshopDataModels.Enums; +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + public int WoodId { get; set; } + [DisplayName("Номер")] + public int Id { get; set; } + [DisplayName("Изделие")] + public string WoodName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/WoodViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/WoodViewModel.cs new file mode 100644 index 0000000..3960f0c --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/WoodViewModel.cs @@ -0,0 +1,20 @@ +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.ViewModels +{ + public class WoodViewModel : IWoodModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string WoodName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary WoodComponents { get; set; } = new(); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/CarpentryWorkshopDataModels.csproj b/CarpentryWorkshop/CarpentryWorkshopDataModels/CarpentryWorkshopDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/CarpentryWorkshopDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/Enums/OrderStatus.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..a28b4c6 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Enums/OrderStatus.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + + Принят = 0, + + Выполняется = 1, + + Готов = 2, + + Выдан = 3 + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/IId.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/IId.cs new file mode 100644 index 0000000..0abec29 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IComponentModel.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..3d73c34 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IOrderModel.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..bf9999f --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using CarpentryWorkshopDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopDataModels.Models +{ + public interface IOrderModel : IId + { + int WoodId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IWoodModel.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IWoodModel.cs new file mode 100644 index 0000000..62833c2 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IWoodModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopDataModels.Models +{ + public interface IWoodModel : IId + { + string WoodName { get; } + double Price { get; } + Dictionary WoodComponents { get; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/CarpentryWorkshopListImplement.csproj b/CarpentryWorkshop/CarpentryWorkshopListImplement/CarpentryWorkshopListImplement.csproj new file mode 100644 index 0000000..319d159 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/CarpentryWorkshopListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..0a14a86 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using CarpentryWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Woods { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Woods = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ComponentStorage.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..ac8f76c --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,110 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..c13be12 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,138 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return WoodStorage(element.GetViewModel); + } + } + + return null; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return WoodStorage(order.GetViewModel); + } + } + + return null; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + + if (!model.Id.HasValue) + { + return result; + } + + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + result.Add(WoodStorage(order.GetViewModel)); + } + } + + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var order in _source.Orders) + { + result.Add(WoodStorage(order.GetViewModel)); + } + + return result; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + + _source.Orders.Add(newOrder); + + return WoodStorage(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return WoodStorage(order.GetViewModel); + } + } + + return null; + } + + public OrderViewModel WoodStorage(OrderViewModel model) + { + foreach (var wood in _source.Woods) + { + if (wood.Id == model.WoodId) + { + model.WoodName = wood.WoodName; + break; + } + } + return model; + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/WoodStorage.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/WoodStorage.cs new file mode 100644 index 0000000..b642c21 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/WoodStorage.cs @@ -0,0 +1,126 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopListImplement.Implements +{ + public class WoodStorage : IWoodStorage + { + private readonly DataListSingleton _source; + + public WoodStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public WoodViewModel? Delete(WoodBindingModel model) + { + for (int i = 0; i < _source.Woods.Count; ++i) + { + if (_source.Woods[i].Id == model.Id) + { + var element = _source.Woods[i]; + _source.Woods.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + + public WoodViewModel? GetElement(WoodSearchModel model) + { + if (string.IsNullOrEmpty(model.WoodName) && !model.Id.HasValue) + { + return null; + } + + foreach (var wood in _source.Woods) + { + if ((!string.IsNullOrEmpty(model.WoodName) && wood.WoodName == model.WoodName) || (model.Id.HasValue && wood.Id == model.Id)) + { + return wood.GetViewModel; + } + } + + return null; + } + + public List GetFilteredList(WoodSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.WoodName)) + { + return result; + } + + foreach (var wood in _source.Woods) + { + if (wood.WoodName.Contains(model.WoodName)) + { + result.Add(wood.GetViewModel); + } + } + + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var wood in _source.Woods) + { + result.Add(wood.GetViewModel); + } + + return result; + } + + public WoodViewModel? Insert(WoodBindingModel model) + { + model.Id = 1; + + foreach (var wood in _source.Woods) + { + if (model.Id <= wood.Id) + { + model.Id = wood.Id + 1; + } + } + + var newWood = Wood.Create(model); + + if (newWood == null) + { + return null; + } + + _source.Woods.Add(newWood); + + return newWood.GetViewModel; + } + + public WoodViewModel? Update(WoodBindingModel model) + { + foreach (var wood in _source.Woods) + { + if (wood.Id == model.Id) + { + wood.Update(model); + return wood.GetViewModel; + } + } + + return null; + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Component.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Component.cs new file mode 100644 index 0000000..4f08148 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Component.cs @@ -0,0 +1,48 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs new file mode 100644 index 0000000..bd978ef --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs @@ -0,0 +1,63 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Enums; +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int WoodId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + WoodId = model.WoodId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + WoodId = WoodId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Wood.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Wood.cs new file mode 100644 index 0000000..fc1dac9 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Wood.cs @@ -0,0 +1,52 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopListImplement.Models +{ + public class Wood : IWoodModel + { + public int Id { get; private set; } + public string WoodName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary WoodComponents { get; private set; } = new Dictionary(); + + public static Wood? Create(WoodBindingModel? model) + { + if (model == null) + { + return null; + } + return new Wood() + { + Id = model.Id, + WoodName = model.WoodName, + Price = model.Price, + WoodComponents = model.WoodComponents + }; + } + + public void Update(WoodBindingModel? model) + { + if (model == null) + { + return; + } + WoodName = model.WoodName; + Price = model.Price; + WoodComponents = model.WoodComponents; + } + public WoodViewModel GetViewModel => new() + { + Id = Id, + WoodName = WoodName, + Price = Price, + WoodComponents = WoodComponents + }; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/CarpentryWorkshopView.csproj b/CarpentryWorkshop/CarpentryWorkshopView/CarpentryWorkshopView.csproj index b57c89e..3db30dd 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/CarpentryWorkshopView.csproj +++ b/CarpentryWorkshop/CarpentryWorkshopView/CarpentryWorkshopView.csproj @@ -8,4 +8,27 @@ enable + + + + + + + Always + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/Form1.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/Form1.Designer.cs deleted file mode 100644 index 2b36df0..0000000 --- a/CarpentryWorkshop/CarpentryWorkshopView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace CarpentryWorkshopView -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/Form1.cs b/CarpentryWorkshop/CarpentryWorkshopView/Form1.cs deleted file mode 100644 index c1ed671..0000000 --- a/CarpentryWorkshop/CarpentryWorkshopView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace CarpentryWorkshopView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormComponent.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormComponent.Designer.cs new file mode 100644 index 0000000..5fee8c1 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace CarpentryWorkshopView +{ + partial class FormComponent + { + /// + /// 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.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(86, 25); + this.label1.TabIndex = 0; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label2.Location = new System.Drawing.Point(12, 48); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(55, 26); + this.label2.TabIndex = 1; + this.label2.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(104, 9); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(302, 23); + this.textBoxName.TabIndex = 2; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(104, 51); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(144, 23); + this.textBoxCost.TabIndex = 3; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(172, 99); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(114, 39); + this.ButtonSave.TabIndex = 4; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(292, 99); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(114, 39); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(418, 154); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormComponent.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormComponent.cs new file mode 100644 index 0000000..f74186f --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormComponent.cs @@ -0,0 +1,93 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.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 CarpentryWorkshopView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + 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; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormComponent.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormComponent.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 diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormComponents.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormComponents.Designer.cs new file mode 100644 index 0000000..4f237a9 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormComponents.Designer.cs @@ -0,0 +1,121 @@ +namespace CarpentryWorkshopView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(569, 450); + this.dataGridView.TabIndex = 0; + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(615, 23); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(158, 53); + this.ButtonAdd.TabIndex = 1; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(615, 99); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(158, 53); + this.ButtonUpd.TabIndex = 2; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(615, 176); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(158, 53); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(615, 264); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(158, 53); + this.ButtonRef.TabIndex = 4; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonUpd); + this.Controls.Add(this.ButtonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonAdd; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonRef; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormComponents.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormComponents.cs new file mode 100644 index 0000000..442cc42 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormComponents.cs @@ -0,0 +1,111 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.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 CarpentryWorkshopView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_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 ComponentBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormComponents.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormComponents.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 diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormCreateOrder.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..ab8e97d --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormCreateOrder.Designer.cs @@ -0,0 +1,149 @@ +namespace CarpentryWorkshopView +{ + partial class FormCreateOrder + { + /// + /// 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.comboBoxWood = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label1.Location = new System.Drawing.Point(20, 17); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(74, 21); + this.label1.TabIndex = 0; + this.label1.Text = "Изделие:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label2.Location = new System.Drawing.Point(20, 52); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(96, 21); + this.label2.TabIndex = 1; + this.label2.Text = "Количество:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label3.Location = new System.Drawing.Point(20, 90); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(61, 21); + this.label3.TabIndex = 2; + this.label3.Text = "Сумма:"; + // + // comboBoxWood + // + this.comboBoxWood.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxWood.FormattingEnabled = true; + this.comboBoxWood.Location = new System.Drawing.Point(127, 19); + this.comboBoxWood.Name = "comboBoxWood"; + this.comboBoxWood.Size = new System.Drawing.Size(278, 23); + this.comboBoxWood.TabIndex = 3; + this.comboBoxWood.SelectedIndexChanged += new System.EventHandler(this.comboBoxWood_SelectedIndexChanged); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(127, 54); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(278, 23); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.BackColor = System.Drawing.SystemColors.Control; + this.textBoxSum.Location = new System.Drawing.Point(127, 92); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(278, 23); + this.textBoxSum.TabIndex = 5; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(157, 135); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(109, 39); + 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(282, 135); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(109, 39); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(458, 213); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxWood); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private ComboBox comboBoxWood; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormCreateOrder.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormCreateOrder.cs new file mode 100644 index 0000000..5d07a52 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormCreateOrder.cs @@ -0,0 +1,132 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.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 CarpentryWorkshopView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + + private readonly IWoodLogic _logicW; + + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IWoodLogic logicW, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicW = logicW; + _logicO = logicO; + LoadData(); + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий для заказа"); + + try + { + var list = _logicW.ReadList(null); + if (list != null) + { + comboBoxWood.DisplayMember = "WoodName"; + comboBoxWood.ValueMember = "Id"; + comboBoxWood.DataSource = list; + comboBoxWood.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CalcSum() + { + if (comboBoxWood.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxWood.SelectedValue); + var product = _logicW.ReadElement(new WoodSearchModel { Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void textBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void comboBoxWood_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxWood.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + WoodId = Convert.ToInt32(comboBoxWood.SelectedValue), + WoodName = comboBoxWood.Text, + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormCreateOrder.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormCreateOrder.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 diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs new file mode 100644 index 0000000..7d8ce28 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs @@ -0,0 +1,187 @@ +namespace CarpentryWorkshopView +{ + partial class FormMain + { + /// + /// 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.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonCreateOrder = new System.Windows.Forms.Button(); + this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); + this.ButtonOrderReady = new System.Windows.Forms.Button(); + this.ButtonIssuedOrder = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1389, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.компонентыToolStripMenuItem, + this.изделияToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 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.Text = "Изделия"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.изделияToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 27); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(1158, 423); + this.dataGridView.TabIndex = 1; + // + // ButtonCreateOrder + // + this.ButtonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonCreateOrder.Location = new System.Drawing.Point(1177, 44); + this.ButtonCreateOrder.Name = "ButtonCreateOrder"; + this.ButtonCreateOrder.Size = new System.Drawing.Size(199, 40); + this.ButtonCreateOrder.TabIndex = 2; + this.ButtonCreateOrder.Text = "Создать заказ"; + this.ButtonCreateOrder.UseVisualStyleBackColor = true; + this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // ButtonTakeOrderInWork + // + this.ButtonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(1177, 121); + this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(199, 40); + this.ButtonTakeOrderInWork.TabIndex = 3; + this.ButtonTakeOrderInWork.Text = "Отдать на выполнение"; + this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // ButtonOrderReady + // + this.ButtonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonOrderReady.Location = new System.Drawing.Point(1177, 206); + this.ButtonOrderReady.Name = "ButtonOrderReady"; + this.ButtonOrderReady.Size = new System.Drawing.Size(199, 40); + this.ButtonOrderReady.TabIndex = 4; + this.ButtonOrderReady.Text = "Заказ готов"; + this.ButtonOrderReady.UseVisualStyleBackColor = true; + this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // ButtonIssuedOrder + // + this.ButtonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonIssuedOrder.Location = new System.Drawing.Point(1177, 292); + this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + this.ButtonIssuedOrder.Size = new System.Drawing.Size(199, 40); + this.ButtonIssuedOrder.TabIndex = 5; + this.ButtonIssuedOrder.Text = "Заказ выдан"; + this.ButtonIssuedOrder.UseVisualStyleBackColor = true; + this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // ButtonRef + // + this.ButtonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonRef.Location = new System.Drawing.Point(1177, 379); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(199, 40); + this.ButtonRef.TabIndex = 6; + this.ButtonRef.Text = "Обновить список"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1389, 450); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonIssuedOrder); + this.Controls.Add(this.ButtonOrderReady); + this.Controls.Add(this.ButtonTakeOrderInWork); + this.Controls.Add(this.ButtonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Столярная мастерская"; + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private DataGridView dataGridView; + private Button ButtonCreateOrder; + private Button ButtonTakeOrderInWork; + private Button ButtonOrderReady; + private Button ButtonIssuedOrder; + private Button ButtonRef; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs new file mode 100644 index 0000000..71ddb64 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs @@ -0,0 +1,175 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopDataModels.Enums; +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 CarpentryWorkshopView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + + try + { + var list = _orderLogic.ReadList(null); + + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["WoodId"].Visible = false; + } + + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void изделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWoods)); + + if (service is FormWoods form) + { + form.ShowDialog(); + } + } + + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id, + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id, + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormWood.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormWood.Designer.cs new file mode 100644 index 0000000..a1a566f --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWood.Designer.cs @@ -0,0 +1,237 @@ +namespace CarpentryWorkshopView +{ + partial class FormWood + { + /// + /// 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.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label1.Location = new System.Drawing.Point(15, 21); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(91, 28); + this.label1.TabIndex = 0; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label2.Location = new System.Drawing.Point(15, 60); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(91, 26); + this.label2.TabIndex = 1; + this.label2.Text = "Стоимость:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(110, 23); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(400, 23); + this.textBoxName.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Enabled = false; + this.textBoxPrice.Location = new System.Drawing.Point(110, 62); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(259, 23); + this.textBoxPrice.TabIndex = 3; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.ButtonRef); + this.groupBox1.Controls.Add(this.ButtonDel); + this.groupBox1.Controls.Add(this.ButtonUpd); + this.groupBox1.Controls.Add(this.ButtonAdd); + this.groupBox1.Controls.Add(this.dataGridView); + this.groupBox1.Location = new System.Drawing.Point(15, 91); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(769, 364); + this.groupBox1.TabIndex = 4; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Компоненты"; + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(622, 180); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(129, 36); + this.ButtonRef.TabIndex = 4; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(622, 126); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(129, 36); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(622, 73); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(129, 36); + this.ButtonUpd.TabIndex = 2; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(622, 22); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(129, 36); + this.ButtonAdd.TabIndex = 1; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnId, + this.ColumnName, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(0, 14); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(600, 350); + this.dataGridView.TabIndex = 0; + // + // ColumnId + // + this.ColumnId.HeaderText = "Id"; + this.ColumnId.Name = "ColumnId"; + this.ColumnId.ReadOnly = true; + this.ColumnId.Visible = false; + // + // ColumnName + // + this.ColumnName.HeaderText = "Компонент"; + this.ColumnName.Name = "ColumnName"; + this.ColumnName.ReadOnly = true; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.ReadOnly = true; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(471, 469); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(121, 41); + this.ButtonSave.TabIndex = 5; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(618, 469); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(121, 41); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormWood + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 534); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormWood"; + this.Text = "Изделие"; + this.Load += new System.EventHandler(this.FormWood_Load); + this.groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBox1; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + private Button ButtonRef; + private Button ButtonDel; + private Button ButtonUpd; + private Button ButtonAdd; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormWood.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormWood.cs new file mode 100644 index 0000000..9213665 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWood.cs @@ -0,0 +1,216 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopDataModels.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 CarpentryWorkshopView +{ + public partial class FormWood : Form + { + private readonly ILogger _logger; + private readonly IWoodLogic _logic; + private int? _id; + + private Dictionary _woodComponents; + + public int Id { set { _id = value; } } + public FormWood(ILogger logger, IWoodLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _woodComponents = new Dictionary(); + } + private void FormWood_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new WoodSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.WoodName; + textBoxPrice.Text = view.Price.ToString(); + _woodComponents = view.WoodComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_woodComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _woodComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWoodComponent)); + if (service is FormWoodComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + if (_woodComponents.ContainsKey(form.Id)) + { + _woodComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _woodComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWoodComponent)); + if (service is FormWoodComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _woodComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + _woodComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _woodComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_woodComponents == null || _woodComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new WoodBindingModel + { + Id = _id ?? 0, + WoodName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + WoodComponents = _woodComponents + }; + 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 double CalcPrice() + { + double price = 0; + foreach (var elem in _woodComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormWood.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormWood.resx new file mode 100644 index 0000000..72380a4 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWood.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/CarpentryWorkshop/CarpentryWorkshopView/FormWoodComponent.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormWoodComponent.Designer.cs new file mode 100644 index 0000000..a8b68cc --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWoodComponent.Designer.cs @@ -0,0 +1,120 @@ +namespace CarpentryWorkshopView +{ + partial class FormWoodComponent + { + /// + /// 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.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label1.Location = new System.Drawing.Point(17, 18); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(96, 25); + this.label1.TabIndex = 0; + this.label1.Text = "Компонент:"; + // + // label2 + // + this.label2.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label2.Location = new System.Drawing.Point(17, 59); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(102, 30); + this.label2.TabIndex = 1; + this.label2.Text = "Количество:"; + // + // comboBoxComponent + // + this.comboBoxComponent.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(119, 18); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(320, 23); + this.comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(119, 59); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(320, 23); + this.textBoxCount.TabIndex = 3; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(183, 106); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(111, 34); + this.ButtonSave.TabIndex = 4; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(300, 106); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(111, 34); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormWoodComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(501, 170); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormWoodComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormWoodComponent.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormWoodComponent.cs new file mode 100644 index 0000000..bd835aa --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWoodComponent.cs @@ -0,0 +1,77 @@ +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CarpentryWorkshopView +{ + public partial class FormWoodComponent : Form + { + private readonly List? _list; + public int Id { get { return Convert.ToInt32(comboBoxComponent.SelectedValue); } set { comboBoxComponent.SelectedValue = value; } } + + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + + public int Count { get { return Convert.ToInt32(textBoxCount.Text); } set { textBoxCount.Text = value.ToString(); } } + + public FormWoodComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormWoodComponent.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormWoodComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWoodComponent.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 diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormWoods.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormWoods.Designer.cs new file mode 100644 index 0000000..0382e87 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWoods.Designer.cs @@ -0,0 +1,122 @@ +namespace CarpentryWorkshopView +{ + partial class FormWoods + { + /// + /// 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.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(636, 25); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(136, 44); + this.ButtonAdd.TabIndex = 0; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(636, 96); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(136, 44); + this.ButtonUpd.TabIndex = 1; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(636, 168); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(136, 44); + this.ButtonDel.TabIndex = 2; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(636, 240); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(136, 44); + this.ButtonRef.TabIndex = 3; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(601, 450); + this.dataGridView.TabIndex = 4; + // + // FormWoods + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonUpd); + this.Controls.Add(this.ButtonAdd); + this.Name = "FormWoods"; + this.Text = "Изделия"; + this.Load += new System.EventHandler(this.FormWoods_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button ButtonAdd; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonRef; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormWoods.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormWoods.cs new file mode 100644 index 0000000..6127444 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWoods.cs @@ -0,0 +1,111 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.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 CarpentryWorkshopView +{ + public partial class FormWoods : Form + { + private readonly ILogger _logger; + private readonly IWoodLogic _logic; + public FormWoods(ILogger logger, IWoodLogic logic) + { + InitializeComponent(); + _logic = logic; + _logger = logger; + } + + private void FormWoods_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["WoodComponents"].Visible = false; + dataGridView.Columns["WoodName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка изделий"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWood)); + if (service is FormWood form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWood)); + if (service is FormWood form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_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 WoodBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Доп информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormWoods.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormWoods.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormWoods.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 diff --git a/CarpentryWorkshop/CarpentryWorkshopView/Program.cs b/CarpentryWorkshop/CarpentryWorkshopView/Program.cs index 3148d7b..435a020 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/Program.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/Program.cs @@ -1,7 +1,18 @@ +using CarpentryWorkshopBusinessLogic.BusinessLogics; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System; + namespace CarpentryWorkshopView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +22,31 @@ namespace CarpentryWorkshopView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/nlog.config b/CarpentryWorkshop/CarpentryWorkshopView/nlog.config new file mode 100644 index 0000000..1c300a9 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file