Compare commits
No commits in common. "Lab3_base" and "main" have entirely different histories.
@ -3,19 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.7.34221.43
|
VisualStudioVersion = 17.7.34221.43
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrdersView", "FoodOrdersView\FoodOrdersView.csproj", "{C61B8C6C-4777-4AB5-854F-55EA1F16622C}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodOrdersView", "FoodOrdersView\FoodOrdersView.csproj", "{C61B8C6C-4777-4AB5-854F-55EA1F16622C}"
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrdersBusinessLogic", "FoodOrdersBusinessLogic\FoodOrdersBusinessLogic.csproj", "{AFE774E2-073F-4E58-81A3-F7044B0693CD}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrdersContracts", "FoodOrdersContracts\FoodOrdersContracts.csproj", "{B44AFA6F-DEB5-473C-9884-656D7A80B8C4}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrdersDataModels", "FoodOrdersDataModels\FoodOrdersDataModels.csproj", "{F780BF8C-B0AF-4CF2-B621-5705877AEE59}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrdersListImplement", "FoodOrdersListImplement\FoodOrdersListImplement.csproj", "{8FBCE353-A28A-4A69-8F6D-086421E781D9}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodOrdersFileImplement", "FoodOrdersFileImplement\FoodOrdersFileImplement.csproj", "{92F623B7-C680-4A3A-9749-26E87628A02E}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodOrdersDatabaseImplement", "FoodOrdersDatabaseImplement\FoodOrdersDatabaseImplement.csproj", "{2190363C-BB1A-4955-B88F-C5F516D7A758}"
|
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -27,30 +15,6 @@ Global
|
|||||||
{C61B8C6C-4777-4AB5-854F-55EA1F16622C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{C61B8C6C-4777-4AB5-854F-55EA1F16622C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{C61B8C6C-4777-4AB5-854F-55EA1F16622C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{C61B8C6C-4777-4AB5-854F-55EA1F16622C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{C61B8C6C-4777-4AB5-854F-55EA1F16622C}.Release|Any CPU.Build.0 = Release|Any CPU
|
{C61B8C6C-4777-4AB5-854F-55EA1F16622C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{AFE774E2-073F-4E58-81A3-F7044B0693CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{AFE774E2-073F-4E58-81A3-F7044B0693CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{AFE774E2-073F-4E58-81A3-F7044B0693CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{AFE774E2-073F-4E58-81A3-F7044B0693CD}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{B44AFA6F-DEB5-473C-9884-656D7A80B8C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{B44AFA6F-DEB5-473C-9884-656D7A80B8C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{B44AFA6F-DEB5-473C-9884-656D7A80B8C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{B44AFA6F-DEB5-473C-9884-656D7A80B8C4}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{F780BF8C-B0AF-4CF2-B621-5705877AEE59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{F780BF8C-B0AF-4CF2-B621-5705877AEE59}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{F780BF8C-B0AF-4CF2-B621-5705877AEE59}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{F780BF8C-B0AF-4CF2-B621-5705877AEE59}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{8FBCE353-A28A-4A69-8F6D-086421E781D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{8FBCE353-A28A-4A69-8F6D-086421E781D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{8FBCE353-A28A-4A69-8F6D-086421E781D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{8FBCE353-A28A-4A69-8F6D-086421E781D9}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{92F623B7-C680-4A3A-9749-26E87628A02E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{92F623B7-C680-4A3A-9749-26E87628A02E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{92F623B7-C680-4A3A-9749-26E87628A02E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{92F623B7-C680-4A3A-9749-26E87628A02E}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{2190363C-BB1A-4955-B88F-C5F516D7A758}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{2190363C-BB1A-4955-B88F-C5F516D7A758}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{2190363C-BB1A-4955-B88F-C5F516D7A758}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{2190363C-BB1A-4955-B88F-C5F516D7A758}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -1,115 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.BusinessLogicsContracts;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.StoragesContracts;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace FoodOrdersBusinessLogic.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("Компонент с таким названием уже есть");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,119 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.BusinessLogicsContracts;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.StoragesContracts;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace FoodOrdersBusinessLogic.BusinessLogics
|
|
||||||
{
|
|
||||||
public class DishLogic : IDishLogic
|
|
||||||
{
|
|
||||||
private readonly ILogger _logger;
|
|
||||||
|
|
||||||
private readonly IDishStorage _DishStorage;
|
|
||||||
|
|
||||||
public DishLogic(ILogger<DishLogic> logger, IDishStorage DishStorage)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
_DishStorage = DishStorage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DishViewModel>? ReadList(DishSearchModel? model)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("ReadList. DishName: {DishName}. Id: {Id}", model?.DishName, model?.Id);
|
|
||||||
var list = model == null ? _DishStorage.GetFullList() : _DishStorage.GetFilteredList(model);
|
|
||||||
if (list == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("ReadList return null list");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel? ReadElement(DishSearchModel model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(model));
|
|
||||||
}
|
|
||||||
_logger.LogInformation("ReadElement. DishName: {DishName}. Id: {Id}", model.DishName, model.Id);
|
|
||||||
var element = _DishStorage.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(DishBindingModel model)
|
|
||||||
{
|
|
||||||
CheckModel(model);
|
|
||||||
if (_DishStorage.Insert(model) == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Insert operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Update(DishBindingModel model)
|
|
||||||
{
|
|
||||||
CheckModel(model);
|
|
||||||
if (_DishStorage.Update(model) == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Update operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Delete(DishBindingModel model)
|
|
||||||
{
|
|
||||||
CheckModel(model, false);
|
|
||||||
_logger.LogInformation("Delete. Id: {Id}", model.Id);
|
|
||||||
if (_DishStorage.Delete(model) == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Delete operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckModel(DishBindingModel model, bool withParams = true)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(model));
|
|
||||||
}
|
|
||||||
if (!withParams)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (string.IsNullOrEmpty(model.DishName))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("Нет названия блюда", nameof(model.DishName));
|
|
||||||
}
|
|
||||||
if (model.Price <= 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("Цена блюда должна быть больше 0", nameof(model.Price));
|
|
||||||
}
|
|
||||||
if (model.DishComponents == null || model.DishComponents.Count == 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("Блюдо должно состоять хотя бы из одного компонента");
|
|
||||||
}
|
|
||||||
_logger.LogInformation("Dish. DishName: {DishName}. Price: {Price}. Id: {Id}", model.DishName, model.Price, model.Id);
|
|
||||||
var element = _DishStorage.GetElement(new DishSearchModel
|
|
||||||
{
|
|
||||||
DishName = model.DishName
|
|
||||||
});
|
|
||||||
if (element != null && element.Id != model.Id)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Блюдо с таким названием уже есть");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,129 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.BusinessLogicsContracts;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.StoragesContracts;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersDataModels.Enums;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace FoodOrdersBusinessLogic.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 bool CreateOrder(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
CheckModel(model);
|
|
||||||
if (model.Status != OrderStatus.Неизвестен)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Invalid order status");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
model.Status = OrderStatus.Принят;
|
|
||||||
if (_orderStorage.Insert(model) == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Insert operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("ReadList. OrderId: {Id}.", model?.Id);
|
|
||||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
|
||||||
if (list == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("ReadList return null list");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TakeOrderInWork(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
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.DishId <= 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("Некорректный идентификатор блюда", nameof(model.DishId));
|
|
||||||
}
|
|
||||||
if (model.Count <= 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("В заказе должно быть хотя бы одна блюдо", nameof(model.Count));
|
|
||||||
}
|
|
||||||
if (model.Sum <= 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum));
|
|
||||||
}
|
|
||||||
_logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. DishId: {DishId}. DishCount: {Count}", model.Id, model.Sum,
|
|
||||||
model.DishId, model.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus)
|
|
||||||
{
|
|
||||||
CheckModel(model, false);
|
|
||||||
var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id } );
|
|
||||||
if (order == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Change status operation failed. Order not found");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (order.Status + 1 != newStatus)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Change status operation failed. Incorrect new status: {newStatus}. Current status: {currStatus}",
|
|
||||||
newStatus, order.Status);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
model.DishId = order.DishId;
|
|
||||||
model.Count = order.Count;
|
|
||||||
model.Sum = order.Sum;
|
|
||||||
model.DateCreate = order.DateCreate;
|
|
||||||
model.Status = newStatus;
|
|
||||||
if (model.Status == OrderStatus.Готов)
|
|
||||||
{
|
|
||||||
model.DateImplement = DateTime.Now;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
model.DateImplement = order.DateImplement;
|
|
||||||
}
|
|
||||||
if (_orderStorage.Update(model) == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Change status operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\FoodOrdersContracts\FoodOrdersContracts.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,13 +0,0 @@
|
|||||||
using FoodOrdersDataModels.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersContracts.BindingModels
|
|
||||||
{
|
|
||||||
public class ComponentBindingModel : IComponentModel
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
public string ComponentName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public double Cost { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
using FoodOrdersDataModels.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersContracts.BindingModels
|
|
||||||
{
|
|
||||||
public class DishBindingModel : IDishModel
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
public string DishName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public double Price { get; set; }
|
|
||||||
|
|
||||||
public Dictionary<int, (IComponentModel, int)> DishComponents
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
} = new();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
using FoodOrdersDataModels.Enums;
|
|
||||||
using FoodOrdersDataModels.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersContracts.BindingModels
|
|
||||||
{
|
|
||||||
public class OrderBindingModel : IOrderModel
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
public int DishId { 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; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
|
|
||||||
namespace FoodOrdersContracts.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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
|
|
||||||
namespace FoodOrdersContracts.BusinessLogicsContracts
|
|
||||||
{
|
|
||||||
public interface IDishLogic
|
|
||||||
{
|
|
||||||
List<DishViewModel>? ReadList(DishSearchModel? model);
|
|
||||||
|
|
||||||
DishViewModel? ReadElement(DishSearchModel model);
|
|
||||||
|
|
||||||
bool Create(DishBindingModel model);
|
|
||||||
|
|
||||||
bool Update(DishBindingModel model);
|
|
||||||
|
|
||||||
bool Delete(DishBindingModel model);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
|
|
||||||
namespace FoodOrdersContracts.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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\FoodOrdersDataModels\FoodOrdersDataModels.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,9 +0,0 @@
|
|||||||
namespace FoodOrdersContracts.SearchModels
|
|
||||||
{
|
|
||||||
public class ComponentSearchModel
|
|
||||||
{
|
|
||||||
public int? Id { get; set; }
|
|
||||||
|
|
||||||
public string? ComponentName { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
namespace FoodOrdersContracts.SearchModels
|
|
||||||
{
|
|
||||||
public class DishSearchModel
|
|
||||||
{
|
|
||||||
public int? Id { get; set; }
|
|
||||||
|
|
||||||
public string? DishName { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
namespace FoodOrdersContracts.SearchModels
|
|
||||||
{
|
|
||||||
public class OrderSearchModel
|
|
||||||
{
|
|
||||||
public int? Id { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
|
|
||||||
namespace FoodOrdersContracts.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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
|
|
||||||
namespace FoodOrdersContracts.StoragesContracts
|
|
||||||
{
|
|
||||||
public interface IDishStorage
|
|
||||||
{
|
|
||||||
List<DishViewModel> GetFullList();
|
|
||||||
|
|
||||||
List<DishViewModel> GetFilteredList(DishSearchModel model);
|
|
||||||
|
|
||||||
DishViewModel? GetElement(DishSearchModel model);
|
|
||||||
|
|
||||||
DishViewModel? Insert(DishBindingModel model);
|
|
||||||
|
|
||||||
DishViewModel? Update(DishBindingModel model);
|
|
||||||
|
|
||||||
DishViewModel? Delete(DishBindingModel model);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
|
|
||||||
namespace FoodOrdersContracts.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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
using FoodOrdersDataModels.Models;
|
|
||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
namespace FoodOrdersContracts.ViewModels
|
|
||||||
{
|
|
||||||
public class ComponentViewModel : IComponentModel
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
[DisplayName("Название компонента")]
|
|
||||||
public string ComponentName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
[DisplayName("Цена")]
|
|
||||||
public double Cost { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
using FoodOrdersDataModels.Models;
|
|
||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
namespace FoodOrdersContracts.ViewModels
|
|
||||||
{
|
|
||||||
public class DishViewModel : IDishModel
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
[DisplayName("Название блюда")]
|
|
||||||
public string DishName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
[DisplayName("Цена")]
|
|
||||||
public double Price { get; set; }
|
|
||||||
|
|
||||||
public Dictionary<int, (IComponentModel, int)> DishComponents
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
} = new();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
using FoodOrdersDataModels.Enums;
|
|
||||||
using FoodOrdersDataModels.Models;
|
|
||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
namespace FoodOrdersContracts.ViewModels
|
|
||||||
{
|
|
||||||
public class OrderViewModel : IOrderModel
|
|
||||||
{
|
|
||||||
[DisplayName("Номер")]
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
public int DishId { get; set; }
|
|
||||||
|
|
||||||
[DisplayName("Еда")]
|
|
||||||
public string DishName { 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; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
namespace FoodOrdersDataModels.Enums
|
|
||||||
{
|
|
||||||
public enum OrderStatus
|
|
||||||
{
|
|
||||||
Неизвестен = -1,
|
|
||||||
|
|
||||||
Принят = 0,
|
|
||||||
|
|
||||||
Выполняется = 1,
|
|
||||||
|
|
||||||
Готов = 2,
|
|
||||||
|
|
||||||
Выдан = 3
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,7 +0,0 @@
|
|||||||
namespace FoodOrdersDataModels
|
|
||||||
{
|
|
||||||
public interface IId
|
|
||||||
{
|
|
||||||
int Id { get; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
namespace FoodOrdersDataModels.Models
|
|
||||||
{
|
|
||||||
public interface IComponentModel : IId
|
|
||||||
{
|
|
||||||
string ComponentName { get; }
|
|
||||||
|
|
||||||
double Cost { get; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
namespace FoodOrdersDataModels.Models
|
|
||||||
{
|
|
||||||
public interface IDishModel : IId
|
|
||||||
{
|
|
||||||
string DishName { get; }
|
|
||||||
|
|
||||||
double Price { get; }
|
|
||||||
|
|
||||||
Dictionary<int, (IComponentModel, int)> DishComponents { get; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
using FoodOrdersDataModels.Enums;
|
|
||||||
|
|
||||||
namespace FoodOrdersDataModels.Models
|
|
||||||
{
|
|
||||||
public interface IOrderModel : IId
|
|
||||||
{
|
|
||||||
int DishId { get; }
|
|
||||||
|
|
||||||
int Count { get; }
|
|
||||||
|
|
||||||
double Sum { get; }
|
|
||||||
|
|
||||||
OrderStatus Status { get; }
|
|
||||||
|
|
||||||
DateTime DateCreate { get; }
|
|
||||||
|
|
||||||
DateTime? DateImplement { get; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using FoodOrdersDatabaseImplement.Models;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace FoodOrdersDatabaseImplement
|
|
||||||
{
|
|
||||||
public class FoodOrdersDatabase : DbContext
|
|
||||||
{
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder
|
|
||||||
optionsBuilder)
|
|
||||||
{
|
|
||||||
if (optionsBuilder.IsConfigured == false)
|
|
||||||
{
|
|
||||||
optionsBuilder.UseSqlServer(@"Data Source=.\SQLEXPRESS;Initial Catalog=FoodOrdersDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
|
||||||
}
|
|
||||||
base.OnConfiguring(optionsBuilder);
|
|
||||||
}
|
|
||||||
public virtual DbSet<Component> Components { set; get; }
|
|
||||||
public virtual DbSet<Dish> Dishs { set; get; }
|
|
||||||
public virtual DbSet<DishComponent> DishComponents { set; get; }
|
|
||||||
public virtual DbSet<Order> Orders { set; get; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.16" />
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.16" />
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.16">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="FoodOrdersContracts">
|
|
||||||
<HintPath>..\FoodOrdersContracts\obj\Debug\net6.0\ref\FoodOrdersContracts.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="FoodOrdersDataModels">
|
|
||||||
<HintPath>..\FoodOrdersDataModels\obj\Debug\net6.0\ref\FoodOrdersDataModels.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,84 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.StoragesContracts;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersDatabaseImplement.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersDatabaseImplement.Implements
|
|
||||||
{
|
|
||||||
public class ComponentStorage : IComponentStorage
|
|
||||||
{
|
|
||||||
public List<ComponentViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
return context.Components.Select(x => x.GetViewModel).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.ComponentName))
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
return context.Components.Where(
|
|
||||||
x => x.ComponentName.Contains(model.ComponentName)
|
|
||||||
).Select(x => x.GetViewModel).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
return context.Components.FirstOrDefault(
|
|
||||||
x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
|
||||||
{
|
|
||||||
var newComponent = Component.Create(model);
|
|
||||||
if (newComponent == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
context.Components.Add(newComponent);
|
|
||||||
context.SaveChanges();
|
|
||||||
return newComponent.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
var component = context.Components.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (component == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
component.Update(model);
|
|
||||||
context.SaveChanges();
|
|
||||||
return component.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
|
||||||
if (element != null)
|
|
||||||
{
|
|
||||||
context.Components.Remove(element);
|
|
||||||
context.SaveChanges();
|
|
||||||
return element.GetViewModel;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,132 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersDatabaseImplement.Models;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection.Metadata;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
using FoodOrdersContracts.StoragesContracts;
|
|
||||||
using System.Runtime.ConstrainedExecution;
|
|
||||||
|
|
||||||
namespace FoodOrdersDatabaseImplement.Implements
|
|
||||||
{
|
|
||||||
public class DishStorage : IDishStorage
|
|
||||||
{
|
|
||||||
public List<DishViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
return context.Dishs
|
|
||||||
.Include(x => x.Components)
|
|
||||||
.ThenInclude(x => x.Component)
|
|
||||||
.ToList()
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DishViewModel> GetFilteredList(DishSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.DishName))
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
return context.Dishs
|
|
||||||
.Include(x => x.Components)
|
|
||||||
.ThenInclude(x => x.Component)
|
|
||||||
.Where(x => x.DishName.Contains(model.DishName))
|
|
||||||
.ToList()
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel? GetElement(DishSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.DishName) && !model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
return context.Dishs.Include(
|
|
||||||
x => x.Components
|
|
||||||
).ThenInclude(x => x.Component).FirstOrDefault(x => (
|
|
||||||
!string.IsNullOrEmpty(model.DishName) &&
|
|
||||||
x.DishName == model.DishName) || (model.Id.HasValue && x.Id == model.Id)
|
|
||||||
)?.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel? Insert(DishBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
using var transaction = context.Database.BeginTransaction();
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var newDish = Dish.Create(context, model);
|
|
||||||
if (newDish == null)
|
|
||||||
{
|
|
||||||
transaction.Rollback();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
context.Dishs.Add(newDish);
|
|
||||||
|
|
||||||
context.SaveChanges();
|
|
||||||
context.Database.CommitTransaction();
|
|
||||||
|
|
||||||
return newDish.GetViewModel;
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
transaction.Rollback();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel? Update(DishBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
using var transaction = context.Database.BeginTransaction();
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var Dish = context.Dishs.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (Dish == null)
|
|
||||||
{
|
|
||||||
transaction.Rollback();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dish.Update(model);
|
|
||||||
Dish.UpdateComponents(context, model);
|
|
||||||
|
|
||||||
context.SaveChanges();
|
|
||||||
context.Database.CommitTransaction();
|
|
||||||
|
|
||||||
return Dish.GetViewModel;
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
transaction.Rollback();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public DishViewModel? Delete(DishBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
var element = context.Dishs.FirstOrDefault(rec => rec.Id == model.Id);
|
|
||||||
if (element != null)
|
|
||||||
{
|
|
||||||
context.Dishs.Remove(element);
|
|
||||||
context.SaveChanges();
|
|
||||||
return element.GetViewModel;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,85 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.StoragesContracts;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersDatabaseImplement.Models;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace FoodOrdersDatabaseImplement.Implements
|
|
||||||
{
|
|
||||||
public class OrderStorage : IOrderStorage
|
|
||||||
{
|
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
if (!model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
return context.Orders.Include(x => x.Dish).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
if (!model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
return context.Orders
|
|
||||||
.Where(x => x.Id == model.Id)
|
|
||||||
.Include(x => x.Dish)
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OrderViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
return context.Orders.Include(x => x.Dish).Select(x => x.GetViewModel).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
var newOrder = Order.Create(model);
|
|
||||||
if (newOrder == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
context.Orders.Add(newOrder);
|
|
||||||
context.SaveChanges();
|
|
||||||
return context.Orders.Include(x => x.Dish).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (order == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
order.Update(model);
|
|
||||||
context.SaveChanges();
|
|
||||||
return context.Orders.Include(x => x.Dish).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
|
||||||
}
|
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new FoodOrdersDatabase();
|
|
||||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
|
||||||
if (element != null)
|
|
||||||
{
|
|
||||||
context.Orders.Remove(element);
|
|
||||||
context.SaveChanges();
|
|
||||||
return element.GetViewModel;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,171 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using FoodOrdersDatabaseImplement;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace FoodOrdersDatabaseImplement.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(FoodOrdersDatabase))]
|
|
||||||
[Migration("20240311061233_InitialCreate")]
|
|
||||||
partial class InitialCreate
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder
|
|
||||||
.HasAnnotation("ProductVersion", "7.0.16")
|
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
|
||||||
|
|
||||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("ComponentName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.Property<double>("Cost")
|
|
||||||
.HasColumnType("float");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Components");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("DishName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.Property<double>("Price")
|
|
||||||
.HasColumnType("float");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Dishs");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("ComponentId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("DishId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ComponentId");
|
|
||||||
|
|
||||||
b.HasIndex("DishId");
|
|
||||||
|
|
||||||
b.ToTable("DishComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreate")
|
|
||||||
.HasColumnType("datetime2");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("DateImplement")
|
|
||||||
.HasColumnType("datetime2");
|
|
||||||
|
|
||||||
b.Property<int>("DishId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Status")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<double>("Sum")
|
|
||||||
.HasColumnType("float");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("DishId");
|
|
||||||
|
|
||||||
b.ToTable("Orders");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("FoodOrdersDatabaseImplement.Models.Component", "Component")
|
|
||||||
.WithMany("DishComponents")
|
|
||||||
.HasForeignKey("ComponentId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish")
|
|
||||||
.WithMany("Components")
|
|
||||||
.HasForeignKey("DishId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Component");
|
|
||||||
|
|
||||||
b.Navigation("Dish");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish")
|
|
||||||
.WithMany("Orders")
|
|
||||||
.HasForeignKey("DishId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Dish");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("DishComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Components");
|
|
||||||
|
|
||||||
b.Navigation("Orders");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,125 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace FoodOrdersDatabaseImplement.Migrations
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class InitialCreate : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Components",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
|
||||||
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
||||||
Cost = table.Column<double>(type: "float", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Components", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Dishs",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
|
||||||
DishName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
|
||||||
Price = table.Column<double>(type: "float", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Dishs", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "DishComponents",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
|
||||||
DishId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
ComponentId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
Count = table.Column<int>(type: "int", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_DishComponents", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_DishComponents_Components_ComponentId",
|
|
||||||
column: x => x.ComponentId,
|
|
||||||
principalTable: "Components",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_DishComponents_Dishs_DishId",
|
|
||||||
column: x => x.DishId,
|
|
||||||
principalTable: "Dishs",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Orders",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "int", nullable: false)
|
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
|
||||||
DishId = table.Column<int>(type: "int", nullable: false),
|
|
||||||
Count = table.Column<int>(type: "int", nullable: false),
|
|
||||||
Sum = table.Column<double>(type: "float", nullable: false),
|
|
||||||
Status = table.Column<int>(type: "int", nullable: false),
|
|
||||||
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
|
||||||
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Orders_Dishs_DishId",
|
|
||||||
column: x => x.DishId,
|
|
||||||
principalTable: "Dishs",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_DishComponents_ComponentId",
|
|
||||||
table: "DishComponents",
|
|
||||||
column: "ComponentId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_DishComponents_DishId",
|
|
||||||
table: "DishComponents",
|
|
||||||
column: "DishId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Orders_DishId",
|
|
||||||
table: "Orders",
|
|
||||||
column: "DishId");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "DishComponents");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Orders");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Components");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Dishs");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,168 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using FoodOrdersDatabaseImplement;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Metadata;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace FoodOrdersDatabaseImplement.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(FoodOrdersDatabase))]
|
|
||||||
partial class FoodOrdersDatabaseModelSnapshot : ModelSnapshot
|
|
||||||
{
|
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder
|
|
||||||
.HasAnnotation("ProductVersion", "7.0.16")
|
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
|
||||||
|
|
||||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("ComponentName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.Property<double>("Cost")
|
|
||||||
.HasColumnType("float");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Components");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("DishName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.Property<double>("Price")
|
|
||||||
.HasColumnType("float");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Dishs");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("ComponentId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("DishId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ComponentId");
|
|
||||||
|
|
||||||
b.HasIndex("DishId");
|
|
||||||
|
|
||||||
b.ToTable("DishComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreate")
|
|
||||||
.HasColumnType("datetime2");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("DateImplement")
|
|
||||||
.HasColumnType("datetime2");
|
|
||||||
|
|
||||||
b.Property<int>("DishId")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int>("Status")
|
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<double>("Sum")
|
|
||||||
.HasColumnType("float");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("DishId");
|
|
||||||
|
|
||||||
b.ToTable("Orders");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("FoodOrdersDatabaseImplement.Models.Component", "Component")
|
|
||||||
.WithMany("DishComponents")
|
|
||||||
.HasForeignKey("ComponentId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish")
|
|
||||||
.WithMany("Components")
|
|
||||||
.HasForeignKey("DishId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Component");
|
|
||||||
|
|
||||||
b.Navigation("Dish");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("FoodOrdersDatabaseImplement.Models.Dish", "Dish")
|
|
||||||
.WithMany("Orders")
|
|
||||||
.HasForeignKey("DishId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Dish");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("DishComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Components");
|
|
||||||
|
|
||||||
b.Navigation("Orders");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
using FoodOrdersDataModels.Models;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
|
|
||||||
namespace FoodOrdersDatabaseImplement.Models
|
|
||||||
{
|
|
||||||
public class Component : IComponentModel
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string ComponentName { get; private set; } = string.Empty;
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public double Cost { get; set; }
|
|
||||||
|
|
||||||
[ForeignKey("ComponentId")]
|
|
||||||
public virtual List<DishComponent> DishComponents { get; set; } = new();
|
|
||||||
|
|
||||||
public static Component? Create(ComponentBindingModel model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new Component()
|
|
||||||
{
|
|
||||||
Id = model.Id,
|
|
||||||
ComponentName = model.ComponentName,
|
|
||||||
Cost = model.Cost
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Component Create(ComponentViewModel model)
|
|
||||||
{
|
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,100 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using FoodOrdersDataModels.Models;
|
|
||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
|
|
||||||
namespace FoodOrdersDatabaseImplement.Models
|
|
||||||
{
|
|
||||||
public class Dish : IDishModel
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
[Required]
|
|
||||||
public string DishName { get; private set; } = string.Empty;
|
|
||||||
[Required]
|
|
||||||
public double Price { get; private set; }
|
|
||||||
|
|
||||||
private Dictionary<int, (IComponentModel, int)>? _dishComponents = null;
|
|
||||||
|
|
||||||
[NotMapped]
|
|
||||||
public Dictionary<int, (IComponentModel, int)> DishComponents
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_dishComponents == null)
|
|
||||||
{
|
|
||||||
_dishComponents = Components.ToDictionary(recPC => recPC.ComponentId, recPC => (recPC.Component as IComponentModel, recPC.Count));
|
|
||||||
}
|
|
||||||
return _dishComponents;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[ForeignKey("DishId")]
|
|
||||||
public virtual List<DishComponent> Components { get; set; } = new();
|
|
||||||
[ForeignKey("DishId")]
|
|
||||||
public virtual List<Order> Orders { get; set; } = new();
|
|
||||||
|
|
||||||
public static Dish? Create(FoodOrdersDatabase context, DishBindingModel model)
|
|
||||||
{
|
|
||||||
var components = context.Components;
|
|
||||||
return new Dish()
|
|
||||||
{
|
|
||||||
Id = model.Id,
|
|
||||||
DishName = model.DishName,
|
|
||||||
Price = model.Price,
|
|
||||||
Components = model.DishComponents.Select(x => new DishComponent
|
|
||||||
{
|
|
||||||
Component = context.Components.First(y => y.Id == x.Key),
|
|
||||||
Count = x.Value.Item2
|
|
||||||
}).ToList()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(DishBindingModel model)
|
|
||||||
{
|
|
||||||
DishName = model.DishName;
|
|
||||||
Price = model.Price;
|
|
||||||
}
|
|
||||||
public DishViewModel GetViewModel => new()
|
|
||||||
{
|
|
||||||
Id = Id,
|
|
||||||
DishName = DishName,
|
|
||||||
Price = Price,
|
|
||||||
DishComponents = DishComponents
|
|
||||||
};
|
|
||||||
|
|
||||||
public void UpdateComponents(FoodOrdersDatabase context, DishBindingModel model)
|
|
||||||
{
|
|
||||||
var dishComponents = context.DishComponents.Where(rec => rec.DishId == model.Id).ToList();
|
|
||||||
if (dishComponents != null && DishComponents.Count > 0)
|
|
||||||
{ // удалили те, которых нет в модели
|
|
||||||
context.DishComponents.RemoveRange(dishComponents.Where(rec => !model.DishComponents.ContainsKey(rec.ComponentId)));
|
|
||||||
context.SaveChanges();
|
|
||||||
// обновили количество у существующих записей
|
|
||||||
foreach (var updateComponent in dishComponents)
|
|
||||||
{
|
|
||||||
updateComponent.Count = model.DishComponents[updateComponent.ComponentId].Item2;
|
|
||||||
model.DishComponents.Remove(updateComponent.ComponentId);
|
|
||||||
}
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
var dish = context.Dishs.First(x => x.Id == Id);
|
|
||||||
foreach (var pc in model.DishComponents)
|
|
||||||
{
|
|
||||||
context.DishComponents.Add(new DishComponent
|
|
||||||
{
|
|
||||||
Dish = dish,
|
|
||||||
Component = context.Components.First(x => x.Id == pc.Key),
|
|
||||||
Count = pc.Value.Item2
|
|
||||||
});
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
_dishComponents = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace FoodOrdersDatabaseImplement.Models
|
|
||||||
{
|
|
||||||
public class DishComponent
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int DishId { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int ComponentId { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int Count { get; set; }
|
|
||||||
public virtual Component Component { get; set; } = new();
|
|
||||||
public virtual Dish Dish { get; set; } = new();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersDataModels.Enums;
|
|
||||||
using FoodOrdersDataModels.Models;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.ConstrainedExecution;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace FoodOrdersDatabaseImplement.Models
|
|
||||||
{
|
|
||||||
public class Order : IOrderModel
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
[Required]
|
|
||||||
public int DishId { get; private set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int Count { get; private set; }
|
|
||||||
[Required]
|
|
||||||
public double Sum { get; private set; }
|
|
||||||
[Required]
|
|
||||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
|
||||||
[Required]
|
|
||||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
|
||||||
|
|
||||||
public DateTime? DateImplement { get; private set; }
|
|
||||||
public virtual Dish Dish { get; private set; }
|
|
||||||
|
|
||||||
public static Order? Create(OrderBindingModel? model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new Order
|
|
||||||
{
|
|
||||||
DishId = model.DishId,
|
|
||||||
Count = model.Count,
|
|
||||||
Sum = model.Sum,
|
|
||||||
Status = model.Status,
|
|
||||||
DateCreate = model.DateCreate,
|
|
||||||
DateImplement = model.DateImplement,
|
|
||||||
Id = model.Id,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(OrderBindingModel? model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Status = model.Status;
|
|
||||||
DateImplement = model.DateImplement;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel GetViewModel => new()
|
|
||||||
{
|
|
||||||
DishId = DishId,
|
|
||||||
Count = Count,
|
|
||||||
Sum = Sum,
|
|
||||||
DateCreate = DateCreate,
|
|
||||||
DateImplement = DateImplement,
|
|
||||||
Id = Id,
|
|
||||||
Status = Status,
|
|
||||||
DishName = Dish.DishName
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
using FoodOrdersFileImplement.Models;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
|
|
||||||
namespace FoodOrdersFileImplement
|
|
||||||
{
|
|
||||||
internal class DataFileSingleton
|
|
||||||
{
|
|
||||||
private static DataFileSingleton? instance;
|
|
||||||
|
|
||||||
private readonly string ComponentFileName = "Component.xml";
|
|
||||||
|
|
||||||
private readonly string OrderFileName = "Order.xml";
|
|
||||||
|
|
||||||
private readonly string DishFileName = "Dish.xml";
|
|
||||||
|
|
||||||
public List<Component> Components { get; private set; }
|
|
||||||
|
|
||||||
public List<Order> Orders { get; private set; }
|
|
||||||
|
|
||||||
public List<Dish> Dishs { get; private set; }
|
|
||||||
|
|
||||||
public static DataFileSingleton GetInstance()
|
|
||||||
{
|
|
||||||
if (instance == null)
|
|
||||||
{
|
|
||||||
instance = new DataFileSingleton();
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
|
||||||
|
|
||||||
public void SaveDishs() => SaveData(Dishs, DishFileName, "Dishs", x => x.GetXElement);
|
|
||||||
|
|
||||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
|
||||||
|
|
||||||
private DataFileSingleton()
|
|
||||||
{
|
|
||||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
|
||||||
Dishs = LoadData(DishFileName, "Dish", x => Dish.Create(x)!)!;
|
|
||||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
|
||||||
{
|
|
||||||
if (File.Exists(filename))
|
|
||||||
{
|
|
||||||
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
|
||||||
}
|
|
||||||
return new List<T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
|
||||||
{
|
|
||||||
if (data != null)
|
|
||||||
{
|
|
||||||
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\FoodOrdersContracts\FoodOrdersContracts.csproj" />
|
|
||||||
<ProjectReference Include="..\FoodOrdersDataModels\FoodOrdersDataModels.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,86 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.StoragesContracts;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersFileImplement.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersFileImplement.Implements
|
|
||||||
{
|
|
||||||
public class ComponentStorage : IComponentStorage
|
|
||||||
{
|
|
||||||
private readonly DataFileSingleton source;
|
|
||||||
|
|
||||||
public ComponentStorage()
|
|
||||||
{
|
|
||||||
source = DataFileSingleton.GetInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ComponentViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
return source.Components
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.ComponentName))
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
return source.Components
|
|
||||||
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return source.Components
|
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) ||
|
|
||||||
(model.Id.HasValue && x.Id == model.Id))
|
|
||||||
?.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
|
||||||
{
|
|
||||||
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
|
|
||||||
var newComponent = Component.Create(model);
|
|
||||||
if (newComponent == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
source.Components.Add(newComponent);
|
|
||||||
source.SaveComponents();
|
|
||||||
return newComponent.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
|
||||||
{
|
|
||||||
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (component == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
component.Update(model);
|
|
||||||
source.SaveComponents();
|
|
||||||
return component.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
|
||||||
{
|
|
||||||
var element = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (element != null)
|
|
||||||
{
|
|
||||||
source.Components.Remove(element);
|
|
||||||
source.SaveComponents();
|
|
||||||
return element.GetViewModel;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.StoragesContracts;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersFileImplement.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersFileImplement.Implements
|
|
||||||
{
|
|
||||||
public class DishStorage : IDishStorage
|
|
||||||
{
|
|
||||||
private readonly DataFileSingleton source;
|
|
||||||
|
|
||||||
public DishStorage()
|
|
||||||
{
|
|
||||||
source = DataFileSingleton.GetInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DishViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
return source.Dishs
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DishViewModel> GetFilteredList(DishSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.DishName))
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
return source.Dishs
|
|
||||||
.Where(x => x.DishName.Contains(model.DishName))
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel? GetElement(DishSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.DishName) && !model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return source.Dishs
|
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DishName) && x.DishName == model.DishName) ||
|
|
||||||
(model.Id.HasValue && x.Id == model.Id))
|
|
||||||
?.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel? Insert(DishBindingModel model)
|
|
||||||
{
|
|
||||||
model.Id = source.Dishs.Count > 0 ? source.Dishs.Max(x => x.Id) + 1 : 1;
|
|
||||||
var newDish = Dish.Create(model);
|
|
||||||
if (newDish == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
source.Dishs.Add(newDish);
|
|
||||||
source.SaveDishs();
|
|
||||||
return newDish.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel? Update(DishBindingModel model)
|
|
||||||
{
|
|
||||||
var Dish = source.Dishs.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (Dish == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Dish.Update(model);
|
|
||||||
source.SaveDishs();
|
|
||||||
return Dish.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel? Delete(DishBindingModel model)
|
|
||||||
{
|
|
||||||
var element = source.Dishs.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (element != null)
|
|
||||||
{
|
|
||||||
source.Dishs.Remove(element);
|
|
||||||
source.SaveDishs();
|
|
||||||
return element.GetViewModel;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,98 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.StoragesContracts;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersFileImplement.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersFileImplement.Implements
|
|
||||||
{
|
|
||||||
public class OrderStorage : IOrderStorage
|
|
||||||
{
|
|
||||||
private readonly DataFileSingleton source;
|
|
||||||
|
|
||||||
public OrderStorage()
|
|
||||||
{
|
|
||||||
source = DataFileSingleton.GetInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OrderViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
return source.Orders
|
|
||||||
.Select(x => AddDishName(x.GetViewModel))
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
if (!model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
return source.Orders
|
|
||||||
.Where(x => x.Id == model.Id)
|
|
||||||
.Select(x => AddDishName(x.GetViewModel))
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
if (!model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (order == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return AddDishName(order.GetViewModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
|
||||||
var newOrder = Order.Create(model);
|
|
||||||
if (newOrder == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
source.Orders.Add(newOrder);
|
|
||||||
source.SaveOrders();
|
|
||||||
return AddDishName(newOrder.GetViewModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (order == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
order.Update(model);
|
|
||||||
source.SaveOrders();
|
|
||||||
return AddDishName(order.GetViewModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (element != null)
|
|
||||||
{
|
|
||||||
source.Orders.Remove(element);
|
|
||||||
source.SaveOrders();
|
|
||||||
return AddDishName(element.GetViewModel);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private OrderViewModel AddDishName(OrderViewModel model)
|
|
||||||
{
|
|
||||||
var selectedDish = source.Dishs.FirstOrDefault(x => x.Id == model.DishId);
|
|
||||||
if (selectedDish != null)
|
|
||||||
{
|
|
||||||
model.DishName = selectedDish.DishName;
|
|
||||||
}
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersDataModels.Models;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
|
|
||||||
namespace FoodOrdersFileImplement.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 static Component? Create(XElement element)
|
|
||||||
{
|
|
||||||
if (element == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new Component()
|
|
||||||
{
|
|
||||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
|
||||||
ComponentName = element.Element("ComponentName")!.Value,
|
|
||||||
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
public XElement GetXElement => new("Component",
|
|
||||||
new XAttribute("Id", Id),
|
|
||||||
new XElement("ComponentName", ComponentName),
|
|
||||||
new XElement("Cost", Cost.ToString()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,94 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersDataModels.Models;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
|
|
||||||
namespace FoodOrdersFileImplement.Models
|
|
||||||
{
|
|
||||||
public class Dish : IDishModel
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
|
|
||||||
public string DishName { get; private set; } = string.Empty;
|
|
||||||
|
|
||||||
public double Price { get; private set; }
|
|
||||||
|
|
||||||
public Dictionary<int, int> Components { get; private set; } = new();
|
|
||||||
|
|
||||||
private Dictionary<int, (IComponentModel, int)>? _DishComponents = null;
|
|
||||||
|
|
||||||
public Dictionary<int, (IComponentModel, int)> DishComponents
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_DishComponents == null)
|
|
||||||
{
|
|
||||||
var source = DataFileSingleton.GetInstance();
|
|
||||||
_DishComponents = Components.ToDictionary(x => x.Key,
|
|
||||||
y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
|
|
||||||
}
|
|
||||||
return _DishComponents;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Dish? Create(DishBindingModel? model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new Dish()
|
|
||||||
{
|
|
||||||
Id = model.Id,
|
|
||||||
DishName = model.DishName,
|
|
||||||
Price = model.Price,
|
|
||||||
Components = model.DishComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Dish? Create(XElement element)
|
|
||||||
{
|
|
||||||
if (element == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new Dish()
|
|
||||||
{
|
|
||||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
|
||||||
DishName = element.Element("DishName")!.Value,
|
|
||||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
|
||||||
Components = element.Element("DishComponents")!.Elements("DishComponent")
|
|
||||||
.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(DishBindingModel? model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DishName = model.DishName;
|
|
||||||
Price = model.Price;
|
|
||||||
Components = model.DishComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
|
||||||
_DishComponents = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel GetViewModel => new()
|
|
||||||
{
|
|
||||||
Id = Id,
|
|
||||||
DishName = DishName,
|
|
||||||
Price = Price,
|
|
||||||
DishComponents = DishComponents
|
|
||||||
};
|
|
||||||
|
|
||||||
public XElement GetXElement => new("Dish",
|
|
||||||
new XAttribute("Id", Id),
|
|
||||||
new XElement("DishName", DishName),
|
|
||||||
new XElement("Price", Price.ToString()),
|
|
||||||
new XElement("DishComponents",
|
|
||||||
Components.Select(x => new XElement("DishComponent",
|
|
||||||
new XElement("Key", x.Key),
|
|
||||||
new XElement("Value", x.Value))).ToArray()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,93 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersDataModels.Enums;
|
|
||||||
using FoodOrdersDataModels.Models;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
|
|
||||||
namespace FoodOrdersFileImplement.Models
|
|
||||||
{
|
|
||||||
public class Order : IOrderModel
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
|
|
||||||
public int DishId { 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,
|
|
||||||
DishId = model.DishId,
|
|
||||||
Count = model.Count,
|
|
||||||
Sum = model.Sum,
|
|
||||||
Status = model.Status,
|
|
||||||
DateCreate = model.DateCreate,
|
|
||||||
DateImplement = model.DateImplement
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Order? Create(XElement element)
|
|
||||||
{
|
|
||||||
if (element == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new Order()
|
|
||||||
{
|
|
||||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
|
||||||
DishId = Convert.ToInt32(element.Element("DishId")!.Value),
|
|
||||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
|
||||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
|
||||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
|
||||||
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
|
||||||
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null
|
|
||||||
: Convert.ToDateTime(element.Element("DateImplement")!.Value)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(OrderBindingModel? model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Status = model.Status;
|
|
||||||
DateImplement = model.DateImplement;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel GetViewModel => new()
|
|
||||||
{
|
|
||||||
Id = Id,
|
|
||||||
DishId = DishId,
|
|
||||||
Count = Count,
|
|
||||||
Sum = Sum,
|
|
||||||
Status = Status,
|
|
||||||
DateCreate = DateCreate,
|
|
||||||
DateImplement = DateImplement
|
|
||||||
};
|
|
||||||
|
|
||||||
public XElement GetXElement => new("Order",
|
|
||||||
new XAttribute("Id", Id),
|
|
||||||
new XElement("DishId", DishId),
|
|
||||||
new XElement("Count", Count.ToString()),
|
|
||||||
new XElement("Sum", Sum.ToString()),
|
|
||||||
new XElement("Status", Status.ToString()),
|
|
||||||
new XElement("DateCreate", DateCreate.ToString()),
|
|
||||||
new XElement("DateImplement", DateImplement.ToString()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
using FoodOrdersListImplement.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersListImplement
|
|
||||||
{
|
|
||||||
public class DataListSingleton
|
|
||||||
{
|
|
||||||
private static DataListSingleton? _instance;
|
|
||||||
|
|
||||||
public List<Component> Components { get; set; }
|
|
||||||
|
|
||||||
public List<Order> Orders { get; set; }
|
|
||||||
|
|
||||||
public List<Dish> Dishes { get; set; }
|
|
||||||
|
|
||||||
private DataListSingleton()
|
|
||||||
{
|
|
||||||
Components = new List<Component>();
|
|
||||||
Orders = new List<Order>();
|
|
||||||
Dishes = new List<Dish>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DataListSingleton GetInstance()
|
|
||||||
{
|
|
||||||
if (_instance == null)
|
|
||||||
{
|
|
||||||
_instance = new DataListSingleton();
|
|
||||||
}
|
|
||||||
return _instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\FoodOrdersContracts\FoodOrdersContracts.csproj" />
|
|
||||||
<ProjectReference Include="..\FoodOrdersDataModels\FoodOrdersDataModels.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,109 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.StoragesContracts;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersListImplement.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersListImplement.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,109 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.StoragesContracts;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersListImplement.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersListImplement.Implements
|
|
||||||
{
|
|
||||||
public class DishStorage : IDishStorage
|
|
||||||
{
|
|
||||||
private readonly DataListSingleton _source;
|
|
||||||
|
|
||||||
public DishStorage()
|
|
||||||
{
|
|
||||||
_source = DataListSingleton.GetInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DishViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
var result = new List<DishViewModel>();
|
|
||||||
foreach (var Dish in _source.Dishes)
|
|
||||||
{
|
|
||||||
result.Add(Dish.GetViewModel);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DishViewModel> GetFilteredList(DishSearchModel model)
|
|
||||||
{
|
|
||||||
var result = new List<DishViewModel>();
|
|
||||||
if (string.IsNullOrEmpty(model.DishName))
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
foreach (var Dish in _source.Dishes)
|
|
||||||
{
|
|
||||||
if (Dish.DishName.Contains(model.DishName))
|
|
||||||
{
|
|
||||||
result.Add(Dish.GetViewModel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel? GetElement(DishSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.DishName) && !model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
foreach (var Dish in _source.Dishes)
|
|
||||||
{
|
|
||||||
if ((!string.IsNullOrEmpty(model.DishName) &&
|
|
||||||
Dish.DishName == model.DishName) ||
|
|
||||||
(model.Id.HasValue && Dish.Id == model.Id))
|
|
||||||
{
|
|
||||||
return Dish.GetViewModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel? Insert(DishBindingModel model)
|
|
||||||
{
|
|
||||||
model.Id = 1;
|
|
||||||
foreach (var Dish in _source.Dishes)
|
|
||||||
{
|
|
||||||
if (model.Id <= Dish.Id)
|
|
||||||
{
|
|
||||||
model.Id = Dish.Id + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var newDish = Dish.Create(model);
|
|
||||||
if (newDish == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
_source.Dishes.Add(newDish);
|
|
||||||
return newDish.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel? Update(DishBindingModel model)
|
|
||||||
{
|
|
||||||
foreach (var Dish in _source.Dishes)
|
|
||||||
{
|
|
||||||
if (Dish.Id == model.Id)
|
|
||||||
{
|
|
||||||
Dish.Update(model);
|
|
||||||
return Dish.GetViewModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel? Delete(DishBindingModel model)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _source.Dishes.Count; ++i)
|
|
||||||
{
|
|
||||||
if (_source.Dishes[i].Id == model.Id)
|
|
||||||
{
|
|
||||||
var element = _source.Dishes[i];
|
|
||||||
_source.Dishes.RemoveAt(i);
|
|
||||||
return element.GetViewModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,117 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.StoragesContracts;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersListImplement.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersListImplement.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(AddDishName(order.GetViewModel));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
var result = new List<OrderViewModel>();
|
|
||||||
if (!model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
foreach (var order in _source.Orders)
|
|
||||||
{
|
|
||||||
if (order.Id == model.Id)
|
|
||||||
{
|
|
||||||
result.Add(AddDishName(order.GetViewModel));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
if (!model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
foreach (var order in _source.Orders)
|
|
||||||
{
|
|
||||||
if (order.Id == model.Id)
|
|
||||||
{
|
|
||||||
return AddDishName(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 AddDishName(newOrder.GetViewModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
foreach (var order in _source.Orders)
|
|
||||||
{
|
|
||||||
if (order.Id == model.Id)
|
|
||||||
{
|
|
||||||
order.Update(model);
|
|
||||||
return AddDishName(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 AddDishName(element.GetViewModel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private OrderViewModel AddDishName(OrderViewModel model)
|
|
||||||
{
|
|
||||||
var selectedDish = _source.Dishes.Find(Dish => Dish.Id == model.DishId);
|
|
||||||
if (selectedDish != null)
|
|
||||||
{
|
|
||||||
model.DishName = selectedDish.DishName;
|
|
||||||
}
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersDataModels.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersListImplement.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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersDataModels.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersListImplement.Models
|
|
||||||
{
|
|
||||||
public class Dish : IDishModel
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
|
|
||||||
public string DishName { get; private set; } = string.Empty;
|
|
||||||
|
|
||||||
public double Price { get; private set; }
|
|
||||||
|
|
||||||
public Dictionary<int, (IComponentModel, int)> DishComponents
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
private set;
|
|
||||||
} = new Dictionary<int, (IComponentModel, int)>();
|
|
||||||
|
|
||||||
public static Dish? Create(DishBindingModel? model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new Dish()
|
|
||||||
{
|
|
||||||
Id = model.Id,
|
|
||||||
DishName = model.DishName,
|
|
||||||
Price = model.Price,
|
|
||||||
DishComponents = model.DishComponents
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(DishBindingModel? model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DishName = model.DishName;
|
|
||||||
Price = model.Price;
|
|
||||||
DishComponents = model.DishComponents;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DishViewModel GetViewModel => new()
|
|
||||||
{
|
|
||||||
Id = Id,
|
|
||||||
DishName = DishName,
|
|
||||||
Price = Price,
|
|
||||||
DishComponents = DishComponents
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersDataModels.Models;
|
|
||||||
using FoodOrdersDataModels.Enums;
|
|
||||||
|
|
||||||
namespace FoodOrdersListImplement.Models
|
|
||||||
{
|
|
||||||
public class Order : IOrderModel
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
|
|
||||||
public int DishId { 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,
|
|
||||||
DishId = model.DishId,
|
|
||||||
Count = model.Count,
|
|
||||||
Sum = model.Sum,
|
|
||||||
Status = model.Status,
|
|
||||||
DateCreate = model.DateCreate,
|
|
||||||
DateImplement = model.DateImplement
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(OrderBindingModel? model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Status = model.Status;
|
|
||||||
DateImplement = model.DateImplement;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel GetViewModel => new()
|
|
||||||
{
|
|
||||||
Id = Id,
|
|
||||||
DishId = DishId,
|
|
||||||
Count = Count,
|
|
||||||
Sum = Sum,
|
|
||||||
Status = Status,
|
|
||||||
DateCreate = DateCreate,
|
|
||||||
DateImplement = DateImplement
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,22 +8,4 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.16">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\FoodOrdersBusinessLogic\FoodOrdersBusinessLogic.csproj" />
|
|
||||||
<ProjectReference Include="..\FoodOrdersContracts\FoodOrdersContracts.csproj" />
|
|
||||||
<ProjectReference Include="..\FoodOrdersDatabaseImplement\FoodOrdersDatabaseImplement.csproj" />
|
|
||||||
<ProjectReference Include="..\FoodOrdersFileImplement\FoodOrdersFileImplement.csproj" />
|
|
||||||
<ProjectReference Include="..\FoodOrdersListImplement\FoodOrdersListImplement.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
39
FoodOrders/FoodOrdersView/Form1.Designer.cs
generated
Normal file
39
FoodOrders/FoodOrdersView/Form1.Designer.cs
generated
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
namespace FoodOrdersView
|
||||||
|
{
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
10
FoodOrders/FoodOrdersView/Form1.cs
Normal file
10
FoodOrders/FoodOrdersView/Form1.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace FoodOrdersView
|
||||||
|
{
|
||||||
|
public partial class Form1 : Form
|
||||||
|
{
|
||||||
|
public Form1()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
122
FoodOrders/FoodOrdersView/FormComponent.Designer.cs
generated
122
FoodOrders/FoodOrdersView/FormComponent.Designer.cs
generated
@ -1,122 +0,0 @@
|
|||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
labelName = new Label();
|
|
||||||
labelCost = new Label();
|
|
||||||
textBoxName = new TextBox();
|
|
||||||
textBoxCost = new TextBox();
|
|
||||||
buttonSave = new Button();
|
|
||||||
buttonCancel = new Button();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// labelName
|
|
||||||
//
|
|
||||||
labelName.AutoSize = true;
|
|
||||||
labelName.Location = new Point(14, 10);
|
|
||||||
labelName.Name = "labelName";
|
|
||||||
labelName.Size = new Size(65, 15);
|
|
||||||
labelName.TabIndex = 0;
|
|
||||||
labelName.Text = "Название :";
|
|
||||||
//
|
|
||||||
// labelCost
|
|
||||||
//
|
|
||||||
labelCost.AutoSize = true;
|
|
||||||
labelCost.Location = new Point(14, 39);
|
|
||||||
labelCost.Name = "labelCost";
|
|
||||||
labelCost.Size = new Size(41, 15);
|
|
||||||
labelCost.TabIndex = 1;
|
|
||||||
labelCost.Text = "Цена :";
|
|
||||||
//
|
|
||||||
// textBoxName
|
|
||||||
//
|
|
||||||
textBoxName.Location = new Point(91, 7);
|
|
||||||
textBoxName.Margin = new Padding(4, 3, 4, 3);
|
|
||||||
textBoxName.Name = "textBoxName";
|
|
||||||
textBoxName.Size = new Size(252, 23);
|
|
||||||
textBoxName.TabIndex = 2;
|
|
||||||
//
|
|
||||||
// textBoxCost
|
|
||||||
//
|
|
||||||
textBoxCost.Location = new Point(91, 36);
|
|
||||||
textBoxCost.Margin = new Padding(4, 3, 4, 3);
|
|
||||||
textBoxCost.Name = "textBoxCost";
|
|
||||||
textBoxCost.Size = new Size(129, 23);
|
|
||||||
textBoxCost.TabIndex = 4;
|
|
||||||
//
|
|
||||||
// buttonSave
|
|
||||||
//
|
|
||||||
buttonSave.Location = new Point(162, 71);
|
|
||||||
buttonSave.Margin = new Padding(4, 3, 4, 3);
|
|
||||||
buttonSave.Name = "buttonSave";
|
|
||||||
buttonSave.Size = new Size(88, 27);
|
|
||||||
buttonSave.TabIndex = 5;
|
|
||||||
buttonSave.Text = "Сохранить";
|
|
||||||
buttonSave.UseVisualStyleBackColor = true;
|
|
||||||
buttonSave.Click += ButtonSave_Click;
|
|
||||||
//
|
|
||||||
// buttonCancel
|
|
||||||
//
|
|
||||||
buttonCancel.Location = new Point(260, 71);
|
|
||||||
buttonCancel.Margin = new Padding(4, 3, 4, 3);
|
|
||||||
buttonCancel.Name = "buttonCancel";
|
|
||||||
buttonCancel.Size = new Size(88, 27);
|
|
||||||
buttonCancel.TabIndex = 6;
|
|
||||||
buttonCancel.Text = "Отмена";
|
|
||||||
buttonCancel.UseVisualStyleBackColor = true;
|
|
||||||
buttonCancel.Click += ButtonCancel_Click;
|
|
||||||
//
|
|
||||||
// FormComponent
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(364, 110);
|
|
||||||
Controls.Add(buttonCancel);
|
|
||||||
Controls.Add(buttonSave);
|
|
||||||
Controls.Add(textBoxCost);
|
|
||||||
Controls.Add(textBoxName);
|
|
||||||
Controls.Add(labelCost);
|
|
||||||
Controls.Add(labelName);
|
|
||||||
Name = "FormComponent";
|
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
|
||||||
Text = "Компонент";
|
|
||||||
ResumeLayout(false);
|
|
||||||
PerformLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private Label labelName;
|
|
||||||
private Label labelCost;
|
|
||||||
private TextBox textBoxName;
|
|
||||||
private TextBox textBoxCost;
|
|
||||||
private Button buttonSave;
|
|
||||||
private Button buttonCancel;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,85 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.BusinessLogicsContracts;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
textBoxCost.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(textBoxCost.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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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,103 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.BusinessLogicsContracts;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
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 ButtonEdit_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 ButtonUpd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
127
FoodOrders/FoodOrdersView/FormComponents.designer.cs
generated
127
FoodOrders/FoodOrdersView/FormComponents.designer.cs
generated
@ -1,127 +0,0 @@
|
|||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
buttonUpd = new Button();
|
|
||||||
buttonDel = new Button();
|
|
||||||
buttonEdit = new Button();
|
|
||||||
buttonAdd = new Button();
|
|
||||||
dataGridView = new DataGridView();
|
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// buttonUpd
|
|
||||||
//
|
|
||||||
buttonUpd.Location = new Point(432, 152);
|
|
||||||
buttonUpd.Margin = new Padding(4, 3, 4, 3);
|
|
||||||
buttonUpd.Name = "buttonUpd";
|
|
||||||
buttonUpd.Size = new Size(88, 27);
|
|
||||||
buttonUpd.TabIndex = 4;
|
|
||||||
buttonUpd.Text = "Обновить";
|
|
||||||
buttonUpd.UseVisualStyleBackColor = true;
|
|
||||||
buttonUpd.Click += ButtonUpd_Click;
|
|
||||||
//
|
|
||||||
// buttonDel
|
|
||||||
//
|
|
||||||
buttonDel.Location = new Point(432, 105);
|
|
||||||
buttonDel.Margin = new Padding(4, 3, 4, 3);
|
|
||||||
buttonDel.Name = "buttonDel";
|
|
||||||
buttonDel.Size = new Size(88, 27);
|
|
||||||
buttonDel.TabIndex = 3;
|
|
||||||
buttonDel.Text = "Удалить";
|
|
||||||
buttonDel.UseVisualStyleBackColor = true;
|
|
||||||
buttonDel.Click += ButtonDel_Click;
|
|
||||||
//
|
|
||||||
// buttonEdit
|
|
||||||
//
|
|
||||||
buttonEdit.Location = new Point(432, 58);
|
|
||||||
buttonEdit.Margin = new Padding(4, 3, 4, 3);
|
|
||||||
buttonEdit.Name = "buttonEdit";
|
|
||||||
buttonEdit.Size = new Size(88, 27);
|
|
||||||
buttonEdit.TabIndex = 2;
|
|
||||||
buttonEdit.Text = "Изменить";
|
|
||||||
buttonEdit.UseVisualStyleBackColor = true;
|
|
||||||
buttonEdit.Click += ButtonEdit_Click;
|
|
||||||
//
|
|
||||||
// buttonAdd
|
|
||||||
//
|
|
||||||
buttonAdd.Location = new Point(432, 14);
|
|
||||||
buttonAdd.Margin = new Padding(4, 3, 4, 3);
|
|
||||||
buttonAdd.Name = "buttonAdd";
|
|
||||||
buttonAdd.Size = new Size(88, 27);
|
|
||||||
buttonAdd.TabIndex = 1;
|
|
||||||
buttonAdd.Text = "Добавить";
|
|
||||||
buttonAdd.UseVisualStyleBackColor = true;
|
|
||||||
buttonAdd.Click += ButtonAdd_Click;
|
|
||||||
//
|
|
||||||
// dataGridView
|
|
||||||
//
|
|
||||||
dataGridView.AllowUserToAddRows = false;
|
|
||||||
dataGridView.AllowUserToDeleteRows = false;
|
|
||||||
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
|
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
|
||||||
dataGridView.Dock = DockStyle.Left;
|
|
||||||
dataGridView.Location = new Point(0, 0);
|
|
||||||
dataGridView.Margin = new Padding(4, 3, 4, 3);
|
|
||||||
dataGridView.MultiSelect = false;
|
|
||||||
dataGridView.Name = "dataGridView";
|
|
||||||
dataGridView.ReadOnly = true;
|
|
||||||
dataGridView.RowHeadersVisible = false;
|
|
||||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
|
||||||
dataGridView.Size = new Size(408, 360);
|
|
||||||
dataGridView.TabIndex = 0;
|
|
||||||
//
|
|
||||||
// FormComponents
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(541, 360);
|
|
||||||
Controls.Add(buttonUpd);
|
|
||||||
Controls.Add(buttonDel);
|
|
||||||
Controls.Add(buttonEdit);
|
|
||||||
Controls.Add(buttonAdd);
|
|
||||||
Controls.Add(dataGridView);
|
|
||||||
Margin = new Padding(4, 3, 4, 3);
|
|
||||||
Name = "FormComponents";
|
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
|
||||||
Text = "Компоненты";
|
|
||||||
Load += FormComponents_Load;
|
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
|
||||||
ResumeLayout(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private Button buttonUpd;
|
|
||||||
private Button buttonDel;
|
|
||||||
private Button buttonEdit;
|
|
||||||
private Button buttonAdd;
|
|
||||||
private DataGridView dataGridView;
|
|
||||||
}
|
|
||||||
}
|
|
155
FoodOrders/FoodOrdersView/FormCreateOrder.Designer.cs
generated
155
FoodOrders/FoodOrdersView/FormCreateOrder.Designer.cs
generated
@ -1,155 +0,0 @@
|
|||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
labelFood = new Label();
|
|
||||||
comboBoxFood = new ComboBox();
|
|
||||||
labelCount = new Label();
|
|
||||||
textBoxCount = new TextBox();
|
|
||||||
labelSum = new Label();
|
|
||||||
textBoxSum = new TextBox();
|
|
||||||
buttonSave = new Button();
|
|
||||||
buttonCancel = new Button();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// labelFood
|
|
||||||
//
|
|
||||||
labelFood.AutoSize = true;
|
|
||||||
labelFood.Location = new Point(16, 14);
|
|
||||||
labelFood.Margin = new Padding(5, 0, 5, 0);
|
|
||||||
labelFood.Name = "labelFood";
|
|
||||||
labelFood.Size = new Size(62, 20);
|
|
||||||
labelFood.TabIndex = 1;
|
|
||||||
labelFood.Text = "Блюдо :";
|
|
||||||
//
|
|
||||||
// comboBoxFood
|
|
||||||
//
|
|
||||||
comboBoxFood.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
||||||
comboBoxFood.FormattingEnabled = true;
|
|
||||||
comboBoxFood.Location = new Point(117, 9);
|
|
||||||
comboBoxFood.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
comboBoxFood.Name = "comboBoxFood";
|
|
||||||
comboBoxFood.Size = new Size(287, 28);
|
|
||||||
comboBoxFood.TabIndex = 2;
|
|
||||||
comboBoxFood.SelectedIndexChanged += ComboBoxFood_SelectedIndexChanged;
|
|
||||||
//
|
|
||||||
// labelCount
|
|
||||||
//
|
|
||||||
labelCount.AutoSize = true;
|
|
||||||
labelCount.Location = new Point(16, 56);
|
|
||||||
labelCount.Margin = new Padding(5, 0, 5, 0);
|
|
||||||
labelCount.Name = "labelCount";
|
|
||||||
labelCount.Size = new Size(97, 20);
|
|
||||||
labelCount.TabIndex = 3;
|
|
||||||
labelCount.Text = "Количество :";
|
|
||||||
//
|
|
||||||
// textBoxCount
|
|
||||||
//
|
|
||||||
textBoxCount.Location = new Point(117, 51);
|
|
||||||
textBoxCount.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
textBoxCount.Name = "textBoxCount";
|
|
||||||
textBoxCount.Size = new Size(287, 27);
|
|
||||||
textBoxCount.TabIndex = 4;
|
|
||||||
textBoxCount.TextChanged += TextBoxCount_TextChanged;
|
|
||||||
//
|
|
||||||
// labelSum
|
|
||||||
//
|
|
||||||
labelSum.AutoSize = true;
|
|
||||||
labelSum.Location = new Point(16, 96);
|
|
||||||
labelSum.Margin = new Padding(5, 0, 5, 0);
|
|
||||||
labelSum.Name = "labelSum";
|
|
||||||
labelSum.Size = new Size(62, 20);
|
|
||||||
labelSum.TabIndex = 5;
|
|
||||||
labelSum.Text = "Сумма :";
|
|
||||||
//
|
|
||||||
// textBoxSum
|
|
||||||
//
|
|
||||||
textBoxSum.Location = new Point(117, 91);
|
|
||||||
textBoxSum.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
textBoxSum.Name = "textBoxSum";
|
|
||||||
textBoxSum.ReadOnly = true;
|
|
||||||
textBoxSum.Size = new Size(287, 27);
|
|
||||||
textBoxSum.TabIndex = 6;
|
|
||||||
//
|
|
||||||
// buttonSave
|
|
||||||
//
|
|
||||||
buttonSave.Location = new Point(184, 131);
|
|
||||||
buttonSave.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonSave.Name = "buttonSave";
|
|
||||||
buttonSave.Size = new Size(101, 36);
|
|
||||||
buttonSave.TabIndex = 7;
|
|
||||||
buttonSave.Text = "Сохранить";
|
|
||||||
buttonSave.UseVisualStyleBackColor = true;
|
|
||||||
buttonSave.Click += ButtonSave_Click;
|
|
||||||
//
|
|
||||||
// buttonCancel
|
|
||||||
//
|
|
||||||
buttonCancel.Location = new Point(291, 131);
|
|
||||||
buttonCancel.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonCancel.Name = "buttonCancel";
|
|
||||||
buttonCancel.Size = new Size(101, 36);
|
|
||||||
buttonCancel.TabIndex = 8;
|
|
||||||
buttonCancel.Text = "Отмена";
|
|
||||||
buttonCancel.UseVisualStyleBackColor = true;
|
|
||||||
buttonCancel.Click += ButtonCancel_Click;
|
|
||||||
//
|
|
||||||
// FormCreateOrder
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(424, 181);
|
|
||||||
Controls.Add(buttonCancel);
|
|
||||||
Controls.Add(buttonSave);
|
|
||||||
Controls.Add(textBoxSum);
|
|
||||||
Controls.Add(labelSum);
|
|
||||||
Controls.Add(textBoxCount);
|
|
||||||
Controls.Add(labelCount);
|
|
||||||
Controls.Add(comboBoxFood);
|
|
||||||
Controls.Add(labelFood);
|
|
||||||
Margin = new Padding(3, 4, 3, 4);
|
|
||||||
Name = "FormCreateOrder";
|
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
|
||||||
Text = "Заказ";
|
|
||||||
Load += FormCreateOrder_Load;
|
|
||||||
ResumeLayout(false);
|
|
||||||
PerformLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private Label labelFood;
|
|
||||||
private ComboBox comboBoxFood;
|
|
||||||
private Label labelCount;
|
|
||||||
private TextBox textBoxCount;
|
|
||||||
private Label labelSum;
|
|
||||||
private TextBox textBoxSum;
|
|
||||||
private Button buttonSave;
|
|
||||||
private Button buttonCancel;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,120 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.BusinessLogicsContracts;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.VisualBasic.Logging;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
public partial class FormCreateOrder : Form
|
|
||||||
{
|
|
||||||
private readonly ILogger _logger;
|
|
||||||
|
|
||||||
private readonly IDishLogic _logicIC;
|
|
||||||
|
|
||||||
private readonly IOrderLogic _logicO;
|
|
||||||
|
|
||||||
public FormCreateOrder(ILogger<FormCreateOrder> logger, IDishLogic logicIC, IOrderLogic logicO)
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
_logger = logger;
|
|
||||||
_logicIC = logicIC;
|
|
||||||
_logicO = logicO;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FormCreateOrder_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Загрузка блюда для заказа");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var FoodList = _logicIC.ReadList(null);
|
|
||||||
if (FoodList != null)
|
|
||||||
{
|
|
||||||
comboBoxFood.DisplayMember = "DishName";
|
|
||||||
comboBoxFood.ValueMember = "Id";
|
|
||||||
comboBoxFood.DataSource = FoodList;
|
|
||||||
comboBoxFood.SelectedItem = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Ошибка загрузки блюда для заказа");
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CalcSum()
|
|
||||||
{
|
|
||||||
if (comboBoxFood.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int id = Convert.ToInt32(comboBoxFood.SelectedValue);
|
|
||||||
var product = _logicIC.ReadElement(new DishSearchModel { 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 ComboBoxFood_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 (comboBoxFood.SelectedValue == null)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Выберите блюдо", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("Order creation");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
|
||||||
{
|
|
||||||
DishId = Convert.ToInt32(comboBoxFood.SelectedValue),
|
|
||||||
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, "Order creation error");
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
DialogResult = DialogResult.Cancel;
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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,209 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.BusinessLogicsContracts;
|
|
||||||
using FoodOrdersContracts.SearchModels;
|
|
||||||
using FoodOrdersDataModels.Models;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
public partial class FormDish : Form
|
|
||||||
{
|
|
||||||
private readonly ILogger _logger;
|
|
||||||
|
|
||||||
private readonly IDishLogic _logic;
|
|
||||||
|
|
||||||
private int? _id;
|
|
||||||
|
|
||||||
private Dictionary<int, (IComponentModel, int)> _FoodComponents;
|
|
||||||
|
|
||||||
public int Id { set { _id = value; } }
|
|
||||||
|
|
||||||
public FormDish(ILogger<FormDish> logger, IDishLogic logic)
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
_logger = logger;
|
|
||||||
_logic = logic;
|
|
||||||
_FoodComponents = new Dictionary<int, (IComponentModel, int)>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FormFood_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (_id.HasValue)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("Загрузка блюда");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var view = _logic.ReadElement(new DishSearchModel { Id = _id.Value });
|
|
||||||
if (view != null)
|
|
||||||
{
|
|
||||||
textBoxName.Text = view.DishName;
|
|
||||||
textBoxPrice.Text = view.Price.ToString();
|
|
||||||
_FoodComponents = view.DishComponents ?? 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 (_FoodComponents != null)
|
|
||||||
{
|
|
||||||
dataGridView.Rows.Clear();
|
|
||||||
foreach (var FoodC in _FoodComponents)
|
|
||||||
{
|
|
||||||
dataGridView.Rows.Add(new object[] { FoodC.Key, FoodC.Value.Item1.ComponentName, FoodC.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(FormDishComponent));
|
|
||||||
if (service is FormDishComponent form)
|
|
||||||
{
|
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
if (form.ComponentModel == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
|
|
||||||
if (_FoodComponents.ContainsKey(form.Id))
|
|
||||||
{
|
|
||||||
_FoodComponents[form.Id] = (form.ComponentModel, form.Count);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_FoodComponents.Add(form.Id, (form.ComponentModel, form.Count));
|
|
||||||
}
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonEdit_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
|
||||||
{
|
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormDishComponent));
|
|
||||||
if (service is FormDishComponent form)
|
|
||||||
{
|
|
||||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
|
||||||
form.Id = id;
|
|
||||||
form.Count = _FoodComponents[id].Item2;
|
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
if (form.ComponentModel == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
|
|
||||||
_FoodComponents[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,
|
|
||||||
dataGridView.SelectedRows[0].Cells[2].Value);
|
|
||||||
_FoodComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonUpd_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 (_FoodComponents == null || _FoodComponents.Count == 0)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("Сохранение блюда");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var model = new DishBindingModel
|
|
||||||
{
|
|
||||||
Id = _id ?? 0,
|
|
||||||
DishName = textBoxName.Text,
|
|
||||||
Price = Convert.ToDouble(textBoxPrice.Text),
|
|
||||||
DishComponents = _FoodComponents
|
|
||||||
};
|
|
||||||
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 _FoodComponents)
|
|
||||||
{
|
|
||||||
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
|
|
||||||
}
|
|
||||||
return Math.Round(price * 1.1, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
254
FoodOrders/FoodOrdersView/FormDish.designer.cs
generated
254
FoodOrders/FoodOrdersView/FormDish.designer.cs
generated
@ -1,254 +0,0 @@
|
|||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
partial class FormDish
|
|
||||||
{
|
|
||||||
/// <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()
|
|
||||||
{
|
|
||||||
buttonCancel = new Button();
|
|
||||||
buttonSave = new Button();
|
|
||||||
textBoxName = new TextBox();
|
|
||||||
labelName = new Label();
|
|
||||||
textBoxPrice = new TextBox();
|
|
||||||
labelPrice = new Label();
|
|
||||||
groupBoxComponents = new GroupBox();
|
|
||||||
buttonUpd = new Button();
|
|
||||||
buttonDel = new Button();
|
|
||||||
buttonEdit = new Button();
|
|
||||||
buttonAdd = new Button();
|
|
||||||
dataGridView = new DataGridView();
|
|
||||||
ColumnId = new DataGridViewTextBoxColumn();
|
|
||||||
ColumnName = new DataGridViewTextBoxColumn();
|
|
||||||
ColumnCount = new DataGridViewTextBoxColumn();
|
|
||||||
groupBoxComponents.SuspendLayout();
|
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// buttonCancel
|
|
||||||
//
|
|
||||||
buttonCancel.Location = new Point(520, 483);
|
|
||||||
buttonCancel.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonCancel.Name = "buttonCancel";
|
|
||||||
buttonCancel.Size = new Size(101, 36);
|
|
||||||
buttonCancel.TabIndex = 6;
|
|
||||||
buttonCancel.Text = "Отмена";
|
|
||||||
buttonCancel.UseVisualStyleBackColor = true;
|
|
||||||
buttonCancel.Click += ButtonCancel_Click;
|
|
||||||
//
|
|
||||||
// buttonSave
|
|
||||||
//
|
|
||||||
buttonSave.Location = new Point(411, 483);
|
|
||||||
buttonSave.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonSave.Name = "buttonSave";
|
|
||||||
buttonSave.Size = new Size(101, 36);
|
|
||||||
buttonSave.TabIndex = 5;
|
|
||||||
buttonSave.Text = "Сохранить";
|
|
||||||
buttonSave.UseVisualStyleBackColor = true;
|
|
||||||
buttonSave.Click += ButtonSave_Click;
|
|
||||||
//
|
|
||||||
// textBoxName
|
|
||||||
//
|
|
||||||
textBoxName.Location = new Point(105, 9);
|
|
||||||
textBoxName.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
textBoxName.Name = "textBoxName";
|
|
||||||
textBoxName.Size = new Size(287, 27);
|
|
||||||
textBoxName.TabIndex = 1;
|
|
||||||
//
|
|
||||||
// labelName
|
|
||||||
//
|
|
||||||
labelName.AutoSize = true;
|
|
||||||
labelName.Location = new Point(16, 13);
|
|
||||||
labelName.Margin = new Padding(5, 0, 5, 0);
|
|
||||||
labelName.Name = "labelName";
|
|
||||||
labelName.Size = new Size(84, 20);
|
|
||||||
labelName.TabIndex = 0;
|
|
||||||
labelName.Text = "Название :";
|
|
||||||
//
|
|
||||||
// textBoxPrice
|
|
||||||
//
|
|
||||||
textBoxPrice.Enabled = false;
|
|
||||||
textBoxPrice.Location = new Point(105, 49);
|
|
||||||
textBoxPrice.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
textBoxPrice.Name = "textBoxPrice";
|
|
||||||
textBoxPrice.Size = new Size(167, 27);
|
|
||||||
textBoxPrice.TabIndex = 3;
|
|
||||||
//
|
|
||||||
// labelPrice
|
|
||||||
//
|
|
||||||
labelPrice.AutoSize = true;
|
|
||||||
labelPrice.Location = new Point(16, 53);
|
|
||||||
labelPrice.Margin = new Padding(5, 0, 5, 0);
|
|
||||||
labelPrice.Name = "labelPrice";
|
|
||||||
labelPrice.Size = new Size(90, 20);
|
|
||||||
labelPrice.TabIndex = 2;
|
|
||||||
labelPrice.Text = "Стоимость :";
|
|
||||||
//
|
|
||||||
// groupBoxComponents
|
|
||||||
//
|
|
||||||
groupBoxComponents.Controls.Add(buttonUpd);
|
|
||||||
groupBoxComponents.Controls.Add(buttonDel);
|
|
||||||
groupBoxComponents.Controls.Add(buttonEdit);
|
|
||||||
groupBoxComponents.Controls.Add(buttonAdd);
|
|
||||||
groupBoxComponents.Controls.Add(dataGridView);
|
|
||||||
groupBoxComponents.Location = new Point(16, 89);
|
|
||||||
groupBoxComponents.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
groupBoxComponents.Name = "groupBoxComponents";
|
|
||||||
groupBoxComponents.Padding = new Padding(5, 4, 5, 4);
|
|
||||||
groupBoxComponents.Size = new Size(638, 384);
|
|
||||||
groupBoxComponents.TabIndex = 4;
|
|
||||||
groupBoxComponents.TabStop = false;
|
|
||||||
groupBoxComponents.Text = "Компоненты";
|
|
||||||
//
|
|
||||||
// buttonUpd
|
|
||||||
//
|
|
||||||
buttonUpd.Location = new Point(504, 228);
|
|
||||||
buttonUpd.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonUpd.Name = "buttonUpd";
|
|
||||||
buttonUpd.Size = new Size(101, 36);
|
|
||||||
buttonUpd.TabIndex = 4;
|
|
||||||
buttonUpd.Text = "Обновить";
|
|
||||||
buttonUpd.UseVisualStyleBackColor = true;
|
|
||||||
buttonUpd.Click += ButtonUpd_Click;
|
|
||||||
//
|
|
||||||
// buttonDel
|
|
||||||
//
|
|
||||||
buttonDel.Location = new Point(504, 164);
|
|
||||||
buttonDel.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonDel.Name = "buttonDel";
|
|
||||||
buttonDel.Size = new Size(101, 36);
|
|
||||||
buttonDel.TabIndex = 3;
|
|
||||||
buttonDel.Text = "Удалить";
|
|
||||||
buttonDel.UseVisualStyleBackColor = true;
|
|
||||||
buttonDel.Click += ButtonDel_Click;
|
|
||||||
//
|
|
||||||
// buttonEdit
|
|
||||||
//
|
|
||||||
buttonEdit.Location = new Point(504, 101);
|
|
||||||
buttonEdit.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonEdit.Name = "buttonEdit";
|
|
||||||
buttonEdit.Size = new Size(101, 36);
|
|
||||||
buttonEdit.TabIndex = 2;
|
|
||||||
buttonEdit.Text = "Изменить";
|
|
||||||
buttonEdit.UseVisualStyleBackColor = true;
|
|
||||||
buttonEdit.Click += ButtonEdit_Click;
|
|
||||||
//
|
|
||||||
// buttonAdd
|
|
||||||
//
|
|
||||||
buttonAdd.Location = new Point(504, 43);
|
|
||||||
buttonAdd.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonAdd.Name = "buttonAdd";
|
|
||||||
buttonAdd.Size = new Size(101, 36);
|
|
||||||
buttonAdd.TabIndex = 1;
|
|
||||||
buttonAdd.Text = "Добавить";
|
|
||||||
buttonAdd.UseVisualStyleBackColor = true;
|
|
||||||
buttonAdd.Click += ButtonAdd_Click;
|
|
||||||
//
|
|
||||||
// dataGridView
|
|
||||||
//
|
|
||||||
dataGridView.AllowUserToAddRows = false;
|
|
||||||
dataGridView.AllowUserToDeleteRows = false;
|
|
||||||
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
|
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
|
||||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount });
|
|
||||||
dataGridView.Dock = DockStyle.Left;
|
|
||||||
dataGridView.Location = new Point(5, 24);
|
|
||||||
dataGridView.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
dataGridView.MultiSelect = false;
|
|
||||||
dataGridView.Name = "dataGridView";
|
|
||||||
dataGridView.ReadOnly = true;
|
|
||||||
dataGridView.RowHeadersVisible = false;
|
|
||||||
dataGridView.RowHeadersWidth = 51;
|
|
||||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
|
||||||
dataGridView.Size = new Size(466, 356);
|
|
||||||
dataGridView.TabIndex = 0;
|
|
||||||
//
|
|
||||||
// ColumnId
|
|
||||||
//
|
|
||||||
ColumnId.HeaderText = "Id";
|
|
||||||
ColumnId.MinimumWidth = 6;
|
|
||||||
ColumnId.Name = "ColumnId";
|
|
||||||
ColumnId.ReadOnly = true;
|
|
||||||
ColumnId.Visible = false;
|
|
||||||
ColumnId.Width = 125;
|
|
||||||
//
|
|
||||||
// ColumnName
|
|
||||||
//
|
|
||||||
ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
||||||
ColumnName.HeaderText = "Компонент";
|
|
||||||
ColumnName.MinimumWidth = 6;
|
|
||||||
ColumnName.Name = "ColumnName";
|
|
||||||
ColumnName.ReadOnly = true;
|
|
||||||
//
|
|
||||||
// ColumnCount
|
|
||||||
//
|
|
||||||
ColumnCount.HeaderText = "Количество";
|
|
||||||
ColumnCount.MinimumWidth = 6;
|
|
||||||
ColumnCount.Name = "ColumnCount";
|
|
||||||
ColumnCount.ReadOnly = true;
|
|
||||||
ColumnCount.Width = 125;
|
|
||||||
//
|
|
||||||
// FormFood
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(670, 536);
|
|
||||||
Controls.Add(groupBoxComponents);
|
|
||||||
Controls.Add(textBoxPrice);
|
|
||||||
Controls.Add(labelPrice);
|
|
||||||
Controls.Add(buttonCancel);
|
|
||||||
Controls.Add(buttonSave);
|
|
||||||
Controls.Add(textBoxName);
|
|
||||||
Controls.Add(labelName);
|
|
||||||
Margin = new Padding(5, 4, 5, 4);
|
|
||||||
Name = "FormFood";
|
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
|
||||||
Text = "Блюдо";
|
|
||||||
Load += FormFood_Load;
|
|
||||||
groupBoxComponents.ResumeLayout(false);
|
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
|
||||||
ResumeLayout(false);
|
|
||||||
PerformLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private Button buttonCancel;
|
|
||||||
private Button buttonSave;
|
|
||||||
private TextBox textBoxName;
|
|
||||||
private Label labelName;
|
|
||||||
private TextBox textBoxPrice;
|
|
||||||
private Label labelPrice;
|
|
||||||
private GroupBox groupBoxComponents;
|
|
||||||
private Button buttonUpd;
|
|
||||||
private Button buttonDel;
|
|
||||||
private Button buttonEdit;
|
|
||||||
private Button buttonAdd;
|
|
||||||
private DataGridView dataGridView;
|
|
||||||
private DataGridViewTextBoxColumn ColumnId;
|
|
||||||
private DataGridViewTextBoxColumn ColumnName;
|
|
||||||
private DataGridViewTextBoxColumn ColumnCount;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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>
|
|
127
FoodOrders/FoodOrdersView/FormDishComponent.Designer.cs
generated
127
FoodOrders/FoodOrdersView/FormDishComponent.Designer.cs
generated
@ -1,127 +0,0 @@
|
|||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
partial class FormDishComponent
|
|
||||||
{
|
|
||||||
/// <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()
|
|
||||||
{
|
|
||||||
labelComponent = new Label();
|
|
||||||
labelCount = new Label();
|
|
||||||
comboBoxComponent = new ComboBox();
|
|
||||||
textBoxCount = new TextBox();
|
|
||||||
buttonSave = new Button();
|
|
||||||
buttonCancel = new Button();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// labelComponent
|
|
||||||
//
|
|
||||||
labelComponent.AutoSize = true;
|
|
||||||
labelComponent.Location = new Point(16, 17);
|
|
||||||
labelComponent.Margin = new Padding(5, 0, 5, 0);
|
|
||||||
labelComponent.Name = "labelComponent";
|
|
||||||
labelComponent.Size = new Size(95, 20);
|
|
||||||
labelComponent.TabIndex = 1;
|
|
||||||
labelComponent.Text = "Компонент :";
|
|
||||||
//
|
|
||||||
// labelCount
|
|
||||||
//
|
|
||||||
labelCount.AutoSize = true;
|
|
||||||
labelCount.Location = new Point(16, 64);
|
|
||||||
labelCount.Margin = new Padding(5, 0, 5, 0);
|
|
||||||
labelCount.Name = "labelCount";
|
|
||||||
labelCount.Size = new Size(97, 20);
|
|
||||||
labelCount.TabIndex = 3;
|
|
||||||
labelCount.Text = "Количество :";
|
|
||||||
//
|
|
||||||
// comboBoxComponent
|
|
||||||
//
|
|
||||||
comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
||||||
comboBoxComponent.FormattingEnabled = true;
|
|
||||||
comboBoxComponent.Location = new Point(117, 13);
|
|
||||||
comboBoxComponent.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
comboBoxComponent.Name = "comboBoxComponent";
|
|
||||||
comboBoxComponent.Size = new Size(287, 28);
|
|
||||||
comboBoxComponent.TabIndex = 4;
|
|
||||||
//
|
|
||||||
// textBoxCount
|
|
||||||
//
|
|
||||||
textBoxCount.Location = new Point(117, 59);
|
|
||||||
textBoxCount.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
textBoxCount.Name = "textBoxCount";
|
|
||||||
textBoxCount.Size = new Size(287, 27);
|
|
||||||
textBoxCount.TabIndex = 5;
|
|
||||||
//
|
|
||||||
// buttonSave
|
|
||||||
//
|
|
||||||
buttonSave.Location = new Point(183, 100);
|
|
||||||
buttonSave.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonSave.Name = "buttonSave";
|
|
||||||
buttonSave.Size = new Size(101, 36);
|
|
||||||
buttonSave.TabIndex = 6;
|
|
||||||
buttonSave.Text = "Сохранить";
|
|
||||||
buttonSave.UseVisualStyleBackColor = true;
|
|
||||||
buttonSave.Click += ButtonSave_Click;
|
|
||||||
//
|
|
||||||
// buttonCancel
|
|
||||||
//
|
|
||||||
buttonCancel.Location = new Point(290, 100);
|
|
||||||
buttonCancel.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonCancel.Name = "buttonCancel";
|
|
||||||
buttonCancel.Size = new Size(101, 36);
|
|
||||||
buttonCancel.TabIndex = 7;
|
|
||||||
buttonCancel.Text = "Отмена";
|
|
||||||
buttonCancel.UseVisualStyleBackColor = true;
|
|
||||||
buttonCancel.Click += ButtonCancel_Click;
|
|
||||||
//
|
|
||||||
// FormFoodComponent
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(426, 148);
|
|
||||||
Controls.Add(buttonCancel);
|
|
||||||
Controls.Add(buttonSave);
|
|
||||||
Controls.Add(textBoxCount);
|
|
||||||
Controls.Add(comboBoxComponent);
|
|
||||||
Controls.Add(labelCount);
|
|
||||||
Controls.Add(labelComponent);
|
|
||||||
Margin = new Padding(3, 4, 3, 4);
|
|
||||||
Name = "FormFoodComponent";
|
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
|
||||||
Text = "Компонент еды";
|
|
||||||
ResumeLayout(false);
|
|
||||||
PerformLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private Label labelComponent;
|
|
||||||
private Label labelCount;
|
|
||||||
private ComboBox comboBoxComponent;
|
|
||||||
private TextBox textBoxCount;
|
|
||||||
private Button buttonSave;
|
|
||||||
private Button buttonCancel;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
using FoodOrdersContracts.BusinessLogicsContracts;
|
|
||||||
using FoodOrdersContracts.ViewModels;
|
|
||||||
using FoodOrdersDataModels.Models;
|
|
||||||
|
|
||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
public partial class FormDishComponent : 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 FormDishComponent(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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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>
|
|
128
FoodOrders/FoodOrdersView/FormDishes.Designer.cs
generated
128
FoodOrders/FoodOrdersView/FormDishes.Designer.cs
generated
@ -1,128 +0,0 @@
|
|||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
partial class FormDishes
|
|
||||||
{
|
|
||||||
/// <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()
|
|
||||||
{
|
|
||||||
dataGridView = new DataGridView();
|
|
||||||
buttonUpd = new Button();
|
|
||||||
buttonDel = new Button();
|
|
||||||
buttonEdit = new Button();
|
|
||||||
buttonAdd = new Button();
|
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// dataGridView
|
|
||||||
//
|
|
||||||
dataGridView.AllowUserToAddRows = false;
|
|
||||||
dataGridView.AllowUserToDeleteRows = false;
|
|
||||||
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
|
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
|
||||||
dataGridView.Dock = DockStyle.Left;
|
|
||||||
dataGridView.Location = new Point(0, 0);
|
|
||||||
dataGridView.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
dataGridView.MultiSelect = false;
|
|
||||||
dataGridView.Name = "dataGridView";
|
|
||||||
dataGridView.ReadOnly = true;
|
|
||||||
dataGridView.RowHeadersVisible = false;
|
|
||||||
dataGridView.RowHeadersWidth = 51;
|
|
||||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
|
||||||
dataGridView.Size = new Size(466, 480);
|
|
||||||
dataGridView.TabIndex = 1;
|
|
||||||
//
|
|
||||||
// buttonUpd
|
|
||||||
//
|
|
||||||
buttonUpd.Location = new Point(494, 203);
|
|
||||||
buttonUpd.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonUpd.Name = "buttonUpd";
|
|
||||||
buttonUpd.Size = new Size(101, 36);
|
|
||||||
buttonUpd.TabIndex = 8;
|
|
||||||
buttonUpd.Text = "Обновить";
|
|
||||||
buttonUpd.UseVisualStyleBackColor = true;
|
|
||||||
buttonUpd.Click += ButtonUpd_Click;
|
|
||||||
//
|
|
||||||
// buttonDel
|
|
||||||
//
|
|
||||||
buttonDel.Location = new Point(494, 140);
|
|
||||||
buttonDel.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonDel.Name = "buttonDel";
|
|
||||||
buttonDel.Size = new Size(101, 36);
|
|
||||||
buttonDel.TabIndex = 7;
|
|
||||||
buttonDel.Text = "Удалить";
|
|
||||||
buttonDel.UseVisualStyleBackColor = true;
|
|
||||||
buttonDel.Click += ButtonDel_Click;
|
|
||||||
//
|
|
||||||
// buttonEdit
|
|
||||||
//
|
|
||||||
buttonEdit.Location = new Point(494, 77);
|
|
||||||
buttonEdit.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonEdit.Name = "buttonEdit";
|
|
||||||
buttonEdit.Size = new Size(101, 36);
|
|
||||||
buttonEdit.TabIndex = 6;
|
|
||||||
buttonEdit.Text = "Изменить";
|
|
||||||
buttonEdit.UseVisualStyleBackColor = true;
|
|
||||||
buttonEdit.Click += ButtonEdit_Click;
|
|
||||||
//
|
|
||||||
// buttonAdd
|
|
||||||
//
|
|
||||||
buttonAdd.Location = new Point(494, 19);
|
|
||||||
buttonAdd.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonAdd.Name = "buttonAdd";
|
|
||||||
buttonAdd.Size = new Size(101, 36);
|
|
||||||
buttonAdd.TabIndex = 5;
|
|
||||||
buttonAdd.Text = "Добавить";
|
|
||||||
buttonAdd.UseVisualStyleBackColor = true;
|
|
||||||
buttonAdd.Click += ButtonAdd_Click;
|
|
||||||
//
|
|
||||||
// FormFoods
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(618, 480);
|
|
||||||
Controls.Add(buttonUpd);
|
|
||||||
Controls.Add(buttonDel);
|
|
||||||
Controls.Add(buttonEdit);
|
|
||||||
Controls.Add(buttonAdd);
|
|
||||||
Controls.Add(dataGridView);
|
|
||||||
Margin = new Padding(3, 4, 3, 4);
|
|
||||||
Name = "FormFoods";
|
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
|
||||||
Text = "Список еды";
|
|
||||||
Load += FormFoods_Load;
|
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
|
||||||
ResumeLayout(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private DataGridView dataGridView;
|
|
||||||
private Button buttonUpd;
|
|
||||||
private Button buttonDel;
|
|
||||||
private Button buttonEdit;
|
|
||||||
private Button buttonAdd;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,104 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.BusinessLogicsContracts;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
public partial class FormDishes : Form
|
|
||||||
{
|
|
||||||
private readonly ILogger _logger;
|
|
||||||
|
|
||||||
private readonly IDishLogic _logic;
|
|
||||||
|
|
||||||
public FormDishes(ILogger<FormDishes> logger, IDishLogic logic)
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
_logger = logger;
|
|
||||||
_logic = logic;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FormFoods_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["DishName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
||||||
dataGridView.Columns["DishComponents"].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(FormDish));
|
|
||||||
if (service is FormDish form)
|
|
||||||
{
|
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonEdit_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
|
||||||
{
|
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormDish));
|
|
||||||
if (service is FormDish 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 DishBindingModel { Id = id }))
|
|
||||||
{
|
|
||||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
|
||||||
}
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Ошибка при удалении блюда");
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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,148 +0,0 @@
|
|||||||
using FoodOrdersContracts.BindingModels;
|
|
||||||
using FoodOrdersContracts.BusinessLogicsContracts;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
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["DishId"].Visible = false;
|
|
||||||
dataGridView.Columns["DishName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("Загрузка заказов");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Ошибка загрузки заказов");
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
|
||||||
if (service is FormComponents form)
|
|
||||||
{
|
|
||||||
form.ShowDialog();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void МороженоеToolStripMenuItem_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormDishes));
|
|
||||||
if (service is FormDishes 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 });
|
|
||||||
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 });
|
|
||||||
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 });
|
|
||||||
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 ButtonUpd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
194
FoodOrders/FoodOrdersView/FormMain.designer.cs
generated
194
FoodOrders/FoodOrdersView/FormMain.designer.cs
generated
@ -1,194 +0,0 @@
|
|||||||
namespace FoodOrdersView
|
|
||||||
{
|
|
||||||
partial class FormMain
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Обязательная переменная конструктора.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Освободить все используемые ресурсы.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Код, автоматически созданный конструктором форм Windows
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
|
||||||
/// содержимое этого метода с помощью редактора кода.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
menuStrip = new MenuStrip();
|
|
||||||
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
|
||||||
компонентыToolStripMenuItem = new ToolStripMenuItem();
|
|
||||||
мороженоеToolStripMenuItem = new ToolStripMenuItem();
|
|
||||||
buttonIssuedOrder = new Button();
|
|
||||||
buttonOrderReady = new Button();
|
|
||||||
buttonTakeOrderInWork = new Button();
|
|
||||||
buttonCreateOrder = new Button();
|
|
||||||
dataGridView = new DataGridView();
|
|
||||||
buttonUpd = new Button();
|
|
||||||
menuStrip.SuspendLayout();
|
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// menuStrip
|
|
||||||
//
|
|
||||||
menuStrip.ImageScalingSize = new Size(20, 20);
|
|
||||||
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem });
|
|
||||||
menuStrip.Location = new Point(0, 0);
|
|
||||||
menuStrip.Name = "menuStrip";
|
|
||||||
menuStrip.Padding = new Padding(8, 3, 0, 3);
|
|
||||||
menuStrip.Size = new Size(1178, 30);
|
|
||||||
menuStrip.TabIndex = 0;
|
|
||||||
menuStrip.Text = "menuStrip1";
|
|
||||||
//
|
|
||||||
// справочникиToolStripMenuItem
|
|
||||||
//
|
|
||||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, мороженоеToolStripMenuItem });
|
|
||||||
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
|
||||||
справочникиToolStripMenuItem.Size = new Size(117, 24);
|
|
||||||
справочникиToolStripMenuItem.Text = "Справочники";
|
|
||||||
//
|
|
||||||
// компонентыToolStripMenuItem
|
|
||||||
//
|
|
||||||
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
|
||||||
компонентыToolStripMenuItem.Size = new Size(224, 26);
|
|
||||||
компонентыToolStripMenuItem.Text = "Компоненты";
|
|
||||||
компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
|
|
||||||
//
|
|
||||||
// мороженоеToolStripMenuItem
|
|
||||||
//
|
|
||||||
мороженоеToolStripMenuItem.Name = "мороженоеToolStripMenuItem";
|
|
||||||
мороженоеToolStripMenuItem.Size = new Size(224, 26);
|
|
||||||
мороженоеToolStripMenuItem.Text = "Еда";
|
|
||||||
мороженоеToolStripMenuItem.Click += МороженоеToolStripMenuItem_Click;
|
|
||||||
//
|
|
||||||
// buttonIssuedOrder
|
|
||||||
//
|
|
||||||
buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
||||||
buttonIssuedOrder.Location = new Point(965, 308);
|
|
||||||
buttonIssuedOrder.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonIssuedOrder.Name = "buttonIssuedOrder";
|
|
||||||
buttonIssuedOrder.Size = new Size(199, 36);
|
|
||||||
buttonIssuedOrder.TabIndex = 4;
|
|
||||||
buttonIssuedOrder.Text = "Заказ выдан";
|
|
||||||
buttonIssuedOrder.UseVisualStyleBackColor = true;
|
|
||||||
buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
|
|
||||||
//
|
|
||||||
// buttonOrderReady
|
|
||||||
//
|
|
||||||
buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
||||||
buttonOrderReady.Location = new Point(965, 228);
|
|
||||||
buttonOrderReady.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonOrderReady.Name = "buttonOrderReady";
|
|
||||||
buttonOrderReady.Size = new Size(199, 36);
|
|
||||||
buttonOrderReady.TabIndex = 3;
|
|
||||||
buttonOrderReady.Text = "Заказ готов";
|
|
||||||
buttonOrderReady.UseVisualStyleBackColor = true;
|
|
||||||
buttonOrderReady.Click += ButtonOrderReady_Click;
|
|
||||||
//
|
|
||||||
// buttonTakeOrderInWork
|
|
||||||
//
|
|
||||||
buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
||||||
buttonTakeOrderInWork.Location = new Point(965, 156);
|
|
||||||
buttonTakeOrderInWork.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
|
||||||
buttonTakeOrderInWork.Size = new Size(199, 36);
|
|
||||||
buttonTakeOrderInWork.TabIndex = 2;
|
|
||||||
buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
|
||||||
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
|
|
||||||
buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
|
|
||||||
//
|
|
||||||
// buttonCreateOrder
|
|
||||||
//
|
|
||||||
buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
||||||
buttonCreateOrder.Location = new Point(965, 77);
|
|
||||||
buttonCreateOrder.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonCreateOrder.Name = "buttonCreateOrder";
|
|
||||||
buttonCreateOrder.Size = new Size(199, 36);
|
|
||||||
buttonCreateOrder.TabIndex = 1;
|
|
||||||
buttonCreateOrder.Text = "Создать заказ";
|
|
||||||
buttonCreateOrder.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreateOrder.Click += ButtonCreateOrder_Click;
|
|
||||||
//
|
|
||||||
// dataGridView
|
|
||||||
//
|
|
||||||
dataGridView.AllowUserToAddRows = false;
|
|
||||||
dataGridView.AllowUserToDeleteRows = false;
|
|
||||||
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
|
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
|
||||||
dataGridView.Location = new Point(0, 37);
|
|
||||||
dataGridView.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
dataGridView.MultiSelect = false;
|
|
||||||
dataGridView.Name = "dataGridView";
|
|
||||||
dataGridView.ReadOnly = true;
|
|
||||||
dataGridView.RowHeadersVisible = false;
|
|
||||||
dataGridView.RowHeadersWidth = 51;
|
|
||||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
|
||||||
dataGridView.Size = new Size(944, 427);
|
|
||||||
dataGridView.TabIndex = 0;
|
|
||||||
//
|
|
||||||
// buttonUpd
|
|
||||||
//
|
|
||||||
buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
|
||||||
buttonUpd.Location = new Point(965, 387);
|
|
||||||
buttonUpd.Margin = new Padding(5, 4, 5, 4);
|
|
||||||
buttonUpd.Name = "buttonUpd";
|
|
||||||
buttonUpd.Size = new Size(199, 36);
|
|
||||||
buttonUpd.TabIndex = 5;
|
|
||||||
buttonUpd.Text = "Обновить список";
|
|
||||||
buttonUpd.UseVisualStyleBackColor = true;
|
|
||||||
buttonUpd.Click += ButtonUpd_Click;
|
|
||||||
//
|
|
||||||
// FormMain
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(1178, 463);
|
|
||||||
Controls.Add(buttonUpd);
|
|
||||||
Controls.Add(buttonIssuedOrder);
|
|
||||||
Controls.Add(buttonOrderReady);
|
|
||||||
Controls.Add(buttonTakeOrderInWork);
|
|
||||||
Controls.Add(buttonCreateOrder);
|
|
||||||
Controls.Add(dataGridView);
|
|
||||||
Controls.Add(menuStrip);
|
|
||||||
MainMenuStrip = menuStrip;
|
|
||||||
Margin = new Padding(5, 4, 5, 4);
|
|
||||||
Name = "FormMain";
|
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
|
||||||
Text = "Столовая";
|
|
||||||
Load += FormMain_Load;
|
|
||||||
menuStrip.ResumeLayout(false);
|
|
||||||
menuStrip.PerformLayout();
|
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
|
||||||
ResumeLayout(false);
|
|
||||||
PerformLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private MenuStrip menuStrip;
|
|
||||||
private ToolStripMenuItem справочникиToolStripMenuItem;
|
|
||||||
private ToolStripMenuItem компонентыToolStripMenuItem;
|
|
||||||
private ToolStripMenuItem мороженоеToolStripMenuItem;
|
|
||||||
private Button buttonIssuedOrder;
|
|
||||||
private Button buttonOrderReady;
|
|
||||||
private Button buttonTakeOrderInWork;
|
|
||||||
private Button buttonCreateOrder;
|
|
||||||
private DataGridView dataGridView;
|
|
||||||
private Button buttonUpd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,123 +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>
|
|
||||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
|
||||||
<value>17, 17</value>
|
|
||||||
</metadata>
|
|
||||||
</root>
|
|
@ -1,18 +1,7 @@
|
|||||||
using FoodOrdersBusinessLogic.BusinessLogics;
|
|
||||||
using FoodOrdersContracts.BusinessLogicsContracts;
|
|
||||||
using FoodOrdersContracts.StoragesContracts;
|
|
||||||
using FoodOrdersDatabaseImplement.Implements;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using NLog.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace FoodOrdersView
|
namespace FoodOrdersView
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
private static ServiceProvider? _serviceProvider;
|
|
||||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -22,34 +11,7 @@ namespace FoodOrdersView
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
var services = new ServiceCollection();
|
Application.Run(new Form1());
|
||||||
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<IDishStorage, DishStorage>();
|
|
||||||
|
|
||||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
|
||||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
|
||||||
services.AddTransient<IDishLogic, DishLogic>();
|
|
||||||
|
|
||||||
services.AddTransient<FormMain>();
|
|
||||||
services.AddTransient<FormComponent>();
|
|
||||||
services.AddTransient<FormComponents>();
|
|
||||||
services.AddTransient<FormCreateOrder>();
|
|
||||||
services.AddTransient<FormDish>();
|
|
||||||
services.AddTransient<FormDishComponent>();
|
|
||||||
services.AddTransient<FormDishes>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,15 +0,0 @@
|
|||||||
<?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="tofile" fileName="log-${shortdate}.log" />
|
|
||||||
</targets>
|
|
||||||
|
|
||||||
<rules>
|
|
||||||
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
|
||||||
</rules>
|
|
||||||
</nlog>
|
|
||||||
</configuration>
|
|
Loading…
Reference in New Issue
Block a user