From 534316c2bda6d427e7d09eb2db5297061c70c59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A4=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sun, 5 May 2024 19:03:58 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B8=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormImplementer.Designer.cs | 4 +- .../CarpentryWorkshop/FormMain.Designer.cs | 4 -- .../CarpentryWorkshop/FormMain.cs | 3 - .../BusinessLogics/OrderLogic.cs | 57 +++++++++++-------- .../CarpentryWorkshopRestApi.csproj | 1 + .../Controllers/ImplementerController.cs | 4 +- .../CarpentryWorkshopRestApi/Program.cs | 2 + 7 files changed, 38 insertions(+), 37 deletions(-) diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormImplementer.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormImplementer.Designer.cs index a749799..6ac6823 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormImplementer.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormImplementer.Designer.cs @@ -108,8 +108,7 @@ // // buttonSave // - buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonSave.Location = new Point(10, 342); + buttonSave.Location = new Point(205, 250); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(140, 53); buttonSave.TabIndex = 8; @@ -119,7 +118,6 @@ // // buttonCancel // - buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonCancel.Location = new Point(346, 250); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(94, 29); diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs index 0aaf4b2..b91e7c9 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMain.Designer.cs @@ -128,12 +128,8 @@ // // dataGridView // - dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - dataGridView.BackgroundColor = SystemColors.ButtonHighlight; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.EnableHeadersVisualStyles = false; dataGridView.Location = new Point(1, 32); - dataGridView.MultiSelect = false; dataGridView.Name = "dataGridView"; dataGridView.RowTemplate.Height = 25; dataGridView.Size = new Size(755, 243); diff --git a/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs b/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs index 1aa93ed..12da52b 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/FormMain.cs @@ -34,11 +34,8 @@ namespace CarpentryWorkshopView { dataGridView.DataSource = list; dataGridView.Columns["WoodId"].Visible = false; - dataGridView.Columns["WoodName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка изделий"); } diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 1b0ab25..439f21e 100644 --- a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -12,7 +12,7 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - static readonly object blocking = new object(); + static readonly object locker = new object(); public OrderLogic(ILogger logger, IOrderStorage orderStorage) { @@ -64,34 +64,41 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics return true; } - public bool ChangeStatus(OrderBindingModel model, OrderStatus status) - { - CheckModel(model); - var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + public bool ChangeStatus(OrderBindingModel model, OrderStatus status) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != status - 1) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); + } if (element.ImplementerId.HasValue) model.ImplementerId = element.ImplementerId; - if (element == null) - { - _logger.LogWarning("Read operation failed"); - return false; - } - if (element.Status != status - 1) - { - _logger.LogWarning("Status change operation failed"); - throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); - } - model.Status = status; - if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; - _orderStorage.Update(model); - return true; - } - - public bool TakeOrderInWork(OrderBindingModel model) - { - lock (blocking) + OrderStatus oldStatus = model.Status; + model.Status = status; + if (model.Status == OrderStatus.Выдан) + model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) { - return ChangeStatus(model, OrderStatus.Выполняется); + model.Status = oldStatus; + _logger.LogWarning("Update operation failed"); + return false; } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + lock (locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } } public bool FinishOrder(OrderBindingModel model) diff --git a/CarpentryWorkshop/CarpentryWorkshopRestApi/CarpentryWorkshopRestApi.csproj b/CarpentryWorkshop/CarpentryWorkshopRestApi/CarpentryWorkshopRestApi.csproj index f2b88ce..12f19e6 100644 --- a/CarpentryWorkshop/CarpentryWorkshopRestApi/CarpentryWorkshopRestApi.csproj +++ b/CarpentryWorkshop/CarpentryWorkshopRestApi/CarpentryWorkshopRestApi.csproj @@ -17,6 +17,7 @@ + diff --git a/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ImplementerController.cs b/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ImplementerController.cs index 1b9fdc3..80c6d70 100644 --- a/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ImplementerController.cs +++ b/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ImplementerController.cs @@ -1,9 +1,9 @@ using DocumentFormat.OpenXml.Office2010.Excel; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using CarpentryWorkshopContracts.BindingModel; +using CarpentryWorkshopContracts.BindingModels; using CarpentryWorkshopContracts.BusinessLogicsContracts; -using CarpentryWorkshopContracts.SearchModel; +using CarpentryWorkshopContracts.SearchModels; using CarpentryWorkshopContracts.ViewModels; using CarpentryWorkshopDataModels.Enums; diff --git a/CarpentryWorkshop/CarpentryWorkshopRestApi/Program.cs b/CarpentryWorkshop/CarpentryWorkshopRestApi/Program.cs index f2ec57a..1116a1f 100644 --- a/CarpentryWorkshop/CarpentryWorkshopRestApi/Program.cs +++ b/CarpentryWorkshop/CarpentryWorkshopRestApi/Program.cs @@ -12,9 +12,11 @@ builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle