Compare commits

...

3 Commits

Author SHA1 Message Date
7b6d7fdfae Merge branch 'Lab2_Main' into lab3 2023-05-04 15:02:50 +04:00
artiogf
e6bea06856 Lab2_Main_Fix 2023-05-02 22:16:49 +04:00
artiogf
51e32cc9f9 Lab2_Main_Fix 2023-05-02 21:54:16 +04:00
14 changed files with 140 additions and 172 deletions

View File

@ -13,129 +13,124 @@ using System.Threading.Tasks;
namespace CarpentryWorkshopBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ 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;
}
public bool CreateOrder(OrderBindingModel model)
{
_orderStorage.Insert(new OrderBindingModel
{
WoodId = model.WoodId,
WoodName = model.WoodName,
Count = model.Count,
Sum = model.Sum,
Status = OrderStatus.Принят,
DateCreate = DateTime.Now
}); ;
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
var order = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (order == null)
{
throw new Exception("Элемент не найден");
}
if (order.Status.ToString() != "Принят")
{
throw new Exception("Заказ не в статусе \"Принят\"");
}
_orderStorage.Update(new OrderBindingModel
{
Id = order.Id,
WoodId = order.WoodId,
WoodName = order.WoodName,
Count = order.Count,
Sum = order.Sum,
DateCreate = order.DateCreate,
Status = OrderStatus.Выполняется
});
return true;
}
public bool FinishOrder(OrderBindingModel model)
{
var order = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (order == null)
{
throw new Exception("Не найден заказ");
}
if (order.Status.ToString() != "Выполняется")
{
throw new Exception("Заказ не в статусе \"Выполняется\"");
}
_orderStorage.Update(new OrderBindingModel
{
Id = order.Id,
WoodId = order.WoodId,
WoodName = order.WoodName,
Count = order.Count,
Sum = order.Sum,
DateCreate = order.DateCreate,
DateImplement = DateTime.Now,
Status = OrderStatus.Готов
});
return true;
}
public bool DeliveryOrder(OrderBindingModel model)
{
var order = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (order == null)
{
throw new Exception("Не найден заказ");
}
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ 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;
}
public bool CreateOrder(OrderBindingModel model)
{
_orderStorage.Insert(new OrderBindingModel
{
WoodId = model.WoodId,
WoodName = model.WoodName,
Count = model.Count,
Sum = model.Sum,
Status = OrderStatus.Принят,
DateCreate = DateTime.Now
}); ;
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
var order = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (order == null)
{
throw new Exception("Элемент не найден");
}
if (order.Status.ToString() != "Принят")
{
throw new Exception("Заказ не в статусе \"Принят\"");
}
_orderStorage.Update(new OrderBindingModel
{
Id = order.Id,
WoodId = order.WoodId,
WoodName = order.WoodName,
Count = order.Count,
Sum = order.Sum,
DateCreate = order.DateCreate,
if (order.Status.ToString() != "Готов")
{
throw new Exception("Заказ не в статусе \"Готов\"");
}
Status = OrderStatus.Выполняется
});
return true;
}
public bool FinishOrder(OrderBindingModel model)
{
var order = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (order == null)
{
throw new Exception("Не найден заказ");
}
if (order.Status.ToString() != "Выполняется")
{
throw new Exception("Заказ не в статусе \"Выполняется\"");
}
_orderStorage.Update(new OrderBindingModel
{
Id = order.Id,
WoodId = order.WoodId,
WoodName = order.WoodName,
Count = order.Count,
Sum = order.Sum,
DateCreate = order.DateCreate,
DateImplement = DateTime.Now,
Status = OrderStatus.Готов
});
return true;
}
public bool DeliveryOrder(OrderBindingModel model)
{
var order = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (order == null)
{
throw new Exception("Не найден заказ");
}
_orderStorage.Update(new OrderBindingModel
{
Id = order.Id,
WoodId = order.WoodId,
WoodName = order.WoodName,
Count = order.Count,
Sum = order.Sum,
DateCreate = order.DateCreate,
DateImplement = order.DateImplement,
Status = OrderStatus.Выдан
});
return true;
if (order.Status.ToString() != "Готов")
{
throw new Exception("Заказ не в статусе \"Готов\"");
}
}
_orderStorage.Update(new OrderBindingModel
{
Id = order.Id,
WoodId = order.WoodId,
WoodName = order.WoodName,
Count = order.Count,
Sum = order.Sum,
DateCreate = order.DateCreate,
DateImplement = order.DateImplement,
Status = OrderStatus.Выдан
});
return true;
}
}
}
}

