diff --git a/Confectionery/Confectionery.sln b/Confectionery/Confectionery.sln index 8f853ab..52d0699 100644 --- a/Confectionery/Confectionery.sln +++ b/Confectionery/Confectionery.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.32112.339 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Confectionery", "Confectionery\Confectionery.csproj", "{B900135E-8594-4AEA-B074-93DECD74C8DE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryDataModels", "ConfectioneryDataModels\ConfectioneryDataModels.csproj", "{D7A8174D-1B45-4463-A4D7-C82CA529EE4D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryContracts", "ConfectioneryContracts\ConfectioneryContracts.csproj", "{C151D91F-BDB0-46AD-8573-3F6174E9E76A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryView", "ConfectioneryView\ConfectioneryView.csproj", "{B222E04E-D0E7-49F4-8747-426125645B93}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{40859695-0BD6-49A8-8997-AD76F6984144}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{8B6BFE3A-CA63-4FCB-B7AC-DB3F28E0F7A7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,10 +19,26 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B900135E-8594-4AEA-B074-93DECD74C8DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B900135E-8594-4AEA-B074-93DECD74C8DE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B900135E-8594-4AEA-B074-93DECD74C8DE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B900135E-8594-4AEA-B074-93DECD74C8DE}.Release|Any CPU.Build.0 = Release|Any CPU + {D7A8174D-1B45-4463-A4D7-C82CA529EE4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D7A8174D-1B45-4463-A4D7-C82CA529EE4D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D7A8174D-1B45-4463-A4D7-C82CA529EE4D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D7A8174D-1B45-4463-A4D7-C82CA529EE4D}.Release|Any CPU.Build.0 = Release|Any CPU + {C151D91F-BDB0-46AD-8573-3F6174E9E76A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C151D91F-BDB0-46AD-8573-3F6174E9E76A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C151D91F-BDB0-46AD-8573-3F6174E9E76A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C151D91F-BDB0-46AD-8573-3F6174E9E76A}.Release|Any CPU.Build.0 = Release|Any CPU + {B222E04E-D0E7-49F4-8747-426125645B93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B222E04E-D0E7-49F4-8747-426125645B93}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B222E04E-D0E7-49F4-8747-426125645B93}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B222E04E-D0E7-49F4-8747-426125645B93}.Release|Any CPU.Build.0 = Release|Any CPU + {40859695-0BD6-49A8-8997-AD76F6984144}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40859695-0BD6-49A8-8997-AD76F6984144}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40859695-0BD6-49A8-8997-AD76F6984144}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40859695-0BD6-49A8-8997-AD76F6984144}.Release|Any CPU.Build.0 = Release|Any CPU + {8B6BFE3A-CA63-4FCB-B7AC-DB3F28E0F7A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8B6BFE3A-CA63-4FCB-B7AC-DB3F28E0F7A7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8B6BFE3A-CA63-4FCB-B7AC-DB3F28E0F7A7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8B6BFE3A-CA63-4FCB-B7AC-DB3F28E0F7A7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ComponentLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..0131360 --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,127 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Metadata.Ecma335; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic.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/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..c39f8bb --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,132 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic.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) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newStatus) + { + _logger.LogWarning("Update operation failed. Order status incorrect."); + return false; + } + model.Status = newStatus; + if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model); + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. 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.PastryId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор документа", + nameof(model.PastryId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество кондитерских изделий в заказе должно быть больше 0", + nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", + nameof(model.Sum)); + } + _logger.LogInformation("Pastry. OrderId:{Id}. Sum:{Sum}. PastryId:{PastryId}.", + model.Id, model.Sum, model.PastryId); + } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs new file mode 100644 index 0000000..416ec00 --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs @@ -0,0 +1,121 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + public class PastryLogic : IPastryLogic + { + private readonly ILogger _logger; + + private readonly IPastryStorage _pastryStorage; + + public PastryLogic(ILogger logger, IPastryStorage pastryStorage) + { + _logger = logger; + _pastryStorage = pastryStorage; + } + + public List? ReadList(PastrySearchModel? model) + { + _logger.LogInformation("ReadList. PastryName:{PastryName}. Id:{Id}", model?.PastryName, model?.Id); + var list = model == null ? _pastryStorage.GetFullList() : _pastryStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public PastryViewModel? ReadElement(PastrySearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. PastryName:{PastryName}. Id:{Id}", model.PastryName, model.Id); + var element = _pastryStorage.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(PastryBindingModel model) + { + CheckModel(model); + if (_pastryStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(PastryBindingModel model) + { + CheckModel(model); + if (_pastryStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(PastryBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_pastryStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(PastryBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PastryName)) + { + throw new ArgumentNullException("Нет названия кондитерского изделия", nameof(model.PastryName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена кондитерского изделия должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Pastry. PastryName:{PastryName}. Cost:{Cost}. Id:{Id}", + model.PastryName, model.Price, model.Id); + var element = _pastryStorage.GetElement(new PastrySearchModel + { + PastryName = model.PastryName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Кондитерское изделие с таким названием уже есть"); + } + } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj new file mode 100644 index 0000000..4590d1c --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/Confectionery/ConfectioneryContracts/BindingModels/ComponentBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..d6107ce --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,18 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.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/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..7859c0f --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,27 @@ +using ConfectioneryDataModels.Enums; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + + public int PastryId { get; set; } + + 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/Confectionery/ConfectioneryContracts/BindingModels/PastryBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/PastryBindingModel.cs new file mode 100644 index 0000000..9649fb5 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/PastryBindingModel.cs @@ -0,0 +1,20 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BindingModels +{ + public class PastryBindingModel : IPastryModel + { + public int Id { get; set; } + + public string PastryName { get; set; } = string.Empty; + + public double Price { get; set; } + + public Dictionary PastryComponents { get; set; } = new(); + } +} diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IComponentLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..d832f16 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,24 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.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/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..96501ad --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,24 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.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/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IPastryLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IPastryLogic.cs new file mode 100644 index 0000000..106936e --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IPastryLogic.cs @@ -0,0 +1,24 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface IPastryLogic + { + List? ReadList(PastrySearchModel? model); + + PastryViewModel? ReadElement(PastrySearchModel model); + + bool Create(PastryBindingModel model); + + bool Update(PastryBindingModel model); + + bool Delete(PastryBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj b/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj new file mode 100644 index 0000000..b0b970c --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Confectionery/ConfectioneryContracts/SearchModels/ComponentSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..5cc1374 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + + public string? ComponentName { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..9393fab --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/SearchModels/PastrySearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/PastrySearchModel.cs new file mode 100644 index 0000000..5e0280b --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/PastrySearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class PastrySearchModel + { + public int? Id { get; set; } + + public string? PastryName { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IComponentStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..6205d5a --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,26 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.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/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..ae004e6 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,26 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.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/Confectionery/ConfectioneryContracts/StoragesContracts/IPastryStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IPastryStorage.cs new file mode 100644 index 0000000..7fce161 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IPastryStorage.cs @@ -0,0 +1,26 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContracts +{ + public interface IPastryStorage + { + List GetFullList(); + + List GetFilteredList(PastrySearchModel model); + + PastryViewModel? GetElement(PastrySearchModel model); + + PastryViewModel? Insert(PastryBindingModel model); + + PastryViewModel? Update(PastryBindingModel model); + + PastryViewModel? Delete(PastryBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/ViewModels/ComponentViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..8706c51 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,21 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.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/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..bb20d71 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,37 @@ +using ConfectioneryDataModels.Enums; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + + public int PastryId { get; set; } + + [DisplayName("Изделие")] + public string PastryName { 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/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs new file mode 100644 index 0000000..5d1919f --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs @@ -0,0 +1,23 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.ViewModels +{ + public class PastryViewModel : IPastryModel + { + public int Id { get; set; } + + [DisplayName("Название изделия")] + public string PastryName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + + public Dictionary PastryComponents { get; set; } = new(); + } +} diff --git a/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj b/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs b/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..1c95908 --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + + Принят = 0, + + Выполняется = 1, + + Готов = 2, + + Выдан = 3 + } +} diff --git a/Confectionery/ConfectioneryDataModels/IId.cs b/Confectionery/ConfectioneryDataModels/IId.cs new file mode 100644 index 0000000..b7d876a --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IId + { + int Id { get; } + } +} diff --git a/Confectionery/ConfectioneryDataModels/Models/IComponentModel.cs b/Confectionery/ConfectioneryDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..811f882 --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/IComponentModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + + double Cost { get; } + } +} diff --git a/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs b/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..8f73357 --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs @@ -0,0 +1,24 @@ +using ConfectioneryDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IOrderModel : IId + { + int PastryId { get; } + + int Count { get; } + + double Sum { get; } + + OrderStatus Status { get; } + + DateTime DateCreate { get; } + + DateTime? DateImplement { get; } + } +} diff --git a/Confectionery/ConfectioneryDataModels/Models/IPastryModel.cs b/Confectionery/ConfectioneryDataModels/Models/IPastryModel.cs new file mode 100644 index 0000000..0d2b1c4 --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/IPastryModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IPastryModel : IId + { + string PastryName { get; } + + double Price { get; } + + Dictionary PastryComponents { get; } + } +} diff --git a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj new file mode 100644 index 0000000..41b6c3e --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs new file mode 100644 index 0000000..9178a26 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs @@ -0,0 +1,37 @@ +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + + public List Components { get; set; } + + public List Orders { get; set; } + + public List Pastries { get; set; } + + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Pastries = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + + return _instance; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Implements/ComponentStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..51e9ee6 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,114 @@ +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.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/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..7a226ce --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs @@ -0,0 +1,121 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement; +using ConfectioneryListImplement.Models; +using ConfectioneryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var Order in _source.Orders) + { + result.Add(GetViewModel(Order)); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model == null) + { + return result; + } + foreach (var Order in _source.Orders) + { + if (Order.Id == model.Id) + { + result.Add(GetViewModel(Order)); + } + } + return result; + } + 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 GetViewModel(Order); + } + } + return null; + } + 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 GetViewModel(newOrder); + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var Order in _source.Orders) + { + if (Order.Id == model.Id) + { + Order.Update(model); + return GetViewModel(Order); + } + } + return null; + } + 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 GetViewModel(element); + } + } + return null; + } + + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var pastry in _source.Pastries) + { + if (pastry.Id == order.PastryId) + { + viewModel.PastryName = pastry.PastryName; + break; + } + } + return viewModel; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Implements/PastryStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/PastryStorage.cs new file mode 100644 index 0000000..9131fbe --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/PastryStorage.cs @@ -0,0 +1,108 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Implements +{ + public class PastryStorage : IPastryStorage + { + private readonly DataListSingleton _source; + + public PastryStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var pastry in _source.Pastries) + { + result.Add(pastry.GetViewModel); + } + return result; + } + public List GetFilteredList(PastrySearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.PastryName)) + { + return result; + } + foreach (var pastry in _source.Pastries) + { + if (pastry.PastryName.Contains(model.PastryName)) + { + result.Add(pastry.GetViewModel); + } + } + return result; + } + public PastryViewModel? GetElement(PastrySearchModel model) + { + if (string.IsNullOrEmpty(model.PastryName) && !model.Id.HasValue) + { + return null; + } + foreach (var pastry in _source.Pastries) + { + if ((!string.IsNullOrEmpty(model.PastryName) && pastry.PastryName == model.PastryName) || + (model.Id.HasValue && pastry.Id == model.Id)) + { + return pastry.GetViewModel; + } + } + return null; + } + public PastryViewModel? Insert(PastryBindingModel model) + { + model.Id = 1; + foreach (var pastry in _source.Pastries) + { + if (model.Id <= pastry.Id) + { + model.Id = pastry.Id + 1; + } + } + var newPastry = Pastry.Create(model); + if (newPastry == null) + { + return null; + } + _source.Pastries.Add(newPastry); + return newPastry.GetViewModel; + } + public PastryViewModel? Update(PastryBindingModel model) + { + foreach (var pastry in _source.Pastries) + { + if (pastry.Id == model.Id) + { + pastry.Update(model); + return pastry.GetViewModel; + } + } + return null; + } + public PastryViewModel? Delete(PastryBindingModel model) + { + for (int i = 0; i < _source.Pastries.Count; ++i) + { + if (_source.Pastries[i].Id == model.Id) + { + var element = _source.Pastries[i]; + _source.Pastries.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryListImplement/Models/Component.cs b/Confectionery/ConfectioneryListImplement/Models/Component.cs new file mode 100644 index 0000000..7a8851e --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Component.cs @@ -0,0 +1,51 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.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/Confectionery/ConfectioneryListImplement/Models/Order.cs b/Confectionery/ConfectioneryListImplement/Models/Order.cs new file mode 100644 index 0000000..58a3bb6 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Order.cs @@ -0,0 +1,74 @@ +using ConfectioneryContracts.ViewModels; +using ConfectioneryContracts.BindingModels; +using ConfectioneryDataModels.Enums; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int PastryId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; set; } = DateTime.Now; + + public DateTime? DateImplement { get; set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Order() + { + Id = model.Id, + PastryId = model.PastryId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel model) + { + if (model == null) + { + return; + } + + PastryId = model.PastryId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + PastryId = PastryId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/Confectionery/ConfectioneryListImplement/Models/Pastry.cs b/Confectionery/ConfectioneryListImplement/Models/Pastry.cs new file mode 100644 index 0000000..c984f27 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Pastry.cs @@ -0,0 +1,57 @@ +using ConfectioneryDataModels.Models; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + public class Pastry : IPastryModel + { + public int Id { get; private set; } + + public string PastryName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public Dictionary PastryComponents { get; private set; } = + new Dictionary(); + + public static Pastry? Create(PastryBindingModel? model) + { + if (model == null) + { + return null; + } + return new Pastry() + { + Id = model.Id, + PastryName = model.PastryName, + Price = model.Price, + PastryComponents = model.PastryComponents, + }; + } + + public void Update(PastryBindingModel? model) + { + if (model == null) + { + return; + } + PastryName = model.PastryName; + Price = model.Price; + PastryComponents = model.PastryComponents; + } + + public PastryViewModel GetViewModel => new() + { + Id = Id, + PastryName = PastryName, + Price = Price, + PastryComponents = PastryComponents + }; + } +} diff --git a/Confectionery/ConfectioneryView/ConfectioneryView.csproj b/Confectionery/ConfectioneryView/ConfectioneryView.csproj new file mode 100644 index 0000000..33aee06 --- /dev/null +++ b/Confectionery/ConfectioneryView/ConfectioneryView.csproj @@ -0,0 +1,23 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormComponent.Designer.cs b/Confectionery/ConfectioneryView/FormComponent.Designer.cs new file mode 100644 index 0000000..eaee711 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace ConfectioneryView +{ + 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.labelName = new System.Windows.Forms.Label(); + this.labelCost = 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(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(41, 40); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(41, 77); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(38, 15); + this.labelCost.TabIndex = 1; + this.labelCost.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(109, 37); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(378, 23); + this.textBoxName.TabIndex = 2; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(109, 77); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(197, 23); + this.textBoxCost.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(316, 144); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + 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(412, 144); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + 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(547, 189); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormComponent.cs b/Confectionery/ConfectioneryView/FormComponent.cs new file mode 100644 index 0000000..15b0292 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormComponent.cs @@ -0,0 +1,96 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.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 ConfectioneryView +{ + 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/Confectionery/ConfectioneryView/FormComponent.resx b/Confectionery/ConfectioneryView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/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/Confectionery/ConfectioneryView/FormComponents.Designer.cs b/Confectionery/ConfectioneryView/FormComponents.Designer.cs new file mode 100644 index 0000000..1a282c9 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormComponents.Designer.cs @@ -0,0 +1,114 @@ +namespace ConfectioneryView +{ + 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.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(-5, -3); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(617, 455); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(654, 32); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(112, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(654, 85); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(112, 28); + this.buttonRef.TabIndex = 2; + this.buttonRef.Text = "Изменить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(654, 134); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(112, 28); + 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(654, 186); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(112, 28); + this.buttonUpd.TabIndex = 4; + this.buttonUpd.Text = "Обновить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.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.buttonUpd); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormComponents.cs b/Confectionery/ConfectioneryView/FormComponents.cs new file mode 100644 index 0000000..bf9ea07 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormComponents.cs @@ -0,0 +1,116 @@ +using Confectionery; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.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 ConfectioneryView +{ + 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(); + } + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormComponents.resx b/Confectionery/ConfectioneryView/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/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/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..e27306a --- /dev/null +++ b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs @@ -0,0 +1,144 @@ +namespace ConfectioneryView +{ + 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.comboBoxPastry = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 33); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(56, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Изделие:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 71); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(75, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Количество:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 109); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(48, 15); + this.label3.TabIndex = 2; + this.label3.Text = "Сумма:"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(199, 143); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 3; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(280, 143); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // comboBoxPastry + // + this.comboBoxPastry.FormattingEnabled = true; + this.comboBoxPastry.Location = new System.Drawing.Point(94, 30); + this.comboBoxPastry.Name = "comboBoxPastry"; + this.comboBoxPastry.Size = new System.Drawing.Size(271, 23); + this.comboBoxPastry.TabIndex = 5; + this.comboBoxPastry.SelectedIndexChanged += new System.EventHandler(this.ComboBoxPastry_SelectedIndexChanged); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(94, 68); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(271, 23); + this.textBoxCount.TabIndex = 6; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(94, 106); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(271, 23); + this.textBoxSum.TabIndex = 7; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(375, 187); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxPastry); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxPastry; + private TextBox textBoxCount; + private TextBox textBoxSum; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs new file mode 100644 index 0000000..ca012fe --- /dev/null +++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs @@ -0,0 +1,135 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.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 ConfectioneryView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IPastryLogic _logicP; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IPastryLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicP.ReadList(null); + if (list != null) + { + comboBoxPastry.DisplayMember = "PastryName"; + comboBoxPastry.ValueMember = "Id"; + comboBoxPastry.DataSource = list; + comboBoxPastry.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка кондитерских изделий."); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CalcSum() + { + if (comboBoxPastry.SelectedValue != null && + !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxPastry.SelectedValue); + var pastry = _logicP.ReadElement(new PastrySearchModel + { + Id + = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (pastry?.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 ComboBoxPastry_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 (comboBoxPastry.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + PastryId = Convert.ToInt32(comboBoxPastry.SelectedValue), + 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/Confectionery/ConfectioneryView/FormCreateOrder.resx b/Confectionery/ConfectioneryView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/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/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs new file mode 100644 index 0000000..c12e3a7 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -0,0 +1,173 @@ +namespace ConfectioneryView +{ + 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.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + this.buttonOrderReady = new System.Windows.Forms.Button(); + this.buttonIsssued = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + 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(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(645, 67); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(143, 43); + this.buttonCreateOrder.TabIndex = 0; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(645, 131); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(143, 42); + this.buttonTakeOrderInWork.TabIndex = 1; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Location = new System.Drawing.Point(645, 196); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(143, 40); + this.buttonOrderReady.TabIndex = 2; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonIsssued + // + this.buttonIsssued.Location = new System.Drawing.Point(645, 261); + this.buttonIsssued.Name = "buttonIsssued"; + this.buttonIsssued.Size = new System.Drawing.Size(143, 40); + this.buttonIsssued.TabIndex = 3; + this.buttonIsssued.Text = "Заказ выдан"; + this.buttonIsssued.UseVisualStyleBackColor = true; + this.buttonIsssued.Click += new System.EventHandler(this.ButtonIsssued_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(645, 327); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(143, 37); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(9, 27); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(627, 413); + this.dataGridView.TabIndex = 5; + // + // 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(800, 24); + this.menuStrip1.TabIndex = 6; + 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(198, 22); + this.кондитерскиеИзделияToolStripMenuItem.Text = "Кондитерские изделия"; + this.кондитерскиеИзделияToolStripMenuItem.Click += new System.EventHandler(this.PastriesToolStripMenuItem_Click); + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(198, 22); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); + // + // FormMain + // + 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.buttonIsssued); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Кондитерская"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIsssued; + private Button buttonRef; + private DataGridView dataGridView; + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem кондитерскиеИзделияToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs new file mode 100644 index 0000000..d23b54b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -0,0 +1,190 @@ +using Confectionery; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryDataModels.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 ConfectioneryView +{ + 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["PastryId"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs +e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void PastriesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPastries)); + if (service is FormPastries 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, + PastryId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PastryId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].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.FinishOrder(new + OrderBindingModel + { + Id = id, + PastryId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PastryId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonIsssued_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, + PastryId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PastryId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].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 ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormMain.resx b/Confectionery/ConfectioneryView/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/Confectionery/ConfectioneryView/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/Confectionery/ConfectioneryView/FormPastries.Designer.cs b/Confectionery/ConfectioneryView/FormPastries.Designer.cs new file mode 100644 index 0000000..c3a9ef1 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastries.Designer.cs @@ -0,0 +1,113 @@ +namespace ConfectioneryView +{ + partial class FormPastries + { + /// + /// 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.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(23, 22); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(461, 388); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(506, 36); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(100, 23); + 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(506, 85); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(100, 23); + 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(506, 133); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(100, 23); + 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(506, 182); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(100, 23); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormPastries + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(644, 449); + 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 = "FormPastries"; + 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/Confectionery/ConfectioneryView/FormPastries.cs b/Confectionery/ConfectioneryView/FormPastries.cs new file mode 100644 index 0000000..f08263a --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastries.cs @@ -0,0 +1,111 @@ +using Confectionery; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.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 ConfectioneryView +{ + public partial class FormPastries : Form + { + private readonly ILogger _logger; + private readonly IPastryLogic _logic; + public FormPastries(ILogger logger, IPastryLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["PastryComponents"].Visible = false; + } + _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(FormPastry)); + if (service is FormPastry 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(FormPastry)); + if (service is FormPastry 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 PastryBindingModel + { + 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/Confectionery/ConfectioneryView/FormPastries.resx b/Confectionery/ConfectioneryView/FormPastries.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastries.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/Confectionery/ConfectioneryView/FormPastry.Designer.cs b/Confectionery/ConfectioneryView/FormPastry.Designer.cs new file mode 100644 index 0000000..b35f486 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastry.Designer.cs @@ -0,0 +1,227 @@ +namespace ConfectioneryView +{ + partial class FormPastry + { + /// + /// 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + 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.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(14, 24); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(62, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(14, 67); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(70, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Стоимость:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(87, 21); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(242, 23); + this.textBoxName.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Enabled = false; + this.textBoxPrice.Location = new System.Drawing.Point(87, 64); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(172, 23); + this.textBoxPrice.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(354, 403); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + 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(435, 403); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // 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(22, 104); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(522, 293); + this.groupBox1.TabIndex = 6; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Компоненты"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(424, 163); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(75, 23); + 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(424, 124); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(75, 23); + 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(424, 83); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(75, 23); + 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(424, 43); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + 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(6, 22); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(401, 265); + this.dataGridView.TabIndex = 0; + // + // ColumnId + // + this.ColumnId.HeaderText = "Id"; + this.ColumnId.Name = "ColumnId"; + this.ColumnId.Visible = false; + // + // ColumnName + // + this.ColumnName.HeaderText = "Компонент"; + this.ColumnName.Name = "ColumnName"; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.Name = "ColumnCount"; + // + // FormPastry + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(550, 450); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormPastry"; + this.Text = "Изделие"; + this.Load += new System.EventHandler(this.FormPastry_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 Button buttonSave; + private Button buttonCancel; + private GroupBox groupBox1; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormPastry.cs b/Confectionery/ConfectioneryView/FormPastry.cs new file mode 100644 index 0000000..8494d1f --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastry.cs @@ -0,0 +1,232 @@ +using ConfectioneryDataModels.Models; +using Microsoft.Extensions.Logging; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +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; +using Confectionery; + +namespace ConfectioneryView +{ + public partial class FormPastry : Form + { + private readonly ILogger _logger; + private readonly IPastryLogic _logic; + private int? _id; + private Dictionary _pastryComponents; + public int Id { set { _id = value; } } + + public FormPastry(ILogger logger, IPastryLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _pastryComponents = new Dictionary(); + } + + private void FormPastry_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new PastrySearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.PastryName; + textBoxPrice.Text = view.Price.ToString(); + _pastryComponents = view.PastryComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_pastryComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _pastryComponents) + { + 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(FormPastryComponent)); + if (service is FormPastryComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_pastryComponents.ContainsKey(form.Id)) + { + _pastryComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _pastryComponents.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(FormPastryComponent)); + if (service is FormPastryComponent form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _pastryComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _pastryComponents[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); + _pastryComponents?.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 (_pastryComponents == null || _pastryComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new PastryBindingModel + { + Id = _id ?? 0, + PastryName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + PastryComponents = _pastryComponents + }; + 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 _pastryComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + + } +} diff --git a/Confectionery/ConfectioneryView/FormPastry.resx b/Confectionery/ConfectioneryView/FormPastry.resx new file mode 100644 index 0000000..72380a4 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastry.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/Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs b/Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs new file mode 100644 index 0000000..d235b81 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace ConfectioneryView +{ + partial class FormPastryComponent + { + /// + /// 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.AutoSize = true; + this.label1.Location = new System.Drawing.Point(20, 29); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(72, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Компонент:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(20, 75); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(75, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Количество:"; + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(98, 26); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(245, 23); + this.comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(98, 72); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(245, 23); + this.textBoxCount.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(162, 110); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + 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(268, 110); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormPastryComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(370, 149); + 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 = "FormPastryComponent"; + 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/Confectionery/ConfectioneryView/FormPastryComponent.cs b/Confectionery/ConfectioneryView/FormPastryComponent.cs new file mode 100644 index 0000000..506da07 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastryComponent.cs @@ -0,0 +1,91 @@ +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using Microsoft.VisualBasic.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 ConfectioneryView +{ + public partial class FormPastryComponent : 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 FormPastryComponent(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/Confectionery/ConfectioneryView/FormPastryComponent.resx b/Confectionery/ConfectioneryView/FormPastryComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/ConfectioneryView/FormPastryComponent.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/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs new file mode 100644 index 0000000..b98db1c --- /dev/null +++ b/Confectionery/ConfectioneryView/Program.cs @@ -0,0 +1,54 @@ +using ConfectioneryBusinessLogic.BusinessLogics; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryListImplement.Implements; +using ConfectioneryView; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + +namespace Confectionery +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + 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