Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
6775260eff | |||
183ee0634e | |||
025f13f0d7 |
@ -3,7 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.2.32616.157
|
VisualStudioVersion = 17.2.32616.157
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractShopView", "AbstractShopView\AbstractShopView.csproj", "{30272FA6-ABB7-4436-AFC6-50478DF2B878}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractShopView", "AbstractShopView\AbstractShopView.csproj", "{30272FA6-ABB7-4436-AFC6-50478DF2B878}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractShopDataModels", "AbstractShopDataModels\AbstractShopDataModels.csproj", "{E47BFE5D-69E3-4A3F-85BE-251F10EAFA02}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractShopContracts", "AbstractShopContracts\AbstractShopContracts.csproj", "{9AD66AC2-51DF-4E16-83E9-35C1CA19E774}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractShopListImplement", "AbstractShopListImplement\AbstractShopListImplement.csproj", "{74283CE4-7CE6-42AC-AA8D-EE4497E08D61}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractShopBusinessLogic", "AbstractShopBusinessLogic\AbstractShopBusinessLogic.csproj", "{9A10E59F-081B-4C4D-AB16-15A777B66502}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractShopFileImplement", "AbstractShopFileImplement\AbstractShopFileImplement.csproj", "{3ECD0091-7E52-48C4-9529-D0BE6D6EF1DE}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractShopDatabaseImplement", "AbstractShopDatabaseImplement\AbstractShopDatabaseImplement.csproj", "{C76CA7A5-B719-4A01-865F-BD6FD679ECCC}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -15,6 +27,30 @@ Global
|
|||||||
{30272FA6-ABB7-4436-AFC6-50478DF2B878}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{30272FA6-ABB7-4436-AFC6-50478DF2B878}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{30272FA6-ABB7-4436-AFC6-50478DF2B878}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{30272FA6-ABB7-4436-AFC6-50478DF2B878}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{30272FA6-ABB7-4436-AFC6-50478DF2B878}.Release|Any CPU.Build.0 = Release|Any CPU
|
{30272FA6-ABB7-4436-AFC6-50478DF2B878}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{E47BFE5D-69E3-4A3F-85BE-251F10EAFA02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{E47BFE5D-69E3-4A3F-85BE-251F10EAFA02}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{E47BFE5D-69E3-4A3F-85BE-251F10EAFA02}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{E47BFE5D-69E3-4A3F-85BE-251F10EAFA02}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{9AD66AC2-51DF-4E16-83E9-35C1CA19E774}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9AD66AC2-51DF-4E16-83E9-35C1CA19E774}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9AD66AC2-51DF-4E16-83E9-35C1CA19E774}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9AD66AC2-51DF-4E16-83E9-35C1CA19E774}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{74283CE4-7CE6-42AC-AA8D-EE4497E08D61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{74283CE4-7CE6-42AC-AA8D-EE4497E08D61}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{74283CE4-7CE6-42AC-AA8D-EE4497E08D61}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{74283CE4-7CE6-42AC-AA8D-EE4497E08D61}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{9A10E59F-081B-4C4D-AB16-15A777B66502}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9A10E59F-081B-4C4D-AB16-15A777B66502}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9A10E59F-081B-4C4D-AB16-15A777B66502}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9A10E59F-081B-4C4D-AB16-15A777B66502}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{3ECD0091-7E52-48C4-9529-D0BE6D6EF1DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{3ECD0091-7E52-48C4-9529-D0BE6D6EF1DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{3ECD0091-7E52-48C4-9529-D0BE6D6EF1DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{3ECD0091-7E52-48C4-9529-D0BE6D6EF1DE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{C76CA7A5-B719-4A01-865F-BD6FD679ECCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C76CA7A5-B719-4A01-865F-BD6FD679ECCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{C76CA7A5-B719-4A01-865F-BD6FD679ECCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C76CA7A5-B719-4A01-865F-BD6FD679ECCC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractShopContracts\AbstractShopContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,115 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.BusinessLogicsContracts;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.StoragesContracts;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace AbstractShopBusinessLogic.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("Компонент с таким названием уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.BusinessLogicsContracts;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace AbstractShopBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class OrderLogic : IOrderLogic
|
||||||
|
{
|
||||||
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeliveryOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool FinishOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.BusinessLogicsContracts;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace AbstractShopBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class ProductLogic : IProductLogic
|
||||||
|
{
|
||||||
|
public bool Create(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel? ReadElement(ProductSearchModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductViewModel>? ReadList(ProductSearchModel? model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractShopDataModels\AbstractShopDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,13 @@
|
|||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace AbstractShopContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ComponentBindingModel : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string ComponentName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public double Cost { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
using AbstractShopDataModels.Enums;
|
||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace AbstractShopContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class OrderBindingModel : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public int ProductId { 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace AbstractShopContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class ProductBindingModel : IProductModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string ProductName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public double Price { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace AbstractShopContracts.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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace AbstractShopContracts.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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace AbstractShopContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IProductLogic
|
||||||
|
{
|
||||||
|
List<ProductViewModel>? ReadList(ProductSearchModel? model);
|
||||||
|
|
||||||
|
ProductViewModel? ReadElement(ProductSearchModel model);
|
||||||
|
|
||||||
|
bool Create(ProductBindingModel model);
|
||||||
|
|
||||||
|
bool Update(ProductBindingModel model);
|
||||||
|
|
||||||
|
bool Delete(ProductBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace AbstractShopContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class ComponentSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
|
||||||
|
public string? ComponentName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
namespace AbstractShopContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class OrderSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace AbstractShopContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class ProductSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
|
||||||
|
public string? ProductName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace AbstractShopContracts.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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace AbstractShopContracts.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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace AbstractShopContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IProductStorage
|
||||||
|
{
|
||||||
|
List<ProductViewModel> GetFullList();
|
||||||
|
|
||||||
|
List<ProductViewModel> GetFilteredList(ProductSearchModel model);
|
||||||
|
|
||||||
|
ProductViewModel? GetElement(ProductSearchModel model);
|
||||||
|
|
||||||
|
ProductViewModel? Insert(ProductBindingModel model);
|
||||||
|
|
||||||
|
ProductViewModel? Update(ProductBindingModel model);
|
||||||
|
|
||||||
|
ProductViewModel? Delete(ProductBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace AbstractShopContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ComponentViewModel : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Название компонента")]
|
||||||
|
public string ComponentName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Цена")]
|
||||||
|
public double Cost { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
using AbstractShopDataModels.Enums;
|
||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace AbstractShopContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class OrderViewModel : IOrderModel
|
||||||
|
{
|
||||||
|
[DisplayName("Номер")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Изделие")]
|
||||||
|
public string ProductName { 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace AbstractShopContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class ProductViewModel : IProductModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Название изделия")]
|
||||||
|
public string ProductName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Цена")]
|
||||||
|
public double Price { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
15
AbstractShop/AbstractShopDataModels/Enums/OrderStatus.cs
Normal file
15
AbstractShop/AbstractShopDataModels/Enums/OrderStatus.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
namespace AbstractShopDataModels.Enums
|
||||||
|
{
|
||||||
|
public enum OrderStatus
|
||||||
|
{
|
||||||
|
Неизвестен = -1,
|
||||||
|
|
||||||
|
Принят = 0,
|
||||||
|
|
||||||
|
Выполняется = 1,
|
||||||
|
|
||||||
|
Готов = 2,
|
||||||
|
|
||||||
|
Выдан = 3
|
||||||
|
}
|
||||||
|
}
|
7
AbstractShop/AbstractShopDataModels/IId.cs
Normal file
7
AbstractShop/AbstractShopDataModels/IId.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace AbstractShopDataModels
|
||||||
|
{
|
||||||
|
public interface IId
|
||||||
|
{
|
||||||
|
int Id { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace AbstractShopDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IComponentModel : IId
|
||||||
|
{
|
||||||
|
string ComponentName { get; }
|
||||||
|
|
||||||
|
double Cost { get; }
|
||||||
|
}
|
||||||
|
}
|
19
AbstractShop/AbstractShopDataModels/Models/IOrderModel.cs
Normal file
19
AbstractShop/AbstractShopDataModels/Models/IOrderModel.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using AbstractShopDataModels.Enums;
|
||||||
|
|
||||||
|
namespace AbstractShopDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IOrderModel : IId
|
||||||
|
{
|
||||||
|
int ProductId { get; }
|
||||||
|
|
||||||
|
int Count { get; }
|
||||||
|
|
||||||
|
double Sum { get; }
|
||||||
|
|
||||||
|
OrderStatus Status { get; }
|
||||||
|
|
||||||
|
DateTime DateCreate { get; }
|
||||||
|
|
||||||
|
DateTime? DateImplement { get; }
|
||||||
|
}
|
||||||
|
}
|
11
AbstractShop/AbstractShopDataModels/Models/IProductModel.cs
Normal file
11
AbstractShop/AbstractShopDataModels/Models/IProductModel.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace AbstractShopDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IProductModel : IId
|
||||||
|
{
|
||||||
|
string ProductName { get; }
|
||||||
|
|
||||||
|
double Price { get; }
|
||||||
|
|
||||||
|
Dictionary<int, (IComponentModel, int)> ProductComponents { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
using AbstractShopDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace AbstractShopDatabaseImplement
|
||||||
|
{
|
||||||
|
public class AbstractShopDatabase : DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (optionsBuilder.IsConfigured == false)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseSqlServer(@"Data Source=CHESHIR\SQLEXPRESS;Initial Catalog=AbstractShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
|
}
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual DbSet<Component> Components { set; get; }
|
||||||
|
|
||||||
|
public virtual DbSet<Product> Products { set; get; }
|
||||||
|
|
||||||
|
public virtual DbSet<ProductComponent> ProductComponents { set; get; }
|
||||||
|
|
||||||
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<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.3" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.3" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractShopContracts\AbstractShopContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\AbstractShopDataModels\AbstractShopDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,84 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.StoragesContracts;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace AbstractShopDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class ComponentStorage : IComponentStorage
|
||||||
|
{
|
||||||
|
public List<ComponentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new AbstractShopDatabase();
|
||||||
|
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 AbstractShopDatabase();
|
||||||
|
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 AbstractShopDatabase();
|
||||||
|
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 AbstractShopDatabase();
|
||||||
|
context.Components.Add(newComponent);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newComponent.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new AbstractShopDatabase();
|
||||||
|
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 AbstractShopDatabase();
|
||||||
|
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Components.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.StoragesContracts;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace AbstractShopDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,106 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.StoragesContracts;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace AbstractShopDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class ProductStorage : IProductStorage
|
||||||
|
{
|
||||||
|
public List<ProductViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new AbstractShopDatabase();
|
||||||
|
return context.Products
|
||||||
|
.Include(x => x.Components)
|
||||||
|
.ThenInclude(x => x.Component)
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ProductName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new AbstractShopDatabase();
|
||||||
|
return context.Products
|
||||||
|
.Include(x => x.Components)
|
||||||
|
.ThenInclude(x => x.Component)
|
||||||
|
.Where(x => x.ProductName.Contains(model.ProductName))
|
||||||
|
.ToList()
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel? GetElement(ProductSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ProductName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new AbstractShopDatabase();
|
||||||
|
return context.Products
|
||||||
|
.Include(x => x.Components)
|
||||||
|
.ThenInclude(x => x.Component)
|
||||||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProductName) && x.ProductName == model.ProductName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel? Insert(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new AbstractShopDatabase();
|
||||||
|
var newProduct = Product.Create(context, model);
|
||||||
|
if (newProduct == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Products.Add(newProduct);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newProduct.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel? Update(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new AbstractShopDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var product = context.Products.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
product.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
product.UpdateComponents(context, model);
|
||||||
|
transaction.Commit();
|
||||||
|
return product.GetViewModel;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel? Delete(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new AbstractShopDatabase();
|
||||||
|
var element = context.Products
|
||||||
|
.Include(x => x.Components)
|
||||||
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
context.Products.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
156
AbstractShop/AbstractShopDatabaseImplement/Migrations/20230224083046_InitMigration.Designer.cs
generated
Normal file
156
AbstractShop/AbstractShopDatabaseImplement/Migrations/20230224083046_InitMigration.Designer.cs
generated
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using AbstractShopDatabaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace AbstractShopDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(AbstractShopDatabase))]
|
||||||
|
[Migration("20230224083046_InitMigration")]
|
||||||
|
partial class InitMigration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.3")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("AbstractShopDatabaseImplement.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("AbstractShopDatabaseImplement.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>("ProductId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AbstractShopDatabaseImplement.Models.Product", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.Property<string>("ProductName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Products");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AbstractShopDatabaseImplement.Models.ProductComponent", 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>("ProductId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ComponentId");
|
||||||
|
|
||||||
|
b.HasIndex("ProductId");
|
||||||
|
|
||||||
|
b.ToTable("ProductComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AbstractShopDatabaseImplement.Models.ProductComponent", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("AbstractShopDatabaseImplement.Models.Component", "Component")
|
||||||
|
.WithMany("ProductComponents")
|
||||||
|
.HasForeignKey("ComponentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("AbstractShopDatabaseImplement.Models.Product", "Product")
|
||||||
|
.WithMany("Components")
|
||||||
|
.HasForeignKey("ProductId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Component");
|
||||||
|
|
||||||
|
b.Navigation("Product");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AbstractShopDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("ProductComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AbstractShopDatabaseImplement.Models.Product", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Components");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,114 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace AbstractShopDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class InitMigration : 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: "Orders",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
ProductId = 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);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Products",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
ProductName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Price = table.Column<double>(type: "float", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Products", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ProductComponents",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
ProductId = 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_ProductComponents", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ProductComponents_Components_ComponentId",
|
||||||
|
column: x => x.ComponentId,
|
||||||
|
principalTable: "Components",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ProductComponents_Products_ProductId",
|
||||||
|
column: x => x.ProductId,
|
||||||
|
principalTable: "Products",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ProductComponents_ComponentId",
|
||||||
|
table: "ProductComponents",
|
||||||
|
column: "ComponentId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ProductComponents_ProductId",
|
||||||
|
table: "ProductComponents",
|
||||||
|
column: "ProductId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ProductComponents");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Components");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Products");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,153 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using AbstractShopDatabaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace AbstractShopDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(AbstractShopDatabase))]
|
||||||
|
partial class AbstractShopDatabaseModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.3")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("AbstractShopDatabaseImplement.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("AbstractShopDatabaseImplement.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>("ProductId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AbstractShopDatabaseImplement.Models.Product", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.Property<string>("ProductName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Products");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AbstractShopDatabaseImplement.Models.ProductComponent", 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>("ProductId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ComponentId");
|
||||||
|
|
||||||
|
b.HasIndex("ProductId");
|
||||||
|
|
||||||
|
b.ToTable("ProductComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AbstractShopDatabaseImplement.Models.ProductComponent", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("AbstractShopDatabaseImplement.Models.Component", "Component")
|
||||||
|
.WithMany("ProductComponents")
|
||||||
|
.HasForeignKey("ComponentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("AbstractShopDatabaseImplement.Models.Product", "Product")
|
||||||
|
.WithMany("Components")
|
||||||
|
.HasForeignKey("ProductId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Component");
|
||||||
|
|
||||||
|
b.Navigation("Product");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AbstractShopDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("ProductComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AbstractShopDatabaseImplement.Models.Product", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Components");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace AbstractShopDatabaseImplement.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<ProductComponent> ProductComponents { 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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
38
AbstractShop/AbstractShopDatabaseImplement/Models/Order.cs
Normal file
38
AbstractShop/AbstractShopDatabaseImplement/Models/Order.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopDataModels.Enums;
|
||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace AbstractShopDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
public double Sum { get; set; }
|
||||||
|
|
||||||
|
public OrderStatus Status { get; set; }
|
||||||
|
|
||||||
|
public DateTime DateCreate { get; set; }
|
||||||
|
|
||||||
|
public DateTime? DateImplement { get; set; }
|
||||||
|
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public static Order? Create(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
return new Order();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
96
AbstractShop/AbstractShopDatabaseImplement/Models/Product.cs
Normal file
96
AbstractShop/AbstractShopDatabaseImplement/Models/Product.cs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace AbstractShopDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Product : IProductModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string ProductName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public double Price { get; set; }
|
||||||
|
|
||||||
|
private Dictionary<int, (IComponentModel, int)>? _productComponents = null;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_productComponents == null)
|
||||||
|
{
|
||||||
|
_productComponents = Components
|
||||||
|
.ToDictionary(recPC => recPC.ComponentId, recPC => (recPC.Component as IComponentModel, recPC.Count));
|
||||||
|
}
|
||||||
|
return _productComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ForeignKey("ProductId")]
|
||||||
|
public virtual List<ProductComponent> Components { get; set; } = new();
|
||||||
|
|
||||||
|
public static Product Create(AbstractShopDatabase context, ProductBindingModel model)
|
||||||
|
{
|
||||||
|
return new Product()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ProductName = model.ProductName,
|
||||||
|
Price = model.Price,
|
||||||
|
Components = model.ProductComponents.Select(x => new ProductComponent
|
||||||
|
{
|
||||||
|
Component = context.Components.First(y => y.Id == x.Key),
|
||||||
|
Count = x.Value.Item2
|
||||||
|
}).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
ProductName = model.ProductName;
|
||||||
|
Price = model.Price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ProductName = ProductName,
|
||||||
|
Price = Price,
|
||||||
|
ProductComponents = ProductComponents
|
||||||
|
};
|
||||||
|
|
||||||
|
public void UpdateComponents(AbstractShopDatabase context, ProductBindingModel model)
|
||||||
|
{
|
||||||
|
var productComponents = context.ProductComponents.Where(rec => rec.ProductId == model.Id).ToList();
|
||||||
|
if (productComponents != null && productComponents.Count > 0)
|
||||||
|
{ // удалили те, которых нет в модели
|
||||||
|
context.ProductComponents.RemoveRange(productComponents.Where(rec => !model.ProductComponents.ContainsKey(rec.ComponentId)));
|
||||||
|
context.SaveChanges();
|
||||||
|
// обновили количество у существующих записей
|
||||||
|
foreach (var updateComponent in productComponents)
|
||||||
|
{
|
||||||
|
updateComponent.Count = model.ProductComponents[updateComponent.ComponentId].Item2;
|
||||||
|
model.ProductComponents.Remove(updateComponent.ComponentId);
|
||||||
|
}
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
var product = context.Products.First(x => x.Id == Id);
|
||||||
|
foreach (var pc in model.ProductComponents)
|
||||||
|
{
|
||||||
|
context.ProductComponents.Add(new ProductComponent
|
||||||
|
{
|
||||||
|
Product = product,
|
||||||
|
Component = context.Components.First(x => x.Id == pc.Key),
|
||||||
|
Count = pc.Value.Item2
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
_productComponents = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace AbstractShopDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class ProductComponent
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int ComponentId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
public virtual Component Component { get; set; } = new();
|
||||||
|
|
||||||
|
public virtual Product Product { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractShopContracts\AbstractShopContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\AbstractShopDataModels\AbstractShopDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
61
AbstractShop/AbstractShopFileImplement/DataFileSingleton.cs
Normal file
61
AbstractShop/AbstractShopFileImplement/DataFileSingleton.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using AbstractShopFileImplement.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace AbstractShopFileImplement
|
||||||
|
{
|
||||||
|
internal class DataFileSingleton
|
||||||
|
{
|
||||||
|
private static DataFileSingleton? instance;
|
||||||
|
|
||||||
|
private readonly string ComponentFileName = "Component.xml";
|
||||||
|
|
||||||
|
private readonly string OrderFileName = "Order.xml";
|
||||||
|
|
||||||
|
private readonly string ProductFileName = "Product.xml";
|
||||||
|
|
||||||
|
public List<Component> Components { get; private set; }
|
||||||
|
|
||||||
|
public List<Order> Orders { get; private set; }
|
||||||
|
|
||||||
|
public List<Product> Products { 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 SaveProducts() => SaveData(Products, ProductFileName, "Products", x => x.GetXElement);
|
||||||
|
|
||||||
|
public void SaveOrders() { }
|
||||||
|
|
||||||
|
private DataFileSingleton()
|
||||||
|
{
|
||||||
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
|
Products = LoadData(ProductFileName, "Product", x => Product.Create(x)!)!;
|
||||||
|
Orders = new List<Order>();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.StoragesContracts;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopFileImplement.Models;
|
||||||
|
|
||||||
|
namespace AbstractShopFileImplement.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.StoragesContracts;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace AbstractShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.StoragesContracts;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace AbstractShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ProductStorage : IProductStorage
|
||||||
|
{
|
||||||
|
public ProductViewModel? Delete(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel? GetElement(ProductSearchModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel? Insert(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel? Update(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
66
AbstractShop/AbstractShopFileImplement/Models/Component.cs
Normal file
66
AbstractShop/AbstractShopFileImplement/Models/Component.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace AbstractShopFileImplement.Models
|
||||||
|
{
|
||||||
|
internal 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()));
|
||||||
|
}
|
||||||
|
}
|
46
AbstractShop/AbstractShopFileImplement/Models/Order.cs
Normal file
46
AbstractShop/AbstractShopFileImplement/Models/Order.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopDataModels.Enums;
|
||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace AbstractShopFileImplement.Models
|
||||||
|
{
|
||||||
|
internal class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int ProductId => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public int Count => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public double Sum => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public OrderStatus Status => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public DateTime DateCreate => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public DateTime? DateImplement => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public int Id => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public static Order? Create(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
return new Order();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Order? Create(XElement element)
|
||||||
|
{
|
||||||
|
return new Order();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("Order");
|
||||||
|
}
|
||||||
|
}
|
93
AbstractShop/AbstractShopFileImplement/Models/Product.cs
Normal file
93
AbstractShop/AbstractShopFileImplement/Models/Product.cs
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace AbstractShopFileImplement.Models
|
||||||
|
{
|
||||||
|
internal class Product : IProductModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
public string ProductName { 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)>? _productComponents = null;
|
||||||
|
|
||||||
|
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_productComponents == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_productComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
|
||||||
|
}
|
||||||
|
return _productComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Product? Create(ProductBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Product()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ProductName = model.ProductName,
|
||||||
|
Price = model.Price,
|
||||||
|
Components = model.ProductComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Product? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Product()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ProductName = element.Element("ProductName")!.Value,
|
||||||
|
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||||
|
Components = element.Element("ProductComponents")!.Elements("ProductComponent")
|
||||||
|
.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ProductBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ProductName = model.ProductName;
|
||||||
|
Price = model.Price;
|
||||||
|
Components = model.ProductComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_productComponents = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ProductName = ProductName,
|
||||||
|
Price = Price,
|
||||||
|
ProductComponents = ProductComponents
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("Product",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ProductName", ProductName),
|
||||||
|
new XElement("Price", Price.ToString()),
|
||||||
|
new XElement("ProductComponents", Components.Select(x => new XElement("ProductComponent",
|
||||||
|
new XElement("Key", x.Key),
|
||||||
|
new XElement("Value", x.Value)))
|
||||||
|
.ToArray()));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractShopContracts\AbstractShopContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\AbstractShopDataModels\AbstractShopDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
32
AbstractShop/AbstractShopListImplement/DataListSingleton.cs
Normal file
32
AbstractShop/AbstractShopListImplement/DataListSingleton.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using AbstractShopListImplement.Models;
|
||||||
|
|
||||||
|
namespace AbstractShopListImplement
|
||||||
|
{
|
||||||
|
internal class DataListSingleton
|
||||||
|
{
|
||||||
|
private static DataListSingleton? _instance;
|
||||||
|
|
||||||
|
public List<Component> Components { get; set; }
|
||||||
|
|
||||||
|
public List<Order> Orders { get; set; }
|
||||||
|
|
||||||
|
public List<Product> Products { get; set; }
|
||||||
|
|
||||||
|
private DataListSingleton()
|
||||||
|
{
|
||||||
|
Components = new List<Component>();
|
||||||
|
Orders = new List<Order>();
|
||||||
|
Products = new List<Product>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DataListSingleton GetInstance()
|
||||||
|
{
|
||||||
|
if (_instance == null)
|
||||||
|
{
|
||||||
|
_instance = new DataListSingleton();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.StoragesContracts;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopListImplement.Models;
|
||||||
|
|
||||||
|
namespace AbstractShopListImplement.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.StoragesContracts;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace AbstractShopListImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopContracts.StoragesContracts;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace AbstractShopListImplement.Implements
|
||||||
|
{
|
||||||
|
public class ProductStorage : IProductStorage
|
||||||
|
{
|
||||||
|
public ProductViewModel? Delete(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel? GetElement(ProductSearchModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel? Insert(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel? Update(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
AbstractShop/AbstractShopListImplement/Models/Component.cs
Normal file
46
AbstractShop/AbstractShopListImplement/Models/Component.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace AbstractShopListImplement.Models
|
||||||
|
{
|
||||||
|
internal 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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
38
AbstractShop/AbstractShopListImplement/Models/Order.cs
Normal file
38
AbstractShop/AbstractShopListImplement/Models/Order.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopDataModels.Enums;
|
||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace AbstractShopListImplement.Models
|
||||||
|
{
|
||||||
|
internal class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int ProductId => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public int Count => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public double Sum => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public OrderStatus Status => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public DateTime DateCreate => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public DateTime? DateImplement => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public int Id => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public static Order? Create(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
return new Order();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
51
AbstractShop/AbstractShopListImplement/Models/Product.cs
Normal file
51
AbstractShop/AbstractShopListImplement/Models/Product.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace AbstractShopListImplement.Models
|
||||||
|
{
|
||||||
|
internal class Product : IProductModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
public string ProductName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public double Price { get; private set; }
|
||||||
|
|
||||||
|
public Dictionary<int, (IComponentModel, int)> ProductComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
|
||||||
|
public static Product? Create(ProductBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Product()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ProductName = model.ProductName,
|
||||||
|
Price = model.Price,
|
||||||
|
ProductComponents = model.ProductComponents
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ProductBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ProductName = model.ProductName;
|
||||||
|
Price = model.Price;
|
||||||
|
ProductComponents = model.ProductComponents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ProductName = ProductName,
|
||||||
|
Price = Price,
|
||||||
|
ProductComponents = ProductComponents
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -8,4 +8,33 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="nlog.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="nlog.config">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AbstractShopBusinessLogic\AbstractShopBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\AbstractShopContracts\AbstractShopContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\AbstractShopDatabaseImplement\AbstractShopDatabaseImplement.csproj" />
|
||||||
|
<ProjectReference Include="..\AbstractShopFileImplement\AbstractShopFileImplement.csproj" />
|
||||||
|
<ProjectReference Include="..\AbstractShopListImplement\AbstractShopListImplement.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
39
AbstractShop/AbstractShopView/Form1.Designer.cs
generated
39
AbstractShop/AbstractShopView/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
|||||||
namespace AbstractShopView
|
|
||||||
{
|
|
||||||
partial class Form1
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
this.components = new System.ComponentModel.Container();
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
|
||||||
this.Text = "Form1";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace AbstractShopView
|
|
||||||
{
|
|
||||||
public partial class Form1 : Form
|
|
||||||
{
|
|
||||||
public Form1()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
85
AbstractShop/AbstractShopView/FormComponent.cs
Normal file
85
AbstractShop/AbstractShopView/FormComponent.cs
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.BusinessLogicsContracts;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace AbstractShopView
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
127
AbstractShop/AbstractShopView/FormComponent.designer.cs
generated
Normal file
127
AbstractShop/AbstractShopView/FormComponent.designer.cs
generated
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
namespace AbstractShopView
|
||||||
|
{
|
||||||
|
partial class FormComponent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||||
|
this.labelName = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxCost = new System.Windows.Forms.TextBox();
|
||||||
|
this.labelCost = new System.Windows.Forms.Label();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(257, 71);
|
||||||
|
this.buttonCancel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(88, 27);
|
||||||
|
this.buttonCancel.TabIndex = 5;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(162, 71);
|
||||||
|
this.buttonSave.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(88, 27);
|
||||||
|
this.buttonSave.TabIndex = 4;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
this.textBoxName.Location = new System.Drawing.Point(91, 7);
|
||||||
|
this.textBoxName.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.textBoxName.Name = "textBoxName";
|
||||||
|
this.textBoxName.Size = new System.Drawing.Size(252, 23);
|
||||||
|
this.textBoxName.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelName
|
||||||
|
//
|
||||||
|
this.labelName.AutoSize = true;
|
||||||
|
this.labelName.Location = new System.Drawing.Point(14, 10);
|
||||||
|
this.labelName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.labelName.Name = "labelName";
|
||||||
|
this.labelName.Size = new System.Drawing.Size(62, 15);
|
||||||
|
this.labelName.TabIndex = 0;
|
||||||
|
this.labelName.Text = "Название:";
|
||||||
|
//
|
||||||
|
// textBoxCost
|
||||||
|
//
|
||||||
|
this.textBoxCost.Location = new System.Drawing.Point(91, 36);
|
||||||
|
this.textBoxCost.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.textBoxCost.Name = "textBoxCost";
|
||||||
|
this.textBoxCost.Size = new System.Drawing.Size(129, 23);
|
||||||
|
this.textBoxCost.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// labelCost
|
||||||
|
//
|
||||||
|
this.labelCost.AutoSize = true;
|
||||||
|
this.labelCost.Location = new System.Drawing.Point(14, 39);
|
||||||
|
this.labelCost.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.labelCost.Name = "labelCost";
|
||||||
|
this.labelCost.Size = new System.Drawing.Size(38, 15);
|
||||||
|
this.labelCost.TabIndex = 2;
|
||||||
|
this.labelCost.Text = "Цена:";
|
||||||
|
//
|
||||||
|
// FormComponent
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(360, 110);
|
||||||
|
this.Controls.Add(this.textBoxCost);
|
||||||
|
this.Controls.Add(this.labelCost);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.textBoxName);
|
||||||
|
this.Controls.Add(this.labelName);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.Name = "FormComponent";
|
||||||
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
|
this.Text = "Компонент";
|
||||||
|
this.Load += new System.EventHandler(this.FormComponent_Load);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Button buttonCancel;
|
||||||
|
private System.Windows.Forms.Button buttonSave;
|
||||||
|
private System.Windows.Forms.TextBox textBoxName;
|
||||||
|
private System.Windows.Forms.Label labelName;
|
||||||
|
private TextBox textBoxCost;
|
||||||
|
private Label labelCost;
|
||||||
|
}
|
||||||
|
}
|
120
AbstractShop/AbstractShopView/FormComponent.resx
Normal file
120
AbstractShop/AbstractShopView/FormComponent.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
103
AbstractShop/AbstractShopView/FormComponents.cs
Normal file
103
AbstractShop/AbstractShopView/FormComponents.cs
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace AbstractShopView
|
||||||
|
{
|
||||||
|
public partial class FormComponents : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly IComponentLogic _logic;
|
||||||
|
|
||||||
|
public FormComponents(ILogger<FormComponents> logger, IComponentLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormComponents_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logic.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
dataGridView.DataSource = list;
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
|
dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Загрузка компонентов");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||||
|
if (service is FormComponent form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||||
|
if (service is FormComponent form)
|
||||||
|
{
|
||||||
|
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
|
_logger.LogInformation("Удаление компонента");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!_logic.Delete(new ComponentBindingModel { Id = id }))
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления компонента");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRef_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
122
AbstractShop/AbstractShopView/FormComponents.designer.cs
generated
Normal file
122
AbstractShop/AbstractShopView/FormComponents.designer.cs
generated
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
namespace AbstractShopView
|
||||||
|
{
|
||||||
|
partial class FormComponents
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.buttonRef = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUpd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonRef
|
||||||
|
//
|
||||||
|
this.buttonRef.Location = new System.Drawing.Point(370, 132);
|
||||||
|
this.buttonRef.Name = "buttonRef";
|
||||||
|
this.buttonRef.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonRef.TabIndex = 4;
|
||||||
|
this.buttonRef.Text = "Обновить";
|
||||||
|
this.buttonRef.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
this.buttonDel.Location = new System.Drawing.Point(370, 91);
|
||||||
|
this.buttonDel.Name = "buttonDel";
|
||||||
|
this.buttonDel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonDel.TabIndex = 3;
|
||||||
|
this.buttonDel.Text = "Удалить";
|
||||||
|
this.buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||||
|
//
|
||||||
|
// buttonUpd
|
||||||
|
//
|
||||||
|
this.buttonUpd.Location = new System.Drawing.Point(370, 50);
|
||||||
|
this.buttonUpd.Name = "buttonUpd";
|
||||||
|
this.buttonUpd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonUpd.TabIndex = 2;
|
||||||
|
this.buttonUpd.Text = "Изменить";
|
||||||
|
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(370, 12);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonAdd.TabIndex = 1;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.AllowUserToAddRows = false;
|
||||||
|
this.dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.dataGridView.MultiSelect = false;
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.ReadOnly = true;
|
||||||
|
this.dataGridView.RowHeadersVisible = false;
|
||||||
|
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(350, 312);
|
||||||
|
this.dataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// FormComponents
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(464, 312);
|
||||||
|
this.Controls.Add(this.buttonRef);
|
||||||
|
this.Controls.Add(this.buttonDel);
|
||||||
|
this.Controls.Add(this.buttonUpd);
|
||||||
|
this.Controls.Add(this.buttonAdd);
|
||||||
|
this.Controls.Add(this.dataGridView);
|
||||||
|
this.Name = "FormComponents";
|
||||||
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
|
this.Text = "Компоненты";
|
||||||
|
this.Load += new System.EventHandler(this.FormComponents_Load);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Button buttonRef;
|
||||||
|
private System.Windows.Forms.Button buttonDel;
|
||||||
|
private System.Windows.Forms.Button buttonUpd;
|
||||||
|
private System.Windows.Forms.Button buttonAdd;
|
||||||
|
private System.Windows.Forms.DataGridView dataGridView;
|
||||||
|
}
|
||||||
|
}
|
120
AbstractShop/AbstractShopView/FormComponents.resx
Normal file
120
AbstractShop/AbstractShopView/FormComponents.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
102
AbstractShop/AbstractShopView/FormCreateOrder.cs
Normal file
102
AbstractShop/AbstractShopView/FormCreateOrder.cs
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.BusinessLogicsContracts;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace AbstractShopView
|
||||||
|
{
|
||||||
|
public partial class FormCreateOrder : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly IProductLogic _logicP;
|
||||||
|
|
||||||
|
private readonly IOrderLogic _logicO;
|
||||||
|
|
||||||
|
public FormCreateOrder(ILogger<FormCreateOrder> logger, IProductLogic logicP, IOrderLogic logicO)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicP = logicP;
|
||||||
|
_logicO = logicO;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormCreateOrder_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка изделий для заказа");
|
||||||
|
// прописать логику
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CalcSum()
|
||||||
|
{
|
||||||
|
if (comboBoxProduct.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(comboBoxProduct.SelectedValue);
|
||||||
|
var product = _logicP.ReadElement(new ProductSearchModel { Id = id });
|
||||||
|
int count = Convert.ToInt32(textBoxCount.Text);
|
||||||
|
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
|
||||||
|
_logger.LogInformation("Расчет суммы заказа");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка расчета суммы заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TextBoxCount_TextChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CalcSum();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ComboBoxProduct_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CalcSum();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxProduct.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Создание заказа");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
ProductId = Convert.ToInt32(comboBoxProduct.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, "Ошибка создания заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
146
AbstractShop/AbstractShopView/FormCreateOrder.designer.cs
generated
Normal file
146
AbstractShop/AbstractShopView/FormCreateOrder.designer.cs
generated
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
namespace AbstractShopView
|
||||||
|
{
|
||||||
|
partial class FormCreateOrder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.labelCount = new System.Windows.Forms.Label();
|
||||||
|
this.comboBoxProduct = new System.Windows.Forms.ComboBox();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||||
|
this.labelProduct = new System.Windows.Forms.Label();
|
||||||
|
this.labelSum = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxSum = new System.Windows.Forms.TextBox();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
this.labelCount.AutoSize = true;
|
||||||
|
this.labelCount.Location = new System.Drawing.Point(12, 36);
|
||||||
|
this.labelCount.Name = "labelCount";
|
||||||
|
this.labelCount.Size = new System.Drawing.Size(69, 13);
|
||||||
|
this.labelCount.TabIndex = 2;
|
||||||
|
this.labelCount.Text = "Количество:";
|
||||||
|
//
|
||||||
|
// comboBoxProduct
|
||||||
|
//
|
||||||
|
this.comboBoxProduct.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBoxProduct.FormattingEnabled = true;
|
||||||
|
this.comboBoxProduct.Location = new System.Drawing.Point(87, 6);
|
||||||
|
this.comboBoxProduct.Name = "comboBoxProduct";
|
||||||
|
this.comboBoxProduct.Size = new System.Drawing.Size(217, 21);
|
||||||
|
this.comboBoxProduct.TabIndex = 1;
|
||||||
|
this.comboBoxProduct.SelectedIndexChanged += new System.EventHandler(this.ComboBoxProduct_SelectedIndexChanged);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(219, 85);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonCancel.TabIndex = 7;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(138, 85);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonSave.TabIndex = 6;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
this.textBoxCount.Location = new System.Drawing.Point(87, 33);
|
||||||
|
this.textBoxCount.Name = "textBoxCount";
|
||||||
|
this.textBoxCount.Size = new System.Drawing.Size(217, 20);
|
||||||
|
this.textBoxCount.TabIndex = 3;
|
||||||
|
this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
|
||||||
|
//
|
||||||
|
// labelProduct
|
||||||
|
//
|
||||||
|
this.labelProduct.AutoSize = true;
|
||||||
|
this.labelProduct.Location = new System.Drawing.Point(12, 9);
|
||||||
|
this.labelProduct.Name = "labelProduct";
|
||||||
|
this.labelProduct.Size = new System.Drawing.Size(54, 13);
|
||||||
|
this.labelProduct.TabIndex = 0;
|
||||||
|
this.labelProduct.Text = "Изделие:";
|
||||||
|
//
|
||||||
|
// labelSum
|
||||||
|
//
|
||||||
|
this.labelSum.AutoSize = true;
|
||||||
|
this.labelSum.Location = new System.Drawing.Point(12, 62);
|
||||||
|
this.labelSum.Name = "labelSum";
|
||||||
|
this.labelSum.Size = new System.Drawing.Size(44, 13);
|
||||||
|
this.labelSum.TabIndex = 4;
|
||||||
|
this.labelSum.Text = "Сумма:";
|
||||||
|
//
|
||||||
|
// textBoxSum
|
||||||
|
//
|
||||||
|
this.textBoxSum.Location = new System.Drawing.Point(87, 59);
|
||||||
|
this.textBoxSum.Name = "textBoxSum";
|
||||||
|
this.textBoxSum.ReadOnly = true;
|
||||||
|
this.textBoxSum.Size = new System.Drawing.Size(217, 20);
|
||||||
|
this.textBoxSum.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// FormCreateOrder
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(318, 118);
|
||||||
|
this.Controls.Add(this.labelSum);
|
||||||
|
this.Controls.Add(this.textBoxSum);
|
||||||
|
this.Controls.Add(this.labelCount);
|
||||||
|
this.Controls.Add(this.comboBoxProduct);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.textBoxCount);
|
||||||
|
this.Controls.Add(this.labelProduct);
|
||||||
|
this.Name = "FormCreateOrder";
|
||||||
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
|
this.Text = "Заказ";
|
||||||
|
this.Load += new System.EventHandler(this.FormCreateOrder_Load);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
private System.Windows.Forms.Label labelCount;
|
||||||
|
private System.Windows.Forms.ComboBox comboBoxProduct;
|
||||||
|
private System.Windows.Forms.Button buttonCancel;
|
||||||
|
private System.Windows.Forms.Button buttonSave;
|
||||||
|
private System.Windows.Forms.TextBox textBoxCount;
|
||||||
|
private System.Windows.Forms.Label labelProduct;
|
||||||
|
private System.Windows.Forms.Label labelSum;
|
||||||
|
private System.Windows.Forms.TextBox textBoxSum;
|
||||||
|
}
|
||||||
|
}
|
120
AbstractShop/AbstractShopView/FormCreateOrder.resx
Normal file
120
AbstractShop/AbstractShopView/FormCreateOrder.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
130
AbstractShop/AbstractShopView/FormMain.cs
Normal file
130
AbstractShop/AbstractShopView/FormMain.cs
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace AbstractShopView
|
||||||
|
{
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка заказов");
|
||||||
|
// прописать логику
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
// прописать логику
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ButtonRef_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
198
AbstractShop/AbstractShopView/FormMain.designer.cs
generated
Normal file
198
AbstractShop/AbstractShopView/FormMain.designer.cs
generated
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
namespace AbstractShopView
|
||||||
|
{
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||||
|
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
this.buttonIssuedOrder = new System.Windows.Forms.Button();
|
||||||
|
this.buttonOrderReady = new System.Windows.Forms.Button();
|
||||||
|
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCreateOrder = new System.Windows.Forms.Button();
|
||||||
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.buttonRef = new System.Windows.Forms.Button();
|
||||||
|
this.menuStrip1.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// menuStrip1
|
||||||
|
//
|
||||||
|
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.справочникиToolStripMenuItem});
|
||||||
|
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.menuStrip1.Name = "menuStrip1";
|
||||||
|
this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2);
|
||||||
|
this.menuStrip1.Size = new System.Drawing.Size(1031, 24);
|
||||||
|
this.menuStrip1.TabIndex = 0;
|
||||||
|
this.menuStrip1.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// справочникиToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.компонентыToolStripMenuItem,
|
||||||
|
this.изделияToolStripMenuItem});
|
||||||
|
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||||
|
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
|
||||||
|
this.справочникиToolStripMenuItem.Text = "Справочники";
|
||||||
|
//
|
||||||
|
// компонентыToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
||||||
|
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
|
||||||
|
this.компонентыToolStripMenuItem.Text = "Компоненты";
|
||||||
|
this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// изделияToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
|
||||||
|
this.изделияToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
|
||||||
|
this.изделияToolStripMenuItem.Text = "Изделия";
|
||||||
|
this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
|
// buttonIssuedOrder
|
||||||
|
//
|
||||||
|
this.buttonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonIssuedOrder.Location = new System.Drawing.Point(844, 231);
|
||||||
|
this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
|
||||||
|
this.buttonIssuedOrder.Size = new System.Drawing.Size(174, 27);
|
||||||
|
this.buttonIssuedOrder.TabIndex = 4;
|
||||||
|
this.buttonIssuedOrder.Text = "Заказ выдан";
|
||||||
|
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
|
||||||
|
//
|
||||||
|
// buttonOrderReady
|
||||||
|
//
|
||||||
|
this.buttonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonOrderReady.Location = new System.Drawing.Point(844, 171);
|
||||||
|
this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.buttonOrderReady.Name = "buttonOrderReady";
|
||||||
|
this.buttonOrderReady.Size = new System.Drawing.Size(174, 27);
|
||||||
|
this.buttonOrderReady.TabIndex = 3;
|
||||||
|
this.buttonOrderReady.Text = "Заказ готов";
|
||||||
|
this.buttonOrderReady.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
|
||||||
|
//
|
||||||
|
// buttonTakeOrderInWork
|
||||||
|
//
|
||||||
|
this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(844, 117);
|
||||||
|
this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
||||||
|
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(174, 27);
|
||||||
|
this.buttonTakeOrderInWork.TabIndex = 2;
|
||||||
|
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
||||||
|
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
|
||||||
|
//
|
||||||
|
// buttonCreateOrder
|
||||||
|
//
|
||||||
|
this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonCreateOrder.Location = new System.Drawing.Point(844, 58);
|
||||||
|
this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.buttonCreateOrder.Name = "buttonCreateOrder";
|
||||||
|
this.buttonCreateOrder.Size = new System.Drawing.Size(174, 27);
|
||||||
|
this.buttonCreateOrder.TabIndex = 1;
|
||||||
|
this.buttonCreateOrder.Text = "Создать заказ";
|
||||||
|
this.buttonCreateOrder.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.AllowUserToAddRows = false;
|
||||||
|
this.dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||||
|
| System.Windows.Forms.AnchorStyles.Left)
|
||||||
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(0, 28);
|
||||||
|
this.dataGridView.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.dataGridView.MultiSelect = false;
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.ReadOnly = true;
|
||||||
|
this.dataGridView.RowHeadersVisible = false;
|
||||||
|
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(826, 320);
|
||||||
|
this.dataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// buttonRef
|
||||||
|
//
|
||||||
|
this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.buttonRef.Location = new System.Drawing.Point(844, 290);
|
||||||
|
this.buttonRef.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.buttonRef.Name = "buttonRef";
|
||||||
|
this.buttonRef.Size = new System.Drawing.Size(174, 27);
|
||||||
|
this.buttonRef.TabIndex = 5;
|
||||||
|
this.buttonRef.Text = "Обновить список";
|
||||||
|
this.buttonRef.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||||
|
//
|
||||||
|
// FormMain
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(1031, 347);
|
||||||
|
this.Controls.Add(this.buttonRef);
|
||||||
|
this.Controls.Add(this.buttonIssuedOrder);
|
||||||
|
this.Controls.Add(this.buttonOrderReady);
|
||||||
|
this.Controls.Add(this.buttonTakeOrderInWork);
|
||||||
|
this.Controls.Add(this.buttonCreateOrder);
|
||||||
|
this.Controls.Add(this.dataGridView);
|
||||||
|
this.Controls.Add(this.menuStrip1);
|
||||||
|
this.MainMenuStrip = this.menuStrip1;
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.Name = "FormMain";
|
||||||
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
|
this.Text = "Абстрактный магазин";
|
||||||
|
this.Load += new System.EventHandler(this.FormMain_Load);
|
||||||
|
this.menuStrip1.ResumeLayout(false);
|
||||||
|
this.menuStrip1.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.MenuStrip menuStrip1;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem справочникиToolStripMenuItem;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem компонентыToolStripMenuItem;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem изделияToolStripMenuItem;
|
||||||
|
private System.Windows.Forms.Button buttonIssuedOrder;
|
||||||
|
private System.Windows.Forms.Button buttonOrderReady;
|
||||||
|
private System.Windows.Forms.Button buttonTakeOrderInWork;
|
||||||
|
private System.Windows.Forms.Button buttonCreateOrder;
|
||||||
|
private System.Windows.Forms.DataGridView dataGridView;
|
||||||
|
private System.Windows.Forms.Button buttonRef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
120
AbstractShop/AbstractShopView/FormMain.resx
Normal file
120
AbstractShop/AbstractShopView/FormMain.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
208
AbstractShop/AbstractShopView/FormProduct.cs
Normal file
208
AbstractShop/AbstractShopView/FormProduct.cs
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
using AbstractShopContracts.BindingModels;
|
||||||
|
using AbstractShopContracts.BusinessLogicsContracts;
|
||||||
|
using AbstractShopContracts.SearchModels;
|
||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace AbstractShopView
|
||||||
|
{
|
||||||
|
public partial class FormProduct : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly IProductLogic _logic;
|
||||||
|
|
||||||
|
private int? _id;
|
||||||
|
|
||||||
|
private Dictionary<int, (IComponentModel, int)> _productComponents;
|
||||||
|
|
||||||
|
public int Id { set { _id = value; } }
|
||||||
|
|
||||||
|
public FormProduct(ILogger<FormProduct> logger, IProductLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
_productComponents = new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormProduct_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_id.HasValue)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var view = _logic.ReadElement(new ProductSearchModel { Id = _id.Value });
|
||||||
|
if (view != null)
|
||||||
|
{
|
||||||
|
textBoxName.Text = view.ProductName;
|
||||||
|
textBoxPrice.Text = view.Price.ToString();
|
||||||
|
_productComponents = view.ProductComponents ?? new Dictionary<int, (IComponentModel, int)>();
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Загрузка компонент изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_productComponents != null)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Clear();
|
||||||
|
foreach (var pc in _productComponents)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
|
||||||
|
}
|
||||||
|
textBoxPrice.Text = CalcPrice().ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки компонент изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormProductComponent));
|
||||||
|
if (service is FormProductComponent form)
|
||||||
|
{
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (form.ComponentModel == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
|
||||||
|
if (_productComponents.ContainsKey(form.Id))
|
||||||
|
{
|
||||||
|
_productComponents[form.Id] = (form.ComponentModel, form.Count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_productComponents.Add(form.Id, (form.ComponentModel, form.Count));
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormProductComponent));
|
||||||
|
if (service is FormProductComponent form)
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
||||||
|
form.Id = id;
|
||||||
|
form.Count = _productComponents[id].Item2;
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (form.ComponentModel == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
|
||||||
|
_productComponents[form.Id] = (form.ComponentModel, form.Count);
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Удаление компонента: {ComponentName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value);
|
||||||
|
_productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRef_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(textBoxPrice.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_productComponents == null || _productComponents.Count == 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Сохранение изделия");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var model = new ProductBindingModel
|
||||||
|
{
|
||||||
|
Id = _id ?? 0,
|
||||||
|
ProductName = textBoxName.Text,
|
||||||
|
Price = Convert.ToDouble(textBoxPrice.Text),
|
||||||
|
ProductComponents = _productComponents
|
||||||
|
};
|
||||||
|
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка сохранения изделия");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private double CalcPrice()
|
||||||
|
{
|
||||||
|
double price = 0;
|
||||||
|
foreach (var elem in _productComponents)
|
||||||
|
{
|
||||||
|
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
|
||||||
|
}
|
||||||
|
return Math.Round(price * 1.1, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
252
AbstractShop/AbstractShopView/FormProduct.designer.cs
generated
Normal file
252
AbstractShop/AbstractShopView/FormProduct.designer.cs
generated
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
namespace AbstractShopView
|
||||||
|
{
|
||||||
|
partial class FormProduct
|
||||||
|
{
|
||||||
|
/// <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.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||||
|
this.labelName = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxPrice = new System.Windows.Forms.TextBox();
|
||||||
|
this.labelPrice = new System.Windows.Forms.Label();
|
||||||
|
this.groupBoxComponents = new System.Windows.Forms.GroupBox();
|
||||||
|
this.buttonRef = new System.Windows.Forms.Button();
|
||||||
|
this.buttonDel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonUpd = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
|
this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
|
this.groupBoxComponents.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(455, 362);
|
||||||
|
this.buttonCancel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(88, 27);
|
||||||
|
this.buttonCancel.TabIndex = 6;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(360, 362);
|
||||||
|
this.buttonSave.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(88, 27);
|
||||||
|
this.buttonSave.TabIndex = 5;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
this.textBoxName.Location = new System.Drawing.Point(92, 7);
|
||||||
|
this.textBoxName.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.textBoxName.Name = "textBoxName";
|
||||||
|
this.textBoxName.Size = new System.Drawing.Size(252, 23);
|
||||||
|
this.textBoxName.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelName
|
||||||
|
//
|
||||||
|
this.labelName.AutoSize = true;
|
||||||
|
this.labelName.Location = new System.Drawing.Point(14, 10);
|
||||||
|
this.labelName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.labelName.Name = "labelName";
|
||||||
|
this.labelName.Size = new System.Drawing.Size(62, 15);
|
||||||
|
this.labelName.TabIndex = 0;
|
||||||
|
this.labelName.Text = "Название:";
|
||||||
|
//
|
||||||
|
// textBoxPrice
|
||||||
|
//
|
||||||
|
this.textBoxPrice.Enabled = false;
|
||||||
|
this.textBoxPrice.Location = new System.Drawing.Point(92, 37);
|
||||||
|
this.textBoxPrice.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.textBoxPrice.Name = "textBoxPrice";
|
||||||
|
this.textBoxPrice.Size = new System.Drawing.Size(147, 23);
|
||||||
|
this.textBoxPrice.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// labelPrice
|
||||||
|
//
|
||||||
|
this.labelPrice.AutoSize = true;
|
||||||
|
this.labelPrice.Location = new System.Drawing.Point(14, 40);
|
||||||
|
this.labelPrice.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||||
|
this.labelPrice.Name = "labelPrice";
|
||||||
|
this.labelPrice.Size = new System.Drawing.Size(70, 15);
|
||||||
|
this.labelPrice.TabIndex = 2;
|
||||||
|
this.labelPrice.Text = "Стоимость:";
|
||||||
|
//
|
||||||
|
// groupBoxComponents
|
||||||
|
//
|
||||||
|
this.groupBoxComponents.Controls.Add(this.buttonRef);
|
||||||
|
this.groupBoxComponents.Controls.Add(this.buttonDel);
|
||||||
|
this.groupBoxComponents.Controls.Add(this.buttonUpd);
|
||||||
|
this.groupBoxComponents.Controls.Add(this.buttonAdd);
|
||||||
|
this.groupBoxComponents.Controls.Add(this.dataGridView);
|
||||||
|
this.groupBoxComponents.Location = new System.Drawing.Point(14, 67);
|
||||||
|
this.groupBoxComponents.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.groupBoxComponents.Name = "groupBoxComponents";
|
||||||
|
this.groupBoxComponents.Padding = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.groupBoxComponents.Size = new System.Drawing.Size(558, 288);
|
||||||
|
this.groupBoxComponents.TabIndex = 4;
|
||||||
|
this.groupBoxComponents.TabStop = false;
|
||||||
|
this.groupBoxComponents.Text = "Компоненты";
|
||||||
|
//
|
||||||
|
// buttonRef
|
||||||
|
//
|
||||||
|
this.buttonRef.Location = new System.Drawing.Point(441, 171);
|
||||||
|
this.buttonRef.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.buttonRef.Name = "buttonRef";
|
||||||
|
this.buttonRef.Size = new System.Drawing.Size(88, 27);
|
||||||
|
this.buttonRef.TabIndex = 4;
|
||||||
|
this.buttonRef.Text = "Обновить";
|
||||||
|
this.buttonRef.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
this.buttonDel.Location = new System.Drawing.Point(441, 123);
|
||||||
|
this.buttonDel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.buttonDel.Name = "buttonDel";
|
||||||
|
this.buttonDel.Size = new System.Drawing.Size(88, 27);
|
||||||
|
this.buttonDel.TabIndex = 3;
|
||||||
|
this.buttonDel.Text = "Удалить";
|
||||||
|
this.buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||||
|
//
|
||||||
|
// buttonUpd
|
||||||
|
//
|
||||||
|
this.buttonUpd.Location = new System.Drawing.Point(441, 76);
|
||||||
|
this.buttonUpd.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.buttonUpd.Name = "buttonUpd";
|
||||||
|
this.buttonUpd.Size = new System.Drawing.Size(88, 27);
|
||||||
|
this.buttonUpd.TabIndex = 2;
|
||||||
|
this.buttonUpd.Text = "Изменить";
|
||||||
|
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||||
|
//
|
||||||
|
// buttonAdd
|
||||||
|
//
|
||||||
|
this.buttonAdd.Location = new System.Drawing.Point(441, 32);
|
||||||
|
this.buttonAdd.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
|
this.buttonAdd.Size = new System.Drawing.Size(88, 27);
|
||||||
|
this.buttonAdd.TabIndex = 1;
|
||||||
|
this.buttonAdd.Text = "Добавить";
|
||||||
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
this.dataGridView.AllowUserToAddRows = false;
|
||||||
|
this.dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
|
||||||
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||||
|
this.ColumnId,
|
||||||
|
this.ColumnName,
|
||||||
|
this.ColumnCount});
|
||||||
|
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
|
||||||
|
this.dataGridView.Location = new System.Drawing.Point(4, 19);
|
||||||
|
this.dataGridView.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.dataGridView.MultiSelect = false;
|
||||||
|
this.dataGridView.Name = "dataGridView";
|
||||||
|
this.dataGridView.ReadOnly = true;
|
||||||
|
this.dataGridView.RowHeadersVisible = false;
|
||||||
|
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
this.dataGridView.Size = new System.Drawing.Size(408, 266);
|
||||||
|
this.dataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// ColumnId
|
||||||
|
//
|
||||||
|
this.ColumnId.HeaderText = "Id";
|
||||||
|
this.ColumnId.Name = "ColumnId";
|
||||||
|
this.ColumnId.ReadOnly = true;
|
||||||
|
this.ColumnId.Visible = false;
|
||||||
|
//
|
||||||
|
// ColumnName
|
||||||
|
//
|
||||||
|
this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
this.ColumnName.HeaderText = "Компонент";
|
||||||
|
this.ColumnName.Name = "ColumnName";
|
||||||
|
this.ColumnName.ReadOnly = true;
|
||||||
|
//
|
||||||
|
// ColumnCount
|
||||||
|
//
|
||||||
|
this.ColumnCount.HeaderText = "Количество";
|
||||||
|
this.ColumnCount.Name = "ColumnCount";
|
||||||
|
this.ColumnCount.ReadOnly = true;
|
||||||
|
//
|
||||||
|
// FormProduct
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(586, 402);
|
||||||
|
this.Controls.Add(this.groupBoxComponents);
|
||||||
|
this.Controls.Add(this.textBoxPrice);
|
||||||
|
this.Controls.Add(this.labelPrice);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.textBoxName);
|
||||||
|
this.Controls.Add(this.labelName);
|
||||||
|
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||||
|
this.Name = "FormProduct";
|
||||||
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
|
this.Text = "Изделие";
|
||||||
|
this.Load += new System.EventHandler(this.FormProduct_Load);
|
||||||
|
this.groupBoxComponents.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Button buttonCancel;
|
||||||
|
private System.Windows.Forms.Button buttonSave;
|
||||||
|
private System.Windows.Forms.TextBox textBoxName;
|
||||||
|
private System.Windows.Forms.Label labelName;
|
||||||
|
private System.Windows.Forms.TextBox textBoxPrice;
|
||||||
|
private System.Windows.Forms.Label labelPrice;
|
||||||
|
private System.Windows.Forms.GroupBox groupBoxComponents;
|
||||||
|
private System.Windows.Forms.Button buttonRef;
|
||||||
|
private System.Windows.Forms.Button buttonDel;
|
||||||
|
private System.Windows.Forms.Button buttonUpd;
|
||||||
|
private System.Windows.Forms.Button buttonAdd;
|
||||||
|
private System.Windows.Forms.DataGridView dataGridView;
|
||||||
|
private System.Windows.Forms.DataGridViewTextBoxColumn ColumnId;
|
||||||
|
private System.Windows.Forms.DataGridViewTextBoxColumn ColumnName;
|
||||||
|
private System.Windows.Forms.DataGridViewTextBoxColumn ColumnCount;
|
||||||
|
}
|
||||||
|
}
|
120
AbstractShop/AbstractShopView/FormProduct.resx
Normal file
120
AbstractShop/AbstractShopView/FormProduct.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
71
AbstractShop/AbstractShopView/FormProductComponent.cs
Normal file
71
AbstractShop/AbstractShopView/FormProductComponent.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
using AbstractShopContracts.BusinessLogicsContracts;
|
||||||
|
using AbstractShopContracts.ViewModels;
|
||||||
|
using AbstractShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace AbstractShopView
|
||||||
|
{
|
||||||
|
public partial class FormProductComponent : 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 FormProductComponent(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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
121
AbstractShop/AbstractShopView/FormProductComponent.designer.cs
generated
Normal file
121
AbstractShop/AbstractShopView/FormProductComponent.designer.cs
generated
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
namespace AbstractShopView
|
||||||
|
{
|
||||||
|
partial class FormProductComponent
|
||||||
|
{
|
||||||
|
/// <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.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.buttonSave = new System.Windows.Forms.Button();
|
||||||
|
this.labelComponent = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||||
|
this.comboBoxComponent = new System.Windows.Forms.ComboBox();
|
||||||
|
this.labelCount = new System.Windows.Forms.Label();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(218, 59);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonCancel.TabIndex = 5;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// buttonSave
|
||||||
|
//
|
||||||
|
this.buttonSave.Location = new System.Drawing.Point(137, 59);
|
||||||
|
this.buttonSave.Name = "buttonSave";
|
||||||
|
this.buttonSave.Size = new System.Drawing.Size(75, 23);
|
||||||
|
this.buttonSave.TabIndex = 4;
|
||||||
|
this.buttonSave.Text = "Сохранить";
|
||||||
|
this.buttonSave.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||||
|
//
|
||||||
|
// labelComponent
|
||||||
|
//
|
||||||
|
this.labelComponent.AutoSize = true;
|
||||||
|
this.labelComponent.Location = new System.Drawing.Point(12, 9);
|
||||||
|
this.labelComponent.Name = "labelComponent";
|
||||||
|
this.labelComponent.Size = new System.Drawing.Size(66, 13);
|
||||||
|
this.labelComponent.TabIndex = 0;
|
||||||
|
this.labelComponent.Text = "Компонент:";
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
this.textBoxCount.Location = new System.Drawing.Point(87, 33);
|
||||||
|
this.textBoxCount.Name = "textBoxCount";
|
||||||
|
this.textBoxCount.Size = new System.Drawing.Size(217, 20);
|
||||||
|
this.textBoxCount.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// comboBoxComponent
|
||||||
|
//
|
||||||
|
this.comboBoxComponent.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.comboBoxComponent.FormattingEnabled = true;
|
||||||
|
this.comboBoxComponent.Location = new System.Drawing.Point(87, 6);
|
||||||
|
this.comboBoxComponent.Name = "comboBoxComponent";
|
||||||
|
this.comboBoxComponent.Size = new System.Drawing.Size(217, 21);
|
||||||
|
this.comboBoxComponent.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
this.labelCount.AutoSize = true;
|
||||||
|
this.labelCount.Location = new System.Drawing.Point(12, 36);
|
||||||
|
this.labelCount.Name = "labelCount";
|
||||||
|
this.labelCount.Size = new System.Drawing.Size(69, 13);
|
||||||
|
this.labelCount.TabIndex = 2;
|
||||||
|
this.labelCount.Text = "Количество:";
|
||||||
|
//
|
||||||
|
// FormProductComponent
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(320, 96);
|
||||||
|
this.Controls.Add(this.labelCount);
|
||||||
|
this.Controls.Add(this.comboBoxComponent);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSave);
|
||||||
|
this.Controls.Add(this.textBoxCount);
|
||||||
|
this.Controls.Add(this.labelComponent);
|
||||||
|
this.Name = "FormProductComponent";
|
||||||
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
|
this.Text = "Компонент изделия";
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.Button buttonCancel;
|
||||||
|
private System.Windows.Forms.Button buttonSave;
|
||||||
|
private System.Windows.Forms.Label labelComponent;
|
||||||
|
private System.Windows.Forms.TextBox textBoxCount;
|
||||||
|
private System.Windows.Forms.ComboBox comboBoxComponent;
|
||||||
|
private System.Windows.Forms.Label labelCount;
|
||||||
|
}
|
||||||
|
}
|
120
AbstractShop/AbstractShopView/FormProductComponent.resx
Normal file
120
AbstractShop/AbstractShopView/FormProductComponent.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?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,7 +1,18 @@
|
|||||||
|
using AbstractShopBusinessLogic.BusinessLogics;
|
||||||
|
using AbstractShopContracts.BusinessLogicsContracts;
|
||||||
|
using AbstractShopContracts.StoragesContracts;
|
||||||
|
using AbstractShopDatabaseImplement.Implements;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
|
||||||
namespace AbstractShopView
|
namespace AbstractShopView
|
||||||
{
|
{
|
||||||
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>
|
||||||
@ -11,7 +22,30 @@ namespace AbstractShopView
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new Form1());
|
// Application.Run(new Form1());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
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<IProductStorage, ProductStorage>();
|
||||||
|
|
||||||
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
|
services.AddTransient<IProductLogic, ProductLogic>();
|
||||||
|
|
||||||
|
services.AddTransient<FormMain>();
|
||||||
|
services.AddTransient<FormComponent>();
|
||||||
|
services.AddTransient<FormComponents>();
|
||||||
|
services.AddTransient<FormCreateOrder>();
|
||||||
|
services.AddTransient<FormProduct>();
|
||||||
|
services.AddTransient<FormProductComponent>();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
15
AbstractShop/AbstractShopView/nlog.config
Normal file
15
AbstractShop/AbstractShopView/nlog.config
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
autoReload="true" internalLogLevel="Info">
|
||||||
|
|
||||||
|
<targets>
|
||||||
|
<target xsi:type="File" name="tofile" fileName="log-${shortdate}.log" />
|
||||||
|
</targets>
|
||||||
|
|
||||||
|
<rules>
|
||||||
|
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
||||||
|
</rules>
|
||||||
|
</nlog>
|
||||||
|
</configuration>
|
Loading…
Reference in New Issue
Block a user