PIbd-21. Kryukov A.I. Lab work 01 base #1

Closed
SooNooClose wants to merge 5 commits from lab_1_base into main
68 changed files with 569 additions and 590 deletions
Showing only changes of commit 581c059cf7 - Show all commits

View File

@ -1,23 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.EventSource" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SnackBarContracts\SnackBarContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarDataModels.Models;
namespace SnackBarContracts.BindingModels
{
public class SnackBindingModel : ISnackModel
{
public int Id { get; set; }
public string SnackName { get; set; } = string.Empty;
public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> SnackComponents { get; set; } = new();
}
}

View File

@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarContracts.BindingModels;
using SnackBarContracts.SearchModels;
using SnackBarContracts.ViewModels;
namespace SnackBarContracts.BusinessLogicsContracts
{
public interface ISnackLogic
{
List<SnackViewModel>? ReadList(SnackSearchModel? model);
SnackViewModel? ReadElement(SnackSearchModel model);
bool Create(SnackBindingModel model);
bool Update(SnackBindingModel model);
bool Delete(SnackBindingModel model);
}
}

View File

@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarContracts.BindingModels;
using SnackBarContracts.SearchModels;
using SnackBarContracts.ViewModels;
namespace SnackBarContracts.StoragesContracts
{
public interface ISnackStorage
{
List<SnackViewModel> GetFullList();
List<SnackViewModel> GetFilteredList(SnackSearchModel model);
SnackViewModel? GetElement(SnackSearchModel model);
SnackViewModel? Insert(SnackBindingModel model);
SnackViewModel? Update(SnackBindingModel model);
SnackViewModel? Delete(SnackBindingModel model);
}
}

View File

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnackBarDataModels.Models
{
public interface ISnackModel : IId
{
string SnackName { get; }
double Price { get; }
Dictionary<int, (IComponentModel, int)> SnackComponents { get; }
}
}

View File

@ -1,51 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarContracts.BindingModels;
using SnackBarContracts.ViewModels;
using SnackBarDataModels.Models;
namespace SnackBarListImplement.Models
{
public class Snack : ISnackModel
{
public int Id { get; private set; }
public string SnackName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> SnackComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();
public static Snack? Create(SnackBindingModel? model)
{
if (model == null)
{
return null;
}
return new Snack()
{
Id = model.Id,
SnackName = model.SnackName,
Price = model.Price,
SnackComponents = model.SnackComponents
};
}
public void Update(SnackBindingModel? model)
{
if (model == null)
{
return;
}
SnackName = model.SnackName;
Price = model.Price;
SnackComponents = model.SnackComponents;
}
public SnackViewModel GetViewModel => new()
{
Id = Id,
SnackName = SnackName,
Price = Price,
SnackComponents = SnackComponents
};
}
}

View File

