Merge branch 'LabWork_06' into LabWork_07

This commit is contained in:
kamilia 2024-05-19 14:38:27 +04:00
commit e7dc91572b
6 changed files with 77 additions and 23 deletions

View File

@ -66,7 +66,7 @@ namespace AircraftPlantListImplement.Implements
return result;
}
if (model.ClientId.HasValue && !model.Id.HasValue)
else if(model.ClientId.HasValue && !model.Id.HasValue)
{
foreach (var order in _source.Orders)
{
@ -74,6 +74,27 @@ namespace AircraftPlantListImplement.Implements
}
}
else if (model.ImplementerId.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.ImplementerId == model.ImplementerId)
{
result.Add(GetViewModel(order));
}
}
}
else if (model.Status != null)
{
foreach (var order in _source.Orders)
{
if (order.Status.Equals(model.Status))
{
result.Add(GetViewModel(order));
}
}
}
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
@ -90,7 +111,7 @@ namespace AircraftPlantListImplement.Implements
/// <returns></returns>
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
if (!model.Id.HasValue && !model.ImplementerId.HasValue)
{
return null;
}
@ -101,6 +122,14 @@ namespace AircraftPlantListImplement.Implements
{
return GetViewModel(order);
}
if (model.ImplementerId.HasValue && model.Status != null && order.ImplementerId == model.ImplementerId && order.Status.Equals(model.Status))
{
return GetViewModel(order);
}
if (model.ImplementerId.HasValue && model.Status == null && order.ImplementerId == model.ImplementerId)
{
return GetViewModel(order);
}
}
return null;
}

View File

@ -30,6 +30,8 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
/// </summary>
private readonly IOrderStorage _orderStorage;
static readonly object locker = new();
/// <summary>
/// Взаимодействие с хранилищем клиентов
/// </summary>
@ -132,9 +134,13 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool TakeOrderInWork(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выполняется);
lock (locker)
{
return StatusUpdate(model, OrderStatus.Выполняется);
}
}
/// <summary>
@ -211,6 +217,10 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
model.Status = newStatus;
if (element.ImplementerId.HasValue)
{
model.ImplementerId = element.ImplementerId;
}
if (model.Status == OrderStatus.Готов)
{
model.DateImplement = DateTime.Now;

View File

@ -84,6 +84,9 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
{
Id = order.Id
});
// отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
// кто-то мог уже перехватить заказ, игнорируем ошибку
catch (InvalidOperationException ex)
@ -97,8 +100,6 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
throw;
}
// отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
});
}

View File

@ -38,17 +38,6 @@ namespace AircraftPlantDatabaseImplement.Implements
.ToList();
}
if (model.Status.HasValue)
{
return context.Orders
.Include(x => x.Plane)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => x.Status == model.Status)
.Select(x => x.GetViewModel)
.ToList();
}
if (model.ClientId.HasValue)
{
return context.Orders
@ -59,7 +48,16 @@ namespace AircraftPlantDatabaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
if (model.Status.HasValue)
{
return context.Orders
.Include(x => x.Plane)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => x.Status == model.Status)
.Select(x => x.GetViewModel)
.ToList();
}
return context.Orders
.Include(x => x.Plane)
.Include(x => x.Client)
@ -104,7 +102,6 @@ namespace AircraftPlantDatabaseImplement.Implements
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)
?.GetViewModel;
}
return null;
}

View File

@ -28,29 +28,47 @@ namespace AircraftPlantFileImplement.Implements
{
return new();
}
if (model.DateFrom.HasValue)
else if (model.DateFrom.HasValue)
{
return _source.Orders
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => GetViewModel(x))
.ToList();
}
if (model.ClientId.HasValue && !model.Id.HasValue)
else if (model.ClientId.HasValue && !model.Id.HasValue)
{
return _source.Orders
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.ImplementerId.HasValue)
{
return _source.Orders
.Where(x => x.ImplementerId == model.ImplementerId)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.Status != null)
{
return _source.Orders
.Where(x => x.Status.Equals(model.Status))
.Select(x => x.GetViewModel)
.ToList();
}
return _source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
if (!model.Id.HasValue && !model.ImplementerId.HasValue)
{
return null;
}
return GetViewModel(_source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
var order = _source.Orders.FirstOrDefault(x =>
model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status)
|| model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId
|| model.Id.HasValue && x.Id == model.Id);
return order?.GetViewModel != null ? order.GetViewModel : null;
}
public OrderViewModel? Insert(OrderBindingModel model)
{

View File

@ -118,7 +118,6 @@ namespace AircraftPlantView
/// <param name="e"></param>
private void ЗапускРаботToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic )) as IImplementerLogic)!, _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
}