7 Commits

Author SHA1 Message Date
fffe836607 я гей 2023-04-03 18:03:56 +04:00
dd52116f62 z utq 2023-04-03 18:01:26 +04:00
f38d94afa8 fix 2023-03-19 02:27:22 +04:00
aba6593945 Lab2_Hard 2023-03-18 01:08:33 +04:00
35856195e8 fix 2023-03-18 00:29:38 +04:00
47eb037c61 fix 2023-03-06 20:44:20 +04:00
9c846fdaed Lab1_Hard 2023-03-06 00:18:18 +04:00
43 changed files with 2316 additions and 237 deletions

View File

@@ -3,6 +3,7 @@ using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels.Models; using SoftwareInstallationDataModels.Models;
using System.Xml.Linq; using System.Xml.Linq;
namespace SoftwareInstallationFileImplement.Models namespace SoftwareInstallationFileImplement.Models
{ {
public class Component : IComponentModel public class Component : IComponentModel
@@ -10,7 +11,7 @@ namespace SoftwareInstallationFileImplement.Models
public int Id { get; private set; } public int Id { get; private set; }
public string ComponentName { get; private set; } = string.Empty; public string ComponentName { get; private set; } = string.Empty;
public double Cost { get; set; } public double Cost { get; set; }
public static Component? Create(ComponentBindingModel? model) public static Component? Create(ComponentBindingModel model)
{ {
if (model == null) if (model == null)
{ {
@@ -36,7 +37,7 @@ namespace SoftwareInstallationFileImplement.Models
Cost = Convert.ToDouble(element.Element("Cost")!.Value) Cost = Convert.ToDouble(element.Element("Cost")!.Value)
}; };
} }
public void Update(ComponentBindingModel? model) public void Update(ComponentBindingModel model)
{ {
if (model == null) if (model == null)
{ {

View File

@@ -8,14 +8,16 @@ namespace SoftwareInstallationFileImplement.Implements
{ {
public class ComponentStorage : IComponentStorage public class ComponentStorage : IComponentStorage
{ {
private readonly DataFileSingleton source; private readonly DataFileSingleton _source;
public ComponentStorage() public ComponentStorage()
{ {
source = DataFileSingleton.GetInstance(); _source = DataFileSingleton.GetInstance();
} }
public List<ComponentViewModel> GetFullList() public List<ComponentViewModel> GetFullList()
{ {
return source.Components.Select(x => x.GetViewModel).ToList(); return _source.Components
.Select(x => x.GetViewModel)
.ToList();
} }
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model) public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{ {
@@ -23,7 +25,10 @@ namespace SoftwareInstallationFileImplement.Implements
{ {
return new(); return new();
} }
return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList(); return _source.Components
.Where(x => x.ComponentName.Contains(model.ComponentName))
.Select(x => x.GetViewModel)
.ToList();
} }
public ComponentViewModel? GetElement(ComponentSearchModel model) public ComponentViewModel? GetElement(ComponentSearchModel model)
{ {
@@ -31,42 +36,41 @@ namespace SoftwareInstallationFileImplement.Implements
{ {
return null; return null;
} }
return source.Components.FirstOrDefault(x => return _source.Components.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ComponentName) && (!string.IsNullOrEmpty(model.ComponentName) &&
x.ComponentName == model.ComponentName) || x.ComponentName == model.ComponentName) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel; (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
} }
public ComponentViewModel? Insert(ComponentBindingModel model) public ComponentViewModel? Insert(ComponentBindingModel model)
{ {
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; model.Id = _source.Components.Count > 0 ? _source.Components.Max(x => x.Id) + 1 : 1;
var newComponent = Component.Create(model); var newComponent = Component.Create(model);
if (newComponent == null) if (newComponent == null)
{ {
return null; return null;
} }
source.Components.Add(newComponent); _source.Components.Add(newComponent);
source.SaveComponents(); _source.SaveComponents();
return newComponent.GetViewModel; return newComponent.GetViewModel;
} }
public ComponentViewModel? Update(ComponentBindingModel model) public ComponentViewModel? Update(ComponentBindingModel model)
{ {
var component = source.Components.FirstOrDefault(x => x.Id == model.Id); var component = _source.Components.FirstOrDefault(x => x.Id == model.Id);
if (component == null) if (component == null)
{ {
return null; return null;
} }
component.Update(model); component.Update(model);
source.SaveComponents(); _source.SaveComponents();
return component.GetViewModel; return component.GetViewModel;
} }
public ComponentViewModel? Delete(ComponentBindingModel model) public ComponentViewModel? Delete(ComponentBindingModel model)
{ {
var element = source.Components.FirstOrDefault(x => x.Id == model.Id); var element = _source.Components.FirstOrDefault(x => x.Id == model.Id);
if (element != null) if (element != null)
{ {
source.Components.Remove(element); _source.Components.Remove(element);
source.SaveComponents(); _source.SaveComponents();
return element.GetViewModel; return element.GetViewModel;
} }
return null; return null;

View File

@@ -9,9 +9,11 @@ namespace SoftwareInstallationFileImplement
private readonly string ComponentFileName = "Component.xml"; private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml"; private readonly string OrderFileName = "Order.xml";
private readonly string PackageFileName = "Package.xml"; private readonly string PackageFileName = "Package.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Component> Components { get; private set; } public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; } public List<Order> Orders { get; private set; }
public List<Package> Packages { get; private set; } public List<Package> Packages { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance() public static DataFileSingleton GetInstance()
{ {
@@ -21,21 +23,23 @@ namespace SoftwareInstallationFileImplement
} }
return instance; return instance;
} }
public void SaveComponents() => SaveData(Components, ComponentFileName,"Components", x => x.GetXElement); public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SavePackages() => SaveData(Packages, PackageFileName, "Packages", 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 SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
private DataFileSingleton() private DataFileSingleton()
{ {
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Packages = LoadData(PackageFileName, "Package", x => Package.Create(x)!)!; Packages = LoadData(PackageFileName, "Package", x => Package.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.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) private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{ {
if (File.Exists(filename)) if (File.Exists(filename))
{ {
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
} }
return new List<T>(); return new List<T>();
} }
@@ -47,4 +51,4 @@ namespace SoftwareInstallationFileImplement
} }
} }
} }
} }

View File

@@ -1,26 +0,0 @@
using SoftwareInstallationFileImplement.Models;
namespace SoftwareInstallationFileImplement
{
public class DataListSingleton
{
private static DataListSingleton? _instance;
public List<Component> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Package> Packages { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Packages = new List<Package>();
}
public static DataListSingleton GetInstance()
{
if (_instance == null)
{
_instance = new DataListSingleton();
}
return _instance;
}
}
}

View File

@@ -1,13 +1,15 @@
using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels.Models;
using SoftwareInstallationDataModels.Enums; using SoftwareInstallationDataModels.Enums;
using SoftwareInstallationDataModels.Models;
using System.Xml.Linq; using System.Xml.Linq;
namespace SoftwareInstallationFileImplement.Models namespace SoftwareInstallationFileImplement.Models
{ {
public class Order : IOrderModel public class Order : IOrderModel
{ {
public int Id { get; private set; }
public int PackageId { get; private set; } public int PackageId { get; private set; }
public int Count { get; private set; } public int Count { get; private set; }
@@ -20,8 +22,6 @@ namespace SoftwareInstallationFileImplement.Models
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
public int Id { get; private set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)
{ {
if (model == null) if (model == null)
@@ -39,7 +39,6 @@ namespace SoftwareInstallationFileImplement.Models
Id = model.Id, Id = model.Id,
}; };
} }
public static Order? Create(XElement element) public static Order? Create(XElement element)
{ {
if (element == null) if (element == null)
@@ -49,12 +48,12 @@ namespace SoftwareInstallationFileImplement.Models
var dateImplement = element.Element("DateImplement")!.Value; var dateImplement = element.Element("DateImplement")!.Value;
return new() return new()
{ {
Id = Convert.ToInt32(element.Attribute("Id")!.Value), Id = Convert.ToInt32(element.Attribute("Id")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value),
Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value), Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
PackageId = Convert.ToInt32(element.Element("PackageId")!.Value), PackageId = Convert.ToInt32(element.Element("PackageId")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement), DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement),
}; };
} }
@@ -65,10 +64,14 @@ namespace SoftwareInstallationFileImplement.Models
{ {
return; return;
} }
PackageId = model.PackageId;
Count = model.Count;
Sum = model.Sum;
Status = model.Status; Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
Id = model.Id;
} }
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
{ {
PackageName = DataFileSingleton.GetInstance().Packages.FirstOrDefault(x => x.Id == PackageId)?.PackageName ?? string.Empty, PackageName = DataFileSingleton.GetInstance().Packages.FirstOrDefault(x => x.Id == PackageId)?.PackageName ?? string.Empty,
@@ -90,4 +93,4 @@ namespace SoftwareInstallationFileImplement.Models
new XElement("DateImplement", DateImplement) new XElement("DateImplement", DateImplement)
); );
} }
} }

View File

@@ -4,7 +4,7 @@ using SoftwareInstallationContracts.StoragesContracts;
using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationFileImplement.Models; using SoftwareInstallationFileImplement.Models;
namespace SoftwareInstallationFileImplement.Implements namespace SoftwareInstallationFileImplement
{ {
public class OrderStorage : IOrderStorage public class OrderStorage : IOrderStorage
{ {
@@ -13,6 +13,7 @@ namespace SoftwareInstallationFileImplement.Implements
{ {
_source = DataFileSingleton.GetInstance(); _source = DataFileSingleton.GetInstance();
} }
public OrderViewModel? Delete(OrderBindingModel model) public OrderViewModel? Delete(OrderBindingModel model)
{ {
var element = _source.Orders.FirstOrDefault(x => x.Id == model.Id); var element = _source.Orders.FirstOrDefault(x => x.Id == model.Id);
@@ -24,6 +25,7 @@ namespace SoftwareInstallationFileImplement.Implements
} }
return null; return null;
} }
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue)
@@ -32,15 +34,20 @@ namespace SoftwareInstallationFileImplement.Implements
} }
return _source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; return _source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
var result = GetElement(model); var result = GetElement(model);
return result != null ? new() { result } : new(); return result != null ? new() { result } : new();
} }
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
return _source.Orders.Select(x => x.GetViewModel).ToList(); return _source.Orders
.Select(x => x.GetViewModel)
.ToList();
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
{ {
model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 1; model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 1;
@@ -53,6 +60,7 @@ namespace SoftwareInstallationFileImplement.Implements
_source.SaveOrders(); _source.SaveOrders();
return newOrder.GetViewModel; return newOrder.GetViewModel;
} }
public OrderViewModel? Update(OrderBindingModel model) public OrderViewModel? Update(OrderBindingModel model)
{ {
var order = _source.Orders.FirstOrDefault(x => x.Id == model.Id); var order = _source.Orders.FirstOrDefault(x => x.Id == model.Id);
@@ -65,4 +73,4 @@ namespace SoftwareInstallationFileImplement.Implements
return order.GetViewModel; return order.GetViewModel;
} }
} }
} }

View File

@@ -3,7 +3,6 @@ using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels.Models; using SoftwareInstallationDataModels.Models;
using System.Xml.Linq; using System.Xml.Linq;
namespace SoftwareInstallationFileImplement.Models namespace SoftwareInstallationFileImplement.Models
{ {
public class Package : IPackageModel public class Package : IPackageModel
@@ -12,23 +11,22 @@ namespace SoftwareInstallationFileImplement.Models
public string PackageName { get; private set; } = string.Empty; public string PackageName { get; private set; } = string.Empty;
public double Price { get; private set; } public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new(); public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)>? _packageComponents = null; private Dictionary<int, (IComponentModel, int)>? _PackageComponents = null;
public Dictionary<int, (IComponentModel, int)> PackageComponents public Dictionary<int, (IComponentModel, int)> PackageComponents
{ {
get get
{ {
if (_packageComponents == null) if (_PackageComponents == null)
{ {
var source = DataFileSingleton.GetInstance(); var source = DataFileSingleton.GetInstance();
_packageComponents = Components.ToDictionary(x => x.Key, y => _PackageComponents = Components.ToDictionary(x => x.Key, y =>
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
y.Value)); y.Value));
} }
return _packageComponents; return _PackageComponents;
} }
} }
public static Package? Create(PackageBindingModel model)
public static Package? Create(PackageBindingModel? model)
{ {
if (model == null) if (model == null)
{ {
@@ -39,8 +37,7 @@ namespace SoftwareInstallationFileImplement.Models
Id = model.Id, Id = model.Id,
PackageName = model.PackageName, PackageName = model.PackageName,
Price = model.Price, Price = model.Price,
Components = model.PackageComponents.ToDictionary(x => x.Key, x Components = model.PackageComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
=> x.Value.Item2)
}; };
} }
public static Package? Create(XElement element) public static Package? Create(XElement element)
@@ -55,11 +52,11 @@ namespace SoftwareInstallationFileImplement.Models
PackageName = element.Element("PackageName")!.Value, PackageName = element.Element("PackageName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value), Price = Convert.ToDouble(element.Element("Price")!.Value),
Components = element.Element("PackageComponents")!.Elements("PackageComponent").ToDictionary(x => Components = element.Element("PackageComponents")!.Elements("PackageComponent").ToDictionary(x =>
Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Key")?.Value), x =>
Convert.ToInt32(x.Element("Value")?.Value)) Convert.ToInt32(x.Element("Value")?.Value))
}; };
} }
public void Update(PackageBindingModel? model) public void Update(PackageBindingModel model)
{ {
if (model == null) if (model == null)
{ {
@@ -68,7 +65,7 @@ namespace SoftwareInstallationFileImplement.Models
PackageName = model.PackageName; PackageName = model.PackageName;
Price = model.Price; Price = model.Price;
Components = model.PackageComponents.ToDictionary(x => x.Key, x => x.Value.Item2); Components = model.PackageComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
_packageComponents = null; _PackageComponents = null;
} }
public PackageViewModel GetViewModel => new() public PackageViewModel GetViewModel => new()
{ {
@@ -77,7 +74,7 @@ namespace SoftwareInstallationFileImplement.Models
Price = Price, Price = Price,
PackageComponents = PackageComponents PackageComponents = PackageComponents
}; };
public XElement GetXElement => new("Package", public XElement GetXElement => new("Package",
new XAttribute("Id", Id), new XAttribute("Id", Id),
new XElement("PackageName", PackageName), new XElement("PackageName", PackageName),
new XElement("Price", Price.ToString()), new XElement("Price", Price.ToString()),

View File

@@ -4,7 +4,7 @@ using SoftwareInstallationContracts.StoragesContracts;
using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationFileImplement.Models; using SoftwareInstallationFileImplement.Models;
namespace SoftwareInstallationFileImplement.Implements namespace SoftwareInstallationFileImplement
{ {
public class PackageStorage : IPackageStorage public class PackageStorage : IPackageStorage
{ {
@@ -32,10 +32,10 @@ namespace SoftwareInstallationFileImplement.Implements
{ {
return null; return null;
} }
return _source.Packages.FirstOrDefault(x => return _source.Packages.FirstOrDefault
(!string.IsNullOrEmpty(model.PackageName) && (x => (!string.IsNullOrEmpty(model.PackageName) && x.PackageName == model.PackageName) ||
x.PackageName == model.PackageName) || (model.Id.HasValue && x.Id == model.Id)
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel; )?.GetViewModel;
} }
public List<PackageViewModel> GetFilteredList(PackageSearchModel model) public List<PackageViewModel> GetFilteredList(PackageSearchModel model)
@@ -82,4 +82,4 @@ namespace SoftwareInstallationFileImplement.Implements
return package.GetViewModel; 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

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>

View File

@@ -1,9 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -13,7 +13,7 @@ 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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SoftwareInstallationFileImplement", "SoftWareInstallationFileImplement\SoftwareInstallationFileImplement.csproj", "{AF966DC2-6172-49DE-97EE-525EF00EBC67}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftWareInstallationFileImplement", "SoftWareInstallationFileImplement\SoftWareInstallationFileImplement.csproj", "{B2816D6F-A74D-4533-8F37-3217FB028243}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -41,10 +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
{AF966DC2-6172-49DE-97EE-525EF00EBC67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B2816D6F-A74D-4533-8F37-3217FB028243}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF966DC2-6172-49DE-97EE-525EF00EBC67}.Debug|Any CPU.Build.0 = Debug|Any CPU {B2816D6F-A74D-4533-8F37-3217FB028243}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF966DC2-6172-49DE-97EE-525EF00EBC67}.Release|Any CPU.ActiveCfg = Release|Any CPU {B2816D6F-A74D-4533-8F37-3217FB028243}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF966DC2-6172-49DE-97EE-525EF00EBC67}.Release|Any CPU.Build.0 = 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

@@ -0,0 +1,215 @@
using SoftwareInstallationBusinessLogic.BusinessLogics;
using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.BusinessLogicsContracts;
using SoftwareInstallationContracts.SearchModels;
using SoftwareInstallationContracts.StoragesContracts;
using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels.Models;
using Microsoft.Extensions.Logging;
namespace SoftwareInstallationBusinessLogic
{
public class ShopLogic : IShopLogic
{
private readonly ILogger _logger;
private readonly IShopStorage _shopStorage;
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage)
{
_logger = logger;
_shopStorage = shopStorage;
}
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
{
_logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id} ",
model?.Name, model?.Id);
var list = (model == null) ? _shopStorage.GetFullList() :
_shopStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ShopViewModel? ReadElement(ShopSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}",
model.Name, model.Id);
var element = _shopStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(ShopBindingModel model)
{
CheckModel(model);
model.Packages = new();
if (_shopStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ShopBindingModel model)
{
CheckModel(model, false);
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Нет названия магазина",
nameof(model.Name));
}
if (_shopStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ShopBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_shopStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ShopBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Name))
{
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
{
Name = model.Name
});
if (element != null && element.Id != model.Id && element.Name == model.Name)
{
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
public bool AddPackage(ShopSearchModel model, IPackageModel package, int count)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (count <= 0)
{
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.First().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.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);
_shopStorage.Update(new()
{
Id = element.Id,
Address = element.Address,
Name = element.Name,
DateOpening = element.DateOpening,
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);
}
}
}

View File

@@ -0,0 +1,23 @@
using SoftwareInstallationDataModels;
using SoftwareInstallationDataModels.Models;
namespace SoftwareInstallationContracts.BindingModels
{
public class ShopBindingModel : IShopModel
{
public string Name { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public DateTime DateOpening { get; set; } = DateTime.Now;
public Dictionary<int, (IPackageModel, int)> Packages
{
get;
set;
} = new();
public int Id { get; set; }
public int MaxCountPackages { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.SearchModels;
using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels.Models;
namespace SoftwareInstallationContracts.BusinessLogicsContracts
{
public interface IShopLogic
{
List<ShopViewModel>? ReadList(ShopSearchModel? model);
ShopViewModel? ReadElement(ShopSearchModel model);
bool Create(ShopBindingModel model);
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);
}
}

View File

@@ -0,0 +1,9 @@

namespace SoftwareInstallationContracts.SearchModels
{
public class ShopSearchModel
{
public int? Id { get; set; }
public string? Name { get; set; }
}
}

View File

@@ -0,0 +1,19 @@
using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.SearchModels;
using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels.Models;
namespace SoftwareInstallationContracts.StoragesContracts
{
public interface IShopStorage
{
List<ShopViewModel> GetFullList();
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
ShopViewModel? GetElement(ShopSearchModel model);
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
public bool SellPackages(IPackageModel package, int needCount);
}
}

View File

@@ -0,0 +1,29 @@
using SoftwareInstallationDataModels;
using SoftwareInstallationDataModels.Models;
using System.ComponentModel;
namespace SoftwareInstallationContracts.ViewModels
{
public class ShopViewModel : IShopModel
{
[DisplayName("Название магазина")]
public string Name { get; set; } = string.Empty;
[DisplayName("Адрес магазина")]
public string Address { get; set; } = string.Empty;
[DisplayName("Максимальное количество изделий в магазине")]
public int MaxCountPackages { get; set; }
[DisplayName("Время открытия")]
public DateTime DateOpening { get; set; } = DateTime.Now;
public Dictionary<int, (IPackageModel, int)> Packages
{
get;
set;
} = new();
public int Id { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using SoftwareInstallationDataModels.Models;
namespace SoftwareInstallationDataModels
{
public interface IShopModel : IId
{
string Name { get; }
string Address { get; }
int MaxCountPackages { get; }
DateTime DateOpening { get; }
Dictionary<int, (IPackageModel, int)> Packages { get; }
}
}

View File

@@ -8,11 +8,13 @@ namespace SoftwareInstallationListImplement
public List<Component> Components { get; set; } public List<Component> Components { get; set; }
public List<Order> Orders { get; set; } public List<Order> Orders { get; set; }
public List<Package> Packages { get; set; } public List<Package> Packages { get; set; }
public List<Shop> Shops { get; set; }
private DataListSingleton() private DataListSingleton()
{ {
Components = new List<Component>(); Components = new List<Component>();
Orders = new List<Order>(); Orders = new List<Order>();
Packages = new List<Package>(); Packages = new List<Package>();
Shops = new List<Shop>();
} }
public static DataListSingleton GetInstance() public static DataListSingleton GetInstance()
{ {

View File

@@ -0,0 +1,64 @@
using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels;
using SoftwareInstallationDataModels.Models;
namespace SoftwareInstallationListImplement
{
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, (IPackageModel, int)> Packages
{
get;
private set;
} = new();
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,
Packages = new()
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
Name = model.Name;
Address = model.Address;
DateOpening = model.DateOpening;
MaxCountPackages = model.MaxCountPackages;
Packages = model.Packages;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Address = Address,
Packages = Packages,
DateOpening = DateOpening,
MaxCountPackages = MaxCountPackages,
};
}
}

View File

@@ -0,0 +1,118 @@
using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.SearchModels;
using SoftwareInstallationContracts.StoragesContracts;
using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels.Models;
namespace SoftwareInstallationListImplement
{
public class ShopStorage : IShopStorage
{
private readonly DataListSingleton _source;
public ShopStorage()
{
_source = DataListSingleton.GetInstance();
}
public ShopViewModel? Delete(ShopBindingModel model)
{
for (int i = 0; i < _source.Shops.Count; ++i)
{
if (_source.Shops[i].Id == model.Id)
{
var element = _source.Shops[i];
_source.Shops.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
foreach (var shop in _source.Shops)
{
if ((!string.IsNullOrEmpty(model.Name) &&
shop.Name == model.Name) ||
(model.Id.HasValue && shop.Id == model.Id))
{
return shop.GetViewModel;
}
}
return null;
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
var result = new List<ShopViewModel>();
if (string.IsNullOrEmpty(model.Name))
{
return result;
}
foreach (var shop in _source.Shops)
{
if (shop.Name.Contains(model.Name ?? string.Empty))
{
result.Add(shop.GetViewModel);
}
}
return result;
}
public List<ShopViewModel> GetFullList()
{
var result = new List<ShopViewModel>();
foreach (var shop in _source.Shops)
{
result.Add(shop.GetViewModel);
}
return result;
}
public bool HasNeedPackages(IPackageModel package, int needCount)
{
throw new NotImplementedException();
}
public ShopViewModel? Insert(ShopBindingModel model)
{
model.Id = 1;
foreach (var shop in _source.Shops)
{
if (model.Id <= shop.Id)
{
model.Id = shop.Id + 1;
}
}
var newShop = Shop.Create(model);
if (newShop == null)
{
return null;
}
_source.Shops.Add(newShop);
return newShop.GetViewModel;
}
public bool SellPackages(IPackageModel package, int needCount)
{
throw new NotImplementedException();
}
public ShopViewModel? Update(ShopBindingModel model)
{
foreach (var shop in _source.Shops)
{
if (shop.Id == model.Id)
{
shop.Update(model);
return shop.GetViewModel;
}
}
return null;
}
}
}

View File

@@ -0,0 +1,151 @@
namespace SoftwareInstallationView
{
partial class FormAddPackageInShop
{
/// <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.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();
this.textBoxPackage = new System.Windows.Forms.ComboBox();
this.numericUpDownCount = new System.Windows.Forms.NumericUpDown();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit();
this.SuspendLayout();
//
// textBoxShop
//
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
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(84, 20);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(124, 15);
this.label1.TabIndex = 2;
this.label1.Text = "Выбранный магазин:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 47);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(196, 15);
this.label2.TabIndex = 4;
this.label2.Text = "Изделие которое нужно добавить:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(133, 73);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(75, 15);
this.label3.TabIndex = 5;
this.label3.Text = "Количество:";
//
// comboBoxPackage
//
this.textBoxPackage.FormattingEnabled = true;
this.textBoxPackage.Location = new System.Drawing.Point(214, 44);
this.textBoxPackage.Name = "comboBoxPackage";
this.textBoxPackage.Size = new System.Drawing.Size(222, 23);
this.textBoxPackage.TabIndex = 6;
//
// numericUpDownCount
//
this.numericUpDownCount.Location = new System.Drawing.Point(215, 71);
this.numericUpDownCount.Maximum = new decimal(new int[] {
1410065408,
2,
0,
0});
this.numericUpDownCount.Name = "numericUpDownCount";
this.numericUpDownCount.Size = new System.Drawing.Size(221, 23);
this.numericUpDownCount.TabIndex = 7;
//
// 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(280, 123);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 8;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_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(361, 123);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 9;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormAddPackageInShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(448, 158);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.numericUpDownCount);
this.Controls.Add(this.textBoxPackage);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBoxShop);
this.Controls.Add(this.label1);
this.Name = "FormAddPackageInShop";
this.Text = "форма добавления пакета в магазин";
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private ComboBox textBoxShop;
private Label label1;
private Label label2;
private Label label3;
private ComboBox textBoxPackage;
private NumericUpDown numericUpDownCount;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@@ -0,0 +1,101 @@
using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.BusinessLogicsContracts;
using SoftwareInstallationContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SoftwareInstallationView
{
public partial class FormAddPackageInShop : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _shopLogic;
private readonly IPackageLogic _packageLogic;
private readonly List<ShopViewModel>? _listShops;
private readonly List<PackageViewModel>? _listPackages;
public FormAddPackageInShop(ILogger<FormAddPackageInShop> logger, IShopLogic shopLogic, IPackageLogic packageLogic)
{
InitializeComponent();
_shopLogic = shopLogic;
_packageLogic = packageLogic;
_logger = logger;
_listShops = shopLogic.ReadList(null);
if (_listShops != null)
{
textBoxShop.DisplayMember = "Name";
textBoxShop.ValueMember = "Id";
textBoxShop.DataSource = _listShops;
textBoxShop.SelectedItem = null;
}
_listPackages = packageLogic.ReadList(null);
if (_listPackages != null)
{
textBoxPackage.DisplayMember = "PackageName";
textBoxPackage.ValueMember= "Id";
textBoxPackage.DataSource = _listPackages;
textBoxPackage.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (textBoxShop.SelectedValue == null)
{
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (textBoxPackage.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Добавление изделия в магазин");
try
{
var package = _packageLogic.ReadElement(new()
{
Id = (int)textBoxPackage.SelectedValue
});
if (package == null)
{
throw new Exception("Не найдено изделие. Дополнительная информация в логах.");
}
var resultOperation = _shopLogic.AddPackage(
model: new() { Id = (int)textBoxShop.SelectedValue },
package: package,
count: (int)numericUpDownCount.Value
);
if (!resultOperation)
{
throw new Exception("Ошибка при добавлении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

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

@@ -102,7 +102,6 @@
this.Controls.Add(this.buttonAdd); this.Controls.Add(this.buttonAdd);
this.Name = "FormComponents"; this.Name = "FormComponents";
this.Text = "Компоненты"; this.Text = "Компоненты";
this.Load += new System.EventHandler(this.FormComponents_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@@ -41,8 +41,7 @@ namespace SoftwareInstallationView
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
var service = var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent form) if (service is FormComponent form)
{ {
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)

View File

@@ -28,141 +28,176 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.menuStrip1 = new System.Windows.Forms.MenuStrip();
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.ButtonRef = new System.Windows.Forms.Button(); this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ButtonIssuedOrder = new System.Windows.Forms.Button(); this.ButtonRef = new System.Windows.Forms.Button();
this.ButtonOrderReady = new System.Windows.Forms.Button(); this.ButtonIssuedOrder = new System.Windows.Forms.Button();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); this.ButtonOrderReady = new System.Windows.Forms.Button();
this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout(); this.dataGridView = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.buttonAddPackageInShop = new System.Windows.Forms.Button();
this.SuspendLayout(); this.buttonSellPackage = new System.Windows.Forms.Button();
// this.menuStrip1.SuspendLayout();
// menuStrip1 ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
// this.SuspendLayout();
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { //
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникиToolStripMenuItem}); this.справочникиToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1125, 24); this.menuStrip1.Size = new System.Drawing.Size(1125, 24);
this.menuStrip1.TabIndex = 1; this.menuStrip1.TabIndex = 1;
this.menuStrip1.Text = "menuStrip1"; this.menuStrip1.Text = "menuStrip1";
// //
// справочникиToolStripMenuItem // справочникиToolStripMenuItem
// //
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.packageToolStripMenuItem, this.packageToolStripMenuItem,
this.componentToolStripMenuItem}); this.componentToolStripMenuItem,
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.магазиныToolStripMenuItem});
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Text = "Справочники"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
// this.справочникиToolStripMenuItem.Text = "Справочники";
// packageToolStripMenuItem //
// // packageToolStripMenuItem
this.packageToolStripMenuItem.Name = "packageToolStripMenuItem"; //
this.packageToolStripMenuItem.Size = new System.Drawing.Size(145, 22); this.packageToolStripMenuItem.Name = "packageToolStripMenuItem";
this.packageToolStripMenuItem.Text = "Изделия"; this.packageToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.packageToolStripMenuItem.Click += new System.EventHandler(this.PackagesToolStripMenuItem_Click); this.packageToolStripMenuItem.Text = "Изделия";
// this.packageToolStripMenuItem.Click += new System.EventHandler(this.PackagesToolStripMenuItem_Click);
// componentToolStripMenuItem //
// // componentToolStripMenuItem
this.componentToolStripMenuItem.Name = "componentToolStripMenuItem"; //
this.componentToolStripMenuItem.Size = new System.Drawing.Size(145, 22); this.componentToolStripMenuItem.Name = "componentToolStripMenuItem";
this.componentToolStripMenuItem.Text = "Компоненты"; this.componentToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); this.componentToolStripMenuItem.Text = "Компоненты";
// this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
// ButtonRef //
// // магазиныToolStripMenuItem
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, 374); this.магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
this.ButtonRef.Name = "ButtonRef"; this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.ButtonRef.Size = new System.Drawing.Size(147, 55); this.магазиныToolStripMenuItem.Text = "Магазины";
this.ButtonRef.TabIndex = 12; this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click);
this.ButtonRef.Text = "Обновить список"; //
this.ButtonRef.UseVisualStyleBackColor = true; // ButtonRef
this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); //
// this.ButtonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
// ButtonIssuedOrder this.ButtonRef.Location = new System.Drawing.Point(966, 232);
// this.ButtonRef.Name = "ButtonRef";
this.ButtonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.ButtonRef.Size = new System.Drawing.Size(147, 42);
this.ButtonIssuedOrder.Location = new System.Drawing.Point(966, 284); this.ButtonRef.TabIndex = 12;
this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; this.ButtonRef.Text = "Обновить список";
this.ButtonIssuedOrder.Size = new System.Drawing.Size(147, 55); this.ButtonRef.UseVisualStyleBackColor = true;
this.ButtonIssuedOrder.TabIndex = 11; this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click);
this.ButtonIssuedOrder.Text = "Заказ выдан"; //
this.ButtonIssuedOrder.UseVisualStyleBackColor = true; // ButtonIssuedOrder
this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); //
// this.ButtonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
// ButtonOrderReady this.ButtonIssuedOrder.Location = new System.Drawing.Point(966, 184);
// this.ButtonIssuedOrder.Name = "ButtonIssuedOrder";
this.ButtonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.ButtonIssuedOrder.Size = new System.Drawing.Size(147, 42);
this.ButtonOrderReady.Location = new System.Drawing.Point(966, 194); this.ButtonIssuedOrder.TabIndex = 11;
this.ButtonOrderReady.Name = "ButtonOrderReady"; this.ButtonIssuedOrder.Text = "Заказ выдан";
this.ButtonOrderReady.Size = new System.Drawing.Size(147, 55); this.ButtonIssuedOrder.UseVisualStyleBackColor = true;
this.ButtonOrderReady.TabIndex = 10; this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
this.ButtonOrderReady.Text = "Заказ готов"; //
this.ButtonOrderReady.UseVisualStyleBackColor = true; // ButtonOrderReady
this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); //
// this.ButtonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
// buttonTakeOrderInWork this.ButtonOrderReady.Location = new System.Drawing.Point(966, 136);
// this.ButtonOrderReady.Name = "ButtonOrderReady";
this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.ButtonOrderReady.Size = new System.Drawing.Size(147, 42);
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(966, 112); this.ButtonOrderReady.TabIndex = 10;
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; this.ButtonOrderReady.Text = "Заказ готов";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(147, 55); this.ButtonOrderReady.UseVisualStyleBackColor = true;
this.buttonTakeOrderInWork.TabIndex = 9; this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; //
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; // buttonTakeOrderInWork
this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); //
// this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
// buttonCreateOrder this.buttonTakeOrderInWork.Location = new System.Drawing.Point(966, 88);
// this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonTakeOrderInWork.Size = new System.Drawing.Size(147, 42);
this.buttonCreateOrder.Location = new System.Drawing.Point(966, 27); this.buttonTakeOrderInWork.TabIndex = 9;
this.buttonCreateOrder.Name = "buttonCreateOrder"; this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonCreateOrder.Size = new System.Drawing.Size(147, 55); this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
this.buttonCreateOrder.TabIndex = 8; this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
this.buttonCreateOrder.Text = "Создать заказ"; //
this.buttonCreateOrder.UseVisualStyleBackColor = true; // buttonCreateOrder
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); //
// this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
// dataGridView this.buttonCreateOrder.Location = new System.Drawing.Point(966, 40);
// this.buttonCreateOrder.Name = "buttonCreateOrder";
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 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.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 27); this.dataGridView.Location = new System.Drawing.Point(12, 27);
this.dataGridView.Name = "dataGridView"; this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25; this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(948, 402); this.dataGridView.Size = new System.Drawing.Size(948, 402);
this.dataGridView.TabIndex = 7; this.dataGridView.TabIndex = 7;
// //
// FormMain // buttonAddPackageInShop
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.buttonAddPackageInShop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.buttonAddPackageInShop.Location = new System.Drawing.Point(966, 387);
this.ClientSize = new System.Drawing.Size(1125, 441); this.buttonAddPackageInShop.Name = "buttonAddPackageInShop";
this.Controls.Add(this.ButtonRef); this.buttonAddPackageInShop.Size = new System.Drawing.Size(147, 42);
this.Controls.Add(this.ButtonIssuedOrder); this.buttonAddPackageInShop.TabIndex = 13;
this.Controls.Add(this.ButtonOrderReady); this.buttonAddPackageInShop.Text = "Пополнение магазина";
this.Controls.Add(this.buttonTakeOrderInWork); this.buttonAddPackageInShop.UseVisualStyleBackColor = true;
this.Controls.Add(this.buttonCreateOrder); this.buttonAddPackageInShop.Click += new System.EventHandler(this.ButtonAddPackageInShop_Click);
this.Controls.Add(this.dataGridView); //
this.Controls.Add(this.menuStrip1); // buttonSellPackage
this.Name = "FormMain"; //
this.Text = "Установка ПО"; this.buttonSellPackage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.Load += new System.EventHandler(this.FormMain_Load); this.buttonSellPackage.Location = new System.Drawing.Point(966, 339);
this.menuStrip1.ResumeLayout(false); this.buttonSellPackage.Name = "buttonSellPackage";
this.menuStrip1.PerformLayout(); this.buttonSellPackage.Size = new System.Drawing.Size(147, 42);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.buttonSellPackage.TabIndex = 14;
this.ResumeLayout(false); this.buttonSellPackage.Text = "Продать изделие";
this.PerformLayout(); 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();
} }
@@ -178,5 +213,8 @@
private Button buttonTakeOrderInWork; private Button buttonTakeOrderInWork;
private Button buttonCreateOrder; private Button buttonCreateOrder;
private DataGridView dataGridView; private DataGridView dataGridView;
private ToolStripMenuItem магазиныToolStripMenuItem;
private Button buttonAddPackageInShop;
private Button buttonSellPackage;
} }
} }

