3 Commits

Author SHA1 Message Date
40ad8979c5 Done 2024-03-16 20:18:37 +04:00
a8a93a1f82 почти 2024-03-05 12:53:08 +04:00
3ca588732e Done 2024-03-04 19:15:57 +04:00
66 changed files with 524 additions and 3638 deletions

View File

@@ -3,7 +3,6 @@ using DinerContracts.BusinessLogicsContracts;
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using DinerDataModels.Models;
using DinerDataModels.Enum;
using Microsoft.Extensions.Logging;
@@ -13,15 +12,10 @@ namespace DinerBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
private readonly IShopStorage _shopStorage;
private readonly IShopLogic _shopLogic;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage)
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_orderStorage = orderStorage;
_logger = logger;
_shopStorage = shopStorage;
_orderStorage = orderStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
@@ -35,7 +29,6 @@ namespace DinerBusinessLogic.BusinessLogics
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
@@ -48,7 +41,6 @@ namespace DinerBusinessLogic.BusinessLogics
}
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return ChangeStatus(model, OrderStatus.Выполняется);
@@ -59,25 +51,8 @@ namespace DinerBusinessLogic.BusinessLogics
}
public bool DeliveryOrder(OrderBindingModel model)
{
var order = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id,
});
if (order == null)
{
throw new ArgumentNullException(nameof(order));
}
if (!_shopStorage.RestockingShops(new SupplyBindingModel
{
SnackId = order.SnackId,
Count = order.Count
}))
{
throw new ArgumentException("Недостаточно места");
}
return ChangeStatus(model, OrderStatus.Выдан);
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)

View File

