Лаб_2сложн

This commit is contained in:
yuliya.mavrina@internet.ru 2024-05-19 23:49:58 +03:00
parent 80550c60fd
commit 136591c7a7
5 changed files with 497 additions and 516 deletions

View File

@ -10,6 +10,7 @@ using System.Windows.Forms;
using RenovationWorkContracts.BindingModels;
using RenovationWorkContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using RenovationWorkDataModels.Enums;
namespace RenovationWorkView
{
@ -76,6 +77,19 @@ namespace RenovationWorkView
}
}
private OrderBindingModel CreateBindingModel(int id, bool isDone = false)
{
return new OrderBindingModel
{
Id = id,
RepairId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["RepairId"].Value),
Status = Enum.Parse<OrderStatus>(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()),
};
}
private void buttonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
@ -84,7 +98,7 @@ namespace RenovationWorkView
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id));
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
@ -108,7 +122,7 @@ namespace RenovationWorkView
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id));
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
@ -131,7 +145,7 @@ namespace RenovationWorkView
_logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel {Id = id});
var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id));
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");

View File

@ -49,13 +49,13 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
}
private bool StatusUpdate(OrderBindingModel model, OrderStatus status)
{
CheckModel(model);
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (element == null)
{
_logger.LogWarning("Read operation failed");
return false;
}
CheckModel(element);
if (element.Status != status - 1)
{
_logger.LogWarning("Status change operation failed");
@ -116,34 +116,6 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
{
return;
}
if (model.RepairId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор документа", nameof(model.RepairId));
}
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. Count: {Count}. Sum: {Sum}. Id: {Id}", model.Count, model.Sum, model.Id);
}
private void CheckModel(OrderViewModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.RepairId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор документа", nameof(model.RepairId));
}
if (model.Count <= 0)
{
throw new ArgumentNullException("Количество работ в заказе должно быть больше 0", nameof(model.Count));

View File

@ -173,4 +173,3 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
}
}
}

View File

@ -81,14 +81,10 @@ namespace RenovationWorkFileImplement.Implements
{
if (model == null)
return null;
foreach (var Repair in source.Repairs)
{
if (Repair.Id == model.RepairId)
{
model.RepairName = Repair.RepairName;
break;
}
}
var repair = source.Repairs.FirstOrDefault(x => (x.Id == model.RepairId));
if (repair == null)
return model;
model.RepairName = repair.RepairName;
return model;
}
}