View File

@@ -134,5 +134,30 @@ namespace SoftwareInstallationView
{ {
LoadData(); LoadData();
} }
private void ShopsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormViewShops));
if (service is FormViewShops form)
{
form.ShowDialog();
}
}
private void ButtonAddPackageInShop_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAddPackageInShop));
if (service is FormAddPackageInShop form)
{
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

@@ -105,7 +105,6 @@
this.Controls.Add(this.dataGridView); this.Controls.Add(this.dataGridView);
this.Name = "FormPackages"; this.Name = "FormPackages";
this.Text = "Изделия"; this.Text = "Изделия";
this.Load += new System.EventHandler(this.FormViewPackage_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);

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

@@ -0,0 +1,216 @@
namespace SoftwareInstallationView
{
partial class FormShop
{
/// <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.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.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(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 DataGridView dataGridView;
private Label label2;
private Label label3;
private TextBox textBoxAddress;
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;
}
}

View File

@@ -0,0 +1,147 @@
using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.BusinessLogicsContracts;
using SoftwareInstallationContracts.ViewModels;
using SoftwareInstallationDataModels;
using SoftwareInstallationDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SoftwareInstallationView
{
public partial class FormShop : Form
{
private readonly List<ShopViewModel>? _listShops;
private readonly IShopLogic _logic;
private readonly ILogger _logger;
public int Id
{
get; set;
}
private IShopModel? GetShop(int id)
{
if (_listShops == null)
{
return null;
}
foreach (var elem in _listShops)
{
if (elem.Id == id)
{
return elem;
}
}
return null;
}
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_listShops = logic.ReadList(null);
_logic = logic;
}
private void LoadData(bool extendDate = true)
{
try
{
var model = GetShop(extendDate ? Id : Convert.ToInt32(null));
if (model != null)
{
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.Packages.Values)
{
dataGridView.Rows.Add(new object[]{el.Item1.PackageName, el.Item1.Price, el.Item2 });
}
}
_logger.LogInformation("Загрузка магазинов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазинов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxShop.Text))
{
MessageBox.Show("Заполните название", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxAddress.Text))
{
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение изделия");
try
{
DateTime.TryParse(textBoxDateOpening.Text, out var dateTime);
ShopBindingModel model = new()
{
Name = textBoxShop.Text,
Address = textBoxAddress.Text,
DateOpening = dateTime,
MaxCountPackages = (int)numericUpDownMaxPackage.Value,
};
var vmodel = GetShop(Id);
bool operationResult = false;
if (vmodel != null)
{
model.Id = vmodel.Id;
operationResult = _logic.Update(model);
}
else
{
operationResult = _logic.Create(model);
}
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormShop_Load(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@@ -0,0 +1,78 @@
<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>
<metadata name="PackageName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Price.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="PackageName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Price.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@@ -0,0 +1,122 @@
namespace SoftwareInstallationView
{
partial class FormViewShops
{
/// <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.buttonRef = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// 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(685, 202);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(90, 37);
this.buttonRef.TabIndex = 14;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// buttonDel
//
this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDel.Location = new System.Drawing.Point(685, 151);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(90, 33);
this.buttonDel.TabIndex = 13;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonUpd
//
this.buttonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUpd.Location = new System.Drawing.Point(685, 102);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(90, 34);
this.buttonUpd.TabIndex = 12;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonAdd
//
this.buttonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonAdd.Location = new System.Drawing.Point(685, 57);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(90, 30);
this.buttonAdd.TabIndex = 11;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_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, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(540, 379);
this.dataGridView.TabIndex = 10;
//
// FormViewShops
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(787, 403);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonUpd);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormViewShops";
this.Text = "Просмотр магазинов";
this.Load += new System.EventHandler(this.FormShops_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Button buttonRef;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
}
}

View File

@@ -0,0 +1,105 @@
using SoftwareInstallationContracts.BindingModels;
using SoftwareInstallationContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace SoftwareInstallationView
{
public partial class FormViewShops : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
public FormViewShops(ILogger<FormViewShops> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormShops_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["Packages"].Visible = false;
dataGridView.Columns["Name"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка магазинов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазинов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
if (service is FormShop form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
if (service is FormShop form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление магазина");
try
{
if (!_logic.Delete(new ShopBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления магазина");
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

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

@@ -1,7 +1,9 @@
using SoftwareInstallationBusinessLogic.BusinessLogics; using SoftwareInstallationBusinessLogic.BusinessLogics;
using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.BusinessLogicsContracts;
using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.StoragesContracts;
using SoftwareInstallationFileImplement;
using SoftwareInstallationFileImplement.Implements; using SoftwareInstallationFileImplement.Implements;
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;
@@ -36,11 +38,11 @@ namespace SoftwareInstallationView
services.AddTransient<IComponentStorage, ComponentStorage>(); services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>(); services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IPackageStorage, PackageStorage>(); services.AddTransient<IPackageStorage, PackageStorage>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>(); services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>(); services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IPackageLogic, PackageLogic>(); services.AddTransient<IPackageLogic, PackageLogic>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormMain>(); services.AddTransient<FormMain>();
services.AddTransient<FormComponent>(); services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>(); services.AddTransient<FormComponents>();
@@ -48,6 +50,10 @@ namespace SoftwareInstallationView
services.AddTransient<FormPackage>(); services.AddTransient<FormPackage>();
services.AddTransient<FormPackageComponent>(); services.AddTransient<FormPackageComponent>();
services.AddTransient<FormPackages>(); services.AddTransient<FormPackages>();
services.AddTransient<FormAddPackageInShop>();
services.AddTransient<FormViewShops>();
services.AddTransient<FormShop>();
services.AddTransient<FormSellPackage>();
} }
} }
} }

View File

@@ -18,7 +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="..\SoftWareInstallationFileImplement\SoftWareInstallationFileImplement.csproj" />
<ProjectReference Include="..\SoftwareInstallationListImplement\SoftwareInstallationListImplement.csproj" /> <ProjectReference Include="..\SoftwareInstallationListImplement\SoftwareInstallationListImplement.csproj" />
</ItemGroup> </ItemGroup>