diff --git a/BlacksmithWorkshop/AbstractShopContracts/BindingModels/ComponentBindingModel.cs b/BlacksmithWorkshop/AbstractShopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..f04f448 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/AbstractShopContracts/BindingModels/ManufactureBindingModel.cs b/BlacksmithWorkshop/AbstractShopContracts/BindingModels/ManufactureBindingModel.cs new file mode 100644 index 0000000..11f2d05 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/BindingModels/ManufactureBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + public class ManufactureBindingModel : IManufactureModel + { + public int Id { get; set; } + public string ManufactureName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary ManufactureComponents + { + get; + set; + } = new(); + } +} diff --git a/BlacksmithWorkshop/AbstractShopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/AbstractShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..afe345e --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int ManufactureId { 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/BlacksmithWorkshop/AbstractShopContracts/BlacksmithWorkshopContracts.csproj b/BlacksmithWorkshop/AbstractShopContracts/BlacksmithWorkshopContracts.csproj new file mode 100644 index 0000000..6b2e826 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/BlacksmithWorkshopContracts.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/BlacksmithWorkshop/AbstractShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/BlacksmithWorkshop/AbstractShopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..ca41e36 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/AbstractShopContracts/BusinessLogicsContracts/IManufactureLogic.cs b/BlacksmithWorkshop/AbstractShopContracts/BusinessLogicsContracts/IManufactureLogic.cs new file mode 100644 index 0000000..a7754e1 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/BusinessLogicsContracts/IManufactureLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +namespace BlacksmithWorkshopContracts.BusinessLogicsContracts +{ + public interface IManufactureLogic + { + List? ReadList(ManufactureSearchModel? model); + ManufactureViewModel? ReadElement(ManufactureSearchModel model); + bool Create(ManufactureBindingModel model); + bool Update(ManufactureBindingModel model); + bool Delete(ManufactureBindingModel model); + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/AbstractShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/BlacksmithWorkshop/AbstractShopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..823570d --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/AbstractShopContracts/SearchModels/ComponentSearchModel.cs b/BlacksmithWorkshop/AbstractShopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..97a2377 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/AbstractShopContracts/SearchModels/ManufactureSearchModel.cs b/BlacksmithWorkshop/AbstractShopContracts/SearchModels/ManufactureSearchModel.cs new file mode 100644 index 0000000..5048a87 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/SearchModels/ManufactureSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.SearchModels +{ + public class ManufactureSearchModel + { + public int? Id { get; set; } + public string? ManufactureName { get; set; } + } +} diff --git a/BlacksmithWorkshop/AbstractShopContracts/SearchModels/OrderSearchModel.cs b/BlacksmithWorkshop/AbstractShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..e68f27f --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/AbstractShopContracts/StorageContracts/IComponentStorage.cs b/BlacksmithWorkshop/AbstractShopContracts/StorageContracts/IComponentStorage.cs new file mode 100644 index 0000000..9d28954 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/StorageContracts/IComponentStorage.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopContracts.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); + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/AbstractShopContracts/StorageContracts/IManufactureStorage.cs b/BlacksmithWorkshop/AbstractShopContracts/StorageContracts/IManufactureStorage.cs new file mode 100644 index 0000000..3b65ed6 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/StorageContracts/IManufactureStorage.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopContracts.StoragesContracts +{ + public interface IManufactureStorage + { + List GetFullList(); + List GetFilteredList(ManufactureSearchModel model); + ManufactureViewModel? GetElement(ManufactureSearchModel model); + ManufactureViewModel? Insert(ManufactureBindingModel model); + ManufactureViewModel? Update(ManufactureBindingModel model); + ManufactureViewModel? Delete(ManufactureBindingModel model); + } +} diff --git a/BlacksmithWorkshop/AbstractShopContracts/StorageContracts/IOrderStorage.cs b/BlacksmithWorkshop/AbstractShopContracts/StorageContracts/IOrderStorage.cs new file mode 100644 index 0000000..2705bab --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/StorageContracts/IOrderStorage.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/AbstractShopContracts/ViewModels/ComponentViewModel.cs b/BlacksmithWorkshop/AbstractShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..e9bacd4 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/AbstractShopContracts/ViewModels/ManufactureViewModel.cs b/BlacksmithWorkshop/AbstractShopContracts/ViewModels/ManufactureViewModel.cs new file mode 100644 index 0000000..742f441 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/ViewModels/ManufactureViewModel.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class ManufactureViewModel : IManufactureModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string ManufactureName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary ManufactureComponents + { + get; + set; + } = new(); + } +} diff --git a/BlacksmithWorkshop/AbstractShopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/AbstractShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..6b92c5f --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopDataModels.Enums; +using System.ComponentModel; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int ManufactureId { get; set; } + [DisplayName("Изделие")] + public string ManufactureName { 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/BlacksmithWorkshop/AbstractShopDataModels/BlacksmithWorkshopDataModels.csproj b/BlacksmithWorkshop/AbstractShopDataModels/BlacksmithWorkshopDataModels.csproj new file mode 100644 index 0000000..17fe669 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopDataModels/BlacksmithWorkshopDataModels.csproj @@ -0,0 +1,15 @@ + + + + net6.0 + enable + enable + + + + + + + + + diff --git a/BlacksmithWorkshop/AbstractShopDataModels/Enums/OrderStatus.cs b/BlacksmithWorkshop/AbstractShopDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..d287cf4 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/BlacksmithWorkshop/AbstractShopDataModels/IId.cs b/BlacksmithWorkshop/AbstractShopDataModels/IId.cs new file mode 100644 index 0000000..e0a71f4 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/BlacksmithWorkshop/AbstractShopDataModels/Models/IComponentModel.cs b/BlacksmithWorkshop/AbstractShopDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..619acd4 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopDataModels/Models/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/AbstractShopDataModels/Models/IManufactureModel.cs b/BlacksmithWorkshop/AbstractShopDataModels/Models/IManufactureModel.cs new file mode 100644 index 0000000..ef6b875 --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopDataModels/Models/IManufactureModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDataModels.Models +{ + public interface IManufactureModel : IId + { + string ManufactureName { get; } + double Price { get; } + Dictionary ManufactureComponents { get; } + } +} + diff --git a/BlacksmithWorkshop/AbstractShopDataModels/Models/IOrderModel.cs b/BlacksmithWorkshop/AbstractShopDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..0a69e6c --- /dev/null +++ b/BlacksmithWorkshop/AbstractShopDataModels/Models/IOrderModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopDataModels.Enums; + +namespace BlacksmithWorkshopDataModels.Models +{ + public interface IOrderModel : IId + { + int ManufactureId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithListImplement/BlacksmithWorkshopListImplement.csproj b/BlacksmithWorkshop/BlacksmithListImplement/BlacksmithWorkshopListImplement.csproj new file mode 100644 index 0000000..d4e61ae --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithListImplement/BlacksmithWorkshopListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/BlacksmithWorkshop/BlacksmithListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithListImplement/DataListSingleton.cs new file mode 100644 index 0000000..f8d1227 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithListImplement/DataListSingleton.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopListImplement.Models; + +namespace BlacksmithWorkshopListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Manufactures { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Manufactures = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithListImplement/Implements/ComponentStorage.cs b/BlacksmithWorkshop/BlacksmithListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..07b6c5c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; + +namespace BlacksmithWorkshopListImplement.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; + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithListImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithListImplement/Implements/ManufactureStorage.cs new file mode 100644 index 0000000..72471da --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithListImplement/Implements/ManufactureStorage.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; + +namespace BlacksmithWorkshopListImplement.Implements +{ + public class ManufactureStorage : IManufactureStorage + { + private readonly DataListSingleton _source; + public ManufactureStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var Manufacture in _source.Manufactures) + { + result.Add(Manufacture.GetViewModel); + } + return result; + } + public List GetFilteredList(ManufactureSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ManufactureName)) + { + return result; + } + foreach (var Manufacture in _source.Manufactures) + { + if (Manufacture.ManufactureName.Contains(model.ManufactureName)) + { + result.Add(Manufacture.GetViewModel); + } + } + return result; + } + public ManufactureViewModel? GetElement(ManufactureSearchModel model) + { + if (string.IsNullOrEmpty(model.ManufactureName) && !model.Id.HasValue) + { + return null; + } + foreach (var Manufacture in _source.Manufactures) + { + if ((!string.IsNullOrEmpty(model.ManufactureName) && Manufacture.ManufactureName == model.ManufactureName) || + (model.Id.HasValue && Manufacture.Id == model.Id)) + { + return Manufacture.GetViewModel; + } + } + return null; + } + public ManufactureViewModel? Insert(ManufactureBindingModel model) + { + model.Id = 1; + foreach (var Manufacture in _source.Manufactures) + { + if (model.Id <= Manufacture.Id) + { + model.Id = Manufacture.Id + 1; + } + } + var newManufacture = Manufacture.Create(model); + if (newManufacture == null) + { + return null; + } + _source.Manufactures.Add(newManufacture); + return newManufacture.GetViewModel; + } + public ManufactureViewModel? Update(ManufactureBindingModel model) + { + foreach (var Manufacture in _source.Manufactures) + { + if (Manufacture.Id == model.Id) + { + Manufacture.Update(model); + return Manufacture.GetViewModel; + } + } + return null; + } + public ManufactureViewModel? Delete(ManufactureBindingModel model) + { + for (int i = 0; i < _source.Manufactures.Count; ++i) + { + if (_source.Manufactures[i].Id == model.Id) + { + var element = _source.Manufactures[i]; + _source.Manufactures.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..a734c01 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithListImplement/Implements/OrderStorage.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement; +using BlacksmithWorkshopListImplement.Models; + +namespace OrdersShopListImplement.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(AttachManufactureName(Order.GetViewModel)); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model == null) + { + return result; + } + foreach (var Order in _source.Orders) + { + if (Order.Id == model.Id) + { + result.Add(AttachManufactureName(Order.GetViewModel)); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var Order in _source.Orders) + { + if (model.Id.HasValue && Order.Id == model.Id) + { + return AttachManufactureName(Order.GetViewModel); + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var Order in _source.Orders) + { + if (model.Id <= Order.Id) + { + model.Id = Order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return AttachManufactureName(newOrder.GetViewModel); + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var Order in _source.Orders) + { + if (Order.Id == model.Id) + { + Order.Update(model); + return AttachManufactureName(Order.GetViewModel); + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return AttachManufactureName(element.GetViewModel); + } + } + return null; + } + private OrderViewModel AttachManufactureName(OrderViewModel model) + { + foreach (var manufacture in _source.Manufactures) + { + if (manufacture.Id == model.ManufactureId) + { + model.ManufactureName = manufacture.ManufactureName; + return model; + } + } + return model; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithListImplement/Models/Component.cs b/BlacksmithWorkshop/BlacksmithListImplement/Models/Component.cs new file mode 100644 index 0000000..31b0f31 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithListImplement/Models/Component.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopListImplement.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 + }; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithListImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithListImplement/Models/Manufacture.cs new file mode 100644 index 0000000..5997b50 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithListImplement/Models/Manufacture.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopListImplement.Models +{ + public class Manufacture : IManufactureModel + { + public int Id { get; private set; } + public string ManufactureName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary ManufactureComponents + { + get; + private set; + } = new Dictionary(); + public static Manufacture? Create(ManufactureBindingModel? model) + { + if (model == null) + { + return null; + } + return new Manufacture() + { + Id = model.Id, + ManufactureName = model.ManufactureName, + Price = model.Price, + ManufactureComponents = model.ManufactureComponents + }; + } + public void Update(ManufactureBindingModel? model) + { + if (model == null) + { + return; + } + ManufactureName = model.ManufactureName; + Price = model.Price; + ManufactureComponents = model.ManufactureComponents; + } + public ManufactureViewModel GetViewModel => new() + { + Id = Id, + ManufactureName = ManufactureName, + Price = Price, + ManufactureComponents = ManufactureComponents + }; + } +} diff --git a/BlacksmithWorkshop/BlacksmithListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithListImplement/Models/Order.cs new file mode 100644 index 0000000..99c55e0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithListImplement/Models/Order.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int ManufactureId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; set; } = DateTime.Now; + + public DateTime? DateImplement { get; set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ManufactureId = model.ManufactureId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + ManufactureId = model.ManufactureId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + ManufactureId = ManufactureId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index 3614cbc..6b3e6c8 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33213.308 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshop", "BlacksmithWorkshop\BlacksmithWorkshop.csproj", "{5F8B5D62-D588-4F87-9EA8-AD6A241FCD81}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDataModels", "AbstractShopDataModels\BlacksmithWorkshopDataModels.csproj", "{3D0FF8DF-07A2-45FA-A823-812674C3B094}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopContracts", "AbstractShopContracts\BlacksmithWorkshopContracts.csproj", "{9EA057E2-4895-45C1-B1E4-76748E34B4BD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopBusinessLogic", "BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj", "{7FB1CF71-6523-4F2C-8C9D-F5F965CBF543}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopListImplement", "BlacksmithListImplement\BlacksmithWorkshopListImplement.csproj", "{DF0A453B-08F8-412D-9A12-15183A01F146}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopView", "BlacksmithWorkshopView\BlacksmithWorkshopView.csproj", "{06FE12F5-A8F2-4FAE-A80A-ADD070E86EB9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,10 +19,26 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5F8B5D62-D588-4F87-9EA8-AD6A241FCD81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5F8B5D62-D588-4F87-9EA8-AD6A241FCD81}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5F8B5D62-D588-4F87-9EA8-AD6A241FCD81}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5F8B5D62-D588-4F87-9EA8-AD6A241FCD81}.Release|Any CPU.Build.0 = Release|Any CPU + {3D0FF8DF-07A2-45FA-A823-812674C3B094}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3D0FF8DF-07A2-45FA-A823-812674C3B094}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3D0FF8DF-07A2-45FA-A823-812674C3B094}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3D0FF8DF-07A2-45FA-A823-812674C3B094}.Release|Any CPU.Build.0 = Release|Any CPU + {9EA057E2-4895-45C1-B1E4-76748E34B4BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9EA057E2-4895-45C1-B1E4-76748E34B4BD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9EA057E2-4895-45C1-B1E4-76748E34B4BD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9EA057E2-4895-45C1-B1E4-76748E34B4BD}.Release|Any CPU.Build.0 = Release|Any CPU + {7FB1CF71-6523-4F2C-8C9D-F5F965CBF543}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7FB1CF71-6523-4F2C-8C9D-F5F965CBF543}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7FB1CF71-6523-4F2C-8C9D-F5F965CBF543}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7FB1CF71-6523-4F2C-8C9D-F5F965CBF543}.Release|Any CPU.Build.0 = Release|Any CPU + {DF0A453B-08F8-412D-9A12-15183A01F146}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF0A453B-08F8-412D-9A12-15183A01F146}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF0A453B-08F8-412D-9A12-15183A01F146}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF0A453B-08F8-412D-9A12-15183A01F146}.Release|Any CPU.Build.0 = Release|Any CPU + {06FE12F5-A8F2-4FAE-A80A-ADD070E86EB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06FE12F5-A8F2-4FAE-A80A-ADD070E86EB9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06FE12F5-A8F2-4FAE-A80A-ADD070E86EB9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {06FE12F5-A8F2-4FAE-A80A-ADD070E86EB9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj index b57c89e..f64dde1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj @@ -8,4 +8,10 @@ enable + + + + + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj new file mode 100644 index 0000000..f822825 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/ComponentLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..1795cc5 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/ComponentLogic.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshopBusinessLogic.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/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/ManufactureLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/ManufactureLogic.cs new file mode 100644 index 0000000..3818063 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/ManufactureLogic.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshopBusinessLogic +{ + public class ManufactureLogic : IManufactureLogic + { + private readonly ILogger _logger; + private readonly IManufactureStorage _ManufactureStorage; + + public ManufactureLogic(ILogger logger, IManufactureStorage ManufactureStorage) + { + _logger = logger; + _ManufactureStorage = ManufactureStorage; + } + + public List? ReadList(ManufactureSearchModel? model) + { + _logger.LogInformation("ReadList. ManufactureName:{ManufactureName}.Id:{ Id}", model?.ManufactureName, model?.Id); + var list = model == null ? _ManufactureStorage.GetFullList() : _ManufactureStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ManufactureViewModel? ReadElement(ManufactureSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ManufactureName:{ManufactureName}.Id:{ Id}", model.ManufactureName, model.Id); + var element = _ManufactureStorage.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(ManufactureBindingModel model) + { + CheckModel(model); + if (_ManufactureStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ManufactureBindingModel model) + { + CheckModel(model); + if (_ManufactureStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ManufactureBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_ManufactureStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ManufactureBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ManufactureName)) + { + throw new ArgumentNullException("Нет названия компьютера", nameof(model.ManufactureName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена компьютера должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Manufacture. ManufactureName:{ManufactureName}.Cost:{ Cost}. Id: { Id}", model.ManufactureName, model.Price, model.Id); + var element = _ManufactureStorage.GetElement(new ManufactureSearchModel + { + ManufactureName = model.ManufactureName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компьютер с таким названием уже есть"); + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..774e55c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OrderLogic.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshopBusinessLogic +{ + 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. OrderId:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (!CheckStatus(model, OrderStatus.Принят, false)) return false; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + CheckModel(model); + if (!CheckStatus(model, OrderStatus.Выполняется)) return false; + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + CheckModel(model); + if (!CheckStatus(model, OrderStatus.Готов)) return false; + return true; + } + + public bool FinishOrder(OrderBindingModel model) + { + CheckModel(model); + if (!CheckStatus(model, OrderStatus.Выдан)) return false; + return true; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.ManufactureId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор компьютера", nameof(model.ManufactureId)); + } + 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. OrderId:{Id}.Sum:{ Sum}. ManufactureId: { ManufactureId}", model.Id, model.Sum, model.ManufactureId); + } + + private bool CheckStatus(OrderBindingModel model, OrderStatus newstatus, bool update = true) + { + if (model.Status != newstatus - 1) + { + _logger.LogWarning("Failed to change status"); + return false; + } + model.Status = newstatus; + if (!update) return true; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + return true; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj b/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj new file mode 100644 index 0000000..2b99627 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj @@ -0,0 +1,21 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponent.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponent.Designer.cs new file mode 100644 index 0000000..ad5aa2f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace BlacksmithWorkshopView +{ + 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.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.labelCost = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 9); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(98, 9); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(366, 27); + this.textBoxName.TabIndex = 1; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(98, 42); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(133, 27); + this.textBoxCost.TabIndex = 3; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(12, 42); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(45, 20); + this.labelCost.TabIndex = 2; + this.labelCost.Text = "Цена"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(171, 90); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(130, 40); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(328, 90); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(136, 40); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(478, 142); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxCost; + private Label labelCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponent.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponent.cs new file mode 100644 index 0000000..0eea386 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponent.cs @@ -0,0 +1,82 @@ +using Microsoft.Extensions.Logging; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using System.Windows.Forms; + +namespace BlacksmithWorkshopView +{ + 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(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponent.resx b/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponent.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponents.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponents.Designer.cs new file mode 100644 index 0000000..cef2a63 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponents.Designer.cs @@ -0,0 +1,130 @@ +namespace BlacksmithWorkshopView +{ + 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.ToolsPanel.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(590, 426); + this.dataGridView.TabIndex = 0; + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(608, 12); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(180, 426); + this.ToolsPanel.TabIndex = 1; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(31, 206); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(126, 36); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(31, 142); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(126, 36); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(31, 76); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(126, 36); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(31, 16); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(126, 36); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ToolsPanel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponents.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponents.cs new file mode 100644 index 0000000..24f27fc --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponents.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +using Microsoft.Extensions.Logging; +using BlacksmithWorkshopView; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; + +namespace BlacksmithWorkshopView +{ + 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) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponents.resx b/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponents.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BlacksmithWorkshop/BlacksmithWorkshopView/FormCreateOrder.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..8dfad4d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormCreateOrder.Designer.cs @@ -0,0 +1,145 @@ +namespace BlacksmithWorkshopView +{ + 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.labelManufacture = new System.Windows.Forms.Label(); + this.comboBoxManufacture = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelSum = new System.Windows.Forms.Label(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelManufacture + // + this.labelManufacture.AutoSize = true; + this.labelManufacture.Location = new System.Drawing.Point(12, 15); + this.labelManufacture.Name = "labelManufacture"; + this.labelManufacture.Size = new System.Drawing.Size(75, 20); + this.labelManufacture.TabIndex = 0; + this.labelManufacture.Text = "Изделие: "; + // + // comboBoxManufacture + // + this.comboBoxManufacture.FormattingEnabled = true; + this.comboBoxManufacture.Location = new System.Drawing.Point(115, 12); + this.comboBoxManufacture.Name = "comboBoxManufacture"; + this.comboBoxManufacture.Size = new System.Drawing.Size(358, 28); + this.comboBoxManufacture.TabIndex = 1; + this.comboBoxManufacture.SelectedIndexChanged += new System.EventHandler(this.ComboBoxManufacture_SelectedIndexChanged); + // + // 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(97, 20); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество: "; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(115, 46); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(358, 27); + this.textBoxCount.TabIndex = 3; + this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(12, 80); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(62, 20); + this.labelSum.TabIndex = 4; + this.labelSum.Text = "Сумма: "; + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(115, 80); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(358, 27); + this.textBoxSum.TabIndex = 5; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(337, 113); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(110, 32); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(221, 113); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(110, 32); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(485, 158); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxManufacture); + this.Controls.Add(this.labelManufacture); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelManufacture; + private ComboBox comboBoxManufacture; + private Label labelCount; + private TextBox textBoxCount; + private Label labelSum; + private TextBox textBoxSum; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormCreateOrder.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormCreateOrder.cs new file mode 100644 index 0000000..539b11a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormCreateOrder.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace BlacksmithWorkshopView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IManufactureLogic _logicM; + private readonly IOrderLogic _logicO; + private List? _list; + public FormCreateOrder(ILogger logger, IManufactureLogic logicM, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicM = logicM; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _list = _logicM.ReadList(null); + if (_list != null) + { + comboBoxManufacture.DisplayMember = "ManufactureName"; + comboBoxManufacture.ValueMember = "Id"; + comboBoxManufacture.DataSource = _list; + comboBoxManufacture.SelectedItem = null; + _logger.LogInformation("Загрузка изделий для заказа"); + } + } + private void CalcSum() + { + if (comboBoxManufacture.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxManufacture.SelectedValue); + var Manufacture = _logicM.ReadElement(new ManufactureSearchModel{ Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Manufacture?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ComboBoxManufacture_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxManufacture.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + ManufactureId = Convert.ToInt32(comboBoxManufacture.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(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormCreateOrder.resx b/BlacksmithWorkshop/BlacksmithWorkshopView/FormCreateOrder.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.Designer.cs new file mode 100644 index 0000000..1dd1fd6 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.Designer.cs @@ -0,0 +1,187 @@ +namespace BlacksmithWorkshopView +{ + 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.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.guideToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.goodsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + this.buttonOrderReady = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.guideToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); + this.menuStrip1.Size = new System.Drawing.Size(1149, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // guideToolStripMenuItem + // + this.guideToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.componentsToolStripMenuItem, + this.goodsToolStripMenuItem}); + this.guideToolStripMenuItem.Name = "guideToolStripMenuItem"; + this.guideToolStripMenuItem.Size = new System.Drawing.Size(87, 20); + this.guideToolStripMenuItem.Text = "Справочник"; + // + // componentsToolStripMenuItem + // + this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + this.componentsToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.componentsToolStripMenuItem.Text = "Компоненты"; + this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); + // + // goodsToolStripMenuItem + // + this.goodsToolStripMenuItem.Name = "goodsToolStripMenuItem"; + this.goodsToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.goodsToolStripMenuItem.Text = "Изделия"; + this.goodsToolStripMenuItem.Click += new System.EventHandler(this.GoodsToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(10, 23); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(855, 286); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(898, 53); + this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(216, 22); + this.buttonCreateOrder.TabIndex = 2; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(898, 92); + this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(216, 22); + this.buttonTakeOrderInWork.TabIndex = 3; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Location = new System.Drawing.Point(898, 129); + this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(216, 22); + this.buttonOrderReady.TabIndex = 4; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Location = new System.Drawing.Point(898, 169); + this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(216, 22); + this.buttonIssuedOrder.TabIndex = 5; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(898, 210); + this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(216, 22); + this.buttonRef.TabIndex = 6; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1149, 319); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormMain"; + this.Text = "Кузнечная мастерская"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem guideToolStripMenuItem; + private ToolStripMenuItem componentsToolStripMenuItem; + private ToolStripMenuItem goodsToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.cs new file mode 100644 index 0000000..868f154 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.cs @@ -0,0 +1,148 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +using Microsoft.Extensions.Logging; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopView +{ + 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) + { + dataGridView.DataSource = list; + dataGridView.Columns["ManufactureId"].Visible = false; + dataGridView.Columns["ManufactureName"].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 GoodsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormManufacturies)); + if (service is FormManufacturies 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 (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ No{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(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.resx b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/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/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacture.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacture.Designer.cs new file mode 100644 index 0000000..0b0703f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacture.Designer.cs @@ -0,0 +1,236 @@ +namespace BlacksmithWorkshopView +{ + partial class FormManufacture + { + /// + /// 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.textBoxName = new System.Windows.Forms.TextBox(); + this.labelPrice = new System.Windows.Forms.Label(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBoxComponents = new System.Windows.Forms.GroupBox(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(16, 15); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(84, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название: "; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(112, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(293, 27); + this.textBoxName.TabIndex = 1; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(16, 51); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(90, 20); + this.labelPrice.TabIndex = 2; + this.labelPrice.Text = "Стоимость: "; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(112, 51); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(171, 27); + this.textBoxPrice.TabIndex = 3; + // + // groupBoxComponents + // + this.groupBoxComponents.Controls.Add(this.buttonRef); + this.groupBoxComponents.Controls.Add(this.buttonDel); + this.groupBoxComponents.Controls.Add(this.buttonUpd); + this.groupBoxComponents.Controls.Add(this.buttonAdd); + this.groupBoxComponents.Controls.Add(this.dataGridView); + this.groupBoxComponents.Location = new System.Drawing.Point(12, 84); + this.groupBoxComponents.Name = "groupBoxComponents"; + this.groupBoxComponents.Size = new System.Drawing.Size(661, 319); + this.groupBoxComponents.TabIndex = 4; + this.groupBoxComponents.TabStop = false; + this.groupBoxComponents.Text = "Компоненты"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(502, 211); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(126, 34); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(502, 157); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(126, 34); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(502, 102); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(126, 34); + 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(502, 47); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(126, 34); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.id, + this.Component, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(6, 26); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(476, 287); + this.dataGridView.TabIndex = 0; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(514, 417); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(126, 34); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(368, 417); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(126, 34); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // id + // + this.id.HeaderText = "id"; + this.id.MinimumWidth = 6; + this.id.Name = "id"; + this.id.ReadOnly = true; + this.id.Visible = false; + // + // Component + // + this.Component.HeaderText = "Компонент"; + this.Component.MinimumWidth = 6; + this.Component.Name = "Component"; + this.Component.ReadOnly = true; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.ReadOnly = true; + // + // FormManufacture + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(685, 463); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.groupBoxComponents); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Name = "FormManufacture"; + this.Text = "Изделие"; + this.Load += new System.EventHandler(this.FormManufacture_Load); + this.groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private Label labelPrice; + private TextBox textBoxPrice; + private GroupBox groupBoxComponents; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + private Button buttonCancel; + private Button buttonSave; + private DataGridViewTextBoxColumn id; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacture.cs new file mode 100644 index 0000000..57c591d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacture.cs @@ -0,0 +1,200 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopDataModels.Models; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + +namespace BlacksmithWorkshopView +{ + public partial class FormManufacture : Form + { + private readonly ILogger _logger; + private readonly IManufactureLogic _logic; + private int? _id; + private Dictionary _ManufactureComponents; + public int Id { set { _id = value; } } + public FormManufacture(ILogger logger, IManufactureLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _ManufactureComponents = new Dictionary(); + } + private void FormManufacture_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new ManufactureSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ManufactureName; + textBoxPrice.Text = view.Price.ToString(); + _ManufactureComponents = view.ManufactureComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_ManufactureComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _ManufactureComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormManufactureComponent)); + if (service is FormManufactureComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_ManufactureComponents.ContainsKey(form.Id)) + { + _ManufactureComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _ManufactureComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormManufactureComponent)); + if (service is FormManufactureComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _ManufactureComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + _ManufactureComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: {ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _ManufactureComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_ManufactureComponents == null || _ManufactureComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new ManufactureBindingModel + { + Id = _id ?? 0, + ManufactureName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + ManufactureComponents = _ManufactureComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _ManufactureComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } +} +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacture.resx b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacture.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacture.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufactureComponent.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufactureComponent.Designer.cs new file mode 100644 index 0000000..d668971 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufactureComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace BlacksmithWorkshopView +{ + partial class FormManufactureComponent + { + /// + /// 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.labelComponent = new System.Windows.Forms.Label(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(12, 9); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(91, 20); + this.labelComponent.TabIndex = 0; + this.labelComponent.Text = "Компонент:"; + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(119, 9); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(355, 28); + this.comboBoxComponent.TabIndex = 1; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 51); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество:"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(119, 51); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(355, 27); + this.textBoxCount.TabIndex = 3; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(317, 94); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(136, 41); + 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(175, 94); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(136, 41); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormManufactureComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(486, 147); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.labelComponent); + this.Name = "FormManufactureComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelComponent; + private ComboBox comboBoxComponent; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufactureComponent.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufactureComponent.cs new file mode 100644 index 0000000..c44f073 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufactureComponent.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopView +{ + public partial class FormManufactureComponent : 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 FormManufactureComponent(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(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufactureComponent.resx b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufactureComponent.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufactureComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacturies.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacturies.Designer.cs new file mode 100644 index 0000000..2c8d5e5 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacturies.Designer.cs @@ -0,0 +1,130 @@ +namespace BlacksmithWorkshopView +{ + partial class FormManufacturies + { + /// + /// 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.ToolsPanel = new System.Windows.Forms.Panel(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ToolsPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // ToolsPanel + // + this.ToolsPanel.Controls.Add(this.buttonRef); + this.ToolsPanel.Controls.Add(this.buttonDel); + this.ToolsPanel.Controls.Add(this.buttonUpd); + this.ToolsPanel.Controls.Add(this.buttonAdd); + this.ToolsPanel.Location = new System.Drawing.Point(608, 12); + this.ToolsPanel.Name = "ToolsPanel"; + this.ToolsPanel.Size = new System.Drawing.Size(180, 426); + this.ToolsPanel.TabIndex = 3; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(31, 206); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(126, 36); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(31, 142); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(126, 36); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(31, 76); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(126, 36); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(31, 16); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(126, 36); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(590, 426); + this.dataGridView.TabIndex = 2; + // + // FormManufacturies + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.ToolsPanel); + this.Controls.Add(this.dataGridView); + this.Name = "FormManufacturies"; + this.Text = "Изделия"; + this.Load += new System.EventHandler(this.FormManufacturies_Load); + this.ToolsPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Panel ToolsPanel; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacturies.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacturies.cs new file mode 100644 index 0000000..62a8816 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacturies.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +using Microsoft.Extensions.Logging; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; + +namespace BlacksmithWorkshopView +{ + public partial class FormManufacturies : Form + { + private readonly ILogger _logger; + private readonly IManufactureLogic _logic; + public FormManufacturies(ILogger logger, IManufactureLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormManufacturies_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ManufactureComponents"].Visible = false; + dataGridView.Columns["ManufactureName"].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(FormManufacture)); + if (service is FormManufacture form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); + if (service is FormManufacture form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление изделия"); + try + { + if (!_logic.Delete(new ManufactureBindingModel { 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(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacturies.resx b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacturies.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormManufacturies.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs new file mode 100644 index 0000000..93df0ab --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs @@ -0,0 +1,54 @@ +using BlacksmithWorkshopBusinessLogic.BusinessLogics; +using BlacksmithWorkshopBusinessLogic; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using OrdersShopListImplement.Implements; + +namespace BlacksmithWorkshopView +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + 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/BlacksmithWorkshop/BlacksmithWorkshopView/nlog.config b/BlacksmithWorkshop/BlacksmithWorkshopView/nlog.config new file mode 100644 index 0000000..dcd37c8 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file