From 832f2ff9401b5b26f122ce1f596218d71fadc7e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B8=D1=88=D0=B5=D1=80=20=D0=91=D1=83=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Sat, 8 Apr 2023 04:29:36 +0400 Subject: [PATCH] First Labs --- FishFactory/FishFactory.sln | 34 ++- .../BusinessLogics/CannedLogic.cs | 112 ++++++++ .../BusinessLogics/IngredientLogic.cs | 112 ++++++++ .../BusinessLogics/OrderLogic.cs | 112 ++++++++ .../FishFactoryBusinessLogic.csproj | 19 ++ .../BindingModels/CannedBindingModel.cs | 16 ++ .../BindingModels/IngredientBindingModel.cs | 11 + .../BindingModels/OrderBindingModel.cs | 17 ++ .../BusinessLogicsContracts/ICannedLogic.cs | 15 ++ .../IIngredientLogic.cs | 15 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 15 ++ .../FishFactoryContracts.csproj | 13 + .../SearchModels/CannedSearchModel.cs | 8 + .../SearchModels/IngredientSearchModel.cs | 8 + .../SearchModels/OrderSearchModel.cs | 7 + .../StoragesContracts/ICannedStorage.cs | 16 ++ .../StoragesContracts/IIngredientStorage.cs | 16 ++ .../StoragesContracts/IOrderStorage.cs | 16 ++ .../ViewModels/CannedViewModel.cs | 19 ++ .../ViewModels/IngredientViewModel.cs | 14 + .../ViewModels/OrderViewModel.cs | 25 ++ .../Enums/OrderStatus.cs | 11 + .../FishFactoryDataModels.csproj | 9 + FishFactory/FishFactoryDataModels/IId.cs | 7 + .../Models/ICannedModel.cs | 10 + .../Models/IIngredientModel.cs | 9 + .../Models/IOrderModel.cs | 14 + .../DataListSingleton.cs | 28 ++ .../FishFactoryListImplement.csproj | 20 ++ .../Implements/CannedStorage.cs | 108 ++++++++ .../Implements/IngredientStorage.cs | 108 ++++++++ .../Implements/OrderStorage.cs | 105 ++++++++ .../FishFactoryListImplement/Models/Canned.cs | 52 ++++ .../Models/Ingredient.cs | 41 +++ .../FishFactoryListImplement/Models/Order.cs | 66 +++++ .../FishFactoryView/FishFactoryView.csproj | 11 + FishFactory/FishFactoryView/Form1.Designer.cs | 39 --- FishFactory/FishFactoryView/Form1.cs | 10 - FishFactory/FishFactoryView/Form1.resx | 120 --------- .../FishFactoryView/FormCanned.Designer.cs | 247 ++++++++++++++++++ FishFactory/FishFactoryView/FormCanned.cs | 206 +++++++++++++++ FishFactory/FishFactoryView/FormCanned.resx | 69 +++++ .../FormCannedIngredients.Designer.cs | 123 +++++++++ .../FishFactoryView/FormCannedIngredients.cs | 79 ++++++ .../FormCannedIngredients.resx | 60 +++++ .../FormCreateOrder.Designer.cs | 150 +++++++++++ .../FishFactoryView/FormCreateOrder.cs | 117 +++++++++ .../FishFactoryView/FormCreateOrder.resx | 60 +++++ .../FormIngredient.Designer.cs | 124 +++++++++ FishFactory/FishFactoryView/FormIngredient.cs | 86 ++++++ .../FishFactoryView/FormIngredient.resx | 60 +++++ .../FormIngredients.Designer.cs | 122 +++++++++ .../FishFactoryView/FormIngredients.cs | 99 +++++++ .../FishFactoryView/FormIngredients.resx | 60 +++++ .../FormListCanned.Designer.cs | 122 +++++++++ FishFactory/FishFactoryView/FormListCanned.cs | 104 ++++++++ .../FishFactoryView/FormListCanned.resx | 60 +++++ .../FishFactoryView/FormMain.Designer.cs | 182 +++++++++++++ FishFactory/FishFactoryView/FormMain.cs | 165 ++++++++++++ FishFactory/FishFactoryView/FormMain.resx | 63 +++++ FishFactory/FishFactoryView/Program.cs | 44 +++- 61 files changed, 3613 insertions(+), 177 deletions(-) create mode 100644 FishFactory/FishFactoryBusinessLogic/BusinessLogics/CannedLogic.cs create mode 100644 FishFactory/FishFactoryBusinessLogic/BusinessLogics/IngredientLogic.cs create mode 100644 FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 FishFactory/FishFactoryBusinessLogic/FishFactoryBusinessLogic.csproj create mode 100644 FishFactory/FishFactoryContracts/BindingModels/CannedBindingModel.cs create mode 100644 FishFactory/FishFactoryContracts/BindingModels/IngredientBindingModel.cs create mode 100644 FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs create mode 100644 FishFactory/FishFactoryContracts/BusinessLogicsContracts/ICannedLogic.cs create mode 100644 FishFactory/FishFactoryContracts/BusinessLogicsContracts/IIngredientLogic.cs create mode 100644 FishFactory/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 FishFactory/FishFactoryContracts/FishFactoryContracts.csproj create mode 100644 FishFactory/FishFactoryContracts/SearchModels/CannedSearchModel.cs create mode 100644 FishFactory/FishFactoryContracts/SearchModels/IngredientSearchModel.cs create mode 100644 FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs create mode 100644 FishFactory/FishFactoryContracts/StoragesContracts/ICannedStorage.cs create mode 100644 FishFactory/FishFactoryContracts/StoragesContracts/IIngredientStorage.cs create mode 100644 FishFactory/FishFactoryContracts/StoragesContracts/IOrderStorage.cs create mode 100644 FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs create mode 100644 FishFactory/FishFactoryContracts/ViewModels/IngredientViewModel.cs create mode 100644 FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs create mode 100644 FishFactory/FishFactoryDataModels/Enums/OrderStatus.cs create mode 100644 FishFactory/FishFactoryDataModels/FishFactoryDataModels.csproj create mode 100644 FishFactory/FishFactoryDataModels/IId.cs create mode 100644 FishFactory/FishFactoryDataModels/Models/ICannedModel.cs create mode 100644 FishFactory/FishFactoryDataModels/Models/IIngredientModel.cs create mode 100644 FishFactory/FishFactoryDataModels/Models/IOrderModel.cs create mode 100644 FishFactory/FishFactoryListImplement/DataListSingleton.cs create mode 100644 FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj create mode 100644 FishFactory/FishFactoryListImplement/Implements/CannedStorage.cs create mode 100644 FishFactory/FishFactoryListImplement/Implements/IngredientStorage.cs create mode 100644 FishFactory/FishFactoryListImplement/Implements/OrderStorage.cs create mode 100644 FishFactory/FishFactoryListImplement/Models/Canned.cs create mode 100644 FishFactory/FishFactoryListImplement/Models/Ingredient.cs create mode 100644 FishFactory/FishFactoryListImplement/Models/Order.cs delete mode 100644 FishFactory/FishFactoryView/Form1.Designer.cs delete mode 100644 FishFactory/FishFactoryView/Form1.cs delete mode 100644 FishFactory/FishFactoryView/Form1.resx create mode 100644 FishFactory/FishFactoryView/FormCanned.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormCanned.cs create mode 100644 FishFactory/FishFactoryView/FormCanned.resx create mode 100644 FishFactory/FishFactoryView/FormCannedIngredients.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormCannedIngredients.cs create mode 100644 FishFactory/FishFactoryView/FormCannedIngredients.resx create mode 100644 FishFactory/FishFactoryView/FormCreateOrder.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormCreateOrder.cs create mode 100644 FishFactory/FishFactoryView/FormCreateOrder.resx create mode 100644 FishFactory/FishFactoryView/FormIngredient.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormIngredient.cs create mode 100644 FishFactory/FishFactoryView/FormIngredient.resx create mode 100644 FishFactory/FishFactoryView/FormIngredients.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormIngredients.cs create mode 100644 FishFactory/FishFactoryView/FormIngredients.resx create mode 100644 FishFactory/FishFactoryView/FormListCanned.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormListCanned.cs create mode 100644 FishFactory/FishFactoryView/FormListCanned.resx create mode 100644 FishFactory/FishFactoryView/FormMain.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormMain.cs create mode 100644 FishFactory/FishFactoryView/FormMain.resx diff --git a/FishFactory/FishFactory.sln b/FishFactory/FishFactory.sln index b6254c5..aeb1db6 100644 --- a/FishFactory/FishFactory.sln +++ b/FishFactory/FishFactory.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryView", "FishFactoryView\FishFactoryView.csproj", "{B9673528-4858-41F6-B8AF-65030A9A0537}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDataModels", "FishFactoryDataModels\FishFactoryDataModels.csproj", "{D3365297-DF47-4830-BF3C-A24EE3E62B15}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryView", "FishFactoryView\FishFactoryView.csproj", "{2304F79F-E763-44E3-8CF6-50CFC3BDC288}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryContracts", "FishFactoryContracts\FishFactoryContracts.csproj", "{78DE3D5B-DA83-4266-B91F-5601C5603450}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryBusinessLogic", "FishFactoryBusinessLogic\FishFactoryBusinessLogic.csproj", "{AC755273-7FEE-42B5-9BA1-5D17FF559C37}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryListImplement", "FishFactoryListImplement\FishFactoryListImplement.csproj", "{923C2993-D4F1-4480-B31C-B80F16575603}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,10 +19,26 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B9673528-4858-41F6-B8AF-65030A9A0537}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B9673528-4858-41F6-B8AF-65030A9A0537}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B9673528-4858-41F6-B8AF-65030A9A0537}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B9673528-4858-41F6-B8AF-65030A9A0537}.Release|Any CPU.Build.0 = Release|Any CPU + {D3365297-DF47-4830-BF3C-A24EE3E62B15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D3365297-DF47-4830-BF3C-A24EE3E62B15}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D3365297-DF47-4830-BF3C-A24EE3E62B15}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D3365297-DF47-4830-BF3C-A24EE3E62B15}.Release|Any CPU.Build.0 = Release|Any CPU + {2304F79F-E763-44E3-8CF6-50CFC3BDC288}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2304F79F-E763-44E3-8CF6-50CFC3BDC288}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2304F79F-E763-44E3-8CF6-50CFC3BDC288}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2304F79F-E763-44E3-8CF6-50CFC3BDC288}.Release|Any CPU.Build.0 = Release|Any CPU + {78DE3D5B-DA83-4266-B91F-5601C5603450}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {78DE3D5B-DA83-4266-B91F-5601C5603450}.Debug|Any CPU.Build.0 = Debug|Any CPU + {78DE3D5B-DA83-4266-B91F-5601C5603450}.Release|Any CPU.ActiveCfg = Release|Any CPU + {78DE3D5B-DA83-4266-B91F-5601C5603450}.Release|Any CPU.Build.0 = Release|Any CPU + {AC755273-7FEE-42B5-9BA1-5D17FF559C37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC755273-7FEE-42B5-9BA1-5D17FF559C37}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC755273-7FEE-42B5-9BA1-5D17FF559C37}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC755273-7FEE-42B5-9BA1-5D17FF559C37}.Release|Any CPU.Build.0 = Release|Any CPU + {923C2993-D4F1-4480-B31C-B80F16575603}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {923C2993-D4F1-4480-B31C-B80F16575603}.Debug|Any CPU.Build.0 = Debug|Any CPU + {923C2993-D4F1-4480-B31C-B80F16575603}.Release|Any CPU.ActiveCfg = Release|Any CPU + {923C2993-D4F1-4480-B31C-B80F16575603}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/CannedLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/CannedLogic.cs new file mode 100644 index 0000000..c3066f5 --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/CannedLogic.cs @@ -0,0 +1,112 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryBusinessLogic.BusinessLogics +{ + public class CannedLogic : ICannedLogic + { + private readonly ILogger _logger; + private readonly ICannedStorage _cannedStorage; + public CannedLogic(ILogger logger, ICannedStorage cannedStorage) + { + _logger = logger; + _cannedStorage = cannedStorage; + } + public List? ReadList(CannedSearchModel model) + { + _logger.LogInformation("ReadList. CannedName: {CannedName}. Id: {Id}", + model?.CannedName, model?.Id); + var list = model == null ? _cannedStorage.GetFullList() : + _cannedStorage.GetFilteredList(model); + if(list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public CannedViewModel? ReadElement(CannedSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadList. CannedName: {CannedName}. Id: {Id}", + model?.CannedName, model?.Id); + var element = _cannedStorage.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(CannedBindingModel model) + { + CheckModel(model, false); + if(_cannedStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(CannedBindingModel model) + { + CheckModel(model, false); + if(_cannedStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(CannedBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_cannedStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(CannedBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.CannedName)) + { + throw new ArgumentNullException("Нет названия консервы", nameof(model.CannedName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена консервы должна быть больше 0", + nameof(model.Price)); + } + _logger.LogInformation("Canned. CannedName: {CannedName}. Cost: {Cost}. Id: {Id}", + model.CannedName, model.Price, model.Id); + var element = _cannedStorage.GetElement(new CannedSearchModel + { + CannedName = model.CannedName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Консерва с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/IngredientLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/IngredientLogic.cs new file mode 100644 index 0000000..6af567a --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/IngredientLogic.cs @@ -0,0 +1,112 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryBusinessLogic.BusinessLogics +{ + public class IngredientLogic : IIngredientLogic + { + private readonly ILogger _logger; + private readonly IIngredientStorage _componentStorage; + public IngredientLogic(ILogger logger, IIngredientStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(IngredientSearchModel? model) + { + _logger.LogInformation("ReadList. IngredientName: {IngredientName}. Id: {Id}", + model?.IngredientName, 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 IngredientViewModel? ReadElement(IngredientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. IngredientName: {IngredientName}. Id: {Id}", + model.IngredientName, 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(IngredientBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(IngredientBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(IngredientBindingModel 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(IngredientBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.IngredientName)) + { + throw new ArgumentNullException("Нет названия ингредиента", nameof(model.IngredientName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена ингредиента должна быть больше 0", + nameof(model.Cost)); + } + _logger.LogInformation("Ingredient. IngredientName: {IngredientName}. Cost: {Cost}. Id: {Id}", + model.IngredientName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new IngredientSearchModel + { + IngredientName = model.IngredientName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..4642678 --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,112 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Enums; + +namespace FishFactoryBusinessLogic.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) + { + CheckModel(model); + if (model.Status + 1 != newStatus) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + model.Status = newStatus; + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Order. OrderID:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.CannedId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор у консервы", nameof(model.CannedId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество консервы в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. CannedId: { CannedId}", model.Id, model.Sum, model.CannedId); + } + } +} diff --git a/FishFactory/FishFactoryBusinessLogic/FishFactoryBusinessLogic.csproj b/FishFactory/FishFactoryBusinessLogic/FishFactoryBusinessLogic.csproj new file mode 100644 index 0000000..cbb2fe0 --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/FishFactoryBusinessLogic.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/FishFactory/FishFactoryContracts/BindingModels/CannedBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/CannedBindingModel.cs new file mode 100644 index 0000000..6ffabfc --- /dev/null +++ b/FishFactory/FishFactoryContracts/BindingModels/CannedBindingModel.cs @@ -0,0 +1,16 @@ +using FishFactoryDataModels.Models; + +namespace FishFactoryContracts.BindingModels +{ + public class CannedBindingModel : ICannedModel + { + public int Id { get; set; } + public string CannedName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary CannedIngredients + { + get; + set; + } = new(); + } +} diff --git a/FishFactory/FishFactoryContracts/BindingModels/IngredientBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/IngredientBindingModel.cs new file mode 100644 index 0000000..e26aa7f --- /dev/null +++ b/FishFactory/FishFactoryContracts/BindingModels/IngredientBindingModel.cs @@ -0,0 +1,11 @@ +using FishFactoryDataModels.Models; + +namespace FishFactoryContracts.BindingModels +{ + public class IngredientBindingModel : IIngredientModel + { + public int Id { get; set; } + public string IngredientName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..40bb262 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,17 @@ +using FishFactoryDataModels.Enums; +using FishFactoryDataModels.Models; + +namespace FishFactoryContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int CannedId { get; set; } + public string CannedName { get; set; } = string.Empty; + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + public int Id { get; set; } + } +} diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/ICannedLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/ICannedLogic.cs new file mode 100644 index 0000000..846cbba --- /dev/null +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/ICannedLogic.cs @@ -0,0 +1,15 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.BusinessLogicsContracts +{ + public interface ICannedLogic + { + List? ReadList(CannedSearchModel? model); + CannedViewModel? ReadElement(CannedSearchModel? model); + bool Create(CannedBindingModel? model); + bool Update(CannedBindingModel? model); + bool Delete(CannedBindingModel? model); + } +} diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IIngredientLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IIngredientLogic.cs new file mode 100644 index 0000000..ec241d6 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IIngredientLogic.cs @@ -0,0 +1,15 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.BusinessLogicsContracts +{ + public interface IIngredientLogic + { + List? ReadList(IngredientSearchModel? model); + IngredientViewModel? ReadElement(IngredientSearchModel model); + bool Create(IngredientBindingModel model); + bool Update(IngredientBindingModel model); + bool Delete(IngredientBindingModel model); + } +} diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..0602638 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj b/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj new file mode 100644 index 0000000..4a17316 --- /dev/null +++ b/FishFactory/FishFactoryContracts/FishFactoryContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/FishFactory/FishFactoryContracts/SearchModels/CannedSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/CannedSearchModel.cs new file mode 100644 index 0000000..a6869f0 --- /dev/null +++ b/FishFactory/FishFactoryContracts/SearchModels/CannedSearchModel.cs @@ -0,0 +1,8 @@ +namespace FishFactoryContracts.SearchModels +{ + public class CannedSearchModel + { + public int? Id { get; set; } + public string? CannedName { get; set; } + } +} diff --git a/FishFactory/FishFactoryContracts/SearchModels/IngredientSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/IngredientSearchModel.cs new file mode 100644 index 0000000..91306be --- /dev/null +++ b/FishFactory/FishFactoryContracts/SearchModels/IngredientSearchModel.cs @@ -0,0 +1,8 @@ +namespace FishFactoryContracts.SearchModels +{ + public class IngredientSearchModel + { + public int? Id { get; set; } + public string? IngredientName { get; set; } + } +} diff --git a/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..22a2384 --- /dev/null +++ b/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace FishFactoryContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/FishFactory/FishFactoryContracts/StoragesContracts/ICannedStorage.cs b/FishFactory/FishFactoryContracts/StoragesContracts/ICannedStorage.cs new file mode 100644 index 0000000..69ca5dd --- /dev/null +++ b/FishFactory/FishFactoryContracts/StoragesContracts/ICannedStorage.cs @@ -0,0 +1,16 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.StoragesContracts +{ + public interface ICannedStorage + { + List GetFullList(); + List GetFilteredList(CannedSearchModel model); + CannedViewModel? GetElement(CannedSearchModel model); + CannedViewModel? Insert(CannedBindingModel model); + CannedViewModel? Update(CannedBindingModel model); + CannedViewModel? Delete(CannedBindingModel model); + } +} diff --git a/FishFactory/FishFactoryContracts/StoragesContracts/IIngredientStorage.cs b/FishFactory/FishFactoryContracts/StoragesContracts/IIngredientStorage.cs new file mode 100644 index 0000000..3e84006 --- /dev/null +++ b/FishFactory/FishFactoryContracts/StoragesContracts/IIngredientStorage.cs @@ -0,0 +1,16 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.StoragesContracts +{ + public interface IIngredientStorage + { + List GetFullList(); + List GetFilteredList(IngredientSearchModel model); + IngredientViewModel? GetElement(IngredientSearchModel model); + IngredientViewModel? Insert(IngredientBindingModel model); + IngredientViewModel? Update(IngredientBindingModel model); + IngredientViewModel? Delete(IngredientBindingModel model); + } +} diff --git a/FishFactory/FishFactoryContracts/StoragesContracts/IOrderStorage.cs b/FishFactory/FishFactoryContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..a81b868 --- /dev/null +++ b/FishFactory/FishFactoryContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,16 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs new file mode 100644 index 0000000..5240f8a --- /dev/null +++ b/FishFactory/FishFactoryContracts/ViewModels/CannedViewModel.cs @@ -0,0 +1,19 @@ +using FishFactoryDataModels.Models; +using System.ComponentModel; + +namespace FishFactoryContracts.ViewModels +{ + public class CannedViewModel : ICannedModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string CannedName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary CannedIngredients + { + get; + set; + } = new(); + } +} diff --git a/FishFactory/FishFactoryContracts/ViewModels/IngredientViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/IngredientViewModel.cs new file mode 100644 index 0000000..8212612 --- /dev/null +++ b/FishFactory/FishFactoryContracts/ViewModels/IngredientViewModel.cs @@ -0,0 +1,14 @@ +using System.ComponentModel; +using FishFactoryDataModels.Models; + +namespace FishFactoryContracts.ViewModels +{ + public class IngredientViewModel : IIngredientModel + { + public int Id { get; set; } + [DisplayName("Название ингредиента")] + public string IngredientName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..c5b5402 --- /dev/null +++ b/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,25 @@ +using System.ComponentModel; +using FishFactoryDataModels.Enums; +using FishFactoryDataModels.Models; + +namespace FishFactoryContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int CannedId { get; set; } + [DisplayName("Консерва")] + public string CannedName { 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/FishFactory/FishFactoryDataModels/Enums/OrderStatus.cs b/FishFactory/FishFactoryDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..ef754e3 --- /dev/null +++ b/FishFactory/FishFactoryDataModels/Enums/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace FishFactoryDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryDataModels/FishFactoryDataModels.csproj b/FishFactory/FishFactoryDataModels/FishFactoryDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/FishFactory/FishFactoryDataModels/FishFactoryDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/FishFactory/FishFactoryDataModels/IId.cs b/FishFactory/FishFactoryDataModels/IId.cs new file mode 100644 index 0000000..1f50104 --- /dev/null +++ b/FishFactory/FishFactoryDataModels/IId.cs @@ -0,0 +1,7 @@ +namespace FishFactoryDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/FishFactory/FishFactoryDataModels/Models/ICannedModel.cs b/FishFactory/FishFactoryDataModels/Models/ICannedModel.cs new file mode 100644 index 0000000..dd4fca9 --- /dev/null +++ b/FishFactory/FishFactoryDataModels/Models/ICannedModel.cs @@ -0,0 +1,10 @@ +namespace FishFactoryDataModels.Models +{ + public interface ICannedModel : IId + { + string CannedName { get; } + double Price { get; } + Dictionary CannedIngredients { get; } + + } +} diff --git a/FishFactory/FishFactoryDataModels/Models/IIngredientModel.cs b/FishFactory/FishFactoryDataModels/Models/IIngredientModel.cs new file mode 100644 index 0000000..97c388f --- /dev/null +++ b/FishFactory/FishFactoryDataModels/Models/IIngredientModel.cs @@ -0,0 +1,9 @@ +namespace FishFactoryDataModels.Models +{ + public interface IIngredientModel : IId + { + string IngredientName { get; } + double Cost { get; } + + } +} diff --git a/FishFactory/FishFactoryDataModels/Models/IOrderModel.cs b/FishFactory/FishFactoryDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..130a247 --- /dev/null +++ b/FishFactory/FishFactoryDataModels/Models/IOrderModel.cs @@ -0,0 +1,14 @@ +using FishFactoryDataModels.Enums; + +namespace FishFactoryDataModels.Models +{ + public interface IOrderModel : IId + { + int CannedId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/FishFactory/FishFactoryListImplement/DataListSingleton.cs b/FishFactory/FishFactoryListImplement/DataListSingleton.cs new file mode 100644 index 0000000..cd30178 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/DataListSingleton.cs @@ -0,0 +1,28 @@ +using FishFactoryListImplement.Models; + +namespace FishFactoryListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Ingredients { get; set; } + public List Orders { get; set; } + public List ListCanned { get; set; } + + private DataListSingleton() + { + Ingredients = new List(); + Orders = new List(); + ListCanned = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj b/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj new file mode 100644 index 0000000..6d7e23b --- /dev/null +++ b/FishFactory/FishFactoryListImplement/FishFactoryListImplement.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + diff --git a/FishFactory/FishFactoryListImplement/Implements/CannedStorage.cs b/FishFactory/FishFactoryListImplement/Implements/CannedStorage.cs new file mode 100644 index 0000000..5832efe --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Implements/CannedStorage.cs @@ -0,0 +1,108 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryListImplement.Models; + +namespace FishFactoryListImplement.Implements +{ + public class CannedStorage : ICannedStorage + { + private readonly DataListSingleton _source; + public CannedStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach(var canned in _source.ListCanned) + { + result.Add(canned.GetViewModel); + } + return result; + } + + public List GetFilteredList(CannedSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.CannedName)) + { + return result; + } + foreach (var canned in _source.ListCanned) + { + if (canned.CannedName.Contains(model.CannedName)) + { + result.Add(canned.GetViewModel); + } + } + return result; + } + + public CannedViewModel? GetElement(CannedSearchModel model) + { + if (string.IsNullOrEmpty(model.CannedName) && !model.Id.HasValue) + { + return null; + } + foreach (var canned in _source.ListCanned) + { + if ((!string.IsNullOrEmpty(model.CannedName) && + canned.CannedName == model.CannedName) || + (model.Id.HasValue && canned.Id == model.Id)) + { + return canned.GetViewModel; + } + } + return null; + } + + public CannedViewModel? Insert(CannedBindingModel model) + { + model.Id = 1; + foreach (var canned in _source.ListCanned) + { + if (model.Id <= canned.Id) + { + model.Id = canned.Id + 1; + } + } + var newSushi = Canned.Create(model); + if (newSushi == null) + { + return null; + } + _source.ListCanned.Add(newSushi); + return newSushi.GetViewModel; + } + + public CannedViewModel? Update(CannedBindingModel model) + { + foreach (var canned in _source.ListCanned) + { + if (canned.Id == model.Id) + { + canned.Update(model); + return canned.GetViewModel; + } + } + return null; + } + + public CannedViewModel? Delete(CannedBindingModel model) + { + for (int i = 0; i < _source.ListCanned.Count; ++i) + { + if (_source.ListCanned[i].Id == model.Id) + { + var element = _source.ListCanned[i]; + _source.ListCanned.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FishFactory/FishFactoryListImplement/Implements/IngredientStorage.cs b/FishFactory/FishFactoryListImplement/Implements/IngredientStorage.cs new file mode 100644 index 0000000..993f171 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Implements/IngredientStorage.cs @@ -0,0 +1,108 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryListImplement.Models; + +namespace FishFactoryListImplement.Implements +{ + public class IngredientStorage : IIngredientStorage + { + private readonly DataListSingleton _source; + public IngredientStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Ingredients) + { + result.Add(component.GetViewModel); + } + return result; + } + + public List GetFilteredList(IngredientSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.IngredientName)) + { + return result; + } + foreach (var component in _source.Ingredients) + { + if (component.IngredientName.Contains(model.IngredientName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + + public IngredientViewModel? GetElement(IngredientSearchModel model) + { + if (string.IsNullOrEmpty(model.IngredientName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Ingredients) + { + if ((!string.IsNullOrEmpty(model.IngredientName) && + component.IngredientName == model.IngredientName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + + public IngredientViewModel? Insert(IngredientBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Ingredients) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newIngredient = Ingredient.Create(model); + if (newIngredient == null) + { + return null; + } + _source.Ingredients.Add(newIngredient); + return newIngredient.GetViewModel; + } + + public IngredientViewModel? Update(IngredientBindingModel model) + { + foreach (var component in _source.Ingredients) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + + public IngredientViewModel? Delete(IngredientBindingModel model) + { + for (int i = 0; i < _source.Ingredients.Count; ++i) + { + if (_source.Ingredients[i].Id == model.Id) + { + var element = _source.Ingredients[i]; + _source.Ingredients.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FishFactory/FishFactoryListImplement/Implements/OrderStorage.cs b/FishFactory/FishFactoryListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..f122fdc --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Implements/OrderStorage.cs @@ -0,0 +1,105 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryListImplement.Models; + +namespace FishFactoryListImplement.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(order.GetViewModel); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + 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 order.GetViewModel; + } + } + 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 newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + 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 element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FishFactory/FishFactoryListImplement/Models/Canned.cs b/FishFactory/FishFactoryListImplement/Models/Canned.cs new file mode 100644 index 0000000..77e9fb9 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Models/Canned.cs @@ -0,0 +1,52 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; + +namespace FishFactoryListImplement.Models +{ + public class Canned : ICannedModel + { + public int Id { get; private set; } + public string CannedName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary CannedIngredients + { + get; + private set; + } = new Dictionary(); + + public static Canned? Create(CannedBindingModel? model) + { + if (model == null) + { + return null; + } + return new Canned() + { + Id = model.Id, + CannedName = model.CannedName, + Price = model.Price, + CannedIngredients = model.CannedIngredients + }; + } + + public void Update(CannedBindingModel? model) + { + if (model == null) + { + return; + } + CannedName = model.CannedName; + Price = model.Price; + CannedIngredients = model.CannedIngredients; + } + + public CannedViewModel GetViewModel => new() + { + Id = Id, + CannedName = CannedName, + Price = Price, + CannedIngredients = CannedIngredients + }; + } +} diff --git a/FishFactory/FishFactoryListImplement/Models/Ingredient.cs b/FishFactory/FishFactoryListImplement/Models/Ingredient.cs new file mode 100644 index 0000000..53cbba0 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Models/Ingredient.cs @@ -0,0 +1,41 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; + +namespace FishFactoryListImplement.Models +{ + public class Ingredient : IIngredientModel + { + public int Id { get; private set; } + public string IngredientName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Ingredient? Create(IngredientBindingModel? model) + { + if (model == null) + { + return null; + } + return new Ingredient() + { + Id = model.Id, + IngredientName = model.IngredientName, + Cost = model.Cost + }; + } + public void Update(IngredientBindingModel? model) + { + if (model == null) + { + return; + } + IngredientName = model.IngredientName; + Cost = model.Cost; + } + public IngredientViewModel GetViewModel => new() + { + Id = Id, + IngredientName = IngredientName, + Cost = Cost + }; + } +} diff --git a/FishFactory/FishFactoryListImplement/Models/Order.cs b/FishFactory/FishFactoryListImplement/Models/Order.cs new file mode 100644 index 0000000..9886ecd --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Models/Order.cs @@ -0,0 +1,66 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Enums; +using FishFactoryDataModels.Models; + +namespace FishFactoryListImplement.Models +{ + public class Order : IOrderModel + { + public int CannedId { get; private set; } + public string CannedName { get; private set; } = string.Empty; + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order + { + CannedId = model.CannedId, + CannedName = model.CannedName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + Id = model.Id, + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + CannedId = model.CannedId; + CannedName = model.CannedName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + Id = model.Id; + } + + public OrderViewModel GetViewModel => new() + { + CannedId = CannedId, + CannedName = CannedName, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + }; + } +} diff --git a/FishFactory/FishFactoryView/FishFactoryView.csproj b/FishFactory/FishFactoryView/FishFactoryView.csproj index b57c89e..0f507c5 100644 --- a/FishFactory/FishFactoryView/FishFactoryView.csproj +++ b/FishFactory/FishFactoryView/FishFactoryView.csproj @@ -8,4 +8,15 @@ enable + + + + + + + + + + + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/Form1.Designer.cs b/FishFactory/FishFactoryView/Form1.Designer.cs deleted file mode 100644 index 780281a..0000000 --- a/FishFactory/FishFactoryView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace FishFactoryView -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/Form1.cs b/FishFactory/FishFactoryView/Form1.cs deleted file mode 100644 index 8a68d8f..0000000 --- a/FishFactory/FishFactoryView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace FishFactoryView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/Form1.resx b/FishFactory/FishFactoryView/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/FishFactory/FishFactoryView/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/FishFactory/FishFactoryView/FormCanned.Designer.cs b/FishFactory/FishFactoryView/FormCanned.Designer.cs new file mode 100644 index 0000000..0a7a8ca --- /dev/null +++ b/FishFactory/FishFactoryView/FormCanned.Designer.cs @@ -0,0 +1,247 @@ +namespace FishFactoryView +{ + partial class FormCanned + { + /// + /// 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.textBoxPrice = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelPrice = new System.Windows.Forms.Label(); + this.labelName = new System.Windows.Forms.Label(); + this.groupBoxIngredients = new System.Windows.Forms.GroupBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnIngredientName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBoxIngredients.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(90, 36); + this.textBoxPrice.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.ReadOnly = true; + this.textBoxPrice.Size = new System.Drawing.Size(138, 23); + this.textBoxPrice.TabIndex = 7; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(90, 11); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(276, 23); + this.textBoxName.TabIndex = 6; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(14, 41); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(70, 15); + this.labelPrice.TabIndex = 5; + this.labelPrice.Text = "Стоимость:"; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(14, 14); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 4; + this.labelName.Text = "Название:"; + // + // groupBoxIngredients + // + this.groupBoxIngredients.Controls.Add(this.buttonCancel); + this.groupBoxIngredients.Controls.Add(this.buttonSave); + this.groupBoxIngredients.Controls.Add(this.buttonUpdate); + this.groupBoxIngredients.Controls.Add(this.buttonDelete); + this.groupBoxIngredients.Controls.Add(this.buttonEdit); + this.groupBoxIngredients.Controls.Add(this.buttonAdd); + this.groupBoxIngredients.Controls.Add(this.dataGridView); + this.groupBoxIngredients.Dock = System.Windows.Forms.DockStyle.Bottom; + this.groupBoxIngredients.Location = new System.Drawing.Point(0, 66); + this.groupBoxIngredients.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxIngredients.Name = "groupBoxIngredients"; + this.groupBoxIngredients.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxIngredients.Size = new System.Drawing.Size(592, 255); + this.groupBoxIngredients.TabIndex = 8; + this.groupBoxIngredients.TabStop = false; + this.groupBoxIngredients.Text = "Ингредиенты"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(490, 222); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(79, 22); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(405, 222); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(79, 22); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(504, 126); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(79, 22); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(504, 100); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(79, 22); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(504, 74); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(79, 22); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(504, 48); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(79, 22); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.ColumnIngredientName, + this.ColumnCount}); + this.dataGridView.Location = new System.Drawing.Point(5, 20); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(493, 182); + this.dataGridView.TabIndex = 0; + // + // ID + // + this.ID.HeaderText = "ID"; + this.ID.MinimumWidth = 6; + this.ID.Name = "ID"; + this.ID.Visible = false; + this.ID.Width = 125; + // + // ColumnIngredientName + // + this.ColumnIngredientName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None; + this.ColumnIngredientName.HeaderText = "Ингредиент"; + this.ColumnIngredientName.MinimumWidth = 6; + this.ColumnIngredientName.Name = "ColumnIngredientName"; + this.ColumnIngredientName.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.ColumnIngredientName.Width = 312; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.Width = 125; + // + // FormCanned + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(592, 321); + this.Controls.Add(this.groupBoxIngredients); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Name = "FormCanned"; + this.Text = "Консервы"; + this.Load += new System.EventHandler(this.FormSushi_Load); + this.groupBoxIngredients.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxPrice; + private TextBox textBoxName; + private Label labelPrice; + private Label labelName; + private GroupBox groupBoxIngredients; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + private Button buttonCancel; + private Button buttonSave; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ColumnIngredientName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCanned.cs b/FishFactory/FishFactoryView/FormCanned.cs new file mode 100644 index 0000000..046cc84 --- /dev/null +++ b/FishFactory/FishFactoryView/FormCanned.cs @@ -0,0 +1,206 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryDataModels.Models; + +namespace FishFactoryView +{ + public partial class FormCanned : Form + { + private readonly ILogger _logger; + private readonly ICannedLogic _logic; + private int? _id; + private Dictionary _cannedIngredients; + public int Id { set { _id = value; } } + public FormCanned(ILogger logger, ICannedLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _cannedIngredients = new Dictionary(); + } + private void FormSushi_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка консервы"); + try + { + var view = _logic.ReadElement(new CannedSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.CannedName; + textBoxPrice.Text = view.Price.ToString(); + _cannedIngredients = view.CannedIngredients ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки консервы"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка ингредиента консервы"); + try + { + if (_cannedIngredients != null) + { + dataGridView.Rows.Clear(); + foreach (var sc in _cannedIngredients) + { + dataGridView.Rows.Add(new object[] { sc.Key, sc.Value.Item1.IngredientName, sc.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(FormCannedIngredients)); + if (service is FormCannedIngredients form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.IngredientModel == null) + { + return; + } + _logger.LogInformation("Добавление нового ингредиента: { IngredientName} - { Count}", form.IngredientModel.IngredientName, form.Count); + if (_cannedIngredients.ContainsKey(form.Id)) + { + _cannedIngredients[form.Id] = (form.IngredientModel, + form.Count); + } + else + { + _cannedIngredients.Add(form.Id, (form.IngredientModel, + form.Count)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCannedIngredients)); + if (service is FormCannedIngredients form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _cannedIngredients[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.IngredientModel == null) + { + return; + } + _logger.LogInformation("Изменение ингредиента: { IngredientName} - { Count} ", form.IngredientModel.IngredientName, form.Count); + _cannedIngredients[form.Id] = (form.IngredientModel, 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("Удаление ингредиента: { IngredientName} - { Count} ", + dataGridView.SelectedRows[0].Cells[1].Value); _cannedIngredients?.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 (_cannedIngredients == null || _cannedIngredients.Count == 0) + { + MessageBox.Show("Заполните ингредиенты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение консервы"); + try + { + var model = new CannedBindingModel + { + Id = _id ?? 0, + CannedName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + CannedIngredients = _cannedIngredients + }; + 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 _cannedIngredients) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/FishFactory/FishFactoryView/FormCanned.resx b/FishFactory/FishFactoryView/FormCanned.resx new file mode 100644 index 0000000..bb082f6 --- /dev/null +++ b/FishFactory/FishFactoryView/FormCanned.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/FishFactory/FishFactoryView/FormCannedIngredients.Designer.cs b/FishFactory/FishFactoryView/FormCannedIngredients.Designer.cs new file mode 100644 index 0000000..6e107ce --- /dev/null +++ b/FishFactory/FishFactoryView/FormCannedIngredients.Designer.cs @@ -0,0 +1,123 @@ +namespace FishFactoryView +{ + partial class FormCannedIngredients + { + /// + /// 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.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxIngredient = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelIngredient = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(319, 80); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(80, 22); + this.buttonCancel.TabIndex = 11; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(233, 80); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(80, 22); + this.buttonSave.TabIndex = 10; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(116, 43); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(283, 23); + this.textBoxCount.TabIndex = 9; + // + // comboBoxIngredient + // + this.comboBoxIngredient.FormattingEnabled = true; + this.comboBoxIngredient.Location = new System.Drawing.Point(116, 11); + this.comboBoxIngredient.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxIngredient.Name = "comboBoxIngredient"; + this.comboBoxIngredient.Size = new System.Drawing.Size(282, 23); + this.comboBoxIngredient.TabIndex = 8; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(10, 46); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 7; + this.labelCount.Text = "Количество:"; + // + // labelIngredient + // + this.labelIngredient.AutoSize = true; + this.labelIngredient.Location = new System.Drawing.Point(10, 14); + this.labelIngredient.Name = "labelIngredient"; + this.labelIngredient.Size = new System.Drawing.Size(72, 15); + this.labelIngredient.TabIndex = 6; + this.labelIngredient.Text = "Ингредиент"; + // + // FormCannedIngredients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(410, 115); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxIngredient); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelIngredient); + this.Name = "FormCannedIngredients"; + this.Text = "Ингредиент консервы"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCount; + private ComboBox comboBoxIngredient; + private Label labelCount; + private Label labelIngredient; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCannedIngredients.cs b/FishFactory/FishFactoryView/FormCannedIngredients.cs new file mode 100644 index 0000000..07cef16 --- /dev/null +++ b/FishFactory/FishFactoryView/FormCannedIngredients.cs @@ -0,0 +1,79 @@ +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; + +namespace FishFactoryView +{ + public partial class FormCannedIngredients : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxIngredient.SelectedValue); + } + set + { + comboBoxIngredient.SelectedValue = value; + } + } + public IIngredientModel? IngredientModel + { + 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 FormCannedIngredients(IIngredientLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxIngredient.DisplayMember = "IngredientName"; + comboBoxIngredient.ValueMember = "Id"; + comboBoxIngredient.DataSource = _list; + comboBoxIngredient.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле 'Количество'", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxIngredient.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/FishFactory/FishFactoryView/FormCannedIngredients.resx b/FishFactory/FishFactoryView/FormCannedIngredients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactoryView/FormCannedIngredients.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/FishFactory/FishFactoryView/FormCreateOrder.Designer.cs b/FishFactory/FishFactoryView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..49e19ad --- /dev/null +++ b/FishFactory/FishFactoryView/FormCreateOrder.Designer.cs @@ -0,0 +1,150 @@ +namespace FishFactoryView +{ + 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.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.comboBoxCanned = new System.Windows.Forms.ComboBox(); + this.labelSum = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelName = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(241, 90); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 15; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(153, 90); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 14; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(93, 63); + this.textBoxSum.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(230, 23); + this.textBoxSum.TabIndex = 13; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(93, 36); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(230, 23); + this.textBoxCount.TabIndex = 12; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // comboBoxCanned + // + this.comboBoxCanned.FormattingEnabled = true; + this.comboBoxCanned.Location = new System.Drawing.Point(93, 9); + this.comboBoxCanned.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxCanned.Name = "comboBoxCanned"; + this.comboBoxCanned.Size = new System.Drawing.Size(230, 23); + this.comboBoxCanned.TabIndex = 11; + this.comboBoxCanned.SelectedIndexChanged += new System.EventHandler(this.ComboBoxCanned_SelectedIndexChanged); + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(12, 63); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(48, 15); + this.labelSum.TabIndex = 10; + this.labelSum.Text = "Сумма:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 36); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 9; + this.labelCount.Text = "Количество:"; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 9); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(65, 15); + this.labelName.TabIndex = 8; + this.labelName.Text = "Консервы:"; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(343, 128); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxCanned); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelName); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxSum; + private TextBox textBoxCount; + private ComboBox comboBoxCanned; + private Label labelSum; + private Label labelCount; + private Label labelName; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormCreateOrder.cs b/FishFactory/FishFactoryView/FormCreateOrder.cs new file mode 100644 index 0000000..8a42249 --- /dev/null +++ b/FishFactory/FishFactoryView/FormCreateOrder.cs @@ -0,0 +1,117 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; + +namespace FishFactoryView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ICannedLogic _logicS; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, ICannedLogic logicS, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicS = logicS; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка консервы для заказа"); + try + { + var list = _logicS.ReadList(null); + if (list != null) + { + comboBoxCanned.DisplayMember = "CannedName"; + comboBoxCanned.ValueMember = "Id"; + comboBoxCanned.DataSource = list; + comboBoxCanned.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка консервы"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxCanned.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxCanned.SelectedValue); + var product = _logicS.ReadElement(new CannedSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ComboBoxCanned_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 (comboBoxCanned.SelectedValue == null) + { + MessageBox.Show("Выберите консерву", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + CannedId = Convert.ToInt32(comboBoxCanned.SelectedValue), + CannedName = comboBoxCanned.Text, + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FishFactory/FishFactoryView/FormCreateOrder.resx b/FishFactory/FishFactoryView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactoryView/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/FishFactory/FishFactoryView/FormIngredient.Designer.cs b/FishFactory/FishFactoryView/FormIngredient.Designer.cs new file mode 100644 index 0000000..6329260 --- /dev/null +++ b/FishFactory/FishFactoryView/FormIngredient.Designer.cs @@ -0,0 +1,124 @@ +namespace FishFactoryView +{ + partial class FormIngredient + { + /// + /// 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.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelPrice = new System.Windows.Forms.Label(); + this.labelBlankName = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(200, 73); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 11; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(112, 73); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 10; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(111, 38); + this.textBoxCost.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(183, 23); + this.textBoxCost.TabIndex = 9; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(111, 11); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(329, 23); + this.textBoxName.TabIndex = 8; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(12, 37); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(38, 15); + this.labelPrice.TabIndex = 7; + this.labelPrice.Text = "Цена:"; + // + // labelBlankName + // + this.labelBlankName.AutoSize = true; + this.labelBlankName.Location = new System.Drawing.Point(12, 14); + this.labelBlankName.Name = "labelBlankName"; + this.labelBlankName.Size = new System.Drawing.Size(62, 15); + this.labelBlankName.TabIndex = 6; + this.labelBlankName.Text = "Название:"; + // + // FormIngredient + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(448, 106); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelBlankName); + this.Name = "FormIngredient"; + this.Text = "Ингредиент"; + this.Load += new System.EventHandler(this.FormIngredient_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCost; + private TextBox textBoxName; + private Label labelPrice; + private Label labelBlankName; + + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormIngredient.cs b/FishFactory/FishFactoryView/FormIngredient.cs new file mode 100644 index 0000000..c0e6714 --- /dev/null +++ b/FishFactory/FishFactoryView/FormIngredient.cs @@ -0,0 +1,86 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BusinessLogicsContracts; + +namespace FishFactoryView +{ + public partial class FormIngredient : Form + { + private readonly ILogger _logger; + private readonly IIngredientLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormIngredient(ILogger logger, IIngredientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormIngredient_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение ингредиента"); + var view = _logic.ReadElement(new IngredientSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.IngredientName; + 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 IngredientBindingModel + { + Id = _id ?? 0, + IngredientName = 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/FishFactory/FishFactoryView/FormIngredient.resx b/FishFactory/FishFactoryView/FormIngredient.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactoryView/FormIngredient.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/FishFactory/FishFactoryView/FormIngredients.Designer.cs b/FishFactory/FishFactoryView/FormIngredients.Designer.cs new file mode 100644 index 0000000..c765c43 --- /dev/null +++ b/FishFactory/FishFactoryView/FormIngredients.Designer.cs @@ -0,0 +1,122 @@ +namespace FishFactoryView +{ + partial class FormIngredients + { + /// + /// 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.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(432, 186); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 9; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(432, 160); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 8; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(432, 134); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 7; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(432, 108); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 6; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(426, 348); + this.dataGridView.TabIndex = 5; + // + // FormIngredients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(571, 348); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormIngredients"; + this.Text = "Ингредиенты"; + this.Load += new System.EventHandler(this.FormIngredients_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormIngredients.cs b/FishFactory/FishFactoryView/FormIngredients.cs new file mode 100644 index 0000000..6ea0e76 --- /dev/null +++ b/FishFactory/FishFactoryView/FormIngredients.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; + +namespace FishFactoryView +{ + public partial class FormIngredients : Form + { + private readonly ILogger _logger; + private readonly IIngredientLogic _logic; + public FormIngredients(ILogger logger, IIngredientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormIngredients_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["IngredientName"].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(FormIngredient)); + if (service is FormIngredient 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(FormIngredient)); + if (service is FormIngredient 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 IngredientBindingModel + { + 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/FishFactory/FishFactoryView/FormIngredients.resx b/FishFactory/FishFactoryView/FormIngredients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactoryView/FormIngredients.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/FishFactory/FishFactoryView/FormListCanned.Designer.cs b/FishFactory/FishFactoryView/FormListCanned.Designer.cs new file mode 100644 index 0000000..ffbe7e4 --- /dev/null +++ b/FishFactory/FishFactoryView/FormListCanned.Designer.cs @@ -0,0 +1,122 @@ +namespace FishFactoryView +{ + partial class FormListCanned + { + /// + /// 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.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(426, 345); + this.dataGridView.TabIndex = 10; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(432, 183); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 14; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(432, 157); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 13; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(432, 131); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 12; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(432, 105); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormListCanned + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(570, 345); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormListCanned"; + this.Text = "Список консерв"; + this.Load += new System.EventHandler(this.FormDocuments_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormListCanned.cs b/FishFactory/FishFactoryView/FormListCanned.cs new file mode 100644 index 0000000..949cca1 --- /dev/null +++ b/FishFactory/FishFactoryView/FormListCanned.cs @@ -0,0 +1,104 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; + +namespace FishFactoryView +{ + public partial class FormListCanned : Form + { + private readonly ILogger _logger; + private readonly ICannedLogic _logic; + public FormListCanned(ILogger logger, ICannedLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormDocuments_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["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["CannedIngredients"].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(FormCanned)); + if (service is FormCanned form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCanned)); + if (service is FormCanned form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление консервы"); + try + { + if (!_logic.Delete(new CannedBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления консервы"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FishFactory/FishFactoryView/FormListCanned.resx b/FishFactory/FishFactoryView/FormListCanned.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactoryView/FormListCanned.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/FishFactory/FishFactoryView/FormMain.Designer.cs b/FishFactory/FishFactoryView/FormMain.Designer.cs new file mode 100644 index 0000000..416d7bb --- /dev/null +++ b/FishFactory/FishFactoryView/FormMain.Designer.cs @@ -0,0 +1,182 @@ +namespace FishFactoryView +{ + 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.menuStrip = new System.Windows.Forms.MenuStrip(); + this.reference_booksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ingredientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.cannedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonSetToFinish = new System.Windows.Forms.Button(); + this.buttonSetToDone = new System.Windows.Forms.Button(); + this.buttonSetToWork = new System.Windows.Forms.Button(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip + // + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.reference_booksToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(975, 24); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "menuStrip1"; + // + // reference_booksToolStripMenuItem + // + this.reference_booksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ingredientsToolStripMenuItem, + this.cannedToolStripMenuItem}); + this.reference_booksToolStripMenuItem.Name = "reference_booksToolStripMenuItem"; + this.reference_booksToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.reference_booksToolStripMenuItem.Text = "Справочники"; + // + // ingredientsингредиентыToolStripMenuItem + // + this.ingredientsToolStripMenuItem.Name = "ingredientsToolStripMenuItem"; + this.ingredientsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.ingredientsToolStripMenuItem.Text = "Ингредиенты"; + this.ingredientsToolStripMenuItem.Click += new System.EventHandler(this.IngredientsToolStripMenuItem_Click); + // + // cannedToolStripMenuItem + // + this.cannedToolStripMenuItem.Name = "cannedToolStripMenuItem"; + this.cannedToolStripMenuItem.Size = new System.Drawing.Size(148, 22); + this.cannedToolStripMenuItem.Text = "Консервы"; + this.cannedToolStripMenuItem.Click += new System.EventHandler(this.CannedToolStripMenuItem_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(780, 314); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(170, 58); + this.buttonUpdate.TabIndex = 12; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonSetToFinish + // + this.buttonSetToFinish.Location = new System.Drawing.Point(780, 252); + this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSetToFinish.Name = "buttonSetToFinish"; + this.buttonSetToFinish.Size = new System.Drawing.Size(170, 58); + this.buttonSetToFinish.TabIndex = 11; + this.buttonSetToFinish.Text = "Заказ выдан"; + this.buttonSetToFinish.UseVisualStyleBackColor = true; + this.buttonSetToFinish.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonSetToDone + // + this.buttonSetToDone.Location = new System.Drawing.Point(780, 190); + this.buttonSetToDone.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSetToDone.Name = "buttonSetToDone"; + this.buttonSetToDone.Size = new System.Drawing.Size(170, 58); + this.buttonSetToDone.TabIndex = 10; + this.buttonSetToDone.Text = "Заказ готов"; + this.buttonSetToDone.UseVisualStyleBackColor = true; + this.buttonSetToDone.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonSetToWork + // + this.buttonSetToWork.Location = new System.Drawing.Point(780, 128); + this.buttonSetToWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSetToWork.Name = "buttonSetToWork"; + this.buttonSetToWork.Size = new System.Drawing.Size(170, 58); + this.buttonSetToWork.TabIndex = 9; + this.buttonSetToWork.Text = "Отдать на выполнение"; + this.buttonSetToWork.UseVisualStyleBackColor = true; + this.buttonSetToWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(780, 66); + this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(170, 58); + this.buttonCreateOrder.TabIndex = 8; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 24); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(755, 426); + this.dataGridView.TabIndex = 7; + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(975, 450); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonSetToFinish); + this.Controls.Add(this.buttonSetToDone); + this.Controls.Add(this.buttonSetToWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.Text = "Рыбный завод"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem reference_booksToolStripMenuItem; + private ToolStripMenuItem ingredientsToolStripMenuItem; + private ToolStripMenuItem cannedToolStripMenuItem; + private Button buttonUpdate; + private Button buttonSetToFinish; + private Button buttonSetToDone; + private Button buttonSetToWork; + private Button buttonCreateOrder; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormMain.cs b/FishFactory/FishFactoryView/FormMain.cs new file mode 100644 index 0000000..9ee7eeb --- /dev/null +++ b/FishFactory/FishFactoryView/FormMain.cs @@ -0,0 +1,165 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryDataModels.Enums; + +namespace FishFactoryView +{ + 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["CannedId"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void IngredientsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormIngredients)); + if (service is FormIngredients form) + { + form.ShowDialog(); + } + } + private void CannedToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormListCanned)); + if (service is FormListCanned 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, + CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].Value), + CannedName = dataGridView.SelectedRows[0].Cells["CannedName"].Value.ToString(), + 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, + CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].Value), + CannedName = dataGridView.SelectedRows[0].Cells["CannedName"].Value.ToString(), + 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 ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id, + CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].Value), + CannedName = dataGridView.SelectedRows[0].Cells["CannedName"].Value.ToString(), + 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/FishFactory/FishFactoryView/FormMain.resx b/FishFactory/FishFactoryView/FormMain.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/FishFactory/FishFactoryView/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/FishFactory/FishFactoryView/Program.cs b/FishFactory/FishFactoryView/Program.cs index 5881723..1356160 100644 --- a/FishFactory/FishFactoryView/Program.cs +++ b/FishFactory/FishFactoryView/Program.cs @@ -1,9 +1,20 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using FishFactoryBusinessLogic.BusinessLogics; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.StoragesContracts; +using FishFactoryListImplement.Implements; +using FishFactoryView; + namespace FishFactoryView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// - /// The main entry point for the application. + /// Главная точка входа для приложения. /// [STAThread] static void Main() @@ -11,7 +22,34 @@ namespace FishFactoryView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + + Application.Run(_serviceProvider.GetRequiredService()); + } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } -} \ No newline at end of file +} -- 2.25.1