@ -1,111 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
using SnackBarContracts.BindingModels;
using SnackBarContracts.SearchModels;
using SnackBarContracts.StoragesContracts;
using SnackBarContracts.ViewModels;
using SnackBarListImplement.Models;
namespace SnackBarListImplement.Implements
{
public class SnackStorage : ISnackStorage
{
private readonly DataListSingleton _source;
public SnackStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<SnackViewModel> GetFullList()
{
var result = new List<SnackViewModel>();
foreach (var snack in _source.Snacks)
{
result.Add(snack.GetViewModel);
}
return result;
}
public List<SnackViewModel> GetFilteredList(SnackSearchModel model)
{
var result = new List<SnackViewModel>();
if (string.IsNullOrEmpty(model.SnackName))
{
return result;
}
foreach (var snack in _source.Snacks)
{
if (snack.SnackName.Contains(model.SnackName))
{
result.Add(snack.GetViewModel);
}
}
return result;
}
public SnackViewModel? GetElement(SnackSearchModel model)
{
if (string.IsNullOrEmpty(model.SnackName) && !model.Id.HasValue)
{
return null;
}
foreach (var snack in _source.Snacks)
{
if ((!string.IsNullOrEmpty(model.SnackName) && snack.SnackName == model.SnackName) || (model.Id.HasValue && snack.Id == model.Id))
{
return snack.GetViewModel;
}
}
return null;
}
public SnackViewModel? Insert(SnackBindingModel model)
{
model.Id = 1;
foreach (var snack in _source.Snacks)
{
if (model.Id <= snack.Id)
{
model.Id = snack.Id + 1;
}
}
var newSnack = Snack.Create(model);
if (newSnack == null)
{
return null;
}
_source.Snacks.Add(newSnack);
return newSnack.GetViewModel;
}
public SnackViewModel? Update(SnackBindingModel model)
{
foreach (var snack in _source.Snacks)
{
if (snack.Id == model.Id)
{
snack.Update(model);
return snack.GetViewModel;
}
}
return null;
}
public SnackViewModel? Delete(SnackBindingModel model)
{
for (int i = 0; i < _source.Snacks.Count; ++i)
{
if (_source.Snacks[i].Id == model.Id)
{
var element = _source.Snacks[i];
_source.Snacks.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -3,16 +3,16 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarContracts.BindingModels;
using SnackBarContracts.BusinessLogicsContracts;
using SnackBarContracts.SearchModels;
using SnackBarContracts.StoragesContracts;
using SnackBarContracts.ViewModels;
using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using TypographyContracts.SearchModels;
using TypographyContracts.StoragesContracts;
using TypographyContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace SnackBarBusinessLogic.BusinessLogics
namespace TypographyBusinessLogic.BusinessLogics
{
public class ComponentLogic : IComponentLogic
{

View File

@ -1,17 +1,17 @@
using SnackBarContracts.BusinessLogicsContracts;
using TypographyContracts.BusinessLogicsContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarContracts.BindingModels;
using SnackBarContracts.SearchModels;
using SnackBarContracts.StoragesContracts;
using SnackBarContracts.ViewModels;
using SnackBarDataModels.Enums;
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.StoragesContracts;
using TypographyContracts.ViewModels;
using TypographyDataModels.Enums;
using Microsoft.Extensions.Logging;
namespace SnackBarBusinessLogic.BusinessLogics
namespace TypographyBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
@ -102,9 +102,9 @@ namespace SnackBarBusinessLogic.BusinessLogics
{
return;
}
if (model.SnackId < 0)
if (model.PrintedId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор закусок", nameof(model.SnackId));
throw new ArgumentNullException("Некорректный идентификатор закусок", nameof(model.PrintedId));
}
if (model.Count <= 0)
{

View File

@ -1,30 +1,30 @@
using Microsoft.Extensions.Logging;
using SnackBarBusinessLogic.BusinessLogics;
using SnackBarContracts.BindingModels;
using SnackBarContracts.BusinessLogicsContracts;
using SnackBarContracts.SearchModels;
using SnackBarContracts.StoragesContracts;
using SnackBarContracts.ViewModels;
using TypographyBusinessLogic.BusinessLogics;
using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using TypographyContracts.SearchModels;
using TypographyContracts.StoragesContracts;
using TypographyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnackBarBusinessLogic.BusinessLogics
namespace TypographyBusinessLogic.BusinessLogics
{
public class SnackLogic : ISnackLogic
public class PrintedLogic : IPrintedLogic
{
private readonly ILogger _logger;
private readonly ISnackStorage _snackStorage;
public SnackLogic(ILogger<SnackLogic> logger, ISnackStorage snackStorage)
private readonly IPrintedStorage _snackStorage;
public PrintedLogic(ILogger<PrintedLogic> logger, IPrintedStorage snackStorage)
{
_logger = logger;
_snackStorage = snackStorage;
}
public List<SnackViewModel>? ReadList(SnackSearchModel? model)
public List<PrintedViewModel>? ReadList(PrintedSearchModel? model)
{
_logger.LogInformation("ReadList. SnackName:{SnackName}.Id:{ Id}", model?.SnackName, model?.Id);
_logger.LogInformation("ReadList. PrintedName:{PrintedName}.Id:{ Id}", model?.PrintedName, model?.Id);
var list = model == null ? _snackStorage.GetFullList() : _snackStorage.GetFilteredList(model);
if (list == null)
{
@ -34,13 +34,13 @@ namespace SnackBarBusinessLogic.BusinessLogics
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public SnackViewModel? ReadElement(SnackSearchModel model)
public PrintedViewModel? ReadElement(PrintedSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. SnackName:{SnackName}.Id:{ Id}", model.SnackName, model.Id);
_logger.LogInformation("ReadElement. PrintedName:{PrintedName}.Id:{ Id}", model.PrintedName, model.Id);
var element = _snackStorage.GetElement(model);
if (element == null)
{
@ -50,7 +50,7 @@ namespace SnackBarBusinessLogic.BusinessLogics
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(SnackBindingModel model)
public bool Create(PrintedBindingModel model)
{
CheckModel(model);
if (_snackStorage.Insert(model) == null)
@ -60,7 +60,7 @@ namespace SnackBarBusinessLogic.BusinessLogics
}
return true;
}
public bool Update(SnackBindingModel model)
public bool Update(PrintedBindingModel model)
{
CheckModel(model);
if (_snackStorage.Update(model) == null)
@ -70,7 +70,7 @@ namespace SnackBarBusinessLogic.BusinessLogics
}
return true;
}
public bool Delete(SnackBindingModel model)
public bool Delete(PrintedBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
@ -81,7 +81,7 @@ namespace SnackBarBusinessLogic.BusinessLogics
}
return true;
}
private void CheckModel(SnackBindingModel model, bool withParams = true)
private void CheckModel(PrintedBindingModel model, bool withParams = true)
{
if (model == null)
{
@ -91,19 +91,19 @@ namespace SnackBarBusinessLogic.BusinessLogics
{
return;
}
if (string.IsNullOrEmpty(model.SnackName))
if (string.IsNullOrEmpty(model.PrintedName))
{
throw new ArgumentNullException("Нет названия закуски",
nameof(model.SnackName));
nameof(model.PrintedName));
}
if (model.Price <= 0)
{
throw new ArgumentNullException("Цена закуски должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation("Snack. SnackName:{SnackName}.Price:{ Price}. Id: { Id}", model.SnackName, model.Price, model.Id);
var element = _snackStorage.GetElement(new SnackSearchModel
_logger.LogInformation("Printed. PrintedName:{PrintedName}.Price:{ Price}. Id: { Id}", model.PrintedName, model.Price, model.Id);
var element = _snackStorage.GetElement(new PrintedSearchModel
{
SnackName = model.SnackName
PrintedName = model.PrintedName
});
if (element != null && element.Id != model.Id)
{

View File

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

View File

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarDataModels.Models;
using TypographyDataModels.Models;
namespace SnackBarContracts.BindingModels
namespace TypographyContracts.BindingModels
{
public class ComponentBindingModel : IComponentModel
{

View File

@ -3,15 +3,15 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarDataModels.Enums;
using SnackBarDataModels.Models;
using TypographyDataModels.Enums;
using TypographyDataModels.Models;
namespace SnackBarContracts.BindingModels
namespace TypographyContracts.BindingModels
{
public class OrderBindingModel : IOrderModel
{
public int Id { get; set; }
public int SnackId { get; set; }
public int PrintedId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TypographyDataModels.Models;
namespace TypographyContracts.BindingModels
{
public class PrintedBindingModel : IPrintedModel
{
public int Id { get; set; }
public string PrintedName { get; set; } = string.Empty;
public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> PrintedComponents { get; set; } = new();
}
}

View File

@ -3,12 +3,12 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarContracts.BindingModels;
using SnackBarContracts.SearchModels;
using SnackBarContracts.ViewModels;
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.ViewModels;
namespace SnackBarContracts.BusinessLogicsContracts
namespace TypographyContracts.BusinessLogicsContracts
{
public interface IComponentLogic
{

View File

@ -3,12 +3,12 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarContracts.BindingModels;
using SnackBarContracts.SearchModels;
using SnackBarContracts.ViewModels;
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.ViewModels;
namespace SnackBarContracts.BusinessLogicsContracts
namespace TypographyContracts.BusinessLogicsContracts
{
public interface IOrderLogic
{

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.ViewModels;
namespace TypographyContracts.BusinessLogicsContracts
{
public interface IPrintedLogic
{
List<PrintedViewModel>? ReadList(PrintedSearchModel? model);
PrintedViewModel? ReadElement(PrintedSearchModel model);
bool Create(PrintedBindingModel model);
bool Update(PrintedBindingModel model);
bool Delete(PrintedBindingModel model);
}
}

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnackBarContracts.SearchModels
namespace TypographyContracts.SearchModels
{
public class ComponentSearchModel
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnackBarContracts.SearchModels
namespace TypographyContracts.SearchModels
{
public class OrderSearchModel
{

View File

@ -4,11 +4,11 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnackBarContracts.SearchModels
namespace TypographyContracts.SearchModels
{
public class SnackSearchModel
public class PrintedSearchModel
{
public int? Id { get; set; }
public string? SnackName { get; set; }
public string? PrintedName { get; set; }
}
}

View File

@ -1,13 +1,13 @@
using SnackBarContracts.BindingModels;
using SnackBarContracts.SearchModels;
using SnackBarContracts.ViewModels;
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnackBarContracts.StoragesContracts
namespace TypographyContracts.StoragesContracts
{
public interface IComponentStorage
{

View File

@ -1,13 +1,13 @@
using SnackBarContracts.BindingModels;
using SnackBarContracts.SearchModels;
using SnackBarContracts.ViewModels;
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnackBarContracts.StoragesContracts
namespace TypographyContracts.StoragesContracts
{
public interface IOrderStorage
{

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.ViewModels;
namespace TypographyContracts.StoragesContracts
{
public interface IPrintedStorage
{
List<PrintedViewModel> GetFullList();
List<PrintedViewModel> GetFilteredList(PrintedSearchModel model);
PrintedViewModel? GetElement(PrintedSearchModel model);
PrintedViewModel? Insert(PrintedBindingModel model);
PrintedViewModel? Update(PrintedBindingModel model);
PrintedViewModel? Delete(PrintedBindingModel model);
}
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SnackBarDataModels\SnackBarDataModels.csproj" />
<ProjectReference Include="..\TypographyDataModels\TypographyDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -3,10 +3,10 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarDataModels.Models;
using TypographyDataModels.Models;
using System.ComponentModel;
namespace SnackBarContracts.ViewModels
namespace TypographyContracts.ViewModels
{
public class ComponentViewModel : IComponentModel
{

View File

@ -3,20 +3,20 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarDataModels.Enums;
using SnackBarDataModels.Models;
using TypographyDataModels.Enums;
using TypographyDataModels.Models;
using System.ComponentModel;
namespace SnackBarContracts.ViewModels
namespace TypographyContracts.ViewModels
{
public class OrderViewModel : IOrderModel
{
[DisplayName("Номер")]
public int Id { get; set; }
public int SnackId { get; set; }
public int PrintedId { get; set; }
[DisplayName("Изделие")]
public string SnackName { get; set; } = string.Empty;
public string PrintedName { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }
[DisplayName("Сумма")]

View File

@ -3,19 +3,19 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarDataModels.Models;
using TypographyDataModels.Models;
using System.ComponentModel;
namespace SnackBarContracts.ViewModels
namespace TypographyContracts.ViewModels
{
public class SnackViewModel : ISnackModel
public class PrintedViewModel : IPrintedModel
{
public int Id { get; set; }
[DisplayName("Название изделия")]
public string SnackName { get; set; } = string.Empty;
public string PrintedName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> SnackComponents { get; set; } = new();
public Dictionary<int, (IComponentModel, int)> PrintedComponents { get; set; } = new();
}
}

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnackBarDataModels.Models
namespace TypographyDataModels.Models
{
public interface IComponentModel : IId
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnackBarDataModels
namespace TypographyDataModels
{
public interface IId
{

View File

@ -4,11 +4,11 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SnackBarDataModels.Enums
namespace TypographyDataModels.Enums
{
public interface IOrderModel : IId
{
int SnackId { get; }
int PrintedId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TypographyDataModels.Models
{
public interface IPrintedModel : IId
{
string PrintedName { get; }
double Price { get; }
Dictionary<int, (IComponentModel, int)> PrintedComponents { get; }
}
}

View File

@ -1,4 +1,4 @@
namespace SnackBarDataModels.Enums
namespace TypographyDataModels.Enums
{
public enum OrderStatus
{

View File

@ -3,11 +3,11 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarContracts.BindingModels;
using SnackBarContracts.ViewModels;
using SnackBarDataModels.Models;
using TypographyContracts.BindingModels;
using TypographyContracts.ViewModels;
using TypographyDataModels.Models;
namespace SnackBarListImplement.Models
namespace TypographyListImplement.Models
{
public class Component : IComponentModel
{

View File

@ -3,14 +3,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarContracts.BindingModels;
using SnackBarContracts.SearchModels;
using SnackBarContracts.StoragesContracts;
using SnackBarContracts.ViewModels;
using SnackBarListImplement.Models;
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.StoragesContracts;
using TypographyContracts.ViewModels;
using TypographyListImplement.Models;
namespace SnackBarListImplement.Implements
namespace TypographyListImplement.Implements
{
public class ComponentStorage : IComponentStorage
{

View File

@ -3,21 +3,21 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarListImplement.Models;
using TypographyListImplement.Models;
namespace SnackBarListImplement
namespace TypographyListImplement
{
public class DataListSingleton
{
private static DataListSingleton? _instance;
public List<Component> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Snack> Snacks { get; set; }
public List<Printed> Printeds { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Snacks = new List<Snack>();
Printeds = new List<Printed>();
}
public static DataListSingleton GetInstance()
{

View File

@ -3,16 +3,16 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarContracts.BindingModels;
using SnackBarContracts.ViewModels;
using SnackBarDataModels.Enums;
using SnackBarDataModels.Models;
using TypographyContracts.BindingModels;
using TypographyContracts.ViewModels;
using TypographyDataModels.Enums;
using TypographyDataModels.Models;
namespace SnackBarListImplement.Models
namespace TypographyListImplement.Models
{
public class Order : IOrderModel
{
public int SnackId { get; private set; }
public int PrintedId { get; private set; }
public int Count { get; private set; }
@ -35,7 +35,7 @@ namespace SnackBarListImplement.Models
return new Order
{
Id = model.Id,
SnackId = model.SnackId,
PrintedId = model.PrintedId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@ -51,7 +51,7 @@ namespace SnackBarListImplement.Models
return;
}
Id = model.Id;
SnackId = model.SnackId;
PrintedId = model.PrintedId;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
@ -61,7 +61,7 @@ namespace SnackBarListImplement.Models
public OrderViewModel GetViewModel => new()
{
SnackId = SnackId,
PrintedId = PrintedId,
Count = Count,
Sum = Sum,
DateCreate = DateCreate,

View File

@ -3,13 +3,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SnackBarContracts.BindingModels;
using SnackBarContracts.SearchModels;
using SnackBarContracts.StoragesContracts;
using SnackBarContracts.ViewModels;
using SnackBarListImplement.Models;
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.StoragesContracts;
using TypographyContracts.ViewModels;
using TypographyListImplement.Models;
namespace SnackBarListImplement.Implements
namespace TypographyListImplement.Implements
{
public class OrderStorage : IOrderStorage
{
@ -25,7 +25,7 @@ namespace SnackBarListImplement.Implements
var result = new List<OrderViewModel>();
foreach (var order in _source.Orders)
{
result.Add(AddSnackName(order.GetViewModel));
result.Add(AddPrintedName(order.GetViewModel));
}
return result;
}
@ -41,7 +41,7 @@ namespace SnackBarListImplement.Implements
{
if (order.Id == model.Id)
{
result.Add(AddSnackName(order.GetViewModel));
result.Add(AddPrintedName(order.GetViewModel));
}
}
return result;
@ -57,7 +57,7 @@ namespace SnackBarListImplement.Implements
{
if (order.Id == model.Id)
{
return AddSnackName(order.GetViewModel);
return AddPrintedName(order.GetViewModel);
}
}
return null;
@ -79,7 +79,7 @@ namespace SnackBarListImplement.Implements
return null;
}
_source.Orders.Add(newOrder);
return AddSnackName(newOrder.GetViewModel);
return AddPrintedName(newOrder.GetViewModel);
}
public OrderViewModel? Update(OrderBindingModel model)
@ -89,7 +89,7 @@ namespace SnackBarListImplement.Implements
if (order.Id == model.Id)
{
order.Update(model);
return AddSnackName(order.GetViewModel);
return AddPrintedName(order.GetViewModel);
}
}
return null;
@ -103,18 +103,18 @@ namespace SnackBarListImplement.Implements
{
var element = _source.Orders[i];
_source.Orders.RemoveAt(i);
return AddSnackName(element.GetViewModel);
return AddPrintedName(element.GetViewModel);
}
}
return null;
}
private OrderViewModel AddSnackName(OrderViewModel model)
private OrderViewModel AddPrintedName(OrderViewModel model)
{
var selectedSnack = _source.Snacks.Find(snack => snack.Id == model.SnackId);
if (selectedSnack != null)
var selectedPrinted = _source.Printeds.Find(printed => printed.Id == model.PrintedId);
if (selectedPrinted != null)
{
model.SnackName = selectedSnack.SnackName;
model.PrintedName = selectedPrinted.PrintedName;
}
return model;
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TypographyContracts.BindingModels;
using TypographyContracts.ViewModels;
using TypographyDataModels.Models;
namespace TypographyListImplement.Models
{
public class Printed : IPrintedModel
{
public int Id { get; private set; }
public string PrintedName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, (IComponentModel, int)> PrintedComponents { get; private set; } = new Dictionary<int, (IComponentModel, int)>();
public static Printed? Create(PrintedBindingModel? model)
{
if (model == null)
{
return null;
}
return new Printed()
{
Id = model.Id,
PrintedName = model.PrintedName,
Price = model.Price,
PrintedComponents = model.PrintedComponents
};
}
public void Update(PrintedBindingModel? model)
{
if (model == null)
{
return;
}
PrintedName = model.PrintedName;
Price = model.Price;
PrintedComponents = model.PrintedComponents;
}
public PrintedViewModel GetViewModel => new()
{
Id = Id,
PrintedName = PrintedName,
Price = Price,
PrintedComponents = PrintedComponents
};
}
}

View File

@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.StoragesContracts;
using TypographyContracts.ViewModels;
using TypographyListImplement.Models;
namespace TypographyListImplement.Implements
{
public class PrintedStorage : IPrintedStorage
{
private readonly DataListSingleton _source;
public PrintedStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<PrintedViewModel> GetFullList()
{
var result = new List<PrintedViewModel>();
foreach (var printed in _source.Printeds)
{
result.Add(printed.GetViewModel);
}
return result;
}
public List<PrintedViewModel> GetFilteredList(PrintedSearchModel model)
{
var result = new List<PrintedViewModel>();
if (string.IsNullOrEmpty(model.PrintedName))
{
return result;
}
foreach (var printed in _source.Printeds)
{
if (printed.PrintedName.Contains(model.PrintedName))
{
result.Add(printed.GetViewModel);
}
}
return result;
}
public PrintedViewModel? GetElement(PrintedSearchModel model)
{
if (string.IsNullOrEmpty(model.PrintedName) && !model.Id.HasValue)
{
return null;
}
foreach (var printed in _source.Printeds)
{
if ((!string.IsNullOrEmpty(model.PrintedName) && printed.PrintedName == model.PrintedName) || (model.Id.HasValue && printed.Id == model.Id))
{
return printed.GetViewModel;
}
}
return null;
}
public PrintedViewModel? Insert(PrintedBindingModel model)
{
model.Id = 1;
foreach (var printed in _source.Printeds)
{
if (model.Id <= printed.Id)
{
model.Id = printed.Id + 1;
}
}
var newPrinted = Printed.Create(model);
if (newPrinted == null)
{
return null;
}
_source.Printeds.Add(newPrinted);
return newPrinted.GetViewModel;
}
public PrintedViewModel? Update(PrintedBindingModel model)
{
foreach (var printed in _source.Printeds)
{
if (printed.Id == model.Id)
{
printed.Update(model);
return printed.GetViewModel;
}
}
return null;
}
public PrintedViewModel? Delete(PrintedBindingModel model)
{
for (int i = 0; i < _source.Printeds.Count; ++i)
{
if (_source.Printeds[i].Id == model.Id)
{
var element = _source.Printeds[i];
_source.Printeds.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -7,8 +7,8 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SnackBarContracts\SnackBarContracts.csproj" />
<ProjectReference Include="..\SnackBarDataModels\SnackBarDataModels.csproj" />
<ProjectReference Include="..\TypographyContracts\TypographyContracts.csproj" />
<ProjectReference Include="..\TypographyDataModels\TypographyDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -1,4 +1,4 @@
namespace SnackBarView
namespace TypographyView
{
partial class FormComponent
{

View File

@ -1,11 +1,11 @@
using SnackBarContracts.BindingModels;
using SnackBarContracts.BusinessLogicsContracts;
using SnackBarContracts.SearchModels;
using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using TypographyContracts.SearchModels;
using Microsoft.Extensions.Logging;
using System.Windows.Forms;
namespace SnackBarView
namespace TypographyView
{
public partial class FormComponent : Form
{

View File

@ -1,4 +1,4 @@
namespace SnackBarView
namespace TypographyView
{
partial class FormComponents
{

View File

@ -7,12 +7,12 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SnackBarContracts.BindingModels;
using SnackBarContracts.BusinessLogicsContracts;
using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
namespace SnackBarView
namespace TypographyView
{
public partial class FormComponents : Form
{

View File

@ -1,4 +1,4 @@
namespace SnackBarView
namespace TypographyView
{
partial class FormCreateOrder
{
@ -28,24 +28,24 @@
/// </summary>
private void InitializeComponent()
{
labelSnack = new Label();
labelPrinted = new Label();
labelCount = new Label();
labelSum = new Label();
comboBoxSnack = new ComboBox();
comboBoxPrinted = new ComboBox();
textBoxCount = new TextBox();
textBoxSum = new TextBox();
buttonSave = new Button();
buttonCancel = new Button();
SuspendLayout();
//
// labelSnack
// labelPrinted
//
labelSnack.AutoSize = true;
labelSnack.Location = new Point(12, 22);
labelSnack.Name = "labelSnack";
labelSnack.Size = new Size(64, 20);
labelSnack.TabIndex = 0;
labelSnack.Text = "Закуска:";
labelPrinted.AutoSize = true;
labelPrinted.Location = new Point(12, 22);
labelPrinted.Name = "labelPrinted";
labelPrinted.Size = new Size(71, 20);
labelPrinted.TabIndex = 0;
labelPrinted.Text = "Изделие:";
//
// labelCount
//
@ -65,14 +65,14 @@
labelSum.TabIndex = 2;
labelSum.Text = "Сумма:";
//
// comboBoxSnack
// comboBoxPrinted
//
comboBoxSnack.FormattingEnabled = true;
comboBoxSnack.Location = new Point(111, 19);
comboBoxSnack.Name = "comboBoxSnack";
comboBoxSnack.Size = new Size(238, 28);
comboBoxSnack.TabIndex = 3;
comboBoxSnack.SelectedIndexChanged += ComboBoxSnack_SelectedIndexChanged;
comboBoxPrinted.FormattingEnabled = true;
comboBoxPrinted.Location = new Point(111, 19);
comboBoxPrinted.Name = "comboBoxPrinted";
comboBoxPrinted.Size = new Size(238, 28);
comboBoxPrinted.TabIndex = 3;
comboBoxPrinted.SelectedIndexChanged += ComboBoxPrinted_SelectedIndexChanged;
//
// textBoxCount
//
@ -118,10 +118,10 @@
Controls.Add(buttonSave);
Controls.Add(textBoxSum);
Controls.Add(textBoxCount);
Controls.Add(comboBoxSnack);
Controls.Add(comboBoxPrinted);
Controls.Add(labelSum);
Controls.Add(labelCount);
Controls.Add(labelSnack);
Controls.Add(labelPrinted);
Name = "FormCreateOrder";
Text = "Заказ";
Load += FormCreateOrder_Load;
@ -131,10 +131,10 @@
#endregion
private Label labelSnack;
private Label labelPrinted;
private Label labelCount;
private Label labelSum;
private ComboBox comboBoxSnack;
private ComboBox comboBoxPrinted;
private TextBox textBoxCount;
private TextBox textBoxSum;
private Button buttonSave;

View File

@ -1,22 +1,22 @@
using SnackBarContracts.BindingModels;
using SnackBarContracts.BusinessLogicsContracts;
using SnackBarContracts.SearchModels;
using SnackBarContracts.ViewModels;
using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using TypographyContracts.SearchModels;
using TypographyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic.Logging;
using System.Windows.Forms;
namespace SnackBarView
namespace TypographyView
{
public partial class FormCreateOrder : Form
{
private readonly ILogger _logger;
private readonly ISnackLogic _logicIC;
private readonly IPrintedLogic _logicIC;
private readonly IOrderLogic _logicO;
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISnackLogic logicIC, IOrderLogic logicO)
public FormCreateOrder(ILogger<FormCreateOrder> logger, IPrintedLogic logicIC, IOrderLogic logicO)
{
InitializeComponent();
_logger = logger;
@ -26,33 +26,33 @@ namespace SnackBarView
private void FormCreateOrder_Load(object sender, EventArgs e)
{
_logger.LogInformation("Loading snack for order");
_logger.LogInformation("Loading printed for order");
try
{
var snackList = _logicIC.ReadList(null);
if (snackList != null)
var printedList = _logicIC.ReadList(null);
if (printedList != null)
{
comboBoxSnack.DisplayMember = "SnackName";
comboBoxSnack.ValueMember = "Id";
comboBoxSnack.DataSource = snackList;
comboBoxSnack.SelectedItem = null;
comboBoxPrinted.DisplayMember = "PrintedName";
comboBoxPrinted.ValueMember = "Id";
comboBoxPrinted.DataSource = printedList;
comboBoxPrinted.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading snack for order");
_logger.LogError(ex, "Error during loading printed for order");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CalcSum()
{
if (comboBoxSnack.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
if (comboBoxPrinted.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
{
try
{
int id = Convert.ToInt32(comboBoxSnack.SelectedValue);
var product = _logicIC.ReadElement(new SnackSearchModel { Id = id });
int id = Convert.ToInt32(comboBoxPrinted.SelectedValue);
var product = _logicIC.ReadElement(new PrintedSearchModel { Id = id });
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
_logger.LogInformation("Calculation of order sum");
@ -70,7 +70,7 @@ namespace SnackBarView
CalcSum();
}
private void ComboBoxSnack_SelectedIndexChanged(object sender, EventArgs e)
private void ComboBoxPrinted_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
@ -82,7 +82,7 @@ namespace SnackBarView
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxSnack.SelectedValue == null)
if (comboBoxPrinted.SelectedValue == null)
{
MessageBox.Show("Выберите закуску", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
@ -92,7 +92,7 @@ namespace SnackBarView
{
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
SnackId = Convert.ToInt32(comboBoxSnack.SelectedValue),
PrintedId = Convert.ToInt32(comboBoxPrinted.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text)
});

View File

@ -1,4 +1,4 @@
namespace SnackBarView
namespace TypographyView
{
partial class FormMain
{
@ -31,7 +31,7 @@
menuStrip = new MenuStrip();
справочникиToolStripMenuItem = new ToolStripMenuItem();
компонентыToolStripMenuItem = new ToolStripMenuItem();
закускаToolStripMenuItem = new ToolStripMenuItem();
изделиеToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
@ -54,7 +54,7 @@
//
// справочникиToolStripMenuItem
//
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, закускаToolStripMenuItem });
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделиеToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(117, 24);
справочникиToolStripMenuItem.Text = "Справочники";
@ -66,12 +66,12 @@
компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
//
// закускаToolStripMenuItem
// изделиеToolStripMenuItem
//
закускаToolStripMenuItem.Name = "закускаToolStripMenuItem";
закускаToolStripMenuItem.Size = new Size(224, 26);
закускаToolStripMenuItem.Text = "Закуска";
закускаToolStripMenuItem.Click += ЗакускаToolStripMenuItem_Click;
изделиеToolStripMenuItem.Name = "изделиеToolStripMenuItem";
изделиеToolStripMenuItem.Size = new Size(224, 26);
изделиеToolStripMenuItem.Text = "Изделие";
изделиеToolStripMenuItem.Click += ЗакускаToolStripMenuItem_Click;
//
// dataGridView
//
@ -149,7 +149,7 @@
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Name = "FormMain";
Text = "Закусочная";
Text = "Типография";
Load += FormMain_Load;
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
@ -169,6 +169,6 @@
private Button buttonIssuedOrder;
private Button buttonUpd;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem закускаToolStripMenuItem;
private ToolStripMenuItem изделиеToolStripMenuItem;
}
}

View File

@ -7,12 +7,12 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SnackBarContracts.BindingModels;
using SnackBarContracts.BusinessLogicsContracts;
using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using SnackBarDataModels.Enums;
using TypographyDataModels.Enums;
namespace SnackBarView
namespace TypographyView
{
public partial class FormMain : Form
{
@ -40,8 +40,8 @@ namespace SnackBarView
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["SnackId"].Visible = false;
dataGridView.Columns["SnackName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["PrintedId"].Visible = false;
dataGridView.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Orders loading");
}
@ -63,8 +63,8 @@ namespace SnackBarView
private void ЗакускаToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSnacks));
if (service is FormSnacks form)
var service = Program.ServiceProvider?.GetService(typeof(FormPrinteds));
if (service is FormPrinteds form)
{
form.ShowDialog();
}
@ -159,7 +159,7 @@ namespace SnackBarView
return new OrderBindingModel
{
Id = id,
SnackId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SnackId"].Value),
PrintedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PrintedId"].Value),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),

View File

@ -1,6 +1,6 @@
namespace SnackBarView
namespace TypographyView
{
partial class FormSnack
partial class FormPrinted
{
/// <summary>
/// Required designer variable.
@ -50,35 +50,33 @@
// labelName
//
labelName.AutoSize = true;
labelName.Location = new Point(10, 7);
labelName.Location = new Point(11, 9);
labelName.Name = "labelName";
labelName.Size = new Size(62, 15);
labelName.Size = new Size(80, 20);
labelName.TabIndex = 0;
labelName.Text = "Название:";
//
// labelPrice
//
labelPrice.AutoSize = true;
labelPrice.Location = new Point(10, 42);
labelPrice.Location = new Point(11, 56);
labelPrice.Name = "labelPrice";
labelPrice.Size = new Size(70, 15);
labelPrice.Size = new Size(86, 20);
labelPrice.TabIndex = 1;
labelPrice.Text = "Стоимость:";
//
// textBoxName
//
textBoxName.Location = new Point(86, 4);
textBoxName.Margin = new Padding(3, 2, 3, 2);
textBoxName.Location = new Point(98, 5);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(261, 23);
textBoxName.Size = new Size(298, 27);
textBoxName.TabIndex = 2;
//
// textBoxPrice
//
textBoxPrice.Location = new Point(86, 40);
textBoxPrice.Margin = new Padding(3, 2, 3, 2);
textBoxPrice.Location = new Point(98, 53);
textBoxPrice.Name = "textBoxPrice";
textBoxPrice.Size = new Size(167, 23);
textBoxPrice.Size = new Size(190, 27);
textBoxPrice.TabIndex = 3;
//
// groupBoxComponents
@ -88,21 +86,18 @@
groupBoxComponents.Controls.Add(buttonEdit);
groupBoxComponents.Controls.Add(buttonAdd);
groupBoxComponents.Controls.Add(dataGridView);
groupBoxComponents.Location = new Point(10, 64);
groupBoxComponents.Margin = new Padding(3, 2, 3, 2);
groupBoxComponents.Location = new Point(11, 85);
groupBoxComponents.Name = "groupBoxComponents";
groupBoxComponents.Padding = new Padding(3, 2, 3, 2);
groupBoxComponents.Size = new Size(679, 263);
groupBoxComponents.Size = new Size(776, 351);
groupBoxComponents.TabIndex = 4;
groupBoxComponents.TabStop = false;
groupBoxComponents.Text = "Компоненты";
//
// buttonUpd
//
buttonUpd.Location = new Point(544, 154);
buttonUpd.Margin = new Padding(3, 2, 3, 2);
buttonUpd.Location = new Point(622, 205);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(103, 27);
buttonUpd.Size = new Size(118, 36);
buttonUpd.TabIndex = 4;
buttonUpd.Text = "Обновить";
buttonUpd.UseVisualStyleBackColor = true;
@ -110,10 +105,9 @@
//
// buttonDel
//
buttonDel.Location = new Point(544, 113);
buttonDel.Margin = new Padding(3, 2, 3, 2);
buttonDel.Location = new Point(622, 151);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(103, 27);
buttonDel.Size = new Size(118, 36);
buttonDel.TabIndex = 3;
buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true;
@ -121,10 +115,9 @@
//
// buttonEdit
//
buttonEdit.Location = new Point(544, 74);
buttonEdit.Margin = new Padding(3, 2, 3, 2);
buttonEdit.Location = new Point(622, 99);
buttonEdit.Name = "buttonEdit";
buttonEdit.Size = new Size(103, 27);
buttonEdit.Size = new Size(118, 36);
buttonEdit.TabIndex = 2;
buttonEdit.Text = "Изменить";
buttonEdit.UseVisualStyleBackColor = true;
@ -132,10 +125,9 @@
//
// buttonAdd
//
buttonAdd.Location = new Point(544, 31);
buttonAdd.Margin = new Padding(3, 2, 3, 2);
buttonAdd.Location = new Point(622, 41);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(103, 27);
buttonAdd.Size = new Size(118, 36);
buttonAdd.TabIndex = 1;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
@ -148,13 +140,12 @@
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { Columnid, ColumnName, ColumnCount });
dataGridView.Location = new Point(5, 20);
dataGridView.Margin = new Padding(3, 2, 3, 2);
dataGridView.Location = new Point(6, 27);
dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true;
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(497, 239);
dataGridView.Size = new Size(568, 319);
dataGridView.TabIndex = 0;
//
// Columnid
@ -183,10 +174,9 @@
//
// buttonSave
//
buttonSave.Location = new Point(478, 332);
buttonSave.Margin = new Padding(3, 2, 3, 2);
buttonSave.Location = new Point(546, 443);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(103, 27);
buttonSave.Size = new Size(118, 36);
buttonSave.TabIndex = 5;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
@ -194,20 +184,19 @@
//
// buttonCancel
//
buttonCancel.Location = new Point(586, 332);
buttonCancel.Margin = new Padding(3, 2, 3, 2);
buttonCancel.Location = new Point(670, 443);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(103, 27);
buttonCancel.Size = new Size(118, 36);
buttonCancel.TabIndex = 6;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormSnack
// FormPrinted
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(700, 368);
ClientSize = new Size(800, 491);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(groupBoxComponents);
@ -215,10 +204,9 @@
Controls.Add(textBoxName);
Controls.Add(labelPrice);
Controls.Add(labelName);
Margin = new Padding(3, 2, 3, 2);
Name = "FormSnack";
Text = "Закуски";
Load += FormSnack_Load;
Name = "FormPrinted";
Text = "Изделия";
Load += FormPrinted_Load;
groupBoxComponents.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);

View File

@ -7,55 +7,55 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SnackBarContracts.BindingModels;
using SnackBarContracts.BusinessLogicsContracts;
using SnackBarContracts.SearchModels;
using SnackBarDataModels.Models;
using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using TypographyContracts.SearchModels;
using TypographyDataModels.Models;
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic.Logging;
using NLog.Extensions.Logging;
namespace SnackBarView
namespace TypographyView
{
public partial class FormSnack : Form
public partial class FormPrinted : Form
{
private readonly ILogger _logger;
private readonly ISnackLogic _logic;
private readonly IPrintedLogic _logic;
private int? _id;
private Dictionary<int, (IComponentModel, int)> _snackComponents;
private Dictionary<int, (IComponentModel, int)> _printedComponents;
public int Id { set { _id = value; } }
public FormSnack(ILogger<FormSnack> logger, ISnackLogic logic)
public FormPrinted(ILogger<FormPrinted> logger, IPrintedLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_snackComponents = new Dictionary<int, (IComponentModel, int)>();
_printedComponents = new Dictionary<int, (IComponentModel, int)>();
}
private void FormSnack_Load(object sender, EventArgs e)
private void FormPrinted_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Snack loading");
_logger.LogInformation("Printed loading");
try
{
var view = _logic.ReadElement(new SnackSearchModel { Id = _id.Value });
var view = _logic.ReadElement(new PrintedSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.SnackName;
textBoxName.Text = view.PrintedName;
textBoxPrice.Text = view.Price.ToString();
_snackComponents = view.SnackComponents ?? new Dictionary<int, (IComponentModel, int)>();
_printedComponents = view.PrintedComponents ?? new Dictionary<int, (IComponentModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Snack loading error");
_logger.LogError(ex, "Printed loading error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
@ -63,15 +63,15 @@ namespace SnackBarView
private void LoadData()
{
_logger.LogInformation("Snack components loading");
_logger.LogInformation("Printed components loading");
try
{
if (_snackComponents != null)
if (_printedComponents != null)
{
dataGridView.Rows.Clear();
foreach (var snackC in _snackComponents)
foreach (var printedC in _printedComponents)
{
dataGridView.Rows.Add(new object[] { snackC.Key, snackC.Value.Item1.ComponentName, snackC.Value.Item2 });
dataGridView.Rows.Add(new object[] { printedC.Key, printedC.Value.Item1.ComponentName, printedC.Value.Item2 });
}
textBoxPrice.Text = CalcPrice().ToString();
}
@ -85,8 +85,8 @@ namespace SnackBarView
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSnackComponent));
if (service is FormSnackComponent form)
var service = Program.ServiceProvider?.GetService(typeof(FormPrintedComponent));
if (service is FormPrintedComponent form)
{
if (form.ShowDialog() == DialogResult.OK)
{
@ -95,13 +95,13 @@ namespace SnackBarView
return;
}
_logger.LogInformation("Adding new component: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
if (_snackComponents.ContainsKey(form.Id))
if (_printedComponents.ContainsKey(form.Id))
{
_snackComponents[form.Id] = (form.ComponentModel, form.Count);
_printedComponents[form.Id] = (form.ComponentModel, form.Count);
}
else
{
_snackComponents.Add(form.Id, (form.ComponentModel, form.Count));
_printedComponents.Add(form.Id, (form.ComponentModel, form.Count));
}
LoadData();
}
@ -112,12 +112,12 @@ namespace SnackBarView
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSnackComponent));
if (service is FormSnackComponent form)
var service = Program.ServiceProvider?.GetService(typeof(FormPrintedComponent));
if (service is FormPrintedComponent form)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _snackComponents[id].Item2;
form.Count = _printedComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
@ -125,7 +125,7 @@ namespace SnackBarView
return;
}
_logger.LogInformation("Component editing: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
_snackComponents[form.Id] = (form.ComponentModel, form.Count);
_printedComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
}
}
@ -142,7 +142,7 @@ namespace SnackBarView
{
_logger.LogInformation("Deletion of component: {ComponentName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value,
dataGridView.SelectedRows[0].Cells[2].Value);
_snackComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
_printedComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
}
catch (Exception ex)
{
@ -170,20 +170,20 @@ namespace SnackBarView
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (_snackComponents == null || _snackComponents.Count == 0)
if (_printedComponents == null || _printedComponents.Count == 0)
{
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Snack saving");
_logger.LogInformation("Printed saving");
try
{
var model = new SnackBindingModel
var model = new PrintedBindingModel
{
Id = _id ?? 0,
SnackName = textBoxName.Text,
PrintedName = textBoxName.Text,
Price = Convert.ToDouble(textBoxPrice.Text),
SnackComponents = _snackComponents
PrintedComponents = _printedComponents
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
@ -196,7 +196,7 @@ namespace SnackBarView
}
catch (Exception ex)
{
_logger.LogError(ex, "Snack saving error");
_logger.LogError(ex, "Printed saving error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
@ -210,7 +210,7 @@ namespace SnackBarView
private double CalcPrice()
{
double price = 0;
foreach (var elem in _snackComponents)
foreach (var elem in _printedComponents)
{
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
}

View File

@ -1,6 +1,6 @@
namespace SnackBarView
namespace TypographyView
{
partial class FormSnackComponent
partial class FormPrintedComponent
{
/// <summary>
/// Required designer variable.
@ -89,7 +89,7 @@
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormSnackComponent
// FormPrintedComponent
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
@ -100,8 +100,8 @@
Controls.Add(comboBoxComponent);
Controls.Add(labelCount);
Controls.Add(labelComponent);
Name = "FormSnackComponent";
Text = "Компонент закуски";
Name = "FormPrintedComponent";
Text = "Компонент изделия";
ResumeLayout(false);
PerformLayout();
}

View File

@ -7,13 +7,13 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SnackBarContracts.BusinessLogicsContracts;
using SnackBarContracts.ViewModels;
using SnackBarDataModels.Models;
using TypographyContracts.BusinessLogicsContracts;
using TypographyContracts.ViewModels;
using TypographyDataModels.Models;
namespace SnackBarView
namespace TypographyView
{
public partial class FormSnackComponent : Form
public partial class FormPrintedComponent : Form
{
private readonly List<ComponentViewModel>? _list;
public int Id
@ -51,7 +51,7 @@ namespace SnackBarView
set { textBoxCount.Text = value.ToString(); }
}
public FormSnackComponent(IComponentLogic logic)
public FormPrintedComponent(IComponentLogic logic)
{
InitializeComponent();
_list = logic.ReadList(null);

View File

@ -1,6 +1,6 @@
namespace SnackBarView
namespace TypographyView
{
partial class FormSnacks
partial class FormPrinteds
{
/// <summary>
/// Required designer variable.
@ -87,7 +87,7 @@
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// FormSnacks
// FormPrinteds
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
@ -97,9 +97,9 @@
Controls.Add(buttonEdit);
Controls.Add(buttonAdd);
Controls.Add(dataGridView);
Name = "FormSnacks";
Text = "Закуски";
Load += FormSnacks_Load;
Name = "FormPrinteds";
Text = "Изделия";
Load += FormPrinteds_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}

View File

@ -7,26 +7,26 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SnackBarContracts.BindingModels;
using SnackBarContracts.BusinessLogicsContracts;
using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace SnackBarView
namespace TypographyView
{
public partial class FormSnacks : Form
public partial class FormPrinteds : Form
{
private readonly ILogger _logger;
private readonly ISnackLogic _logic;
private readonly IPrintedLogic _logic;
public FormSnacks(ILogger<FormSnacks> logger, ISnackLogic logic)
public FormPrinteds(ILogger<FormPrinteds> logger, IPrintedLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormSnacks_Load(object sender, EventArgs e)
private void FormPrinteds_Load(object sender, EventArgs e)
{
LoadData();
}
@ -40,8 +40,8 @@ namespace SnackBarView
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["SnackName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["SnackComponents"].Visible = false;
dataGridView.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["PrintedComponents"].Visible = false;
}
_logger.LogInformation("Ice creams loading");
}
@ -54,8 +54,8 @@ namespace SnackBarView
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSnack));
if (service is FormSnack form)
var service = Program.ServiceProvider?.GetService(typeof(FormPrinted));
if (service is FormPrinted form)
{
if (form.ShowDialog() == DialogResult.OK)
{
@ -68,8 +68,8 @@ namespace SnackBarView
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSnack));
if (service is FormSnack form)
var service = Program.ServiceProvider?.GetService(typeof(FormPrinted));
if (service is FormPrinted form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
@ -90,7 +90,7 @@ namespace SnackBarView
_logger.LogInformation("Deletion of ice cream");
try
{
if (!_logic.Delete(new SnackBindingModel { Id = id }))
if (!_logic.Delete(new PrintedBindingModel { Id = id }))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}

View File

@ -1,12 +1,12 @@
using SnackBarBusinessLogic.BusinessLogics;
using SnackBarContracts.BusinessLogicsContracts;
using SnackBarContracts.StoragesContracts;
using SnackBarListImplement.Implements;
using TypographyBusinessLogic.BusinessLogics;
using TypographyContracts.BusinessLogicsContracts;
using TypographyContracts.StoragesContracts;
using TypographyListImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
namespace SnackBarView
namespace TypographyView
{
internal static class Program
{
@ -35,19 +35,19 @@ namespace SnackBarView
});
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ISnackStorage, SnackStorage>();
services.AddTransient<IPrintedStorage, PrintedStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ISnackLogic, SnackLogic>();
services.AddTransient<IPrintedLogic, PrintedLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormSnack>();
services.AddTransient<FormSnackComponent>();
services.AddTransient<FormSnacks>();
services.AddTransient<FormPrinted>();
services.AddTransient<FormPrintedComponent>();
services.AddTransient<FormPrinteds>();
}
}
}

View File

@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace SnackBarView.Properties {
namespace TypographyView.Properties {
using System;
@ -39,7 +39,7 @@ namespace SnackBarView.Properties {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SnackBarView.Properties.Resources", typeof(Resources).Assembly);
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TypographyView.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;

View File

@ -9,17 +9,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
<PackageReference Include="NLog.Schema" Version="5.2.8" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SnackBarBusinessLogic\SnackBarBusinessLogic.csproj" />
<ProjectReference Include="..\SnackBarContracts\SnackBarContracts.csproj" />
<ProjectReference Include="..\SnackBarDataModels\SnackBarDataModels.csproj" />
<ProjectReference Include="..\SnackBarListImplement\SnackBarListImplement.csproj" />
<ProjectReference Include="..\TypographyBusinessLogic\TypographyBusinessLogic.csproj" />
<ProjectReference Include="..\TypographyContracts\TypographyContracts.csproj" />
<ProjectReference Include="..\TypographyDataModels\TypographyDataModels.csproj" />
<ProjectReference Include="..\TypographyListImplement\TypographyListImplement.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -3,15 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34525.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SnackBarView", "SnackBarView.csproj", "{F33DFCDC-9D11-44B7-9A5B-794E500A2B7B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyView", "TypographyView.csproj", "{F33DFCDC-9D11-44B7-9A5B-794E500A2B7B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnackBarListImplement", "..\SnackBarListImplement\SnackBarListImplement.csproj", "{9D223B95-71A3-4914-9532-A4D8B31288FD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyListImplement", "..\TypographyListImplement\TypographyListImplement.csproj", "{9D223B95-71A3-4914-9532-A4D8B31288FD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnackBarDataModels", "..\SnackBarDataModels\SnackBarDataModels.csproj", "{11F46ADA-6833-42AD-BF19-78A7826BC741}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyDataModels", "..\TypographyDataModels\TypographyDataModels.csproj", "{11F46ADA-6833-42AD-BF19-78A7826BC741}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnackBarContracts", "..\SnackBarContracts\SnackBarContracts.csproj", "{E8B5103A-3CAB-4C14-9DC8-6FFF40CA0D34}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyContracts", "..\TypographyContracts\TypographyContracts.csproj", "{E8B5103A-3CAB-4C14-9DC8-6FFF40CA0D34}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnackBarBusinessLogic", "..\SnackBarBusinessLogic\SnackBarBusinessLogic.csproj", "{1057A33D-538D-4E7F-862B-1FF8E9E021A0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyBusinessLogic", "..\TypographyBusinessLogic\TypographyBusinessLogic.csproj", "{1057A33D-538D-4E7F-862B-1FF8E9E021A0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution