diff --git a/Typography/.editorconfig b/Typography/.editorconfig new file mode 100644 index 0000000..c5033c9 --- /dev/null +++ b/Typography/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# IDE0058: Значение выражения никогда не используется +csharp_style_unused_value_expression_statement_preference = unused_local_variable diff --git a/Typography/Typography.sln b/Typography/Typography.sln index 57cefca..7d6ed57 100644 --- a/Typography/Typography.sln +++ b/Typography/Typography.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34322.80 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypographyView", "TypographyView\TypographyView.csproj", "{D3102193-D19D-44E5-B4AB-151568C7578C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyView", "TypographyView\TypographyView.csproj", "{D3102193-D19D-44E5-B4AB-151568C7578C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyContracts", "TypographyContracts\TypographyContracts.csproj", "{73F083E2-BA42-4976-BDC3-0B622832884F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyListImplement", "TypographyListImplement\TypographyListImplement.csproj", "{C7EEF3BD-859E-49F1-84C0-C8A9F2A2817A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyBusinessLogic", "TypographyBusinessLogic\TypographyBusinessLogic.csproj", "{095C3460-8DB2-4129-89B1-7B42A7D0440A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyDataModels", "TypographyDataModels\TypographyDataModels.csproj", "{75576C57-02E9-4D1D-9A02-D39C1EBE992D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {D3102193-D19D-44E5-B4AB-151568C7578C}.Debug|Any CPU.Build.0 = Debug|Any CPU {D3102193-D19D-44E5-B4AB-151568C7578C}.Release|Any CPU.ActiveCfg = Release|Any CPU {D3102193-D19D-44E5-B4AB-151568C7578C}.Release|Any CPU.Build.0 = Release|Any CPU + {73F083E2-BA42-4976-BDC3-0B622832884F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {73F083E2-BA42-4976-BDC3-0B622832884F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {73F083E2-BA42-4976-BDC3-0B622832884F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {73F083E2-BA42-4976-BDC3-0B622832884F}.Release|Any CPU.Build.0 = Release|Any CPU + {C7EEF3BD-859E-49F1-84C0-C8A9F2A2817A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C7EEF3BD-859E-49F1-84C0-C8A9F2A2817A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C7EEF3BD-859E-49F1-84C0-C8A9F2A2817A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C7EEF3BD-859E-49F1-84C0-C8A9F2A2817A}.Release|Any CPU.Build.0 = Release|Any CPU + {095C3460-8DB2-4129-89B1-7B42A7D0440A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {095C3460-8DB2-4129-89B1-7B42A7D0440A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {095C3460-8DB2-4129-89B1-7B42A7D0440A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {095C3460-8DB2-4129-89B1-7B42A7D0440A}.Release|Any CPU.Build.0 = Release|Any CPU + {75576C57-02E9-4D1D-9A02-D39C1EBE992D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {75576C57-02E9-4D1D-9A02-D39C1EBE992D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {75576C57-02E9-4D1D-9A02-D39C1EBE992D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {75576C57-02E9-4D1D-9A02-D39C1EBE992D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Typography/TypographyBusinessLogic/BusinessLogics/ComponentLogic.cs b/Typography/TypographyBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..619e238 --- /dev/null +++ b/Typography/TypographyBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,111 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace TypographyBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + + public List? 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("Компонент с таким названием уже есть"); + } + } + + } +} diff --git a/Typography/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs b/Typography/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..fca1b7a --- /dev/null +++ b/Typography/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,114 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using Microsoft.Extensions.Logging; +using TypographyDataModels.Enums; + +namespace TypographyBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Order status change failed"); + return false; + } + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Order creation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeOrderStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeOrderStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeOrderStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Кол-во печатных изделий в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. Count: {Count}. Sum: {Sum} Id: {Id}", model.Count, model.Sum, model.Id); + } + + private bool ChangeOrderStatus(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model, false); + var orderView = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + + if (orderView == null || newStatus - orderView.Status != 1) + { + _logger.LogWarning("Order status change failed"); + return false; + } + + model.Status = newStatus; + if (newStatus == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Order status change failed"); + return false; + } + return true; + } + } +} diff --git a/Typography/TypographyBusinessLogic/BusinessLogics/PrintedLogic.cs b/Typography/TypographyBusinessLogic/BusinessLogics/PrintedLogic.cs new file mode 100644 index 0000000..6d7744c --- /dev/null +++ b/Typography/TypographyBusinessLogic/BusinessLogics/PrintedLogic.cs @@ -0,0 +1,112 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace TypographyBusinessLogic.BusinessLogics +{ + public class PrintedLogic : IPrintedLogic + { + private readonly ILogger _logger; + private readonly IPrintedStorage _printedStorage; + + public PrintedLogic(ILogger logger, IPrintedStorage printedStorage) + { + _logger = logger; + _printedStorage = printedStorage; + } + + public List? ReadList(PrintedSearchModel? model) + { + _logger.LogInformation("ReadList. PrintedName: {PrintedName}. Id:{Id}", model?.PrintedName, model?.Id); + var list = model == null ? _printedStorage.GetFullList() : _printedStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public PrintedViewModel? ReadElement(PrintedSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. PrintedName: {PrintedName}. Id: {Id}", model.PrintedName, model.Id); + var element = _printedStorage.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(PrintedBindingModel model) + { + CheckModel(model); + if (_printedStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(PrintedBindingModel model) + { + CheckModel(model); + if (_printedStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(PrintedBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_printedStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(PrintedBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PrintedName)) + { + throw new ArgumentNullException("Нет названия печатного изделия", nameof(model.PrintedName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена печатного изделия должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Printed. PrintedName: {PrintedName}. Price: {Price}. Id: {Id}", + model.PrintedName, model.Price, model.Id); + var element = _printedStorage.GetElement(new PrintedSearchModel { PrintedName = model.PrintedName }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Печатное изделие с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/Typography/TypographyBusinessLogic/TypographyBusinessLogic.csproj b/Typography/TypographyBusinessLogic/TypographyBusinessLogic.csproj new file mode 100644 index 0000000..31772ec --- /dev/null +++ b/Typography/TypographyBusinessLogic/TypographyBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/Typography/TypographyContracts/BindingModels/ComponentBindingModel.cs b/Typography/TypographyContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..15f49db --- /dev/null +++ b/Typography/TypographyContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyDataModels.Models; + +namespace TypographyContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/Typography/TypographyContracts/BindingModels/OrderBindingModel.cs b/Typography/TypographyContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..edbcab6 --- /dev/null +++ b/Typography/TypographyContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using TypographyDataModels.Enums; +using TypographyDataModels.Models; + +namespace TypographyContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int PrintedId { 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; } + } +} diff --git a/Typography/TypographyContracts/BindingModels/PrintedBindingModel.cs b/Typography/TypographyContracts/BindingModels/PrintedBindingModel.cs new file mode 100644 index 0000000..faf5644 --- /dev/null +++ b/Typography/TypographyContracts/BindingModels/PrintedBindingModel.cs @@ -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 PrintedComponents { get; set; } = new(); + } +} diff --git a/Typography/TypographyContracts/BusinessLogicsContracts/IComponentLogic.cs b/Typography/TypographyContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..526f3ae --- /dev/null +++ b/Typography/TypographyContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -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 IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/Typography/TypographyContracts/BusinessLogicsContracts/IOrderLogic.cs b/Typography/TypographyContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..394bf91 --- /dev/null +++ b/Typography/TypographyContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -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 IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/Typography/TypographyContracts/BusinessLogicsContracts/IPrintedLogic.cs b/Typography/TypographyContracts/BusinessLogicsContracts/IPrintedLogic.cs new file mode 100644 index 0000000..d8519f8 --- /dev/null +++ b/Typography/TypographyContracts/BusinessLogicsContracts/IPrintedLogic.cs @@ -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? ReadList(PrintedSearchModel? model); + PrintedViewModel? ReadElement(PrintedSearchModel model); + bool Create(PrintedBindingModel model); + bool Update(PrintedBindingModel model); + bool Delete(PrintedBindingModel model); + } +} diff --git a/Typography/TypographyContracts/SearchModels/ComponentSearchModel.cs b/Typography/TypographyContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..23af955 --- /dev/null +++ b/Typography/TypographyContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/Typography/TypographyContracts/SearchModels/OrderSearchModel.cs b/Typography/TypographyContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..e321ecf --- /dev/null +++ b/Typography/TypographyContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/Typography/TypographyContracts/SearchModels/PrintedSearchModel.cs b/Typography/TypographyContracts/SearchModels/PrintedSearchModel.cs new file mode 100644 index 0000000..115aa32 --- /dev/null +++ b/Typography/TypographyContracts/SearchModels/PrintedSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyContracts.SearchModels +{ + public class PrintedSearchModel + { + public int? Id { get; set; } + public string? PrintedName { get; set; } + } +} diff --git a/Typography/TypographyContracts/StoragesContracts/IComponentStorage.cs b/Typography/TypographyContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..6f2daa0 --- /dev/null +++ b/Typography/TypographyContracts/StoragesContracts/IComponentStorage.cs @@ -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 IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/Typography/TypographyContracts/StoragesContracts/IOrderStorage.cs b/Typography/TypographyContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..f14d009 --- /dev/null +++ b/Typography/TypographyContracts/StoragesContracts/IOrderStorage.cs @@ -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 IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} diff --git a/Typography/TypographyContracts/StoragesContracts/IPrintedStorage.cs b/Typography/TypographyContracts/StoragesContracts/IPrintedStorage.cs new file mode 100644 index 0000000..794b240 --- /dev/null +++ b/Typography/TypographyContracts/StoragesContracts/IPrintedStorage.cs @@ -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 GetFullList(); + List GetFilteredList(PrintedSearchModel model); + PrintedViewModel? GetElement(PrintedSearchModel model); + PrintedViewModel? Insert(PrintedBindingModel model); + PrintedViewModel? Update(PrintedBindingModel model); + PrintedViewModel? Delete(PrintedBindingModel model); + } +} diff --git a/Typography/TypographyContracts/TypographyContracts.csproj b/Typography/TypographyContracts/TypographyContracts.csproj new file mode 100644 index 0000000..30c2576 --- /dev/null +++ b/Typography/TypographyContracts/TypographyContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs b/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..5e43a62 --- /dev/null +++ b/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyDataModels.Models; + +namespace TypographyContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/Typography/TypographyContracts/ViewModels/OrderViewModel.cs b/Typography/TypographyContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..2c284d1 --- /dev/null +++ b/Typography/TypographyContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyDataModels.Enums; +using TypographyDataModels.Models; + +namespace TypographyContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + + public int PrintedId { get; set; } + + [DisplayName("Изделие")] + public string PrintedName { get; set; } = string.Empty; + + [DisplayName("Количество")] + public int Count { get; set; } + + [DisplayName("Сумма")] + public double Sum { get; set; } + + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs b/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs new file mode 100644 index 0000000..d31efdc --- /dev/null +++ b/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyDataModels.Models; + +namespace TypographyContracts.ViewModels +{ + public class PrintedViewModel : IPrintedModel + { + public int Id { get; set; } + + [DisplayName("Название изделия")] + public string PrintedName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary PrintedComponents { get; set; } = new(); + } +} diff --git a/Typography/TypographyDataModels/Enums/OrderStatus.cs b/Typography/TypographyDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..03a4182 --- /dev/null +++ b/Typography/TypographyDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/Typography/TypographyDataModels/IId.cs b/Typography/TypographyDataModels/IId.cs new file mode 100644 index 0000000..fd121a2 --- /dev/null +++ b/Typography/TypographyDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/Typography/TypographyDataModels/Models/IComponentModel.cs b/Typography/TypographyDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..99d1c30 --- /dev/null +++ b/Typography/TypographyDataModels/Models/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/Typography/TypographyDataModels/Models/IOrderModel.cs b/Typography/TypographyDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..12e66c2 --- /dev/null +++ b/Typography/TypographyDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyDataModels.Enums; + +namespace TypographyDataModels.Models +{ + public interface IOrderModel : IId + { + int PrintedId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/Typography/TypographyDataModels/Models/IPrintedModel.cs b/Typography/TypographyDataModels/Models/IPrintedModel.cs new file mode 100644 index 0000000..b115996 --- /dev/null +++ b/Typography/TypographyDataModels/Models/IPrintedModel.cs @@ -0,0 +1,15 @@ +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 PrintedComponents { get; } + } +} diff --git a/Typography/TypographyDataModels/TypographyDataModels.csproj b/Typography/TypographyDataModels/TypographyDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/Typography/TypographyDataModels/TypographyDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Typography/TypographyListImplement/DataListSingleton.cs b/Typography/TypographyListImplement/DataListSingleton.cs new file mode 100644 index 0000000..5279bda --- /dev/null +++ b/Typography/TypographyListImplement/DataListSingleton.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyListImplement.Models; + +namespace TypographyListImplement +{ + internal class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Printeds { get; set; } + + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Printeds = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/Typography/TypographyListImplement/Implements/ComponentStorage.cs b/Typography/TypographyListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..dd946d3 --- /dev/null +++ b/Typography/TypographyListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +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 ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + 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; + } + } +} diff --git a/Typography/TypographyListImplement/Implements/OrderStorage.cs b/Typography/TypographyListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..b7a8e4c --- /dev/null +++ b/Typography/TypographyListImplement/Implements/OrderStorage.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using System.Linq; +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 OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(DefinePrintedName(order)); + } + return result; + } + private OrderViewModel DefinePrintedName(Order model) + { + OrderViewModel result = model.GetViewModel; + foreach (var order in _source.Printeds) + { + if (result.PrintedId == order.Id) + { + result.PrintedName = order.PrintedName; + break; + } + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model.Id == null) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(DefinePrintedName(order)); + } + } + 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 DefinePrintedName(order); + } + } + 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 DefinePrintedName(newOrder); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return DefinePrintedName(order); + } + } + 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 DefinePrintedName(element); + } + } + return null; + } + } +} diff --git a/Typography/TypographyListImplement/Implements/PrintedStorage.cs b/Typography/TypographyListImplement/Implements/PrintedStorage.cs new file mode 100644 index 0000000..04bef1c --- /dev/null +++ b/Typography/TypographyListImplement/Implements/PrintedStorage.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.Linq; +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 GetFullList() + { + var result = new List(); + foreach (var printed in _source.Printeds) + { + result.Add(printed.GetViewModel); + } + return result; + } + + public List GetFilteredList(PrintedSearchModel model) + { + var result = new List(); + 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; + } + } +} diff --git a/Typography/TypographyListImplement/Models/Component.cs b/Typography/TypographyListImplement/Models/Component.cs new file mode 100644 index 0000000..c260557 --- /dev/null +++ b/Typography/TypographyListImplement/Models/Component.cs @@ -0,0 +1,49 @@ +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 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 + }; + } +} diff --git a/Typography/TypographyListImplement/Models/Order.cs b/Typography/TypographyListImplement/Models/Order.cs new file mode 100644 index 0000000..24ec092 --- /dev/null +++ b/Typography/TypographyListImplement/Models/Order.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Enums; +using TypographyDataModels.Models; + +namespace TypographyListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int PrintedId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + PrintedId = model.PrintedId, + 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, + PrintedId = PrintedId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/Typography/TypographyListImplement/Models/Printed.cs b/Typography/TypographyListImplement/Models/Printed.cs new file mode 100644 index 0000000..e8707e8 --- /dev/null +++ b/Typography/TypographyListImplement/Models/Printed.cs @@ -0,0 +1,50 @@ +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 PrintedComponents { get; private set; } = new(); + 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 + }; + } +} diff --git a/Typography/TypographyListImplement/TypographyListImplement.csproj b/Typography/TypographyListImplement/TypographyListImplement.csproj new file mode 100644 index 0000000..db73c6b --- /dev/null +++ b/Typography/TypographyListImplement/TypographyListImplement.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Typography/TypographyView/Form1.Designer.cs b/Typography/TypographyView/Form1.Designer.cs deleted file mode 100644 index 33a07e2..0000000 --- a/Typography/TypographyView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace TypographyView -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/Typography/TypographyView/Form1.cs b/Typography/TypographyView/Form1.cs deleted file mode 100644 index 4e03c29..0000000 --- a/Typography/TypographyView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace TypographyView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/Typography/TypographyView/FormComponent.Designer.cs b/Typography/TypographyView/FormComponent.Designer.cs new file mode 100644 index 0000000..69d97e8 --- /dev/null +++ b/Typography/TypographyView/FormComponent.Designer.cs @@ -0,0 +1,120 @@ +namespace TypographyView +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 15); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(77, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(12, 47); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(45, 20); + this.labelCost.TabIndex = 1; + this.labelCost.Text = "Цена"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(95, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(241, 27); + this.textBoxName.TabIndex = 2; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(95, 44); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(134, 27); + this.textBoxCost.TabIndex = 3; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(234, 77); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(102, 29); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(127, 77); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(102, 29); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(347, 118); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Name = "FormComponent"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormComponent.cs b/Typography/TypographyView/FormComponent.cs new file mode 100644 index 0000000..b6586aa --- /dev/null +++ b/Typography/TypographyView/FormComponent.cs @@ -0,0 +1,83 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace TypographyView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + + public int Id { set { _id = value; } } + + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation(" "); + var view = _logic.ReadElement(new ComponentSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation(" "); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) :_logic.Create(model); + if (!operationResult) + { + throw new Exception(" . ."); + } + MessageBox.Show(" ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, " "); + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormComponent.resx b/Typography/TypographyView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Typography/TypographyView/FormComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Typography/TypographyView/FormComponents.Designer.cs b/Typography/TypographyView/FormComponents.Designer.cs new file mode 100644 index 0000000..c75b6b7 --- /dev/null +++ b/Typography/TypographyView/FormComponents.Designer.cs @@ -0,0 +1,119 @@ +namespace TypographyView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridViewComponents = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewComponents)).BeginInit(); + this.SuspendLayout(); + // + // dataGridViewComponents + // + this.dataGridViewComponents.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridViewComponents.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridViewComponents.Location = new System.Drawing.Point(1, 1); + this.dataGridViewComponents.Name = "dataGridViewComponents"; + this.dataGridViewComponents.RowHeadersVisible = false; + this.dataGridViewComponents.RowHeadersWidth = 51; + this.dataGridViewComponents.RowTemplate.Height = 29; + this.dataGridViewComponents.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridViewComponents.Size = new System.Drawing.Size(650, 402); + this.dataGridViewComponents.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(668, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(102, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(668, 47); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(102, 29); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(668, 82); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(102, 29); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(668, 117); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(102, 29); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(782, 403); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridViewComponents); + this.Name = "FormComponents"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewComponents)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridViewComponents; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormComponents.cs b/Typography/TypographyView/FormComponents.cs new file mode 100644 index 0000000..85d0784 --- /dev/null +++ b/Typography/TypographyView/FormComponents.cs @@ -0,0 +1,103 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace TypographyView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridViewComponents.DataSource = list; + dataGridViewComponents.Columns["Id"].Visible = false; + dataGridViewComponents.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == + DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormComponents.resx b/Typography/TypographyView/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Typography/TypographyView/FormComponents.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Typography/TypographyView/FormCreateOrder.Designer.cs b/Typography/TypographyView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..7bca9c4 --- /dev/null +++ b/Typography/TypographyView/FormCreateOrder.Designer.cs @@ -0,0 +1,146 @@ +namespace TypographyView +{ + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelPrinted = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.comboBoxPrinted = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelPrinted + // + this.labelPrinted.AutoSize = true; + this.labelPrinted.Location = new System.Drawing.Point(12, 15); + this.labelPrinted.Name = "labelPrinted"; + this.labelPrinted.Size = new System.Drawing.Size(154, 20); + this.labelPrinted.TabIndex = 0; + this.labelPrinted.Text = "Печатная продукция"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 49); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(90, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(12, 82); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(55, 20); + this.labelSum.TabIndex = 2; + this.labelSum.Text = "Сумма"; + // + // comboBoxPrinted + // + this.comboBoxPrinted.FormattingEnabled = true; + this.comboBoxPrinted.Location = new System.Drawing.Point(172, 12); + this.comboBoxPrinted.Name = "comboBoxPrinted"; + this.comboBoxPrinted.Size = new System.Drawing.Size(240, 28); + this.comboBoxPrinted.TabIndex = 3; + this.comboBoxPrinted.SelectedIndexChanged += new System.EventHandler(this.ComboBoxPrinted_SelectedIndexChanged); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(172, 46); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(240, 27); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(172, 79); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(240, 27); + this.textBoxSum.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(202, 112); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(102, 29); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(310, 112); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(102, 29); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(427, 153); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxPrinted); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelPrinted); + this.Name = "FormCreateOrder"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelPrinted; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxPrinted; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormCreateOrder.cs b/Typography/TypographyView/FormCreateOrder.cs new file mode 100644 index 0000000..7a34f43 --- /dev/null +++ b/Typography/TypographyView/FormCreateOrder.cs @@ -0,0 +1,110 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace TypographyView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IPrintedLogic _logicP; + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, IPrintedLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + var _list = _logicP.ReadList(null); + if (_list != null) + { + comboBoxPrinted.DisplayMember = "PrintedName"; + comboBoxPrinted.ValueMember = "Id"; + comboBoxPrinted.DataSource = _list; + comboBoxPrinted.SelectedItem = null; + } + } + + private void CalcSum() + { + if (comboBoxPrinted.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxPrinted.SelectedValue); + var product = _logicP.ReadElement(new PrintedSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ComboBoxPrinted_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPrinted.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + PrintedId = Convert.ToInt32(comboBoxPrinted.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormCreateOrder.resx b/Typography/TypographyView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Typography/TypographyView/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Typography/TypographyView/FormMain.Designer.cs b/Typography/TypographyView/FormMain.Designer.cs new file mode 100644 index 0000000..696e4d3 --- /dev/null +++ b/Typography/TypographyView/FormMain.Designer.cs @@ -0,0 +1,180 @@ +namespace TypographyView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.dataGridViewOrders = new System.Windows.Forms.DataGridView(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonOrderReady = new System.Windows.Forms.Button(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.directoriesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.printedsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewOrders)).BeginInit(); + this.menuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(1100, 31); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(203, 29); + this.buttonCreateOrder.TabIndex = 0; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1100, 66); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(203, 29); + this.buttonTakeOrderInWork.TabIndex = 1; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Location = new System.Drawing.Point(1100, 136); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(203, 29); + this.buttonIssuedOrder.TabIndex = 2; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // dataGridViewOrders + // + this.dataGridViewOrders.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridViewOrders.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridViewOrders.Location = new System.Drawing.Point(0, 31); + this.dataGridViewOrders.Name = "dataGridViewOrders"; + this.dataGridViewOrders.RowHeadersVisible = false; + this.dataGridViewOrders.RowHeadersWidth = 51; + this.dataGridViewOrders.RowTemplate.Height = 29; + this.dataGridViewOrders.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridViewOrders.Size = new System.Drawing.Size(1078, 402); + this.dataGridViewOrders.TabIndex = 3; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(1100, 171); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(203, 29); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Location = new System.Drawing.Point(1100, 101); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(203, 29); + this.buttonOrderReady.TabIndex = 5; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.directoriesToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(1315, 28); + this.menuStrip.TabIndex = 6; + this.menuStrip.Text = "menuStrip1"; + // + // directoriesToolStripMenuItem + // + this.directoriesToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.componentsToolStripMenuItem, + this.printedsToolStripMenuItem}); + this.directoriesToolStripMenuItem.Name = "directoriesToolStripMenuItem"; + this.directoriesToolStripMenuItem.Size = new System.Drawing.Size(117, 24); + this.directoriesToolStripMenuItem.Text = "Справочники"; + // + // componentsToolStripMenuItem + // + this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + this.componentsToolStripMenuItem.Size = new System.Drawing.Size(237, 26); + this.componentsToolStripMenuItem.Text = "Компоненты"; + this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); + // + // printedsToolStripMenuItem + // + this.printedsToolStripMenuItem.Name = "printedsToolStripMenuItem"; + this.printedsToolStripMenuItem.Size = new System.Drawing.Size(237, 26); + this.printedsToolStripMenuItem.Text = "Печатная продукция"; + this.printedsToolStripMenuItem.Click += new System.EventHandler(this.PrintedsToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1315, 433); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.dataGridViewOrders); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.Name = "FormMain"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Типография"; + this.Load += new System.EventHandler(this.FormMain_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewOrders)).EndInit(); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonIssuedOrder; + private DataGridView dataGridViewOrders; + private Button buttonRef; + private Button buttonOrderReady; + private MenuStrip menuStrip; + private ToolStripMenuItem directoriesToolStripMenuItem; + private ToolStripMenuItem componentsToolStripMenuItem; + private ToolStripMenuItem printedsToolStripMenuItem; + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormMain.cs b/Typography/TypographyView/FormMain.cs new file mode 100644 index 0000000..67b11cd --- /dev/null +++ b/Typography/TypographyView/FormMain.cs @@ -0,0 +1,148 @@ +using TypographyDataModels.Enums; +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace TypographyView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridViewOrders.DataSource = list; + dataGridViewOrders.Columns["PrintedId"].Visible = false; + dataGridViewOrders.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void PrintedsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPrinteds)); + if (service is FormPrinteds form) + { + form.ShowDialog(); + } + } + + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridViewOrders.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridViewOrders.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridViewOrders.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridViewOrders.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridViewOrders.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridViewOrders.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormMain.resx b/Typography/TypographyView/FormMain.resx new file mode 100644 index 0000000..81a9e3d --- /dev/null +++ b/Typography/TypographyView/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Typography/TypographyView/FormPrinted.Designer.cs b/Typography/TypographyView/FormPrinted.Designer.cs new file mode 100644 index 0000000..b170696 --- /dev/null +++ b/Typography/TypographyView/FormPrinted.Designer.cs @@ -0,0 +1,238 @@ +namespace TypographyView +{ + partial class FormPrinted + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.labelPrice = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBoxComponents = new System.Windows.Forms.GroupBox(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridViewComponents = new System.Windows.Forms.DataGridView(); + this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnComponentName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewComponents)).BeginInit(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(560, 520); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(102, 29); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(668, 520); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(102, 29); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 15); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(77, 20); + this.labelName.TabIndex = 2; + this.labelName.Text = "Название"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(12, 48); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(83, 20); + this.labelPrice.TabIndex = 3; + this.labelPrice.Text = "Стоимость"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(101, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(208, 27); + this.textBoxName.TabIndex = 4; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(101, 45); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.ReadOnly = true; + this.textBoxPrice.Size = new System.Drawing.Size(208, 27); + this.textBoxPrice.TabIndex = 5; + // + // groupBoxComponents + // + this.groupBoxComponents.Controls.Add(this.buttonDel); + this.groupBoxComponents.Controls.Add(this.buttonRef); + this.groupBoxComponents.Controls.Add(this.buttonUpd); + this.groupBoxComponents.Controls.Add(this.buttonAdd); + this.groupBoxComponents.Controls.Add(this.dataGridViewComponents); + this.groupBoxComponents.Location = new System.Drawing.Point(12, 78); + this.groupBoxComponents.Name = "groupBoxComponents"; + this.groupBoxComponents.Size = new System.Drawing.Size(758, 436); + this.groupBoxComponents.TabIndex = 6; + this.groupBoxComponents.TabStop = false; + this.groupBoxComponents.Text = "Компоненты"; + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(650, 96); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(102, 29); + this.buttonDel.TabIndex = 4; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(650, 131); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(102, 29); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(650, 61); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(102, 29); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(650, 26); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(102, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridViewComponents + // + this.dataGridViewComponents.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridViewComponents.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridViewComponents.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnId, + this.ColumnComponentName, + this.ColumnCount}); + this.dataGridViewComponents.GridColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridViewComponents.Location = new System.Drawing.Point(6, 26); + this.dataGridViewComponents.Name = "dataGridViewComponents"; + this.dataGridViewComponents.RowHeadersVisible = false; + this.dataGridViewComponents.RowHeadersWidth = 51; + this.dataGridViewComponents.RowTemplate.Height = 29; + this.dataGridViewComponents.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridViewComponents.Size = new System.Drawing.Size(638, 400); + this.dataGridViewComponents.TabIndex = 0; + // + // ColumnId + // + this.ColumnId.HeaderText = "Id"; + this.ColumnId.MinimumWidth = 6; + this.ColumnId.Name = "ColumnId"; + this.ColumnId.Visible = false; + this.ColumnId.Width = 125; + // + // ColumnComponentName + // + this.ColumnComponentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnComponentName.HeaderText = "Компонент"; + this.ColumnComponentName.MinimumWidth = 6; + this.ColumnComponentName.Name = "ColumnComponentName"; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.MinimumWidth = 6; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.Width = 125; + // + // FormPrinted + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(782, 563); + this.Controls.Add(this.groupBoxComponents); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormPrinted"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Печатная продукция"; + this.Load += new System.EventHandler(this.FormPrinted_Load); + this.groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewComponents)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxComponents; + private Button buttonDel; + private Button buttonRef; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridViewComponents; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnComponentName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormPrinted.cs b/Typography/TypographyView/FormPrinted.cs new file mode 100644 index 0000000..ddb1c5d --- /dev/null +++ b/Typography/TypographyView/FormPrinted.cs @@ -0,0 +1,210 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using TypographyDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace TypographyView +{ + public partial class FormPrinted : Form + { + private readonly ILogger _logger; + private readonly IPrintedLogic _logic; + private int? _id; + private Dictionary _printedComponents; + + public int Id { set { _id = value; } } + public FormPrinted(ILogger logger, IPrintedLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _printedComponents = new Dictionary(); + } + + private void FormPrinted_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new PrintedSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.PrintedName; + textBoxPrice.Text = view.Price.ToString(); + _printedComponents = view.PrintedComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_printedComponents != null) + { + dataGridViewComponents.Rows.Clear(); + foreach (var pc in _printedComponents) + { + dataGridViewComponents.Rows.Add(new object[] { pc.Key, + pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private double CalcPrice() + { + double price = 0; + foreach (var elem in _printedComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPrintedComponent)); + if (service is FormPrintedComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", + form.ComponentModel.ComponentName, form.Count); + if (_printedComponents.ContainsKey(form.Id)) + { + _printedComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _printedComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPrintedComponent)); + if (service is FormPrintedComponent form) + { + int id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _printedComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", + form.ComponentModel.ComponentName, form.Count); + _printedComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == + DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", + dataGridViewComponents.SelectedRows[0].Cells[1].Value); + _printedComponents?.Remove(Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_printedComponents == null || _printedComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new PrintedBindingModel + { + Id = _id ?? 0, + PrintedName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + PrintedComponents = _printedComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) :_logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormPrinted.resx b/Typography/TypographyView/FormPrinted.resx new file mode 100644 index 0000000..f82c6b6 --- /dev/null +++ b/Typography/TypographyView/FormPrinted.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/Typography/TypographyView/FormPrintedComponent.Designer.cs b/Typography/TypographyView/FormPrintedComponent.Designer.cs new file mode 100644 index 0000000..5858793 --- /dev/null +++ b/Typography/TypographyView/FormPrintedComponent.Designer.cs @@ -0,0 +1,126 @@ +namespace TypographyView +{ + partial class FormPrintedComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelComponent = new Label(); + labelCount = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + textBoxCount = new TextBox(); + comboBoxComponent = new ComboBox(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(20, 24); + labelComponent.Margin = new Padding(5, 0, 5, 0); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(138, 32); + labelComponent.TabIndex = 0; + labelComponent.Text = "Компонент"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(16, 78); + labelCount.Margin = new Padding(5, 0, 5, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(144, 32); + labelCount.TabIndex = 1; + labelCount.Text = "Количество"; + // + // buttonSave + // + buttonSave.Location = new Point(365, 129); + buttonSave.Margin = new Padding(5, 5, 5, 5); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(166, 46); + buttonSave.TabIndex = 2; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(541, 126); + buttonCancel.Margin = new Padding(5, 5, 5, 5); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(166, 46); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // textBoxCount + // + textBoxCount.Location = new Point(172, 74); + textBoxCount.Margin = new Padding(5, 5, 5, 5); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(355, 39); + textBoxCount.TabIndex = 4; + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(172, 19); + comboBoxComponent.Margin = new Padding(5, 5, 5, 5); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(355, 40); + comboBoxComponent.TabIndex = 5; + // + // FormPrintedComponent + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(726, 189); + Controls.Add(comboBoxComponent); + Controls.Add(textBoxCount); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Margin = new Padding(5, 5, 5, 5); + Name = "FormPrintedComponent"; + StartPosition = FormStartPosition.CenterParent; + Text = "Компонент печатной продукции"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponent; + private Label labelCount; + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxCount; + private ComboBox comboBoxComponent; + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormPrintedComponent.cs b/Typography/TypographyView/FormPrintedComponent.cs new file mode 100644 index 0000000..ffa3628 --- /dev/null +++ b/Typography/TypographyView/FormPrintedComponent.cs @@ -0,0 +1,75 @@ +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; + +namespace TypographyView +{ + public partial class FormPrintedComponent : Form + { + private readonly List? _list; + + public int Id + { + get { return Convert.ToInt32(comboBoxComponent.SelectedValue); } + set { comboBoxComponent.SelectedValue = value; } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + + public FormPrintedComponent(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(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyView/Form1.resx b/Typography/TypographyView/FormPrintedComponent.resx similarity index 93% rename from Typography/TypographyView/Form1.resx rename to Typography/TypographyView/FormPrintedComponent.resx index 1af7de1..af32865 100644 --- a/Typography/TypographyView/Form1.resx +++ b/Typography/TypographyView/FormPrintedComponent.resx @@ -1,17 +1,17 @@  - diff --git a/Typography/TypographyView/FormPrinteds.Designer.cs b/Typography/TypographyView/FormPrinteds.Designer.cs new file mode 100644 index 0000000..374bfb9 --- /dev/null +++ b/Typography/TypographyView/FormPrinteds.Designer.cs @@ -0,0 +1,121 @@ +using TypographyListImplement.Models; + +namespace TypographyView +{ + partial class FormPrinteds + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridViewPrinteds = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewPrinteds)).BeginInit(); + this.SuspendLayout(); + // + // dataGridViewPrinteds + // + this.dataGridViewPrinteds.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridViewPrinteds.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridViewPrinteds.Location = new System.Drawing.Point(1, 1); + this.dataGridViewPrinteds.Name = "dataGridViewPrinteds"; + this.dataGridViewPrinteds.RowHeadersVisible = false; + this.dataGridViewPrinteds.RowHeadersWidth = 51; + this.dataGridViewPrinteds.RowTemplate.Height = 29; + this.dataGridViewPrinteds.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridViewPrinteds.Size = new System.Drawing.Size(650, 402); + this.dataGridViewPrinteds.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(668, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(102, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(668, 47); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(102, 29); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(668, 82); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(102, 29); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(668, 117); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(102, 29); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormPrinteds + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(782, 403); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridViewPrinteds); + this.Name = "FormPrinteds"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Печатная продукция"; + this.Load += new System.EventHandler(this.FormPrinteds_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewPrinteds)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridViewPrinteds; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormPrinteds.cs b/Typography/TypographyView/FormPrinteds.cs new file mode 100644 index 0000000..50fead6 --- /dev/null +++ b/Typography/TypographyView/FormPrinteds.cs @@ -0,0 +1,104 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace TypographyView +{ + public partial class FormPrinteds : Form + { + private readonly ILogger _logger; + private readonly IPrintedLogic _logic; + + public FormPrinteds(ILogger logger, IPrintedLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormPrinteds_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridViewPrinteds.DataSource = list; + dataGridViewPrinteds.Columns["Id"].Visible = false; + dataGridViewPrinteds.Columns["PrintedComponents"].Visible = false; + dataGridViewPrinteds.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка печатной продукции"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки печатной продукции"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPrinted)); + if (service is FormPrinted form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridViewPrinteds.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPrinted)); + if (service is FormPrinted form) + { + form.Id = Convert.ToInt32(dataGridViewPrinteds.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridViewPrinteds.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == + DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridViewPrinteds.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new PrintedBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления печатной продукции"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormPrinteds.resx b/Typography/TypographyView/FormPrinteds.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Typography/TypographyView/FormPrinteds.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Typography/TypographyView/Program.cs b/Typography/TypographyView/Program.cs index 4191d21..20a1e90 100644 --- a/Typography/TypographyView/Program.cs +++ b/Typography/TypographyView/Program.cs @@ -1,7 +1,19 @@ +using TypographyBusinessLogic.BusinessLogics; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.StoragesContracts; +using TypographyListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System; + namespace TypographyView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -11,7 +23,32 @@ namespace TypographyView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/Typography/TypographyView/TypographyView.csproj b/Typography/TypographyView/TypographyView.csproj index b57c89e..d5e8cf5 100644 --- a/Typography/TypographyView/TypographyView.csproj +++ b/Typography/TypographyView/TypographyView.csproj @@ -8,4 +8,26 @@ enable + + + + + + + Always + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Typography/TypographyView/nlog.config b/Typography/TypographyView/nlog.config new file mode 100644 index 0000000..6b2ff40 --- /dev/null +++ b/Typography/TypographyView/nlog.config @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file