diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/Component.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/Component.cs new file mode 100644 index 0000000..c3a3d7e --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/Component.cs @@ -0,0 +1,60 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using System.Xml.Linq; + + +namespace SoftwareInstallationFileImplement.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/SoftwareInstallation/SoftWareInstallationFileImplement/ComponentStorage.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/ComponentStorage.cs new file mode 100644 index 0000000..b582fb0 --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/ComponentStorage.cs @@ -0,0 +1,79 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationFileImplement.Models; + +namespace SoftwareInstallationFileImplement.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/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..1303039 --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs @@ -0,0 +1,54 @@ +using SoftwareInstallationFileImplement.Models; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string PackageFileName = "Package.xml"; + private readonly string ShopFileName = "Shop.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Packages { 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 SavePackages() => SaveData(Packages, PackageFileName, "Packages", 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)!)!; + Packages = LoadData(PackageFileName, "Package", x => Package.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); + } + } + } +} diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/Order.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/Order.cs new file mode 100644 index 0000000..ff0d3f7 --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/Order.cs @@ -0,0 +1,96 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Enums; +using SoftwareInstallationDataModels.Models; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int PackageId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } + + public DateTime DateCreate { get; private set; } + + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + PackageId = model.PackageId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + Id = model.Id, + }; + } + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + var dateImplement = element.Element("DateImplement")!.Value; + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value), + PackageId = Convert.ToInt32(element.Element("PackageId")!.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; + } + PackageId = model.PackageId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + Id = model.Id; + } + public OrderViewModel GetViewModel => new() + { + PackageName = DataFileSingleton.GetInstance().Packages.FirstOrDefault(x => x.Id == PackageId)?.PackageName ?? string.Empty, + PackageId = PackageId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + }; + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("PackageId", PackageId), + new XElement("Count", Count), + new XElement("Sum", Sum.ToString()), + new XElement("Status", (int)Status), + new XElement("DateCreate", DateCreate), + new XElement("DateImplement", DateImplement) + ); + } +} diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/OrderStorage.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/OrderStorage.cs new file mode 100644 index 0000000..952b672 --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/OrderStorage.cs @@ -0,0 +1,76 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationFileImplement.Models; + +namespace SoftwareInstallationFileImplement +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton _source; + public OrderStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + 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 element.GetViewModel; + } + return null; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return _source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = GetElement(model); + return result != null ? new() { result } : new(); + } + + public List GetFullList() + { + return _source.Orders + .Select(x => x.GetViewModel) + .ToList(); + } + + 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 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 order.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/Package.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/Package.cs new file mode 100644 index 0000000..4df34d5 --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/Package.cs @@ -0,0 +1,86 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement.Models +{ + public class Package : IPackageModel + { + public int Id { get; private set; } + public string PackageName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _PackageComponents = null; + public Dictionary PackageComponents + { + get + { + if (_PackageComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _PackageComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, + y.Value)); + } + return _PackageComponents; + } + } + public static Package? Create(PackageBindingModel model) + { + if (model == null) + { + return null; + } + return new Package() + { + Id = model.Id, + PackageName = model.PackageName, + Price = model.Price, + Components = model.PackageComponents.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Package? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Package() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + PackageName = element.Element("PackageName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = element.Element("PackageComponents")!.Elements("PackageComponent").ToDictionary(x => + Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(PackageBindingModel model) + { + if (model == null) + { + return; + } + PackageName = model.PackageName; + Price = model.Price; + Components = model.PackageComponents.ToDictionary(x => x.Key, x => x.Value.Item2); + _PackageComponents = null; + } + public PackageViewModel GetViewModel => new() + { + Id = Id, + PackageName = PackageName, + Price = Price, + PackageComponents = PackageComponents + }; + public XElement GetXElement => new("Package", + new XAttribute("Id", Id), + new XElement("PackageName", PackageName), + new XElement("Price", Price.ToString()), + new XElement("PackageComponents", Components.Select(x => + new XElement("PackageComponent", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/PackageStorage.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/PackageStorage.cs new file mode 100644 index 0000000..34e9a5f --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/PackageStorage.cs @@ -0,0 +1,85 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationFileImplement.Models; + +namespace SoftwareInstallationFileImplement +{ + public class PackageStorage : IPackageStorage + { + private readonly DataFileSingleton _source; + public PackageStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public PackageViewModel? Delete(PackageBindingModel model) + { + var element = _source.Packages.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + _source.Packages.Remove(element); + _source.SavePackages(); + return element.GetViewModel; + } + return null; + } + + public PackageViewModel? GetElement(PackageSearchModel model) + { + if (string.IsNullOrEmpty(model.PackageName) && !model.Id.HasValue) + { + return null; + } + return _source.Packages.FirstOrDefault + (x => (!string.IsNullOrEmpty(model.PackageName) && x.PackageName == model.PackageName) || + (model.Id.HasValue && x.Id == model.Id) + )?.GetViewModel; + } + + public List GetFilteredList(PackageSearchModel model) + { + if (string.IsNullOrEmpty(model.PackageName)) + { + return new(); + } + return _source.Packages + .Select(x => x.GetViewModel) + .Where(x => x.PackageName.Contains(model.PackageName)) + .ToList(); + } + + public List GetFullList() + { + return _source.Packages + .Select(x => x.GetViewModel) + .ToList(); + } + + public PackageViewModel? Insert(PackageBindingModel model) + { + model.Id = _source.Packages.Count > 0 ? _source.Packages.Max(x => x.Id) + 1 : 1; + var newPackage = Package.Create(model); + if (newPackage == null) + { + return null; + } + _source.Packages.Add(newPackage); + _source.SavePackages(); + return newPackage.GetViewModel; + } + + public PackageViewModel? Update(PackageBindingModel model) + { + var package = _source.Packages.FirstOrDefault(x => x.Id == model.Id); + if (package == null) + { + return null; + } + package.Update(model); + _source.SavePackages(); + return package.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/Shop.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/Shop.cs new file mode 100644 index 0000000..cc5fd8a --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/Shop.cs @@ -0,0 +1,109 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels; +using SoftwareInstallationDataModels.Models; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement +{ + public class Shop : IShopModel + { + public string Name { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public int MaxCountPackages { get; private set; } + + public DateTime DateOpening { get; private set; } + + public Dictionary CountPackages { get; private set; } = new(); + + private Dictionary? _cachedPackages = null; + public Dictionary Packages + { + get + { + if (_cachedPackages == null) + { + var source = DataFileSingleton.GetInstance(); + _cachedPackages = CountPackages + .ToDictionary(x => x.Key, x => (source.Packages + .FirstOrDefault(y => y.Id == x.Key)! as IPackageModel, x.Value)); + } + return _cachedPackages; + } + } + + public int Id { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + DateOpening = model.DateOpening, + MaxCountPackages = model.MaxCountPackages, + CountPackages = new() + }; + } + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Name = element.Element("Name")!.Value, + Address = element.Element("Address")!.Value, + DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), + MaxCountPackages = Convert.ToInt32(element.Element("MaxCountPackages")!.Value), + CountPackages = element.Element("CountPackages")!.Elements("CountPackage") + .ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value) + ) + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + Address = model.Address; + DateOpening = model.DateOpening; + CountPackages = model.Packages.ToDictionary(x => x.Key, x => x.Value.Item2); + _cachedPackages = null; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + Packages = Packages, + DateOpening = DateOpening, + MaxCountPackages = MaxCountPackages, + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("Name", Name), + new XElement("Address", Address), + new XElement("DateOpening", DateOpening), + new XElement("MaxCountPackages", MaxCountPackages), + new XElement("CountPackages", CountPackages + .Select(x => new XElement("CountPackage", + new XElement("Key", x.Key), + new XElement("Value", x.Value)) + )) + ); + } +} diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/ShopStorage.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/ShopStorage.cs new file mode 100644 index 0000000..6817ddf --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/ShopStorage.cs @@ -0,0 +1,110 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels; +using SoftwareInstallationDataModels.Models; + +namespace SoftwareInstallationFileImplement +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton _source; + public ShopStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + 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 ShopViewModel? GetElement(ShopSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return _source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + return _source.Shops + .Select(x => x.GetViewModel) + .Where(x => x.Name.Contains(model.Name ?? string.Empty)) + .ToList(); + } + + public List GetFullList() + { + return _source.Shops + .Select(shop => shop.GetViewModel) + .ToList(); + } + + 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 bool SellPackages(IPackageModel package, int needCount) + { + var resultCount = _source.Shops + .Select(shop => shop.Packages + .FirstOrDefault(x => x.Key == package.Id).Value.Item2) + .Sum(); + + if (resultCount >= needCount) + { + return false; + } + foreach (var shop in _source.Shops.Where(shop => shop.Packages.ContainsKey(package.Id))) + { + var tuple = shop.Packages[package.Id]; + var diff = Math.Min(tuple.Item2, needCount); + shop.Packages[package.Id] = (tuple.Item1, tuple.Item2 - diff); + + needCount -= diff; + if (needCount <= 0) + { + return true; + } + } + + return true; + } + } +} diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/SoftWareInstallationFileImplement.csproj b/SoftwareInstallation/SoftWareInstallationFileImplement/SoftWareInstallationFileImplement.csproj new file mode 100644 index 0000000..546bcfc --- /dev/null +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/SoftWareInstallationFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/SoftwareInstallation/SoftwareInstallation.sln b/SoftwareInstallation/SoftwareInstallation.sln index 9e530be..cb408cb 100644 --- a/SoftwareInstallation/SoftwareInstallation.sln +++ b/SoftwareInstallation/SoftwareInstallation.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SoftwareInstallationListImp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SoftwareInstallationView", "SoftwareInstallationView\SoftwareInstallationView.csproj", "{564F09E4-FA75-4090-BBC8-656F23FC8F3E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftWareInstallationFileImplement", "SoftWareInstallationFileImplement\SoftWareInstallationFileImplement.csproj", "{B2816D6F-A74D-4533-8F37-3217FB028243}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {564F09E4-FA75-4090-BBC8-656F23FC8F3E}.Debug|Any CPU.Build.0 = Debug|Any CPU {564F09E4-FA75-4090-BBC8-656F23FC8F3E}.Release|Any CPU.ActiveCfg = Release|Any CPU {564F09E4-FA75-4090-BBC8-656F23FC8F3E}.Release|Any CPU.Build.0 = Release|Any CPU + {B2816D6F-A74D-4533-8F37-3217FB028243}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B2816D6F-A74D-4533-8F37-3217FB028243}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B2816D6F-A74D-4533-8F37-3217FB028243}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B2816D6F-A74D-4533-8F37-3217FB028243}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/OrderLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/OrderLogic.cs index 413fb3c..f7403ce 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/OrderLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/OrderLogic.cs @@ -12,10 +12,14 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IPackageStorage _packageStorage; + private readonly IShopLogic _shopLogic; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IPackageStorage packageStorage, IShopLogic shopLogic) { _logger = logger; + _shopLogic = shopLogic; + _packageStorage = packageStorage; _orderStorage = orderStorage; } public bool CreateOrder(OrderBindingModel model) @@ -101,6 +105,15 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics $"Доступный статус: {(OrderStatus)((int)viewModel.Status + 1)}", nameof(viewModel)); } + if (orderStatus == OrderStatus.Готов) + { + var vpackage = _packageStorage.GetElement(new() { Id = viewModel.PackageId }); + + if (vpackage == null || !_shopLogic.AddPackagesInShops(vpackage, viewModel.Count)) + { + throw new Exception($"Не удалось заполнить магазины изделием '{vpackage?.PackageName ?? string.Empty}' из заказа {viewModel.Id}"); + } + } if (model.DateImplement == null) model.DateImplement = viewModel.DateImplement; model.Status = orderStatus; model.Sum = viewModel.Sum; diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/ShopLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/ShopLogic.cs index 7c54e22..23cd6cc 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/ShopLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/ShopLogic.cs @@ -52,7 +52,7 @@ namespace SoftwareInstallationBusinessLogic public bool Create(ShopBindingModel model) { CheckModel(model); - model.Pastries = new(); + model.Packages = new(); if (_shopStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -101,6 +101,12 @@ namespace SoftwareInstallationBusinessLogic throw new ArgumentNullException("Нет названия магазина", nameof(model.Name)); } + if (model.MaxCountPackages < 0) + { + throw new ArgumentException( + "Максимальное количество изделий в магазине не должно быть отрицательным", + nameof(model.MaxCountPackages)); + } _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", model.Name, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel @@ -123,19 +129,26 @@ namespace SoftwareInstallationBusinessLogic { throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count)); } + _logger.LogInformation("AddPackageInShop. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id); var element = _shopStorage.GetElement(model); + int currCount = element.Packages.Values.FirstOrDefault().Item2; if (element == null) { _logger.LogWarning("AddPackageInShop element not found"); return false; } + if (count + currCount > element.MaxCountPackages) + { + throw new ArgumentException("Количество изделий не должно быть больше максимального количества изделий"); + return false; + } + _logger.LogInformation("AddPackageInShop find. Id:{Id}", element.Id); - - var prevCount = element.Pastries.GetValueOrDefault(package.Id, (package, 0)).Item2; - element.Pastries[package.Id] = (package, prevCount + count); + var prevCount = element.Packages.GetValueOrDefault(package.Id, (package, 0)).Item2; + element.Packages[package.Id] = (package, prevCount + count); _logger.LogInformation( "AddPackageInShop. Has been added {count} {package} in {ShopName}", count, package.PackageName, element.Name); @@ -146,9 +159,57 @@ namespace SoftwareInstallationBusinessLogic Address = element.Address, Name = element.Name, DateOpening = element.DateOpening, - Pastries = element.Pastries + Packages = element.Packages }); return true; } + public int GetFreePlacesWithPackagesInShops(int countPackages) + { + // Сумма разностей между максимальный кол-вом изделий и суммой всех изделий в магазине + return _shopStorage.GetFullList() + .Select(x => x.MaxCountPackages - x.Packages + .Select(p => p.Value.Item2).Sum()) + .Sum() - countPackages; + } + + public bool AddPackagesInShops(IPackageModel package, int count) + { + if (count <= 0) + { + _logger.LogWarning("AddPackagesInShops. Количество добавляемых изделий должно быть больше 0. Количество - {count}", count); + return false; + } + var freePlaces = GetFreePlacesWithPackagesInShops(count); + if (freePlaces < 0) + { + _logger.LogInformation("AddPackagesInShops. Не удалось добавить изделия в магазины, поскольку они переполнены." + + "Освободите магазины на {places} изделий", -freePlaces); + return false; + } + foreach (var shop in _shopStorage.GetFullList()) + { + var cnt = Math.Min(count, shop.MaxCountPackages - shop.Packages.Select(x => x.Value.Item2).Sum()); + if (cnt <= 0) + { + continue; + } + if (!AddPackage(new() { Id = shop.Id }, package, cnt)) + { + _logger.LogWarning("При добавления изделий во все магазины произошла ошибка"); + return false; + } + count -= cnt; + if (count == 0) + { + return true; + } + } + return true; + } + + public bool SellPackages(IPackageModel package, int needCount) + { + return _shopStorage.SellPackages(package, needCount); + } } -} +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs index 7923811..1a6e477 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs @@ -9,9 +9,11 @@ namespace SoftwareInstallationContracts.BindingModels public string Address { get; set; } = string.Empty; + public int MaxCountPackages { get; set; } + public DateTime DateOpening { get; set; } = DateTime.Now; - public Dictionary Pastries + public Dictionary Packages { get; set; @@ -19,4 +21,4 @@ namespace SoftwareInstallationContracts.BindingModels public int Id { get; set; } } -} +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IShopLogic.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IShopLogic.cs index e051445..e3d035c 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IShopLogic.cs @@ -13,5 +13,8 @@ namespace SoftwareInstallationContracts.BusinessLogicsContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool AddPackage(ShopSearchModel model, IPackageModel package, int count); + int GetFreePlacesWithPackagesInShops(int countPackages); + bool AddPackagesInShops(IPackageModel package, int count); + public bool SellPackages(IPackageModel package, int needCount); } } diff --git a/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IShopStorage.cs b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IShopStorage.cs index c848cde..6d7d4d6 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IShopStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; namespace SoftwareInstallationContracts.StoragesContracts { @@ -12,5 +13,7 @@ namespace SoftwareInstallationContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + + public bool SellPackages(IPackageModel package, int needCount); } } diff --git a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs index 16ebf6a..3b9e534 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs @@ -12,10 +12,13 @@ namespace SoftwareInstallationContracts.ViewModels [DisplayName("Адрес магазина")] public string Address { get; set; } = string.Empty; + [DisplayName("Максимальное количество изделий в магазине")] + public int MaxCountPackages { get; set; } + [DisplayName("Время открытия")] public DateTime DateOpening { get; set; } = DateTime.Now; - public Dictionary Pastries + public Dictionary Packages { get; set; @@ -23,4 +26,4 @@ namespace SoftwareInstallationContracts.ViewModels public int Id { get; set; } } -} +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/IShopModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/IShopModel.cs index d7a0513..afb2051 100644 --- a/SoftwareInstallation/SoftwareInstallationDataModels/IShopModel.cs +++ b/SoftwareInstallation/SoftwareInstallationDataModels/IShopModel.cs @@ -6,7 +6,8 @@ namespace SoftwareInstallationDataModels { string Name { get; } string Address { get; } + int MaxCountPackages { get; } DateTime DateOpening { get; } - Dictionary Pastries { get; } + Dictionary Packages { get; } } } diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Shop.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Shop.cs index ba18c06..660b82b 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/Shop.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Shop.cs @@ -11,9 +11,11 @@ namespace SoftwareInstallationListImplement public string Address { get; private set; } = string.Empty; + public int MaxCountPackages { get; private set; } + public DateTime DateOpening { get; private set; } - public Dictionary Pastries + public Dictionary Packages { get; private set; @@ -33,7 +35,8 @@ namespace SoftwareInstallationListImplement Name = model.Name, Address = model.Address, DateOpening = model.DateOpening, - Pastries = new() + MaxCountPackages = model.MaxCountPackages, + Packages = new() }; } public void Update(ShopBindingModel? model) @@ -45,15 +48,17 @@ namespace SoftwareInstallationListImplement Name = model.Name; Address = model.Address; DateOpening = model.DateOpening; - Pastries = model.Pastries; + MaxCountPackages = model.MaxCountPackages; + Packages = model.Packages; } public ShopViewModel GetViewModel => new() { Id = Id, Name = Name, Address = Address, - Pastries = Pastries, + Packages = Packages, DateOpening = DateOpening, + MaxCountPackages = MaxCountPackages, }; } } diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/ShopStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/ShopStorage.cs index 6e198e9..7bdba6b 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/ShopStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/ShopStorage.cs @@ -2,6 +2,7 @@ using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; namespace SoftwareInstallationListImplement { @@ -72,6 +73,11 @@ namespace SoftwareInstallationListImplement return result; } + public bool HasNeedPackages(IPackageModel package, int needCount) + { + throw new NotImplementedException(); + } + public ShopViewModel? Insert(ShopBindingModel model) { model.Id = 1; @@ -91,6 +97,11 @@ namespace SoftwareInstallationListImplement return newShop.GetViewModel; } + public bool SellPackages(IPackageModel package, int needCount) + { + throw new NotImplementedException(); + } + public ShopViewModel? Update(ShopBindingModel model) { foreach (var shop in _source.Shops) diff --git a/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.Designer.cs index fe10656..97d3cd2 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.Designer.cs @@ -28,7 +28,7 @@ /// private void InitializeComponent() { - this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.textBoxShop = new System.Windows.Forms.ComboBox(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); @@ -39,13 +39,13 @@ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); this.SuspendLayout(); // - // comboBoxShop + // textBoxShop // - this.comboBoxShop.FormattingEnabled = true; - this.comboBoxShop.Location = new System.Drawing.Point(214, 17); - this.comboBoxShop.Name = "comboBoxShop"; - this.comboBoxShop.Size = new System.Drawing.Size(222, 23); - this.comboBoxShop.TabIndex = 3; + this.textBoxShop.FormattingEnabled = true; + this.textBoxShop.Location = new System.Drawing.Point(214, 17); + this.textBoxShop.Name = "textBoxShop"; + this.textBoxShop.Size = new System.Drawing.Size(222, 23); + this.textBoxShop.TabIndex = 3; // // label1 // @@ -127,7 +127,7 @@ this.Controls.Add(this.comboBoxPackage); this.Controls.Add(this.label3); this.Controls.Add(this.label2); - this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.textBoxShop); this.Controls.Add(this.label1); this.Name = "FormAddPackageInShop"; this.Text = "форма добавления пакета в магазин"; @@ -139,7 +139,7 @@ #endregion - private ComboBox comboBoxShop; + private ComboBox textBoxShop; private Label label1; private Label label2; private Label label3; diff --git a/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.cs b/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.cs index d64f927..ecc981e 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.cs @@ -21,7 +21,7 @@ namespace SoftwareInstallationView private readonly IShopLogic _shopLogic; private readonly IPackageLogic _packageLogic; private readonly List? _listShops; - private readonly List? _listPastries; + private readonly List? _listPackages; public FormAddPackageInShop(ILogger logger, IShopLogic shopLogic, IPackageLogic packageLogic) { @@ -32,25 +32,25 @@ namespace SoftwareInstallationView _listShops = shopLogic.ReadList(null); if (_listShops != null) { - comboBoxShop.DisplayMember = "Name"; - comboBoxShop.ValueMember = "Id"; - comboBoxShop.DataSource = _listShops; - comboBoxShop.SelectedItem = null; + textBoxShop.DisplayMember = "Name"; + textBoxShop.ValueMember = "Id"; + textBoxShop.DataSource = _listShops; + textBoxShop.SelectedItem = null; } - _listPastries = packageLogic.ReadList(null); - if (_listPastries != null) + _listPackages = packageLogic.ReadList(null); + if (_listPackages != null) { comboBoxPackage.DisplayMember = "PackageName"; comboBoxPackage.ValueMember= "Id"; - comboBoxPackage.DataSource = _listPastries; + comboBoxPackage.DataSource = _listPackages; comboBoxPackage.SelectedItem = null; } } private void ButtonSave_Click(object sender, EventArgs e) { - if (comboBoxShop.SelectedValue == null) + if (textBoxShop.SelectedValue == null) { MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -72,7 +72,7 @@ namespace SoftwareInstallationView throw new Exception("Не найдено изделие. Дополнительная информация в логах."); } var resultOperation = _shopLogic.AddPackage( - model: new() { Id = (int)comboBoxShop.SelectedValue }, + model: new() { Id = (int)textBoxShop.SelectedValue }, package: package, count: (int)numericUpDownCount.Value ); diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs index 7a5f28a..a86da86 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs @@ -28,162 +28,176 @@ /// private void InitializeComponent() { - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.packageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.componentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.ButtonRef = new System.Windows.Forms.Button(); - this.ButtonIssuedOrder = new System.Windows.Forms.Button(); - this.ButtonOrderReady = new System.Windows.Forms.Button(); - this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); - this.buttonCreateOrder = new System.Windows.Forms.Button(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonAddPackageInShop = new System.Windows.Forms.Button(); - this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // menuStrip1 - // - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.packageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.componentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.ButtonIssuedOrder = new System.Windows.Forms.Button(); + this.ButtonOrderReady = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAddPackageInShop = new System.Windows.Forms.Button(); + this.buttonSellPackage = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1125, 24); - this.menuStrip1.TabIndex = 1; - this.menuStrip1.Text = "menuStrip1"; - // - // справочникиToolStripMenuItem - // - this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1125, 24); + this.menuStrip1.TabIndex = 1; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.packageToolStripMenuItem, this.componentToolStripMenuItem, this.магазиныToolStripMenuItem}); - this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); - this.справочникиToolStripMenuItem.Text = "Справочники"; - // - // packageToolStripMenuItem - // - this.packageToolStripMenuItem.Name = "packageToolStripMenuItem"; - this.packageToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.packageToolStripMenuItem.Text = "Изделия"; - this.packageToolStripMenuItem.Click += new System.EventHandler(this.PackagesToolStripMenuItem_Click); - // - // componentToolStripMenuItem - // - this.componentToolStripMenuItem.Name = "componentToolStripMenuItem"; - this.componentToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.componentToolStripMenuItem.Text = "Компоненты"; - this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); - // - // ButtonRef - // - this.ButtonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonRef.Location = new System.Drawing.Point(966, 313); - this.ButtonRef.Name = "ButtonRef"; - this.ButtonRef.Size = new System.Drawing.Size(147, 55); - this.ButtonRef.TabIndex = 12; - this.ButtonRef.Text = "Обновить список"; - this.ButtonRef.UseVisualStyleBackColor = true; - this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); - // - // ButtonIssuedOrder - // - this.ButtonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonIssuedOrder.Location = new System.Drawing.Point(966, 210); - this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; - this.ButtonIssuedOrder.Size = new System.Drawing.Size(147, 55); - this.ButtonIssuedOrder.TabIndex = 11; - this.ButtonIssuedOrder.Text = "Заказ выдан"; - this.ButtonIssuedOrder.UseVisualStyleBackColor = true; - this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); - // - // ButtonOrderReady - // - this.ButtonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ButtonOrderReady.Location = new System.Drawing.Point(966, 149); - this.ButtonOrderReady.Name = "ButtonOrderReady"; - this.ButtonOrderReady.Size = new System.Drawing.Size(147, 55); - this.ButtonOrderReady.TabIndex = 10; - this.ButtonOrderReady.Text = "Заказ готов"; - this.ButtonOrderReady.UseVisualStyleBackColor = true; - this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // - // buttonTakeOrderInWork - // - this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(966, 88); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(147, 55); - this.buttonTakeOrderInWork.TabIndex = 9; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // - // buttonCreateOrder - // - this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonCreateOrder.Location = new System.Drawing.Point(966, 27); - this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(147, 55); - this.buttonCreateOrder.TabIndex = 8; - this.buttonCreateOrder.Text = "Создать заказ"; - this.buttonCreateOrder.UseVisualStyleBackColor = true; - this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); - // - // dataGridView - // - this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // packageToolStripMenuItem + // + this.packageToolStripMenuItem.Name = "packageToolStripMenuItem"; + this.packageToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.packageToolStripMenuItem.Text = "Изделия"; + this.packageToolStripMenuItem.Click += new System.EventHandler(this.PackagesToolStripMenuItem_Click); + // + // componentToolStripMenuItem + // + this.componentToolStripMenuItem.Name = "componentToolStripMenuItem"; + this.componentToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.componentToolStripMenuItem.Text = "Компоненты"; + this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); + // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); + // + // ButtonRef + // + this.ButtonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonRef.Location = new System.Drawing.Point(966, 232); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(147, 42); + this.ButtonRef.TabIndex = 12; + this.ButtonRef.Text = "Обновить список"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // ButtonIssuedOrder + // + this.ButtonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonIssuedOrder.Location = new System.Drawing.Point(966, 184); + this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + this.ButtonIssuedOrder.Size = new System.Drawing.Size(147, 42); + this.ButtonIssuedOrder.TabIndex = 11; + this.ButtonIssuedOrder.Text = "Заказ выдан"; + this.ButtonIssuedOrder.UseVisualStyleBackColor = true; + this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // ButtonOrderReady + // + this.ButtonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonOrderReady.Location = new System.Drawing.Point(966, 136); + this.ButtonOrderReady.Name = "ButtonOrderReady"; + this.ButtonOrderReady.Size = new System.Drawing.Size(147, 42); + this.ButtonOrderReady.TabIndex = 10; + this.ButtonOrderReady.Text = "Заказ готов"; + this.ButtonOrderReady.UseVisualStyleBackColor = true; + this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(966, 88); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(147, 42); + this.buttonTakeOrderInWork.TabIndex = 9; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonCreateOrder + // + this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCreateOrder.Location = new System.Drawing.Point(966, 40); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(147, 42); + this.buttonCreateOrder.TabIndex = 8; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 27); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(948, 402); - this.dataGridView.TabIndex = 7; - // - // buttonAddPackageInShop - // - this.buttonAddPackageInShop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonAddPackageInShop.Location = new System.Drawing.Point(966, 374); - this.buttonAddPackageInShop.Name = "buttonAddPackageInShop"; - this.buttonAddPackageInShop.Size = new System.Drawing.Size(147, 55); - this.buttonAddPackageInShop.TabIndex = 13; - this.buttonAddPackageInShop.Text = "Пополнение магазина"; - this.buttonAddPackageInShop.UseVisualStyleBackColor = true; - this.buttonAddPackageInShop.Click += new System.EventHandler(this.ButtonAddPackageInShop_Click); - // - // магазиныToolStripMenuItem - // - this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.магазиныToolStripMenuItem.Text = "Магазины"; - this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); - // - // FormMain - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1125, 441); - this.Controls.Add(this.buttonAddPackageInShop); - this.Controls.Add(this.ButtonRef); - this.Controls.Add(this.ButtonIssuedOrder); - this.Controls.Add(this.ButtonOrderReady); - this.Controls.Add(this.buttonTakeOrderInWork); - this.Controls.Add(this.buttonCreateOrder); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.menuStrip1); - this.Name = "FormMain"; - this.Text = "Установка ПО"; - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 27); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(948, 402); + this.dataGridView.TabIndex = 7; + // + // buttonAddPackageInShop + // + this.buttonAddPackageInShop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonAddPackageInShop.Location = new System.Drawing.Point(966, 387); + this.buttonAddPackageInShop.Name = "buttonAddPackageInShop"; + this.buttonAddPackageInShop.Size = new System.Drawing.Size(147, 42); + this.buttonAddPackageInShop.TabIndex = 13; + this.buttonAddPackageInShop.Text = "Пополнение магазина"; + this.buttonAddPackageInShop.UseVisualStyleBackColor = true; + this.buttonAddPackageInShop.Click += new System.EventHandler(this.ButtonAddPackageInShop_Click); + // + // buttonSellPackage + // + this.buttonSellPackage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSellPackage.Location = new System.Drawing.Point(966, 339); + this.buttonSellPackage.Name = "buttonSellPackage"; + this.buttonSellPackage.Size = new System.Drawing.Size(147, 42); + this.buttonSellPackage.TabIndex = 14; + this.buttonSellPackage.Text = "Продать изделие"; + this.buttonSellPackage.UseVisualStyleBackColor = true; + this.buttonSellPackage.Click += new System.EventHandler(this.ButtonSellPackage_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1125, 441); + this.Controls.Add(this.buttonSellPackage); + this.Controls.Add(this.buttonAddPackageInShop); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonIssuedOrder); + this.Controls.Add(this.ButtonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.Name = "FormMain"; + this.Text = "Установка ПО"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -201,5 +215,6 @@ private DataGridView dataGridView; private ToolStripMenuItem магазиныToolStripMenuItem; private Button buttonAddPackageInShop; + private Button buttonSellPackage; } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMain.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs index fbbf69a..84935ef 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormMain.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs @@ -151,5 +151,13 @@ namespace SoftwareInstallationView form.ShowDialog(); } } + private void ButtonSellPackage_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellPackage)); + if (service is FormSellPackage form) + { + form.ShowDialog(); + } + } } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormSellPackage.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormSellPackage.Designer.cs new file mode 100644 index 0000000..e176cf5 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormSellPackage.Designer.cs @@ -0,0 +1,133 @@ +namespace SoftwareInstallationView +{ + partial class FormSellPackage + { + /// + /// 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.comboBoxPackage = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); + this.buttonSell = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); + this.SuspendLayout(); + // + // comboBoxPackage + // + this.comboBoxPackage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.comboBoxPackage.FormattingEnabled = true; + this.comboBoxPackage.Location = new System.Drawing.Point(141, 12); + this.comboBoxPackage.Name = "comboBoxPackage"; + this.comboBoxPackage.Size = new System.Drawing.Size(121, 23); + this.comboBoxPackage.TabIndex = 0; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 15); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(123, 15); + this.label1.TabIndex = 1; + this.label1.Text = "Изделие на продажу:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(60, 46); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(75, 15); + this.label2.TabIndex = 2; + this.label2.Text = "Количество:"; + // + // numericUpDownCount + // + this.numericUpDownCount.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.numericUpDownCount.Location = new System.Drawing.Point(142, 46); + this.numericUpDownCount.Maximum = new decimal(new int[] { + 10000000, + 0, + 0, + 0}); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.numericUpDownCount.Size = new System.Drawing.Size(120, 23); + this.numericUpDownCount.TabIndex = 3; + // + // buttonSell + // + this.buttonSell.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSell.Location = new System.Drawing.Point(12, 90); + this.buttonSell.Name = "buttonSell"; + this.buttonSell.Size = new System.Drawing.Size(123, 23); + this.buttonSell.TabIndex = 4; + this.buttonSell.Text = "Продать"; + this.buttonSell.UseVisualStyleBackColor = true; + this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(142, 90); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(123, 23); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormSellPackage + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(277, 122); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSell); + this.Controls.Add(this.numericUpDownCount); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.comboBoxPackage); + this.Name = "FormSellPackage"; + this.Text = "Продажа изделия"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxPackage; + private Label label1; + private Label label2; + private NumericUpDown numericUpDownCount; + private Button buttonSell; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormSellPackage.cs b/SoftwareInstallation/SoftwareInstallationView/FormSellPackage.cs new file mode 100644 index 0000000..3d9e851 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormSellPackage.cs @@ -0,0 +1,54 @@ +using SoftwareInstallationContracts.BusinessLogicsContracts; + +namespace SoftwareInstallationView +{ + public partial class FormSellPackage : Form + { + private readonly IShopLogic _shopLogic; + private readonly IPackageLogic _packageLogic; + + public FormSellPackage(IPackageLogic logic, IShopLogic shopLogic) + { + InitializeComponent(); + _packageLogic = logic; + _shopLogic = shopLogic; + var list = logic.ReadList(null); + if (list != null) + { + comboBoxPackage.DisplayMember = "PackageName"; + comboBoxPackage.ValueMember = "Id"; + comboBoxPackage.DataSource = list; + comboBoxPackage.SelectedItem = null; + } + } + + private void ButtonSell_Click(object sender, EventArgs e) + { + if (comboBoxPackage.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (numericUpDownCount.Value <= 0) + { + MessageBox.Show("Количество должно быть больше нуля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + var count = (int)numericUpDownCount.Value; + var package = _packageLogic.ReadElement(new() { Id = (int)comboBoxPackage.SelectedValue }); + if (package == null || !_shopLogic.SellPackages(package, count)) + { + MessageBox.Show("Не удалось продать изделия. Информацию смотрите в логах", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationView/FormSellPackage.resx b/SoftwareInstallation/SoftwareInstallationView/FormSellPackage.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormSellPackage.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/SoftwareInstallation/SoftwareInstallationView/FormShop.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormShop.Designer.cs index b60d0e6..c6bb107 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormShop.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormShop.Designer.cs @@ -28,162 +28,189 @@ /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); - this.comboBoxShop = new System.Windows.Forms.ComboBox(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.PackageName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.label2 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); - this.textBoxAddress = new System.Windows.Forms.TextBox(); - this.textBoxDateOpening = new System.Windows.Forms.TextBox(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.buttonSave = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(12, 9); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(116, 15); - this.label1.TabIndex = 0; - this.label1.Text = "Название магазина:"; - // - // comboBoxShop - // - this.comboBoxShop.FormattingEnabled = true; - this.comboBoxShop.Location = new System.Drawing.Point(12, 27); - this.comboBoxShop.Name = "comboBoxShop"; - this.comboBoxShop.Size = new System.Drawing.Size(141, 23); - this.comboBoxShop.TabIndex = 1; - this.comboBoxShop.SelectedIndexChanged += new System.EventHandler(this.ComboBoxShop_SelectedIndexChanged); - // - // dataGridView - // - this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.label1 = new System.Windows.Forms.Label(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.PackageName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.numericUpDownMaxPackage = new System.Windows.Forms.NumericUpDown(); + this.label4 = new System.Windows.Forms.Label(); + this.textBoxDateOpening = new System.Windows.Forms.DateTimePicker(); + this.textBoxShop = new System.Windows.Forms.TextBox(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxPackage)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(116, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Название магазина:"; + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.PackageName, this.Price, this.Count}); - this.dataGridView.Location = new System.Drawing.Point(12, 64); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(583, 213); - this.dataGridView.TabIndex = 2; - // - // PackageName - // - this.PackageName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.PackageName.HeaderText = "Имя изделия"; - this.PackageName.Name = "PackageName"; - // - // Price - // - this.Price.HeaderText = "Цена"; - this.Price.Name = "Price"; - // - // Count - // - this.Count.HeaderText = "Количество"; - this.Count.Name = "Count"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(159, 9); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(97, 15); - this.label2.TabIndex = 3; - this.label2.Text = "Адрес магазина:"; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(386, 9); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(100, 15); - this.label3.TabIndex = 4; - this.label3.Text = "Время открытия:"; - // - // textBoxAddress - // - this.textBoxAddress.Location = new System.Drawing.Point(159, 27); - this.textBoxAddress.Name = "textBoxAddress"; - this.textBoxAddress.Size = new System.Drawing.Size(221, 23); - this.textBoxAddress.TabIndex = 5; - // - // textBoxDateOpening - // - this.textBoxDateOpening.Location = new System.Drawing.Point(386, 27); - this.textBoxDateOpening.Name = "textBoxDateOpening"; - this.textBoxDateOpening.Size = new System.Drawing.Size(209, 23); - this.textBoxDateOpening.TabIndex = 6; - // - // buttonCancel - // - this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonCancel.Location = new System.Drawing.Point(492, 283); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(103, 23); - this.buttonCancel.TabIndex = 7; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // buttonSave - // - this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonSave.Location = new System.Drawing.Point(366, 284); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(120, 22); - this.buttonSave.TabIndex = 8; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // - // FormShop - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(607, 317); - this.Controls.Add(this.buttonSave); - this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.textBoxDateOpening); - this.Controls.Add(this.textBoxAddress); - this.Controls.Add(this.label3); - this.Controls.Add(this.label2); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.comboBoxShop); - this.Controls.Add(this.label1); - this.Name = "FormShop"; - this.Text = "Просмотр изделий магазина"; - this.Load += new System.EventHandler(this.FormShop_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + this.dataGridView.Location = new System.Drawing.Point(12, 64); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(583, 213); + this.dataGridView.TabIndex = 2; + // + // PackageName + // + this.PackageName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.PackageName.HeaderText = "Имя изделия"; + this.PackageName.Name = "PackageName"; + // + // Price + // + this.Price.HeaderText = "Цена"; + this.Price.Name = "Price"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.Name = "Count"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(159, 9); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(97, 15); + this.label2.TabIndex = 3; + this.label2.Text = "Адрес магазина:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(340, 9); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(100, 15); + this.label3.TabIndex = 4; + this.label3.Text = "Время открытия:"; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(159, 27); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(175, 23); + this.textBoxAddress.TabIndex = 5; + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(492, 283); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(103, 23); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(366, 284); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(120, 22); + this.buttonSave.TabIndex = 8; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // numericUpDownMaxPackage + // + this.numericUpDownMaxPackage.Location = new System.Drawing.Point(462, 27); + this.numericUpDownMaxPackage.Maximum = new decimal(new int[] { + 10000000, + 0, + 0, + 0}); + this.numericUpDownMaxPackage.Name = "numericUpDownMaxPackage"; + this.numericUpDownMaxPackage.Size = new System.Drawing.Size(133, 23); + this.numericUpDownMaxPackage.TabIndex = 11; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(462, 9); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(118, 15); + this.label4.TabIndex = 12; + this.label4.Text = "Максимум изделий:"; + // + // textBoxDateOpening + // + this.textBoxDateOpening.Location = new System.Drawing.Point(340, 27); + this.textBoxDateOpening.Name = "textBoxDateOpening"; + this.textBoxDateOpening.Size = new System.Drawing.Size(116, 23); + this.textBoxDateOpening.TabIndex = 13; + // + // textBoxShop + // + this.textBoxShop.Location = new System.Drawing.Point(12, 26); + this.textBoxShop.Name = "textBoxShop"; + this.textBoxShop.Size = new System.Drawing.Size(141, 23); + this.textBoxShop.TabIndex = 14; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(607, 317); + this.Controls.Add(this.textBoxShop); + this.Controls.Add(this.textBoxDateOpening); + this.Controls.Add(this.label4); + this.Controls.Add(this.numericUpDownMaxPackage); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.label1); + this.Name = "FormShop"; + this.Text = "Просмотр изделий магазина"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxPackage)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } #endregion private Label label1; - private ComboBox comboBoxShop; private DataGridView dataGridView; private Label label2; private Label label3; private TextBox textBoxAddress; - private TextBox textBoxDateOpening; private Button buttonCancel; private Button buttonSave; private DataGridViewTextBoxColumn PackageName; private DataGridViewTextBoxColumn Price; private DataGridViewTextBoxColumn Count; - } + private NumericUpDown numericUpDownMaxPackage; + private Label label4; + private DateTimePicker textBoxDateOpening; + private TextBox textBoxShop; + } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormShop.cs b/SoftwareInstallation/SoftwareInstallationView/FormShop.cs index 188449a..8ed0581 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormShop.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormShop.cs @@ -50,28 +50,22 @@ namespace SoftwareInstallationView InitializeComponent(); _logger = logger; _listShops = logic.ReadList(null); - _logic = logic; - if (_listShops != null) - { - comboBoxShop.DisplayMember = "Name"; - comboBoxShop.ValueMember = "Id"; - comboBoxShop.DataSource = _listShops; - comboBoxShop.SelectedItem = null; - } + _logic = logic; } private void LoadData(bool extendDate = true) { try { - var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.SelectedValue)); + var model = GetShop(extendDate ? Id : Convert.ToInt32(null)); if (model != null) - { - comboBoxShop.Text = model.Name; + { + numericUpDownMaxPackage.Value = model.MaxCountPackages; + textBoxShop.Text = model.Name; textBoxAddress.Text = model.Address; textBoxDateOpening.Text = Convert.ToString(model.DateOpening); dataGridView.Rows.Clear(); - foreach (var el in model.Pastries.Values) + foreach (var el in model.Packages.Values) { dataGridView.Rows.Add(new object[]{el.Item1.PackageName, el.Item1.Price, el.Item2 }); } @@ -93,7 +87,7 @@ namespace SoftwareInstallationView private void ButtonSave_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(comboBoxShop.Text)) + if (string.IsNullOrEmpty(textBoxShop.Text)) { MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -111,9 +105,10 @@ namespace SoftwareInstallationView DateTime.TryParse(textBoxDateOpening.Text, out var dateTime); ShopBindingModel model = new() { - Name = comboBoxShop.Text, + Name = textBoxShop.Text, Address = textBoxAddress.Text, - DateOpening = dateTime + DateOpening = dateTime, + MaxCountPackages = (int)numericUpDownMaxPackage.Value, }; var vmodel = GetShop(Id); bool operationResult = false; diff --git a/SoftwareInstallation/SoftwareInstallationView/FormViewShops.cs b/SoftwareInstallation/SoftwareInstallationView/FormViewShops.cs index 4c2bd8b..1612a8e 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormViewShops.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormViewShops.cs @@ -28,7 +28,7 @@ namespace SoftwareInstallationView dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["Pastries"].Visible = false; + dataGridView.Columns["Packages"].Visible = false; dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } diff --git a/SoftwareInstallation/SoftwareInstallationView/Program.cs b/SoftwareInstallation/SoftwareInstallationView/Program.cs index a0d4196..9aa5740 100644 --- a/SoftwareInstallation/SoftwareInstallationView/Program.cs +++ b/SoftwareInstallation/SoftwareInstallationView/Program.cs @@ -1,14 +1,13 @@ using SoftwareInstallationBusinessLogic.BusinessLogics; using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.StoragesContracts; -using SoftwareInstallationListImplement.Implements; -using SoftwareInstallationListImplement; +using SoftwareInstallationFileImplement; +using SoftwareInstallationFileImplement.Implements; using SoftwareInstallationBusinessLogic; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; - namespace SoftwareInstallationView { internal static class Program @@ -54,6 +53,7 @@ namespace SoftwareInstallationView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/SoftwareInstallationView.csproj b/SoftwareInstallation/SoftwareInstallationView/SoftwareInstallationView.csproj index 08ea107..27700ff 100644 --- a/SoftwareInstallation/SoftwareInstallationView/SoftwareInstallationView.csproj +++ b/SoftwareInstallation/SoftwareInstallationView/SoftwareInstallationView.csproj @@ -18,6 +18,7 @@ +