что-то делается
This commit is contained in:
parent
0763ef71df
commit
b4a88a1231
@ -11,6 +11,8 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ConfectioneryContracts.StoragesContracts
|
namespace ConfectioneryContracts.StoragesContracts
|
||||||
{
|
{
|
||||||
internal interface IOrderStorage
|
public interface IOrderStorage
|
||||||
{
|
{
|
||||||
List<OrderViewModel> GetFullList();
|
List<OrderViewModel> GetFullList();
|
||||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||||
|
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ConfectioneryContracts.StoragesContracts
|
namespace ConfectioneryContracts.StoragesContracts
|
||||||
{
|
{
|
||||||
internal interface IPastryStorage
|
public interface IPastryStorage
|
||||||
{
|
{
|
||||||
List<PastryViewModel> GetFullList();
|
List<PastryViewModel> GetFullList();
|
||||||
List<PastryViewModel> GetFilteredList(PastrySearchModel model);
|
List<PastryViewModel> GetFilteredList(PastrySearchModel model);
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -9,34 +9,127 @@ using ConfectioneryContracts.ViewModels;
|
|||||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||||
using ConfectioneryContracts.StoragesContracts;
|
using ConfectioneryContracts.StoragesContracts;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using ConfectioneryDataModels.Enums;
|
||||||
|
|
||||||
namespace ConfectioneryBusinessLogic
|
namespace ConfectioneryBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
internal class OrderLogic : IOrderLogic
|
public class OrderLogic : IOrderLogic
|
||||||
{
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
|
||||||
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_orderStorage = orderStorage;
|
||||||
|
}
|
||||||
|
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
CheckModel(model);
|
||||||
}
|
if (model.Status != OrderStatus.Неизвестен)
|
||||||
|
{
|
||||||
public bool DeliveryOrder(OrderBindingModel model)
|
_logger.LogWarning("Invalid order status");
|
||||||
{
|
return false;
|
||||||
throw new NotImplementedException();
|
}
|
||||||
}
|
model.Status = OrderStatus.Принят;
|
||||||
|
if (_orderStorage.Insert(model) == null)
|
||||||
public bool FinishOrder(OrderBindingModel model)
|
{
|
||||||
{
|
_logger.LogWarning("Insert operation failed");
|
||||||
throw new NotImplementedException();
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
_logger.LogInformation("ReadList. OrderId: {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 TakeOrderInWork(OrderBindingModel model)
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool FinishOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return ChangeStatus(model, OrderStatus.Готов);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeliveryOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return ChangeStatus(model, OrderStatus.Выдан);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (model.PastryId <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Некорректный идентификатор мороженого", nameof(model.PastryId));
|
||||||
|
}
|
||||||
|
if (model.Count <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("В заказе должно быть хотя бы одно мороженое", nameof(model.Count));
|
||||||
|
}
|
||||||
|
if (model.Sum <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. PastryId: {PastryId}. PastryCount: {Count}", model.Id, model.Sum,
|
||||||
|
model.PastryId, model.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Change status operation failed. Order not found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (order.Status + 1 != newStatus)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Change status operation failed. Incorrect new status: {newStatus}. Current status: {currStatus}",
|
||||||
|
newStatus, order.Status);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
model.PastryId = order.PastryId;
|
||||||
|
model.Count = order.Count;
|
||||||
|
model.Sum = order.Sum;
|
||||||
|
model.DateCreate = order.DateCreate;
|
||||||
|
model.Status = newStatus;
|
||||||
|
if (model.Status == OrderStatus.Готов)
|
||||||
|
{
|
||||||
|
model.DateImplement = DateTime.Now;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
model.DateImplement = order.DateImplement;
|
||||||
|
}
|
||||||
|
if (_orderStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Change status operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,31 +12,113 @@ using Microsoft.Extensions.Logging;
|
|||||||
|
|
||||||
namespace ConfectioneryBusinessLogic.BusinessLogics
|
namespace ConfectioneryBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
internal class PastryLogic : IPastryLogic
|
public class PastryLogic : IPastryLogic
|
||||||
{
|
{
|
||||||
public bool Create(PastryBindingModel model)
|
private readonly ILogger _logger;
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Delete(PastryBindingModel model)
|
private readonly IPastryStorage _iceCreamStorage;
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PastryViewModel? ReadElement(PastrySearchModel model)
|
public PastryLogic(ILogger<PastryLogic> logger, IPastryStorage iceCreamStorage)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
_logger = logger;
|
||||||
|
_iceCreamStorage = iceCreamStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PastryViewModel>? ReadList(PastrySearchModel? model)
|
public List<PastryViewModel>? ReadList(PastrySearchModel? model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
_logger.LogInformation("ReadList. PastryName: {PastryName}. Id: {Id}", model?.PastryName, model?.Id);
|
||||||
|
var list = model == null ? _iceCreamStorage.GetFullList() : _iceCreamStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PastryViewModel? ReadElement(PastrySearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. PastryName: {PastryName}. Id: {Id}", model.PastryName, model.Id);
|
||||||
|
var element = _iceCreamStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(PastryBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_iceCreamStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Update(PastryBindingModel model)
|
public bool Update(PastryBindingModel model)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
CheckModel(model);
|
||||||
|
if (_iceCreamStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(PastryBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id: {Id}", model.Id);
|
||||||
|
if (_iceCreamStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(PastryBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.PastryName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия мороженого", nameof(model.PastryName));
|
||||||
|
}
|
||||||
|
if (model.Price <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Цена мороженого должна быть больше 0", nameof(model.Price));
|
||||||
|
}
|
||||||
|
if (model.PastryComponents == null || model.PastryComponents.Count == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Мороженое должно состоять хотя бы из одного компонента");
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Pastry. PastryName: {PastryName}. Price: {Price}. Id: {Id}", model.PastryName, model.Price, model.Id);
|
||||||
|
var element = _iceCreamStorage.GetElement(new PastrySearchModel
|
||||||
|
{
|
||||||
|
PastryName = model.PastryName
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Мороженое с таким названием уже есть");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ConfectioneryListImplement.Implements
|
namespace ConfectioneryListImplement.Implements
|
||||||
{
|
{
|
||||||
internal class ComponentStorage : IComponentStorage
|
public class ComponentStorage : IComponentStorage
|
||||||
{
|
{
|
||||||
private readonly DataListSingleton _source;
|
private readonly DataListSingleton _source;
|
||||||
public ComponentStorage()
|
public ComponentStorage()
|
||||||
|
@ -6,6 +6,11 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ConfectionaryContracts\ConfectioneryContracts.csproj" />
|
<ProjectReference Include="..\ConfectionaryContracts\ConfectioneryContracts.csproj" />
|
||||||
<ProjectReference Include="..\ConfectionaryDataModels\ConfectioneryDataModels.csproj" />
|
<ProjectReference Include="..\ConfectionaryDataModels\ConfectioneryDataModels.csproj" />
|
||||||
|
@ -11,12 +11,12 @@ namespace ConfectioneryListImplement.Models
|
|||||||
private static DataListSingleton? _instance;
|
private static DataListSingleton? _instance;
|
||||||
public List<Component> Components { get; set; }
|
public List<Component> Components { get; set; }
|
||||||
public List<Order> Orders { get; set; }
|
public List<Order> Orders { get; set; }
|
||||||
public List<Pastry> Pastrys { get; set; }
|
public List<Pastry> Pastries { get; set; }
|
||||||
private DataListSingleton()
|
private DataListSingleton()
|
||||||
{
|
{
|
||||||
Components = new List<Component>();
|
Components = new List<Component>();
|
||||||
Orders = new List<Order>();
|
Orders = new List<Order>();
|
||||||
Pastrys = new List<Pastry>();
|
Pastries = new List<Pastry>();
|
||||||
}
|
}
|
||||||
public static DataListSingleton GetInstance()
|
public static DataListSingleton GetInstance()
|
||||||
{
|
{
|
||||||
|
122
Confectionery/ConfectioneryListImplement/OrderStorage.cs
Normal file
122
Confectionery/ConfectioneryListImplement/OrderStorage.cs
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
|
using ConfectioneryContracts.SearchModels;
|
||||||
|
using ConfectioneryContracts.StoragesContracts;
|
||||||
|
using ConfectioneryContracts.ViewModels;
|
||||||
|
using ConfectioneryListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ConfectioneryListImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
|
||||||
|
public OrderStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<OrderViewModel>();
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
result.Add(AddPastryName(order.GetViewModel));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<OrderViewModel>();
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
result.Add(AddPastryName(order.GetViewModel));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
return AddPastryName(order.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (model.Id <= order.Id)
|
||||||
|
{
|
||||||
|
model.Id = order.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Orders.Add(newOrder);
|
||||||
|
return AddPastryName(newOrder.GetViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
order.Update(model);
|
||||||
|
return AddPastryName(order.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Orders.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Orders[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Orders[i];
|
||||||
|
_source.Orders.RemoveAt(i);
|
||||||
|
return AddPastryName(element.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OrderViewModel AddPastryName(OrderViewModel model)
|
||||||
|
{
|
||||||
|
var selectedPastry = _source.Pastries.Find(pastry => pastry.Id == model.PastryId);
|
||||||
|
if (selectedPastry != null)
|
||||||
|
{
|
||||||
|
model.PastryName = selectedPastry.PastryName;
|
||||||
|
}
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
114
Confectionery/ConfectioneryListImplement/PastryStorage.cs
Normal file
114
Confectionery/ConfectioneryListImplement/PastryStorage.cs
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
using ConfectioneryContracts.StoragesContracts;
|
||||||
|
using ConfectioneryContracts.ViewModels;
|
||||||
|
using ConfectioneryContracts.SearchModels;
|
||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
|
using ConfectioneryListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ConfectioneryListImplement.Implements
|
||||||
|
{
|
||||||
|
public class PastryStorage : IPastryStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
|
||||||
|
public PastryStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PastryViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<PastryViewModel>();
|
||||||
|
foreach (var pastry in _source.Pastries)
|
||||||
|
{
|
||||||
|
result.Add(pastry.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PastryViewModel> GetFilteredList(PastrySearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<PastryViewModel>();
|
||||||
|
if (string.IsNullOrEmpty(model.PastryName))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var pastry in _source.Pastries)
|
||||||
|
{
|
||||||
|
if (pastry.PastryName.Contains(model.PastryName))
|
||||||
|
{
|
||||||
|
result.Add(pastry.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PastryViewModel? GetElement(PastrySearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.PastryName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var pastry in _source.Pastries)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.PastryName) &&
|
||||||
|
pastry.PastryName == model.PastryName) ||
|
||||||
|
(model.Id.HasValue && pastry.Id == model.Id))
|
||||||
|
{
|
||||||
|
return pastry.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PastryViewModel? Insert(PastryBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var pastry in _source.Pastries)
|
||||||
|
{
|
||||||
|
if (model.Id <= pastry.Id)
|
||||||
|
{
|
||||||
|
model.Id = pastry.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newPastry = Pastry.Create(model);
|
||||||
|
if (newPastry == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Pastries.Add(newPastry);
|
||||||
|
return newPastry.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PastryViewModel? Update(PastryBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var pastry in _source.Pastries)
|
||||||
|
{
|
||||||
|
if (pastry.Id == model.Id)
|
||||||
|
{
|
||||||
|
pastry.Update(model);
|
||||||
|
return pastry.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PastryViewModel? Delete(PastryBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Pastries.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Pastries[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Pastries[i];
|
||||||
|
_source.Pastries.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,8 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
28
Confectionery/ConfectioneryView/FormMain.Designer.cs
generated
28
Confectionery/ConfectioneryView/FormMain.Designer.cs
generated
@ -32,14 +32,14 @@
|
|||||||
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.dataGridView1 = new System.Windows.Forms.DataGridView();
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
this.ButtonCreateOrder = new System.Windows.Forms.Button();
|
this.ButtonCreateOrder = new System.Windows.Forms.Button();
|
||||||
this.ButtonTakeOrderInWork = new System.Windows.Forms.Button();
|
this.ButtonTakeOrderInWork = new System.Windows.Forms.Button();
|
||||||
this.ButtonOrderReady = new System.Windows.Forms.Button();
|
this.ButtonOrderReady = new System.Windows.Forms.Button();
|
||||||
this.ButtonIssuedOrder = new System.Windows.Forms.Button();
|
this.ButtonIssuedOrder = new System.Windows.Forms.Button();
|
||||||
this.ButtonRef = new System.Windows.Forms.Button();
|
this.ButtonRef = new System.Windows.Forms.Button();
|
||||||
this.menuStrip1.SuspendLayout();
|
this.menuStrip1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// menuStrip1
|
// menuStrip1
|
||||||
@ -67,22 +67,24 @@
|
|||||||
this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
||||||
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||||
this.компонентыToolStripMenuItem.Text = "Компоненты";
|
this.компонентыToolStripMenuItem.Text = "Компоненты";
|
||||||
|
this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// изделияToolStripMenuItem
|
// изделияToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
|
this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
|
||||||
this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||||
this.изделияToolStripMenuItem.Text = "Изделия";
|
this.изделияToolStripMenuItem.Text = "Изделия";
|
||||||
|
this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// dataGridView1
|
// dataGridView
|
||||||
//
|
//
|
||||||
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
this.dataGridView1.Location = new System.Drawing.Point(13, 31);
|
this.dataGridView.Location = new System.Drawing.Point(13, 31);
|
||||||
this.dataGridView1.Name = "dataGridView1";
|
this.dataGridView.Name = "dataGridView";
|
||||||
this.dataGridView1.RowHeadersWidth = 51;
|
this.dataGridView.RowHeadersWidth = 51;
|
||||||
this.dataGridView1.RowTemplate.Height = 29;
|
this.dataGridView.RowTemplate.Height = 29;
|
||||||
this.dataGridView1.Size = new System.Drawing.Size(968, 526);
|
this.dataGridView.Size = new System.Drawing.Size(968, 526);
|
||||||
this.dataGridView1.TabIndex = 1;
|
this.dataGridView.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// ButtonCreateOrder
|
// ButtonCreateOrder
|
||||||
//
|
//
|
||||||
@ -144,7 +146,7 @@
|
|||||||
this.Controls.Add(this.ButtonOrderReady);
|
this.Controls.Add(this.ButtonOrderReady);
|
||||||
this.Controls.Add(this.ButtonTakeOrderInWork);
|
this.Controls.Add(this.ButtonTakeOrderInWork);
|
||||||
this.Controls.Add(this.ButtonCreateOrder);
|
this.Controls.Add(this.ButtonCreateOrder);
|
||||||
this.Controls.Add(this.dataGridView1);
|
this.Controls.Add(this.dataGridView);
|
||||||
this.Controls.Add(this.menuStrip1);
|
this.Controls.Add(this.menuStrip1);
|
||||||
this.MainMenuStrip = this.menuStrip1;
|
this.MainMenuStrip = this.menuStrip1;
|
||||||
this.Name = "FormMain";
|
this.Name = "FormMain";
|
||||||
@ -152,7 +154,7 @@
|
|||||||
this.Load += new System.EventHandler(this.FormMain_Load);
|
this.Load += new System.EventHandler(this.FormMain_Load);
|
||||||
this.menuStrip1.ResumeLayout(false);
|
this.menuStrip1.ResumeLayout(false);
|
||||||
this.menuStrip1.PerformLayout();
|
this.menuStrip1.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
@ -164,7 +166,7 @@
|
|||||||
private ToolStripMenuItem справочникиToolStripMenuItem;
|
private ToolStripMenuItem справочникиToolStripMenuItem;
|
||||||
private ToolStripMenuItem компонентыToolStripMenuItem;
|
private ToolStripMenuItem компонентыToolStripMenuItem;
|
||||||
private ToolStripMenuItem изделияToolStripMenuItem;
|
private ToolStripMenuItem изделияToolStripMenuItem;
|
||||||
private DataGridView dataGridView1;
|
private DataGridView dataGridView;
|
||||||
private Button ButtonCreateOrder;
|
private Button ButtonCreateOrder;
|
||||||
private Button ButtonTakeOrderInWork;
|
private Button ButtonTakeOrderInWork;
|
||||||
private Button ButtonOrderReady;
|
private Button ButtonOrderReady;
|
||||||
|
@ -31,8 +31,22 @@ namespace ConfectioneryView
|
|||||||
|
|
||||||
private void LoadData()
|
private void LoadData()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Загрузка заказов");
|
try
|
||||||
// прописать логику
|
{
|
||||||
|
var list = _orderLogic.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
dataGridView.DataSource = list;
|
||||||
|
dataGridView.Columns["PastryId"].Visible = false;
|
||||||
|
dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Orders loading");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Orders loading error");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
@ -47,7 +61,11 @@ namespace ConfectioneryView
|
|||||||
|
|
||||||
private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
|
private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
// прописать логику
|
var service = Program.ServiceProvider?.GetService(typeof(FormPastries));
|
||||||
|
if (service is FormPastries form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
||||||
|
110
Confectionery/ConfectioneryView/FormPastries.Designer.cs
generated
Normal file
110
Confectionery/ConfectioneryView/FormPastries.Designer.cs
generated
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
namespace ConfectioneryView
|
||||||
|
{
|
||||||
|
partial class FormPastries
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.ButtonUpd = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonDel = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonRef = new System.Windows.Forms.Button();
|
||||||
|
this.ButtonAdd = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(12, 12);
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.RowHeadersWidth = 51;
|
||||||
|
this.dataGridView.RowTemplate.Height = 29;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(490, 426);
|
||||||
|
this.dataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// ButtonUpd
|
||||||
|
//
|
||||||
|
this.ButtonUpd.Location = new System.Drawing.Point(530, 94);
|
||||||
|
this.ButtonUpd.Name = "ButtonUpd";
|
||||||
|
this.ButtonUpd.Size = new System.Drawing.Size(111, 32);
|
||||||
|
this.ButtonUpd.TabIndex = 8;
|
||||||
|
this.ButtonUpd.Text = "Изменить";
|
||||||
|
this.ButtonUpd.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// ButtonDel
|
||||||
|
//
|
||||||
|
this.ButtonDel.Location = new System.Drawing.Point(530, 163);
|
||||||
|
this.ButtonDel.Name = "ButtonDel";
|
||||||
|
this.ButtonDel.Size = new System.Drawing.Size(111, 32);
|
||||||
|
this.ButtonDel.TabIndex = 7;
|
||||||
|
this.ButtonDel.Text = "Удалить";
|
||||||
|
this.ButtonDel.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// ButtonRef
|
||||||
|
//
|
||||||
|
this.ButtonRef.Location = new System.Drawing.Point(530, 232);
|
||||||
|
this.ButtonRef.Name = "ButtonRef";
|
||||||
|
this.ButtonRef.Size = new System.Drawing.Size(111, 32);
|
||||||
|
this.ButtonRef.TabIndex = 6;
|
||||||
|
this.ButtonRef.Text = "Обновить";
|
||||||
|
this.ButtonRef.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// ButtonAdd
|
||||||
|
//
|
||||||
|
this.ButtonAdd.Location = new System.Drawing.Point(530, 26);
|
||||||
|
this.ButtonAdd.Name = "ButtonAdd";
|
||||||
|
this.ButtonAdd.Size = new System.Drawing.Size(111, 32);
|
||||||
|
this.ButtonAdd.TabIndex = 5;
|
||||||
|
this.ButtonAdd.Text = "Добавить";
|
||||||
|
this.ButtonAdd.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// FormPastries
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(670, 450);
|
||||||
|
this.Controls.Add(this.ButtonUpd);
|
||||||
|
this.Controls.Add(this.ButtonDel);
|
||||||
|
this.Controls.Add(this.ButtonRef);
|
||||||
|
this.Controls.Add(this.ButtonAdd);
|
||||||
|
this.Controls.Add(this.dataGridView);
|
||||||
|
this.Name = "FormPastries";
|
||||||
|
this.Text = "Выпечка";
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private Button ButtonUpd;
|
||||||
|
private Button ButtonDel;
|
||||||
|
private Button ButtonRef;
|
||||||
|
private Button ButtonAdd;
|
||||||
|
}
|
||||||
|
}
|
112
Confectionery/ConfectioneryView/FormPastries.cs
Normal file
112
Confectionery/ConfectioneryView/FormPastries.cs
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||||
|
|
||||||
|
namespace ConfectioneryView
|
||||||
|
{
|
||||||
|
public partial class FormPastries : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly IPastryLogic _logic;
|
||||||
|
public FormPastries(ILogger<FormPastries> logger, IPastryLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormPastrys_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logic.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
dataGridView.DataSource = list;
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
|
dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["PastryComponents"].Visible = false;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Pastries loading");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Pastries loading error");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormPastry));
|
||||||
|
if (service is FormPastry form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonEdit_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormPastry));
|
||||||
|
if (service is FormPastry form)
|
||||||
|
{
|
||||||
|
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Deletion of ice cream");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!_logic.Delete(new PastryBindingModel { Id = id }))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ice cream deletion error");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
Confectionery/ConfectioneryView/FormPastries.resx
Normal file
60
Confectionery/ConfectioneryView/FormPastries.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -1,4 +1,10 @@
|
|||||||
|
using ConfectioneryBusinessLogic.BusinessLogics;
|
||||||
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||||
|
using ConfectioneryContracts.StoragesContracts;
|
||||||
|
using ConfectioneryListImplement.Implements;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
|
||||||
namespace ConfectioneryView
|
namespace ConfectioneryView
|
||||||
{
|
{
|
||||||
@ -15,7 +21,33 @@ namespace ConfectioneryView
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormComponent());
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
_serviceProvider = services.BuildServiceProvider();
|
||||||
|
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||||
|
}
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddLogging(option =>
|
||||||
|
{
|
||||||
|
option.SetMinimumLevel(LogLevel.Information);
|
||||||
|
option.AddNLog("nlog.config");
|
||||||
|
});
|
||||||
|
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||||
|
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
|
services.AddTransient<IPastryStorage, PastryStorage>();
|
||||||
|
|
||||||
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
|
services.AddTransient<IPastryLogic, PastryLogic>();
|
||||||
|
|
||||||
|
services.AddTransient<FormMain>();
|
||||||
|
services.AddTransient<FormComponent>();
|
||||||
|
services.AddTransient<FormComponents>();
|
||||||
|
services.AddTransient<FormCreateOrder>();
|
||||||
|
services.AddTransient<FormPastry>();
|
||||||
|
services.AddTransient<FormPastryComponent>();
|
||||||
|
services.AddTransient<FormPastries>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user