diff --git a/PrecastConcretePlant/PrecastConcretePlant.sln b/PrecastConcretePlant/PrecastConcretePlant.sln index 8791798..ca28c64 100644 --- a/PrecastConcretePlant/PrecastConcretePlant.sln +++ b/PrecastConcretePlant/PrecastConcretePlant.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantBusines EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantListImplement", "PrecastConcretePlantListImplement\PrecastConcretePlantListImplement.csproj", "{CF73527C-9003-4A88-AFBB-58272DFB6859}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantFileImplement", "PrecastConcretePlantFileImplement\PrecastConcretePlantFileImplement.csproj", "{EBD137D3-EB6D-4CE4-9A03-357373300240}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {CF73527C-9003-4A88-AFBB-58272DFB6859}.Debug|Any CPU.Build.0 = Debug|Any CPU {CF73527C-9003-4A88-AFBB-58272DFB6859}.Release|Any CPU.ActiveCfg = Release|Any CPU {CF73527C-9003-4A88-AFBB-58272DFB6859}.Release|Any CPU.Build.0 = Release|Any CPU + {EBD137D3-EB6D-4CE4-9A03-357373300240}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EBD137D3-EB6D-4CE4-9A03-357373300240}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EBD137D3-EB6D-4CE4-9A03-357373300240}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EBD137D3-EB6D-4CE4-9A03-357373300240}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/OrderLogic.cs index 1626f0a..519df4b 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/OrderLogic.cs @@ -10,6 +10,7 @@ using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.StoragesContracts; using PrecastConcretePlantContracts.ViewModels; using PrecastConcretePlantDataModels.Enums; +using System.Xml.Linq; namespace PrecastConcretePlantBusinessLogic.BusinessLogics { @@ -17,12 +18,14 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) - { + private readonly IShopStorage _shopStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage) + { _logger = logger; _orderStorage = orderStorage; - } - public List? ReadList(OrderSearchModel? model) + _shopStorage = shopStorage; + } + public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); @@ -57,7 +60,23 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics } public bool DeliveryOrder(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выдан); + var order = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id, + }); + if (order == null) + { + throw new ArgumentNullException(nameof(order)); + } + if (!_shopStorage.RestockingShops(new SupplyBindingModel + { + ReinforcedId = order.ReinforcedId, + count = order.Count + })) + { + throw new ArgumentException("Недостаточно места в магазинах для поставки"); + } + return ChangeStatus(model, OrderStatus.Выдан); } private void CheckModel(OrderBindingModel model, bool withParams = true) { diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ShopLogic.cs index 1e79fb0..cbb0a3c 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ShopLogic.cs @@ -118,8 +118,32 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics } shop.ShopReinforcedes.Add(model.ReinforcedId, (reinforsed, model.count)); } + _shopStorage.Update(new() + { + Id = shop.Id, + ShopName = shop.ShopName, + Adress = shop.Adress, + OpeningDate = shop.OpeningDate, + ShopReinforcedes = shop.ShopReinforcedes, + ReinforcedMaxCount = shop.ReinforcedMaxCount + }); return true; } + public bool Sale(SupplySearchModel model) + { + if (!model.ReinforcedId.HasValue || !model.Count.HasValue) + { + return false; + } + _logger.LogInformation("Check reinforced count in all shops"); + if (_shopStorage.Sale(model)) + { + _logger.LogInformation("amount is enough. Selling sucsess"); + return true; + } + _logger.LogInformation("amount is insufficient"); + return false; + } private void CheckModel(ShopBindingModel model, bool withParams = true) { if (model == null) diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs index 371d1e1..cded059 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -14,5 +14,6 @@ namespace PrecastConcretePlantContracts.BindingModels public string Adress { get; set; } = string.Empty; public DateTime OpeningDate { get; set; } = DateTime.Now;//Предполагается, что открытие магазина совпадает с добавлением его в Систему. public Dictionary ShopReinforcedes { get; set; } = new(); + public int ReinforcedMaxCount { get; set; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs index 68e7667..95e8bcf 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -17,5 +17,6 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool MakeSupply(SupplyBindingModel model); + bool Sale(SupplySearchModel model); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/SupplySearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/SupplySearchModel.cs new file mode 100644 index 0000000..f5ff760 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/SupplySearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.SearchModels +{ + public class SupplySearchModel + { + public int? ReinforcedId { get; set; } + public int? Count { get; set; } + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs index 357d521..05dfaf8 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs @@ -17,5 +17,7 @@ namespace PrecastConcretePlantContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool Sale(SupplySearchModel model); + bool RestockingShops(SupplyBindingModel model); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs index 83db4bf..ca79447 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -18,5 +18,7 @@ namespace PrecastConcretePlantContracts.ViewModels [DisplayName("Дата открытия")] public DateTime OpeningDate { get; set; } public Dictionary ShopReinforcedes { get; set; } = new(); + [DisplayName("Вместимость")] + public int ReinforcedMaxCount { get; set; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/IComponentModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/IComponentModel.cs deleted file mode 100644 index dee2b92..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/IComponentModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using PrecastConcretePlantDataModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PrecastConcretePlantDataModels.Models -{ - public interface IComponentModel : IId - { - string ComponentName { get; } - double Cost { get; } - } -} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/IOrderModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/IOrderModel.cs deleted file mode 100644 index db89e4e..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/IOrderModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -using PrecastConcretePlantDataModels.Enums; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PrecastConcretePlantDataModels.Models -{ - public interface IOrderModel : IId - { - int ReinforcedId { get; } - int Count { get; } - double Sum { get; } - OrderStatus Status { get; } - DateTime DateCreate { get; } - DateTime? DateImplement { get; } - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/IReinforcedModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/IReinforcedModel.cs deleted file mode 100644 index a0df31c..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/IReinforcedModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using PrecastConcretePlantDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PrecastConcretePlantDataModels.Models -{ - public interface IReinforcedModel : IId - { - string ReinforcedName { get; } - double Price { get; } - Dictionary ReinforcedComponents { get; } - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs index 66ad021..e9afeb6 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs @@ -14,5 +14,6 @@ namespace PrecastConcretePlantDataModels.Models string Adress { get; } DateTime OpeningDate { get; } Dictionary ShopReinforcedes { get; } + int ReinforcedMaxCount { get; } } -} +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/OrderStatus.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/OrderStatus.cs deleted file mode 100644 index e90a627..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/OrderStatus.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PrecastConcretePlantDataModels.Enums -{ - public enum OrderStatus - { - Неизвестен = -1, - Принят = 0, - Выполняется = 1, - Готов = 2, - Выдан = 3 - } -} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..d20a052 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs @@ -0,0 +1,57 @@ +using PrecastConcretePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string ReinforcedFileName = "Reinforced.xml"; + private readonly string ShopFileName = "Shop.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Reinforceds { get; private set; } + public List Shops { get; private set; } + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); + public void SaveReinforceds() => SaveData(Reinforceds, ReinforcedFileName, "Reinforceds", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Reinforceds = LoadData(ReinforcedFileName, "Reinforced", x => Reinforced.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) + { + if (File.Exists(filename)) + { + return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + return new List(); + } + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); + } + } + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ComponentStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..17e3521 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ComponentStorage.cs @@ -0,0 +1,79 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataFileSingleton source; + public ComponentStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Components.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList(); + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + return source.Components.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + source.Components.Add(newComponent); + source.SaveComponents(); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + var component = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + source.SaveComponents(); + return component.GetViewModel; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + var element = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Components.Remove(element); + source.SaveComponents(); + return element.GetViewModel; + } + return null; + } + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..12d5c5a --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,93 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Orders.Select(x => AttachReinforcedName(x.GetViewModel)).ToList(); + } + public List GetFilteredList(OrderSearchModel model) + { + //Метод полностью может быть заменён следующим. Практическая польза незначительна + if (!model.Id.HasValue) + { + return new(); + } + return source.Orders.Where(x => x.Id == model.Id).Select(x => AttachReinforcedName(x.GetViewModel)).ToList(); + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return AttachReinforcedName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel); + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return AttachReinforcedName(newOrder.GetViewModel); + } + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return AttachReinforcedName(order.GetViewModel); + } + public OrderViewModel? Delete(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order != null) + { + source.Orders.Remove(order); + source.SaveOrders(); + return AttachReinforcedName(order.GetViewModel); + } + return null; + } + private OrderViewModel AttachReinforcedName(OrderViewModel? model) + { + //Из всех мест, это выглядит наиболее подходящим, для данной манипуляции. + //При расположении ниже нарушится целостность данных + //При расположении выше будет нарушен принцип разделения уровней + if (model == null) + { + return null; + } + var reinforced = source.Reinforceds.FirstOrDefault(x => x.Id == model.ReinforcedId); + if (reinforced != null) + { + model.ReinforcedName = reinforced.ReinforcedName; + } + return model; + } + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ReinforcedStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ReinforcedStorage.cs new file mode 100644 index 0000000..df0a72d --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ReinforcedStorage.cs @@ -0,0 +1,79 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class ReinforcedStorage : IReinforcedStorage + { + private readonly DataFileSingleton source; + public ReinforcedStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Reinforceds.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ReinforcedSearchModel model) + { + if (string.IsNullOrEmpty(model.ReinforcedName)) + { + return new(); + } + return source.Reinforceds.Where(x => x.ReinforcedName.Contains(model.ReinforcedName)).Select(x => x.GetViewModel).ToList(); + } + public ReinforcedViewModel? GetElement(ReinforcedSearchModel model) + { + if (string.IsNullOrEmpty(model.ReinforcedName) && !model.Id.HasValue) + { + return null; + } + return source.Reinforceds.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ReinforcedName) && x.ReinforcedName == model.ReinforcedName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + public ReinforcedViewModel? Insert(ReinforcedBindingModel model) + { + model.Id = source.Reinforceds.Count > 0 ? source.Reinforceds.Max(x => x.Id) + 1 : 1; + var newReinforced = Reinforced.Create(model); + if (newReinforced == null) + { + return null; + } + source.Reinforceds.Add(newReinforced); + source.SaveReinforceds(); + return newReinforced.GetViewModel; + } + public ReinforcedViewModel? Update(ReinforcedBindingModel model) + { + var reinforced = source.Reinforceds.FirstOrDefault(x => x.Id == model.Id); + if (reinforced == null) + { + return null; + } + reinforced.Update(model); + source.SaveReinforceds(); + return reinforced.GetViewModel; + } + public ReinforcedViewModel? Delete(ReinforcedBindingModel model) + { + var reinforced = source.Reinforceds.FirstOrDefault(x => x.Id == model.Id); + if (reinforced != null) + { + source.Reinforceds.Remove(reinforced); + source.SaveReinforceds(); + return reinforced.GetViewModel; + } + return null; + } + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..b83f6dc --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,141 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Shops.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + return source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList(); + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + return source.Shops.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop != null) + { + source.Shops.Remove(shop); + source.SaveShops(); + return shop.GetViewModel; + } + return null; + } + public bool Sale(SupplySearchModel model) + { + if (model == null || !model.ReinforcedId.HasValue || !model.Count.HasValue) + return false; + int remainingSpace = source.Shops.Select(x => x.Reinforcedes.ContainsKey(model.ReinforcedId.Value) ? x.Reinforcedes[model.ReinforcedId.Value] : 0).Sum(); + if (remainingSpace < model.Count) + { + return false; + } + var shops = source.Shops.Where(x => x.Reinforcedes.ContainsKey(model.ReinforcedId.Value)).OrderByDescending(x => x.Reinforcedes[model.ReinforcedId.Value]).ToList(); + foreach (var shop in shops) + { + int residue = model.Count.Value - shop.Reinforcedes[model.ReinforcedId.Value]; + if (residue > 0) + { + shop.Reinforcedes.Remove(model.ReinforcedId.Value); + shop.UpdateContent(); + model.Count = residue; + } + else + { + if (residue == 0) + shop.Reinforcedes.Remove(model.ReinforcedId.Value); + else + shop.Reinforcedes[model.ReinforcedId.Value] = -residue; + shop.UpdateContent(); + source.SaveShops(); + return true; + } + } + source.SaveShops(); + return false; + } + public bool RestockingShops(SupplyBindingModel model) + { + if (model == null || source.Shops.Select(x => x.ReinforcedMaxCount - x.ShopReinforcedes.Select(y => y.Value.Item2).Sum()).Sum() < model.count) + { + return false; + } + foreach (Shop shop in source.Shops) + { + int difference = shop.ReinforcedMaxCount - shop.ShopReinforcedes.Select(x => x.Value.Item2).Sum(); + if (difference <= 0) + continue; + int refill = Math.Min(difference, model.count); + model.count -= refill; + if (shop.Reinforcedes.ContainsKey(model.ReinforcedId)) + { + shop.Reinforcedes[model.ReinforcedId] += refill; + } + else + { + shop.Reinforcedes.Add(model.ReinforcedId, refill); + } + shop.UpdateContent(); + if (model.count == 0) + { + source.SaveShops(); + return true; + } + } + throw new ArgumentException("Непредвиденная ошибка при пополнении магазинов"); + } + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Component.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Component.cs new file mode 100644 index 0000000..03859fc --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Component.cs @@ -0,0 +1,65 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement.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 static Component? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Component() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComponentName = element.Element("ComponentName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + public XElement GetXElement => new("Component", + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs new file mode 100644 index 0000000..602eebf --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs @@ -0,0 +1,88 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Enums; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int ReinforcedId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ReinforcedId = model.ReinforcedId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + string dateImplement = element.Element("DateImplement")!.Value; + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Sum = Convert.ToInt32(element.Element("Sum")!.Value), + Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement) + }; + + } + public void Update(OrderBindingModel model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + //ReinforcedName ,будет определено далее, в классе хранилища, так как это более рационально + Id = Id, + ReinforcedId = ReinforcedId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("ReinforcedId", ReinforcedId.ToString()), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Reinforced.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Reinforced.cs new file mode 100644 index 0000000..7bba1d7 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Reinforced.cs @@ -0,0 +1,88 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement.Models +{ + public class Reinforced : IReinforcedModel + { + public int Id { get; private set; } + public string ReinforcedName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _reinforcedComponents = null; + public Dictionary ReinforcedComponents + { + get + { + if (_reinforcedComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _reinforcedComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); + } + return _reinforcedComponents; + } + } + public static Reinforced? Create(ReinforcedBindingModel model) + { + if (model == null) + { + return null; + } + return new Reinforced() + { + Id = model.Id, + ReinforcedName = model.ReinforcedName, + Price = model.Price, + Components = model.ReinforcedComponents.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Reinforced? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Reinforced() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ReinforcedName = element.Element("ReinforcedName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = element.Element("ReinforcedComponents")!.Elements("ReinforcedComponent").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(ReinforcedBindingModel model) + { + if (model == null) + { + return; + } + ReinforcedName = model.ReinforcedName; + Price = model.Price; + Components = model.ReinforcedComponents.ToDictionary(x => x.Key, x => x.Value.Item2); + _reinforcedComponents = null; + } + public ReinforcedViewModel GetViewModel => new() + { + Id = Id, + ReinforcedName = ReinforcedName, + Price = Price, + ReinforcedComponents = ReinforcedComponents + }; + public XElement GetXElement => new("Reinforced", + new XAttribute("Id", Id), + new XElement("ReinforcedName", ReinforcedName), + new XElement("Price", Price.ToString()), + new XElement("ReinforcedComponents", Components.Select( + x => new XElement("ReinforcedComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray())); + } + + +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs new file mode 100644 index 0000000..165e07d --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs @@ -0,0 +1,104 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Adress { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary Reinforcedes { get; private set; } = new(); + private Dictionary? _shopReinforcedes = null; + public Dictionary ShopReinforcedes + { + get + { + if (_shopReinforcedes == null) + { + var source = DataFileSingleton.GetInstance(); + _shopReinforcedes = Reinforcedes.ToDictionary(x => x.Key, y => ((source.Reinforceds.FirstOrDefault(z => z.Id == y.Key) as IReinforcedModel)!, y.Value)); + } + return _shopReinforcedes; + } + } + public int ReinforcedMaxCount { get; private set; } + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate, + Reinforcedes = model.ShopReinforcedes.ToDictionary(x => x.Key, x => x.Value.Item2), + ReinforcedMaxCount = model.ReinforcedMaxCount + }; + } + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Adress = element.Element("Adress")!.Value, + OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value), + Reinforcedes = element.Element("ShopReinforcedes")!.Elements("ShopReinforced")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)), + ReinforcedMaxCount = Convert.ToInt32(element.Element("ReinforcedMaxCount")!.Value) + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + ReinforcedMaxCount = model.ReinforcedMaxCount; + Reinforcedes = model.ShopReinforcedes.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopReinforcedes = null; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopReinforcedes = ShopReinforcedes, + ReinforcedMaxCount = ReinforcedMaxCount + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Adress", Adress), + new XElement("OpeningDate", OpeningDate.ToString()), + new XElement("ShopReinforcedes", Reinforcedes.Select( + x => new XElement("ShopReinforced", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()), + new XElement("ReinforcedMaxCount", ReinforcedMaxCount.ToString()) + ); + public void UpdateContent() + { + //метод придуман для удобного обновления на низком уровне(из хранилища). Фактически меняем мы там Reinforcedes. + _shopReinforcedes = null; + } + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj b/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj new file mode 100644 index 0000000..d3bab3e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs index d486dd4..214a69b 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs @@ -102,5 +102,17 @@ namespace PrecastConcretePlantListImplement.Implements } return null; } + public bool Sale(SupplySearchModel model) + { + throw new NotImplementedException(); + } + public bool PresenceCheck(SupplySearchModel model) + { + throw new NotImplementedException(); + } + public bool RestockingShops(SupplyBindingModel model) + { + throw new NotImplementedException(); + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormCreateSupply.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormCreateSupply.cs index 968b145..42dd985 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormCreateSupply.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormCreateSupply.cs @@ -74,7 +74,7 @@ namespace PrecastConcretePlantView }); if (!operationResult) { - throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + throw new Exception("Магазин заполнен."); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs index 3c8fd90..b1abbd9 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs @@ -41,6 +41,7 @@ buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); + создатьПродажуToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -83,7 +84,7 @@ // // операцииToolStripMenuItem // - операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { создатьПоставкуToolStripMenuItem }); + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { создатьПоставкуToolStripMenuItem, создатьПродажуToolStripMenuItem }); операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; операцииToolStripMenuItem.Size = new Size(75, 20); операцииToolStripMenuItem.Text = "Операции"; @@ -155,6 +156,12 @@ buttonRef.UseVisualStyleBackColor = true; buttonRef.Click += buttonRef_Click; // + // создатьПродажуToolStripMenuItem + // + создатьПродажуToolStripMenuItem.Name = "создатьПродажуToolStripMenuItem"; + создатьПродажуToolStripMenuItem.Size = new Size(180, 22); + создатьПродажуToolStripMenuItem.Text = "Создать продажу"; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); @@ -193,5 +200,6 @@ private ToolStripMenuItem магазиныToolStripMenuItem; private ToolStripMenuItem операцииToolStripMenuItem; private ToolStripMenuItem создатьПоставкуToolStripMenuItem; + private ToolStripMenuItem создатьПродажуToolStripMenuItem; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.resx index 938108a..a0623c8 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.resx +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.resx @@ -1,4 +1,64 @@ - + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormSellingReinforsed.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormSellingReinforsed.Designer.cs new file mode 100644 index 0000000..e075a60 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormSellingReinforsed.Designer.cs @@ -0,0 +1,120 @@ +namespace PrecastConcretePlantView +{ + partial class FormSellingReinforsed + { + /// + /// 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.labelReinforced = new System.Windows.Forms.Label(); + this.comboBoxReinforced = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSell = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelReinforced + // + this.labelReinforced.AutoSize = true; + this.labelReinforced.Location = new System.Drawing.Point(12, 14); + this.labelReinforced.Name = "labelReinforced"; + this.labelReinforced.Size = new System.Drawing.Size(75, 20); + this.labelReinforced.TabIndex = 0; + this.labelReinforced.Text = "Изделие: "; + // + // comboBoxReinforced + // + this.comboBoxReinforced.FormattingEnabled = true; + this.comboBoxReinforced.Location = new System.Drawing.Point(115, 11); + this.comboBoxReinforced.Name = "comboBoxReinforced"; + this.comboBoxReinforced.Size = new System.Drawing.Size(239, 28); + this.comboBoxReinforced.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 55); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(97, 20); + this.label1.TabIndex = 2; + this.label1.Text = "Количество: "; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(115, 52); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(239, 27); + this.textBoxCount.TabIndex = 3; + // + // buttonSell + // + this.buttonSell.Location = new System.Drawing.Point(128, 99); + this.buttonSell.Name = "buttonSell"; + this.buttonSell.Size = new System.Drawing.Size(94, 29); + this.buttonSell.TabIndex = 4; + this.buttonSell.Text = "Продать"; + this.buttonSell.UseVisualStyleBackColor = true; + this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(242, 99); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormSellingReinforsed + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(366, 140); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSell); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.label1); + this.Controls.Add(this.comboBoxReinforced); + this.Controls.Add(this.labelReinforced); + this.Name = "FormSellingReinforsed"; + this.Text = "Продажа изделий"; + this.Load += new System.EventHandler(this.FormSellingReinforsed_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelReinforced; + private ComboBox comboBoxReinforced; + private Label label1; + private TextBox textBoxCount; + private Button buttonSell; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormSellingReinforsed.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormSellingReinforsed.cs new file mode 100644 index 0000000..614e2ca --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormSellingReinforsed.cs @@ -0,0 +1,83 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PrecastConcretePlantView +{ + public partial class FormSellingReinforsed : Form + { + private readonly ILogger _logger; + private readonly IReinforcedLogic _logicR; + private readonly IShopLogic _logicS; + private List _reinforcedList = new List(); + public FormSellingReinforsed(ILogger logger, IReinforcedLogic logicR, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicR = logicR; + _logicS = logicS; + } + private void FormSellingReinforsed_Load(object sender, EventArgs e) + { + _reinforcedList = _logicR.ReadList(null); + if (_reinforcedList != null) + { + comboBoxReinforced.DisplayMember = "ReinforcedName"; + comboBoxReinforced.ValueMember = "Id"; + comboBoxReinforced.DataSource = _reinforcedList; + comboBoxReinforced.SelectedItem = null; + _logger.LogInformation("Загрузка изделий для продажи"); + } + } + private void buttonSell_Click(object sender, EventArgs e) + { + if (comboBoxReinforced.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание покупки"); + try + { + bool resout = _logicS.Sale(new SupplySearchModel + { + ReinforcedId = Convert.ToInt32(comboBoxReinforced.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (resout) + { + _logger.LogInformation("Проверка пройдена, продажа проведена"); + MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + else { + _logger.LogInformation("Проверка не пройдена"); + MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + catch(Exception ex) + { + _logger.LogError(ex, "Ошибка создания покупки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormSellingReinforsed.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormSellingReinforsed.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormSellingReinforsed.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs index 29c05c2..5a87421 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs @@ -40,7 +40,10 @@ labelAdress = new Label(); textBoxName = new TextBox(); labelName = new Label(); + labelMaxCount = new Label(); + numericUpDownMaxCount = new NumericUpDown(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownMaxCount).BeginInit(); SuspendLayout(); // // dateTimePickerOpeningDate @@ -48,7 +51,7 @@ dateTimePickerOpeningDate.Location = new Point(118, 79); dateTimePickerOpeningDate.Margin = new Padding(3, 2, 3, 2); dateTimePickerOpeningDate.Name = "dateTimePickerOpeningDate"; - dateTimePickerOpeningDate.Size = new Size(216, 23); + dateTimePickerOpeningDate.Size = new Size(165, 23); dateTimePickerOpeningDate.TabIndex = 17; // // labelOpeningDate @@ -155,11 +158,30 @@ labelName.TabIndex = 9; labelName.Text = "Название: "; // + // labelMaxCount + // + labelMaxCount.AutoSize = true; + labelMaxCount.Location = new Point(289, 80); + labelMaxCount.Name = "labelMaxCount"; + labelMaxCount.Size = new Size(86, 15); + labelMaxCount.TabIndex = 19; + labelMaxCount.Text = "Вместимость: "; + // + // numericUpDownMaxCount + // + numericUpDownMaxCount.Location = new Point(388, 79); + numericUpDownMaxCount.Margin = new Padding(3, 2, 3, 2); + numericUpDownMaxCount.Name = "numericUpDownMaxCount"; + numericUpDownMaxCount.Size = new Size(164, 23); + numericUpDownMaxCount.TabIndex = 18; + // // FormShop // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(563, 352); + Controls.Add(labelMaxCount); + Controls.Add(numericUpDownMaxCount); Controls.Add(dateTimePickerOpeningDate); Controls.Add(labelOpeningDate); Controls.Add(buttonSave); @@ -173,6 +195,7 @@ Text = "Магазин"; Load += FormShop_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownMaxCount).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -191,5 +214,7 @@ private Label labelAdress; private TextBox textBoxName; private Label labelName; + private Label labelMaxCount; + private NumericUpDown numericUpDownMaxCount; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs index 762c13e..be4fc32 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs @@ -46,6 +46,7 @@ namespace PrecastConcretePlantView textBoxAdress.Text = view.Adress; dateTimePickerOpeningDate.Value = view.OpeningDate; _ShopReinforcedes = view.ShopReinforcedes ?? new Dictionary(); + numericUpDownMaxCount.Value = view.ReinforcedMaxCount; LoadData(); } } @@ -96,7 +97,9 @@ namespace PrecastConcretePlantView Id = _id ?? 0, ShopName = textBoxName.Text, Adress = textBoxAdress.Text, - OpeningDate = dateTimePickerOpeningDate.Value + OpeningDate = dateTimePickerOpeningDate.Value, + ReinforcedMaxCount = (int)numericUpDownMaxCount.Value, + ShopReinforcedes = _ShopReinforcedes }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx index b620bc0..7fac55a 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx @@ -1,4 +1,64 @@ - + + + @@ -66,13 +126,4 @@ True - - True - - - True - - - True - \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj b/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj index 00b5484..01355f7 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj +++ b/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj @@ -15,6 +15,7 @@ + diff --git a/PrecastConcretePlant/PrecastConcretePlantView/Program.cs b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs index 6eec3a4..ea079b3 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs @@ -4,7 +4,7 @@ using NLog.Extensions.Logging; using PrecastConcretePlantBusinessLogic.BusinessLogics; using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantContracts.StoragesContracts; -using PrecastConcretePlantListImplement.Implements; +using PrecastConcretePlantFileImplement.Implements; using PrecastConcretePlantView; using System; using System.Drawing; @@ -40,10 +40,12 @@ namespace PrecastConcretePlant services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); + + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -55,6 +57,7 @@ namespace PrecastConcretePlant services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } - } + } } \ No newline at end of file