Lab2_Hard

This commit is contained in:
m1aksim1 2023-03-18 01:08:33 +04:00
parent 47eb037c61
commit aba6593945
32 changed files with 1512 additions and 342 deletions

View File

@ -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()));
}
}

View File

@ -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<ComponentViewModel> GetFullList()
{
return _source.Components
.Select(x => x.GetViewModel)
.ToList();
}
public List<ComponentViewModel> 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;
}
}
}

View File

@ -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<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Package> Packages { get; private set; }
public List<Shop> 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<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{
if (File.Exists(filename))
{
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
}
return new List<T>();
}
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
{
if (data != null)
{
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
}
}
}
}

View File

@ -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)
);
}
}

View File

@ -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<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = GetElement(model);
return result != null ? new() { result } : new();
}
public List<OrderViewModel> 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;
}
}
}

View File

@ -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<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _PackageComponents = null;
public Dictionary<int, (IComponentModel, int)> 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()));
}
}

View File

@ -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<PackageViewModel> 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<PackageViewModel> 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;
}
}
}

View File

@ -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<int, int> CountPackages { get; private set; } = new();
private Dictionary<int, (IPackageModel, int)>? _cachedPackages = null;
public Dictionary<int, (IPackageModel, int)> 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))
))
);
}
}

View File

@ -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<ShopViewModel> 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<ShopViewModel> 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;
}
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SoftwareInstallationContracts\SoftwareInstallationContracts.csproj" />
<ProjectReference Include="..\SoftwareInstallationDataModels\SoftwareInstallationDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SoftwareInstallationListImp
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SoftwareInstallationView", "SoftwareInstallationView\SoftwareInstallationView.csproj", "{564F09E4-FA75-4090-BBC8-656F23FC8F3E}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SoftwareInstallationView", "SoftwareInstallationView\SoftwareInstallationView.csproj", "{564F09E4-FA75-4090-BBC8-656F23FC8F3E}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftWareInstallationFileImplement", "SoftWareInstallationFileImplement\SoftWareInstallationFileImplement.csproj", "{B2816D6F-A74D-4533-8F37-3217FB028243}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{564F09E4-FA75-4090-BBC8-656F23FC8F3E}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -12,10 +12,14 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
private readonly IPackageStorage _packageStorage;
private readonly IShopLogic _shopLogic;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage) public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IPackageStorage packageStorage, IShopLogic shopLogic)
{ {
_logger = logger; _logger = logger;
_shopLogic = shopLogic;
_packageStorage = packageStorage;
_orderStorage = orderStorage; _orderStorage = orderStorage;
} }
public bool CreateOrder(OrderBindingModel model) public bool CreateOrder(OrderBindingModel model)
@ -101,6 +105,15 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics
$"Доступный статус: {(OrderStatus)((int)viewModel.Status + 1)}", $"Доступный статус: {(OrderStatus)((int)viewModel.Status + 1)}",
nameof(viewModel)); 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; if (model.DateImplement == null) model.DateImplement = viewModel.DateImplement;
model.Status = orderStatus; model.Status = orderStatus;
model.Sum = viewModel.Sum; model.Sum = viewModel.Sum;

View File

