diff --git a/Typography/ImplementationExtensions/TypographyBusinessLogic.dll b/Typography/ImplementationExtensions/TypographyBusinessLogic.dll new file mode 100644 index 0000000..d1d4e48 Binary files /dev/null and b/Typography/ImplementationExtensions/TypographyBusinessLogic.dll differ diff --git a/Typography/ImplementationExtensions/TypographyContracts.dll b/Typography/ImplementationExtensions/TypographyContracts.dll new file mode 100644 index 0000000..87eb51a Binary files /dev/null and b/Typography/ImplementationExtensions/TypographyContracts.dll differ diff --git a/Typography/ImplementationExtensions/TypographyDataModels.dll b/Typography/ImplementationExtensions/TypographyDataModels.dll new file mode 100644 index 0000000..1cc62ae Binary files /dev/null and b/Typography/ImplementationExtensions/TypographyDataModels.dll differ diff --git a/Typography/ImplementationExtensions/TypographyFileImplement.dll b/Typography/ImplementationExtensions/TypographyFileImplement.dll new file mode 100644 index 0000000..44c5d56 Binary files /dev/null and b/Typography/ImplementationExtensions/TypographyFileImplement.dll differ diff --git a/Typography/ImplementationExtensions/TypographyListImplement.dll b/Typography/ImplementationExtensions/TypographyListImplement.dll new file mode 100644 index 0000000..00845ce Binary files /dev/null and b/Typography/ImplementationExtensions/TypographyListImplement.dll differ diff --git a/Typography/Typography.sln b/Typography/Typography.sln index 7d6ed57..e90331c 100644 --- a/Typography/Typography.sln +++ b/Typography/Typography.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyBusinessLogic", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyDataModels", "TypographyDataModels\TypographyDataModels.csproj", "{75576C57-02E9-4D1D-9A02-D39C1EBE992D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypographyFileImplement", "TypographyFileImplement\TypographyFileImplement.csproj", "{C6E23C8E-9FCD-40B9-B21E-F64D8BDDA9C1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {75576C57-02E9-4D1D-9A02-D39C1EBE992D}.Debug|Any CPU.Build.0 = Debug|Any CPU {75576C57-02E9-4D1D-9A02-D39C1EBE992D}.Release|Any CPU.ActiveCfg = Release|Any CPU {75576C57-02E9-4D1D-9A02-D39C1EBE992D}.Release|Any CPU.Build.0 = Release|Any CPU + {C6E23C8E-9FCD-40B9-B21E-F64D8BDDA9C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C6E23C8E-9FCD-40B9-B21E-F64D8BDDA9C1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C6E23C8E-9FCD-40B9-B21E-F64D8BDDA9C1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C6E23C8E-9FCD-40B9-B21E-F64D8BDDA9C1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Typography/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs b/Typography/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs index fca1b7a..55f5f3e 100644 --- a/Typography/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/Typography/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs @@ -1,10 +1,10 @@ -using TypographyContracts.BindingModels; +using TypographyDataModels.Enums; +using TypographyContracts.BindingModels; using TypographyContracts.BusinessLogicsContracts; using TypographyContracts.SearchModels; using TypographyContracts.StoragesContracts; using TypographyContracts.ViewModels; using Microsoft.Extensions.Logging; -using TypographyDataModels.Enums; namespace TypographyBusinessLogic.BusinessLogics { @@ -12,11 +12,18 @@ namespace TypographyBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IPrintedStorage _printedStorage; + private readonly IShopStorage _shopStorage; + private readonly IShopLogic _shopLogic; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IPrintedStorage printedStorage, + IShopStorage shopStorage, IShopLogic shopLogic) { _logger = logger; _orderStorage = orderStorage; + _printedStorage = printedStorage; + _shopStorage = shopStorage; + _shopLogic = shopLogic; } public List? ReadList(OrderSearchModel? model) @@ -97,6 +104,21 @@ namespace TypographyBusinessLogic.BusinessLogics return false; } + if (newStatus == OrderStatus.Готов) + { + var supplyPrinted = _printedStorage.GetElement(new PrintedSearchModel { Id = orderView.PrintedId }); + if (supplyPrinted == null) + { + _logger.LogWarning("Printed not found in order"); + return false; + } + if(!SypplyFromOrder(supplyPrinted, orderView.Count)) + { + _logger.LogWarning("Supply of printeds to shops failed"); + return false; + } + } + model.Status = newStatus; if (newStatus == OrderStatus.Выдан) { @@ -110,5 +132,50 @@ namespace TypographyBusinessLogic.BusinessLogics } return true; } + + private bool SypplyFromOrder (PrintedViewModel model, int amount) + { + if(_shopStorage.GetFullList() + .Sum(x => x.MaxNumberPrinteds - x.ShopPrinteds.Sum(y => y.Value.Item2) < 0 ? 0 : x.MaxNumberPrinteds - x.ShopPrinteds.Sum(y => y.Value.Item2)) < amount) + //Тернарное выражение не учитывает переполненные обычными поставками магазины (т. к. это не отражается на других) + { + _logger.LogWarning("Insufficient capacity to accept an order"); + return false; + } + + foreach (var shop in _shopStorage.GetFullList()) + { + int freeSpace = shop.MaxNumberPrinteds - shop.ShopPrinteds.Sum(x => x.Value.Item2); + if (freeSpace < 0) + { + continue; + } + + if (freeSpace > amount) + { + if(!_shopLogic.SupplyPrinteds(new ShopSearchModel { Id = shop.Id}, model, amount)) + { + _logger.LogWarning("Shop partial fill failed"); + return false; + } + amount = 0; + } + if (freeSpace < amount) + { + if (!_shopLogic.SupplyPrinteds(new ShopSearchModel { Id = shop.Id }, model, freeSpace)) + { + _logger.LogWarning("Shop max fill failed"); + return false; + } + amount -= freeSpace; + } + + if (amount <= 0) + { + return true; + } + } + return true; + } } -} +} \ No newline at end of file diff --git a/Typography/TypographyBusinessLogic/BusinessLogics/ShopLogic.cs b/Typography/TypographyBusinessLogic/BusinessLogics/ShopLogic.cs index a42e032..27b163e 100644 --- a/Typography/TypographyBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/Typography/TypographyBusinessLogic/BusinessLogics/ShopLogic.cs @@ -9,6 +9,7 @@ using TypographyContracts.BusinessLogicsContracts; using TypographyContracts.SearchModels; using TypographyContracts.StoragesContracts; using TypographyContracts.ViewModels; +using TypographyDataModels.Models; namespace TypographyBusinessLogic.BusinessLogics { @@ -87,8 +88,8 @@ namespace TypographyBusinessLogic.BusinessLogics return true; } - public bool SupplyPrinteds(ShopSearchModel shop, PrintedBindingModel printed, int amount) - { + public bool SupplyPrinteds(ShopSearchModel shop, IPrintedModel printed, int amount) + { if (shop == null) { throw new ArgumentNullException(nameof(shop)); @@ -125,7 +126,8 @@ namespace TypographyBusinessLogic.BusinessLogics ShopName = shopView.ShopName, Address = shopView.Address, OpeningDate = shopView.OpeningDate, - ShopPrinteds = shopView.ShopPrinteds + MaxNumberPrinteds = shopView.MaxNumberPrinteds, + ShopPrinteds = shopView.ShopPrinteds }) == null) { _logger.LogWarning("SupplyPrinteds. Update operation failed"); @@ -133,8 +135,12 @@ namespace TypographyBusinessLogic.BusinessLogics } return true; } + public bool SellPrinteds(PrintedBindingModel model, int amount) + { + return _shopStorage.SellPrinteds(model, amount); + } - private void CheckModel(ShopBindingModel model, bool withParams = true) + private void CheckModel(ShopBindingModel model, bool withParams = true) { if (model == null) { diff --git a/Typography/TypographyContracts/BindingModels/ShopBindingModel .cs b/Typography/TypographyContracts/BindingModels/ShopBindingModel .cs index aa6a644..aa31899 100644 --- a/Typography/TypographyContracts/BindingModels/ShopBindingModel .cs +++ b/Typography/TypographyContracts/BindingModels/ShopBindingModel .cs @@ -16,7 +16,8 @@ namespace TypographyContracts.BindingModels public string Address { get; set; } = string.Empty; public DateTime OpeningDate { get; set; } = DateTime.Now; + public int MaxNumberPrinteds { get; set; } - public Dictionary ShopPrinteds { get; set; } = new(); + public Dictionary ShopPrinteds { get; set; } = new(); } } diff --git a/Typography/TypographyContracts/BusinessLogicsContracts/IShopLogic.cs b/Typography/TypographyContracts/BusinessLogicsContracts/IShopLogic.cs index 56e0aa0..527d38b 100644 --- a/Typography/TypographyContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/Typography/TypographyContracts/BusinessLogicsContracts/IShopLogic.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using TypographyContracts.BindingModels; using TypographyContracts.SearchModels; using TypographyContracts.ViewModels; +using TypographyDataModels.Models; namespace TypographyContracts.BusinessLogicsContracts { @@ -16,6 +17,7 @@ namespace TypographyContracts.BusinessLogicsContracts bool Create(ShopBindingModel model); bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); - bool SupplyPrinteds(ShopSearchModel shop, PrintedBindingModel printed, int amount); - } + bool SupplyPrinteds(ShopSearchModel shop, IPrintedModel printed, int amount); + bool SellPrinteds(PrintedBindingModel model, int amount); + } } diff --git a/Typography/TypographyContracts/StoragesContracts/IShopStorage.cs b/Typography/TypographyContracts/StoragesContracts/IShopStorage.cs index 9556633..ba4ef6e 100644 --- a/Typography/TypographyContracts/StoragesContracts/IShopStorage.cs +++ b/Typography/TypographyContracts/StoragesContracts/IShopStorage.cs @@ -12,5 +12,7 @@ namespace TypographyContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); - } + bool SellPrinteds(PrintedBindingModel model, int amount); + + } } diff --git a/Typography/TypographyContracts/ViewModels/ShopViewModel.cs b/Typography/TypographyContracts/ViewModels/ShopViewModel.cs index 8099d05..eeebb10 100644 --- a/Typography/TypographyContracts/ViewModels/ShopViewModel.cs +++ b/Typography/TypographyContracts/ViewModels/ShopViewModel.cs @@ -21,6 +21,9 @@ namespace TypographyContracts.ViewModels [DisplayName("Дата открытия")] public DateTime OpeningDate { get; set; } = DateTime.Now; - public Dictionary ShopPrinteds { get; set; } = new(); + [DisplayName("Вместимость")] + public int MaxNumberPrinteds { get; set; } + + public Dictionary ShopPrinteds { get; set; } = new(); } } diff --git a/Typography/TypographyDataModels/Models/IShopModel.cs b/Typography/TypographyDataModels/Models/IShopModel.cs index 50df113..507c0d4 100644 --- a/Typography/TypographyDataModels/Models/IShopModel.cs +++ b/Typography/TypographyDataModels/Models/IShopModel.cs @@ -11,6 +11,7 @@ namespace TypographyDataModels.Models string ShopName { get; } string Address { get; } DateTime OpeningDate { get; } - Dictionary ShopPrinteds { get; } + int MaxNumberPrinteds { get; } + Dictionary ShopPrinteds { get; } } } diff --git a/Typography/TypographyFileImplement/DataFileSingleton.cs b/Typography/TypographyFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..152dc9f --- /dev/null +++ b/Typography/TypographyFileImplement/DataFileSingleton.cs @@ -0,0 +1,62 @@ +using TypographyFileImplement.Models; +using System.Xml.Linq; + +namespace TypographyFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string PrintedFileName = "Printed.xml"; + private readonly string ShopFileName = "Shop.xml"; + + public List Components { get; private set; } + public List Orders { get; private set; } + public List Printeds { 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 SavePrinteds() => SaveData(Printeds, PrintedFileName, "Printeds", 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)!)!; + Printeds = LoadData(PrintedFileName, "Product", x => Printed.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/Typography/TypographyFileImplement/Implements/ComponentStorage.cs b/Typography/TypographyFileImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..ea0cbfe --- /dev/null +++ b/Typography/TypographyFileImplement/Implements/ComponentStorage.cs @@ -0,0 +1,85 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using TypographyFileImplement.Models; + +namespace TypographyFileImplement.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/Typography/TypographyFileImplement/Implements/OrderStorage.cs b/Typography/TypographyFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..de16f04 --- /dev/null +++ b/Typography/TypographyFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,94 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using TypographyFileImplement.Models; + +namespace TypographyFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Orders + .Select(x => DefinePrintedName(x.GetViewModel)) + .ToList(); + } + + private OrderViewModel DefinePrintedName(OrderViewModel model) + { + string? printedName = source.Printeds.FirstOrDefault(x => model.PrintedId == x.Id)?.PrintedName; + if (printedName != null) + { + model.PrintedName = printedName; + } + return model; + } + + public List GetFilteredList(OrderSearchModel model) + { + if (model.Id == null) + { + return new(); + } + return source.Orders + .Where(x => x.Id == model.Id) + .Select(x => DefinePrintedName(x.GetViewModel)) + .ToList(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return DefinePrintedName(source.Orders + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return DefinePrintedName(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 DefinePrintedName(order.GetViewModel); + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Orders.Remove(element); + source.SaveOrders(); + return DefinePrintedName(element.GetViewModel); + } + return null; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Implements/PrintedStorage.cs b/Typography/TypographyFileImplement/Implements/PrintedStorage.cs new file mode 100644 index 0000000..6b69661 --- /dev/null +++ b/Typography/TypographyFileImplement/Implements/PrintedStorage.cs @@ -0,0 +1,85 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using TypographyFileImplement.Models; + +namespace TypographyFileImplement.Implements +{ + public class PrintedStorage : IPrintedStorage + { + private readonly DataFileSingleton source; + + public PrintedStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Printeds + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(PrintedSearchModel model) + { + if (string.IsNullOrEmpty(model.PrintedName)) + { + return new(); + } + return source.Printeds + .Where(x => x.PrintedName.Contains(model.PrintedName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public PrintedViewModel? GetElement(PrintedSearchModel model) + { + if (string.IsNullOrEmpty(model.PrintedName) && !model.Id.HasValue) + { + return null; + } + return source.Printeds + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.PrintedName) && x.PrintedName == model.PrintedName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public PrintedViewModel? Insert(PrintedBindingModel model) + { + model.Id = source.Printeds.Count > 0 ? source.Printeds.Max(x => x.Id) + 1 : 1; + var newPrinted = Printed.Create(model); + if (newPrinted == null) + { + return null; + } + source.Printeds.Add(newPrinted); + source.SavePrinteds(); + return newPrinted.GetViewModel; + } + + public PrintedViewModel? Update(PrintedBindingModel model) + { + var printed = source.Printeds.FirstOrDefault(x => x.Id == model.Id); + if (printed == null) + { + return null; + } + printed.Update(model); + source.SavePrinteds(); + return printed.GetViewModel; + } + + public PrintedViewModel? Delete(PrintedBindingModel model) + { + var element = source.Printeds.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Printeds.Remove(element); + source.SavePrinteds(); + return element.GetViewModel; + } + return null; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Implements/ShopStorage.cs b/Typography/TypographyFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..3352eb9 --- /dev/null +++ b/Typography/TypographyFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,134 @@ +using System.Linq; +using System.Net; +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using TypographyFileImplement.Models; + +namespace TypographyFileImplement.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 element = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Shops.Remove(element); + source.SaveShops(); + return element.GetViewModel; + } + return null; + } + + public bool SellPrinteds(PrintedBindingModel model, int amount) + { + var sellPrinted = source.Printeds.FirstOrDefault(x => x.Id == model.Id); + if (sellPrinted == null) + { + return false; + } + + if (source.Shops.SelectMany(x => x.ShopPrinteds.Where(y => y.Key == sellPrinted.Id)).Sum(x => x.Value.Item2) < amount) + { + return false; + } + + foreach(var shop in source.Shops) + { + var shopPrinteds = shop.ShopPrinteds; + + foreach(var printed in shopPrinteds.Where(x => x.Key == sellPrinted.Id)) + { + int minAmount = amount > printed.Value.Item2 ? printed.Value.Item2 : amount; + shopPrinteds[printed.Value.Item1.Id] = (printed.Value.Item1, printed.Value.Item2 - minAmount); + + amount -= minAmount; + if (amount == 0) + { + break; + } + } + + Update(new ShopBindingModel + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + OpeningDate = shop.OpeningDate, + MaxNumberPrinteds = shop.MaxNumberPrinteds, + ShopPrinteds = shopPrinteds + }); + + if (amount == 0) + { + break; + } + } + return true; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Models/Component.cs b/Typography/TypographyFileImplement/Models/Component.cs new file mode 100644 index 0000000..5b8d4dc --- /dev/null +++ b/Typography/TypographyFileImplement/Models/Component.cs @@ -0,0 +1,64 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; +using System.Xml.Linq; + +namespace TypographyFileImplement.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/Typography/TypographyFileImplement/Models/Order.cs b/Typography/TypographyFileImplement/Models/Order.cs new file mode 100644 index 0000000..5f9a36e --- /dev/null +++ b/Typography/TypographyFileImplement/Models/Order.cs @@ -0,0 +1,86 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; +using System.Xml.Linq; +using TypographyDataModels.Enums; + +namespace TypographyFileImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int PrintedId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + PrintedId = model.PrintedId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + PrintedId = Convert.ToInt32(element.Element("PrintedId")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = String.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : + Convert.ToDateTime(element.Element("DateImplement")!.Value) + }; + } + + public void Update(OrderBindingModel model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + PrintedId = PrintedId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("PrintedId", PrintedId), + new XElement("Count", Count), + 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/Typography/TypographyFileImplement/Models/Printed.cs b/Typography/TypographyFileImplement/Models/Printed.cs new file mode 100644 index 0000000..cab067a --- /dev/null +++ b/Typography/TypographyFileImplement/Models/Printed.cs @@ -0,0 +1,93 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; +using System.Xml.Linq; + +namespace TypographyFileImplement.Models +{ + public class Printed : IPrintedModel + { + public int Id { get; private set; } + public string PrintedName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + + private Dictionary? _productComponents = null; + + public Dictionary PrintedComponents + { + get + { + if (_productComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _productComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,y.Value)); + } + return _productComponents; + } + } + + public static Printed? Create(PrintedBindingModel model) + { + if (model == null) + { + return null; + } + return new Printed() + { + Id = model.Id, + PrintedName = model.PrintedName, + Price = model.Price, + Components = model.PrintedComponents.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Printed? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Printed() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + PrintedName = element.Element("ProductName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = element.Element("ProductComponents")!.Elements("ProductComponent").ToDictionary(x => + Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(PrintedBindingModel model) + { + if (model == null) + { + return; + } + PrintedName = model.PrintedName; + Price = model.Price; + Components = model.PrintedComponents.ToDictionary(x => x.Key, x =>x.Value.Item2); + _productComponents = null; + } + + public PrintedViewModel GetViewModel => new() + { + Id = Id, + PrintedName = PrintedName, + Price = Price, + PrintedComponents = PrintedComponents + }; + + public XElement GetXElement => new("Product", + new XAttribute("Id", Id), + new XElement("ProductName", PrintedName), + new XElement("Price", Price.ToString()), + new XElement("ProductComponents", Components.Select(x => + new XElement("ProductComponent", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/Models/Shop.cs b/Typography/TypographyFileImplement/Models/Shop.cs new file mode 100644 index 0000000..78cb2a0 --- /dev/null +++ b/Typography/TypographyFileImplement/Models/Shop.cs @@ -0,0 +1,111 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; +using System.Xml.Linq; +using System.Diagnostics; + +namespace TypographyFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime OpeningDate { get; private set; } = DateTime.Now; + + public int MaxNumberPrinteds { get; private set; } + + public Dictionary Printeds { get; private set; } = new(); + + private Dictionary? _shopPrinteds = null; + + public Dictionary ShopPrinteds + { + get + { + if (_shopPrinteds == null) + { + var source = DataFileSingleton.GetInstance(); + _shopPrinteds = Printeds.ToDictionary(x => x.Key, y => + ((source.Printeds.FirstOrDefault(z => z.Id == y.Key) as IPrintedModel)!, y.Value)); + } + return _shopPrinteds; + } + } + + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + OpeningDate = model.OpeningDate, + MaxNumberPrinteds = model.MaxNumberPrinteds, + Printeds = model.ShopPrinteds.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value), + MaxNumberPrinteds = Convert.ToInt32(element.Element("MaxNumberPrinteds")!.Value), + Printeds = element.Element("ShopPrinteds")!.Elements("ShopPrinted").ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(ShopBindingModel model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + OpeningDate = model.OpeningDate; + MaxNumberPrinteds = model.MaxNumberPrinteds; + Printeds = model.ShopPrinteds.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopPrinteds = null; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + OpeningDate = OpeningDate, + MaxNumberPrinteds = MaxNumberPrinteds, + ShopPrinteds = ShopPrinteds + }; + + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("OpeningDate", OpeningDate.ToString()), + new XElement("MaxNumberPrinteds", MaxNumberPrinteds), + new XElement("ShopPrinteds", Printeds.Select(x => + new XElement("ShopPrinted", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} \ No newline at end of file diff --git a/Typography/TypographyFileImplement/TypographyFileImplement.csproj b/Typography/TypographyFileImplement/TypographyFileImplement.csproj new file mode 100644 index 0000000..db73c6b --- /dev/null +++ b/Typography/TypographyFileImplement/TypographyFileImplement.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Typography/TypographyListImplement/Implements/ShopStorage .cs b/Typography/TypographyListImplement/Implements/ShopStorage .cs index 7ac6108..92fec7e 100644 --- a/Typography/TypographyListImplement/Implements/ShopStorage .cs +++ b/Typography/TypographyListImplement/Implements/ShopStorage .cs @@ -105,5 +105,9 @@ namespace TypographyListImplement.Implements } return null; } - } + public bool SellPrinteds(PrintedBindingModel model, int amount) + { + throw new NotImplementedException(); + } + } } diff --git a/Typography/TypographyListImplement/Models/Shop.cs b/Typography/TypographyListImplement/Models/Shop.cs index a62caf8..8e17579 100644 --- a/Typography/TypographyListImplement/Models/Shop.cs +++ b/Typography/TypographyListImplement/Models/Shop.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using TypographyContracts.BindingModels; @@ -15,7 +16,9 @@ namespace TypographyListImplement.Models public string ShopName { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty; public DateTime OpeningDate { get; private set; } = DateTime.Now; - public Dictionary ShopPrinteds { get; private set; } = new(); + public int MaxNumberPrinteds { get; private set; } + public Dictionary ShopPrinteds { get; private set; } = new(); + public static Shop? Create(ShopBindingModel? model) { @@ -29,7 +32,8 @@ namespace TypographyListImplement.Models ShopName = model.ShopName, Address = model.Address, OpeningDate = model.OpeningDate, - ShopPrinteds = new() + MaxNumberPrinteds = model.MaxNumberPrinteds, + ShopPrinteds = new() }; } public void Update(ShopBindingModel? model) @@ -41,7 +45,8 @@ namespace TypographyListImplement.Models ShopName = model.ShopName; Address = model.Address; OpeningDate = model.OpeningDate; - ShopPrinteds = model.ShopPrinteds; + MaxNumberPrinteds = model.MaxNumberPrinteds; + ShopPrinteds = model.ShopPrinteds; } public ShopViewModel GetViewModel => new() { @@ -49,6 +54,7 @@ namespace TypographyListImplement.Models ShopName = ShopName, Address = Address, OpeningDate = OpeningDate, + MaxNumberPrinteds = MaxNumberPrinteds, ShopPrinteds = ShopPrinteds }; } diff --git a/Typography/TypographyView/FormMain.Designer.cs b/Typography/TypographyView/FormMain.Designer.cs index bc93e30..7745d21 100644 --- a/Typography/TypographyView/FormMain.Designer.cs +++ b/Typography/TypographyView/FormMain.Designer.cs @@ -20,173 +20,181 @@ base.Dispose(disposing); } - #region Windows Form Designer generated code + #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() - { - buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonIssuedOrder = new Button(); - dataGridViewOrders = new DataGridView(); - buttonRef = new Button(); - buttonOrderReady = new Button(); - menuStrip = new MenuStrip(); - directoriesToolStripMenuItem = new ToolStripMenuItem(); - componentsToolStripMenuItem = new ToolStripMenuItem(); - printedsToolStripMenuItem = new ToolStripMenuItem(); - shopsToolStripMenuItem = new ToolStripMenuItem(); - supplyToolStripMenuItem = new ToolStripMenuItem(); - ((System.ComponentModel.ISupportInitialize)dataGridViewOrders).BeginInit(); - menuStrip.SuspendLayout(); - SuspendLayout(); - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(1224, 70); - buttonCreateOrder.Margin = new Padding(5, 5, 5, 5); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(330, 46); - buttonCreateOrder.TabIndex = 0; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += ButtonCreateOrder_Click; - // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Location = new Point(1224, 162); - buttonTakeOrderInWork.Margin = new Padding(5, 5, 5, 5); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(330, 46); - buttonTakeOrderInWork.TabIndex = 1; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // - // buttonIssuedOrder - // - buttonIssuedOrder.Location = new Point(1224, 379); - buttonIssuedOrder.Margin = new Padding(5, 5, 5, 5); - buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(330, 46); - buttonIssuedOrder.TabIndex = 2; - buttonIssuedOrder.Text = "Заказ выдан"; - buttonIssuedOrder.UseVisualStyleBackColor = true; - buttonIssuedOrder.Click += ButtonIssuedOrder_Click; - // - // dataGridViewOrders - // - dataGridViewOrders.BackgroundColor = SystemColors.ControlLightLight; - dataGridViewOrders.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewOrders.Location = new Point(0, 50); - dataGridViewOrders.Margin = new Padding(5, 5, 5, 5); - dataGridViewOrders.Name = "dataGridViewOrders"; - dataGridViewOrders.RowHeadersVisible = false; - dataGridViewOrders.RowHeadersWidth = 51; - dataGridViewOrders.RowTemplate.Height = 29; - dataGridViewOrders.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridViewOrders.Size = new Size(1156, 506); - dataGridViewOrders.TabIndex = 3; - // - // buttonRef - // - buttonRef.Location = new Point(1224, 487); - buttonRef.Margin = new Padding(5, 5, 5, 5); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(330, 46); - buttonRef.TabIndex = 4; - buttonRef.Text = "Обновить список"; - buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += ButtonRef_Click; - // - // buttonOrderReady - // - buttonOrderReady.Location = new Point(1224, 265); - buttonOrderReady.Margin = new Padding(5, 5, 5, 5); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(330, 46); - buttonOrderReady.TabIndex = 5; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += ButtonOrderReady_Click; - // - // menuStrip - // - menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { directoriesToolStripMenuItem, supplyToolStripMenuItem }); - menuStrip.Location = new Point(0, 0); - menuStrip.Name = "menuStrip"; - menuStrip.Padding = new Padding(10, 3, 0, 3); - menuStrip.Size = new Size(1580, 42); - menuStrip.TabIndex = 6; - menuStrip.Text = "menuStrip1"; - // - // directoriesToolStripMenuItem - // - directoriesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, printedsToolStripMenuItem, shopsToolStripMenuItem }); - directoriesToolStripMenuItem.Name = "directoriesToolStripMenuItem"; - directoriesToolStripMenuItem.Size = new Size(184, 36); - directoriesToolStripMenuItem.Text = "Справочники"; - // - // componentsToolStripMenuItem - // - componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; - componentsToolStripMenuItem.Size = new Size(377, 44); - componentsToolStripMenuItem.Text = "Компоненты"; - componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; - // - // printedsToolStripMenuItem - // - printedsToolStripMenuItem.Name = "printedsToolStripMenuItem"; - printedsToolStripMenuItem.Size = new Size(377, 44); - printedsToolStripMenuItem.Text = "Печатная продукция"; - printedsToolStripMenuItem.Click += PrintedsToolStripMenuItem_Click; - // - // shopsToolStripMenuItem - // - shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; - shopsToolStripMenuItem.Size = new Size(377, 44); - shopsToolStripMenuItem.Text = "Магазины"; - shopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; - // - // supplyToolStripMenuItem - // - supplyToolStripMenuItem.Name = "supplyToolStripMenuItem"; - supplyToolStripMenuItem.Size = new Size(282, 36); - supplyToolStripMenuItem.Text = "Пополнение магазина"; - supplyToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(13F, 32F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1580, 605); - Controls.Add(buttonOrderReady); - Controls.Add(buttonRef); - Controls.Add(dataGridViewOrders); - Controls.Add(buttonIssuedOrder); - Controls.Add(buttonTakeOrderInWork); - Controls.Add(buttonCreateOrder); - Controls.Add(menuStrip); - MainMenuStrip = menuStrip; - Margin = new Padding(5, 5, 5, 5); - Name = "FormMain"; - StartPosition = FormStartPosition.CenterScreen; - Text = "Типография"; - Load += FormMain_Load; - ((System.ComponentModel.ISupportInitialize)dataGridViewOrders).EndInit(); - menuStrip.ResumeLayout(false); - menuStrip.PerformLayout(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonIssuedOrder = new Button(); + dataGridViewOrders = new DataGridView(); + buttonRef = new Button(); + buttonOrderReady = new Button(); + menuStrip = new MenuStrip(); + directoriesToolStripMenuItem = new ToolStripMenuItem(); + componentsToolStripMenuItem = new ToolStripMenuItem(); + printedsToolStripMenuItem = new ToolStripMenuItem(); + shopsToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + supplyToolStripMenuItem = new ToolStripMenuItem(); + saleToolStripMenuItem = new ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)dataGridViewOrders).BeginInit(); + menuStrip.SuspendLayout(); + SuspendLayout(); + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(1100, 31); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(203, 29); + buttonCreateOrder.TabIndex = 0; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(1100, 66); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(203, 29); + buttonTakeOrderInWork.TabIndex = 1; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(1100, 136); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(203, 29); + buttonIssuedOrder.TabIndex = 2; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // dataGridViewOrders + // + dataGridViewOrders.BackgroundColor = SystemColors.ControlLightLight; + dataGridViewOrders.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewOrders.Location = new Point(0, 31); + dataGridViewOrders.Name = "dataGridViewOrders"; + dataGridViewOrders.RowHeadersVisible = false; + dataGridViewOrders.RowHeadersWidth = 51; + dataGridViewOrders.RowTemplate.Height = 29; + dataGridViewOrders.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewOrders.Size = new Size(1078, 402); + dataGridViewOrders.TabIndex = 3; + // + // buttonRef + // + buttonRef.Location = new Point(1100, 171); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(203, 29); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(1100, 101); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(203, 29); + buttonOrderReady.TabIndex = 5; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { directoriesToolStripMenuItem, магазиныToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1315, 28); + menuStrip.TabIndex = 6; + menuStrip.Text = "menuStrip1"; + // + // directoriesToolStripMenuItem + // + directoriesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, printedsToolStripMenuItem, shopsToolStripMenuItem }); + directoriesToolStripMenuItem.Name = "directoriesToolStripMenuItem"; + directoriesToolStripMenuItem.Size = new Size(117, 24); + directoriesToolStripMenuItem.Text = "Справочники"; + // + // componentsToolStripMenuItem + // + componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + componentsToolStripMenuItem.Size = new Size(237, 26); + componentsToolStripMenuItem.Text = "Компоненты"; + componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; + // + // printedsToolStripMenuItem + // + printedsToolStripMenuItem.Name = "printedsToolStripMenuItem"; + printedsToolStripMenuItem.Size = new Size(237, 26); + printedsToolStripMenuItem.Text = "Печатная продукция"; + printedsToolStripMenuItem.Click += PrintedsToolStripMenuItem_Click; + // + // shopsToolStripMenuItem + // + shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; + shopsToolStripMenuItem.Size = new Size(237, 26); + shopsToolStripMenuItem.Text = "Магазины"; + shopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { supplyToolStripMenuItem, saleToolStripMenuItem }); + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(94, 24); + магазиныToolStripMenuItem.Text = "Магазины"; + // + // supplyToolStripMenuItem + // + supplyToolStripMenuItem.Name = "supplyToolStripMenuItem"; + supplyToolStripMenuItem.Size = new Size(224, 26); + supplyToolStripMenuItem.Text = "Пополнение"; + supplyToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; + // + // saleToolStripMenuItem + // + saleToolStripMenuItem.Name = "saleToolStripMenuItem"; + saleToolStripMenuItem.Size = new Size(224, 26); + saleToolStripMenuItem.Text = "Продажа"; + saleToolStripMenuItem.Click += SaleToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1315, 433); + Controls.Add(buttonOrderReady); + Controls.Add(buttonRef); + Controls.Add(dataGridViewOrders); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Типография"; + Load += FormMain_Load; + ((System.ComponentModel.ISupportInitialize)dataGridViewOrders).EndInit(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private Button buttonCreateOrder; + private Button buttonCreateOrder; private Button buttonTakeOrderInWork; private Button buttonIssuedOrder; private DataGridView dataGridViewOrders; @@ -197,6 +205,8 @@ private ToolStripMenuItem componentsToolStripMenuItem; private ToolStripMenuItem printedsToolStripMenuItem; private ToolStripMenuItem shopsToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; private ToolStripMenuItem supplyToolStripMenuItem; + private ToolStripMenuItem saleToolStripMenuItem; } } \ No newline at end of file diff --git a/Typography/TypographyView/FormMain.cs b/Typography/TypographyView/FormMain.cs index ac8b728..823eb53 100644 --- a/Typography/TypographyView/FormMain.cs +++ b/Typography/TypographyView/FormMain.cs @@ -78,6 +78,15 @@ namespace TypographyView } } + private void SaleToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSale)); + if (service is FormSale form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); diff --git a/Typography/TypographyView/FormMain.resx b/Typography/TypographyView/FormMain.resx index 6c82d08..81a9e3d 100644 --- a/Typography/TypographyView/FormMain.resx +++ b/Typography/TypographyView/FormMain.resx @@ -1,64 +1,4 @@ - - - + diff --git a/Typography/TypographyView/FormSale.Designer.cs b/Typography/TypographyView/FormSale.Designer.cs new file mode 100644 index 0000000..4c5dcd1 --- /dev/null +++ b/Typography/TypographyView/FormSale.Designer.cs @@ -0,0 +1,120 @@ +namespace TypographyView +{ + partial class FormSale + { + /// + /// 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() + { + buttonSave = new Button(); + buttonCancel = new Button(); + comboBoxPrinted = new ComboBox(); + textBoxAmount = new TextBox(); + labelAmount = new Label(); + labelPrinted = new Label(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Location = new Point(205, 80); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(102, 29); + buttonSave.TabIndex = 0; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(313, 80); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(102, 29); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // comboBoxPrinted + // + comboBoxPrinted.FormattingEnabled = true; + comboBoxPrinted.Location = new Point(172, 12); + comboBoxPrinted.Name = "comboBoxPrinted"; + comboBoxPrinted.Size = new Size(243, 28); + comboBoxPrinted.TabIndex = 2; + // + // textBoxAmount + // + textBoxAmount.Location = new Point(172, 46); + textBoxAmount.Name = "textBoxAmount"; + textBoxAmount.Size = new Size(243, 27); + textBoxAmount.TabIndex = 3; + // + // labelAmount + // + labelAmount.AutoSize = true; + labelAmount.Location = new Point(12, 49); + labelAmount.Name = "labelAmount"; + labelAmount.Size = new Size(90, 20); + labelAmount.TabIndex = 4; + labelAmount.Text = "Количество"; + // + // labelPrinted + // + labelPrinted.AutoSize = true; + labelPrinted.Location = new Point(12, 15); + labelPrinted.Name = "labelPrinted"; + labelPrinted.Size = new Size(154, 20); + labelPrinted.TabIndex = 5; + labelPrinted.Text = "Печатная продукция"; + // + // FormSale + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(427, 118); + Controls.Add(labelPrinted); + Controls.Add(labelAmount); + Controls.Add(textBoxAmount); + Controls.Add(comboBoxPrinted); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormSale"; + StartPosition = FormStartPosition.CenterParent; + Text = "Продажа"; + Load += FormSale_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxPrinted; + private TextBox textBoxAmount; + private Label labelAmount; + private Label labelPrinted; + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormSale.cs b/Typography/TypographyView/FormSale.cs new file mode 100644 index 0000000..247b19b --- /dev/null +++ b/Typography/TypographyView/FormSale.cs @@ -0,0 +1,79 @@ +using TypographyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; + +namespace TypographyView +{ + public partial class FormSale : Form + { + private readonly ILogger _logger; + private readonly IPrintedLogic _logicP; + private readonly IShopLogic _logicS; + + public FormSale(ILogger logger, IPrintedLogic logicP, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + + private void FormSale_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка печатной продукции для поставки"); + var _listP = _logicP.ReadList(null); + if (_listP != null) + { + comboBoxPrinted.DisplayMember = "PrintedName"; + comboBoxPrinted.ValueMember = "Id"; + comboBoxPrinted.DataSource = _listP; + comboBoxPrinted.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxPrinted.SelectedValue == null) + { + MessageBox.Show("Выберите печатную продукцию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAmount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Создание продажи"); + try + { + var operationResult = _logicS.SellPrinteds( + new PrintedBindingModel() + { + Id = Convert.ToInt32(comboBoxPrinted.SelectedValue), + PrintedName = comboBoxPrinted.Text + }, + Convert.ToInt32(textBoxAmount.Text)); + if (!operationResult) + { + throw new Exception("Ошибка при создании продажи. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания продажи"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/Typography/TypographyView/FormSale.resx b/Typography/TypographyView/FormSale.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Typography/TypographyView/FormSale.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Typography/TypographyView/FormShop.Designer.cs b/Typography/TypographyView/FormShop.Designer.cs index 9b3f2e9..e13022d 100644 --- a/Typography/TypographyView/FormShop.Designer.cs +++ b/Typography/TypographyView/FormShop.Designer.cs @@ -20,198 +20,206 @@ base.Dispose(disposing); } - #region Windows Form Designer generated code + #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() - { - buttonCancel = new Button(); - buttonSave = new Button(); - groupBoxPrinteds = new GroupBox(); - dataGridViewPrinteds = new DataGridView(); - dataGridViewTextBoxColumn1 = new DataGridViewTextBoxColumn(); - ColumnPrintedName = new DataGridViewTextBoxColumn(); - ColumnAmount = new DataGridViewTextBoxColumn(); - buttonRef = new Button(); - labelName = new Label(); - labelAddress = new Label(); - textBoxAddress = new TextBox(); - textBoxName = new TextBox(); - labelDate = new Label(); - dateTimePickerOpening = new DateTimePicker(); - groupBoxPrinteds.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridViewPrinteds).BeginInit(); - SuspendLayout(); - // - // buttonCancel - // - buttonCancel.Location = new Point(1086, 885); - buttonCancel.Margin = new Padding(5, 5, 5, 5); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(166, 46); - buttonCancel.TabIndex = 0; - buttonCancel.Text = "Закрыть"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; - // - // buttonSave - // - buttonSave.Location = new Point(910, 885); - buttonSave.Margin = new Padding(5, 5, 5, 5); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(166, 46); - buttonSave.TabIndex = 1; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; - // - // groupBoxPrinteds - // - groupBoxPrinteds.Controls.Add(dataGridViewPrinteds); - groupBoxPrinteds.Controls.Add(buttonRef); - groupBoxPrinteds.Location = new Point(20, 178); - groupBoxPrinteds.Margin = new Padding(5, 5, 5, 5); - groupBoxPrinteds.Name = "groupBoxPrinteds"; - groupBoxPrinteds.Padding = new Padding(5, 5, 5, 5); - groupBoxPrinteds.Size = new Size(1232, 698); - groupBoxPrinteds.TabIndex = 2; - groupBoxPrinteds.TabStop = false; - groupBoxPrinteds.Text = "Печатная продукция"; - // - // dataGridViewPrinteds - // - dataGridViewPrinteds.BackgroundColor = SystemColors.ControlLightLight; - dataGridViewPrinteds.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewPrinteds.Columns.AddRange(new DataGridViewColumn[] { dataGridViewTextBoxColumn1, ColumnPrintedName, ColumnAmount }); - dataGridViewPrinteds.GridColor = SystemColors.ControlLightLight; - dataGridViewPrinteds.Location = new Point(10, 42); - dataGridViewPrinteds.Margin = new Padding(5, 5, 5, 5); - dataGridViewPrinteds.Name = "dataGridViewPrinteds"; - dataGridViewPrinteds.RowHeadersVisible = false; - dataGridViewPrinteds.RowHeadersWidth = 51; - dataGridViewPrinteds.RowTemplate.Height = 29; - dataGridViewPrinteds.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridViewPrinteds.Size = new Size(1037, 640); - dataGridViewPrinteds.TabIndex = 4; - // - // dataGridViewTextBoxColumn1 - // - dataGridViewTextBoxColumn1.HeaderText = "Id"; - dataGridViewTextBoxColumn1.MinimumWidth = 6; - dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; - dataGridViewTextBoxColumn1.Visible = false; - dataGridViewTextBoxColumn1.Width = 125; - // - // ColumnPrintedName - // - ColumnPrintedName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - ColumnPrintedName.HeaderText = "Печатное изделие"; - ColumnPrintedName.MinimumWidth = 6; - ColumnPrintedName.Name = "ColumnPrintedName"; - // - // ColumnAmount - // - ColumnAmount.HeaderText = "Количество"; - ColumnAmount.MinimumWidth = 6; - ColumnAmount.Name = "ColumnAmount"; - ColumnAmount.Width = 125; - // - // buttonRef - // - buttonRef.Location = new Point(1056, 42); - buttonRef.Margin = new Padding(5, 5, 5, 5); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(166, 46); - buttonRef.TabIndex = 3; - buttonRef.Text = "Обновить"; - buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += ButtonRef_Click; - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(20, 24); - labelName.Margin = new Padding(5, 0, 5, 0); - labelName.Name = "labelName"; - labelName.Size = new Size(120, 32); - labelName.TabIndex = 0; - labelName.Text = "Название"; - // - // labelAddress - // - labelAddress.AutoSize = true; - labelAddress.Location = new Point(20, 77); - labelAddress.Margin = new Padding(5, 0, 5, 0); - labelAddress.Name = "labelAddress"; - labelAddress.Size = new Size(80, 32); - labelAddress.TabIndex = 1; - labelAddress.Text = "Адрес"; - // - // textBoxAddress - // - textBoxAddress.Location = new Point(208, 72); - textBoxAddress.Margin = new Padding(5, 5, 5, 5); - textBoxAddress.Name = "textBoxAddress"; - textBoxAddress.Size = new Size(336, 39); - textBoxAddress.TabIndex = 3; - // - // textBoxName - // - textBoxName.Location = new Point(208, 24); - textBoxName.Margin = new Padding(5, 5, 5, 5); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(336, 39); - textBoxName.TabIndex = 4; - // - // labelDate - // - labelDate.AutoSize = true; - labelDate.Location = new Point(20, 133); - labelDate.Margin = new Padding(5, 0, 5, 0); - labelDate.Name = "labelDate"; - labelDate.Size = new Size(175, 32); - labelDate.TabIndex = 5; - labelDate.Text = "Дата открытия"; - // - // dateTimePickerOpening - // - dateTimePickerOpening.Location = new Point(208, 125); - dateTimePickerOpening.Margin = new Padding(5, 5, 5, 5); - dateTimePickerOpening.Name = "dateTimePickerOpening"; - dateTimePickerOpening.Size = new Size(336, 39); - dateTimePickerOpening.TabIndex = 6; - // - // FormShop - // - AutoScaleDimensions = new SizeF(13F, 32F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1271, 949); - Controls.Add(dateTimePickerOpening); - Controls.Add(labelDate); - Controls.Add(labelName); - Controls.Add(labelAddress); - Controls.Add(textBoxName); - Controls.Add(textBoxAddress); - Controls.Add(groupBoxPrinteds); - Controls.Add(buttonSave); - Controls.Add(buttonCancel); - Margin = new Padding(5, 5, 5, 5); - Name = "FormShop"; - StartPosition = FormStartPosition.CenterParent; - Text = "Магазин"; - Load += FormShop_Load; - groupBoxPrinteds.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)dataGridViewPrinteds).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonCancel = new Button(); + buttonSave = new Button(); + groupBoxPrinteds = new GroupBox(); + dataGridViewPrinteds = new DataGridView(); + dataGridViewTextBoxColumn1 = new DataGridViewTextBoxColumn(); + ColumnPrintedName = new DataGridViewTextBoxColumn(); + ColumnAmount = new DataGridViewTextBoxColumn(); + buttonRef = new Button(); + labelName = new Label(); + labelAddress = new Label(); + textBoxAddress = new TextBox(); + textBoxName = new TextBox(); - #endregion + labelDate = new Label(); + textBoxMaxNumber = new TextBox(); + labelMaxNumber = new Label(); + dateTimePickerOpening = new DateTimePicker(); + groupBoxPrinteds.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewPrinteds).BeginInit(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Location = new Point(668, 586); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(102, 29); + buttonCancel.TabIndex = 0; + buttonCancel.Text = "Закрыть"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(560, 586); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(102, 29); + buttonSave.TabIndex = 1; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // groupBoxPrinteds + // + groupBoxPrinteds.Controls.Add(dataGridViewPrinteds); + groupBoxPrinteds.Controls.Add(buttonRef); + groupBoxPrinteds.Location = new Point(12, 144); + groupBoxPrinteds.Name = "groupBoxPrinteds"; + groupBoxPrinteds.Size = new Size(758, 436); + groupBoxPrinteds.TabIndex = 2; + groupBoxPrinteds.TabStop = false; + groupBoxPrinteds.Text = "Печатная продукция"; + // + // dataGridViewPrinteds + // + dataGridViewPrinteds.BackgroundColor = SystemColors.ControlLightLight; + dataGridViewPrinteds.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewPrinteds.Columns.AddRange(new DataGridViewColumn[] { dataGridViewTextBoxColumn1, ColumnPrintedName, ColumnAmount }); + dataGridViewPrinteds.GridColor = SystemColors.ControlLightLight; + dataGridViewPrinteds.Location = new Point(6, 26); + dataGridViewPrinteds.Name = "dataGridViewPrinteds"; + dataGridViewPrinteds.RowHeadersVisible = false; + dataGridViewPrinteds.RowHeadersWidth = 51; + dataGridViewPrinteds.RowTemplate.Height = 29; + dataGridViewPrinteds.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewPrinteds.Size = new Size(638, 400); + dataGridViewPrinteds.TabIndex = 4; + // + // dataGridViewTextBoxColumn1 + // + dataGridViewTextBoxColumn1.HeaderText = "Id"; + dataGridViewTextBoxColumn1.MinimumWidth = 6; + dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; + dataGridViewTextBoxColumn1.Visible = false; + dataGridViewTextBoxColumn1.Width = 125; + // + // ColumnPrintedName + // + ColumnPrintedName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnPrintedName.HeaderText = "Печатное изделие"; + ColumnPrintedName.MinimumWidth = 6; + ColumnPrintedName.Name = "ColumnPrintedName"; + // + // ColumnAmount + // + ColumnAmount.HeaderText = "Количество"; + ColumnAmount.MinimumWidth = 6; + ColumnAmount.Name = "ColumnAmount"; + ColumnAmount.Width = 125; + // + // buttonRef + // + buttonRef.Location = new Point(650, 26); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(102, 29); + buttonRef.TabIndex = 3; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 15); + labelName.Name = "labelName"; + labelName.Size = new Size(77, 20); + labelName.TabIndex = 0; + labelName.Text = "Название"; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(12, 48); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(51, 20); + labelAddress.TabIndex = 1; + labelAddress.Text = "Адрес"; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(128, 45); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(208, 27); + textBoxAddress.TabIndex = 3; + // + // textBoxName + // + textBoxName.Location = new Point(128, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(208, 27); + textBoxName.TabIndex = 4; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(12, 81); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(110, 20); + labelDate.TabIndex = 5; + labelDate.Text = "Дата открытия"; + // + // textBoxMaxNumber + // + textBoxMaxNumber.Location = new Point(128, 111); + textBoxMaxNumber.Name = "textBoxMaxNumber"; + textBoxMaxNumber.Size = new Size(104, 27); + textBoxMaxNumber.TabIndex = 6; + // + // labelMaxNumber + // + labelMaxNumber.AutoSize = true; + labelMaxNumber.Location = new Point(12, 114); + labelMaxNumber.Name = "labelMaxNumber"; + labelMaxNumber.Size = new Size(100, 20); + labelMaxNumber.TabIndex = 7; + labelMaxNumber.Text = "Вместимость"; + // + // dateTimePickerOpening + // + dateTimePickerOpening.Location = new Point(128, 78); + dateTimePickerOpening.Name = "dateTimePickerOpening"; + dateTimePickerOpening.Size = new Size(208, 27); + dateTimePickerOpening.TabIndex = 8; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(782, 628); + Controls.Add(dateTimePickerOpening); + Controls.Add(labelMaxNumber); + Controls.Add(textBoxMaxNumber); + Controls.Add(labelDate); + Controls.Add(labelName); + Controls.Add(labelAddress); + Controls.Add(textBoxName); + Controls.Add(textBoxAddress); + Controls.Add(groupBoxPrinteds); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Name = "FormShop"; + StartPosition = FormStartPosition.CenterParent; + Text = "Магазин"; + Load += FormShop_Load; + groupBoxPrinteds.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewPrinteds).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - private Button buttonCancel; + #endregion + + private Button buttonCancel; private Button buttonSave; private GroupBox groupBoxPrinteds; private Label labelName; @@ -224,6 +232,8 @@ private DataGridViewTextBoxColumn ColumnPrintedName; private DataGridViewTextBoxColumn ColumnAmount; private Label labelDate; + private TextBox textBoxMaxNumber; + private Label labelMaxNumber; private DateTimePicker dateTimePickerOpening; } } \ No newline at end of file diff --git a/Typography/TypographyView/FormShop.cs b/Typography/TypographyView/FormShop.cs index 992e367..a4a7ff2 100644 --- a/Typography/TypographyView/FormShop.cs +++ b/Typography/TypographyView/FormShop.cs @@ -36,6 +36,7 @@ namespace TypographyView textBoxName.Text = view.ShopName; textBoxAddress.Text = view.Address; dateTimePickerOpening.Value = view.OpeningDate; + textBoxMaxNumber.Text = view.MaxNumberPrinteds.ToString(); _shopPrinteds = view.ShopPrinteds ?? new Dictionary(); LoadData(); } @@ -87,6 +88,11 @@ namespace TypographyView MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (string.IsNullOrEmpty(textBoxMaxNumber.Text)) + { + MessageBox.Show("Заполните вместимость", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Сохранение магазина"); try { @@ -96,6 +102,7 @@ namespace TypographyView ShopName = textBoxName.Text, Address = textBoxAddress.Text, OpeningDate = dateTimePickerOpening.Value.Date, + MaxNumberPrinteds = Convert.ToInt32(textBoxMaxNumber.Text), ShopPrinteds = _shopPrinteds }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); diff --git a/Typography/TypographyView/FormShop.resx b/Typography/TypographyView/FormShop.resx index b92e6b9..0bbad28 100644 --- a/Typography/TypographyView/FormShop.resx +++ b/Typography/TypographyView/FormShop.resx @@ -1,64 +1,4 @@ - - - + @@ -126,13 +66,4 @@ True - - True - - - True - - - True - \ No newline at end of file diff --git a/Typography/TypographyView/Program.cs b/Typography/TypographyView/Program.cs index 33b0b9b..7b7ee3a 100644 --- a/Typography/TypographyView/Program.cs +++ b/Typography/TypographyView/Program.cs @@ -1,17 +1,15 @@ using TypographyBusinessLogic.BusinessLogics; using TypographyContracts.BusinessLogicsContracts; using TypographyContracts.StoragesContracts; -using TypographyListImplement.Implements; +using TypographyFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -using System; namespace TypographyView { internal static class Program { - private static ServiceProvider? _serviceProvider; public static ServiceProvider? ServiceProvider => _serviceProvider; @@ -29,6 +27,7 @@ namespace TypographyView _serviceProvider = services.BuildServiceProvider(); Application.Run(_serviceProvider.GetRequiredService()); } + private static void ConfigureServices(ServiceCollection services) { services.AddLogging(option => @@ -41,21 +40,22 @@ namespace TypographyView 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(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - } + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } } } \ No newline at end of file diff --git a/Typography/TypographyView/TypographyView.csproj b/Typography/TypographyView/TypographyView.csproj index d5e8cf5..bc5359e 100644 --- a/Typography/TypographyView/TypographyView.csproj +++ b/Typography/TypographyView/TypographyView.csproj @@ -12,12 +12,6 @@ - - - Always - - - @@ -26,8 +20,14 @@ - + + + + Always + + + \ No newline at end of file