@@ -1,185 +0,0 @@
using Microsoft.Extensions.Logging;
using DinerContracts.BindingModels;
using DinerContracts.BusinessLogicsContracts;
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DinerListImplement.Implements;
namespace DinerBusinessLogic.BusinessLogics
{
public class ShopLogic : IShopLogic
{
private readonly ILogger _logger;
private readonly IShopStorage _shopStorage;
private readonly ISnackStorage _snackStorage;
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage, ISnackStorage snackStorage)
{
_logger = logger;
_shopStorage = shopStorage;
_snackStorage = snackStorage;
}
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
{
_logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id);
var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ShopViewModel? ReadElement(ShopSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
var element = _shopStorage.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(ShopBindingModel model)
{
CheckModel(model);
if (_shopStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ShopBindingModel model)
{
CheckModel(model);
if (_shopStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ShopBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_shopStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool MakeSupply(SupplyBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (model.Count <= 0)
{
throw new ArgumentException("Количество изделий должно быть больше 0");
}
var shop = _shopStorage.GetElement(new ShopSearchModel
{
Id = model.ShopId
});
if (shop == null)
{
throw new ArgumentException("Магазина не существует");
}
if (shop.ShopSnacks.ContainsKey(model.SnackId))
{
var oldValue = shop.ShopSnacks[model.SnackId];
oldValue.Item2 += model.Count;
shop.ShopSnacks[model.SnackId] = oldValue;
}
else
{
var snack = _snackStorage.GetElement(new SnackSearchModel
{
Id = model.SnackId
});
if (snack == null)
{
throw new ArgumentException($"Поставка: Товар с id:{model.SnackId} не найденн");
}
shop.ShopSnacks.Add(model.SnackId, (snack, model.Count));
}
_shopStorage.Update(new ShopBindingModel()
{
Id = shop.Id,
ShopName = shop.ShopName,
Adress = shop.Adress,
OpeningDate = shop.OpeningDate,
ShopSnacks = shop.ShopSnacks,
SnackMaxCount = shop.SnackMaxCount,
});
return true;
}
private void CheckModel(ShopBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Adress))
{
throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress));
}
if (string.IsNullOrEmpty(model.ShopName))
{
throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName));
}
_logger.LogInformation("Shop. ShopName:{ShopName}.Adres:{Adres}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id);
var element = _shopStorage.GetElement(new ShopSearchModel
{
ShopName = model.ShopName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
public bool Sale(SupplySearchModel model)
{
if (!model.SnackId.HasValue || !model.Count.HasValue)
{
return false;
}
_logger.LogInformation("Check snack count in all shops");
if (_shopStorage.Sale(model))
{
_logger.LogInformation("Selling sucsess");
return true;
}
_logger.LogInformation("Selling failed");
return false;
}
}
}

View File

@@ -7,12 +7,17 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AbstractShopContracts\DinerContracts.csproj" />
<ProjectReference Include="..\Diner\AbstractShopListImplement\DinerListImplement.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,19 +0,0 @@
using DinerDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.BindingModels
{
public class ShopBindingModel : IShopModel
{
public int Id { get; set; }
public string ShopName { get; set; } = string.Empty;
public string Adress { get; set; } = string.Empty;
public DateTime OpeningDate { get; set; } = DateTime.Now;
public Dictionary<int, (ISnackModel, int)> ShopSnacks { get; set; } = new();
public int SnackMaxCount { get; set; }
}
}

View File

@@ -1,16 +0,0 @@
using DinerDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.BindingModels
{
public class SupplyBindingModel : ISupplyModel
{
public int ShopId { get; set; }
public int SnackId { get; set; }
public int Count { get; set; }
}
}

View File

@@ -1,22 +0,0 @@
using DinerContracts.BindingModels;
using DinerContracts.SearchModels;
using DinerContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.BusinessLogicsContracts
{
public interface IShopLogic
{
List<ShopViewModel>? ReadList(ShopSearchModel? model);
ShopViewModel? ReadElement(ShopSearchModel model);
bool Create(ShopBindingModel model);
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool MakeSupply(SupplyBindingModel model);
bool Sale(SupplySearchModel model);
}
}

View File

@@ -6,6 +6,15 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AbstractShopDataModels\DinerDataModels.csproj" />
</ItemGroup>

View File

@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.SearchModels
{
public class ShopSearchModel
{
public int? Id { get; set; }
public string? ShopName { get; set; }
}
}

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.SearchModels
{
public class SupplySearchModel
{
public int? SnackId { get; set; }
public int? Count { get; set; }
}
}

View File

@@ -1,23 +0,0 @@
using DinerContracts.BindingModels;
using DinerContracts.SearchModels;
using DinerContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.StoragesContracts
{
public interface IShopStorage
{
List<ShopViewModel> GetFullList();
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
ShopViewModel? GetElement(ShopSearchModel model);
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool Sale(SupplySearchModel model);
bool RestockingShops(SupplyBindingModel model);
}
}

View File

@@ -1,24 +0,0 @@
using DinerDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.ViewModels
{
public class ShopViewModel : IShopModel
{
public int Id { get; set; }
[DisplayName("Название")]
public string ShopName { get; set; } = string.Empty;
[DisplayName("Адрес")]
public string Adress { get; set; } = string.Empty;
[DisplayName("Дата открытия")]
public DateTime OpeningDate { get; set; }
public Dictionary<int, (ISnackModel, int)> ShopSnacks { get; set; } = new();
[DisplayName("Вместимость")]
public int SnackMaxCount { get; set; }
}
}

View File

@@ -6,4 +6,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

View File

@@ -1,19 +0,0 @@
using DinerDataModels;
using DinerDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerDataModels.Models
{
public interface IShopModel : IId
{
string ShopName { get; }
string Adress { get; }
DateTime OpeningDate { get; }
Dictionary<int, (ISnackModel, int)> ShopSnacks { get; }
public int SnackMaxCount { get; }
}
}

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerDataModels.Models
{
public interface ISupplyModel
{
int ShopId { get; }
int SnackId { get; }
int Count { get; }
}
}

View File

@@ -13,13 +13,11 @@ namespace DinerListImplement
public List<Component> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Snack> Products { get; set; }
public List<Shop> Shops { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Products = new List<Snack>();
Shops = new List<Shop>();
}
public static DataListSingleton GetInstance()
{

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@@ -6,6 +6,15 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\AbstractShopContracts\DinerContracts.csproj" />
<ProjectReference Include="..\..\AbstractShopDataModels\DinerDataModels.csproj" />

View File

@@ -1,122 +0,0 @@
using DinerContracts.BindingModels;
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using DinerListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerListImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataListSingleton _source;
public ShopStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<ShopViewModel> GetFullList()
{
var result = new List<ShopViewModel>();
foreach (var shop in _source.Shops)
{
result.Add(shop.GetViewModel);
}
return result;
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
var result = new List<ShopViewModel>();
if (string.IsNullOrEmpty(model.ShopName))
{
return result;
}
foreach (var shop in _source.Shops)
{
if (shop.ShopName.Contains(model.ShopName))
{
result.Add(shop.GetViewModel);
}
}
return result;
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return null;
}
foreach (var shop in _source.Shops)
{
if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) ||
(model.Id.HasValue && shop.Id == model.Id))
{
return shop.GetViewModel;
}
}
return null;
}
public ShopViewModel? Insert(ShopBindingModel model)
{
model.Id = 1;
foreach (var shop in _source.Shops)
{
if (model.Id <= shop.Id)
{
model.Id = shop.Id + 1;
}
}
var newShop = Shop.Create(model);
if (newShop == null)
{
return null;
}
_source.Shops.Add(newShop);
return newShop.GetViewModel;
}
public ShopViewModel? Update(ShopBindingModel model)
{
foreach (var shop in _source.Shops)
{
if (shop.Id == model.Id)
{
shop.Update(model);
return shop.GetViewModel;
}
}
return null;
}
public ShopViewModel? Delete(ShopBindingModel model)
{
for (int i = 0; i < _source.Shops.Count; ++i)
{
if (_source.Shops[i].Id == model.Id)
{
var element = _source.Shops[i];
_source.Shops.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
public bool Sale(SupplySearchModel model)
{
throw new NotImplementedException();
}
public bool RestockingShops(SupplyBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@@ -39,9 +39,14 @@ namespace DinerListImplement.Models
{
return;
}
Id = model.Id;
SnackID = model.SnackId;
SnackName = model.SnackName;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement;
if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{

View File

@@ -1,59 +0,0 @@
using DinerDataModels.Models;
using DinerContracts.BindingModels;
using DinerContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerListImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; private set; }
public string ShopName { get; private set; } = string.Empty;
public string Adress { get; private set; } = string.Empty;
public DateTime OpeningDate { get; private set; }
public Dictionary<int, (ISnackModel, int)> ShopSnacks { get; private set; } = new();
public int SnackMaxCount { get; private set; }
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Adress = model.Adress,
OpeningDate = model.OpeningDate,
SnackMaxCount = model.SnackMaxCount,
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Adress = model.Adress;
OpeningDate = model.OpeningDate;
SnackMaxCount = model.SnackMaxCount;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Adress = Adress,
OpeningDate = OpeningDate,
ShopSnacks = ShopSnacks,
SnackMaxCount = SnackMaxCount,
};
}
}

View File

@@ -13,9 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerBusinessLogic", "..\Ab
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerListImplement", "AbstractShopListImplement\DinerListImplement.csproj", "{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DinerFileImplement", "DinerFileImplement\DinerFileImplement.csproj", "{13294C1E-C8DF-4E4B-B645-A61900A797EB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DinerFileImplement", "DinerFileImplement\DinerFileImplement.csproj", "{BF814E5C-E62C-4BFC-9B14-3D2F97F21CE6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DinerDatabaseImplement", "DinerDatabaseImplements\DinerDatabaseImplement.csproj", "{BE778091-B058-4BDD-8AEE-2773F4E00979}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DinerDataBaseImplement", "DinerDataBaseImplement\DinerDataBaseImplement.csproj", "{3AC09806-4792-4A84-BCB8-87B29E0E1C8A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -43,14 +43,14 @@ Global
{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A24E7474-4B43-4E81-A6BF-2B7323D5C26A}.Release|Any CPU.Build.0 = Release|Any CPU
{13294C1E-C8DF-4E4B-B645-A61900A797EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13294C1E-C8DF-4E4B-B645-A61900A797EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13294C1E-C8DF-4E4B-B645-A61900A797EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13294C1E-C8DF-4E4B-B645-A61900A797EB}.Release|Any CPU.Build.0 = Release|Any CPU
{BE778091-B058-4BDD-8AEE-2773F4E00979}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE778091-B058-4BDD-8AEE-2773F4E00979}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE778091-B058-4BDD-8AEE-2773F4E00979}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE778091-B058-4BDD-8AEE-2773F4E00979}.Release|Any CPU.Build.0 = Release|Any CPU
{BF814E5C-E62C-4BFC-9B14-3D2F97F21CE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF814E5C-E62C-4BFC-9B14-3D2F97F21CE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF814E5C-E62C-4BFC-9B14-3D2F97F21CE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF814E5C-E62C-4BFC-9B14-3D2F97F21CE6}.Release|Any CPU.Build.0 = Release|Any CPU
{3AC09806-4792-4A84-BCB8-87B29E0E1C8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3AC09806-4792-4A84-BCB8-87B29E0E1C8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3AC09806-4792-4A84-BCB8-87B29E0E1C8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3AC09806-4792-4A84-BCB8-87B29E0E1C8A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -9,40 +9,24 @@
</PropertyGroup>
<ItemGroup>
<None Remove="FormSellSnack" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\AbstractShopBusinessLogic\DinerBusinessLogic.csproj" />
<ProjectReference Include="..\..\AbstractShopContracts\DinerContracts.csproj" />
<ProjectReference Include="..\..\AbstractShopDataModels\DinerDataModels.csproj" />
<ProjectReference Include="..\AbstractShopListImplement\DinerListImplement.csproj" />
<ProjectReference Include="..\DinerDatabaseImplements\DinerDatabaseImplement.csproj" />
<ProjectReference Include="..\DinerDataBaseImplement\DinerDataBaseImplement.csproj" />
<ProjectReference Include="..\DinerFileImplement\DinerFileImplement.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@@ -1,142 +0,0 @@
namespace DinerView
{
partial class FormCreateSupply
{
/// <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()
{
comboBoxShop = new ComboBox();
labelShop = new Label();
labelSnack = new Label();
comboBoxSnack = new ComboBox();
labelCount = new Label();
textBoxCount = new TextBox();
buttonCancel = new Button();
buttonSave = new Button();
SuspendLayout();
//
// comboBoxShop
//
comboBoxShop.FormattingEnabled = true;
comboBoxShop.Location = new Point(115, 12);
comboBoxShop.Name = "comboBoxShop";
comboBoxShop.Size = new Size(344, 28);
comboBoxShop.TabIndex = 0;
//
// labelShop
//
labelShop.AutoSize = true;
labelShop.Location = new Point(12, 15);
labelShop.Name = "labelShop";
labelShop.Size = new Size(76, 20);
labelShop.TabIndex = 1;
labelShop.Text = "Магазин: ";
//
// labelSnack
//
labelSnack.AutoSize = true;
labelSnack.Location = new Point(12, 49);
labelSnack.Name = "labelSnack";
labelSnack.Size = new Size(75, 20);
labelSnack.TabIndex = 2;
labelSnack.Text = "Изделие: ";
//
// comboBoxSnack
//
comboBoxSnack.FormattingEnabled = true;
comboBoxSnack.Location = new Point(115, 46);
comboBoxSnack.Name = "comboBoxSnack";
comboBoxSnack.Size = new Size(344, 28);
comboBoxSnack.TabIndex = 3;
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(12, 83);
labelCount.Name = "labelCount";
labelCount.Size = new Size(97, 20);
labelCount.TabIndex = 4;
labelCount.Text = "Количество: ";
//
// textBoxCount
//
textBoxCount.Location = new Point(115, 80);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(344, 27);
textBoxCount.TabIndex = 5;
//
// buttonCancel
//
buttonCancel.Location = new Point(300, 113);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(116, 39);
buttonCancel.TabIndex = 6;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// buttonSave
//
buttonSave.Location = new Point(168, 113);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(116, 39);
buttonSave.TabIndex = 7;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// FormCreateSupply
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(471, 164);
Controls.Add(buttonSave);
Controls.Add(buttonCancel);
Controls.Add(textBoxCount);
Controls.Add(labelCount);
Controls.Add(comboBoxSnack);
Controls.Add(labelSnack);
Controls.Add(labelShop);
Controls.Add(comboBoxShop);
Name = "FormCreateSupply";
Text = "Создание поставки";
Load += FormCreateSupply_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private ComboBox comboBoxShop;
private Label labelShop;
private Label labelSnack;
private ComboBox comboBoxSnack;
private Label labelCount;
private TextBox textBoxCount;
private Button buttonCancel;
private Button buttonSave;
}
}

View File

@@ -1,99 +0,0 @@
using Microsoft.Extensions.Logging;
using DinerContracts.BindingModels;
using DinerContracts.BusinessLogicsContracts;
using DinerContracts.ViewModels;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace DinerView
{
public partial class FormCreateSupply : Form
{
private readonly ILogger _logger;
private readonly ISnackLogic _logicP;
private readonly IShopLogic _logicS;
private List<ShopViewModel> _shopList = new List<ShopViewModel>();
private List<SnackViewModel> _snackList = new List<SnackViewModel>();
public FormCreateSupply(ILogger<FormCreateSupply> logger, ISnackLogic logicP, IShopLogic logicS)
{
InitializeComponent();
_logger = logger;
_logicP = logicP;
_logicS = logicS;
}
private void FormCreateSupply_Load(object sender, EventArgs e)
{
_shopList = _logicS.ReadList(null);
_snackList = _logicP.ReadList(null);
if (_shopList != null)
{
comboBoxShop.DisplayMember = "ShopName";
comboBoxShop.ValueMember = "Id";
comboBoxShop.DataSource = _shopList;
comboBoxShop.SelectedItem = null;
_logger.LogInformation("Загрузка магазинов для поставок");
}
if (_snackList != null)
{
comboBoxSnack.DisplayMember = "SnackName";
comboBoxSnack.ValueMember = "Id";
comboBoxSnack.DataSource = _snackList;
comboBoxSnack.SelectedItem = null;
_logger.LogInformation("Загрузка закуски для поставок");
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (comboBoxShop.SelectedValue == null)
{
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxSnack.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание поставки");
try
{
var operationResult = _logicS.MakeSupply(new SupplyBindingModel
{
ShopId = Convert.ToInt32(comboBoxShop.SelectedValue),
SnackId = Convert.ToInt32(comboBoxSnack.SelectedValue),
Count = Convert.ToInt32(textBoxCount.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();
}
}
}

View File

@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -28,166 +28,136 @@
/// </summary>
private void InitializeComponent()
{
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
toolStrip1 = new ToolStrip();
toolStripLabel1 = new ToolStripDropDownButton();
componentsToolStripMenuItem = new ToolStripMenuItem();
snacksToolStripMenuItem = new ToolStripMenuItem();
магазиныToolStripMenuItem = new ToolStripMenuItem();
toolStripDropDownButton1 = new ToolStripDropDownButton();
поставкаToolStripMenuItem = new ToolStripMenuItem();
SellToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
toolStrip1.SuspendLayout();
SuspendLayout();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripLabel1 = new System.Windows.Forms.ToolStripDropDownButton();
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.snacksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.toolStrip1.SuspendLayout();
this.SuspendLayout();
//
// dataGridView
//
dataGridView.BackgroundColor = SystemColors.ButtonHighlight;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(0, 27);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(986, 421);
dataGridView.TabIndex = 0;
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(0, 27);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(986, 421);
this.dataGridView.TabIndex = 0;
//
// buttonCreateOrder
//
buttonCreateOrder.Location = new Point(1040, 88);
buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.Size = new Size(202, 29);
buttonCreateOrder.TabIndex = 1;
buttonCreateOrder.Text = "Создать заказ";
buttonCreateOrder.UseVisualStyleBackColor = true;
buttonCreateOrder.Click += ButtonCreateOrder_Click;
this.buttonCreateOrder.Location = new System.Drawing.Point(1040, 88);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(202, 29);
this.buttonCreateOrder.TabIndex = 1;
this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
//
// buttonTakeOrderInWork
//
buttonTakeOrderInWork.Location = new Point(1040, 136);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(202, 29);
buttonTakeOrderInWork.TabIndex = 2;
buttonTakeOrderInWork.Text = "Отдать на выполнение";
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1040, 136);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(202, 29);
this.buttonTakeOrderInWork.TabIndex = 2;
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
//
// buttonOrderReady
//
buttonOrderReady.Location = new Point(1040, 184);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(202, 29);
buttonOrderReady.TabIndex = 3;
buttonOrderReady.Text = "Заказ готов";
buttonOrderReady.UseVisualStyleBackColor = true;
buttonOrderReady.Click += ButtonOrderReady_Click;
this.buttonOrderReady.Location = new System.Drawing.Point(1040, 184);
this.buttonOrderReady.Name = "buttonOrderReady";
this.buttonOrderReady.Size = new System.Drawing.Size(202, 29);
this.buttonOrderReady.TabIndex = 3;
this.buttonOrderReady.Text = "Заказ готов";
this.buttonOrderReady.UseVisualStyleBackColor = true;
this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
//
// buttonIssuedOrder
//
buttonIssuedOrder.Location = new Point(1040, 237);
buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(202, 29);
buttonIssuedOrder.TabIndex = 4;
buttonIssuedOrder.Text = "Заказ выдан";
buttonIssuedOrder.UseVisualStyleBackColor = true;
buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
this.buttonIssuedOrder.Location = new System.Drawing.Point(1040, 237);
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonIssuedOrder.Size = new System.Drawing.Size(202, 29);
this.buttonIssuedOrder.TabIndex = 4;
this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
//
// buttonRef
//
buttonRef.Location = new Point(1040, 287);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(202, 29);
buttonRef.TabIndex = 5;
buttonRef.Text = "Обновить список";
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
this.buttonRef.Location = new System.Drawing.Point(1040, 287);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(202, 29);
this.buttonRef.TabIndex = 5;
this.buttonRef.Text = "Обновить список";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// toolStrip1
//
toolStrip1.ImageScalingSize = new Size(20, 20);
toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripLabel1, toolStripDropDownButton1 });
toolStrip1.Location = new Point(0, 0);
toolStrip1.Name = "toolStrip1";
toolStrip1.Size = new Size(1280, 27);
toolStrip1.TabIndex = 6;
toolStrip1.Text = "toolStrip1";
this.toolStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripLabel1});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(1280, 27);
this.toolStrip1.TabIndex = 6;
this.toolStrip1.Text = "toolStrip1";
//
// toolStripLabel1
//
toolStripLabel1.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, snacksToolStripMenuItem, магазиныToolStripMenuItem });
toolStripLabel1.Name = "toolStripLabel1";
toolStripLabel1.Size = new Size(117, 24);
toolStripLabel1.Text = "Справочники";
this.toolStripLabel1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.componentsToolStripMenuItem,
this.snacksToolStripMenuItem});
this.toolStripLabel1.Name = "toolStripLabel1";
this.toolStripLabel1.Size = new System.Drawing.Size(117, 24);
this.toolStripLabel1.Text = "Справочники";
//
// componentsToolStripMenuItem
//
componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
componentsToolStripMenuItem.Size = new Size(182, 26);
componentsToolStripMenuItem.Text = "Компоненты";
componentsToolStripMenuItem.Click += ComponentToolStripMenuItem_Click;
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.componentsToolStripMenuItem.Text = "Компоненты";
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentToolStripMenuItem_Click);
//
// snacksToolStripMenuItem
//
snacksToolStripMenuItem.Name = "snacksToolStripMenuItem";
snacksToolStripMenuItem.Size = new Size(182, 26);
snacksToolStripMenuItem.Text = "Закуски";
snacksToolStripMenuItem.Click += ProductToolStripMenuItem_Click;
//
// магазиныToolStripMenuItem
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(182, 26);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += shopsToolStripMenuItem_Click;
//
// toolStripDropDownButton1
//
toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text;
toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { поставкаToolStripMenuItem, SellToolStripMenuItem });
toolStripDropDownButton1.ImageTransparentColor = Color.Magenta;
toolStripDropDownButton1.Name = "toolStripDropDownButton1";
toolStripDropDownButton1.Size = new Size(95, 24);
toolStripDropDownButton1.Text = "Операции";
//
// поставкаToolStripMenuItem
//
поставкаToolStripMenuItem.Name = "поставкаToolStripMenuItem";
поставкаToolStripMenuItem.Size = new Size(224, 26);
поставкаToolStripMenuItem.Text = "Поставка";
поставкаToolStripMenuItem.Click += transactionToolStripMenuItem_Click;
//
// SellToolStripMenuItem
//
SellToolStripMenuItem.Name = "SellToolStripMenuItem";
SellToolStripMenuItem.Size = new Size(224, 26);
SellToolStripMenuItem.Text = "Продажа";
SellToolStripMenuItem.Click += SellToolStripMenuItem_Click;
this.snacksToolStripMenuItem.Name = "snacksToolStripMenuItem";
this.snacksToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.snacksToolStripMenuItem.Text = "Закуски";
this.snacksToolStripMenuItem.Click += new System.EventHandler(this.ProductToolStripMenuItem_Click);
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1280, 450);
Controls.Add(toolStrip1);
Controls.Add(buttonRef);
Controls.Add(buttonIssuedOrder);
Controls.Add(buttonOrderReady);
Controls.Add(buttonTakeOrderInWork);
Controls.Add(buttonCreateOrder);
Controls.Add(dataGridView);
Name = "FormMain";
Text = "Закусочная";
Load += FormMain_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
toolStrip1.ResumeLayout(false);
toolStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1280, 450);
this.Controls.Add(this.toolStrip1);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonIssuedOrder);
this.Controls.Add(this.buttonOrderReady);
this.Controls.Add(this.buttonTakeOrderInWork);
this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView);
this.Name = "FormMain";
this.Text = "Закусочная";
this.Load += new System.EventHandler(this.FormMain_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
@@ -202,9 +172,5 @@
private ToolStripDropDownButton toolStripLabel1;
private ToolStripMenuItem componentsToolStripMenuItem;
private ToolStripMenuItem snacksToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripDropDownButton toolStripDropDownButton1;
private ToolStripMenuItem поставкаToolStripMenuItem;
private ToolStripMenuItem SellToolStripMenuItem;
}
}