@ -52,7 +52,7 @@ namespace SoftwareInstallationBusinessLogic
public bool Create(ShopBindingModel model) public bool Create(ShopBindingModel model)
{ {
CheckModel(model); CheckModel(model);
model.Pastries = new(); model.Packages = new();
if (_shopStorage.Insert(model) == null) if (_shopStorage.Insert(model) == null)
{ {
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
@ -101,6 +101,12 @@ namespace SoftwareInstallationBusinessLogic
throw new ArgumentNullException("Нет названия магазина", throw new ArgumentNullException("Нет названия магазина",
nameof(model.Name)); nameof(model.Name));
} }
if (model.MaxCountPackages < 0)
{
throw new ArgumentException(
"Максимальное количество изделий в магазине не должно быть отрицательным",
nameof(model.MaxCountPackages));
}
_logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}",
model.Name, model.Address, model.Id); model.Name, model.Address, model.Id);
var element = _shopStorage.GetElement(new ShopSearchModel var element = _shopStorage.GetElement(new ShopSearchModel
@ -123,19 +129,26 @@ namespace SoftwareInstallationBusinessLogic
{ {
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count)); throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count));
} }
_logger.LogInformation("AddPackageInShop. ShopName:{ShopName}.Id:{ Id}", _logger.LogInformation("AddPackageInShop. ShopName:{ShopName}.Id:{ Id}",
model.Name, model.Id); model.Name, model.Id);
var element = _shopStorage.GetElement(model); var element = _shopStorage.GetElement(model);
int currCount = element.Packages.Values.FirstOrDefault().Item2;
if (element == null) if (element == null)
{ {
_logger.LogWarning("AddPackageInShop element not found"); _logger.LogWarning("AddPackageInShop element not found");
return false; return false;
} }
if (count + currCount > element.MaxCountPackages)
{
throw new ArgumentException("Количество изделий не должно быть больше максимального количества изделий");
return false;
}
_logger.LogInformation("AddPackageInShop find. Id:{Id}", element.Id); _logger.LogInformation("AddPackageInShop find. Id:{Id}", element.Id);
var prevCount = element.Packages.GetValueOrDefault(package.Id, (package, 0)).Item2;
var prevCount = element.Pastries.GetValueOrDefault(package.Id, (package, 0)).Item2; element.Packages[package.Id] = (package, prevCount + count);
element.Pastries[package.Id] = (package, prevCount + count);
_logger.LogInformation( _logger.LogInformation(
"AddPackageInShop. Has been added {count} {package} in {ShopName}", "AddPackageInShop. Has been added {count} {package} in {ShopName}",
count, package.PackageName, element.Name); count, package.PackageName, element.Name);
@ -146,9 +159,57 @@ namespace SoftwareInstallationBusinessLogic
Address = element.Address, Address = element.Address,
Name = element.Name, Name = element.Name,
DateOpening = element.DateOpening, DateOpening = element.DateOpening,
Pastries = element.Pastries Packages = element.Packages
}); });
return true; 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);
}
} }
} }

View File

@ -9,9 +9,11 @@ namespace SoftwareInstallationContracts.BindingModels
public string Address { get; set; } = string.Empty; public string Address { get; set; } = string.Empty;
public int MaxCountPackages { get; set; }
public DateTime DateOpening { get; set; } = DateTime.Now; public DateTime DateOpening { get; set; } = DateTime.Now;
public Dictionary<int, (IPackageModel, int)> Pastries public Dictionary<int, (IPackageModel, int)> Packages
{ {
get; get;
set; set;

View File

@ -13,5 +13,8 @@ namespace SoftwareInstallationContracts.BusinessLogicsContracts
bool Update(ShopBindingModel model); bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model); bool Delete(ShopBindingModel model);
bool AddPackage(ShopSearchModel model, IPackageModel package, int count); 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);
} }
} }

View File

@ -1,6 +1,7 @@
using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.SearchModels;
using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels.Models;
namespace SoftwareInstallationContracts.StoragesContracts namespace SoftwareInstallationContracts.StoragesContracts
{ {
@ -12,5 +13,7 @@ namespace SoftwareInstallationContracts.StoragesContracts
ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model);
public bool SellPackages(IPackageModel package, int needCount);
} }
} }

View File

