Compare commits

...

32 Commits

Author SHA1 Message Date
d3ff902275 OnlyMyCode 2024-04-04 22:25:08 +04:00
ecb8f9287a Merge pull request 'Lab3Update magic' (#12) from Lab3Update into Lab3-Hard
Reviewed-on: #12
2024-04-04 19:54:28 +04:00
10e49e048a Context 2024-03-22 00:06:07 +04:00
a420278bcb NameChecker 2024-03-22 00:02:47 +04:00
ac8618e3e5 BaseUpdate 2024-03-09 09:52:08 +04:00
01f88864c8 AllCommit 2024-03-08 14:55:42 +04:00
f134d1fb63 Finish hard 2024-03-06 17:03:40 +04:00
a0f9235e3d SomeDoing 2024-03-05 21:02:14 +04:00
f973e8af40 Merge pull request 'Lab1-Hard-Lab2-Hard' (#5) from Lab1-Hard into Lab2-Hard
Reviewed-on: #5
2024-03-05 14:34:46 +04:00
880272b84d RemoveConflict 2024-03-05 14:34:27 +04:00
807b93dd34 TestSave 2024-03-05 14:05:17 +04:00
527a8e2931 save base 2024-03-05 14:02:54 +04:00
4be2cfc5a4 name2 2024-02-24 10:22:10 +04:00
a91928a1ac name1 2024-02-24 10:17:19 +04:00
32bd22a63e Naming Update plus log 2024-02-24 10:15:21 +04:00
e9f8e389ff make it better 2024-02-24 10:02:06 +04:00
a37c33399e DateUpdate 2024-02-24 09:21:12 +04:00
c8d59d9fbc dress 2024-02-24 08:42:24 +04:00
a84b866e0f DoubleUpdate 2024-02-24 08:37:46 +04:00
d1e32b3dca orderChange 2024-02-24 08:25:45 +04:00
3ed13c865c singleton 2024-02-24 08:22:23 +04:00
bf1eaebd1c 1 2024-02-24 08:10:44 +04:00
626b501cda FormUpdate 2024-02-24 08:05:42 +04:00
5e39f7cd00 OrderUpdate 2024-02-23 20:20:44 +04:00
c64d5f465a updateOrder 2024-02-23 20:20:16 +04:00
67452aaa46 orderUpdate 2024-02-23 20:19:36 +04:00
13eaa58145 WithoutNaming 2024-02-23 20:02:16 +04:00
b8e31eb308 HardFinal 2024-02-23 17:16:11 +04:00
4720434f98 UpdateCommit 2024-02-21 17:38:19 +04:00
eb19e42237 OrderCheck 2024-02-20 19:33:08 +04:00
eec33dadc4 savecommit 2024-02-20 19:32:55 +04:00
58ffae6460 Проверка коммит 2024-02-20 16:32:44 +04:00
106 changed files with 8585 additions and 0 deletions

View File

@ -0,0 +1,61 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34009.444
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SewingDressesContracts", "SewingDressesContracts\SewingDressesContracts.csproj", "{2E3AE66A-3036-4B42-BD1B-B58B70C4F581}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SewingDressesDataModels", "SewingDressesDataModels\SewingDressesDataModels.csproj", "{317807C6-FB9B-4330-BC13-97F997FCC34D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SewingDressesView", "SewingDressesView\SewingDressesView.csproj", "{E39E6495-2356-4AF8-8C24-C2C5E113341B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SewingDressesBusinessLogic", "SewingDressesBusinessLogic\SewingDressesBusinessLogic.csproj", "{3A0DDBD6-0799-4047-A316-C1EEC0F24DFE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SewingDressesListImplement", "SewingDressesListImplement\SewingDressesListImplement.csproj", "{0F2DC551-6221-4471-BBAA-C5C65E45E66C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SewingDressesFileImplement", "SewingDressesFileImplement\SewingDressesFileImplement.csproj", "{340D02B6-5B03-47A2-8498-BB7DBBCB7F5B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SewingDressesDatabaseImplement", "SewingDressesDatabaseImplement\SewingDressesDatabaseImplement.csproj", "{A3420FD5-1798-447D-957E-6455474228CC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2E3AE66A-3036-4B42-BD1B-B58B70C4F581}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E3AE66A-3036-4B42-BD1B-B58B70C4F581}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E3AE66A-3036-4B42-BD1B-B58B70C4F581}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E3AE66A-3036-4B42-BD1B-B58B70C4F581}.Release|Any CPU.Build.0 = Release|Any CPU
{317807C6-FB9B-4330-BC13-97F997FCC34D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{317807C6-FB9B-4330-BC13-97F997FCC34D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{317807C6-FB9B-4330-BC13-97F997FCC34D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{317807C6-FB9B-4330-BC13-97F997FCC34D}.Release|Any CPU.Build.0 = Release|Any CPU
{E39E6495-2356-4AF8-8C24-C2C5E113341B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E39E6495-2356-4AF8-8C24-C2C5E113341B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E39E6495-2356-4AF8-8C24-C2C5E113341B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E39E6495-2356-4AF8-8C24-C2C5E113341B}.Release|Any CPU.Build.0 = Release|Any CPU
{3A0DDBD6-0799-4047-A316-C1EEC0F24DFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A0DDBD6-0799-4047-A316-C1EEC0F24DFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A0DDBD6-0799-4047-A316-C1EEC0F24DFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A0DDBD6-0799-4047-A316-C1EEC0F24DFE}.Release|Any CPU.Build.0 = Release|Any CPU
{0F2DC551-6221-4471-BBAA-C5C65E45E66C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F2DC551-6221-4471-BBAA-C5C65E45E66C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F2DC551-6221-4471-BBAA-C5C65E45E66C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F2DC551-6221-4471-BBAA-C5C65E45E66C}.Release|Any CPU.Build.0 = Release|Any CPU
{340D02B6-5B03-47A2-8498-BB7DBBCB7F5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{340D02B6-5B03-47A2-8498-BB7DBBCB7F5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{340D02B6-5B03-47A2-8498-BB7DBBCB7F5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{340D02B6-5B03-47A2-8498-BB7DBBCB7F5B}.Release|Any CPU.Build.0 = Release|Any CPU
{A3420FD5-1798-447D-957E-6455474228CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3420FD5-1798-447D-957E-6455474228CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3420FD5-1798-447D-957E-6455474228CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3420FD5-1798-447D-957E-6455474228CC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F9D79E6E-C2A7-4432-B00F-6B4E5F173DD5}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,115 @@
using Microsoft.Extensions.Logging;
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
namespace SewingDressesBusinessLogic.BusinessLogic
{
public class ComponentLogic : IComponentLogic
{
private readonly ILogger _logger;
private readonly IComponentStorage _componentStorage;
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
{
_logger = logger;
_componentStorage = componentStorage;
}
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
{
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{Id}", model?.ComponentName, model?.Id);
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ComponentViewModel? ReadElement(ComponentSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{Id}", model.ComponentName, model.Id);
var element = _componentStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(ComponentBindingModel model)
{
CheckModel(model);
if (_componentStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ComponentBindingModel model)
{
CheckModel(model);
if (_componentStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ComponentBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_componentStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ComponentBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ComponentName))
{
throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName));
}
if (model.Cost <= 0)
{
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
}
_logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{Cost}. Id:{Id}", model.ComponentName, model.Cost, model.Id);
var element = _componentStorage.GetElement(new ComponentSearchModel
{
ComponentName = model.ComponentName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Компонент с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,111 @@
using Microsoft.Extensions.Logging;
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
namespace SewingDressesBusinessLogic.BusinessLogic
{
public class DressLogic : IDressLogic
{
private readonly ILogger _logger;
private readonly IDressStorage _dressStorage;
public DressLogic(ILogger<DressLogic> logger, IDressStorage dressStorage)
{
_logger = logger;
_dressStorage = dressStorage;
}
public List<DressViewModel>? ReadList(DressSearchModel? model)
{
_logger.LogInformation("ReadList. DressName:{DressName}. Id:{Id}", model?.DressName, model?.Id);
var list = model == null ? _dressStorage.GetFullList() : _dressStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public DressViewModel? ReadElement(DressSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. DressName:{DressName}. Id: {Id}", model.DressName, model.Id);
var element = _dressStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
private void CheckModel(DressBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.DressName))
{
throw new ArgumentNullException("Нет названия платья", nameof(model.DressComponents));
}
if (model.Price <= 0)
{
throw new ArgumentNullException("Цена платья должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Dress. DressName:{DressName}. Price:{Price}. Id:{Id}", model.DressName, model.Price, model.Id);
var element = _dressStorage.GetElement(new DressSearchModel
{
DressName = model.DressName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Платье с таким названием уже есть");
}
}
public bool Create(DressBindingModel model)
{
CheckModel(model);
if (_dressStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(DressBindingModel model)
{
CheckModel(model);
if (_dressStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(DressBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_dressStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
}
}

View File

@ -0,0 +1,184 @@
using Microsoft.Extensions.Logging;
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Enums;
using SewingDressesDataModels.Models;
using System.Collections.Specialized;
namespace SewingDressesBusinessLogic.BusinessLogic
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
private readonly IShopStorage _shopStorage;
private readonly IShopLogic _shopLogic;
private readonly IDressStorage _dressStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IDressStorage dressStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_shopStorage = shopStorage;
_shopLogic = shopLogic;
_dressStorage = dressStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
private void CheckModel(OrderBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (model.Count <= 0)
{
throw new ArgumentNullException("Количество заказов должно быть больше нуля");
}
if (model.Sum <= 0)
{
throw new ArgumentNullException("Цена заказа должна быть больше нуля");
}
_logger.LogInformation("Order. OrderId:{Id}. Sum:{Sum}", model.Id, model.Sum);
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Неизвестен)
{
return false;
}
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
private bool ChangeStatus(OrderBindingModel model, OrderStatus status)
{
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (element == null)
{
_logger.LogWarning("Find order failed");
return false;
}
if (element.Status != status-1)
{
_logger.LogWarning("Status change failed");
throw new InvalidOperationException("Невозможно перевести состояние заказа");
}
if (status == OrderStatus.Готов)
{
var dress = _dressStorage.GetElement(new DressSearchModel() { Id = model.DressId });
if (dress == null)
{
_logger.LogWarning("Status change error. Dress not found");
return false;
}
if (!CheckSupply(dress, model.Count))
{
_logger.LogWarning("Status change error. Shop doesnt have dresses");
return false;
}
}
model.Status = status;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
_orderStorage.Update(model);
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return ChangeStatus(model, OrderStatus.Выполняется);
}
public bool FinishOrder(OrderBindingModel model)
{
return ChangeStatus(model, OrderStatus.Готов);
}
public bool DeliveryOrder(OrderBindingModel model)
{
return ChangeStatus(model, OrderStatus.Выдан);
}
public bool CheckSupply(IDressModel dress, int count)
{
if (count <= 0)
{
_logger.LogWarning("Check supply operation error. Dress count < 0");
return false;
}
int sumCapacity = _shopStorage.GetFullList().Select(x => x.MaxCount).Sum();
int sumCount = _shopStorage.GetFullList().Select(x => x.ShopDresses.Select(y => y.Value.Item2).Sum()).Sum();
int free = sumCapacity - sumCount;
if (free < count)
{
_logger.LogWarning("Check supply error. No place for new Dresses");
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
free = shop.MaxCount;
foreach (var doc in shop.ShopDresses)
{
free -= doc.Value.Item2;
}
if (free == 0)
{
continue;
}
if (free >= count)
{
if (_shopLogic.MakeSupply(new()
{
Id = shop.Id
}, dress, count))
{
count = 0;
}
else
{
_logger.LogWarning("Supply error");
return false;
}
}
else
{
if (_shopLogic.MakeSupply(new() { Id = shop.Id}, dress, free))
count -= free;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (count <= 0)
{
return true;
}
}
return false;
}
}
}

View File

@ -0,0 +1,170 @@
using Microsoft.Extensions.Logging;
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesBusinessLogic.BusinessLogic
{
public class ShopLogic : IShopLogic
{
private readonly ILogger _logger;
private readonly IShopStorage _shopStorage;
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage)
{
_logger = logger;
_shopStorage = shopStorage;
}
public List<ShopViewModel> ReadList(ShopSearchModel model)
{
_logger.LogInformation("ReadList. ShopName:{Name}. Id:{ Id}", model?.Name, 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.Name, 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;
}
private void CheckModel(ShopBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ShopName))
{
throw new ArgumentNullException("Нет названия магазина",
nameof(model.ShopName));
}
if (string.IsNullOrEmpty(model.Adress))
{
throw new ArgumentNullException("Нет адресса магазина",
nameof(model.ShopName));
}
if (model.DateOpen == null)
{
throw new ArgumentNullException("Нет даты открытия магазина",
nameof(model.ShopName));
}
_logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}", model.ShopName, model.Adress, model.DateOpen, model.Id);
var element = _shopStorage.GetElement(new ShopSearchModel
{
Name = model.ShopName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
public bool MakeSell(IDressModel model, int count)
{
return _shopStorage.SellDresses(model, count);
}
public bool MakeSupply(ShopSearchModel model, IDressModel dress, int count)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (dress == null)
throw new ArgumentNullException(nameof(dress));
if (count <= 0)
throw new ArgumentNullException("Количество должно быть положительным числом");
ShopViewModel? curModel = _shopStorage.GetElement(model);
_logger.LogInformation("Make Supply. Id: {Id}. ShopName: {Name}",model.Id, model.Name);
if (curModel == null)
throw new ArgumentNullException(nameof(curModel));
var countItems = curModel.ShopDresses.Select(x => x.Value.Item2).Sum();
if (curModel.MaxCount - countItems < count)
{
_logger.LogWarning("Shop is overflowed");
return false;
}
if (curModel.ShopDresses.TryGetValue(dress.Id, out var pair))
{
curModel.ShopDresses[dress.Id] = (pair.Item1, pair.Item2 + count);
_logger.LogInformation("Make Supply. Add Dress. ShopName: {ShopName}. DressName: {Name}. Count: {Count}", curModel.ShopName, pair.Item1, count + pair.Item2);
}
else
{
curModel.ShopDresses.Add(dress.Id, (dress, count));
_logger.LogInformation("Make Supply. Add new Dress. ShopName: {ShopName}. DressName: {Name}. Count: {Count}", curModel.ShopName, pair.Item1, count);
}
return Update(new()
{
Id = curModel.Id,
ShopName = curModel.ShopName,
DateOpen = curModel.DateOpen,
MaxCount = curModel.MaxCount,
Adress = curModel.Adress,
ShopDresses = curModel.ShopDresses,
});
}
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SewingDressesContracts\SewingDressesContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,11 @@
using SewingDressesDataModels.Models;
namespace SewingDressesContracts.BindingModels
{
public class ComponentBindingModel : IComponentModel
{
public int Id { get; set; }
public string ComponentName { get; set; } = string.Empty;
public double Cost { get; set; }
}
}

View File

@ -0,0 +1,12 @@
using SewingDressesDataModels.Models;
namespace SewingDressesContracts.BindingModels
{
public class DressBindingModel : IDressModel
{
public int Id { get; set; }
public string DressName { get; set; } = string.Empty;
public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> DressComponents { get; set; } = new();
}
}

View File

@ -0,0 +1,16 @@
using SewingDressesDataModels.Models;
using SewingDressesDataModels.Enums;
namespace SewingDressesContracts.BindingModels
{
public class OrderBindingModel : IOrderModel
{
public int Id { get; set; }
public int DressId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using SewingDressesDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesContracts.BindingModels
{
public class ShopBindingModel : IShopModel
{
public int Id { get; set; }
public string ShopName { get; set; }
public string Adress { get; set; }
public DateTime DateOpen { get; set; }
public int MaxCount { get; set; }
public Dictionary<int, (IDressModel, int)> ShopDresses { get; set; } = new();
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.ViewModels;
namespace SewingDressesContracts.BusinessLogicsContracts
{
public interface IComponentLogic
{
List<ComponentViewModel>? ReadList(ComponentSearchModel? model);
ComponentViewModel? ReadElement(ComponentSearchModel model);
bool Create(ComponentBindingModel model);
bool Update(ComponentBindingModel model);
bool Delete(ComponentBindingModel model);
}
}

View File

@ -0,0 +1,15 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.ViewModels;
namespace SewingDressesContracts.BusinessLogicsContracts
{
public interface IDressLogic
{
List<DressViewModel>? ReadList(DressSearchModel? model);
DressViewModel? ReadElement(DressSearchModel? model);
bool Create(DressBindingModel? model);
bool Update(DressBindingModel? model);
bool Delete(DressBindingModel? model);
}
}

View File

@ -0,0 +1,15 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.ViewModels;
namespace SewingDressesContracts.BusinessLogicsContracts
{
public interface IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
bool DeliveryOrder(OrderBindingModel model);
}
}

View File

@ -0,0 +1,23 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesContracts.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(ShopSearchModel model, IDressModel dress, int count);
bool MakeSell(IDressModel model, int count);
}
}

View File

@ -0,0 +1,8 @@
namespace SewingDressesContracts.SearchModels
{
public class ComponentSearchModel
{
public int? Id { get; set; }
public string? ComponentName { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace SewingDressesContracts.SearchModels
{
public class DressSearchModel
{
public int? Id { get; set; }
public string? DressName { get; set; }
}
}

View File

@ -0,0 +1,7 @@
namespace SewingDressesContracts.SearchModels
{
public class OrderSearchModel
{
public int? Id { get; set; }
}
}

View File

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

View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Nlog" Version="5.2.8" />
<PackageReference Include="Nlog.Extensions" Version="1.0.1" />
<PackageReference Include="Nlog.Extensions.Logging" Version="5.3.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SewingDressesDataModels\SewingDressesDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,16 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.ViewModels;
namespace SewingDressesContracts.StoragesContracts
{
public interface IComponentStorage
{
List<ComponentViewModel> GetFullList();
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
ComponentViewModel? GetElement(ComponentSearchModel model);
ComponentViewModel? Insert(ComponentBindingModel model);
ComponentViewModel? Update(ComponentBindingModel model);
ComponentViewModel? Delete(ComponentBindingModel model);
}
}

View File

@ -0,0 +1,16 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.ViewModels;
namespace SewingDressesContracts.StoragesContracts
{
public interface IDressStorage
{
List<DressViewModel> GetFullList();
List<DressViewModel> GetFilteredList(DressSearchModel model);
DressViewModel? GetElement(DressSearchModel model);
DressViewModel? Insert(DressBindingModel model);
DressViewModel? Update(DressBindingModel model);
DressViewModel? Delete(DressBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.ViewModels;
namespace SewingDressesContracts.StoragesContracts
{
public interface IOrderStorage
{
List<OrderViewModel> GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
OrderViewModel? GetElement(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
}
}

View File

@ -0,0 +1,23 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesContracts.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 SellDresses(IDressModel model, int count);
}
}

View File

@ -0,0 +1,14 @@
using SewingDressesDataModels.Models;
using System.ComponentModel;
namespace SewingDressesContracts.ViewModels
{
public class ComponentViewModel : IComponentModel
{
public int Id { get; set; }
[DisplayName("Название компонента")]
public string ComponentName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Cost { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System.ComponentModel;
using SewingDressesDataModels.Models;
namespace SewingDressesContracts.ViewModels
{
public class DressViewModel : IDressModel
{
public int Id { get; set; }
[DisplayName("Название платья")]
public string DressName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> DressComponents { get; set; } = new();
}
}

View File

@ -0,0 +1,25 @@
using System.ComponentModel;
using SewingDressesDataModels.Enums;
using SewingDressesDataModels.Models;
namespace SewingDressesContracts.ViewModels
{
public class OrderViewModel : IOrderModel
{
[DisplayName("Номер")]
public int Id { get; set; }
public int DressId { get; set; }
[DisplayName("Платье")]
public string DressName { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }
[DisplayName("Сумма")]
public double Sum { get; set; }
[DisplayName("Статус")]
public OrderStatus Status { get; set; }
[DisplayName("Дата создания")]
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; }
}
}

View File

@ -0,0 +1,24 @@
using SewingDressesDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesContracts.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 DateOpen { get; set; }
[DisplayName("Вмещаемость")]
public int MaxCount { get; set; }
public Dictionary<int, (IDressModel, int)> ShopDresses { get; set; } = new();
}
}

View File

@ -0,0 +1,11 @@
namespace SewingDressesDataModels.Enums
{
public enum OrderStatus
{
Неизвестен = -1,
Принят = 0,
Выполняется = 1,
Готов = 2,
Выдан = 3
}
}

View File

@ -0,0 +1,7 @@
namespace SewingDressesDataModels
{
public interface IId
{
int Id { get; }
}
}

View File

@ -0,0 +1,8 @@
namespace SewingDressesDataModels.Models
{
public interface IComponentModel : IId
{
string ComponentName { get; }
double Cost { get; }
}
}

View File

@ -0,0 +1,9 @@
namespace SewingDressesDataModels.Models
{
public interface IDressModel : IId
{
string DressName { get; }
double Price { get; }
Dictionary<int, (IComponentModel, int)> DressComponents { get; }
}
}

View File

@ -0,0 +1,14 @@
using SewingDressesDataModels.Enums;
namespace SewingDressesDataModels.Models
{
public interface IOrderModel : IId
{
int DressId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }
DateTime DateCreate { get; }
DateTime? DateImplement { get; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesDataModels.Models
{
public interface IShopModel : IId
{
string ShopName { get; }
string Adress { get; }
DateTime DateOpen { get; }
int MaxCount { get; }
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,70 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesDatabaseImplement.Models;
namespace SewingDressesDatabaseImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
public List<ComponentViewModel> GetFullList()
{
using var context = new SewingDressesDatabase();
return context.Components.Select(x => x.GetViewModel).ToList();
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName))
{
return new();
}
using var context = new SewingDressesDatabase();
return context.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList();
}
public ComponentViewModel? GetElement(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
{
return null;
}
using var context = new SewingDressesDatabase();
return context.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ComponentViewModel? Insert(ComponentBindingModel model)
{
var newComponent = Component.Create(model);
if (newComponent == null)
{
return null;
}
using var context = new SewingDressesDatabase();
context.Components.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel model)
{
using var context = new SewingDressesDatabase();
var component = context.Components.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
public ComponentViewModel? Delete(ComponentBindingModel model)
{
using var context = new SewingDressesDatabase();
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
if (element == null )
{
return null;
}
context.Components.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
}
}

View File

@ -0,0 +1,90 @@
using Microsoft.EntityFrameworkCore;
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesDatabaseImplement.Models;
namespace SewingDressesDatabaseImplement.Implements
{
public class DressStorage : IDressStorage
{
public List<DressViewModel> GetFullList()
{
using var context = new SewingDressesDatabase();
return context.Dresses.Include(x => x.Components).ThenInclude(x => x.Component).ToList().Select(x => x.GetViewModel).ToList();
}
public List<DressViewModel> GetFilteredList(DressSearchModel model)
{
if (string.IsNullOrEmpty(model.DressName))
{
return new();
}
using var context = new SewingDressesDatabase();
return context.Dresses.Include(x => x.Components).ThenInclude(x => x.Component).Where(x => x.DressName.Contains(model.DressName)).ToList().Select(x => x.GetViewModel).ToList();
}
public DressViewModel? GetElement(DressSearchModel model)
{
if (string.IsNullOrEmpty(model.DressName) &&
!model.Id.HasValue)
{
return null;
}
using var context = new SewingDressesDatabase();
return context.Dresses.Include(x => x.Components).ThenInclude(x => x.Component)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DressName) && x.DressName == model.DressName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public DressViewModel? Insert(DressBindingModel model)
{
using var context = new SewingDressesDatabase();
var newDress = Dress.Create(context, model);
if (newDress == null)
{
return null;
}
context.Dresses.Add(newDress);
context.SaveChanges();
return newDress.GetViewModel;
}
public DressViewModel? Update(DressBindingModel model)
{
using var context = new SewingDressesDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var dress = context.Dresses.FirstOrDefault(rec =>
rec.Id == model.Id);
if (dress == null)
{
return null;
}
dress.Update(model);
context.SaveChanges();
dress.UpdateComponents(context, model);
transaction.Commit();
return dress.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public DressViewModel? Delete(DressBindingModel model)
{
using var context = new SewingDressesDatabase();
var element = context.Dresses
.Include(x => x.Components)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Dresses.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,89 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesDatabaseImplement.Models;
namespace SewingDressesDatabaseImplement.Implements
{
public class OrderStorage : IOrderStorage
{
public List<OrderViewModel?> GetFullList()
{
using var context = new SewingDressesDatabase();
return context.Orders.Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList();
}
public List<OrderViewModel?> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
using var context = new SewingDressesDatabase();
return context.Orders.Where(x => x.Id == model.Id).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new SewingDressesDatabase();
return AcessDressesStorage(context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel, context);
}
public OrderViewModel? Insert(OrderBindingModel model)
{
var order = Order.Create(model);
if (order == null)
{
return null;
}
using var context = new SewingDressesDatabase();
context.Orders.Add(order);
context.SaveChanges();
return AcessDressesStorage(order.GetViewModel, context);
}
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new SewingDressesDatabase();
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
context.SaveChanges();
return AcessDressesStorage(order.GetViewModel, context);
}
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new SewingDressesDatabase();
var element = context.Orders.FirstOrDefault(x => x.Id == model.Id);
if (element == null)
{
return null;
}
context.Orders.Remove(element);
context.SaveChanges();
return AcessDressesStorage(element.GetViewModel, context);
}
public static OrderViewModel? AcessDressesStorage(OrderViewModel? model, SewingDressesDatabase context)
{
if (model == null)
{
return null;
}
var dress = context.Dresses.FirstOrDefault(x => x.Id == model.DressId);
if (dress == null)
{
return null;
}
model.DressName = dress.DressName;
return model;
}
}
}

View File

@ -0,0 +1,144 @@
using Microsoft.EntityFrameworkCore;
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesDatabaseImplement.Models;
using SewingDressesDataModels.Models;
namespace SewingDressesDatabaseImplement.Implements
{
public class ShopStorage : IShopStorage
{
public ShopViewModel? Delete(ShopBindingModel model)
{
using var context = new SewingDressesDatabase();
var element = context.Shops.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Shops.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new SewingDressesDatabase();
return context.Shops.Include(x => x.Dresses).ThenInclude(x => x.Dress).FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new SewingDressesDatabase();
return context.Shops
.Include(x => x.Dresses)
.ThenInclude(x => x.Dress)
.Select(x => x.GetViewModel)
.Where(x => x.ShopName.Contains(model.Name ?? string.Empty))
.ToList();
}
public List<ShopViewModel> GetFullList()
{
using var context = new SewingDressesDatabase();
return context.Shops
.Include(x => x.Dresses)
.ThenInclude(x => x.Dress)
.Select(x => x.GetViewModel)
.ToList();
}
public ShopViewModel? Insert(ShopBindingModel model)
{
using var context = new SewingDressesDatabase();
try
{
var newShop = Shop.Create(context, model);
if (newShop == null)
{
return null;
}
if (context.Shops.Any(x => x.ShopName == newShop.ShopName))
{
throw new Exception("Не должно быть два магазина с одним названием");
}
context.Shops.Add(newShop);
context.SaveChanges();
return newShop.GetViewModel;
}
catch
{
throw;
}
}
public ShopViewModel? Update(ShopBindingModel model)
{
using var context = new SewingDressesDatabase();
var shop = context.Shops.FirstOrDefault(x => x.Id == model.Id);
if (shop == null)
{
return null;
}
try
{
if (context.Shops.Any(x => (x.ShopName == model.ShopName && x.Id != model.Id)))
{
throw new Exception("Не должно быть два магазина с одним названием");
}
shop.Update(model);
shop.UpdateDresses(context, model);
context.SaveChanges();
return shop.GetViewModel;
}
catch
{
throw;
}
}
public bool SellDresses(IDressModel model, int count)
{
if (model == null)
return false;
using var context = new SewingDressesDatabase();
using var transaction = context.Database.BeginTransaction();
List<ShopDress> lst = new List<ShopDress>();
foreach (var el in context.ShopDresses.Where(x => x.DressId == model.Id))
{
int dif = count;
if (el.Count < dif)
dif = el.Count;
el.Count -= dif;
count -= dif;
if (el.Count == 0)
{
lst.Add(el);
}
if (count == 0)
break;
}
if (count > 0)
{
transaction.Rollback();
return false;
}
foreach (var el in lst)
{
context.ShopDresses.Remove(el);
}
context.SaveChanges();
transaction.Commit();
return true;
}
}
}

View File

@ -0,0 +1,169 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SewingDressesDatabaseImplement;
#nullable disable
namespace SewingDressesDatabaseImplement1.Migrations
{
[DbContext(typeof(SewingDressesDatabase))]
[Migration("20240308104531_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("DressName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Dresses");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DressId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("DressId");
b.ToTable("DressComponents");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("DressId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("DressId");
b.ToTable("Orders");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b =>
{
b.HasOne("SewingDressesDatabaseImplement.Models.Component", "Component")
.WithMany("DressComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress")
.WithMany("Components")
.HasForeignKey("DressId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Dress");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
{
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", null)
.WithMany("Orders")
.HasForeignKey("DressId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b =>
{
b.Navigation("DressComponents");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,125 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SewingDressesDatabaseImplement1.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Components",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Cost = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Components", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Dresses",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DressName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Dresses", x => x.Id);
});
migrationBuilder.CreateTable(
name: "DressComponents",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DressId = table.Column<int>(type: "int", nullable: false),
ComponentId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DressComponents", x => x.Id);
table.ForeignKey(
name: "FK_DressComponents_Components_ComponentId",
column: x => x.ComponentId,
principalTable: "Components",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_DressComponents_Dresses_DressId",
column: x => x.DressId,
principalTable: "Dresses",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DressId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Dresses_DressId",
column: x => x.DressId,
principalTable: "Dresses",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_DressComponents_ComponentId",
table: "DressComponents",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_DressComponents_DressId",
table: "DressComponents",
column: "DressId");
migrationBuilder.CreateIndex(
name: "IX_Orders_DressId",
table: "Orders",
column: "DressId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DressComponents");
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Dresses");
}
}
}

View File

@ -0,0 +1,246 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SewingDressesDatabaseImplement;
#nullable disable
namespace SewingDressesDatabaseImplement1.Migrations
{
[DbContext(typeof(SewingDressesDatabase))]
[Migration("20240404175726_ClientAboba")]
partial class ClientAboba
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.16")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("DressName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Dresses");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DressId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("DressId");
b.ToTable("DressComponents");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("DressId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("DressId");
b.ToTable("Orders");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.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>("DateOpen")
.HasColumnType("datetime2");
b.Property<int>("MaxCount")
.HasColumnType("int");
b.Property<string>("ShopName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Shops");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.ShopDress", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DressId")
.HasColumnType("int");
b.Property<int>("ShopId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DressId");
b.HasIndex("ShopId");
b.ToTable("ShopDresses");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b =>
{
b.HasOne("SewingDressesDatabaseImplement.Models.Component", "Component")
.WithMany("DressComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress")
.WithMany("Components")
.HasForeignKey("DressId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Dress");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
{
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", null)
.WithMany("Orders")
.HasForeignKey("DressId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.ShopDress", b =>
{
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress")
.WithMany()
.HasForeignKey("DressId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SewingDressesDatabaseImplement.Models.Shop", "Shop")
.WithMany("Dresses")
.HasForeignKey("ShopId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Dress");
b.Navigation("Shop");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b =>
{
b.Navigation("DressComponents");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Shop", b =>
{
b.Navigation("Dresses");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,78 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SewingDressesDatabaseImplement1.Migrations
{
/// <inheritdoc />
public partial class ClientAboba : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
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),
DateOpen = table.Column<DateTime>(type: "datetime2", nullable: false),
MaxCount = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Shops", x => x.Id);
});
migrationBuilder.CreateTable(
name: "ShopDresses",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DressId = 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_ShopDresses", x => x.Id);
table.ForeignKey(
name: "FK_ShopDresses_Dresses_DressId",
column: x => x.DressId,
principalTable: "Dresses",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ShopDresses_Shops_ShopId",
column: x => x.ShopId,
principalTable: "Shops",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ShopDresses_DressId",
table: "ShopDresses",
column: "DressId");
migrationBuilder.CreateIndex(
name: "IX_ShopDresses_ShopId",
table: "ShopDresses",
column: "ShopId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ShopDresses");
migrationBuilder.DropTable(
name: "Shops");
}
}
}

View File

@ -0,0 +1,243 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SewingDressesDatabaseImplement;
#nullable disable
namespace SewingDressesDatabaseImplement1.Migrations
{
[DbContext(typeof(SewingDressesDatabase))]
partial class SewingDressesDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.16")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("DressName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Dresses");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DressId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("DressId");
b.ToTable("DressComponents");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("DressId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("DressId");
b.ToTable("Orders");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.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>("DateOpen")
.HasColumnType("datetime2");
b.Property<int>("MaxCount")
.HasColumnType("int");
b.Property<string>("ShopName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Shops");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.ShopDress", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("DressId")
.HasColumnType("int");
b.Property<int>("ShopId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("DressId");
b.HasIndex("ShopId");
b.ToTable("ShopDresses");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b =>
{
b.HasOne("SewingDressesDatabaseImplement.Models.Component", "Component")
.WithMany("DressComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress")
.WithMany("Components")
.HasForeignKey("DressId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Dress");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b =>
{
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", null)
.WithMany("Orders")
.HasForeignKey("DressId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.ShopDress", b =>
{
b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress")
.WithMany()
.HasForeignKey("DressId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SewingDressesDatabaseImplement.Models.Shop", "Shop")
.WithMany("Dresses")
.HasForeignKey("ShopId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Dress");
b.Navigation("Shop");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b =>
{
b.Navigation("DressComponents");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Shop", b =>
{
b.Navigation("Dresses");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,57 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace SewingDressesDatabaseImplement.Models
{
public class Component : IComponentModel
{
public int Id { get; private set; }
[Required]
public string ComponentName { get; private set; } = string.Empty;
[Required]
public double Cost { get; set; }
[ForeignKey("ComponentId")]
public virtual List<DressComponent> DressComponents { get; set; } = new();
public static Component? Create (ComponentBindingModel model)
{
if (model == null)
{
return null;
}
return new Component
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public static Component Create(ComponentViewModel model)
{
return new Component
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public void Update(ComponentBindingModel model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
}
}

View File

@ -0,0 +1,89 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace SewingDressesDatabaseImplement.Models
{
public class Dress : IDressModel
{
public int Id { get; set; }
[Required]
public string DressName { get; set; } = string.Empty;
[Required]
public double Price { get; set; }
private Dictionary<int, (IComponentModel, int)>? _dressComponents = null;
[NotMapped]
public Dictionary<int, (IComponentModel, int)> DressComponents
{
get
{
if (_dressComponents == null)
{
_dressComponents = Components.ToDictionary(recDC => recDC.ComponentId, recDC => (recDC.Component as IComponentModel, recDC.Count));
}
return _dressComponents;
}
}
[ForeignKey("DressId")]
public virtual List<DressComponent> Components { get; set; } = new();
[ForeignKey("DressId")]
public virtual List<Order> Orders { get; set; } = new();
public static Dress Create(SewingDressesDatabase context, DressBindingModel model)
{
return new Dress()
{
Id = model.Id,
DressName = model.DressName,
Price = model.Price,
Components = model.DressComponents.Select(x => new DressComponent
{
Component = context.Components.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList()
};
}
public void Update(DressBindingModel model)
{
DressName = model.DressName;
Price = model.Price;
}
public DressViewModel GetViewModel => new()
{
Id = Id,
DressName = DressName,
Price = Price,
DressComponents = DressComponents
};
public void UpdateComponents(SewingDressesDatabase context, DressBindingModel model)
{
var dressComponents = context.DressComponents.Where(rec => rec.DressId == model.Id).ToList();
if (dressComponents != null && dressComponents.Count > 0)
{
context.DressComponents.RemoveRange(dressComponents.Where(rec => !model.DressComponents.ContainsKey(rec.ComponentId)));
context.SaveChanges();
foreach (var updateComponent in dressComponents)
{
updateComponent.Count = model.DressComponents[updateComponent.ComponentId].Item2;
model.DressComponents.Remove(updateComponent.ComponentId);
}
context.SaveChanges();
}
var dress = context.Dresses.First(x => x.Id == Id);
foreach (var pc in model.DressComponents)
{
context.DressComponents.Add(new DressComponent
{
Dress = dress,
Component = context.Components.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_dressComponents = null;
}
}
}

View File

@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations;
namespace SewingDressesDatabaseImplement.Models
{
public class DressComponent
{
public int Id { get; set; }
[Required]
public int DressId { get; set; }
[Required]
public int ComponentId { get; set; }
[Required]
public int Count { get; set; }
public virtual Component Component { get; set; } = new();
public virtual Dress Dress { get; set; } = new();
}
}

View File

@ -0,0 +1,61 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Enums;
using SewingDressesDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace SewingDressesDatabaseImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
[Required]
public int DressId { get; private set; }
[Required]
public int Count { get; private set; }
[Required]
public double Sum { get; private set; }
[Required]
public OrderStatus Status { get; private set; }
[Required]
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
DressId = model.DressId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate
};
}
public void Update(OrderBindingModel model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
DressId = DressId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
}
}

View File

@ -0,0 +1,100 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace SewingDressesDatabaseImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; private set; }
[Required]
public string ShopName { get; private set; }
[Required]
public string Adress { get; private set; }
[Required]
public DateTime DateOpen { get; private set; }
[Required]
public int MaxCount { get; private set; }
private Dictionary<int, (IDressModel, int)>? _shopDresses = null;
[NotMapped]
public Dictionary<int, (IDressModel, int)>? ShopDresses
{
get
{
if ( _shopDresses == null )
{
_shopDresses = Dresses.ToDictionary(x => x.DressId, x => (x.Dress as IDressModel, x.Count));
}
return _shopDresses;
}
}
[ForeignKey("ShopId")]
public virtual List<ShopDress> Dresses { get; set; } = new();
public static Shop? Create(SewingDressesDatabase context, ShopBindingModel model)
{
if (model == null)
return null;
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Adress = model.Adress,
DateOpen = model.DateOpen,
MaxCount = model.MaxCount,
Dresses = model.ShopDresses.Select(x => new ShopDress
{
Dress = context.Dresses.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList()
};
}
public void Update(ShopBindingModel? model)
{
if (model == null )
return;
ShopName = model.ShopName;
Adress = model.Adress;
DateOpen = model.DateOpen;
MaxCount = model.MaxCount;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Adress = Adress,
DateOpen = DateOpen,
MaxCount = MaxCount,
ShopDresses = ShopDresses
};
public void UpdateDresses(SewingDressesDatabase context, ShopBindingModel model)
{
var shopDresses = context.ShopDresses.Where(rec => rec.ShopId == model.Id).ToList();
if (shopDresses != null && shopDresses.Count > 0)
{
context.ShopDresses.RemoveRange(shopDresses.Where(rec => !model.ShopDresses.ContainsKey(rec.DressId)));
context.SaveChanges();
foreach (var uDress in shopDresses)
{
uDress.Count = model.ShopDresses[uDress.DressId].Item2;
model.ShopDresses.Remove(uDress.DressId);
}
context.SaveChanges();
}
var shop = context.Shops.First(x => x.Id == Id);
foreach (var pc in model.ShopDresses)
{
context.ShopDresses.Add(new ShopDress
{
Shop = shop,
Dress = context.Dresses.First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges() ;
}
_shopDresses = null;
}
}
}

View File

@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations;
namespace SewingDressesDatabaseImplement.Models
{
public class ShopDress
{
public int Id { get; set; }
[Required]
public int DressId { get; set; }
[Required]
public int ShopId { get; set; }
[Required]
public int Count { get; set; }
public virtual Shop Shop { get; set; } = new();
public virtual Dress Dress { get; set; } = new();
}
}

View File

@ -0,0 +1,22 @@
using SewingDressesDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace SewingDressesDatabaseImplement
{
public class SewingDressesDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=.\SQLEXPRESS;Initial Catalog=SewingDressesDatabaseHard;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Component> Components { get; set; }
public virtual DbSet<Dress> Dresses { get; set; }
public virtual DbSet<DressComponent> DressComponents { get; set; }
public virtual DbSet<Order> Orders { get; set; }
public virtual DbSet<Shop> Shops { get; set; }
public virtual DbSet<ShopDress> ShopDresses { get; set; }
}
}

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SewingDressesContracts\SewingDressesContracts.csproj" />
<ProjectReference Include="..\SewingDressesDataModels\SewingDressesDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,53 @@
using SewingDressesFileImplement.Models;
using System.Xml.Linq;
namespace SewingDressesFileImplement
{
internal class DataFileSingleton
{
private static DataFileSingleton? instance;
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string DressFileName = "Dress.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Dress> Dresses { get; private set;}
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
{
instance = new DataFileSingleton();
}
return instance;
}
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
{
if (data != null)
{
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
}
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{
if (File.Exists(filename))
{
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
}
return new List<T>();
}
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SaveDresses() => SaveData(Dresses, DressFileName, "Dresses", 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)!)!;
Dresses = LoadData(DressFileName, "Dress", x => Dress.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
}
}
}

View File

@ -0,0 +1,73 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesFileImplement.Models;
namespace SewingDressesFileImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
private readonly DataFileSingleton source;
public ComponentStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<ComponentViewModel> GetFullList()
{
return source.Components.Select(x => x.GetViewModel).ToList();
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName))
{
return new();
}
return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName))
.Select(x => x.GetViewModel)
.ToList();
}
public ComponentViewModel? GetElement(ComponentSearchModel model)
{
if (string.IsNullOrEmpty (model.ComponentName) && !model.Id.HasValue)
{
return null;
}
return source.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ComponentViewModel? Insert(ComponentBindingModel model)
{
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
var newComponent = Component.Create(model);
if (newComponent == null)
{
return null;
}
source.Components.Add(newComponent);
source.SaveComponents();
return newComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel model)
{
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
source.SaveComponents();
return component.GetViewModel;
}
public ComponentViewModel? Delete(ComponentBindingModel model)
{
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
source.Components.Remove(component);
source.SaveComponents();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,71 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using SewingDressesFileImplement.Models;
namespace SewingDressesFileImplement.Implements
{
public class DressStorage : IDressStorage
{
private readonly DataFileSingleton source;
public DressStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<DressViewModel> GetFullList()
{
return source.Dresses.Select(x => x.GetViewModel).ToList();
}
public List<DressViewModel> GetFilteredList(DressSearchModel model)
{
return source.Dresses.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
public DressViewModel? GetElement(DressSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return source.Dresses.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DressName) && x.DressName == model.DressName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public DressViewModel? Insert(DressBindingModel model)
{
model.Id = source.Dresses.Count > 0 ? source.Dresses.Max(x => x.Id) + 1 : 1;
var newDress = Dress.Create(model);
if (newDress == null)
{
return null;
}
source.Dresses.Add(newDress);
source.SaveDresses();
return newDress.GetViewModel;
}
public DressViewModel? Update(DressBindingModel model)
{
var component = source.Dresses.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
source.SaveDresses();
return component.GetViewModel;
}
public DressViewModel? Delete(DressBindingModel model)
{
var component = source.Dresses.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
source.Dresses.Remove(component);
source.SaveDresses();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,77 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using SewingDressesFileImplement.Models;
namespace SewingDressesFileImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly DataFileSingleton source;
public OrderStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<OrderViewModel> GetFullList()
{
return source.Orders.Select(x => AcessDressesStorage(x.GetViewModel)).ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
return source.Orders.Where(x => x.Id == model.Id)
.Select(x => AcessDressesStorage( x.GetViewModel))
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
source.Orders.Add(newOrder);
source.SaveOrders();
return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
var component = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
source.SaveOrders();
return component.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var component = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
source.Orders.Remove(component);
source.SaveOrders();
return component.GetViewModel;
}
public OrderViewModel AcessDressesStorage(OrderViewModel model)
{
var component = source.Dresses.FirstOrDefault(x => x.Id == model.DressId);
model.DressName = component.DressName;
return model;
}
}
}

View File

@ -0,0 +1,121 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using SewingDressesFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesFileImplement.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.Name))
{
return new();
}
return _source.Shops.Where(x => x.ShopName.Contains(model.Name)).Select(x => x.GetViewModel).ToList();
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
return _source.Shops.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.ShopName == model.Name) || (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 component = _source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
_source.SaveShops();
return component.GetViewModel;
}
public ShopViewModel? Delete(ShopBindingModel model)
{
var element = _source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
_source.Shops.Remove(element);
_source.SaveShops();
return element.GetViewModel;
}
return null;
}
public bool CheckAvailability(int dressId, int count)
{
int store = _source.Shops.Select(x => x.ShopDresses.Select(y => (y.Value.Item1.Id == dressId ? y.Value.Item2 : 0)).Sum()).Sum();
return store >= count;
}
public bool SellDresses(IDressModel model, int count)
{
var dres = _source.Dresses.FirstOrDefault(x => x.Id == model.Id);
if (dres == null || !CheckAvailability(model.Id, count))
{
return false;
}
for (int i = 0; i < _source.Shops.Count; i++)
{
var shop = _source.Shops[i];
var dresses = shop.ShopDresses;
foreach (var dress in dresses.Where(x => x.Value.Item1.Id == dres.Id))
{
var selling = Math.Min(dress.Value.Item2, count);
dresses[dress.Value.Item1.Id] = (dress.Value.Item1, dress.Value.Item2 - selling);
count -= selling;
if (count <= 0)
{
break;
}
}
shop.Update(new ShopBindingModel
{
Id = model.Id,
ShopName = shop.ShopName,
Adress = shop.Adress,
MaxCount = shop.MaxCount,
DateOpen = shop.DateOpen,
ShopDresses = dresses
});
}
_source.SaveShops();
return true;
}
}
}

View File

@ -0,0 +1,58 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System.Xml.Linq;
namespace SewingDressesFileImplement.Models
{
public class Component : IComponentModel
{
public int Id { get; private set; }
public string ComponentName { get; private set; } = string.Empty;
public double Cost { get; private set; }
public static Component? Create(ComponentBindingModel model)
{
if (model == null)
{
return null;
}
return new Component()
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public static Component? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Component()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ComponentName = element.Element("ComponentName")!.Value,
Cost = Convert.ToDouble(element.Element("Cost")!.Value, new System.Globalization.CultureInfo("en-US"))
};
}
public void Update(ComponentBindingModel model)
{
if (model == null)
{ return; }
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
public XElement GetXElement => new("Component",
new XAttribute("Id", Id),
new XElement("ComponentName", ComponentName),
new XElement("Cost", Cost.ToString()));
}
}

View File

@ -0,0 +1,78 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System.Xml.Linq;
namespace SewingDressesFileImplement.Models
{
public class Dress : IDressModel
{
public int Id { get; private set; }
public string DressName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _dressComponents = null;
public Dictionary<int, (IComponentModel, int)> DressComponents
{
get
{
if (_dressComponents == null)
{
var source = DataFileSingleton.GetInstance();
_dressComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
}
return _dressComponents;
}
}
public static Dress? Create(DressBindingModel model)
{
if (model == null)
{
return null;
}
return new Dress()
{
Id = model.Id,
DressName = model.DressName,
Price = model.Price,
Components = model.DressComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public static Dress? Create(XElement element)
{
if (element == null)
{ return null; }
return new Dress()
{
Id = Convert.ToInt32(element.Attribute("Id")?.Value),
DressName = element.Element("DressName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value, new System.Globalization.CultureInfo("en-US")),
Components = element.Element("DressComponents")!.Elements("DressComponent").ToDictionary(x =>Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(DressBindingModel model)
{
if (model == null)
{
return;
}
DressName = model.DressName;
Price = model.Price;
Components = model.DressComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
_dressComponents = null;
}
public DressViewModel GetViewModel => new()
{
Id = Id,
DressName = DressName,
Price = Price,
DressComponents = DressComponents
};
public XElement GetXElement => new("Dress",
new XAttribute("Id", Id),
new XElement("DressName", DressName),
new XElement("Price", Price),
new XElement("DressComponents", Components.Select(x => new XElement("DressComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()));
}
}

View File

@ -0,0 +1,82 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Enums;
using SewingDressesDataModels.Models;
using System.Data;
using System.Xml.Linq;
namespace SewingDressesFileImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public int DressId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; }
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set;}
public static Order? Create(OrderBindingModel model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
DressId = model.DressId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate
};
}
public static Order? Create(XElement element)
{
if (element == null)
{
return null;
}
var dateImplement = element.Element("DateImplement")?.Value;
return new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
DressId = Convert.ToInt32(element.Element("DressId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value, new System.Globalization.CultureInfo("en-US")),
Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")?.Value),
DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement)
};
}
public void Update(OrderBindingModel model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
DressId = DressId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("DressId", DressId),
new XElement("Count", Count),
new XElement("Sum", Sum),
new XElement("Status", Status - OrderStatus.Принят),
new XElement("DateCreate", DateCreate),
new XElement("DateImplement", DateImplement));
}
}

View File

@ -0,0 +1,101 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace SewingDressesFileImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; private set; }
public string ShopName { get; private set; }
public string Adress { get; private set; }
public DateTime DateOpen { get; private set; }
public int MaxCount { get; private set; }
public Dictionary<int, int> Dresses { get; private set; } = new();
private Dictionary<int, (IDressModel, int)>? _shopDresses = null;
public Dictionary<int, (IDressModel, int)> ShopDresses
{
get
{
if (_shopDresses == null)
{
var source = DataFileSingleton.GetInstance();
_shopDresses = Dresses.ToDictionary(x => x.Key, y => ((source.Dresses.FirstOrDefault(z => z.Id == y.Key) as IDressModel)!, y.Value));
}
return _shopDresses;
}
}
public static Shop? Create(ShopBindingModel model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Adress = model.Adress,
DateOpen = model.DateOpen,
MaxCount = model.MaxCount,
Dresses = model.ShopDresses.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public static Shop? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Shop()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ShopName = element.Element("ShopName")!.Value,
Adress = element.Element("Adress")!.Value,
MaxCount = Convert.ToInt32(element.Element("MaxCount")!.Value),
DateOpen = Convert.ToDateTime(element.Element("DateOpen")!.Value),
Dresses = element.Element("ShopDresses")!.Elements("ShopDress").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Adress = model.Adress;
DateOpen = model.DateOpen;
MaxCount = model.MaxCount;
if (model.ShopDresses.Count > 0)
{
Dresses = model.ShopDresses.ToDictionary(x => x.Key, x => x.Value.Item2);
_shopDresses = null;
}
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Adress = Adress,
DateOpen = DateOpen,
MaxCount = MaxCount,
ShopDresses = ShopDresses
};
public XElement GetXElement => new XElement("Shop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Adress", Adress),
new XElement("DateOpen", DateOpen),
new XElement("MaxCount", MaxCount),
new XElement("ShopDresses", Dresses.Select(x => new XElement("ShopDress", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()));
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SewingDressesContracts\SewingDressesContracts.csproj" />
<ProjectReference Include="..\SewingDressesDataModels\SewingDressesDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,28 @@
using SewingDressesListImplement.Models;
namespace SewingDressesListImplement
{
public class DataListSingleton
{
private static DataListSingleton? _instance;
public List<Component> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Dress> Dresses { get; set; }
public List<Shop> Shops { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Dresses = new List<Dress>();
Shops = new List<Shop>();
}
public static DataListSingleton GetInstance()
{
if (_instance == null)
{
_instance = new DataListSingleton();
}
return _instance;
}
}
}

View File

@ -0,0 +1,104 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesListImplement.Models;
namespace SewingDressesListImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
private readonly DataListSingleton _source;
public ComponentStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<ComponentViewModel> GetFullList()
{
var result = new List<ComponentViewModel>();
foreach (var component in _source.Components)
{
result.Add(component.GetViewModel);
}
return result;
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
var result = new List<ComponentViewModel>();
if (string.IsNullOrEmpty(model.ComponentName))
{
return result;
}
foreach (var component in _source.Components)
{
if (component.ComponentName.Contains(model.ComponentName))
{
result.Add(component.GetViewModel);
}
}
return result;
}
public ComponentViewModel? GetElement(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
{
return null;
}
foreach (var component in _source.Components)
{
if ((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) ||
(model.Id.HasValue && component.Id == model.Id))
{
return component.GetViewModel;
}
}
return null;
}
public ComponentViewModel? Insert(ComponentBindingModel model)
{
model.Id = 1;
foreach(var component in _source.Components)
{
if (model.Id <= component.Id)
{
model.Id = component.Id + 1;
}
}
var newComponent = Component.Create(model);
if (newComponent == null)
{
return null;
}
_source.Components.Add(newComponent);
return newComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel model)
{
foreach (var component in _source.Components)
{
if (component.Id == model.Id)
{
component.Update(model);
return component.GetViewModel;
}
}
return null;
}
public ComponentViewModel? Delete(ComponentBindingModel model)
{
for (int i = 0; i < _source.Components.Count; i++)
{
if (_source.Components[i].Id == model.Id)
{
var element = _source.Components[i];
_source.Components.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,104 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesListImplement.Models;
namespace SewingDressesListImplement.Implements
{
public class DressStorage : IDressStorage
{
private readonly DataListSingleton _source;
public DressStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<DressViewModel> GetFullList()
{
var result = new List<DressViewModel>();
foreach (var component in _source.Dresses)
{
result.Add(component.GetViewModel);
}
return result;
}
public List<DressViewModel> GetFilteredList(DressSearchModel model)
{
var result = new List<DressViewModel>();
if (string.IsNullOrEmpty(model.DressName))
{
return result;
}
foreach (var component in _source.Dresses)
{
if (component.DressName.Contains(model.DressName))
{
result.Add(component.GetViewModel);
}
}
return result;
}
public DressViewModel? GetElement(DressSearchModel model)
{
if (string.IsNullOrEmpty(model.DressName) && !model.Id.HasValue)
{
return null;
}
foreach (var component in _source.Dresses)
{
if ((!string.IsNullOrEmpty(model.DressName) && component.DressName == model.DressName) ||
(model.Id.HasValue && component.Id == model.Id))
{
return component.GetViewModel;
}
}
return null;
}
public DressViewModel? Insert(DressBindingModel model)
{
model.Id = 1;
foreach (var component in _source.Dresses)
{
if (model.Id <= component.Id)
{
model.Id = component.Id + 1;
}
}
var newDress = Dress.Create(model);
if (newDress == null)
{
return null;
}
_source.Dresses.Add(newDress);
return newDress.GetViewModel;
}
public DressViewModel? Update(DressBindingModel model)
{
foreach (var component in _source.Dresses)
{
if (component.Id == model.Id)
{
component.Update(model);
return component.GetViewModel;
}
}
return null;
}
public DressViewModel? Delete(DressBindingModel model)
{
for (int i = 0; i < _source.Dresses.Count; i++)
{
if (_source.Dresses[i].Id == model.Id)
{
var element = _source.Dresses[i];
_source.Dresses.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,110 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesListImplement.Models;
using System.Runtime.CompilerServices;
namespace SewingDressesListImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly DataListSingleton _source;
public OrderStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<OrderViewModel> GetFullList()
{
var result = new List<OrderViewModel>();
foreach (var order in _source.Orders)
{
result.Add(AcessDressesStorage(order.GetViewModel));
}
return result;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
{
result.Add(AcessDressesStorage(order.GetViewModel));
}
}
return result;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
foreach (var order in _source.Orders)
{
if (model.Id.HasValue && order.Id == model.Id)
{
return order.GetViewModel;
}
}
return null;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
model.Id = 1;
foreach (var order in _source.Orders)
{
if (model.Id <= order.Id)
{
model.Id = order.Id + 1;
}
}
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
_source.Orders.Add(newOrder);
return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
{
order.Update(model);
return order.GetViewModel;
}
}
return null;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
for (int i = 0; i < _source.Orders.Count; i++)
{
if (_source.Orders[i].Id == model.Id)
{
var element = _source.Orders[i];
_source.Orders.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
public OrderViewModel AcessDressesStorage(OrderViewModel model)
{
foreach (var dress in _source.Dresses)
{
if (dress.Id == model.DressId)
{
model.DressName = dress.DressName;
break;
}
}
return model;
}
}
}

View File

@ -0,0 +1,117 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using SewingDressesListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesListImplement.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.Name))
{
return result;
}
foreach (var shop in _source.Shops)
{
if (shop.ShopName.Contains(model.Name))
{
result.Add(shop.GetViewModel);
}
}
return result;
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
foreach (var shop in _source.Shops)
{
if ((!string.IsNullOrEmpty(model.Name) &&
shop.ShopName == model.Name) ||
(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 CheckAvailability(int dressId, int count)
{
return true;
}
public bool SellDresses(IDressModel model, int count)
{
return true;
}
}
}

View File

@ -0,0 +1,46 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
namespace SewingDressesListImplement.Models
{
public class Component : IComponentModel
{
public int Id { get; private set; }
public string ComponentName { get; private set; } = string.Empty;
public double Cost { get; set; }
public static Component? Create(ComponentBindingModel? model)
{
if (model == null)
{
return null;
}
return new Component()
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public void Update(ComponentBindingModel? model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
}
}

View File

@ -0,0 +1,52 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
namespace SewingDressesListImplement.Models
{
public class Dress : IDressModel
{
public int Id { get; private set; }
public string DressName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> DressComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();
public static Dress? Create(DressBindingModel? model)
{
if (model == null)
{
return null;
}
return new Dress()
{
Id = model.Id,
DressName = model.DressName,
Price = model.Price,
DressComponents = model.DressComponents
};
}
public void Update(DressBindingModel? model)
{
if (model == null)
{
return;
}
DressName = model.DressName;
Price = model.Price;
DressComponents = model.DressComponents;
}
public DressViewModel GetViewModel => new()
{
Id = Id,
DressName = DressName,
Price = Price,
DressComponents = DressComponents
};
}
}

View File

@ -0,0 +1,56 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Enums;
using SewingDressesDataModels.Models;
namespace SewingDressesListImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public int DressId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; }
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order
{
Id = model.Id,
DressId = model.DressId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
DressId = DressId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
}
}

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using SewingDressesContracts.BindingModels;
namespace SewingDressesListImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; private set; }
public string ShopName { get; private set; }
public string Adress { get; private set; }
public DateTime DateOpen { get; private set; }
public int MaxCount { get; private set; }
public Dictionary<int, (IDressModel, int)> ShopDresses { get; private set; } = new();
public static Shop? Create (ShopBindingModel model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Adress = model.Adress,
DateOpen = model.DateOpen,
MaxCount = model.MaxCount,
ShopDresses = new()
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Adress = model.Adress;
DateOpen = model.DateOpen;
MaxCount = model.MaxCount;
ShopDresses = model.ShopDresses;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Adress = Adress,
DateOpen = DateOpen,
MaxCount = MaxCount,
ShopDresses = ShopDresses
};
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SewingDressesContracts\SewingDressesContracts.csproj" />
<ProjectReference Include="..\SewingDressesDataModels\SewingDressesDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,118 @@
namespace SewingDressesView
{
partial class ComponentForm
{
/// <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()
{
label1 = new Label();
label2 = new Label();
textBoxName = new TextBox();
textBoxCost = new TextBox();
buttonSave = new Button();
CancelButton = new Button();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(26, 21);
label1.Name = "label1";
label1.Size = new Size(80, 20);
label1.TabIndex = 0;
label1.Text = "Название:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(26, 63);
label2.Name = "label2";
label2.Size = new Size(48, 20);
label2.TabIndex = 1;
label2.Text = "Цена:";
//
// textBoxName
//
textBoxName.Location = new Point(141, 18);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(331, 27);
textBoxName.TabIndex = 2;
//
// textBoxCost
//
textBoxCost.Location = new Point(141, 63);
textBoxCost.Name = "textBoxCost";
textBoxCost.Size = new Size(125, 27);
textBoxCost.TabIndex = 3;
//
// buttonSave
//
buttonSave.Location = new Point(234, 126);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 4;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// CancelButton
//
CancelButton.Location = new Point(378, 126);
CancelButton.Name = "CancelButton";
CancelButton.Size = new Size(94, 29);
CancelButton.TabIndex = 5;
CancelButton.Text = "Отмена";
CancelButton.UseVisualStyleBackColor = true;
CancelButton.Click += CancelButton_Click;
//
// ComponentForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(530, 182);
Controls.Add(CancelButton);
Controls.Add(buttonSave);
Controls.Add(textBoxCost);
Controls.Add(textBoxName);
Controls.Add(label2);
Controls.Add(label1);
Name = "ComponentForm";
Text = "Компонент";
Load += ComponentForm_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private TextBox textBoxName;
private TextBox textBoxCost;
private Button buttonSave;
private Button CancelButton;
}
}

View File

@ -0,0 +1,82 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.SearchModels;
using Microsoft.Extensions.Logging;
namespace SewingDressesView
{
public partial class ComponentForm : Form
{
private readonly ILogger _logger;
private readonly IComponentLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public ComponentForm(ILogger<ComponentForm> logger, IComponentLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void ComponentForm_Load(object sender, EventArgs e)
{
if (!_id.HasValue)
{
return;
}
try
{
_logger.LogInformation("Get component");
var view = _logic.ReadElement(new ComponentSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.ComponentName;
textBoxCost.Text = view.Cost.ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Get component error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Save component");
try
{
var model = new ComponentBindingModel
{
Id = _id ?? 0,
ComponentName = textBoxName.Text,
Cost = Convert.ToDouble(textBoxCost.Text)
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополительная информация в логах");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Save component error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

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

View File

@ -0,0 +1,114 @@
namespace SewingDressesView
{
partial class ComponentsForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
dataGridView = new DataGridView();
buttonAdd = new Button();
buttonChange = new Button();
buttonDelete = new Button();
buttonReset = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 10);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(518, 428);
dataGridView.TabIndex = 0;
//
// buttonAdd
//
buttonAdd.Location = new Point(586, 41);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(94, 29);
buttonAdd.TabIndex = 1;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_Click;
//
// buttonChange
//
buttonChange.Location = new Point(586, 113);
buttonChange.Name = "buttonChange";
buttonChange.Size = new Size(94, 29);
buttonChange.TabIndex = 2;
buttonChange.Text = "Изменить";
buttonChange.UseVisualStyleBackColor = true;
buttonChange.Click += buttonChange_Click;
//
// buttonDelete
//
buttonDelete.Location = new Point(586, 191);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(94, 29);
buttonDelete.TabIndex = 3;
buttonDelete.Text = "Удалить";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonReset
//
buttonReset.Location = new Point(586, 263);
buttonReset.Name = "buttonReset";
buttonReset.Size = new Size(94, 29);
buttonReset.TabIndex = 4;
buttonReset.Text = "Обновить";
buttonReset.UseVisualStyleBackColor = true;
buttonReset.Click += buttonReset_Click;
//
// ComponentsForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(728, 450);
Controls.Add(buttonReset);
Controls.Add(buttonDelete);
Controls.Add(buttonChange);
Controls.Add(buttonAdd);
Controls.Add(dataGridView);
Name = "ComponentsForm";
Text = "Форма компонентов";
Load += ComponentsForm_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonChange;
private Button buttonDelete;
private Button buttonReset;
}
}

View File

@ -0,0 +1,113 @@
using Microsoft.Extensions.Logging;
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.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 SewingDressesView
{
public partial class ComponentsForm : Form
{
private readonly ILogger _logger;
private readonly IComponentLogic _logic;
public ComponentsForm(ILogger<ComponentsForm> logger, IComponentLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(ComponentForm));
if (service is ComponentForm form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void buttonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(ComponentForm));
if (service is ComponentForm form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void buttonDelete_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("Delete component");
try
{
if (!_logic.Delete(new ComponentBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Delete component error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void buttonReset_Click(object sender, EventArgs e)
{
LoadData();
}
private void ComponentsForm_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Load components");
}
catch (Exception ex)
{
_logger.LogError(ex, "Load components error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

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

View File

@ -0,0 +1,118 @@
namespace SewingDressesView
{
partial class DressComponentForm
{
/// <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()
{
label1 = new Label();
label2 = new Label();
comboBoxComponent = new ComboBox();
textBoxCount = new TextBox();
buttonSave = new Button();
buttonCancel = new Button();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(46, 32);
label1.Name = "label1";
label1.Size = new Size(91, 20);
label1.TabIndex = 0;
label1.Text = "Компонент:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(46, 75);
label2.Name = "label2";
label2.Size = new Size(93, 20);
label2.TabIndex = 1;
label2.Text = "Количество:";
//
// comboBoxComponent
//
comboBoxComponent.FormattingEnabled = true;
comboBoxComponent.Location = new Point(158, 29);
comboBoxComponent.Name = "comboBoxComponent";
comboBoxComponent.Size = new Size(259, 28);
comboBoxComponent.TabIndex = 2;
//
// textBoxCount
//
textBoxCount.Location = new Point(158, 72);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(259, 27);
textBoxCount.TabIndex = 3;
//
// buttonSave
//
buttonSave.Location = new Point(223, 131);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 4;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(323, 131);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// DressComponentForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(446, 189);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxCount);
Controls.Add(comboBoxComponent);
Controls.Add(label2);
Controls.Add(label1);
Name = "DressComponentForm";
Text = "Компоненты платьев";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private ComboBox comboBoxComponent;
private TextBox textBoxCount;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,81 @@
using Microsoft.VisualBasic.Logging;
using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
namespace SewingDressesView
{
public partial class DressComponentForm : Form
{
private readonly List<ComponentViewModel>? _list;
public int Id
{
get
{
return Convert.ToInt32(comboBoxComponent.SelectedValue);
}
set
{
comboBoxComponent.SelectedValue = value;
}
}
public int Count
{
get { return Convert.ToInt32(textBoxCount.Text); }
set { textBoxCount.Text = value.ToString(); }
}
public IComponentModel? ComponentModel
{
get
{
if (_list == null)
return null;
foreach (var elem in _list)
{
if (elem.Id == Id)
return elem;
}
return null;
}
}
public DressComponentForm(IComponentLogic logic)
{
InitializeComponent();
_list = logic.ReadList(null);
if (_list != null)
{
comboBoxComponent.DisplayMember = "ComponentName";
comboBoxComponent.ValueMember = "Id";
comboBoxComponent.DataSource = _list;
comboBoxComponent.SelectedItem = null;
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxComponent.SelectedValue == null)
{
MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

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

View File

@ -0,0 +1,228 @@
namespace SewingDressesView
{
partial class DressForm
{
/// <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()
{
label1 = new Label();
label2 = new Label();
groupBox1 = new GroupBox();
buttonUpdate = new Button();
buttonDelete = new Button();
buttonChange = new Button();
buttonAdd = new Button();
dataGridView = new DataGridView();
IdColumn = new DataGridViewTextBoxColumn();
ComponentColumn = new DataGridViewTextBoxColumn();
CountColumn = new DataGridViewTextBoxColumn();
textBoxName = new TextBox();
textBoxCost = new TextBox();
buttonSave = new Button();
buttonCancel = new Button();
groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(21, 19);
label1.Name = "label1";
label1.Size = new Size(80, 20);
label1.TabIndex = 0;
label1.Text = "Название:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(21, 58);
label2.Name = "label2";
label2.Size = new Size(86, 20);
label2.TabIndex = 1;
label2.Text = "Стоимость:";
//
// groupBox1
//
groupBox1.Controls.Add(buttonUpdate);
groupBox1.Controls.Add(buttonDelete);
groupBox1.Controls.Add(buttonChange);
groupBox1.Controls.Add(buttonAdd);
groupBox1.Controls.Add(dataGridView);
groupBox1.Location = new Point(21, 98);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(752, 340);
groupBox1.TabIndex = 2;
groupBox1.TabStop = false;
groupBox1.Text = "Компоненты";
//
// buttonUpdate
//
buttonUpdate.Location = new Point(612, 212);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(94, 29);
buttonUpdate.TabIndex = 4;
buttonUpdate.Text = "Обновить";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += buttonUpdate_Click;
//
// buttonDelete
//
buttonDelete.Location = new Point(612, 162);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(94, 29);
buttonDelete.TabIndex = 3;
buttonDelete.Text = "Удалить";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonChange
//
buttonChange.Location = new Point(612, 105);
buttonChange.Name = "buttonChange";
buttonChange.Size = new Size(94, 29);
buttonChange.TabIndex = 2;
buttonChange.Text = "Изменить";
buttonChange.UseVisualStyleBackColor = true;
buttonChange.Click += buttonChange_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(612, 52);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(94, 29);
buttonAdd.TabIndex = 1;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_Click;
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { IdColumn, ComponentColumn, CountColumn });
dataGridView.Location = new Point(6, 29);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(562, 305);
dataGridView.TabIndex = 0;
//
// IdColumn
//
IdColumn.HeaderText = "Id";
IdColumn.MinimumWidth = 6;
IdColumn.Name = "IdColumn";
IdColumn.Visible = false;
IdColumn.Width = 125;
//
// ComponentColumn
//
ComponentColumn.HeaderText = "Компонент";
ComponentColumn.MinimumWidth = 6;
ComponentColumn.Name = "ComponentColumn";
ComponentColumn.Width = 125;
//
// CountColumn
//
CountColumn.HeaderText = "Количество";
CountColumn.MinimumWidth = 6;
CountColumn.Name = "CountColumn";
CountColumn.Width = 125;
//
// textBoxName
//
textBoxName.Location = new Point(125, 16);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(365, 27);
textBoxName.TabIndex = 3;
//
// textBoxCost
//
textBoxCost.Location = new Point(125, 58);
textBoxCost.Name = "textBoxCost";
textBoxCost.Size = new Size(152, 27);
textBoxCost.TabIndex = 4;
//
// buttonSave
//
buttonSave.Location = new Point(533, 444);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 5;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(633, 444);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 6;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// DressForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 502);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxCost);
Controls.Add(textBoxName);
Controls.Add(groupBox1);
Controls.Add(label2);
Controls.Add(label1);
Name = "DressForm";
Text = "Платья";
Load += DressForm_Load;
groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private GroupBox groupBox1;
private DataGridView dataGridView;
private DataGridViewTextBoxColumn IdColumn;
private DataGridViewTextBoxColumn ComponentColumn;
private DataGridViewTextBoxColumn CountColumn;
private TextBox textBoxName;
private TextBox textBoxCost;
private Button buttonUpdate;
private Button buttonDelete;
private Button buttonChange;
private Button buttonAdd;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,215 @@
using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using SewingDressesContracts.SearchModels;
using Microsoft.Extensions.Logging;
using SewingDressesContracts.BindingModels;
namespace SewingDressesView
{
public partial class DressForm : Form
{
private readonly ILogger _logger;
private readonly IDressLogic _logic;
private int? _id;
private Dictionary<int, (IComponentModel, int)> _dressComponents;
public int Id
{
set { _id = value; }
}
public DressForm(ILogger<DressForm> logger, IDressLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_dressComponents = new Dictionary<int, (IComponentModel, int)>();
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(DressComponentForm));
if (service is DressComponentForm form)
{
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Add new component: {ComponentName} - {Count} ", form.ComponentModel.ComponentName, form.Count);
if (_dressComponents.ContainsKey(form.Id))
{
_dressComponents[form.Id] = (form.ComponentModel, form.Count);
}
else
{
_dressComponents.Add(form.Id, (form.ComponentModel, form.Count));
}
LoadData();
}
}
}
private void buttonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service =
Program.ServiceProvider?.GetService(typeof(DressComponentForm));
if (service is DressComponentForm form)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _dressComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Update component: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
_dressComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
}
}
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
_logger.LogInformation("Delete component: {ComponentName}- {Count}", dataGridView.SelectedRows[0].Cells[1].Value);
_dressComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxCost.Text))
{
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (_dressComponents == null || _dressComponents.Count == 0)
{
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Save dress");
try
{
var model = new DressBindingModel
{
Id = _id ?? 0,
DressName = textBoxName.Text,
Price = Convert.ToDouble(textBoxCost.Text),
DressComponents = _dressComponents
};
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, "Save dress error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void DressForm_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Loading dress");
try
{
var view = _logic.ReadElement(new DressSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxName.Text = view.DressName;
textBoxCost.Text = view.Price.ToString();
_dressComponents = view.DressComponents ?? new
Dictionary<int, (IComponentModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Load dress error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Load dress component");
try
{
if (_dressComponents != null)
{
dataGridView.Rows.Clear();
foreach (var pc in _dressComponents)
{
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
}
textBoxCost.Text = CalcPrice().ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Load dress component Error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private double CalcPrice()
{
double price = 0;
foreach (var elem in _dressComponents)
{
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
}
return Math.Round(price * 1.1, 2);
}
}
}

View File

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

View File

@ -0,0 +1,114 @@
namespace SewingDressesView
{
partial class DressesForm
{
/// <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()
{
buttonReset = new Button();
buttonDelete = new Button();
buttonChange = new Button();
buttonAdd = new Button();
dataGridView = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonReset
//
buttonReset.Location = new Point(586, 263);
buttonReset.Name = "buttonReset";
buttonReset.Size = new Size(94, 29);
buttonReset.TabIndex = 9;
buttonReset.Text = "Обновить";
buttonReset.UseVisualStyleBackColor = true;
buttonReset.Click += buttonReset_Click;
//
// buttonDelete
//
buttonDelete.Location = new Point(586, 191);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(94, 29);
buttonDelete.TabIndex = 8;
buttonDelete.Text = "Удалить";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonChange
//
buttonChange.Location = new Point(586, 113);
buttonChange.Name = "buttonChange";
buttonChange.Size = new Size(94, 29);
buttonChange.TabIndex = 7;
buttonChange.Text = "Изменить";
buttonChange.UseVisualStyleBackColor = true;
buttonChange.Click += buttonChange_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(586, 41);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(94, 29);
buttonAdd.TabIndex = 6;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_Click;
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 10);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(518, 428);
dataGridView.TabIndex = 5;
//
// DressesForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(763, 450);
Controls.Add(buttonReset);
Controls.Add(buttonDelete);
Controls.Add(buttonChange);
Controls.Add(buttonAdd);
Controls.Add(dataGridView);
Name = "DressesForm";
Text = "Форма с платьем";
Load += DressesForm_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private Button buttonReset;
private Button buttonDelete;
private Button buttonChange;
private Button buttonAdd;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,115 @@
using Microsoft.Extensions.Logging;
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.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 SewingDressesView
{
public partial class DressesForm : Form
{
private readonly ILogger _logger;
private readonly IDressLogic _logic;
public DressesForm(ILogger<DressesForm> logger, IDressLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void buttonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(DressForm));
if (service is DressForm form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void buttonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(DressForm));
if (service is DressForm form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void buttonDelete_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("Delete component");
try
{
if (!_logic.Delete(new DressBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Delete component error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void buttonReset_Click(object sender, EventArgs e)
{
LoadData();
}
private void DressesForm_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["DressComponents"].Visible = false;
dataGridView.Columns["DressName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["DressComponents"].Visible = false;
}
_logger.LogInformation("Load components");
}
catch (Exception ex)
{
_logger.LogError(ex, "Load components error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

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

View File

@ -0,0 +1,199 @@
namespace SewingDressesView
{
partial class MainForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
dataGridView = new DataGridView();
buttonCreate = new Button();
buttonDoOrder = new Button();
buttonOrderReady = new Button();
buttonOrderGive = new Button();
buttonOrderUpdate = new Button();
menuStrip1 = new MenuStrip();
справочникиToolStripMenuItem = new ToolStripMenuItem();
компонентыToolStripMenuItem = new ToolStripMenuItem();
платьяToolStripMenuItem = new ToolStripMenuItem();
магазиныToolStripMenuItem = new ToolStripMenuItem();
поставкиToolStripMenuItem = new ToolStripMenuItem();
продажаToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
menuStrip1.SuspendLayout();
SuspendLayout();
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(2, 39);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(804, 447);
dataGridView.TabIndex = 0;
//
// buttonCreate
//
buttonCreate.Location = new Point(854, 62);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(194, 37);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать заказ";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// buttonDoOrder
//
buttonDoOrder.Location = new Point(854, 130);
buttonDoOrder.Name = "buttonDoOrder";
buttonDoOrder.Size = new Size(194, 37);
buttonDoOrder.TabIndex = 2;
buttonDoOrder.Text = "Отдать на выполнение";
buttonDoOrder.UseVisualStyleBackColor = true;
buttonDoOrder.Click += buttonDoOrder_Click;
//
// buttonOrderReady
//
buttonOrderReady.Location = new Point(854, 205);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(194, 37);
buttonOrderReady.TabIndex = 3;
buttonOrderReady.Text = "Заказ готов";
buttonOrderReady.UseVisualStyleBackColor = true;
buttonOrderReady.Click += buttonOrderReady_Click;
//
// buttonOrderGive
//
buttonOrderGive.Location = new Point(854, 280);
buttonOrderGive.Name = "buttonOrderGive";
buttonOrderGive.Size = new Size(194, 37);
buttonOrderGive.TabIndex = 4;
buttonOrderGive.Text = "Заказ выдан";
buttonOrderGive.UseVisualStyleBackColor = true;
buttonOrderGive.Click += buttonOrderGive_Click;
//
// buttonOrderUpdate
//
buttonOrderUpdate.Location = new Point(854, 357);
buttonOrderUpdate.Name = "buttonOrderUpdate";
buttonOrderUpdate.Size = new Size(194, 37);
buttonOrderUpdate.TabIndex = 5;
buttonOrderUpdate.Text = "Обновить список";
buttonOrderUpdate.UseVisualStyleBackColor = true;
buttonOrderUpdate.Click += buttonOrderUpdate_Click;
//
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(1096, 28);
menuStrip1.TabIndex = 6;
menuStrip1.Text = "menuStrip1";
//
// справочникиToolStripMenuItem
//
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, платьяToolStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem, продажаToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(117, 24);
справочникиToolStripMenuItem.Text = "Справочники";
//
// компонентыToolStripMenuItem
//
компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
компонентыToolStripMenuItem.Size = new Size(224, 26);
компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
//
// платьяToolStripMenuItem
//
платьяToolStripMenuItem.Name = "платьяToolStripMenuItem";
платьяToolStripMenuItem.Size = new Size(224, 26);
платьяToolStripMenuItem.Text = "Платья";
платьяToolStripMenuItem.Click += DressesToolStripMenuItem_Click;
//
// магазиныToolStripMenuItem
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(224, 26);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += ShopsToolStripMenuItem_Click;
//
// поставкиToolStripMenuItem
//
поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem";
поставкиToolStripMenuItem.Size = new Size(224, 26);
поставкиToolStripMenuItem.Text = "Поставки";
поставкиToolStripMenuItem.Click += SupplyToolStripMenuItem_Click;
//
// продажаToolStripMenuItem
//
продажаToolStripMenuItem.Name = "продажаToolStripMenuItem";
продажаToolStripMenuItem.Size = new Size(224, 26);
продажаToolStripMenuItem.Text = "Продажа";
продажаToolStripMenuItem.Click += SellToolStripMenuItem_Click;
//
// MainForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1096, 493);
Controls.Add(buttonOrderUpdate);
Controls.Add(buttonOrderGive);
Controls.Add(buttonOrderReady);
Controls.Add(buttonDoOrder);
Controls.Add(buttonCreate);
Controls.Add(dataGridView);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Name = "MainForm";
Text = "Магазин пошива одежды";
Load += MainForm_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private DataGridView dataGridView;
private Button buttonCreate;
private Button buttonDoOrder;
private Button buttonOrderReady;
private Button buttonOrderGive;
private Button buttonOrderUpdate;
private MenuStrip menuStrip1;
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem платьяToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripMenuItem поставкиToolStripMenuItem;
private ToolStripMenuItem продажаToolStripMenuItem;
}
}

View File

@ -0,0 +1,177 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using System.Windows.Forms;
namespace SewingDressesView
{
public partial class MainForm : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
public MainForm(ILogger<MainForm> logger, IOrderLogic orderLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
}
private void LoadData()
{
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["DressId"].Visible = false;
dataGridView.Columns["DressName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
}
_logger.LogInformation("Load orders");
}
catch (Exception ex)
{
_logger.LogError(ex, "Load orders error");
}
}
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(ComponentsForm));
if (service is ComponentsForm form)
{
form.ShowDialog();
}
}
private void DressesToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(DressesForm));
if (service is DressesForm form)
{
form.ShowDialog();
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(OrderForm));
if (service is OrderForm form)
{
form.ShowDialog();
LoadData();
}
}
private void buttonDoOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Change Status on 'In work'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Change Status on 'In work' error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
var dressId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressId"].Value);
var count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value);
_logger.LogInformation("Order №{id}. Change status on 'Ready'", id);
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, DressId = dressId, Count = count });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Change status on 'Ready' error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonOrderGive_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Status change on 'Given'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Order №{id} given", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Change status on 'Give' error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonOrderUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
private void ShopsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(ShopsForm));
if (service is ShopsForm form)
{
form.ShowDialog();
}
}
private void SupplyToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(SupplyForm));
if (service is SupplyForm form)
{
form.ShowDialog();
}
}
private void MainForm_Load(object sender, EventArgs e)
{
LoadData();
}
private void SellToolStripMenuItem_Click(Object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(SellForm));
if (service is SellForm form)
{
form.ShowDialog();
}
}
}
}

View File

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

View File

@ -0,0 +1,143 @@
namespace SewingDressesView
{
partial class OrderForm
{
/// <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()
{
label1 = new Label();
label2 = new Label();
label3 = new Label();
comboBoxDress = new ComboBox();
textBoxCount = new TextBox();
textBoxSum = new TextBox();
buttonSave = new Button();
buttonCancel = new Button();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(26, 21);
label1.Name = "label1";
label1.Size = new Size(61, 20);
label1.TabIndex = 0;
label1.Text = "Платье:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(26, 65);
label2.Name = "label2";
label2.Size = new Size(93, 20);
label2.TabIndex = 1;
label2.Text = "Количество:";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(26, 107);
label3.Name = "label3";
label3.Size = new Size(55, 20);
label3.TabIndex = 2;
label3.Text = "Сумма";
//
// comboBoxDress
//
comboBoxDress.FormattingEnabled = true;
comboBoxDress.Location = new Point(142, 21);
comboBoxDress.Name = "comboBoxDress";
comboBoxDress.Size = new Size(288, 28);
comboBoxDress.TabIndex = 3;
comboBoxDress.SelectedIndexChanged += comboBoxDress_SelectedIndexChanged;
//
// textBoxCount
//
textBoxCount.Location = new Point(142, 62);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(288, 27);
textBoxCount.TabIndex = 4;
textBoxCount.TextChanged += textBoxCount_TextChanged;
//
// textBoxSum
//
textBoxSum.Location = new Point(142, 100);
textBoxSum.Name = "textBoxSum";
textBoxSum.Size = new Size(288, 27);
textBoxSum.TabIndex = 5;
//
// buttonSave
//
buttonSave.Location = new Point(222, 145);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 6;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(336, 145);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 7;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// OrderForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(484, 198);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxSum);
Controls.Add(textBoxCount);
Controls.Add(comboBoxDress);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "OrderForm";
Text = "Форма заказа";
Load += OrderForm_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label3;
private ComboBox comboBoxDress;
private TextBox textBoxCount;
private TextBox textBoxSum;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,118 @@
using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using Microsoft.Extensions.Logging;
namespace SewingDressesView
{
public partial class OrderForm : Form
{
private readonly ILogger _logger;
private readonly IDressLogic _logicD;
private readonly IOrderLogic _logicO;
public OrderForm(ILogger<OrderForm> logger, IDressLogic logicD, IOrderLogic logicO)
{
InitializeComponent();
_logger = logger;
_logicD = logicD;
_logicO = logicO;
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxDress.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа");
try
{
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
DressId = Convert.ToInt32(comboBoxDress.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text)
});
if (!operationResult)
{
throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Create order error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CalcSum()
{
if (comboBoxDress.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
{
try
{
int id = Convert.ToInt32(comboBoxDress.SelectedValue);
var dress = _logicD.ReadElement(new DressSearchModel
{
Id = id
});
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * dress?.Price ?? 0, 2).ToString();
}
catch (Exception ex)
{
_logger.LogError(ex, "Calculate sum order error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void comboBoxDress_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
private void textBoxCount_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void OrderForm_Load(object sender, EventArgs e)
{
try
{
var list = _logicD.ReadList(null);
if (list != null)
{
comboBoxDress.DisplayMember = "DressName";
comboBoxDress.ValueMember = "Id";
comboBoxDress.DataSource = list;
comboBoxDress.SelectedItem = null;
_logger.LogInformation("Load dress for order");
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Load dress for order error");
}
}
}
}

View File

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

View File

@ -0,0 +1,53 @@
using SewingDressesBusinessLogic.BusinessLogic;
using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.StoragesContracts;
using SewingDressesDatabaseImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using System.Drawing;
namespace SewingDressesView
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<MainForm>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IDressStorage, DressStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IDressLogic, DressLogic>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<MainForm>();
services.AddTransient<ComponentForm>();
services.AddTransient<ComponentsForm>();
services.AddTransient<OrderForm>();
services.AddTransient<DressForm>();
services.AddTransient<DressComponentForm>();
services.AddTransient<DressesForm>();
services.AddTransient<ShopForm>();
services.AddTransient<ShopsForm>();
services.AddTransient<SupplyForm>();
services.AddTransient<SellForm>();
}
}
}

View File

@ -0,0 +1,118 @@
namespace SewingDressesView
{
partial class SellForm
{
/// <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()
{
comboBoxDress = new ComboBox();
textBoxCount = new TextBox();
buttonSave = new Button();
buttonCancel = new Button();
label1 = new Label();
label2 = new Label();
SuspendLayout();
//
// comboBoxDress
//
comboBoxDress.FormattingEnabled = true;
comboBoxDress.Location = new Point(126, 30);
comboBoxDress.Name = "comboBoxDress";
comboBoxDress.Size = new Size(151, 28);
comboBoxDress.TabIndex = 0;
//
// textBoxCount
//
textBoxCount.Location = new Point(126, 95);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(151, 27);
textBoxCount.TabIndex = 1;
//
// buttonSave
//
buttonSave.Location = new Point(45, 172);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 2;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(183, 172);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 3;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(27, 33);
label1.Name = "label1";
label1.Size = new Size(58, 20);
label1.TabIndex = 4;
label1.Text = "Платье";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(27, 98);
label2.Name = "label2";
label2.Size = new Size(90, 20);
label2.TabIndex = 5;
label2.Text = "Количество";
//
// SellForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(306, 234);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxCount);
Controls.Add(comboBoxDress);
Name = "SellForm";
Text = "Продажа";
ResumeLayout(false);
PerformLayout();
}
#endregion
private ComboBox comboBoxDress;
private TextBox textBoxCount;
private Button buttonSave;
private Button buttonCancel;
private Label label1;
private Label label2;
}
}

View File

@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
namespace SewingDressesView
{
public partial class SellForm : Form
{
private readonly List<DressViewModel>? _dressList;
IShopLogic _shopLogic;
IDressLogic _dressLogic;
public SellForm(IDressLogic dressLogic, IShopLogic shopLogic)
{
InitializeComponent();
_shopLogic = shopLogic;
_dressLogic = dressLogic;
_dressList = dressLogic.ReadList(null);
if (_dressList != null)
{
comboBoxDress.DisplayMember = "DressName";
comboBoxDress.ValueMember = "Id";
comboBoxDress.DataSource = _dressList;
comboBoxDress.SelectedItem = null;
}
}
public int DressId
{
get
{
return Convert.ToInt32(comboBoxDress.SelectedValue);
}
set
{
comboBoxDress.SelectedValue = value;
}
}
public IDressModel? IceCreamModel
{
get
{
if (_dressList == null)
{
return null;
}
foreach (var elem in _dressList)
{
if (elem.Id == DressId)
{
return elem;
}
}
return null;
}
}
public int Count
{
get { return Convert.ToInt32(textBoxCount.Text); }
set
{ textBoxCount.Text = value.ToString(); }
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxDress.SelectedValue == null)
{
MessageBox.Show("Выберите мороженное", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
int count = Convert.ToInt32(textBoxCount.Text);
bool res = _shopLogic.MakeSell(
_dressLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxDress.SelectedValue) }),
count
);
if (!res)
{
throw new Exception("Ошибка при продаже.");
}
MessageBox.Show("Продажа прошла успешно");
DialogResult = DialogResult.OK;
Close();
}
catch (Exception err)
{
MessageBox.Show("Ошибка продажи");
return;
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
Close();
}
}
}

View File

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

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SewingDressesBusinessLogic\SewingDressesBusinessLogic.csproj" />
<ProjectReference Include="..\SewingDressesContracts\SewingDressesContracts.csproj" />
<ProjectReference Include="..\SewingDressesDatabaseImplement\SewingDressesDatabaseImplement.csproj" />
<ProjectReference Include="..\SewingDressesFileImplement\SewingDressesFileImplement.csproj" />
<ProjectReference Include="..\SewingDressesListImplement\SewingDressesListImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,217 @@
namespace SewingDressesView
{
partial class ShopForm
{
/// <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()
{
dateTimePicker = new DateTimePicker();
textBoxName = new TextBox();
textBoxAdress = new TextBox();
dataGridView = new DataGridView();
IdColumn = new DataGridViewTextBoxColumn();
Title = new DataGridViewTextBoxColumn();
Cost = new DataGridViewTextBoxColumn();
Count = new DataGridViewTextBoxColumn();
buttonSave = new Button();
buttonCancel = new Button();
label1 = new Label();
label2 = new Label();
label3 = new Label();
numeric = new NumericUpDown();
label4 = new Label();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
((System.ComponentModel.ISupportInitialize)numeric).BeginInit();
SuspendLayout();
//
// dateTimePicker
//
dateTimePicker.Location = new Point(714, 34);
dateTimePicker.Name = "dateTimePicker";
dateTimePicker.Size = new Size(250, 27);
dateTimePicker.TabIndex = 0;
//
// textBoxName
//
textBoxName.Location = new Point(714, 85);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(250, 27);
textBoxName.TabIndex = 1;
//
// textBoxAdress
//
textBoxAdress.Location = new Point(714, 139);
textBoxAdress.Name = "textBoxAdress";
textBoxAdress.Size = new Size(250, 27);
textBoxAdress.TabIndex = 2;
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { IdColumn, Title, Cost, Count });
dataGridView.Location = new Point(10, 32);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(554, 380);
dataGridView.TabIndex = 3;
//
// IdColumn
//
IdColumn.HeaderText = "Номер платья";
IdColumn.MinimumWidth = 6;
IdColumn.Name = "IdColumn";
IdColumn.Visible = false;
IdColumn.Width = 125;
//
// Title
//
Title.HeaderText = "Название";
Title.MinimumWidth = 6;
Title.Name = "Title";
Title.Width = 125;
//
// Cost
//
Cost.HeaderText = "Цена";
Cost.MinimumWidth = 6;
Cost.Name = "Cost";
Cost.Width = 125;
//
// Count
//
Count.HeaderText = "Количество";
Count.MinimumWidth = 6;
Count.Name = "Count";
Count.Width = 125;
//
// buttonSave
//
buttonSave.Location = new Point(714, 248);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 4;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(870, 248);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(592, 39);
label1.Name = "label1";
label1.Size = new Size(110, 20);
label1.TabIndex = 6;
label1.Text = "Дата создания";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(592, 88);
label2.Name = "label2";
label2.Size = new Size(77, 20);
label2.TabIndex = 7;
label2.Text = "Название";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(592, 142);
label3.Name = "label3";
label3.Size = new Size(51, 20);
label3.TabIndex = 8;
label3.Text = "Адрес";
//
// numeric
//
numeric.Location = new Point(714, 196);
numeric.Name = "numeric";
numeric.Size = new Size(150, 27);
numeric.TabIndex = 9;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(592, 198);
label4.Name = "label4";
label4.Size = new Size(100, 20);
label4.TabIndex = 10;
label4.Text = "Вместимость";
//
// ShopForm
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(976, 450);
Controls.Add(label4);
Controls.Add(numeric);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(dataGridView);
Controls.Add(textBoxAdress);
Controls.Add(textBoxName);
Controls.Add(dateTimePicker);
Name = "ShopForm";
Text = "Форма магазина";
Load += ShopForm_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
((System.ComponentModel.ISupportInitialize)numeric).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private DateTimePicker dateTimePicker;
private TextBox textBoxName;
private TextBox textBoxAdress;
private DataGridView dataGridView;
private Button buttonSave;
private Button buttonCancel;
private Label label1;
private Label label2;
private Label label3;
private DataGridViewTextBoxColumn IdColumn;
private DataGridViewTextBoxColumn Title;
private DataGridViewTextBoxColumn Cost;
private DataGridViewTextBoxColumn Count;
private NumericUpDown numeric;
private Label label4;
}
}

View File

@ -0,0 +1,123 @@
using Microsoft.Extensions.Logging;
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.SearchModels;
using SewingDressesDataModels.Models;
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 SewingDressesView
{
public partial class ShopForm : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
public int? _id;
private Dictionary<int, (IDressModel, int)> _dresses;
public ShopForm(ILogger<ShopForm> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void ShopForm_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Shop load");
try
{
var shop = _logic.ReadElement(new ShopSearchModel { Id = _id });
if (shop != null)
{
textBoxName.Text = shop.ShopName;
textBoxAdress.Text = shop.Adress;
dateTimePicker.Text = shop.DateOpen.ToString();
numeric.Value = shop.MaxCount;
_dresses = shop.ShopDresses ?? new Dictionary<int, (IDressModel, int)>();
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Load shop error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Load dresses");
try
{
if (_dresses != null)
{
foreach (var dress in _dresses)
{
dataGridView.Rows.Add(new object[] { dress.Key, dress.Value.Item1.DressName, dress.Value.Item1.Price, dress.Value.Item2 });
}
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Load dresses into shop error");
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("Save shop");
try
{
var model = new ShopBindingModel
{
Id = _id ?? 0,
ShopName = textBoxName.Text,
Adress = textBoxAdress.Text,
DateOpen = dateTimePicker.Value.Date,
MaxCount = Convert.ToInt32(numeric.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, "Save shop error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

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

Some files were not shown because too many files have changed in this diff Show More