From b94c1cd942d518866f05bd317813a461046495ed Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Sun, 12 Feb 2023 13:13:30 +0400 Subject: [PATCH] Fix --- Shipyard/Shipyard/FormCreateOrder.Designer.cs | 4 +-- Shipyard/Shipyard/FormCreateOrder.cs | 1 - Shipyard/Shipyard/FormMain.cs | 14 +++++------ Shipyard/Shipyard/FormShip.cs | 12 ++++----- .../BusinessLogics/OrderLogic.cs | 10 ++++++-- .../BindingModels/OrderBindingModel.cs | 1 - .../ViewModels/DetailViewModel.cs | 2 +- .../ViewModels/OrderViewModel.cs | 2 +- .../ViewModels/ShipViewModel.cs | 2 +- .../Implements/OrderStorage.cs | 25 ++++++++++++++----- .../ShipyardListImplement»/Models/Order.cs | 9 ------- 11 files changed, 45 insertions(+), 37 deletions(-) diff --git a/Shipyard/Shipyard/FormCreateOrder.Designer.cs b/Shipyard/Shipyard/FormCreateOrder.Designer.cs index bb5c635..847b23b 100644 --- a/Shipyard/Shipyard/FormCreateOrder.Designer.cs +++ b/Shipyard/Shipyard/FormCreateOrder.Designer.cs @@ -43,9 +43,9 @@ this.labelShip.AutoSize = true; this.labelShip.Location = new System.Drawing.Point(33, 26); this.labelShip.Name = "labelShip"; - this.labelShip.Size = new System.Drawing.Size(68, 20); + this.labelShip.Size = new System.Drawing.Size(69, 20); this.labelShip.TabIndex = 0; - this.labelShip.Text = "Изделие"; + this.labelShip.Text = "Корабль"; // // labelCount // diff --git a/Shipyard/Shipyard/FormCreateOrder.cs b/Shipyard/Shipyard/FormCreateOrder.cs index 54d5ef5..1cb08d9 100644 --- a/Shipyard/Shipyard/FormCreateOrder.cs +++ b/Shipyard/Shipyard/FormCreateOrder.cs @@ -99,7 +99,6 @@ namespace ShipyardView var operationResult = _logicO.CreateOrder(new OrderBindingModel { ShipId = Convert.ToInt32(ComboBoxShips.SelectedValue), - ShipName = ComboBoxShips.Text, Count = Convert.ToInt32(TextBoxCount.Text), Sum = Convert.ToDouble(TextBoxSum.Text) }); diff --git a/Shipyard/Shipyard/FormMain.cs b/Shipyard/Shipyard/FormMain.cs index 67ec6e3..f8c0c91 100644 --- a/Shipyard/Shipyard/FormMain.cs +++ b/Shipyard/Shipyard/FormMain.cs @@ -87,7 +87,7 @@ namespace ShipyardView _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); try { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel{ Id = id , Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value), ShipName = dataGridView.SelectedRows[0].Cells["ShipName"].Value.ToString(),DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value),DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -108,10 +108,10 @@ namespace ShipyardView if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'",id); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); try { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value), ShipName = dataGridView.SelectedRows[0].Cells["ShipName"].Value.ToString(), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value),DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { throw new Exception("Ошибка при сохранении.Дополнительная информация в логах."); @@ -121,7 +121,7 @@ namespace ShipyardView catch (Exception ex) { _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } @@ -130,11 +130,11 @@ namespace ShipyardView { if (dataGridView.SelectedRows.Count == 1) { - int id =Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'",id); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); try { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value), ShipName = dataGridView.SelectedRows[0].Cells["ShipName"].Value.ToString(), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id, Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), ShipId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ShipId"].Value), DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); diff --git a/Shipyard/Shipyard/FormShip.cs b/Shipyard/Shipyard/FormShip.cs index 28bb900..dade8cd 100644 --- a/Shipyard/Shipyard/FormShip.cs +++ b/Shipyard/Shipyard/FormShip.cs @@ -35,7 +35,7 @@ namespace ShipyardView { if (_id.HasValue) { - _logger.LogInformation("Загрузка изделия"); + _logger.LogInformation("Загрузка корабля"); try { var view = _logic.ReadElement(new ShipSearchModel @@ -52,7 +52,7 @@ namespace ShipyardView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки изделия"); + _logger.LogError(ex, "Ошибка загрузки корабля"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); } } @@ -60,7 +60,7 @@ namespace ShipyardView } private void LoadData() { - _logger.LogInformation("Загрузка деталей изделия"); + _logger.LogInformation("Загрузка деталей корабля"); try { if (_shipDetails != null) @@ -75,7 +75,7 @@ namespace ShipyardView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + _logger.LogError(ex, "Ошибка загрузки компонент корабля"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); } } @@ -171,7 +171,7 @@ namespace ShipyardView MessageBox.Show("Заполните компоненты", "Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Сохранение изделия"); + _logger.LogInformation("Сохранение корабля"); try { var model = new ShipBindingModel @@ -192,7 +192,7 @@ namespace ShipyardView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения изделия"); + _logger.LogError(ex, "Ошибка сохранения корабля"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error); } } diff --git a/Shipyard/ShipyardBusinessLogic/BusinessLogics/OrderLogic.cs b/Shipyard/ShipyardBusinessLogic/BusinessLogics/OrderLogic.cs index 189f0a3..cbe07b8 100644 --- a/Shipyard/ShipyardBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/Shipyard/ShipyardBusinessLogic/BusinessLogics/OrderLogic.cs @@ -76,14 +76,19 @@ namespace ShipyardBusinessLogic.BusinessLogics } public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) { - CheckModel(model); + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); 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 (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model); if (_orderStorage.Update(model) == null) { model.Status--; @@ -93,6 +98,7 @@ namespace ShipyardBusinessLogic.BusinessLogics return true; } + public bool TakeOrderInWork(OrderBindingModel model) { return StatusUpdate(model, OrderStatus.Выполняется); diff --git a/Shipyard/ShipyardContracts/BindingModels/OrderBindingModel.cs b/Shipyard/ShipyardContracts/BindingModels/OrderBindingModel.cs index c3768ef..b46f18b 100644 --- a/Shipyard/ShipyardContracts/BindingModels/OrderBindingModel.cs +++ b/Shipyard/ShipyardContracts/BindingModels/OrderBindingModel.cs @@ -12,7 +12,6 @@ namespace ShipyardContracts.BindingModels { public int Id { get; set; } public int ShipId { get; set; } - public string ShipName { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/Shipyard/ShipyardContracts/ViewModels/DetailViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/DetailViewModel.cs index f3ed480..3017778 100644 --- a/Shipyard/ShipyardContracts/ViewModels/DetailViewModel.cs +++ b/Shipyard/ShipyardContracts/ViewModels/DetailViewModel.cs @@ -12,7 +12,7 @@ namespace ShipyardContracts.ViewModels public class DetailViewModel:IDetailModel { public int Id { get; set; } - [DisplayName("Название компонента")] + [DisplayName("Название детали")] public string DetailName { get; set; } = string.Empty; [DisplayName("Цена")] public double Cost { get; set; } diff --git a/Shipyard/ShipyardContracts/ViewModels/OrderViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/OrderViewModel.cs index d7e4250..fc7d012 100644 --- a/Shipyard/ShipyardContracts/ViewModels/OrderViewModel.cs +++ b/Shipyard/ShipyardContracts/ViewModels/OrderViewModel.cs @@ -14,7 +14,7 @@ namespace ShipyardContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } public int ShipId { get; set; } - [DisplayName("Изделие")] + [DisplayName("Корабль")] public string ShipName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } diff --git a/Shipyard/ShipyardContracts/ViewModels/ShipViewModel.cs b/Shipyard/ShipyardContracts/ViewModels/ShipViewModel.cs index 0159d11..07b135f 100644 --- a/Shipyard/ShipyardContracts/ViewModels/ShipViewModel.cs +++ b/Shipyard/ShipyardContracts/ViewModels/ShipViewModel.cs @@ -11,7 +11,7 @@ namespace ShipyardContracts.ViewModels public class ShipViewModel:IShipModel { public int Id { get; set; } - [DisplayName("Название изделия")] + [DisplayName("Название корабля")] public string ShipName { get; set; } = string.Empty; [DisplayName("Цена")] public double Price { get; set; } diff --git a/Shipyard/ShipyardListImplement»/Implements/OrderStorage.cs b/Shipyard/ShipyardListImplement»/Implements/OrderStorage.cs index b1f2b33..c5f540e 100644 --- a/Shipyard/ShipyardListImplement»/Implements/OrderStorage.cs +++ b/Shipyard/ShipyardListImplement»/Implements/OrderStorage.cs @@ -23,7 +23,7 @@ namespace ShipyardListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } return result; } @@ -38,7 +38,7 @@ namespace ShipyardListImplement.Implements { if (order.Id==model.Id) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } } return result; @@ -53,7 +53,7 @@ namespace ShipyardListImplement.Implements { if (model.Id.HasValue && order.Id == model.Id) { - return order.GetViewModel; + return GetViewModel(order); } } return null; @@ -74,7 +74,7 @@ namespace ShipyardListImplement.Implements return null; } _source.Orders.Add(newOrder); - return newOrder.GetViewModel; + return GetViewModel(newOrder); } public OrderViewModel? Update(OrderBindingModel model) { @@ -83,7 +83,7 @@ namespace ShipyardListImplement.Implements if (order.Id == model.Id) { order.Update(model); - return order.GetViewModel; + return GetViewModel(order); } } return null; @@ -96,10 +96,23 @@ namespace ShipyardListImplement.Implements { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return element.GetViewModel; + return GetViewModel(element); } } return null; } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var iceCream in _source.Ships) + { + if (iceCream.Id == order.ShipId) + { + viewModel.ShipName = iceCream.ShipName; + break; + } + } + return viewModel; + } } } diff --git a/Shipyard/ShipyardListImplement»/Models/Order.cs b/Shipyard/ShipyardListImplement»/Models/Order.cs index 882e147..8f6d4bf 100644 --- a/Shipyard/ShipyardListImplement»/Models/Order.cs +++ b/Shipyard/ShipyardListImplement»/Models/Order.cs @@ -16,7 +16,6 @@ namespace ShipyardListImplement.Models { public int Id { get; private set; } public int ShipId { get; private set; } - public string ShipName { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -33,7 +32,6 @@ namespace ShipyardListImplement.Models { Id = model.Id, ShipId = model.ShipId, - ShipName = model.ShipName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -47,20 +45,13 @@ namespace ShipyardListImplement.Models { return; } - Id = model.Id; - ShipId = model.ShipId; - ShipName = model.ShipName; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { Id = Id, ShipId = ShipId, - ShipName = ShipName, Count = Count, Sum = Sum, Status = Status,