@ -12,10 +12,13 @@ namespace SoftwareInstallationContracts.ViewModels
[DisplayName("Адрес магазина")] [DisplayName("Адрес магазина")]
public string Address { get; set; } = string.Empty; public string Address { get; set; } = string.Empty;
[DisplayName("Максимальное количество изделий в магазине")]
public int MaxCountPackages { get; set; }
[DisplayName("Время открытия")] [DisplayName("Время открытия")]
public DateTime DateOpening { get; set; } = DateTime.Now; public DateTime DateOpening { get; set; } = DateTime.Now;
public Dictionary<int, (IPackageModel, int)> Pastries public Dictionary<int, (IPackageModel, int)> Packages
{ {
get; get;
set; set;

View File

@ -6,7 +6,8 @@ namespace SoftwareInstallationDataModels
{ {
string Name { get; } string Name { get; }
string Address { get; } string Address { get; }
int MaxCountPackages { get; }
DateTime DateOpening { get; } DateTime DateOpening { get; }
Dictionary<int, (IPackageModel, int)> Pastries { get; } Dictionary<int, (IPackageModel, int)> Packages { get; }
} }
} }

View File

@ -11,9 +11,11 @@ namespace SoftwareInstallationListImplement
public string Address { 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 DateTime DateOpening { get; private set; }
public Dictionary<int, (IPackageModel, int)> Pastries public Dictionary<int, (IPackageModel, int)> Packages
{ {
get; get;
private set; private set;
@ -33,7 +35,8 @@ namespace SoftwareInstallationListImplement
Name = model.Name, Name = model.Name,
Address = model.Address, Address = model.Address,
DateOpening = model.DateOpening, DateOpening = model.DateOpening,
Pastries = new() MaxCountPackages = model.MaxCountPackages,
Packages = new()
}; };
} }
public void Update(ShopBindingModel? model) public void Update(ShopBindingModel? model)
@ -45,15 +48,17 @@ namespace SoftwareInstallationListImplement
Name = model.Name; Name = model.Name;
Address = model.Address; Address = model.Address;
DateOpening = model.DateOpening; DateOpening = model.DateOpening;
Pastries = model.Pastries; MaxCountPackages = model.MaxCountPackages;
Packages = model.Packages;
} }
public ShopViewModel GetViewModel => new() public ShopViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
Name = Name, Name = Name,
Address = Address, Address = Address,
Pastries = Pastries, Packages = Packages,
DateOpening = DateOpening, DateOpening = DateOpening,
MaxCountPackages = MaxCountPackages,
}; };
} }
} }

View File