View File

@@ -1,9 +1,7 @@
using DinerContracts.BindingModels;
using DinerContracts.BusinessLogicsContracts;
using DinerDataModels.Enum;
using DinerView;
using Microsoft.Extensions.Logging;
using DinerView;
namespace Diner
{
@@ -163,30 +161,5 @@ namespace Diner
{
LoadData();
}
private void shopsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
}
private void transactionToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply));
if (service is FormCreateSupply form)
{
form.ShowDialog();
}
}
private void SellToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellSnack));
if (service is FormSellSnack form)
{
form.ShowDialog();
}
}
}
}

View File

@@ -1,64 +1,4 @@
<?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.
-->
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">

View File

@@ -1,119 +0,0 @@
namespace DinerView
{
partial class FormSellSnack
{
/// <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()
{
labelSnack = new Label();
comboBoxSnack = new ComboBox();
labelCount = new Label();
textBoxCount = new TextBox();
buttonSell = new Button();
buttonCancel = new Button();
SuspendLayout();
//
// labelSnack
//
labelSnack.AutoSize = true;
labelSnack.Location = new Point(12, 14);
labelSnack.Name = "labelSnack";
labelSnack.Size = new Size(68, 20);
labelSnack.TabIndex = 0;
labelSnack.Text = "Закуска: ";
//
// comboBoxSnack
//
comboBoxSnack.FormattingEnabled = true;
comboBoxSnack.Location = new Point(115, 11);
comboBoxSnack.Name = "comboBoxSnack";
comboBoxSnack.Size = new Size(239, 28);
comboBoxSnack.TabIndex = 1;
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(12, 55);
labelCount.Name = "labelCount";
labelCount.Size = new Size(97, 20);
labelCount.TabIndex = 2;
labelCount.Text = "Количество: ";
//
// textBoxCount
//
textBoxCount.Location = new Point(115, 52);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(239, 27);
textBoxCount.TabIndex = 3;
//
// buttonSell
//
buttonSell.Location = new Point(128, 99);
buttonSell.Name = "buttonSell";
buttonSell.Size = new Size(94, 29);
buttonSell.TabIndex = 4;
buttonSell.Text = "Продать";
buttonSell.UseVisualStyleBackColor = true;
buttonSell.Click += ButtonSell_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(242, 99);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormSellSnack
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(366, 140);
Controls.Add(buttonCancel);
Controls.Add(buttonSell);
Controls.Add(textBoxCount);
Controls.Add(labelCount);
Controls.Add(comboBoxSnack);
Controls.Add(labelSnack);
Name = "FormSellSnack";
Text = "Продажа закуски";
Load += FormSellingSnack_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelSnack;
private ComboBox comboBoxSnack;
private Label labelCount;
private TextBox textBoxCount;
private Button buttonSell;
private Button buttonCancel;
}
}

View File

@@ -1,83 +0,0 @@
using Microsoft.Extensions.Logging;
using DinerContracts.BusinessLogicsContracts;
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DinerView
{
public partial class FormSellSnack : Form
{
private readonly ILogger _logger;
private readonly ISnackLogic _logicP;
private readonly IShopLogic _logicS;
private List<SnackViewModel> _snackList = new List<SnackViewModel>();
public FormSellSnack(ILogger<FormSellSnack> logger, ISnackLogic logicP, IShopLogic logicS)
{
InitializeComponent();
_logger = logger;
_logicP = logicP;
_logicS = logicS;
}
private void FormSellingSnack_Load(object sender, EventArgs e)
{
_snackList = _logicP.ReadList(null);
if (_snackList != null)
{
comboBoxSnack.DisplayMember = "SnackName";
comboBoxSnack.ValueMember = "Id";
comboBoxSnack.DataSource = _snackList;
comboBoxSnack.SelectedItem = null;
_logger.LogInformation("Загрузка закуски для продажи");
}
}
private void ButtonSell_Click(object sender, EventArgs e)
{
if (comboBoxSnack.SelectedValue == null)
{
MessageBox.Show("Выберите закуску", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание покупки");
try
{
bool resout = _logicS.Sale(new SupplySearchModel
{
SnackId = Convert.ToInt32(comboBoxSnack.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text)
});
if (resout)
{
_logger.LogInformation("Проверка пройдена, продажа проведена");
MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
else {
_logger.LogInformation("Проверка не пройдена");
MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
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();
}
}
}

View File

@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -1,214 +0,0 @@
namespace DinerView
{
partial class FormShop
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
labelName = new Label();
textBoxName = new TextBox();
textBoxAdress = new TextBox();
labelAdress = new Label();
buttonCancel = new Button();
buttonSave = new Button();
dataGridView = new DataGridView();
id = new DataGridViewTextBoxColumn();
DinerName = new DataGridViewTextBoxColumn();
Count = new DataGridViewTextBoxColumn();
label1 = new Label();
dateTimeOpen = new DateTimePicker();
label2 = new Label();
numericUpSnackMaxCount = new NumericUpDown();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpSnackMaxCount).BeginInit();
SuspendLayout();
//
// labelName
//
labelName.AutoSize = true;
labelName.Location = new Point(11, 15);
labelName.Name = "labelName";
labelName.Size = new Size(84, 20);
labelName.TabIndex = 0;
labelName.Text = "Название: ";
//
// textBoxName
//
textBoxName.Location = new Point(102, 12);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(276, 27);
textBoxName.TabIndex = 1;
//
// textBoxAdress
//
textBoxAdress.Location = new Point(102, 59);
textBoxAdress.Name = "textBoxAdress";
textBoxAdress.Size = new Size(427, 27);
textBoxAdress.TabIndex = 3;
//
// labelAdress
//
labelAdress.AutoSize = true;
labelAdress.Location = new Point(11, 61);
labelAdress.Name = "labelAdress";
labelAdress.Size = new Size(58, 20);
labelAdress.TabIndex = 2;
labelAdress.Text = "Адрес: ";
//
// buttonCancel
//
buttonCancel.Location = new Point(451, 457);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(130, 44);
buttonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSave
//
buttonSave.Location = new Point(315, 457);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(130, 44);
buttonSave.TabIndex = 6;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToDeleteRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { id, DinerName, Count });
dataGridView.Location = new Point(12, 197);
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
dataGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(569, 254);
dataGridView.TabIndex = 7;
//
// id
//
id.HeaderText = "id";
id.MinimumWidth = 6;
id.Name = "id";
id.ReadOnly = true;
id.Visible = false;
//
// DinerName
//
DinerName.HeaderText = "Закуска";
DinerName.MinimumWidth = 6;
DinerName.Name = "DinerName";
DinerName.ReadOnly = true;
//
// Count
//
Count.HeaderText = "Количество";
Count.MinimumWidth = 6;
Count.Name = "Count";
Count.ReadOnly = true;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(12, 103);
label1.Name = "label1";
label1.Size = new Size(110, 20);
label1.TabIndex = 8;
label1.Text = "Дата открытия";
//
// dateTimeOpen
//
dateTimeOpen.Location = new Point(128, 103);
dateTimeOpen.Name = "dateTimeOpen";
dateTimeOpen.Size = new Size(401, 27);
dateTimeOpen.TabIndex = 9;
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(12, 156);
label2.Name = "label2";
label2.Size = new Size(107, 20);
label2.TabIndex = 10;
label2.Text = "Вместимость: ";
//
// numericUpSnackMaxCount
//
numericUpSnackMaxCount.Location = new Point(128, 154);
numericUpSnackMaxCount.Maximum = new decimal(new int[] { 10000, 0, 0, 0 });
numericUpSnackMaxCount.Name = "numericUpSnackMaxCount";
numericUpSnackMaxCount.Size = new Size(401, 27);
numericUpSnackMaxCount.TabIndex = 12;
//
// FormShop
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(593, 513);
Controls.Add(numericUpSnackMaxCount);
Controls.Add(label2);
Controls.Add(dateTimeOpen);
Controls.Add(label1);
Controls.Add(dataGridView);
Controls.Add(buttonSave);
Controls.Add(buttonCancel);
Controls.Add(textBoxAdress);
Controls.Add(labelAdress);
Controls.Add(textBoxName);
Controls.Add(labelName);
Name = "FormShop";
Text = "Магазин";
Load += FormShop_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpSnackMaxCount).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelName;
private TextBox textBoxName;
private TextBox textBoxAdress;
private Label labelAdress;
private Button buttonCancel;
private Button buttonSave;
private DataGridView dataGridView;
private Label label1;
private DateTimePicker dateTimeOpen;
private DataGridViewTextBoxColumn id;
private DataGridViewTextBoxColumn DinerName;
private DataGridViewTextBoxColumn Count;
private Label label2;
private NumericUpDown numericUpSnackMaxCount;
}
}

View File

@@ -1,130 +0,0 @@
using DinerDataModels.Models;
using Microsoft.Extensions.Logging;
using DinerContracts.BindingModels;
using DinerContracts.BusinessLogicsContracts;
using DinerContracts.SearchModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DinerView
{
public partial class FormShop : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
private Dictionary<int, (ISnackModel, int)> _ShopSnacks;
private DateTime? _openingDate = null;
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_ShopSnacks = new Dictionary<int, (ISnackModel, int)>();
}
private void FormShop_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка магазина");
try
{
var view = _logic.ReadElement(new ShopSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxName.Text = view.ShopName;
textBoxAdress.Text = view.Adress;
dateTimeOpen.Value = view.OpeningDate;
numericUpSnackMaxCount.Value = view.SnackMaxCount;
_ShopSnacks = view.ShopSnacks ?? new Dictionary<int, (ISnackModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка изделий в магазине");
try
{
if (_ShopSnacks != null)
{
dataGridView.Rows.Clear();
foreach (var sr in _ShopSnacks)
{
dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.SnackName, sr.Value.Item2 });
}
}
}
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;
}
if (string.IsNullOrEmpty(textBoxAdress.Text))
{
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение магазина");
try
{
var model = new ShopBindingModel
{
Id = _id ?? 0,
ShopName = textBoxName.Text,
Adress = textBoxAdress.Text,
OpeningDate = dateTimeOpen.Value,
SnackMaxCount = (int)numericUpSnackMaxCount.Value
};
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();
}
}
}

View File

@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -1,130 +0,0 @@
namespace DinerView
{
partial class FormShops
{
/// <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.ToolsPanel = new System.Windows.Forms.Panel();
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.ToolsPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// ToolsPanel
//
this.ToolsPanel.Controls.Add(this.buttonRef);
this.ToolsPanel.Controls.Add(this.buttonDel);
this.ToolsPanel.Controls.Add(this.buttonUpd);
this.ToolsPanel.Controls.Add(this.buttonAdd);
this.ToolsPanel.Location = new System.Drawing.Point(608, 12);
this.ToolsPanel.Name = "ToolsPanel";
this.ToolsPanel.Size = new System.Drawing.Size(180, 426);
this.ToolsPanel.TabIndex = 3;
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(31, 206);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(126, 36);
this.buttonRef.TabIndex = 3;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(31, 142);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(126, 36);
this.buttonDel.TabIndex = 2;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(31, 76);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(126, 36);
this.buttonUpd.TabIndex = 1;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(31, 16);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(126, 36);
this.buttonAdd.TabIndex = 0;
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.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.ReadOnly = true;
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(590, 426);
this.dataGridView.TabIndex = 2;
//
// FormShops
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.ToolsPanel);
this.Controls.Add(this.dataGridView);
this.Name = "FormShops";
this.Text = "Магазины";
this.Load += new System.EventHandler(this.FormShops_Load);
this.ToolsPanel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Panel ToolsPanel;
private Button buttonRef;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
}
}