View File

@ -88,11 +88,11 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics
}
if (string.IsNullOrEmpty(model.WoodName))
{
throw new ArgumentNullException("Нет названия компонента", nameof(model.WoodName));
throw new ArgumentNullException("Нет названия изделия", nameof(model.WoodName));
}
if (model.Price <= 0)
{
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Price));
throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Wood. WoodName:{WoodName}. Cost:{ Cost}. Id: { Id}", model.WoodName, model.Price, model.Id);
var element = _woodStorage.GetElement(new WoodSearchModel
@ -101,7 +101,7 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Компонент с таким названием уже есть");
throw new InvalidOperationException("Изделие с таким названием уже есть");
}
}
}

View File

@ -1,7 +0,0 @@
namespace CarpentryWorkshopBusinessLogic
{
public class Class1
{
}
}

View File

@ -16,6 +16,5 @@ namespace CarpentryWorkshopContracts.BusinessLogicsContracts
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
bool DeliveryOrder(OrderBindingModel model);
}
}

View File

@ -1,7 +0,0 @@
namespace CarpentryWorkshopContracts
{
public class Class1
{
}
}

View File

@ -11,5 +11,4 @@ namespace CarpentryWorkshopContracts.SearchModels
public int? Id { get; set; }
public string? ComponentName { get; set; }
}
}

View File

@ -11,5 +11,4 @@ namespace CarpentryWorkshopContracts.SearchModels
public int? Id { get; set; }
public string? WoodName { get; set; }
}
}

View File

@ -16,5 +16,4 @@ namespace CarpentryWorkshopContracts.ViewModels
[DisplayName("Цена")]
public double Cost { get; set; }
}
}

View File

@ -6,4 +6,7 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
</Project>

View File

@ -10,11 +10,7 @@ namespace CarpentryWorkshopDataModels.Models
public interface IOrderModel : IId
{
int WoodId { get; }
string WoodName
{
get;
}
string WoodName { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }

View File

@ -14,14 +14,14 @@ namespace CarpentryWorkshopFileImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; set; }
public int WoodId { get; set; }
public string WoodName { 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; private set; }
public int WoodId { get; private set; }
public string WoodName { get; private set; }
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 static Order? Create(OrderBindingModel model)
{
if (model == null)
@ -65,14 +65,7 @@ namespace CarpentryWorkshopFileImplement.Models
{
return;
}
Id = model.Id;
WoodId = model.WoodId;
WoodName = model.WoodName;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{

View File

@ -13,14 +13,14 @@ namespace CarpentryWorkshopListImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; set; }
public int WoodId { get; set; }
public string WoodName { get; set; } = string.Empty;
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; }
public DateTime DateCreate { get; set; }
public DateTime? DateImplement { get; set; }
public int Id { get; private set; }
public int WoodId { get; private set; }
public string WoodName { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; }
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)

View File

@ -27,5 +27,4 @@
<ProjectReference Include="..\CarpentryWorkshopFileImplement\CarpentryWorkshopFileImplement.csproj" />
<ProjectReference Include="..\CarpentryWorkshopListImplement\CarpentryWorkshopListImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -100,7 +100,7 @@
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.ButtonSave);
this.Name = "FormComponent";
this.Text = "FormComponent";
this.Text = "Форма Компонента";
this.Load += new System.EventHandler(this.FormComponent_Load);
this.ResumeLayout(false);
this.PerformLayout();