@ -2,6 +2,7 @@
using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.SearchModels;
using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.StoragesContracts;
using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels.Models;
namespace SoftwareInstallationListImplement namespace SoftwareInstallationListImplement
{ {
@ -72,6 +73,11 @@ namespace SoftwareInstallationListImplement
return result; return result;
} }
public bool HasNeedPackages(IPackageModel package, int needCount)
{
throw new NotImplementedException();
}
public ShopViewModel? Insert(ShopBindingModel model) public ShopViewModel? Insert(ShopBindingModel model)
{ {
model.Id = 1; model.Id = 1;
@ -91,6 +97,11 @@ namespace SoftwareInstallationListImplement
return newShop.GetViewModel; return newShop.GetViewModel;
} }
public bool SellPackages(IPackageModel package, int needCount)
{
throw new NotImplementedException();
}
public ShopViewModel? Update(ShopBindingModel model) public ShopViewModel? Update(ShopBindingModel model)
{ {
foreach (var shop in _source.Shops) foreach (var shop in _source.Shops)

View File

@ -28,7 +28,7 @@
/// </summary> /// </summary>
private void InitializeComponent() 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.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
@ -39,13 +39,13 @@
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// comboBoxShop // textBoxShop
// //
this.comboBoxShop.FormattingEnabled = true; this.textBoxShop.FormattingEnabled = true;
this.comboBoxShop.Location = new System.Drawing.Point(214, 17); this.textBoxShop.Location = new System.Drawing.Point(214, 17);
this.comboBoxShop.Name = "comboBoxShop"; this.textBoxShop.Name = "textBoxShop";
this.comboBoxShop.Size = new System.Drawing.Size(222, 23); this.textBoxShop.Size = new System.Drawing.Size(222, 23);
this.comboBoxShop.TabIndex = 3; this.textBoxShop.TabIndex = 3;
// //
// label1 // label1
// //
@ -127,7 +127,7 @@
this.Controls.Add(this.comboBoxPackage); this.Controls.Add(this.comboBoxPackage);
this.Controls.Add(this.label3); this.Controls.Add(this.label3);
this.Controls.Add(this.label2); this.Controls.Add(this.label2);
this.Controls.Add(this.comboBoxShop); this.Controls.Add(this.textBoxShop);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
this.Name = "FormAddPackageInShop"; this.Name = "FormAddPackageInShop";
this.Text = "форма добавления пакета в магазин"; this.Text = "форма добавления пакета в магазин";
@ -139,7 +139,7 @@
#endregion #endregion
private ComboBox comboBoxShop; private ComboBox textBoxShop;
private Label label1; private Label label1;
private Label label2; private Label label2;
private Label label3; private Label label3;

View File

@ -21,7 +21,7 @@ namespace SoftwareInstallationView
private readonly IShopLogic _shopLogic; private readonly IShopLogic _shopLogic;
private readonly IPackageLogic _packageLogic; private readonly IPackageLogic _packageLogic;
private readonly List<ShopViewModel>? _listShops; private readonly List<ShopViewModel>? _listShops;
private readonly List<PackageViewModel>? _listPastries; private readonly List<PackageViewModel>? _listPackages;
public FormAddPackageInShop(ILogger<FormAddPackageInShop> logger, IShopLogic shopLogic, IPackageLogic packageLogic) public FormAddPackageInShop(ILogger<FormAddPackageInShop> logger, IShopLogic shopLogic, IPackageLogic packageLogic)
{ {
@ -32,25 +32,25 @@ namespace SoftwareInstallationView
_listShops = shopLogic.ReadList(null); _listShops = shopLogic.ReadList(null);
if (_listShops != null) if (_listShops != null)
{ {
comboBoxShop.DisplayMember = "Name"; textBoxShop.DisplayMember = "Name";
comboBoxShop.ValueMember = "Id"; textBoxShop.ValueMember = "Id";
comboBoxShop.DataSource = _listShops; textBoxShop.DataSource = _listShops;
comboBoxShop.SelectedItem = null; textBoxShop.SelectedItem = null;
} }
_listPastries = packageLogic.ReadList(null); _listPackages = packageLogic.ReadList(null);
if (_listPastries != null) if (_listPackages != null)
{ {
comboBoxPackage.DisplayMember = "PackageName"; comboBoxPackage.DisplayMember = "PackageName";
comboBoxPackage.ValueMember= "Id"; comboBoxPackage.ValueMember= "Id";
comboBoxPackage.DataSource = _listPastries; comboBoxPackage.DataSource = _listPackages;
comboBoxPackage.SelectedItem = null; comboBoxPackage.SelectedItem = null;
} }
} }
private void ButtonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
{ {
if (comboBoxShop.SelectedValue == null) if (textBoxShop.SelectedValue == null)
{ {
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
@ -72,7 +72,7 @@ namespace SoftwareInstallationView
throw new Exception("Не найдено изделие. Дополнительная информация в логах."); throw new Exception("Не найдено изделие. Дополнительная информация в логах.");
} }
var resultOperation = _shopLogic.AddPackage( var resultOperation = _shopLogic.AddPackage(
model: new() { Id = (int)comboBoxShop.SelectedValue }, model: new() { Id = (int)textBoxShop.SelectedValue },
package: package, package: package,
count: (int)numericUpDownCount.Value count: (int)numericUpDownCount.Value
); );

View File

@ -32,6 +32,7 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.packageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.packageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentToolStripMenuItem = 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.ButtonRef = new System.Windows.Forms.Button();
this.ButtonIssuedOrder = new System.Windows.Forms.Button(); this.ButtonIssuedOrder = new System.Windows.Forms.Button();
this.ButtonOrderReady = new System.Windows.Forms.Button(); this.ButtonOrderReady = new System.Windows.Forms.Button();
@ -39,7 +40,7 @@
this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView(); this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonAddPackageInShop = new System.Windows.Forms.Button(); this.buttonAddPackageInShop = new System.Windows.Forms.Button();
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.buttonSellPackage = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@ -67,23 +68,30 @@
// packageToolStripMenuItem // packageToolStripMenuItem
// //
this.packageToolStripMenuItem.Name = "packageToolStripMenuItem"; this.packageToolStripMenuItem.Name = "packageToolStripMenuItem";
this.packageToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.packageToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.packageToolStripMenuItem.Text = "Изделия"; this.packageToolStripMenuItem.Text = "Изделия";
this.packageToolStripMenuItem.Click += new System.EventHandler(this.PackagesToolStripMenuItem_Click); this.packageToolStripMenuItem.Click += new System.EventHandler(this.PackagesToolStripMenuItem_Click);
// //
// componentToolStripMenuItem // componentToolStripMenuItem
// //
this.componentToolStripMenuItem.Name = "componentToolStripMenuItem"; this.componentToolStripMenuItem.Name = "componentToolStripMenuItem";
this.componentToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.componentToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.componentToolStripMenuItem.Text = "Компоненты"; this.componentToolStripMenuItem.Text = "Компоненты";
this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); 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 // ButtonRef
// //
this.ButtonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 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.Location = new System.Drawing.Point(966, 232);
this.ButtonRef.Name = "ButtonRef"; this.ButtonRef.Name = "ButtonRef";
this.ButtonRef.Size = new System.Drawing.Size(147, 55); this.ButtonRef.Size = new System.Drawing.Size(147, 42);
this.ButtonRef.TabIndex = 12; this.ButtonRef.TabIndex = 12;
this.ButtonRef.Text = "Обновить список"; this.ButtonRef.Text = "Обновить список";
this.ButtonRef.UseVisualStyleBackColor = true; this.ButtonRef.UseVisualStyleBackColor = true;
@ -92,9 +100,9 @@
// ButtonIssuedOrder // ButtonIssuedOrder
// //
this.ButtonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 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.Location = new System.Drawing.Point(966, 184);
this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; this.ButtonIssuedOrder.Name = "ButtonIssuedOrder";
this.ButtonIssuedOrder.Size = new System.Drawing.Size(147, 55); this.ButtonIssuedOrder.Size = new System.Drawing.Size(147, 42);
this.ButtonIssuedOrder.TabIndex = 11; this.ButtonIssuedOrder.TabIndex = 11;
this.ButtonIssuedOrder.Text = "Заказ выдан"; this.ButtonIssuedOrder.Text = "Заказ выдан";
this.ButtonIssuedOrder.UseVisualStyleBackColor = true; this.ButtonIssuedOrder.UseVisualStyleBackColor = true;
@ -103,9 +111,9 @@
// ButtonOrderReady // ButtonOrderReady
// //
this.ButtonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 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.Location = new System.Drawing.Point(966, 136);
this.ButtonOrderReady.Name = "ButtonOrderReady"; this.ButtonOrderReady.Name = "ButtonOrderReady";
this.ButtonOrderReady.Size = new System.Drawing.Size(147, 55); this.ButtonOrderReady.Size = new System.Drawing.Size(147, 42);
this.ButtonOrderReady.TabIndex = 10; this.ButtonOrderReady.TabIndex = 10;
this.ButtonOrderReady.Text = "Заказ готов"; this.ButtonOrderReady.Text = "Заказ готов";
this.ButtonOrderReady.UseVisualStyleBackColor = true; this.ButtonOrderReady.UseVisualStyleBackColor = true;
@ -116,7 +124,7 @@
this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 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.Location = new System.Drawing.Point(966, 88);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(147, 55); this.buttonTakeOrderInWork.Size = new System.Drawing.Size(147, 42);
this.buttonTakeOrderInWork.TabIndex = 9; this.buttonTakeOrderInWork.TabIndex = 9;
this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
@ -125,9 +133,9 @@
// buttonCreateOrder // buttonCreateOrder
// //
this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 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.Location = new System.Drawing.Point(966, 40);
this.buttonCreateOrder.Name = "buttonCreateOrder"; this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(147, 55); this.buttonCreateOrder.Size = new System.Drawing.Size(147, 42);
this.buttonCreateOrder.TabIndex = 8; this.buttonCreateOrder.TabIndex = 8;
this.buttonCreateOrder.Text = "Создать заказ"; this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true; this.buttonCreateOrder.UseVisualStyleBackColor = true;
@ -149,26 +157,31 @@
// buttonAddPackageInShop // buttonAddPackageInShop
// //
this.buttonAddPackageInShop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 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.Location = new System.Drawing.Point(966, 387);
this.buttonAddPackageInShop.Name = "buttonAddPackageInShop"; this.buttonAddPackageInShop.Name = "buttonAddPackageInShop";
this.buttonAddPackageInShop.Size = new System.Drawing.Size(147, 55); this.buttonAddPackageInShop.Size = new System.Drawing.Size(147, 42);
this.buttonAddPackageInShop.TabIndex = 13; this.buttonAddPackageInShop.TabIndex = 13;
this.buttonAddPackageInShop.Text = "Пополнение магазина"; this.buttonAddPackageInShop.Text = "Пополнение магазина";
this.buttonAddPackageInShop.UseVisualStyleBackColor = true; this.buttonAddPackageInShop.UseVisualStyleBackColor = true;
this.buttonAddPackageInShop.Click += new System.EventHandler(this.ButtonAddPackageInShop_Click); this.buttonAddPackageInShop.Click += new System.EventHandler(this.ButtonAddPackageInShop_Click);
// //
// магазиныToolStripMenuItem // buttonSellPackage
// //
this.магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem"; this.buttonSellPackage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.buttonSellPackage.Location = new System.Drawing.Point(966, 339);
this.магазиныToolStripMenuItem.Text = "Магазины"; this.buttonSellPackage.Name = "buttonSellPackage";
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); 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 // FormMain
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1125, 441); this.ClientSize = new System.Drawing.Size(1125, 441);
this.Controls.Add(this.buttonSellPackage);
this.Controls.Add(this.buttonAddPackageInShop); this.Controls.Add(this.buttonAddPackageInShop);
this.Controls.Add(this.ButtonRef); this.Controls.Add(this.ButtonRef);
this.Controls.Add(this.ButtonIssuedOrder); this.Controls.Add(this.ButtonIssuedOrder);
@ -179,6 +192,7 @@
this.Controls.Add(this.menuStrip1); this.Controls.Add(this.menuStrip1);
this.Name = "FormMain"; this.Name = "FormMain";
this.Text = "Установка ПО"; this.Text = "Установка ПО";
this.Load += new System.EventHandler(this.FormMain_Load);
this.menuStrip1.ResumeLayout(false); this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout(); this.menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
@ -201,5 +215,6 @@
private DataGridView dataGridView; private DataGridView dataGridView;
private ToolStripMenuItem магазиныToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem;
private Button buttonAddPackageInShop; private Button buttonAddPackageInShop;
private Button buttonSellPackage;
} }
} }

