Done
This commit is contained in:
parent
23f9200318
commit
c1dcce61b0
108
AbstractShopBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
108
AbstractShopBusinessLogic/BusinessLogics/ComponentLogic.cs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.BusinessLogicsContracts;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using DinerContracts.StoragesContracts;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace DinerBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class ComponentLogic : IComponentLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IComponentStorage _componentStorage;
|
||||||
|
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_componentStorage = componentStorage;
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id);
|
||||||
|
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? ReadElement(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id}", model.ComponentName, model.Id);
|
||||||
|
var element = _componentStorage.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(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_componentStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_componentStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_componentStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(ComponentBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия компонента",
|
||||||
|
nameof(model.ComponentName));
|
||||||
|
}
|
||||||
|
if (model.Cost <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id);
|
||||||
|
var element = _componentStorage.GetElement(new ComponentSearchModel{
|
||||||
|
ComponentName = model.ComponentName
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Компонент с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
122
AbstractShopBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
122
AbstractShopBusinessLogic/BusinessLogics/OrderLogic.cs
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.BusinessLogicsContracts;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using DinerContracts.StoragesContracts;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
using DinerDataModels.Enum;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace DinerBusinessLogic.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)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (model.Status != OrderStatus.Неизвестен) return false;
|
||||||
|
model.Status = OrderStatus.Принят;
|
||||||
|
if (_orderStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
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.SnackId < 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Неверный идентификатор компонента", nameof(model.SnackId));
|
||||||
|
}
|
||||||
|
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. ProductId: {ProductId}. Count: {Count}. Sum: {Sum}. Id: {Id}", model.SnackId, model.Count, model.Sum, model.Id);
|
||||||
|
var element = _orderStorage.GetElement(new OrderSearchModel
|
||||||
|
{
|
||||||
|
Id = model.Id
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Изделие с таким идентификатором уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
var element = _orderStorage.GetElement(new OrderSearchModel()
|
||||||
|
{
|
||||||
|
Id = model.Id
|
||||||
|
});
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(element));
|
||||||
|
}
|
||||||
|
model.DateCreate = element.DateCreate;
|
||||||
|
model.SnackId = element.SnackId;
|
||||||
|
model.DateImplement = element.DateImplement;
|
||||||
|
model.Status = element.Status;
|
||||||
|
model.Count = element.Count;
|
||||||
|
model.Sum = element.Sum;
|
||||||
|
if (requiredStatus - model.Status == 1)
|
||||||
|
{
|
||||||
|
model.Status = requiredStatus;
|
||||||
|
if (model.Status == OrderStatus.Выдан)
|
||||||
|
model.DateImplement = DateTime.Now;
|
||||||
|
if (_orderStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
|
||||||
|
throw new ArgumentException($"Невозможно приствоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
108
AbstractShopBusinessLogic/BusinessLogics/SnackLogic.cs
Normal file
108
AbstractShopBusinessLogic/BusinessLogics/SnackLogic.cs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.BusinessLogicsContracts;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using DinerContracts.StoragesContracts;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace DinerBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class SnackLogic : ISnackLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ISnackStorage _snackStorage;
|
||||||
|
public SnackLogic(ILogger<SnackLogic> logger, ISnackStorage snackStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_snackStorage = snackStorage;
|
||||||
|
}
|
||||||
|
public List<SnackViewModel>? ReadList(SnackSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. BouquetName:{BouquetName}.Id:{ Id}", model?.SnackName, model?.Id);
|
||||||
|
var list = model == null ? _snackStorage.GetFullList() : _snackStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public SnackViewModel? ReadElement(SnackSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. BouquetName:{BouquetName}.Id:{ Id}", model.SnackName, model.Id);
|
||||||
|
var element = _snackStorage.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(SnackBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_snackStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(SnackBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_snackStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(SnackBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_snackStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(SnackBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.SnackName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия изделия",
|
||||||
|
nameof(model.SnackName));
|
||||||
|
}
|
||||||
|
if (model.Price <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Product. BouquetName:{BouquetName}.Cost:{ Cost}. Id: { Id}", model.SnackName, model.Price, model.Id);
|
||||||
|
var element = _snackStorage.GetElement(new SnackSearchModel
|
||||||
|
{
|
||||||
|
SnackName = model.SnackName
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Изделие с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
AbstractShopBusinessLogic/DinerBusinessLogic.csproj
Normal file
17
AbstractShopBusinessLogic/DinerBusinessLogic.csproj
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractShopContracts\DinerContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
12
AbstractShopContracts/BindingModels/ComponentBindingModel.cs
Normal file
12
AbstractShopContracts/BindingModels/ComponentBindingModel.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using DinerDataModels.Models;
|
||||||
|
|
||||||
|
namespace DinerContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ComponentBindingModel : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string ComponentName { get; set; } = string.Empty;
|
||||||
|
public double Cost { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
18
AbstractShopContracts/BindingModels/OrderBindingModel.cs
Normal file
18
AbstractShopContracts/BindingModels/OrderBindingModel.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using DinerDataModels.Enum;
|
||||||
|
using DinerDataModels.Models;
|
||||||
|
|
||||||
|
|
||||||
|
namespace DinerContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class OrderBindingModel : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int SnackId { get; set; }
|
||||||
|
public string SnackName { get; set; }
|
||||||
|
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;}
|
||||||
|
}
|
||||||
|
}
|
14
AbstractShopContracts/BindingModels/SnackBindingModel.cs
Normal file
14
AbstractShopContracts/BindingModels/SnackBindingModel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using DinerDataModels.Models;
|
||||||
|
|
||||||
|
|
||||||
|
namespace DinerContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class SnackBindingModel : ISnackModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string SnackName { get; set; } = string.Empty;
|
||||||
|
public double Price { get; set; }
|
||||||
|
public Dictionary<int, (IComponentModel, int)> SnackComponents { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
|
||||||
|
|
||||||
|
namespace DinerContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IComponentLogic
|
||||||
|
{
|
||||||
|
List<ComponentViewModel>? ReadList(ComponentSearchModel? model);
|
||||||
|
ComponentViewModel? ReadElement(ComponentSearchModel model);
|
||||||
|
bool Create(ComponentBindingModel model);
|
||||||
|
bool Update(ComponentBindingModel model);
|
||||||
|
bool Delete(ComponentBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
15
AbstractShopContracts/BusinessLogicsContracts/IOrderLogic.cs
Normal file
15
AbstractShopContracts/BusinessLogicsContracts/IOrderLogic.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace DinerContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IOrderLogic
|
||||||
|
{
|
||||||
|
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||||
|
bool CreateOrder(OrderBindingModel model);
|
||||||
|
bool TakeOrderInWork(OrderBindingModel model);
|
||||||
|
bool FinishOrder(OrderBindingModel model);
|
||||||
|
bool DeliveryOrder(OrderBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
15
AbstractShopContracts/BusinessLogicsContracts/ISnackLogic.cs
Normal file
15
AbstractShopContracts/BusinessLogicsContracts/ISnackLogic.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace DinerContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface ISnackLogic
|
||||||
|
{
|
||||||
|
List<SnackViewModel>? ReadList(SnackSearchModel? model);
|
||||||
|
SnackViewModel? ReadElement(SnackSearchModel model);
|
||||||
|
bool Create(SnackBindingModel model);
|
||||||
|
bool Update(SnackBindingModel model);
|
||||||
|
bool Delete(SnackBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
13
AbstractShopContracts/DinerContracts.csproj
Normal file
13
AbstractShopContracts/DinerContracts.csproj
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractShopDataModels\DinerDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,8 @@
|
|||||||
|
namespace DinerContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class ComponentSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? ComponentName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
7
AbstractShopContracts/SearchModels/OrderSearchModel.cs
Normal file
7
AbstractShopContracts/SearchModels/OrderSearchModel.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace DinerContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class OrderSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
8
AbstractShopContracts/SearchModels/SnackSearchModel.cs
Normal file
8
AbstractShopContracts/SearchModels/SnackSearchModel.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace DinerContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class SnackSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public string? SnackName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
16
AbstractShopContracts/StoragesContracts/IComponentStorage.cs
Normal file
16
AbstractShopContracts/StoragesContracts/IComponentStorage.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace DinerContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IComponentStorage
|
||||||
|
{
|
||||||
|
List<ComponentViewModel> GetFullList();
|
||||||
|
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
|
||||||
|
ComponentViewModel? GetElement(ComponentSearchModel model);
|
||||||
|
ComponentViewModel? Insert(ComponentBindingModel model);
|
||||||
|
ComponentViewModel? Update(ComponentBindingModel model);
|
||||||
|
ComponentViewModel? Delete(ComponentBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
17
AbstractShopContracts/StoragesContracts/IOrderStorage.cs
Normal file
17
AbstractShopContracts/StoragesContracts/IOrderStorage.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace DinerContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IOrderStorage
|
||||||
|
{
|
||||||
|
List<OrderViewModel> GetFullList();
|
||||||
|
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||||
|
OrderViewModel? GetElement(OrderSearchModel model);
|
||||||
|
OrderViewModel? Insert(OrderBindingModel model);
|
||||||
|
OrderViewModel? Update(OrderBindingModel model);
|
||||||
|
OrderViewModel? Delete(OrderBindingModel model);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
17
AbstractShopContracts/StoragesContracts/ISnackStorage.cs
Normal file
17
AbstractShopContracts/StoragesContracts/ISnackStorage.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace DinerContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface ISnackStorage
|
||||||
|
{
|
||||||
|
List<SnackViewModel> GetFullList();
|
||||||
|
List<SnackViewModel> GetFilteredList(SnackSearchModel model);
|
||||||
|
SnackViewModel? GetElement(SnackSearchModel model);
|
||||||
|
SnackViewModel? Insert(SnackBindingModel model);
|
||||||
|
SnackViewModel? Update(SnackBindingModel model);
|
||||||
|
SnackViewModel? Delete(SnackBindingModel model);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
14
AbstractShopContracts/ViewModels/ComponentViewModel.cs
Normal file
14
AbstractShopContracts/ViewModels/ComponentViewModel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using DinerDataModels.Models;
|
||||||
|
|
||||||
|
namespace DinerContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ComponentViewModel : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Название компонента")]
|
||||||
|
public string ComponentName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Цена")]
|
||||||
|
public double Cost { get; set; }
|
||||||
|
}
|
||||||
|
}
|
25
AbstractShopContracts/ViewModels/OrderViewModel.cs
Normal file
25
AbstractShopContracts/ViewModels/OrderViewModel.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using DinerDataModels.Models;
|
||||||
|
using DinerDataModels.Enum;
|
||||||
|
|
||||||
|
namespace DinerContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class OrderViewModel : IOrderModel
|
||||||
|
{
|
||||||
|
[DisplayName("Номер")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int SnackId { get; set; }
|
||||||
|
[DisplayName("Изделие")]
|
||||||
|
public string SnackName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Количество")]
|
||||||
|
public int Count { get; set; }
|
||||||
|
[DisplayName("Сумма")]
|
||||||
|
public double Sum { get; set; }
|
||||||
|
[DisplayName("Статус")]
|
||||||
|
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||||
|
[DisplayName("Дата создания")]
|
||||||
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
|
[DisplayName("Дата выполнения")]
|
||||||
|
public DateTime? DateImplement { get; set; }
|
||||||
|
}
|
||||||
|
}
|
16
AbstractShopContracts/ViewModels/SnackViewModel.cs
Normal file
16
AbstractShopContracts/ViewModels/SnackViewModel.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using DinerDataModels.Models;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace DinerContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class SnackViewModel : ISnackModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Название изделия")]
|
||||||
|
public string SnackName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Цена")]
|
||||||
|
public double Price { get; set; }
|
||||||
|
public Dictionary<int, (IComponentModel, int)> SnackComponents { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
9
AbstractShopDataModels/DinerDataModels.csproj
Normal file
9
AbstractShopDataModels/DinerDataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
11
AbstractShopDataModels/Enum/OrderStatus.cs
Normal file
11
AbstractShopDataModels/Enum/OrderStatus.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace DinerDataModels.Enum
|
||||||
|
{
|
||||||
|
public enum OrderStatus
|
||||||
|
{
|
||||||
|
Неизвестен = -1,
|
||||||
|
Принят = 0,
|
||||||
|
Выполняется = 1,
|
||||||
|
Готов = 2,
|
||||||
|
Выдан = 3
|
||||||
|
}
|
||||||
|
}
|
7
AbstractShopDataModels/IId.cs
Normal file
7
AbstractShopDataModels/IId.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace DinerDataModels
|
||||||
|
{
|
||||||
|
public interface IId
|
||||||
|
{
|
||||||
|
int Id { get; }
|
||||||
|
}
|
||||||
|
}
|
8
AbstractShopDataModels/Models/IComponentModel.cs
Normal file
8
AbstractShopDataModels/Models/IComponentModel.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace DinerDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IComponentModel : IId
|
||||||
|
{
|
||||||
|
string ComponentName { get; }
|
||||||
|
double Cost { get; }
|
||||||
|
}
|
||||||
|
}
|
14
AbstractShopDataModels/Models/IOrderModel.cs
Normal file
14
AbstractShopDataModels/Models/IOrderModel.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using DinerDataModels.Enum;
|
||||||
|
|
||||||
|
namespace DinerDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IOrderModel : IId
|
||||||
|
{
|
||||||
|
int Id { get; }
|
||||||
|
int Count { get; }
|
||||||
|
double Sum { get; }
|
||||||
|
OrderStatus Status { get; }
|
||||||
|
DateTime DateCreate { get; }
|
||||||
|
DateTime? DateImplement { get;}
|
||||||
|
}
|
||||||
|
}
|
9
AbstractShopDataModels/Models/ISnackModel.cs
Normal file
9
AbstractShopDataModels/Models/ISnackModel.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace DinerDataModels.Models
|
||||||
|
{
|
||||||
|
public interface ISnackModel : IId
|
||||||
|
{
|
||||||
|
string SnackName { get; }
|
||||||
|
double Price { get; }
|
||||||
|
Dictionary<int, (IComponentModel, int)> SnackComponents { get; }
|
||||||
|
}
|
||||||
|
}
|
31
Diner/AbstractShopListImplement/DataListSingleton.cs
Normal file
31
Diner/AbstractShopListImplement/DataListSingleton.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using DinerListImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DinerListImplement
|
||||||
|
{
|
||||||
|
public class DataListSingleton
|
||||||
|
{
|
||||||
|
private static DataListSingleton? _instance;
|
||||||
|
public List<Component> Components { get; set; }
|
||||||
|
public List<Order> Orders { get; set; }
|
||||||
|
public List<Snack> Products { get; set; }
|
||||||
|
private DataListSingleton()
|
||||||
|
{
|
||||||
|
Components = new List<Component>();
|
||||||
|
Orders = new List<Order>();
|
||||||
|
Products = new List<Snack>();
|
||||||
|
}
|
||||||
|
public static DataListSingleton GetInstance()
|
||||||
|
{
|
||||||
|
if (_instance == null)
|
||||||
|
{
|
||||||
|
_instance = new DataListSingleton();
|
||||||
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Diner/AbstractShopListImplement/DinerListImplement.csproj
Normal file
14
Diner/AbstractShopListImplement/DinerListImplement.csproj
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\AbstractShopContracts\DinerContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\..\AbstractShopDataModels\DinerDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
102
Diner/AbstractShopListImplement/Implements/ComponentStorage.cs
Normal file
102
Diner/AbstractShopListImplement/Implements/ComponentStorage.cs
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using DinerContracts.StoragesContracts;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
using DinerListImplement.Models;
|
||||||
|
|
||||||
|
namespace DinerListImplement.Implements
|
||||||
|
{
|
||||||
|
public class ComponentStorage : IComponentStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
public ComponentStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<ComponentViewModel>();
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
result.Add(component.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<ComponentViewModel>();
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
if (component.ComponentName.Contains(model.ComponentName))
|
||||||
|
{
|
||||||
|
result.Add(component.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.ComponentName) &&
|
||||||
|
component.ComponentName == model.ComponentName) ||
|
||||||
|
(model.Id.HasValue && component.Id == model.Id))
|
||||||
|
{
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
if (model.Id <= component.Id)
|
||||||
|
{
|
||||||
|
model.Id = component.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newComponent = Component.Create(model);
|
||||||
|
if (newComponent == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Components.Add(newComponent);
|
||||||
|
return newComponent.GetViewModel;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var component in _source.Components)
|
||||||
|
{
|
||||||
|
if (component.Id == model.Id)
|
||||||
|
{
|
||||||
|
component.Update(model);
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Components.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Components[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Components[i];
|
||||||
|
_source.Components.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
115
Diner/AbstractShopListImplement/Implements/OrderStorage.cs
Normal file
115
Diner/AbstractShopListImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using DinerContracts.StoragesContracts;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
using DinerListImplement.Models;
|
||||||
|
using DinerListImplement;
|
||||||
|
|
||||||
|
namespace DinerListImplement.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(AttachDinerName(order.GetViewModel));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<OrderViewModel>();
|
||||||
|
if (model == null || !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
result.Add(AttachDinerName(order.GetViewModel));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (model.Id.HasValue && order.Id == model.Id)
|
||||||
|
{
|
||||||
|
return AttachDinerName(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 AttachDinerName(newOrder.GetViewModel);
|
||||||
|
}
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
order.Update(model);
|
||||||
|
return AttachDinerName(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 AttachDinerName(element.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
private OrderViewModel AttachDinerName(OrderViewModel model)
|
||||||
|
{
|
||||||
|
foreach (var snack in _source.Products)
|
||||||
|
{
|
||||||
|
if (snack.Id == model.SnackId)
|
||||||
|
{
|
||||||
|
model.SnackName = snack.SnackName;
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
104
Diner/AbstractShopListImplement/Implements/SnackStorage.cs
Normal file
104
Diner/AbstractShopListImplement/Implements/SnackStorage.cs
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using DinerContracts.StoragesContracts;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
using DinerListImplement.Models;
|
||||||
|
|
||||||
|
namespace DinerListImplement.Implements
|
||||||
|
{
|
||||||
|
public class SnackStorage : ISnackStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
public SnackStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public SnackViewModel? Delete(SnackBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Products.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Products[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Products[i];
|
||||||
|
_source.Products.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public SnackViewModel? GetElement(SnackSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.SnackName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var product in _source.Products)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.SnackName) && product.SnackName == model.SnackName) || (model.Id.HasValue && product.Id == model.Id))
|
||||||
|
{
|
||||||
|
return product.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SnackViewModel> GetFilteredList(SnackSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<SnackViewModel>();
|
||||||
|
if (string.IsNullOrEmpty(model.SnackName))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var product in _source.Products)
|
||||||
|
{
|
||||||
|
if (product.SnackName.Contains(model.SnackName))
|
||||||
|
{
|
||||||
|
result.Add(product.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SnackViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<SnackViewModel>();
|
||||||
|
foreach (var product in _source.Products)
|
||||||
|
{
|
||||||
|
result.Add(product.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SnackViewModel? Insert(SnackBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var product in _source.Products)
|
||||||
|
{
|
||||||
|
if (model.Id <= product.Id)
|
||||||
|
{
|
||||||
|
model.Id = product.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newProduct = Snack.Create(model);
|
||||||
|
if (newProduct == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Products.Add(newProduct);
|
||||||
|
return newProduct.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SnackViewModel? Update(SnackBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var product in _source.Products)
|
||||||
|
{
|
||||||
|
if (product.Id == model.Id)
|
||||||
|
{
|
||||||
|
product.Update(model);
|
||||||
|
return product.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
Diner/AbstractShopListImplement/Models/Component.cs
Normal file
41
Diner/AbstractShopListImplement/Models/Component.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
using DinerDataModels.Models;
|
||||||
|
|
||||||
|
namespace DinerListImplement.Models
|
||||||
|
{
|
||||||
|
public class Component : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ComponentName { get; private set; } = string.Empty;
|
||||||
|
public double Cost { get; set; }
|
||||||
|
public static Component? Create(ComponentBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Component()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ComponentName = model.ComponentName,
|
||||||
|
Cost = model.Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ComponentBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ComponentName = model.ComponentName;
|
||||||
|
Cost = model.Cost;
|
||||||
|
}
|
||||||
|
public ComponentViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ComponentName = ComponentName,
|
||||||
|
Cost = Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
63
Diner/AbstractShopListImplement/Models/Order.cs
Normal file
63
Diner/AbstractShopListImplement/Models/Order.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
using DinerDataModels.Enum;
|
||||||
|
using DinerDataModels.Models;
|
||||||
|
|
||||||
|
namespace DinerListImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string SnackName { get; private set; }
|
||||||
|
public int SnackID { 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)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
SnackName = model.SnackName,
|
||||||
|
SnackID = model.SnackId,
|
||||||
|
Count = model.Count,
|
||||||
|
Sum = model.Sum,
|
||||||
|
Status = model.Status,
|
||||||
|
DateCreate = model.DateCreate,
|
||||||
|
DateImplement = model.DateImplement
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Id = model.Id;
|
||||||
|
SnackID = model.SnackId;
|
||||||
|
SnackName = model.SnackName;
|
||||||
|
Count = model.Count;
|
||||||
|
Sum = model.Sum;
|
||||||
|
Status = model.Status;
|
||||||
|
DateCreate = model.DateCreate;
|
||||||
|
DateImplement = model.DateImplement;
|
||||||
|
}
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
SnackId = SnackID,
|
||||||
|
SnackName = SnackName,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
49
Diner/AbstractShopListImplement/Models/Snack.cs
Normal file
49
Diner/AbstractShopListImplement/Models/Snack.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
using DinerDataModels.Models;
|
||||||
|
|
||||||
|
namespace DinerListImplement.Models
|
||||||
|
{
|
||||||
|
public class Snack : ISnackModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string SnackName { get; private set; } = string.Empty;
|
||||||
|
public double Price { get; private set; }
|
||||||
|
public Dictionary<int, (IComponentModel, int)> SnackComponents
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
} = new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
public static Snack? Create(SnackBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Snack()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
SnackName = model.SnackName,
|
||||||
|
Price = model.Price,
|
||||||
|
SnackComponents = model.SnackComponents
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(SnackBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SnackName = model.SnackName;
|
||||||
|
Price = model.Price;
|
||||||
|
SnackComponents = model.SnackComponents;
|
||||||
|
}
|
||||||
|
public SnackViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
SnackName = SnackName,
|
||||||
|
Price = Price,
|
||||||
|
SnackComponents = SnackComponents
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>WinExe</OutputType>
|
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,9 +1,17 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.3.32825.248
|
VisualStudioVersion = 17.3.32819.101
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Diner", "Diner.csproj", "{23C9B122-7EEF-4651-88E0-1A0C4A5D342A}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerView", "Diner\DinerView.csproj", "{65DDF152-0786-40A2-8CAD-091C19000D84}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerDataModels", "..\AbstractShopDataModels\DinerDataModels.csproj", "{1AA0331A-FF61-4CA9-8273-51DF0A9ABBEC}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerContracts", "..\AbstractShopContracts\DinerContracts.csproj", "{86956F83-EF92-432E-B2DA-7E719873AC98}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerBusinessLogic", "..\AbstractShopBusinessLogic\DinerBusinessLogic.csproj", "{DDA6A507-23B7-4CB2-B5CF-3FBBB687D43C}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerListImplement", "AbstractShopListImplement\DinerListImplement.csproj", "{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -11,15 +19,31 @@ Global
|
|||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{23C9B122-7EEF-4651-88E0-1A0C4A5D342A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{65DDF152-0786-40A2-8CAD-091C19000D84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{23C9B122-7EEF-4651-88E0-1A0C4A5D342A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{65DDF152-0786-40A2-8CAD-091C19000D84}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{23C9B122-7EEF-4651-88E0-1A0C4A5D342A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{65DDF152-0786-40A2-8CAD-091C19000D84}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{23C9B122-7EEF-4651-88E0-1A0C4A5D342A}.Release|Any CPU.Build.0 = Release|Any CPU
|
{65DDF152-0786-40A2-8CAD-091C19000D84}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{1AA0331A-FF61-4CA9-8273-51DF0A9ABBEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{1AA0331A-FF61-4CA9-8273-51DF0A9ABBEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{1AA0331A-FF61-4CA9-8273-51DF0A9ABBEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{1AA0331A-FF61-4CA9-8273-51DF0A9ABBEC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{86956F83-EF92-432E-B2DA-7E719873AC98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{86956F83-EF92-432E-B2DA-7E719873AC98}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{86956F83-EF92-432E-B2DA-7E719873AC98}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{86956F83-EF92-432E-B2DA-7E719873AC98}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{DDA6A507-23B7-4CB2-B5CF-3FBBB687D43C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{DDA6A507-23B7-4CB2-B5CF-3FBBB687D43C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{DDA6A507-23B7-4CB2-B5CF-3FBBB687D43C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{DDA6A507-23B7-4CB2-B5CF-3FBBB687D43C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {5ED0C012-8FB3-4A50-B469-47606ADB8FC8}
|
SolutionGuid = {78CA589A-698F-4822-A1DB-E616926BB9B3}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
20
Diner/Diner/DinerView.csproj
Normal file
20
Diner/Diner/DinerView.csproj
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\AbstractShopBusinessLogic\DinerBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\AbstractShopListImplement\DinerListImplement.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
119
Diner/Diner/FormComponent.Designer.cs
generated
Normal file
119
Diner/Diner/FormComponent.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
partial class FormComponent
|
||||||
|
{
|
||||||
|
/// <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.labelName = new System.Windows.Forms.Label();
|
||||||
|
this.labelPrice = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||||
|
this.textBoxPrice = new System.Windows.Forms.TextBox();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelName
|
||||||
|
//
|
||||||
|
this.labelName.AutoSize = true;
|
||||||
|
this.labelName.Location = new System.Drawing.Point(27, 26);
|
||||||
|
this.labelName.Name = "labelName";
|
||||||
|
this.labelName.Size = new System.Drawing.Size(80, 20);
|
||||||
|
this.labelName.TabIndex = 0;
|
||||||
|
this.labelName.Text = "Название:";
|
||||||
|
//
|
||||||
|
// labelPrice
|
||||||
|
//
|
||||||
|
this.labelPrice.AutoSize = true;
|
||||||
|
this.labelPrice.Location = new System.Drawing.Point(27, 64);
|
||||||
|
this.labelPrice.Name = "labelPrice";
|
||||||
|
this.labelPrice.Size = new System.Drawing.Size(48, 20);
|
||||||
|
this.labelPrice.TabIndex = 1;
|
||||||
|
this.labelPrice.Text = "Цена:";
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
this.textBoxName.Location = new System.Drawing.Point(113, 23);
|
||||||
|
this.textBoxName.Name = "textBoxName";
|
||||||
|
this.textBoxName.Size = new System.Drawing.Size(317, 27);
|
||||||
|
this.textBoxName.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// textBoxPrice
|
||||||
|
//
|
||||||
|
this.textBoxPrice.Location = new System.Drawing.Point(113, 61);
|
||||||
|
this.textBoxPrice.Name = "textBoxPrice";
|
||||||
|
this.textBoxPrice.Size = new System.Drawing.Size(172, 27);
|
||||||
|
this.textBoxPrice.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(224, 105);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonSave.TabIndex = 4;
|
||||||
|
this.buttonSave.Text = "Создать";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(336, 105);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonCancel.TabIndex = 5;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormComponent
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(470, 162);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.textBoxPrice);
|
||||||
|
this.Controls.Add(this.textBoxName);
|
||||||
|
this.Controls.Add(this.labelPrice);
|
||||||
|
this.Controls.Add(this.labelName);
|
||||||
|
this.Name = "FormComponent";
|
||||||
|
this.Text = "Компонент";
|
||||||
|
this.Load += new System.EventHandler(this.FormComponent_Load);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label labelName;
|
||||||
|
private Label labelPrice;
|
||||||
|
private TextBox textBoxName;
|
||||||
|
private TextBox textBoxPrice;
|
||||||
|
private Button buttonSave;
|
||||||
|
private Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
88
Diner/Diner/FormComponent.cs
Normal file
88
Diner/Diner/FormComponent.cs
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.BusinessLogicsContracts;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.VisualBasic.Logging;
|
||||||
|
|
||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
public partial class FormComponent : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IComponentLogic _logic;
|
||||||
|
private int? _id;
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
public FormComponent(ILogger<FormComponent> logger, IComponentLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
private void FormComponent_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Ïîëó÷åíèå êîìïîíåíòà");
|
||||||
|
var view = _logic.ReadElement(new ComponentSearchModel
|
||||||
|
{
|
||||||
|
Id =
|
||||||
|
_id.Value
|
||||||
|
});
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
textBoxName.Text = view.ComponentName;
|
||||||
|
textBoxPrice.Text = view.Cost.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Îøèáêà ïîëó÷åíèÿ êîìïîíåíòà");
|
||||||
|
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Çàïîëíèòå íàçâàíèå", "Îøèáêà",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Ñîõðàíåíèå êîìïîíåíòà");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new ComponentBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
ComponentName = textBoxName.Text,
|
||||||
|
Cost = Convert.ToDouble(textBoxPrice.Text)
|
||||||
|
};
|
||||||
|
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||||
|
_logic.Create(model);
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Îøèáêà ïðè ñîõðàíåíèè. Äîïîëíèòåëüíàÿ èíôîðìàöèÿ â ëîãàõ.");
|
||||||
|
}
|
||||||
|
MessageBox.Show("Ñîõðàíåíèå ïðîøëî óñïåøíî", "Ñîîáùåíèå",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Îøèáêà ñîõðàíåíèÿ êîìïîíåíòà");
|
||||||
|
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
Diner/Diner/FormComponent.resx
Normal file
60
Diner/Diner/FormComponent.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>
|
116
Diner/Diner/FormComponents.Designer.cs
generated
Normal file
116
Diner/Diner/FormComponents.Designer.cs
generated
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
partial class FormComponents
|
||||||
|
{
|
||||||
|
/// <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.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUpd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonRef = new System.Windows.Forms.Button();
|
||||||
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(559, 31);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonAdd.TabIndex = 0;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
|
//
|
||||||
|
// buttonUpd
|
||||||
|
//
|
||||||
|
this.buttonUpd.Location = new System.Drawing.Point(559, 84);
|
||||||
|
this.buttonUpd.Name = "buttonUpd";
|
||||||
|
this.buttonUpd.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonUpd.TabIndex = 1;
|
||||||
|
this.buttonUpd.Text = "Изменить";
|
||||||
|
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
this.buttonDel.Location = new System.Drawing.Point(559, 138);
|
||||||
|
this.buttonDel.Name = "buttonDel";
|
||||||
|
this.buttonDel.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonDel.TabIndex = 2;
|
||||||
|
this.buttonDel.Text = "Удалить";
|
||||||
|
this.buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||||
|
//
|
||||||
|
// buttonRef
|
||||||
|
//
|
||||||
|
this.buttonRef.Location = new System.Drawing.Point(559, 189);
|
||||||
|
this.buttonRef.Name = "buttonRef";
|
||||||
|
this.buttonRef.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonRef.TabIndex = 3;
|
||||||
|
this.buttonRef.Text = "Обновить";
|
||||||
|
this.buttonRef.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(0, 1);
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.RowHeadersWidth = 51;
|
||||||
|
this.dataGridView.RowTemplate.Height = 29;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(529, 442);
|
||||||
|
this.dataGridView.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// FormComponents
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(680, 450);
|
||||||
|
this.Controls.Add(this.dataGridView);
|
||||||
|
this.Controls.Add(this.buttonRef);
|
||||||
|
this.Controls.Add(this.buttonDel);
|
||||||
|
this.Controls.Add(this.buttonUpd);
|
||||||
|
this.Controls.Add(this.buttonAdd);
|
||||||
|
this.Name = "FormComponents";
|
||||||
|
this.Text = "Компоненты";
|
||||||
|
this.Load += new System.EventHandler(this.FormComponents_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonAdd;
|
||||||
|
private Button buttonUpd;
|
||||||
|
private Button buttonDel;
|
||||||
|
private Button buttonRef;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
}
|
||||||
|
}
|
103
Diner/Diner/FormComponents.cs
Normal file
103
Diner/Diner/FormComponents.cs
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
public partial class FormComponents : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IComponentLogic _logic;
|
||||||
|
public FormComponents(ILogger<FormComponents> logger, IComponentLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
private void FormComponents_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["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Загрузка компонентов");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||||
|
if (service is FormComponent form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||||
|
if (service is FormComponent 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("Удаление компонента");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!_logic.Delete(new ComponentBindingModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления компонента");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRef_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
Diner/Diner/FormComponents.resx
Normal file
60
Diner/Diner/FormComponents.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>
|
144
Diner/Diner/FormCreateOrder.Designer.cs
generated
Normal file
144
Diner/Diner/FormCreateOrder.Designer.cs
generated
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
partial class FormCreateOrder
|
||||||
|
{
|
||||||
|
/// <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.labelProduct = new System.Windows.Forms.Label();
|
||||||
|
this.labelCount = new System.Windows.Forms.Label();
|
||||||
|
this.labelPrice = new System.Windows.Forms.Label();
|
||||||
|
this.comboBoxProduct = new System.Windows.Forms.ComboBox();
|
||||||
|
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||||
|
this.textBoxSum = new System.Windows.Forms.TextBox();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelProduct
|
||||||
|
//
|
||||||
|
this.labelProduct.AutoSize = true;
|
||||||
|
this.labelProduct.Location = new System.Drawing.Point(47, 21);
|
||||||
|
this.labelProduct.Name = "labelProduct";
|
||||||
|
this.labelProduct.Size = new System.Drawing.Size(71, 20);
|
||||||
|
this.labelProduct.TabIndex = 0;
|
||||||
|
this.labelProduct.Text = "Изделие:";
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
this.labelCount.AutoSize = true;
|
||||||
|
this.labelCount.Location = new System.Drawing.Point(47, 62);
|
||||||
|
this.labelCount.Name = "labelCount";
|
||||||
|
this.labelCount.Size = new System.Drawing.Size(93, 20);
|
||||||
|
this.labelCount.TabIndex = 1;
|
||||||
|
this.labelCount.Text = "Количество:";
|
||||||
|
//
|
||||||
|
// labelPrice
|
||||||
|
//
|
||||||
|
this.labelPrice.AutoSize = true;
|
||||||
|
this.labelPrice.Location = new System.Drawing.Point(47, 104);
|
||||||
|
this.labelPrice.Name = "labelPrice";
|
||||||
|
this.labelPrice.Size = new System.Drawing.Size(58, 20);
|
||||||
|
this.labelPrice.TabIndex = 2;
|
||||||
|
this.labelPrice.Text = "Сумма:";
|
||||||
|
//
|
||||||
|
// comboBoxProduct
|
||||||
|
//
|
||||||
|
this.comboBoxProduct.FormattingEnabled = true;
|
||||||
|
this.comboBoxProduct.Location = new System.Drawing.Point(149, 18);
|
||||||
|
this.comboBoxProduct.Name = "comboBoxProduct";
|
||||||
|
this.comboBoxProduct.Size = new System.Drawing.Size(246, 28);
|
||||||
|
this.comboBoxProduct.TabIndex = 3;
|
||||||
|
this.comboBoxProduct.SelectedIndexChanged += new System.EventHandler(this.ComboBoxProduct_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
this.textBoxCount.Location = new System.Drawing.Point(149, 59);
|
||||||
|
this.textBoxCount.Name = "textBoxCount";
|
||||||
|
this.textBoxCount.Size = new System.Drawing.Size(246, 27);
|
||||||
|
this.textBoxCount.TabIndex = 4;
|
||||||
|
this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
|
||||||
|
//
|
||||||
|
// textBoxSum
|
||||||
|
//
|
||||||
|
this.textBoxSum.Location = new System.Drawing.Point(149, 101);
|
||||||
|
this.textBoxSum.Name = "textBoxSum";
|
||||||
|
this.textBoxSum.Size = new System.Drawing.Size(246, 27);
|
||||||
|
this.textBoxSum.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(178, 153);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonSave.TabIndex = 6;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(301, 153);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonCancel.TabIndex = 7;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormCreateOrder
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(420, 205);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.textBoxSum);
|
||||||
|
this.Controls.Add(this.textBoxCount);
|
||||||
|
this.Controls.Add(this.comboBoxProduct);
|
||||||
|
this.Controls.Add(this.labelPrice);
|
||||||
|
this.Controls.Add(this.labelCount);
|
||||||
|
this.Controls.Add(this.labelProduct);
|
||||||
|
this.Name = "FormCreateOrder";
|
||||||
|
this.Text = "Заказ";
|
||||||
|
this.Load += new System.EventHandler(this.FormCreateOrder_Load);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label labelProduct;
|
||||||
|
private Label labelCount;
|
||||||
|
private Label labelPrice;
|
||||||
|
private ComboBox comboBoxProduct;
|
||||||
|
private TextBox textBoxCount;
|
||||||
|
private TextBox textBoxSum;
|
||||||
|
private Button buttonSave;
|
||||||
|
private Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
119
Diner/Diner/FormCreateOrder.cs
Normal file
119
Diner/Diner/FormCreateOrder.cs
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.BusinessLogicsContracts;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
public partial class FormCreateOrder : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ISnackLogic _logicP;
|
||||||
|
private readonly IOrderLogic _logicO;
|
||||||
|
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISnackLogic logicP, IOrderLogic logicO)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicP = logicP;
|
||||||
|
_logicO = logicO;
|
||||||
|
}
|
||||||
|
private void FormCreateOrder_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка изделий для заказа");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logicP.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
comboBoxProduct.DisplayMember = "Snack";
|
||||||
|
comboBoxProduct.ValueMember = "Id";
|
||||||
|
comboBoxProduct.DataSource = list.Select(c => c.SnackName).ToList();
|
||||||
|
comboBoxProduct.SelectedItem = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки списка изделий");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void CalcSum()
|
||||||
|
{
|
||||||
|
if (comboBoxProduct.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(comboBoxProduct.SelectedIndex + 1);
|
||||||
|
var product = _logicP.ReadElement(new SnackSearchModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
});
|
||||||
|
int count = Convert.ToInt32(textBoxCount.Text);
|
||||||
|
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
|
||||||
|
_logger.LogInformation("Расчет суммы заказа");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка расчета суммы заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void TextBoxCount_TextChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CalcSum();
|
||||||
|
}
|
||||||
|
private void ComboBoxProduct_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CalcSum();
|
||||||
|
}
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxProduct.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите изделие", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Создание заказа");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
SnackId = Convert.ToInt32(comboBoxProduct.SelectedIndex + 1),
|
||||||
|
SnackName = comboBoxProduct.SelectedValue.ToString(),
|
||||||
|
Count = Convert.ToInt32(textBoxCount.Text),
|
||||||
|
Sum = Convert.ToDouble(textBoxSum.Text)
|
||||||
|
});
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
Diner/Diner/FormCreateOrder.resx
Normal file
60
Diner/Diner/FormCreateOrder.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>
|
176
Diner/Diner/FormMain.Designer.cs
generated
Normal file
176
Diner/Diner/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
partial class FormMain
|
||||||
|
{
|
||||||
|
/// <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.buttonCreateOrder = new System.Windows.Forms.Button();
|
||||||
|
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
|
||||||
|
this.buttonOrderReady = new System.Windows.Forms.Button();
|
||||||
|
this.buttonIssuedOrder = new System.Windows.Forms.Button();
|
||||||
|
this.buttonRef = new System.Windows.Forms.Button();
|
||||||
|
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
|
||||||
|
this.toolStripLabel1 = new System.Windows.Forms.ToolStripDropDownButton();
|
||||||
|
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.snacksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.toolStrip1.SuspendLayout();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(0, 27);
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.RowHeadersWidth = 51;
|
||||||
|
this.dataGridView.RowTemplate.Height = 29;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(986, 421);
|
||||||
|
this.dataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonCreateOrder
|
||||||
|
//
|
||||||
|
this.buttonCreateOrder.Location = new System.Drawing.Point(1040, 88);
|
||||||
|
this.buttonCreateOrder.Name = "buttonCreateOrder";
|
||||||
|
this.buttonCreateOrder.Size = new System.Drawing.Size(202, 29);
|
||||||
|
this.buttonCreateOrder.TabIndex = 1;
|
||||||
|
this.buttonCreateOrder.Text = "Создать заказ";
|
||||||
|
this.buttonCreateOrder.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
|
||||||
|
//
|
||||||
|
// buttonTakeOrderInWork
|
||||||
|
//
|
||||||
|
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1040, 136);
|
||||||
|
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
||||||
|
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(202, 29);
|
||||||
|
this.buttonTakeOrderInWork.TabIndex = 2;
|
||||||
|
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
||||||
|
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
|
||||||
|
//
|
||||||
|
// buttonOrderReady
|
||||||
|
//
|
||||||
|
this.buttonOrderReady.Location = new System.Drawing.Point(1040, 184);
|
||||||
|
this.buttonOrderReady.Name = "buttonOrderReady";
|
||||||
|
this.buttonOrderReady.Size = new System.Drawing.Size(202, 29);
|
||||||
|
this.buttonOrderReady.TabIndex = 3;
|
||||||
|
this.buttonOrderReady.Text = "Заказ готов";
|
||||||
|
this.buttonOrderReady.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
|
||||||
|
//
|
||||||
|
// buttonIssuedOrder
|
||||||
|
//
|
||||||
|
this.buttonIssuedOrder.Location = new System.Drawing.Point(1040, 237);
|
||||||
|
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
|
||||||
|
this.buttonIssuedOrder.Size = new System.Drawing.Size(202, 29);
|
||||||
|
this.buttonIssuedOrder.TabIndex = 4;
|
||||||
|
this.buttonIssuedOrder.Text = "Заказ выдан";
|
||||||
|
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
|
||||||
|
//
|
||||||
|
// buttonRef
|
||||||
|
//
|
||||||
|
this.buttonRef.Location = new System.Drawing.Point(1040, 287);
|
||||||
|
this.buttonRef.Name = "buttonRef";
|
||||||
|
this.buttonRef.Size = new System.Drawing.Size(202, 29);
|
||||||
|
this.buttonRef.TabIndex = 5;
|
||||||
|
this.buttonRef.Text = "Обновить список";
|
||||||
|
this.buttonRef.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||||
|
//
|
||||||
|
// toolStrip1
|
||||||
|
//
|
||||||
|
this.toolStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||||
|
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.toolStripLabel1});
|
||||||
|
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.toolStrip1.Name = "toolStrip1";
|
||||||
|
this.toolStrip1.Size = new System.Drawing.Size(1280, 27);
|
||||||
|
this.toolStrip1.TabIndex = 6;
|
||||||
|
this.toolStrip1.Text = "toolStrip1";
|
||||||
|
//
|
||||||
|
// toolStripLabel1
|
||||||
|
//
|
||||||
|
this.toolStripLabel1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.componentsToolStripMenuItem,
|
||||||
|
this.snacksToolStripMenuItem});
|
||||||
|
this.toolStripLabel1.Name = "toolStripLabel1";
|
||||||
|
this.toolStripLabel1.Size = new System.Drawing.Size(117, 24);
|
||||||
|
this.toolStripLabel1.Text = "Справочники";
|
||||||
|
//
|
||||||
|
// componentsToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
|
||||||
|
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||||
|
this.componentsToolStripMenuItem.Text = "Компоненты";
|
||||||
|
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// snacksToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.snacksToolStripMenuItem.Name = "snacksToolStripMenuItem";
|
||||||
|
this.snacksToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||||
|
this.snacksToolStripMenuItem.Text = "Закуски";
|
||||||
|
this.snacksToolStripMenuItem.Click += new System.EventHandler(this.ProductToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// FormMain
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(1280, 450);
|
||||||
|
this.Controls.Add(this.toolStrip1);
|
||||||
|
this.Controls.Add(this.buttonRef);
|
||||||
|
this.Controls.Add(this.buttonIssuedOrder);
|
||||||
|
this.Controls.Add(this.buttonOrderReady);
|
||||||
|
this.Controls.Add(this.buttonTakeOrderInWork);
|
||||||
|
this.Controls.Add(this.buttonCreateOrder);
|
||||||
|
this.Controls.Add(this.dataGridView);
|
||||||
|
this.Name = "FormMain";
|
||||||
|
this.Text = "Закусочная";
|
||||||
|
this.Load += new System.EventHandler(this.FormMain_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
this.toolStrip1.ResumeLayout(false);
|
||||||
|
this.toolStrip1.PerformLayout();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private Button buttonCreateOrder;
|
||||||
|
private Button buttonTakeOrderInWork;
|
||||||
|
private Button buttonOrderReady;
|
||||||
|
private Button buttonIssuedOrder;
|
||||||
|
private Button buttonRef;
|
||||||
|
private ToolStrip toolStrip1;
|
||||||
|
private ToolStripDropDownButton toolStripLabel1;
|
||||||
|
private ToolStripMenuItem componentsToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem snacksToolStripMenuItem;
|
||||||
|
}
|
||||||
|
}
|
165
Diner/Diner/FormMain.cs
Normal file
165
Diner/Diner/FormMain.cs
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.BusinessLogicsContracts;
|
||||||
|
using DinerDataModels.Enum;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
public partial class FormMain : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IOrderLogic _orderLogic;
|
||||||
|
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_orderLogic = orderLogic;
|
||||||
|
}
|
||||||
|
private void FormMain_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
// прописать логику
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _orderLogic.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
dataGridView.DataSource = list;
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Загрузка заказов");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки списка заказов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ComponentToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||||
|
if (service is FormComponents form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ProductToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormSnacks));
|
||||||
|
if (service is FormSnacks form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||||
|
if (service is FormCreateOrder form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
SnackId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value),
|
||||||
|
SnackName = dataGridView.SelectedRows[0].Cells["SnackName"].Value.ToString(),
|
||||||
|
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()),
|
||||||
|
});
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка передачи заказа в работу");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonOrderReady_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
SnackId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value),
|
||||||
|
SnackName = dataGridView.SelectedRows[0].Cells["SnackName"].Value.ToString(),
|
||||||
|
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()),
|
||||||
|
});
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
SnackId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value),
|
||||||
|
SnackName = dataGridView.SelectedRows[0].Cells["SnackName"].Value.ToString(),
|
||||||
|
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()),
|
||||||
|
});
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Заказ №{id} выдан", id);
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRef_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
Diner/Diner/FormMain.resx
Normal file
63
Diner/Diner/FormMain.resx
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<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>
|
||||||
|
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
236
Diner/Diner/FormSnack.Designer.cs
generated
Normal file
236
Diner/Diner/FormSnack.Designer.cs
generated
Normal file
@ -0,0 +1,236 @@
|
|||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
partial class FormSnack
|
||||||
|
{
|
||||||
|
/// <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.labelName = new System.Windows.Forms.Label();
|
||||||
|
this.labelPrice = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||||
|
this.textBoxPrice = new System.Windows.Forms.TextBox();
|
||||||
|
this.groupBoxComponents = new System.Windows.Forms.GroupBox();
|
||||||
|
this.buttonRef = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUpd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.groupBoxComponents.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelName
|
||||||
|
//
|
||||||
|
this.labelName.AutoSize = true;
|
||||||
|
this.labelName.Location = new System.Drawing.Point(41, 20);
|
||||||
|
this.labelName.Name = "labelName";
|
||||||
|
this.labelName.Size = new System.Drawing.Size(80, 20);
|
||||||
|
this.labelName.TabIndex = 0;
|
||||||
|
this.labelName.Text = "Название:";
|
||||||
|
//
|
||||||
|
// labelPrice
|
||||||
|
//
|
||||||
|
this.labelPrice.AutoSize = true;
|
||||||
|
this.labelPrice.Location = new System.Drawing.Point(41, 52);
|
||||||
|
this.labelPrice.Name = "labelPrice";
|
||||||
|
this.labelPrice.Size = new System.Drawing.Size(86, 20);
|
||||||
|
this.labelPrice.TabIndex = 1;
|
||||||
|
this.labelPrice.Text = "Стоимость:";
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
this.textBoxName.Location = new System.Drawing.Point(140, 17);
|
||||||
|
this.textBoxName.Name = "textBoxName";
|
||||||
|
this.textBoxName.Size = new System.Drawing.Size(267, 27);
|
||||||
|
this.textBoxName.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// textBoxPrice
|
||||||
|
//
|
||||||
|
this.textBoxPrice.Location = new System.Drawing.Point(140, 52);
|
||||||
|
this.textBoxPrice.Name = "textBoxPrice";
|
||||||
|
this.textBoxPrice.Size = new System.Drawing.Size(144, 27);
|
||||||
|
this.textBoxPrice.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// groupBoxComponents
|
||||||
|
//
|
||||||
|
this.groupBoxComponents.Controls.Add(this.buttonRef);
|
||||||
|
this.groupBoxComponents.Controls.Add(this.buttonDel);
|
||||||
|
this.groupBoxComponents.Controls.Add(this.buttonUpd);
|
||||||
|
this.groupBoxComponents.Controls.Add(this.buttonAdd);
|
||||||
|
this.groupBoxComponents.Controls.Add(this.dataGridView);
|
||||||
|
this.groupBoxComponents.Location = new System.Drawing.Point(41, 95);
|
||||||
|
this.groupBoxComponents.Name = "groupBoxComponents";
|
||||||
|
this.groupBoxComponents.Size = new System.Drawing.Size(587, 291);
|
||||||
|
this.groupBoxComponents.TabIndex = 4;
|
||||||
|
this.groupBoxComponents.TabStop = false;
|
||||||
|
this.groupBoxComponents.Text = "Компоненты";
|
||||||
|
//
|
||||||
|
// buttonRef
|
||||||
|
//
|
||||||
|
this.buttonRef.Location = new System.Drawing.Point(464, 195);
|
||||||
|
this.buttonRef.Name = "buttonRef";
|
||||||
|
this.buttonRef.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonRef.TabIndex = 9;
|
||||||
|
this.buttonRef.Text = "Обновить";
|
||||||
|
this.buttonRef.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
this.buttonDel.Location = new System.Drawing.Point(464, 146);
|
||||||
|
this.buttonDel.Name = "buttonDel";
|
||||||
|
this.buttonDel.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonDel.TabIndex = 8;
|
||||||
|
this.buttonDel.Text = "Удалить";
|
||||||
|
this.buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||||
|
//
|
||||||
|
// buttonUpd
|
||||||
|
//
|
||||||
|
this.buttonUpd.Location = new System.Drawing.Point(464, 102);
|
||||||
|
this.buttonUpd.Name = "buttonUpd";
|
||||||
|
this.buttonUpd.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonUpd.TabIndex = 7;
|
||||||
|
this.buttonUpd.Text = "Изменить";
|
||||||
|
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(464, 55);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonAdd.TabIndex = 6;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.AllowUserToAddRows = false;
|
||||||
|
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||||
|
this.ID,
|
||||||
|
this.Component,
|
||||||
|
this.Count});
|
||||||
|
this.dataGridView.GridColor = System.Drawing.SystemColors.ControlDarkDark;
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(6, 26);
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
|
||||||
|
this.dataGridView.RowTemplate.Height = 29;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(428, 259);
|
||||||
|
this.dataGridView.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// ID
|
||||||
|
//
|
||||||
|
this.ID.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
this.ID.HeaderText = "";
|
||||||
|
this.ID.MinimumWidth = 6;
|
||||||
|
this.ID.Name = "ID";
|
||||||
|
this.ID.Resizable = System.Windows.Forms.DataGridViewTriState.True;
|
||||||
|
this.ID.Visible = false;
|
||||||
|
//
|
||||||
|
// Component
|
||||||
|
//
|
||||||
|
this.Component.HeaderText = "Компонент";
|
||||||
|
this.Component.MinimumWidth = 6;
|
||||||
|
this.Component.Name = "Component";
|
||||||
|
this.Component.Width = 125;
|
||||||
|
//
|
||||||
|
// Count
|
||||||
|
//
|
||||||
|
this.Count.HeaderText = "Количество";
|
||||||
|
this.Count.MinimumWidth = 6;
|
||||||
|
this.Count.Name = "Count";
|
||||||
|
this.Count.Width = 125;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(381, 392);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonSave.TabIndex = 10;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(505, 392);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonCancel.TabIndex = 11;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormSnack
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(660, 450);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.groupBoxComponents);
|
||||||
|
this.Controls.Add(this.textBoxPrice);
|
||||||
|
this.Controls.Add(this.textBoxName);
|
||||||
|
this.Controls.Add(this.labelPrice);
|
||||||
|
this.Controls.Add(this.labelName);
|
||||||
|
this.Name = "FormSnack";
|
||||||
|
this.Text = "Закуска";
|
||||||
|
this.Load += new System.EventHandler(this.FormProduct_Load);
|
||||||
|
this.groupBoxComponents.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label labelName;
|
||||||
|
private Label labelPrice;
|
||||||
|
private TextBox textBoxName;
|
||||||
|
private TextBox textBoxPrice;
|
||||||
|
private GroupBox groupBoxComponents;
|
||||||
|
private Button buttonRef;
|
||||||
|
private Button buttonDel;
|
||||||
|
private Button buttonUpd;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private DataGridViewTextBoxColumn ID;
|
||||||
|
private DataGridViewTextBoxColumn Component;
|
||||||
|
private DataGridViewTextBoxColumn Count;
|
||||||
|
private Button buttonSave;
|
||||||
|
private Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
209
Diner/Diner/FormSnack.cs
Normal file
209
Diner/Diner/FormSnack.cs
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.BusinessLogicsContracts;
|
||||||
|
using DinerContracts.SearchModels;
|
||||||
|
using DinerDataModels.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
public partial class FormSnack : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ISnackLogic _logic;
|
||||||
|
private int? _id;
|
||||||
|
private Dictionary<int, (IComponentModel, int)> _productComponents;
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
public FormSnack(ILogger<FormSnack> logger, ISnackLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
_productComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
}
|
||||||
|
private void FormProduct_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var view = _logic.ReadElement(new SnackSearchModel
|
||||||
|
{
|
||||||
|
Id = _id.Value
|
||||||
|
});
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
textBoxName.Text = view.SnackName;
|
||||||
|
textBoxPrice.Text = view.Price.ToString();
|
||||||
|
_productComponents = view.SnackComponents ?? new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка компонент изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_productComponents != null)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Clear();
|
||||||
|
foreach (var pc in _productComponents)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
|
||||||
|
}
|
||||||
|
textBoxPrice.Text = CalcPrice().ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки компонент изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service =
|
||||||
|
Program.ServiceProvider?.GetService(typeof(FormSnackComponent));
|
||||||
|
if (service is FormSnackComponent form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (form.ComponentModel == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
|
||||||
|
if (_productComponents.ContainsKey(form.Id))
|
||||||
|
{
|
||||||
|
_productComponents[form.Id] = (form.ComponentModel,
|
||||||
|
form.Count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_productComponents.Add(form.Id, (form.ComponentModel,
|
||||||
|
form.Count));
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service =
|
||||||
|
Program.ServiceProvider?.GetService(typeof(FormSnackComponent));
|
||||||
|
if (service is FormSnackComponent form)
|
||||||
|
{
|
||||||
|
int id =
|
||||||
|
Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
||||||
|
form.Id = id;
|
||||||
|
form.Count = _productComponents[id].Item2;
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (form.ComponentModel == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
|
||||||
|
_productComponents[form.Id] = (form.ComponentModel, form.Count);
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Вопрос",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
|
||||||
|
_productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRef_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните название", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(textBoxPrice.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_productComponents == null || _productComponents.Count == 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните компоненты", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Сохранение изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new SnackBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
SnackName = textBoxName.Text,
|
||||||
|
Price = Convert.ToDouble(textBoxPrice.Text),
|
||||||
|
SnackComponents = _productComponents
|
||||||
|
};
|
||||||
|
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||||
|
_logic.Create(model);
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка сохранения изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
private double CalcPrice()
|
||||||
|
{
|
||||||
|
double price = 0;
|
||||||
|
foreach (var elem in _productComponents)
|
||||||
|
{
|
||||||
|
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
|
||||||
|
}
|
||||||
|
return Math.Round(price * 1.1, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
69
Diner/Diner/FormSnack.resx
Normal file
69
Diner/Diner/FormSnack.resx
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<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>
|
||||||
|
<metadata name="ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="Component.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
119
Diner/Diner/FormSnackComponent.Designer.cs
generated
Normal file
119
Diner/Diner/FormSnackComponent.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
partial class FormSnackComponent
|
||||||
|
{
|
||||||
|
/// <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.textBoxCount = new System.Windows.Forms.TextBox();
|
||||||
|
this.labelNumber = new System.Windows.Forms.Label();
|
||||||
|
this.labelComponent = new System.Windows.Forms.Label();
|
||||||
|
this.comboBoxComponent = new System.Windows.Forms.ComboBox();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
this.textBoxCount.Location = new System.Drawing.Point(164, 88);
|
||||||
|
this.textBoxCount.Name = "textBoxCount";
|
||||||
|
this.textBoxCount.Size = new System.Drawing.Size(243, 27);
|
||||||
|
this.textBoxCount.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// labelNumber
|
||||||
|
//
|
||||||
|
this.labelNumber.AutoSize = true;
|
||||||
|
this.labelNumber.Location = new System.Drawing.Point(40, 88);
|
||||||
|
this.labelNumber.Name = "labelNumber";
|
||||||
|
this.labelNumber.Size = new System.Drawing.Size(93, 20);
|
||||||
|
this.labelNumber.TabIndex = 1;
|
||||||
|
this.labelNumber.Text = "Количество:";
|
||||||
|
//
|
||||||
|
// labelComponent
|
||||||
|
//
|
||||||
|
this.labelComponent.AutoSize = true;
|
||||||
|
this.labelComponent.Location = new System.Drawing.Point(40, 44);
|
||||||
|
this.labelComponent.Name = "labelComponent";
|
||||||
|
this.labelComponent.Size = new System.Drawing.Size(91, 20);
|
||||||
|
this.labelComponent.TabIndex = 2;
|
||||||
|
this.labelComponent.Text = "Компонент:";
|
||||||
|
//
|
||||||
|
// comboBoxComponent
|
||||||
|
//
|
||||||
|
this.comboBoxComponent.FormattingEnabled = true;
|
||||||
|
this.comboBoxComponent.Location = new System.Drawing.Point(164, 44);
|
||||||
|
this.comboBoxComponent.Name = "comboBoxComponent";
|
||||||
|
this.comboBoxComponent.Size = new System.Drawing.Size(243, 28);
|
||||||
|
this.comboBoxComponent.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(194, 141);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonSave.TabIndex = 4;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(313, 141);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonCancel.TabIndex = 5;
|
||||||
|
this.buttonCancel.Text = "Отменить";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormSnackComponent
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(438, 199);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.comboBoxComponent);
|
||||||
|
this.Controls.Add(this.labelComponent);
|
||||||
|
this.Controls.Add(this.labelNumber);
|
||||||
|
this.Controls.Add(this.textBoxCount);
|
||||||
|
this.Name = "FormSnackComponent";
|
||||||
|
this.Text = "Добавление компонента";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private TextBox textBoxCount;
|
||||||
|
private Label labelNumber;
|
||||||
|
private Label labelComponent;
|
||||||
|
private ComboBox comboBoxComponent;
|
||||||
|
private Button buttonSave;
|
||||||
|
private Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
80
Diner/Diner/FormSnackComponent.cs
Normal file
80
Diner/Diner/FormSnackComponent.cs
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
using DinerContracts.BusinessLogicsContracts;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
|
using DinerDataModels.Models;
|
||||||
|
|
||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
public partial class FormSnackComponent : Form
|
||||||
|
{
|
||||||
|
private readonly List<ComponentViewModel>? _list;
|
||||||
|
public int Id
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Convert.ToInt32(comboBoxComponent.SelectedValue);
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
comboBoxComponent.SelectedValue = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IComponentModel? ComponentModel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_list == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var elem in _list)
|
||||||
|
{
|
||||||
|
if (elem.Id == Id)
|
||||||
|
{
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int Count
|
||||||
|
{
|
||||||
|
get { return Convert.ToInt32(textBoxCount.Text); }
|
||||||
|
set
|
||||||
|
{ textBoxCount.Text = value.ToString(); }
|
||||||
|
}
|
||||||
|
public FormSnackComponent(IComponentLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_list = logic.ReadList(null);
|
||||||
|
if (_list != null)
|
||||||
|
{
|
||||||
|
comboBoxComponent.DisplayMember = "ComponentName";
|
||||||
|
comboBoxComponent.ValueMember = "Id";
|
||||||
|
comboBoxComponent.DataSource = _list;
|
||||||
|
comboBoxComponent.SelectedItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxComponent.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите компонент", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
Diner/Diner/FormSnackComponent.resx
Normal file
60
Diner/Diner/FormSnackComponent.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>
|
123
Diner/Diner/FormSnacks.Designer.cs
generated
Normal file
123
Diner/Diner/FormSnacks.Designer.cs
generated
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
partial class FormSnacks
|
||||||
|
{
|
||||||
|
/// <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.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonChange = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDelete = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.dataGridView.Margin = new System.Windows.Forms.Padding(2);
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.RowHeadersWidth = 62;
|
||||||
|
this.dataGridView.RowTemplate.Height = 33;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(514, 390);
|
||||||
|
this.dataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(545, 27);
|
||||||
|
this.buttonAdd.Margin = new System.Windows.Forms.Padding(2);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(90, 27);
|
||||||
|
this.buttonAdd.TabIndex = 1;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
|
//
|
||||||
|
// buttonChange
|
||||||
|
//
|
||||||
|
this.buttonChange.Location = new System.Drawing.Point(546, 69);
|
||||||
|
this.buttonChange.Margin = new System.Windows.Forms.Padding(2);
|
||||||
|
this.buttonChange.Name = "buttonChange";
|
||||||
|
this.buttonChange.Size = new System.Drawing.Size(90, 27);
|
||||||
|
this.buttonChange.TabIndex = 2;
|
||||||
|
this.buttonChange.Text = "Изменить";
|
||||||
|
this.buttonChange.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonChange.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||||
|
//
|
||||||
|
// buttonDelete
|
||||||
|
//
|
||||||
|
this.buttonDelete.Location = new System.Drawing.Point(545, 113);
|
||||||
|
this.buttonDelete.Margin = new System.Windows.Forms.Padding(2);
|
||||||
|
this.buttonDelete.Name = "buttonDelete";
|
||||||
|
this.buttonDelete.Size = new System.Drawing.Size(90, 27);
|
||||||
|
this.buttonDelete.TabIndex = 3;
|
||||||
|
this.buttonDelete.Text = "Удалить";
|
||||||
|
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||||
|
//
|
||||||
|
// buttonUpdate
|
||||||
|
//
|
||||||
|
this.buttonUpdate.Location = new System.Drawing.Point(546, 153);
|
||||||
|
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(2);
|
||||||
|
this.buttonUpdate.Name = "buttonUpdate";
|
||||||
|
this.buttonUpdate.Size = new System.Drawing.Size(90, 27);
|
||||||
|
this.buttonUpdate.TabIndex = 4;
|
||||||
|
this.buttonUpdate.Text = "Обновить";
|
||||||
|
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||||
|
//
|
||||||
|
// FormSnacks
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(661, 390);
|
||||||
|
this.Controls.Add(this.buttonUpdate);
|
||||||
|
this.Controls.Add(this.buttonDelete);
|
||||||
|
this.Controls.Add(this.buttonChange);
|
||||||
|
this.Controls.Add(this.buttonAdd);
|
||||||
|
this.Controls.Add(this.dataGridView);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(2);
|
||||||
|
this.Name = "FormSnacks";
|
||||||
|
this.Text = "Закуски";
|
||||||
|
this.Load += new System.EventHandler(this.FormProducts_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private Button buttonAdd;
|
||||||
|
private Button buttonChange;
|
||||||
|
private Button buttonDelete;
|
||||||
|
private Button buttonUpdate;
|
||||||
|
}
|
||||||
|
}
|
109
Diner/Diner/FormSnacks.cs
Normal file
109
Diner/Diner/FormSnacks.cs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
using DinerContracts.BindingModels;
|
||||||
|
using DinerContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
public partial class FormSnacks : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ISnackLogic _logic;
|
||||||
|
|
||||||
|
public FormSnacks(ILogger<FormSnacks> logger, ISnackLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logic.ReadList(null);
|
||||||
|
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
dataGridView.DataSource = list;
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
|
dataGridView.Columns["SnackName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["SnackComponents"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("Загрузка компонентов");
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormSnack));
|
||||||
|
|
||||||
|
if (service is FormSnack form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormSnack));
|
||||||
|
|
||||||
|
if (service is FormSnack 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("Удаление компонента");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!_logic.Delete(new SnackBindingModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления компонента");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRef_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
private void FormProducts_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
Diner/Diner/FormSnacks.resx
Normal file
60
Diner/Diner/FormSnacks.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>
|
51
Diner/Diner/Program.cs
Normal file
51
Diner/Diner/Program.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using DinerContracts.BusinessLogicsContracts;
|
||||||
|
using DinerContracts.StoragesContracts;
|
||||||
|
using DinerListImplement.Implements;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
using DinerBusinessLogic.BusinessLogics;
|
||||||
|
|
||||||
|
namespace Diner
|
||||||
|
{
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
private static ServiceProvider? _serviceProvider;
|
||||||
|
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||||
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
|
// see https://aka.ms/applicationconfiguration.
|
||||||
|
ApplicationConfiguration.Initialize();
|
||||||
|
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<ISnackStorage, SnackStorage>();
|
||||||
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
|
services.AddTransient<ISnackLogic, SnackLogic>();
|
||||||
|
services.AddTransient<FormMain>();
|
||||||
|
services.AddTransient<FormComponent>();
|
||||||
|
services.AddTransient<FormComponents>();
|
||||||
|
services.AddTransient<FormCreateOrder>();
|
||||||
|
services.AddTransient<FormSnack>();
|
||||||
|
services.AddTransient<FormSnackComponent>();
|
||||||
|
services.AddTransient<FormSnacks>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
This file is automatically generated by Visual Studio. It is
|
||||||
|
used to store generic object data source configuration information.
|
||||||
|
Renaming the file extension or editing the content of this file may
|
||||||
|
cause the file to be unrecognizable by the program.
|
||||||
|
-->
|
||||||
|
<GenericObjectDataSource DisplayName="DataListSingleton" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
|
||||||
|
<TypeInfo>DinerListImplement.DataListSingleton, DinerListImplement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
|
||||||
|
</GenericObjectDataSource>
|
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
This file is automatically generated by Visual Studio. It is
|
||||||
|
used to store generic object data source configuration information.
|
||||||
|
Renaming the file extension or editing the content of this file may
|
||||||
|
cause the file to be unrecognizable by the program.
|
||||||
|
-->
|
||||||
|
<GenericObjectDataSource DisplayName="ComponentStorage" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
|
||||||
|
<TypeInfo>DinerListImplement.Implements.ComponentStorage, DinerListImplement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
|
||||||
|
</GenericObjectDataSource>
|
15
Diner/Diner/nlog.config
Normal file
15
Diner/Diner/nlog.config
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
autoReload="true" internalLogLevel="Info">
|
||||||
|
|
||||||
|
<targets>
|
||||||
|
<target xsi:type="File" name="file" fileName="${basedir}/carlog-${shortdate}.log" />
|
||||||
|
</targets>
|
||||||
|
|
||||||
|
<rules>
|
||||||
|
<logger name="*" minlevel="Debug" writeTo="file" />
|
||||||
|
</rules>
|
||||||
|
</nlog>
|
||||||
|
</configuration>
|
39
Diner/Form1.Designer.cs
generated
39
Diner/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
|||||||
namespace Diner
|
|
||||||
{
|
|
||||||
partial class Form1
|
|
||||||
{
|
|
||||||
/// <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.components = new System.ComponentModel.Container();
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
|
||||||
this.Text = "Form1";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace Diner
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
120
Diner/Form1.resx
120
Diner/Form1.resx
@ -1,120 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<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,17 +0,0 @@
|
|||||||
namespace Diner
|
|
||||||
{
|
|
||||||
internal static class Program
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The main entry point for the application.
|
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
|
||||||
static void Main()
|
|
||||||
{
|
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
|
||||||
// see https://aka.ms/applicationconfiguration.
|
|
||||||
ApplicationConfiguration.Initialize();
|
|
||||||
Application.Run(new Form1());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user