View File

@@ -1,117 +0,0 @@
using Microsoft.Extensions.Logging;
using Diner;
using DinerContracts.BindingModels;
using DinerContracts.BusinessLogicsContracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DinerView
{
public partial class FormShops : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
public FormShops(ILogger<FormShops> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormShops_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["ShopName"].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(FormShop));
if (service is FormShop 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(FormShop));
if (service is FormShop 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 ShopBindingModel
{
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();
}
}
}

View File

@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -1,13 +1,11 @@
using DinerContracts.BusinessLogicsContracts;
using DinerContracts.StoragesContracts;
using DinerDatabaseImplement.Implements;
using DinerDataBaseImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using DinerBusinessLogic.BusinessLogics;
using DinerView;
namespace Diner
{
internal static class Program
@@ -48,12 +46,6 @@ namespace Diner
services.AddTransient<FormSnack>();
services.AddTransient<FormSnackComponent>();
services.AddTransient<FormSnacks>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormCreateSupply>();
services.AddTransient<FormSellSnack>();
}
}
}

View File

@@ -1,63 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DinerView.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DinerView.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
<PrivateAssets>all</PrivateAssets>
@@ -17,7 +18,6 @@
<ItemGroup>
<ProjectReference Include="..\..\AbstractShopContracts\DinerContracts.csproj" />
<ProjectReference Include="..\..\AbstractShopDataModels\DinerDataModels.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,21 @@
using DinerDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace DinerDataBaseImplement
{
public class DinerDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS01;Initial Catalog=DinerDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Component> Components { set; get; }
public virtual DbSet<Snack> Snacks { set; get; }
public virtual DbSet<SnackComponent> SnackComponents { set; get; }
public virtual DbSet<Order> Orders { set; get; }
}
}

View File

@@ -2,18 +2,19 @@
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using DinerDatabaseImplement.Models;
using DinerDataBaseImplement.Models;
namespace DinerDatabaseImplement.Implements
namespace DinerDataBaseImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
public List<ComponentViewModel> GetFullList()
{
using var context = new DinerDatabase();
return context.Components.Select(x => x.GetViewModel).ToList();
return context.Components
.Select(x => x.GetViewModel)
.ToList();
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName))
@@ -21,9 +22,11 @@ namespace DinerDatabaseImplement.Implements
return new();
}
using var context = new DinerDatabase();
return context.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList();
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)
@@ -31,12 +34,10 @@ namespace DinerDatabaseImplement.Implements
return null;
}
using var context = new DinerDatabase();
return context.Components.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
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);
@@ -49,7 +50,6 @@ namespace DinerDatabaseImplement.Implements
context.SaveChanges();
return newComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel model)
{
using var context = new DinerDatabase();
@@ -62,7 +62,6 @@ namespace DinerDatabaseImplement.Implements
context.SaveChanges();
return component.GetViewModel;
}
public ComponentViewModel? Delete(ComponentBindingModel model)
{
using var context = new DinerDatabase();

View File

@@ -0,0 +1,93 @@
using DinerContracts.BindingModels;
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using DinerDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerDataBaseImplement.Implements
{
public class OrderStorage : IOrderStorage
{
public List<OrderViewModel> GetFullList()
{
using var context = new DinerDatabase();
return context.Orders
.Include(x => x.Snack)
.Select(x => x.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
using var context = new DinerDatabase();
return context.Orders
.Include(x => x.Snack)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new DinerDatabase();
return context.Orders.Include(x => x.Snack)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
using var context = new DinerDatabase();
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
context.Orders.Add(newOrder);
context.SaveChanges();
return context.Orders.Include(x => x.Snack)
.FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; ;
}
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new DinerDatabase();
var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
context.SaveChanges();
return context.Orders
.Include(x => x.Snack)
.FirstOrDefault(x => x.Id == model.Id)?
.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new DinerDatabase();
var element = context.Orders
.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@@ -2,20 +2,23 @@
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using DinerDatabaseImplement.Models;
using DinerDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace DinerDatabaseImplement.Implements
namespace DinerDataBaseImplement.Implements
{
public class SnackStorage : ISnackStorage
{
public List<SnackViewModel> GetFullList()
{
using var context = new DinerDatabase();
return context.Snacks.Include(x => x.Components).ThenInclude(x => x.Component).ToList()
.Select(x => x.GetViewModel).ToList();
return context.Snacks
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<SnackViewModel> GetFilteredList(SnackSearchModel model)
{
if (string.IsNullOrEmpty(model.SnackName))
@@ -23,24 +26,26 @@ namespace DinerDatabaseImplement.Implements
return new();
}
using var context = new DinerDatabase();
return context.Snacks.Include(x => x.Components).ThenInclude(x => x.Component)
.Where(x => x.SnackName.Contains(model.SnackName)).ToList().Select(x => x.GetViewModel).ToList();
return context.Snacks
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.Where(x => x.SnackName.Contains(model.SnackName))
.ToList()
.Select(x => x.GetViewModel).ToList();
}
public SnackViewModel? GetElement(SnackSearchModel model)
{
if (string.IsNullOrEmpty(model.SnackName) && !model.Id.HasValue)
if (string.IsNullOrEmpty(model.SnackName) &&
!model.Id.HasValue)
{
return null;
}
using var context = new DinerDatabase();
return context.Snacks.Include(x => x.Components).ThenInclude(x => x.Component)
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.SnackName) && x.SnackName == model.SnackName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
return context.Snacks
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SnackName) && x.SnackName == model.SnackName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public SnackViewModel? Insert(SnackBindingModel model)
{
using var context = new DinerDatabase();
@@ -53,23 +58,22 @@ namespace DinerDatabaseImplement.Implements
context.SaveChanges();
return newSnack.GetViewModel;
}
public SnackViewModel? Update(SnackBindingModel model)
{
using var context = new DinerDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var Snack = context.Snacks.FirstOrDefault(rec => rec.Id == model.Id);
if (Snack == null)
var snack = context.Snacks.FirstOrDefault(rec => rec.Id == model.Id);
if (snack == null)
{
return null;
}
Snack.Update(model);
snack.Update(model);
context.SaveChanges();
Snack.UpdateComponents(context, model);
snack.UpdateComponents(context, model);
transaction.Commit();
return Snack.GetViewModel;
return snack.GetViewModel;
}
catch
{
@@ -77,11 +81,13 @@ namespace DinerDatabaseImplement.Implements
throw;
}
}
public SnackViewModel? Delete(SnackBindingModel model)
{
using var context = new DinerDatabase();
var element = context.Snacks.Include(x => x.Components).FirstOrDefault(rec => rec.Id == model.Id);
var element = context.Snacks
.Include(x => x.Components)
.Include(x => x.Orders)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Snacks.Remove(element);

View File

@@ -1,6 +1,6 @@
// <auto-generated />
using System;
using DinerDatabaseImplement;
using DinerDataBaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
@@ -9,10 +9,10 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace DinerDatabaseImplement.Migrations
namespace DinerDataBaseImplement.Migrations
{
[DbContext(typeof(DinerDatabase))]
[Migration("20240506162016_InitialCreate")]
[Migration("20240316161514_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@@ -25,7 +25,7 @@ namespace DinerDatabaseImplement.Migrations
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("DinerDatabaseImplement.Models.Component", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
@@ -45,7 +45,7 @@ namespace DinerDatabaseImplement.Migrations
b.ToTable("Components");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Order", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
@@ -78,60 +78,7 @@ namespace DinerDatabaseImplement.Migrations
b.ToTable("Orders");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Shop", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Adress")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OpeningDate")
.HasColumnType("datetime2");
b.Property<string>("ShopName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("SnackMaxCount")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Shops");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.ShopSnacks", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ShopId")
.HasColumnType("int");
b.Property<int>("SnackId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ShopId");
b.HasIndex("SnackId");
b.ToTable("ShopSnacks");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Snack", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.Snack", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
@@ -151,7 +98,7 @@ namespace DinerDatabaseImplement.Migrations
b.ToTable("Snacks");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.SnackComponent", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.SnackComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
@@ -177,9 +124,9 @@ namespace DinerDatabaseImplement.Migrations
b.ToTable("SnackComponents");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Order", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b =>
{
b.HasOne("DinerDatabaseImplement.Models.Snack", "Snack")
b.HasOne("DinerDataBaseImplement.Models.Snack", "Snack")
.WithMany("Orders")
.HasForeignKey("SnackId")
.OnDelete(DeleteBehavior.Cascade)
@@ -188,34 +135,15 @@ namespace DinerDatabaseImplement.Migrations
b.Navigation("Snack");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.ShopSnacks", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.SnackComponent", b =>
{
b.HasOne("DinerDatabaseImplement.Models.Shop", "Shop")
.WithMany("Snacks")
.HasForeignKey("ShopId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DinerDatabaseImplement.Models.Snack", "Snack")
.WithMany()
.HasForeignKey("SnackId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Shop");
b.Navigation("Snack");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.SnackComponent", b =>
{
b.HasOne("DinerDatabaseImplement.Models.Component", "Component")
b.HasOne("DinerDataBaseImplement.Models.Component", "Component")
.WithMany("SnackComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DinerDatabaseImplement.Models.Snack", "Snack")
b.HasOne("DinerDataBaseImplement.Models.Snack", "Snack")
.WithMany("Components")
.HasForeignKey("SnackId")
.OnDelete(DeleteBehavior.Cascade)
@@ -226,17 +154,12 @@ namespace DinerDatabaseImplement.Migrations
b.Navigation("Snack");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Component", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.Component", b =>
{
b.Navigation("SnackComponents");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Shop", b =>
{
b.Navigation("Snacks");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Snack", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.Snack", b =>
{
b.Navigation("Components");

View File

@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DinerDatabaseImplement.Migrations
namespace DinerDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
@@ -25,22 +25,6 @@ namespace DinerDatabaseImplement.Migrations
table.PrimaryKey("PK_Components", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Shops",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ShopName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Adress = table.Column<string>(type: "nvarchar(max)", nullable: false),
OpeningDate = table.Column<DateTime>(type: "datetime2", nullable: false),
SnackMaxCount = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Shops", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Snacks",
columns: table => new
@@ -79,33 +63,6 @@ namespace DinerDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ShopSnacks",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
SnackId = table.Column<int>(type: "int", nullable: false),
ShopId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ShopSnacks", x => x.Id);
table.ForeignKey(
name: "FK_ShopSnacks_Shops_ShopId",
column: x => x.ShopId,
principalTable: "Shops",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ShopSnacks_Snacks_SnackId",
column: x => x.SnackId,
principalTable: "Snacks",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "SnackComponents",
columns: table => new
@@ -138,16 +95,6 @@ namespace DinerDatabaseImplement.Migrations
table: "Orders",
column: "SnackId");
migrationBuilder.CreateIndex(
name: "IX_ShopSnacks_ShopId",
table: "ShopSnacks",
column: "ShopId");
migrationBuilder.CreateIndex(
name: "IX_ShopSnacks_SnackId",
table: "ShopSnacks",
column: "SnackId");
migrationBuilder.CreateIndex(
name: "IX_SnackComponents_ComponentId",
table: "SnackComponents",
@@ -165,15 +112,9 @@ namespace DinerDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "ShopSnacks");
migrationBuilder.DropTable(
name: "SnackComponents");
migrationBuilder.DropTable(
name: "Shops");
migrationBuilder.DropTable(
name: "Components");

View File

@@ -1,6 +1,6 @@
// <auto-generated />
using System;
using DinerDatabaseImplement;
using DinerDataBaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
@@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace DinerDatabaseImplement.Migrations
namespace DinerDataBaseImplement.Migrations
{
[DbContext(typeof(DinerDatabase))]
partial class DinerDatabaseModelSnapshot : ModelSnapshot
@@ -22,7 +22,7 @@ namespace DinerDatabaseImplement.Migrations
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("DinerDatabaseImplement.Models.Component", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
@@ -42,7 +42,7 @@ namespace DinerDatabaseImplement.Migrations
b.ToTable("Components");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Order", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
@@ -75,60 +75,7 @@ namespace DinerDatabaseImplement.Migrations
b.ToTable("Orders");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Shop", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Adress")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OpeningDate")
.HasColumnType("datetime2");
b.Property<string>("ShopName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("SnackMaxCount")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Shops");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.ShopSnacks", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ShopId")
.HasColumnType("int");
b.Property<int>("SnackId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ShopId");
b.HasIndex("SnackId");
b.ToTable("ShopSnacks");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Snack", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.Snack", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
@@ -148,7 +95,7 @@ namespace DinerDatabaseImplement.Migrations
b.ToTable("Snacks");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.SnackComponent", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.SnackComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
@@ -174,9 +121,9 @@ namespace DinerDatabaseImplement.Migrations
b.ToTable("SnackComponents");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Order", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.Order", b =>
{
b.HasOne("DinerDatabaseImplement.Models.Snack", "Snack")
b.HasOne("DinerDataBaseImplement.Models.Snack", "Snack")
.WithMany("Orders")
.HasForeignKey("SnackId")
.OnDelete(DeleteBehavior.Cascade)
@@ -185,34 +132,15 @@ namespace DinerDatabaseImplement.Migrations
b.Navigation("Snack");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.ShopSnacks", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.SnackComponent", b =>
{
b.HasOne("DinerDatabaseImplement.Models.Shop", "Shop")
.WithMany("Snacks")
.HasForeignKey("ShopId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DinerDatabaseImplement.Models.Snack", "Snack")
.WithMany()
.HasForeignKey("SnackId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Shop");
b.Navigation("Snack");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.SnackComponent", b =>
{
b.HasOne("DinerDatabaseImplement.Models.Component", "Component")
b.HasOne("DinerDataBaseImplement.Models.Component", "Component")
.WithMany("SnackComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DinerDatabaseImplement.Models.Snack", "Snack")
b.HasOne("DinerDataBaseImplement.Models.Snack", "Snack")
.WithMany("Components")
.HasForeignKey("SnackId")
.OnDelete(DeleteBehavior.Cascade)
@@ -223,17 +151,12 @@ namespace DinerDatabaseImplement.Migrations
b.Navigation("Snack");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Component", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.Component", b =>
{
b.Navigation("SnackComponents");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Shop", b =>
{
b.Navigation("Snacks");
});
modelBuilder.Entity("DinerDatabaseImplement.Models.Snack", b =>
modelBuilder.Entity("DinerDataBaseImplement.Models.Snack", b =>
{
b.Navigation("Components");

View File

@@ -4,7 +4,7 @@ using DinerDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace DinerDatabaseImplement.Models
namespace DinerDataBaseImplement.Models
{
public class Component : IComponentModel
{
@@ -28,7 +28,6 @@ namespace DinerDatabaseImplement.Models
Cost = model.Cost
};
}
public static Component Create(ComponentViewModel model)
{
return new Component
@@ -38,7 +37,6 @@ namespace DinerDatabaseImplement.Models
Cost = model.Cost
};
}
public void Update(ComponentBindingModel model)
{
if (model == null)

View File

@@ -1,73 +1,67 @@
using DinerContracts.BindingModels;

using DinerContracts.BindingModels;
using DinerContracts.ViewModels;
using DinerDataModels.Enum;
using System;
using System.Collections.Generic;
using DinerDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace DinerDatabaseImplement.Models
namespace DinerDataBaseImplement.Models
{
public class Order
public class Order : IOrderModel
{
public int Id { get; private set; }
[Required]
public int SnackId { get; private set; }
public virtual Snack Snack { get; set; } = new();
[Required]
public int Count { get; private set; }
[Required]
public double Sum { get; private set; }
[Required]
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public OrderStatus Status { get; private set; }
[Required]
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
public static Order Create(DinerDatabase context, OrderBindingModel model)
public virtual Snack Snack { get; set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
SnackId = model.SnackId,
Snack = context.Snacks.First(x => x.Id == model.SnackId),
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
DateImplement = model.DateImplement
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Sum = model.Sum;
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
SnackId = SnackId,
SnackName = Snack.SnackName,
SnackId = SnackId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
SnackName = Snack.SnackName
};
}
}

View File

@@ -1,10 +1,10 @@
using DinerContracts.BindingModels;
using DinerContracts.ViewModels;
using DinerDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DinerDatabaseImplement.Models
namespace DinerDataBaseImplement.Models
{
public class Snack : ISnackModel
{
@@ -13,8 +13,7 @@ namespace DinerDatabaseImplement.Models
public string SnackName { get; set; } = string.Empty;
[Required]
public double Price { get; set; }
private Dictionary<int, (IComponentModel, int)>? _snackComponents = null;
private Dictionary<int, (IComponentModel, int)>? _snackComponents = null;
[NotMapped]
public Dictionary<int, (IComponentModel, int)> SnackComponents
{
@@ -22,8 +21,8 @@ namespace DinerDatabaseImplement.Models
{
if (_snackComponents == null)
{
_snackComponents = Components.ToDictionary(recPC => recPC.ComponentId, recPC =>
(recPC.Component as IComponentModel, recPC.Count));
_snackComponents = Components
.ToDictionary(recPC => recPC.ComponentId, recPC => (recPC.Component as IComponentModel, recPC.Count));
}
return _snackComponents;
}
@@ -32,16 +31,15 @@ namespace DinerDatabaseImplement.Models
public virtual List<SnackComponent> Components { get; set; } = new();
[ForeignKey("SnackId")]
public virtual List<Order> Orders { get; set; } = new();
public static Snack
Create(DinerDatabase context, SnackBindingModel model)
public static Snack Create(DinerDatabase context, SnackBindingModel model)
{
return new Snack()
{
Id = model.Id,
SnackName = model.SnackName,
Price = model.Price,
Components = model.SnackComponents.Select(x => new SnackComponent {
Components = model.SnackComponents.Select(x => new SnackComponent
{
Component = context.Components.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList()
@@ -57,15 +55,16 @@ namespace DinerDatabaseImplement.Models
Id = Id,
SnackName = SnackName,
Price = Price,
SnackComponents = SnackComponents
SnackComponents = SnackComponents
};
public void UpdateComponents(DinerDatabase context, SnackBindingModel model)
{
var snackComponents = context.SnackComponents.Where(rec => rec.SnackId == model.Id).ToList();
if (snackComponents != null && snackComponents.Count > 0) {
if (snackComponents != null && snackComponents.Count > 0)
{ // удалили те, которых нет в модели
context.SnackComponents.RemoveRange(snackComponents.Where(rec => !model.SnackComponents.ContainsKey(rec.ComponentId)));
context.SaveChanges();
// обновили количество у существующих записей
foreach (var updateComponent in snackComponents)
{
updateComponent.Count = model.SnackComponents[updateComponent.ComponentId].Item2;
@@ -73,9 +72,9 @@ namespace DinerDatabaseImplement.Models
}
context.SaveChanges();
}
var snack = context.Snacks.First(x => x.Id == Id);
foreach (var pc in model.SnackComponents) {
foreach (var pc in model.SnackComponents)
{
context.SnackComponents.Add(new SnackComponent
{
Snack = snack,
@@ -86,6 +85,5 @@ namespace DinerDatabaseImplement.Models
}
_snackComponents = null;
}
}
}

View File

@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
namespace DinerDatabaseImplement.Models
namespace DinerDataBaseImplement.Models
{
public class SnackComponent
{

View File

@@ -1,24 +0,0 @@
using DinerDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
namespace DinerDatabaseImplement
{
public class DinerDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS01;Initial Catalog=DinerDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Component> Components { get; set; }
public virtual DbSet<Snack> Snacks { get; set; }
public virtual DbSet<SnackComponent> SnackComponents { get; set; }
public virtual DbSet<Order> Orders { get; set; }
public virtual DbSet<Shop> Shops { get; set; }
public virtual DbSet<ShopSnacks> ShopSnacks { get; set; }
}
}

View File

@@ -1,79 +0,0 @@
using DinerContracts.BindingModels;
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using DinerDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace DinerDatabaseImplement.Implements
{
public class OrderStorage : IOrderStorage
{
public List<OrderViewModel> GetFullList()
{
using var context = new DinerDatabase();
return context.Orders.Include(x => x.Snack).Select(x => x.GetViewModel).ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
using var context = new DinerDatabase();
return context.Orders.Include(x => x.Snack).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
using var context = new DinerDatabase();
return context.Orders.Include(x => x.Snack).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
using var context = new DinerDatabase();
if (model == null)
return null;
var newOrder = Order.Create(context, model);
if (newOrder == null)
{
return null;
}
context.Orders.Add(newOrder);
context.SaveChanges();
return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new DinerDatabase();
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
context.SaveChanges();
return order.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new DinerDatabase();
var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (order != null)
{
context.Orders.Remove(order);
context.SaveChanges();
return order.GetViewModel;
}
return null;
}
}
}

View File

@@ -1,191 +0,0 @@
using Microsoft.EntityFrameworkCore;
using DinerContracts.BindingModels;
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using DinerDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerDatabaseImplement.Implements
{
public class ShopStorage : IShopStorage
{
public List<ShopViewModel> GetFullList()
{
using var context = new DinerDatabase();
return context.Shops.Include(x => x.Snacks).ThenInclude(x => x.Snack).ToList().
Select(x => x.GetViewModel).ToList();
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName))
{
return new();
}
using var context = new DinerDatabase();
return context.Shops.Include(x => x.Snacks).ThenInclude(x => x.Snack).Where(x => x.ShopName.Contains(model.ShopName)).
ToList().Select(x => x.GetViewModel).ToList();
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return new();
}
using var context = new DinerDatabase();
return context.Shops.Include(x => x.Snacks).ThenInclude(x => x.Snack)
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ShopViewModel? Insert(ShopBindingModel model)
{
using var context = new DinerDatabase();
var newShop = Shop.Create(context, model);
if (newShop == null)
{
return null;
}
context.Shops.Add(newShop);
context.SaveChanges();
return newShop.GetViewModel;
}
public ShopViewModel? Update(ShopBindingModel model)
{
using var context = new DinerDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var shop = context.Shops.FirstOrDefault(x => x.Id == model.Id);
if (shop == null)
{
return null;
}
shop.Update(model);
context.SaveChanges();
shop.UpdateSnacks(context, model);
transaction.Commit();
return shop.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public ShopViewModel? Delete(ShopBindingModel model)
{
using var context = new DinerDatabase();
var shop = context.Shops.Include(x => x.Snacks).FirstOrDefault(x => x.Id == model.Id);
if (shop != null)
{
context.Shops.Remove(shop);
context.SaveChanges();
return shop.GetViewModel;
}
return null;
}
public bool RestockingShops(SupplyBindingModel model)
{
using var context = new DinerDatabase();
var transaction = context.Database.BeginTransaction();
var Shops = context.Shops.Include(x => x.Snacks).ThenInclude(x => x.Snack).ToList().
Where(x => x.SnackMaxCount > x.ShopSnacks.Select(x => x.Value.Item2).Sum()).ToList();
if (model == null)
{
return false;
}
try
{
foreach (Shop shop in Shops)
{
int difference = shop.SnackMaxCount - shop.ShopSnacks.Select(x => x.Value.Item2).Sum();
int refill = Math.Min(difference, model.Count);
model.Count -= refill;
if (shop.ShopSnacks.ContainsKey(model.SnackId))
{
var datePair = shop.ShopSnacks[model.SnackId];
datePair.Item2 += refill;
shop.ShopSnacks[model.SnackId] = datePair;
}
else
{
var snack = context.Snacks.First(x => x.Id == model.SnackId);
shop.ShopSnacks.Add(model.SnackId, (snack, refill));
}
shop.SnacksDictionatyUpdate(context);
if (model.Count == 0)
{
transaction.Commit();
return true;
}
}
transaction.Rollback();
return false;
}
catch
{
transaction.Rollback();
throw;
}
}
public bool Sale(SupplySearchModel model)
{
using var context = new DinerDatabase();
var transaction = context.Database.BeginTransaction();
try
{
var shops = context.Shops.Include(x => x.Snacks).ThenInclude(x => x.Snack).ToList().
Where(x => x.ShopSnacks.ContainsKey(model.SnackId.Value)).OrderByDescending(x => x.ShopSnacks[model.SnackId.Value].Item2).ToList();
foreach (var shop in shops)
{
int residue = model.Count.Value - shop.ShopSnacks[model.SnackId.Value].Item2;
if (residue > 0)
{
shop.ShopSnacks.Remove(model.SnackId.Value);
shop.SnacksDictionatyUpdate(context);
context.SaveChanges();
model.Count = residue;
}
else
{
if (residue == 0)
shop.ShopSnacks.Remove(model.SnackId.Value);
else
{
var dataPair = shop.ShopSnacks[model.SnackId.Value];
dataPair.Item2 = -residue;
shop.ShopSnacks[model.SnackId.Value] = dataPair;
}
shop.SnacksDictionatyUpdate(context);
transaction.Commit();
return true;
}
}
transaction.Rollback();
return false;
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

View File

@@ -1,120 +0,0 @@
using DinerContracts.BindingModels;
using DinerContracts.ViewModels;
using DinerDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerDatabaseImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; set; }
public string ShopName { get; set; } = String.Empty;
public string Adress { get; set; } = String.Empty;
public DateTime OpeningDate { get; set; }
public int SnackMaxCount { get; set; }
private Dictionary<int, (ISnackModel, int)>? _shopSnacks = null;
public Dictionary<int, (ISnackModel, int)> ShopSnacks
{
get
{
if (_shopSnacks == null) {
if (_shopSnacks == null)
{
_shopSnacks = Snacks
.ToDictionary(recSP => recSP.SnackId, recSP => (recSP.Snack as ISnackModel, recSP.Count));
}
return _shopSnacks;
}
return _shopSnacks;
}
}
[ForeignKey("ShopId")]
public List<ShopSnacks> Snacks { get; set; } = new();
public static Shop Create(DinerDatabase context, ShopBindingModel model)
{
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Adress = model.Adress,
OpeningDate = model.OpeningDate,
Snacks = model.ShopSnacks.Select(x => new ShopSnacks
{
Snack = context.Snacks.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList(),
SnackMaxCount = model.SnackMaxCount
};
}
public void Update(ShopBindingModel model)
{
ShopName = model.ShopName;
Adress = model.Adress;
OpeningDate = model.OpeningDate;
SnackMaxCount = model.SnackMaxCount;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Adress = Adress,
OpeningDate = OpeningDate,
ShopSnacks = ShopSnacks,
SnackMaxCount = SnackMaxCount
};
public void UpdateSnacks(DinerDatabase context, ShopBindingModel model)
{
var ShopSnacks = context.ShopSnacks.Where(rec => rec.ShopId == model.Id).ToList();
if (ShopSnacks != null && this.ShopSnacks.Count > 0)
{
context.ShopSnacks.RemoveRange(ShopSnacks.Where(rec => !model.ShopSnacks.ContainsKey(rec.SnackId)));
context.SaveChanges();
ShopSnacks = context.ShopSnacks.Where(rec => rec.ShopId == model.Id).ToList();
foreach (var updateSnack in ShopSnacks)
{
updateSnack.Count = model.ShopSnacks[updateSnack.SnackId].Item2;
model.ShopSnacks.Remove(updateSnack.SnackId);
}
context.SaveChanges();
}
var shop = context.Shops.First(x => x.Id == Id);
foreach (var ar in model.ShopSnacks)
{
context.ShopSnacks.Add(new ShopSnacks
{
Shop = shop,
Snack = context.Snacks.First(x => x.Id == ar.Key),
Count = ar.Value.Item2
});
context.SaveChanges();
}
_shopSnacks = null;
}
public void SnacksDictionatyUpdate(DinerDatabase context)
{
UpdateSnacks(context, new ShopBindingModel
{
Id = Id,
ShopSnacks = ShopSnacks,
});
}
}
}

View File

@@ -1,27 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerDatabaseImplement.Models
{
public class ShopSnacks
{
public int Id { get; set; }
[Required]
public int SnackId { get; set; }
[Required]
public int ShopId { get; set; }
[Required]
public int Count { get; set; }
public virtual Shop Shop { get; set; } = new();
public virtual Snack Snack { get; set; } = new();
}
}

View File

@@ -3,18 +3,15 @@ using System.Xml.Linq;
namespace DinerFileImplement
{
public class DataFileSingleton
internal class DataFileSingleton
{
private static DataFileSingleton? instance;
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string SnackFileName = "Snack.xml";
private readonly string ShopFileName = "Shop.xml";
private readonly string ProductFileName = "Snack.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Snack> Snacks { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@@ -24,16 +21,13 @@ namespace DinerFileImplement
return instance;
}
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SaveSnacks() => SaveData(Snacks, SnackFileName, "Snacks", x => x.GetXElement);
public void SaveSnacks() => SaveData(Snacks, ProductFileName, "Snacks", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Snacks = LoadData(SnackFileName, "Snack", x => Snack.Create(x)!)!;
Snacks = LoadData(ProductFileName, "Snack", x => Snack.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{
@@ -50,6 +44,5 @@ namespace DinerFileImplement
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
}
}
}
}
}

View File

@@ -6,6 +6,15 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\AbstractShopContracts\DinerContracts.csproj" />
<ProjectReference Include="..\..\AbstractShopDataModels\DinerDataModels.csproj" />

View File

@@ -3,6 +3,11 @@ using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using DinerFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerFileImplement.Implements
{
@@ -15,7 +20,9 @@ namespace DinerFileImplement.Implements
}
public List<ComponentViewModel> GetFullList()
{
return source.Components.Select(x => x.GetViewModel).ToList();
return source.Components
.Select(x => x.GetViewModel)
.ToList();
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
@@ -23,7 +30,10 @@ namespace DinerFileImplement.Implements
{
return new();
}
return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList();
return source.Components
.Where(x => x.ComponentName.Contains(model.ComponentName))
.Select(x => x.GetViewModel)
.ToList();
}
public ComponentViewModel? GetElement(ComponentSearchModel model)
{
@@ -31,10 +41,9 @@ namespace DinerFileImplement.Implements
{
return null;
}
return source.Components.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
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)
{

View File

@@ -13,7 +13,28 @@ namespace DinerFileImplement.Implements
{
source = DataFileSingleton.GetInstance();
}
public List<OrderViewModel> GetFullList() => source.Orders.Select(x => AttachPizzaName(x.GetViewModel)).ToList();
public OrderViewModel? Delete(OrderBindingModel model)
{
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Orders.Remove(element);
source.SaveOrders();
return AttachSnackName(element.GetViewModel);
}
return null;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return AttachSnackName(source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel);
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
@@ -21,17 +42,16 @@ namespace DinerFileImplement.Implements
return new();
}
return source.Orders.Where(x => x.Id == model.Id)
.Select(x => AttachPizzaName(x.GetViewModel))
.Select(x => AttachSnackName(x.GetViewModel))
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
public List<OrderViewModel> GetFullList()
{
if (!model.Id.HasValue)
{
return new();
}
return AttachPizzaName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel);
return source.Orders
.Select(x => AttachSnackName(x.GetViewModel)).ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
{
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
@@ -42,8 +62,9 @@ namespace DinerFileImplement.Implements
}
source.Orders.Add(newOrder);
source.SaveOrders();
return AttachPizzaName(newOrder.GetViewModel);
return AttachSnackName(newOrder.GetViewModel);
}
public OrderViewModel? Update(OrderBindingModel model)
{
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
@@ -53,20 +74,9 @@ namespace DinerFileImplement.Implements
}
order.Update(model);
source.SaveOrders();
return AttachPizzaName(order.GetViewModel);
return AttachSnackName(order.GetViewModel);
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order != null)
{
source.Orders.Remove(order);
source.SaveOrders();
return AttachPizzaName(order.GetViewModel);
}
return null;
}
private OrderViewModel? AttachPizzaName(OrderViewModel? model)
private OrderViewModel? AttachSnackName(OrderViewModel? model)
{
if (model == null)
{
@@ -80,5 +90,4 @@ namespace DinerFileImplement.Implements
return model;
}
}
}

View File

@@ -1,144 +0,0 @@
using DinerContracts.BindingModels;
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
using DinerFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerFileImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataFileSingleton source;
public ShopStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<ShopViewModel> GetFullList()
{
return source.Shops.Select(x=>x.GetViewModel).ToList();
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName))
{
return new();
}
return source.Shops.Where(x=>x.ShopName.Contains(model.ShopName)).Select(x=>x.GetViewModel).ToList();
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return null;
}
return source.Shops.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ShopViewModel? Insert(ShopBindingModel model)
{
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
var newShop = Shop.Create(model);
if (newShop == null)
{
return null;
}
source.Shops.Add(newShop);
source.SaveShops();
return newShop.GetViewModel;
}
public ShopViewModel? Update(ShopBindingModel model)
{
var shop = source.Shops.FirstOrDefault(x=>x.Id == model.Id);
if(shop == null)
{
return null;
}
shop.Update(model);
source.SaveShops();
return shop.GetViewModel;
}
public ShopViewModel? Delete(ShopBindingModel model)
{
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if(shop != null)
{
source.Shops.Remove(shop);
source.SaveShops();
return shop.GetViewModel;
}
return null;
}
public bool Sale(SupplySearchModel model) {
if (model == null || !model.SnackId.HasValue || !model.Count.HasValue)
return false;
int remainingSpace = source.Shops.Select(x => x.Snacks.ContainsKey(model.SnackId.Value) ? x.Snacks[model.SnackId.Value] : 0).Sum();
if(remainingSpace < model.Count)
{
return false;
}
var shops = source.Shops.Where(x => x.Snacks.ContainsKey(model.SnackId.Value)).OrderByDescending(x => x.Snacks[model.SnackId.Value]).ToList();
foreach (var shop in shops)
{
int residue = model.Count.Value - shop.Snacks[model.SnackId.Value];
if (residue > 0)
{
shop.Snacks.Remove(model.SnackId.Value);
shop.SnackUpdate();
model.Count = residue;
}
else
{
if (residue == 0)
{
shop.Snacks.Remove(model.SnackId.Value);
}
else
{
shop.Snacks[model.SnackId.Value] = -residue;
}
shop.SnackUpdate();
source.SaveShops();
return true;
}
}
source.SaveShops();
return false;
}
public bool RestockingShops(SupplyBindingModel model)
{
if (model==null || source.Shops.Select(x => x.SnackMaxCount - x.ShopSnacks.Select(y => y.Value.Item2).Sum()).Sum() < model.Count)
{
return false;
}
foreach (Shop shop in source.Shops)
{
int free_places = shop.SnackMaxCount - shop.ShopSnacks.Select(x => x.Value.Item2).Sum();
if (free_places <= 0)
continue;
free_places = Math.Min(free_places, model.Count);
model.Count -= free_places;
if (shop.Snacks.ContainsKey(model.SnackId))
{
shop.Snacks[model.SnackId] += free_places;
}
else
{
shop.Snacks.Add(model.SnackId, free_places);
}
shop.SnackUpdate();
if (model.Count == 0)
{
source.SaveShops();
return true;
}
}
return false;
}
}
}

View File

@@ -13,29 +13,48 @@ namespace DinerFileImplement.Implements
{
source = DataFileSingleton.GetInstance();
}
public List<SnackViewModel> GetFullList()
public SnackViewModel? Delete(SnackBindingModel model)
{
return source.Snacks.Select(x => x.GetViewModel).ToList();
}
public List<SnackViewModel> GetFilteredList(SnackSearchModel model)
{
if (string.IsNullOrEmpty(model.SnackName))
var element = source.Snacks.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
return new();
source.Snacks.Remove(element);
source.SaveSnacks();
return element.GetViewModel;
}
return source.Snacks.Where(x => x.SnackName.Contains(model.SnackName)).Select(x => x.GetViewModel).ToList();
return null;
}
public SnackViewModel? GetElement(SnackSearchModel model)
{
if (string.IsNullOrEmpty(model.SnackName) && !model.Id.HasValue)
{
return null;
}
return source.Snacks.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.SnackName) && x.SnackName == model.SnackName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
return source.Snacks
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SnackName) && x.SnackName == model.SnackName) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<SnackViewModel> GetFilteredList(SnackSearchModel model)
{
if (string.IsNullOrEmpty(model.SnackName))
{
return new();
}
return source.Snacks
.Where(x => x.SnackName.Contains(model.SnackName))
.Select(x => x.GetViewModel)
.ToList();
}
public List<SnackViewModel> GetFullList()
{
return source.Snacks
.Select(x => x.GetViewModel)
.ToList();
}
public SnackViewModel? Insert(SnackBindingModel model)
{
model.Id = source.Snacks.Count > 0 ? source.Snacks.Max(x => x.Id) + 1 : 1;
@@ -48,27 +67,19 @@ namespace DinerFileImplement.Implements
source.SaveSnacks();
return newSnack.GetViewModel;
}
public SnackViewModel? Update(SnackBindingModel model)
{
var Snack = source.Snacks.FirstOrDefault(x => x.Id == model.Id);
if (Snack == null)
var element = source.Snacks.FirstOrDefault(x => x.Id == model.Id);
if (element == null)
{
return null;
}
Snack.Update(model);
element.Update(model);
source.SaveSnacks();
return Snack.GetViewModel;
}
public SnackViewModel? Delete(SnackBindingModel model)
{
var Snack = source.Snacks.FirstOrDefault(x => x.Id == model.Id);
if (Snack != null)
{
source.Snacks.Remove(Snack);
source.SaveSnacks();
return Snack.GetViewModel;
}
return null;
return element.GetViewModel;
}
}
}

View File

@@ -52,8 +52,8 @@ namespace DinerFileImplement.Models
Cost = Cost
};
public XElement GetXElement => new("Component",
new XAttribute("Id", Id),
new XElement("ComponentName", ComponentName),
new XElement("Cost", Cost.ToString()));
new XAttribute("Id", Id),
new XElement("ComponentName", ComponentName),
new XElement("Cost", Cost.ToString()));
}
}
}

View File

@@ -1,7 +1,7 @@
using DinerDataModels.Enum;
using DinerDataModels.Models;
using DinerContracts.BindingModels;
using DinerContracts.BindingModels;
using DinerContracts.ViewModels;
using DinerDataModels.Enum;
using DinerDataModels.Models;
using System.Xml.Linq;
namespace DinerFileImplement.Models
@@ -9,11 +9,16 @@ namespace DinerFileImplement.Models
public class Order : IOrderModel
{
public int Id { get; private set; }
public int SnackId { get; private set; }
public int SnackID { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now;
public OrderStatus Status { get; private set; }
public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
@@ -24,12 +29,12 @@ namespace DinerFileImplement.Models
return new Order()
{
Id = model.Id,
SnackId = model.SnackId,
SnackID = model.SnackId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
DateImplement = model.DateImplement
};
}
public static Order? Create(XElement element)
@@ -38,18 +43,18 @@ namespace DinerFileImplement.Models
{
return null;
}
string dateImplement = element.Element("DateImplement")!.Value;
return new Order()
var order = new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
SnackId = Convert.ToInt32(element.Element("SnackId")!.Value),
SnackID = Convert.ToInt32(element.Element("SnackID")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = (dateImplement == "" || dateImplement is null) ? Convert.ToDateTime(null) : Convert.ToDateTime(dateImplement)
};
DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime _dateImplement);
order.DateImplement = _dateImplement;
return order;
}
public void Update(OrderBindingModel? model)
{
@@ -57,27 +62,28 @@ namespace DinerFileImplement.Models
{
return;
}
Status = model.Status;
if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
SnackId = SnackId,
SnackId = SnackID,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
DateImplement = DateImplement
};
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("SnackId", SnackId.ToString()),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()),
new XElement("DateImplement", DateImplement.ToString()));
new XAttribute("Id", Id),
new XElement("SnackID", SnackID.ToString()),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()),
new XElement("DateImplement", DateImplement?.ToString())
);
}
}

View File

@@ -1,102 +0,0 @@
using DinerDataModels.Models;
using DinerContracts.BindingModels;
using DinerContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace DinerFileImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; private set; }
public string ShopName { get; private set; } = string.Empty;
public string Adress { get; private set; } = string.Empty;
public DateTime OpeningDate { get; private set; }
public Dictionary<int, int> Snacks { get; private set; } = new();
private Dictionary<int, (ISnackModel, int)>? _shopSnacks = null;
public Dictionary<int, (ISnackModel, int)> ShopSnacks {
get {
if (_shopSnacks == null)
{
var source = DataFileSingleton.GetInstance();
_shopSnacks = Snacks.ToDictionary(x => x.Key, y => ((source.Snacks.FirstOrDefault(z => z.Id == y.Key) as ISnackModel)!, y.Value));
}
return _shopSnacks;
}
}
public int SnackMaxCount { get; private set; }
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Adress = model.Adress,
OpeningDate = model.OpeningDate,
Snacks = model.ShopSnacks.ToDictionary(x => x.Key, x => x.Value.Item2),
SnackMaxCount = model.SnackMaxCount
};
}
public static Shop? Create(XElement element)
{
if (element == null)
{
return null;
}
return new()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ShopName = element.Element("ShopName")!.Value,
Adress = element.Element("Adress")!.Value,
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
Snacks = element.Element("ShopSnacks")!.Elements("ShopSnack")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value)),
SnackMaxCount = Convert.ToInt32(element.Element("SnackMaxCount")!.Value)
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Adress = model.Adress;
OpeningDate = model.OpeningDate;
SnackMaxCount = model.SnackMaxCount;
Snacks = model.ShopSnacks.ToDictionary(x => x.Key, x => x.Value.Item2);
_shopSnacks = null;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Adress = Adress,
OpeningDate = OpeningDate,
ShopSnacks = ShopSnacks,
SnackMaxCount = SnackMaxCount
};
public XElement GetXElement => new("Shop",
new XAttribute("Id", Id),
new XElement("ShopName",ShopName),
new XElement("Adress", Adress),
new XElement("OpeningDate", OpeningDate.ToString()),
new XElement("ShopSnacks", Snacks.Select(
x => new XElement("ShopSnack", new XElement("Key",x.Key),new XElement("Value",x.Value))).ToArray()),
new XElement("SnackMaxCount", SnackMaxCount.ToString())
);
public void SnackUpdate() {
_shopSnacks = null;
}
}
}

View File

@@ -49,8 +49,10 @@ namespace DinerFileImplement.Models
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
SnackName = element.Element("SnackName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
Components = element.Element("SnackComponents")!.Elements("SnackComponent").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value))
Components = element.Element("SnackComponents")!.Elements("SnackComponent")
.ToDictionary(x =>
Convert.ToInt32(x.Element("Key")?.Value), x =>
Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(SnackBindingModel model)
@@ -72,10 +74,13 @@ namespace DinerFileImplement.Models
SnackComponents = SnackComponents
};
public XElement GetXElement => new("Snack",
new XAttribute("Id", Id),
new XElement("SnackName", SnackName),
new XElement("Price", Price.ToString()),
new XElement("SnackComponents", Components.Select(
x => new XElement("SnackComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()));
new XAttribute("Id", Id),
new XElement("SnackName", SnackName),
new XElement("Price", Price.ToString()),
new XElement("SnackComponents", Components.Select(x =>
new XElement("SnackComponent",
new XElement("Key", x.Key),
new XElement("Value", x.Value)))
.ToArray()));
}
}