View File

@ -151,5 +151,13 @@ namespace SoftwareInstallationView
form.ShowDialog(); form.ShowDialog();
} }
} }
private void ButtonSellPackage_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellPackage));
if (service is FormSellPackage form)
{
form.ShowDialog();
}
}
} }
} }

View File

@ -0,0 +1,133 @@
namespace SoftwareInstallationView
{
partial class FormSellPackage
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -29,7 +29,6 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.comboBoxShop = new System.Windows.Forms.ComboBox();
this.dataGridView = new System.Windows.Forms.DataGridView(); this.dataGridView = new System.Windows.Forms.DataGridView();
this.PackageName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.PackageName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn();
@ -37,10 +36,14 @@
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
this.textBoxAddress = new System.Windows.Forms.TextBox(); this.textBoxAddress = new System.Windows.Forms.TextBox();
this.textBoxDateOpening = new System.Windows.Forms.TextBox();
this.buttonCancel = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = 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.dataGridView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxPackage)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// label1 // label1
@ -52,15 +55,6 @@
this.label1.TabIndex = 0; this.label1.TabIndex = 0;
this.label1.Text = "Название магазина:"; 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 // dataGridView
// //
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@ -106,7 +100,7 @@
// label3 // label3
// //
this.label3.AutoSize = true; this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(386, 9); this.label3.Location = new System.Drawing.Point(340, 9);
this.label3.Name = "label3"; this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(100, 15); this.label3.Size = new System.Drawing.Size(100, 15);
this.label3.TabIndex = 4; this.label3.TabIndex = 4;
@ -116,16 +110,9 @@
// //
this.textBoxAddress.Location = new System.Drawing.Point(159, 27); this.textBoxAddress.Location = new System.Drawing.Point(159, 27);
this.textBoxAddress.Name = "textBoxAddress"; this.textBoxAddress.Name = "textBoxAddress";
this.textBoxAddress.Size = new System.Drawing.Size(221, 23); this.textBoxAddress.Size = new System.Drawing.Size(175, 23);
this.textBoxAddress.TabIndex = 5; 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 // buttonCancel
// //
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@ -148,24 +135,62 @@
this.buttonSave.UseVisualStyleBackColor = true; this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); 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 // FormShop
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(607, 317); 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.buttonSave);
this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.textBoxDateOpening);
this.Controls.Add(this.textBoxAddress); this.Controls.Add(this.textBoxAddress);
this.Controls.Add(this.label3); this.Controls.Add(this.label3);
this.Controls.Add(this.label2); this.Controls.Add(this.label2);
this.Controls.Add(this.dataGridView); this.Controls.Add(this.dataGridView);
this.Controls.Add(this.comboBoxShop);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
this.Name = "FormShop"; this.Name = "FormShop";
this.Text = "Просмотр изделий магазина"; this.Text = "Просмотр изделий магазина";
this.Load += new System.EventHandler(this.FormShop_Load); this.Load += new System.EventHandler(this.FormShop_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxPackage)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -174,16 +199,18 @@
#endregion #endregion
private Label label1; private Label label1;
private ComboBox comboBoxShop;
private DataGridView dataGridView; private DataGridView dataGridView;
private Label label2; private Label label2;
private Label label3; private Label label3;
private TextBox textBoxAddress; private TextBox textBoxAddress;
private TextBox textBoxDateOpening;
private Button buttonCancel; private Button buttonCancel;
private Button buttonSave; private Button buttonSave;
private DataGridViewTextBoxColumn PackageName; private DataGridViewTextBoxColumn PackageName;
private DataGridViewTextBoxColumn Price; private DataGridViewTextBoxColumn Price;
private DataGridViewTextBoxColumn Count; private DataGridViewTextBoxColumn Count;
private NumericUpDown numericUpDownMaxPackage;
private Label label4;
private DateTimePicker textBoxDateOpening;
private TextBox textBoxShop;
} }
} }

View File

@ -51,27 +51,21 @@ namespace SoftwareInstallationView
_logger = logger; _logger = logger;
_listShops = logic.ReadList(null); _listShops = logic.ReadList(null);
_logic = logic; _logic = logic;
if (_listShops != null)
{
comboBoxShop.DisplayMember = "Name";
comboBoxShop.ValueMember = "Id";
comboBoxShop.DataSource = _listShops;
comboBoxShop.SelectedItem = null;
}
} }
private void LoadData(bool extendDate = true) private void LoadData(bool extendDate = true)
{ {
try try
{ {
var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.SelectedValue)); var model = GetShop(extendDate ? Id : Convert.ToInt32(null));
if (model != null) if (model != null)
{ {
comboBoxShop.Text = model.Name; numericUpDownMaxPackage.Value = model.MaxCountPackages;
textBoxShop.Text = model.Name;
textBoxAddress.Text = model.Address; textBoxAddress.Text = model.Address;
textBoxDateOpening.Text = Convert.ToString(model.DateOpening); textBoxDateOpening.Text = Convert.ToString(model.DateOpening);
dataGridView.Rows.Clear(); 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 }); 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) private void ButtonSave_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(comboBoxShop.Text)) if (string.IsNullOrEmpty(textBoxShop.Text))
{ {
MessageBox.Show("Заполните название", "Ошибка", MessageBox.Show("Заполните название", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
@ -111,9 +105,10 @@ namespace SoftwareInstallationView
DateTime.TryParse(textBoxDateOpening.Text, out var dateTime); DateTime.TryParse(textBoxDateOpening.Text, out var dateTime);
ShopBindingModel model = new() ShopBindingModel model = new()
{ {
Name = comboBoxShop.Text, Name = textBoxShop.Text,
Address = textBoxAddress.Text, Address = textBoxAddress.Text,
DateOpening = dateTime DateOpening = dateTime,
MaxCountPackages = (int)numericUpDownMaxPackage.Value,
}; };
var vmodel = GetShop(Id); var vmodel = GetShop(Id);
bool operationResult = false; bool operationResult = false;

View File

@ -28,7 +28,7 @@ namespace SoftwareInstallationView
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["Pastries"].Visible = false; dataGridView.Columns["Packages"].Visible = false;
dataGridView.Columns["Name"].AutoSizeMode = dataGridView.Columns["Name"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill; DataGridViewAutoSizeColumnMode.Fill;
} }

View File

@ -1,14 +1,13 @@
using SoftwareInstallationBusinessLogic.BusinessLogics; using SoftwareInstallationBusinessLogic.BusinessLogics;
using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.BusinessLogicsContracts;
using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.StoragesContracts;
using SoftwareInstallationListImplement.Implements; using SoftwareInstallationFileImplement;
using SoftwareInstallationListImplement; using SoftwareInstallationFileImplement.Implements;
using SoftwareInstallationBusinessLogic; using SoftwareInstallationBusinessLogic;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
namespace SoftwareInstallationView namespace SoftwareInstallationView
{ {
internal static class Program internal static class Program
@ -54,6 +53,7 @@ namespace SoftwareInstallationView
services.AddTransient<FormAddPackageInShop>(); services.AddTransient<FormAddPackageInShop>();
services.AddTransient<FormViewShops>(); services.AddTransient<FormViewShops>();
services.AddTransient<FormShop>(); services.AddTransient<FormShop>();
services.AddTransient<FormSellPackage>();
} }
} }
} }

View File

@ -18,6 +18,7 @@
<ProjectReference Include="..\SoftwareInstallationBusinessLogic\SoftwareInstallationBusinessLogic.csproj" /> <ProjectReference Include="..\SoftwareInstallationBusinessLogic\SoftwareInstallationBusinessLogic.csproj" />
<ProjectReference Include="..\SoftwareInstallationContracts\SoftwareInstallationContracts.csproj" /> <ProjectReference Include="..\SoftwareInstallationContracts\SoftwareInstallationContracts.csproj" />
<ProjectReference Include="..\SoftwareInstallationDataModels\SoftwareInstallationDataModels.csproj" /> <ProjectReference Include="..\SoftwareInstallationDataModels\SoftwareInstallationDataModels.csproj" />
<ProjectReference Include="..\SoftWareInstallationFileImplement\SoftWareInstallationFileImplement.csproj" />
<ProjectReference Include="..\SoftwareInstallationListImplement\SoftwareInstallationListImplement.csproj" /> <ProjectReference Include="..\SoftwareInstallationListImplement\SoftwareInstallationListImplement.csproj" />
</ItemGroup> </ItemGroup>