diff --git a/.gitignore b/.gitignore index ca1c7a3..4f51ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,4 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +ImplementationExtensions/ \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs index 44b56f0..844b960 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs @@ -12,11 +12,15 @@ namespace SecuritySystemBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IShopLogic _shopLogic; + private readonly ISecureStorage _secureStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, ISecureStorage secureStorage) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _secureStorage = secureStorage; } public List? ReadList(OrderSearchModel? model) @@ -45,7 +49,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics return true; } - public bool ChangeStatus(OrderBindingModel model, OrderStatus status) + public bool ChangeStatus(OrderBindingModel model, OrderStatus targetStatus) { CheckModel(model, false); var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); @@ -54,18 +58,24 @@ namespace SecuritySystemBusinessLogic.BusinessLogics _logger.LogWarning("Read operation failed"); return false; } - if (element.Status != status - 1) + model.SecureId = element.SecureId; + model.Count = element.Count; + model.Sum = element.Sum; + if (element.Status != targetStatus - 1) { _logger.LogWarning("Status change operation failed"); throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } - OrderStatus oldStatus = model.Status; - model.Status = status; + var secure = _secureStorage.GetElement(new SecureSearchModel { Id = model.SecureId }); + if (targetStatus == OrderStatus.Выдан) + { + _shopLogic.SupplySecures(secure, model.Count); + } + model.Status = targetStatus; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; if (_orderStorage.Update(model) == null) { - model.Status = oldStatus; _logger.LogWarning("Update operation failed"); return false; } diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ShopLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..178f78f --- /dev/null +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,224 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; +using System.Reflection; + +namespace SecuritySystemBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Shop Name:{0}, ID:{1}", model.Name, model.Id); + + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement. element not found"); + return null; + } + + _logger.LogInformation("ReadElement found. Id:{Id}", element.Id); + + return element; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. Shop Name:{0}, ID:{1} ", 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 bool Create(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + + 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)); + } + + _logger.LogInformation("Shop. Name: {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) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + public bool SupplySecures(ShopSearchModel model, ISecureModel secure, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (secure == null) + { + throw new ArgumentNullException(nameof(secure)); + } + + if (count <= 0) + { + throw new ArgumentNullException("Количество продукта для пополнения должно быть больше 0", nameof(count)); + } + + var shopElement = _shopStorage.GetElement(model); + + if (shopElement == null) + { + _logger.LogWarning("Required shop element not found in storage"); + return false; + } + + _logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name); + + if (GetFreeSpace(shopElement.Id) < count) + { + throw new InvalidOperationException("В магазине не хватает места"); + } + + if (shopElement.ShopSecures.TryGetValue(secure.Id, out var sameSecure)) + { + shopElement.ShopSecures[secure.Id] = (secure, sameSecure.Item2 + count); + _logger.LogInformation("Same secure found by supply. Added {0} of {1} in {2} shop", count, secure.SecureName, shopElement.Name); + } + else + { + shopElement.ShopSecures[secure.Id] = (secure, count); + _logger.LogInformation("New secure added by supply. Added {0} of {1} in {2} shop", count, secure.SecureName, shopElement.Name); + } + + _shopStorage.Update(new() + { + Id = shopElement.Id, + Name = shopElement.Name, + Address = shopElement.Address, + OpeningDate = shopElement.OpeningDate, + ShopSecures = shopElement.ShopSecures, + MaxSecuresCount = shopElement.MaxSecuresCount + }); + + return true; + } + public bool SupplySecures(ISecureModel secure, int count) + { + if (!CheckSupplySecures(count)) + { + throw new InvalidOperationException("Невозможно пополнить: в магазинах не хватает места"); + } + + var shops = _shopStorage.GetFullList(); + foreach (var shop in shops) + { + int shopFreeSpace = GetFreeSpace(shop.Id); + if (shopFreeSpace > 0 && count > 0) + { + int min = Math.Min(count, shopFreeSpace); + count -= min; + SupplySecures(new ShopSearchModel { Id = shop.Id }, secure, min); + } + } + + return true; + } + public bool SellSecures(ISecureModel model, int count) + { + return _shopStorage.SellSecures(model, count); + } + public bool CheckSupplySecures(int count) + { + return GetFreeSpace() >= count; + } + private int GetFreeSpace() + { + var shops = _shopStorage.GetFullList(); + return shops.Select(shop => shop.MaxSecuresCount - shop.ShopSecures.Select(shopSecure => shopSecure.Value.Item2).Sum()).Sum(); + } + private int GetFreeSpace(int shopId) + { + var shop = _shopStorage.GetElement(new ShopSearchModel { Id = shopId }); + return shop.MaxSecuresCount - shop.ShopSecures.Select(shopSecure => shopSecure.Value.Item2).Sum(); + } + } +} diff --git a/SecuritySystem/SecuritySystemContracts/BindingModels/ShopBindingModel.cs b/SecuritySystem/SecuritySystemContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..c1d683a --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,14 @@ +using SecuritySystemDataModels.Models; + +namespace SecuritySystemContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + public string Address { get; set; } = string.Empty; + public DateTime OpeningDate { get; set; } + public int MaxSecuresCount { get; set; } + public Dictionary ShopSecures { get; set; } = new(); + } +} diff --git a/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IShopLogic.cs b/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..fc8c42b --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,32 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + ShopViewModel? ReadElement(ShopSearchModel model); + List? ReadList(ShopSearchModel? model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + /// + /// Продает продукт со всех магазинов в заданном количестве + /// + bool SellSecures(ISecureModel model, int count); + /// + /// Проверяет можно ли распределить во все магазины продукты в указанном количестве + /// + bool CheckSupplySecures(int count); + /// + /// Пополняет конкретный магазин продуктом в указанном количестве + /// + bool SupplySecures(ShopSearchModel model, ISecureModel secure, int count); + /// + /// Рапределяет по всем магазинам продукт в указанном количестве + /// + bool SupplySecures(ISecureModel secure, int count); + } +} diff --git a/SecuritySystem/SecuritySystemContracts/SearchModels/ShopSearchModel.cs b/SecuritySystem/SecuritySystemContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..103b5ef --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,8 @@ +namespace SecuritySystemContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/SecuritySystem/SecuritySystemContracts/StoragesContracts/IShopStorage.cs b/SecuritySystem/SecuritySystemContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..1e0e3ae --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,19 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemContracts.StoragesContracts +{ + public interface IShopStorage + { + ShopViewModel? GetElement(ShopSearchModel model); + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + bool SellSecures(ISecureModel secureModel, int securesCount); + bool CanSellSecures(ISecureModel secureModel, int securesCount); + } +} diff --git a/SecuritySystem/SecuritySystemContracts/ViewModels/ShopViewModel.cs b/SecuritySystem/SecuritySystemContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..e8bc4ca --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,19 @@ +using SecuritySystemDataModels.Models; +using System.ComponentModel; + +namespace SecuritySystemContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название")] + public string Name { get; set; } = string.Empty; + [DisplayName("Адрес")] + public string Address { get; set; } = string.Empty; + [DisplayName("Макс. кол-во товара")] + public int MaxSecuresCount { get; set; } + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } + public Dictionary ShopSecures { get; set; } = new(); + } +} diff --git a/SecuritySystem/SecuritySystemDataModels/Models/IShopModel.cs b/SecuritySystem/SecuritySystemDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..91bea8c --- /dev/null +++ b/SecuritySystem/SecuritySystemDataModels/Models/IShopModel.cs @@ -0,0 +1,11 @@ +namespace SecuritySystemDataModels.Models +{ + public interface IShopModel : IId + { + string Name { get; } + string Address { get; } + DateTime OpeningDate { get; } + int MaxSecuresCount { get; } + Dictionary ShopSecures { get; } + } +} diff --git a/SecuritySystem/SecuritySystemFileImplement/DataFileSingleton.cs b/SecuritySystem/SecuritySystemFileImplement/DataFileSingleton.cs index 735bec9..073d85d 100644 --- a/SecuritySystem/SecuritySystemFileImplement/DataFileSingleton.cs +++ b/SecuritySystem/SecuritySystemFileImplement/DataFileSingleton.cs @@ -9,9 +9,11 @@ namespace SecuritySystemFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string SecureFileName = "Secure.xml"; + private readonly string ShopFileName = "Shop.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Secures { get; private set; } + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -23,11 +25,13 @@ namespace SecuritySystemFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveSecures() => SaveData(Secures, SecureFileName, "Secures", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Secures = LoadData(SecureFileName, "Secure", x => Secure.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/SecuritySystem/SecuritySystemFileImplement/Implements/ShopStorage.cs b/SecuritySystem/SecuritySystemFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..8ae6ecf --- /dev/null +++ b/SecuritySystem/SecuritySystemFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,141 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; +using SecuritySystemFileImplement.Models; + +namespace SecuritySystemFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + return source.Shops + .Select(x => x.GetViewModel) + .Where(x => x.Name.Contains(model.Name ?? string.Empty)) + .ToList(); + } + + public List GetFullList() + { + return source.Shops.Select(shop => shop.GetViewModel).ToList(); + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + source.Shops.Remove(shop); + source.SaveShops(); + return shop.GetViewModel; + } + + public bool SellSecures(ISecureModel secureModel, int securesCount) + { + var secure = source.Secures.FirstOrDefault(x => x.Id == secureModel.Id); + + if (secure == null) + { + return false; + } + + var shopSecures = source.Shops.SelectMany(shop => shop.ShopSecures.Where(c => c.Value.Item1.Id == secure.Id)); + + if (!CanSellSecures(secureModel, securesCount)) + { + return false; + } + + foreach (var shop in source.Shops) + { + var secures = shop.ShopSecures; + + foreach (var c in secures.Where(x => x.Value.Item1.Id == secure.Id)) + { + int min = Math.Min(c.Value.Item2, securesCount); + secures[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min); + securesCount -= min; + + if (securesCount <= 0) + break; + } + + shop.Update(new ShopBindingModel + { + Id = shop.Id, + Name = shop.Name, + Address = shop.Address, + MaxSecuresCount = shop.MaxSecuresCount, + OpeningDate = shop.OpeningDate, + ShopSecures = secures + }); + + source.SaveShops(); + + if (securesCount <= 0) + return true; + } + + return true; + } + + + private int GetSecuresCount(ISecureModel secureModel) + { + var shopSecures = source.Shops.SelectMany(shop => shop.ShopSecures.Where(c => c.Value.Item1.Id == secureModel.Id)); + // посчитаем количество изделий во всех магазинах + return shopSecures.Select(x => x.Value.Item2).Sum(); + } + + public bool CanSellSecures(ISecureModel secureModel, int securesCount) + { + return GetSecuresCount(secureModel) >= securesCount; + } + } +} diff --git a/SecuritySystem/SecuritySystemFileImplement/Models/Shop.cs b/SecuritySystem/SecuritySystemFileImplement/Models/Shop.cs new file mode 100644 index 0000000..d8164eb --- /dev/null +++ b/SecuritySystem/SecuritySystemFileImplement/Models/Shop.cs @@ -0,0 +1,111 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; +using SecuritySystemFileImplement; +using System.Xml.Linq; + +namespace SecuritySystemFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string Name { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public int MaxSecuresCount { get; private set; } + public DateTime OpeningDate { get; private set; } + public Dictionary Secures { get; private set; } = new(); + private Dictionary? _shopSecures = null; + public Dictionary ShopSecures + { + get + { + if (_shopSecures == null) + { + var source = DataFileSingleton.GetInstance(); + _shopSecures = Secures.ToDictionary( + x => x.Key, + y => ((source.Secures.FirstOrDefault(z => z.Id == y.Key) as ISecureModel)!, y.Value) + ); + } + return _shopSecures; + } + } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + MaxSecuresCount = model.MaxSecuresCount, + OpeningDate = model.OpeningDate, + Secures = model.ShopSecures.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Name = element.Element("Name")!.Value, + Address = element.Element("Address")!.Value, + MaxSecuresCount = Convert.ToInt32(element.Element("MaxSecuresCount")!.Value), + OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value), + Secures = element.Element("ShopSecures")!.Elements("ShopSecure").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; + MaxSecuresCount = model.MaxSecuresCount; + OpeningDate = model.OpeningDate; + if (model.ShopSecures.Count > 0) + { + Secures = model.ShopSecures.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopSecures = null; + } + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + MaxSecuresCount = MaxSecuresCount, + OpeningDate = OpeningDate, + ShopSecures = ShopSecures, + }; + + public XElement GetXElement => new( + "Shop", + new XAttribute("Id", Id), + new XElement("Name", Name), + new XElement("Address", Address), + new XElement("MaxSecuresCount", MaxSecuresCount), + new XElement("OpeningDate", OpeningDate.ToString()), + new XElement("ShopSecures", Secures.Select(x => + new XElement("ShopSecure", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs index e173975..85dbcbf 100644 --- a/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs +++ b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs @@ -8,11 +8,13 @@ namespace SecuritySystemListImplement public List Components { get; set; } public List Orders { get; set; } public List Secures { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Secures = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/SecuritySystem/SecuritySystemListImplement/Implements/ShopStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..f4515af --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Implements/ShopStorage.cs @@ -0,0 +1,132 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; +using SecuritySystemListImplement.Models; + +namespace SecuritySystemListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + 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 GetFilteredList(ShopSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.Name)) + { + return result; + } + + foreach (var shop in _source.Shops) + { + if (shop.Name.Contains(model.Name)) + { + result.Add(shop.GetViewModel); + } + } + + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + + return result; + } + + 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 ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + + return null; + } + + 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 bool SellSecures(ISecureModel secureModel, int securesCount) + { + throw new NotImplementedException(); + } + + public bool CanSellSecures(ISecureModel secureModel, int securesCount) + { + throw new NotImplementedException(); + } + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/Models/Shop.cs b/SecuritySystem/SecuritySystemListImplement/Models/Shop.cs new file mode 100644 index 0000000..6b4621d --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Models/Shop.cs @@ -0,0 +1,57 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string Name { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public int MaxSecuresCount { get; private set; } + public Dictionary ShopSecures { get; private set; } = new(); + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + { + return null; + } + + return new Shop() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + OpeningDate = model.OpeningDate, + MaxSecuresCount = model.MaxSecuresCount, + ShopSecures = new() + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + + Name = model.Name; + Address = model.Address; + OpeningDate = model.OpeningDate; + MaxSecuresCount = model.MaxSecuresCount; + ShopSecures = model.ShopSecures; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + OpeningDate = OpeningDate, + MaxSecuresCount = MaxSecuresCount, + ShopSecures = ShopSecures + }; + } +} diff --git a/SecuritySystem/SecuritySystemView/FormComponent.Designer.cs b/SecuritySystem/SecuritySystemView/Component/FormComponent.Designer.cs similarity index 95% rename from SecuritySystem/SecuritySystemView/FormComponent.Designer.cs rename to SecuritySystem/SecuritySystemView/Component/FormComponent.Designer.cs index ffb456e..17bf335 100644 --- a/SecuritySystem/SecuritySystemView/FormComponent.Designer.cs +++ b/SecuritySystem/SecuritySystemView/Component/FormComponent.Designer.cs @@ -41,14 +41,14 @@ textBoxComponentName.Location = new Point(98, 6); textBoxComponentName.Name = "textBoxComponentName"; textBoxComponentName.Size = new Size(372, 27); - textBoxComponentName.TabIndex = 0; + textBoxComponentName.TabIndex = 1; // // textBoxComponentCost // textBoxComponentCost.Location = new Point(98, 41); textBoxComponentCost.Name = "textBoxComponentCost"; textBoxComponentCost.Size = new Size(125, 27); - textBoxComponentCost.TabIndex = 1; + textBoxComponentCost.TabIndex = 2; // // labelComponentName // @@ -73,7 +73,7 @@ buttonSaveComponent.Location = new Point(211, 80); buttonSaveComponent.Name = "buttonSaveComponent"; buttonSaveComponent.Size = new Size(115, 29); - buttonSaveComponent.TabIndex = 1; + buttonSaveComponent.TabIndex = 3; buttonSaveComponent.Text = "Сохранить"; buttonSaveComponent.UseVisualStyleBackColor = true; buttonSaveComponent.Click += ButtonSaveComponent_Click; @@ -83,7 +83,7 @@ buttonCancel.Location = new Point(348, 80); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(122, 29); - buttonCancel.TabIndex = 5; + buttonCancel.TabIndex = 4; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; diff --git a/SecuritySystem/SecuritySystemView/FormComponent.cs b/SecuritySystem/SecuritySystemView/Component/FormComponent.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormComponent.cs rename to SecuritySystem/SecuritySystemView/Component/FormComponent.cs diff --git a/SecuritySystem/SecuritySystemView/FormComponent.resx b/SecuritySystem/SecuritySystemView/Component/FormComponent.resx similarity index 100% rename from SecuritySystem/SecuritySystemView/FormComponent.resx rename to SecuritySystem/SecuritySystemView/Component/FormComponent.resx diff --git a/SecuritySystem/SecuritySystemView/FormComponents.Designer.cs b/SecuritySystem/SecuritySystemView/Component/FormComponents.Designer.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormComponents.Designer.cs rename to SecuritySystem/SecuritySystemView/Component/FormComponents.Designer.cs diff --git a/SecuritySystem/SecuritySystemView/FormComponents.cs b/SecuritySystem/SecuritySystemView/Component/FormComponents.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormComponents.cs rename to SecuritySystem/SecuritySystemView/Component/FormComponents.cs diff --git a/SecuritySystem/SecuritySystemView/FormComponents.resx b/SecuritySystem/SecuritySystemView/Component/FormComponents.resx similarity index 100% rename from SecuritySystem/SecuritySystemView/FormComponents.resx rename to SecuritySystem/SecuritySystemView/Component/FormComponents.resx diff --git a/SecuritySystem/SecuritySystemView/FormMain.Designer.cs b/SecuritySystem/SecuritySystemView/FormMain.Designer.cs index 5ff6f2b..30f84a3 100644 --- a/SecuritySystem/SecuritySystemView/FormMain.Designer.cs +++ b/SecuritySystem/SecuritySystemView/FormMain.Designer.cs @@ -32,6 +32,9 @@ справочникиToolStripMenuItem = new ToolStripMenuItem(); ComponentsToolStripMenuItem = new ToolStripMenuItem(); SecuresToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem(); + продатьИзделияToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); @@ -45,7 +48,7 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem, продатьИзделияToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1043, 28); @@ -54,7 +57,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, SecuresToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, SecuresToolStripMenuItem, магазиныToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -73,6 +76,27 @@ SecuresToolStripMenuItem.Text = "Изделия"; SecuresToolStripMenuItem.Click += SecuresToolStripMenuItem_Click; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(182, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // пополнениеМагазинаToolStripMenuItem + // + пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24); + пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + пополнениеМагазинаToolStripMenuItem.Click += SupplyShopToolStripMenuItem_Click; + // + // продатьИзделияToolStripMenuItem + // + продатьИзделияToolStripMenuItem.Name = "продатьИзделияToolStripMenuItem"; + продатьИзделияToolStripMenuItem.Size = new Size(143, 24); + продатьИзделияToolStripMenuItem.Text = "Продать изделие"; + продатьИзделияToolStripMenuItem.Click += продатьИзделияToolStripMenuItem_Click; + // // dataGridView // dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; @@ -177,5 +201,8 @@ private Button buttonOrderReady; private Button button4; private Button buttonRefresh; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; + private ToolStripMenuItem продатьИзделияToolStripMenuItem; } } \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormMain.cs b/SecuritySystem/SecuritySystemView/FormMain.cs index 2fed95c..23179ec 100644 --- a/SecuritySystem/SecuritySystemView/FormMain.cs +++ b/SecuritySystem/SecuritySystemView/FormMain.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemView.Shop; namespace SecuritySystemView { @@ -136,5 +137,32 @@ namespace SecuritySystemView { LoadData(); } + + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void SupplyShopToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply)); + if (service is FormShopSupply form) + { + form.ShowDialog(); + } + } + + private void продатьИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopSell)); + if (service is FormShopSell form) + { + form.ShowDialog(); + } + } } } diff --git a/SecuritySystem/SecuritySystemView/FormMain.resx b/SecuritySystem/SecuritySystemView/FormMain.resx index c17a880..6c82d08 100644 --- a/SecuritySystem/SecuritySystemView/FormMain.resx +++ b/SecuritySystem/SecuritySystemView/FormMain.resx @@ -18,7 +18,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, ... System.Resources.ResXResourceWriter, System.Windows.Forms, ... this is my long stringthis is a comment - Blue + Blue [base64 mime encoded serialized .NET Framework object] diff --git a/SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs b/SecuritySystem/SecuritySystemView/Order/FormCreateOrder.Designer.cs similarity index 97% rename from SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs rename to SecuritySystem/SecuritySystemView/Order/FormCreateOrder.Designer.cs index d99f108..0c53ac2 100644 --- a/SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs +++ b/SecuritySystem/SecuritySystemView/Order/FormCreateOrder.Designer.cs @@ -72,7 +72,7 @@ comboBoxSecure.Location = new Point(110, 9); comboBoxSecure.Name = "comboBoxSecure"; comboBoxSecure.Size = new Size(462, 28); - comboBoxSecure.TabIndex = 3; + comboBoxSecure.TabIndex = 1; comboBoxSecure.SelectedIndexChanged += ComboBoxSecure_SelectedIndexChanged; // // textBoxCount @@ -80,7 +80,7 @@ textBoxCount.Location = new Point(110, 43); textBoxCount.Name = "textBoxCount"; textBoxCount.Size = new Size(462, 27); - textBoxCount.TabIndex = 4; + textBoxCount.TabIndex = 2; textBoxCount.TextChanged += TextBoxCount_TextChanged; // // textBoxSum @@ -96,7 +96,7 @@ buttonSave.Location = new Point(370, 118); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(94, 29); - buttonSave.TabIndex = 1; + buttonSave.TabIndex = 3; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; buttonSave.Click += ButtonSave_Click; @@ -106,7 +106,7 @@ buttonCancel.Location = new Point(478, 118); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(94, 29); - buttonCancel.TabIndex = 7; + buttonCancel.TabIndex = 4; buttonCancel.Text = "Отменить"; buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; diff --git a/SecuritySystem/SecuritySystemView/FormCreateOrder.cs b/SecuritySystem/SecuritySystemView/Order/FormCreateOrder.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormCreateOrder.cs rename to SecuritySystem/SecuritySystemView/Order/FormCreateOrder.cs diff --git a/SecuritySystem/SecuritySystemView/FormCreateOrder.resx b/SecuritySystem/SecuritySystemView/Order/FormCreateOrder.resx similarity index 100% rename from SecuritySystem/SecuritySystemView/FormCreateOrder.resx rename to SecuritySystem/SecuritySystemView/Order/FormCreateOrder.resx diff --git a/SecuritySystem/SecuritySystemView/Program.cs b/SecuritySystem/SecuritySystemView/Program.cs index 6757ecc..05b152b 100644 --- a/SecuritySystem/SecuritySystemView/Program.cs +++ b/SecuritySystem/SecuritySystemView/Program.cs @@ -5,6 +5,7 @@ using SecuritySystemBusinessLogic.BusinessLogics; using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.StoragesContracts; using SecuritySystemFileImplement.Implements; +using SecuritySystemView.Shop; namespace SecuritySystemView { @@ -39,6 +40,8 @@ namespace SecuritySystemView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -46,6 +49,10 @@ namespace SecuritySystemView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormSecure.Designer.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecure.Designer.cs similarity index 96% rename from SecuritySystem/SecuritySystemView/FormSecure.Designer.cs rename to SecuritySystem/SecuritySystemView/Secure/FormSecure.Designer.cs index d64046a..99d5de1 100644 --- a/SecuritySystem/SecuritySystemView/FormSecure.Designer.cs +++ b/SecuritySystem/SecuritySystemView/Secure/FormSecure.Designer.cs @@ -70,7 +70,7 @@ textBoxName.Location = new Point(108, 6); textBoxName.Name = "textBoxName"; textBoxName.Size = new Size(368, 27); - textBoxName.TabIndex = 2; + textBoxName.TabIndex = 1; // // textBoxPrice // @@ -78,7 +78,7 @@ textBoxPrice.Location = new Point(108, 43); textBoxPrice.Name = "textBoxPrice"; textBoxPrice.Size = new Size(143, 27); - textBoxPrice.TabIndex = 3; + textBoxPrice.TabIndex = 2; // // groupBoxComponentsControl // @@ -99,7 +99,7 @@ buttonRefresh.Location = new Point(668, 197); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(94, 29); - buttonRefresh.TabIndex = 4; + buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += ButtonRefresh_Click; @@ -109,7 +109,7 @@ buttonDelete.Location = new Point(668, 147); buttonDelete.Name = "buttonDelete"; buttonDelete.Size = new Size(94, 29); - buttonDelete.TabIndex = 3; + buttonDelete.TabIndex = 5; buttonDelete.Text = "Удалить"; buttonDelete.UseVisualStyleBackColor = true; buttonDelete.Click += ButtonDelete_Click; @@ -119,7 +119,7 @@ buttonEdit.Location = new Point(668, 99); buttonEdit.Name = "buttonEdit"; buttonEdit.Size = new Size(94, 29); - buttonEdit.TabIndex = 2; + buttonEdit.TabIndex = 4; buttonEdit.Text = "Изменить"; buttonEdit.UseVisualStyleBackColor = true; buttonEdit.Click += ButtonEdit_Click; @@ -129,7 +129,7 @@ buttonAdd.Location = new Point(668, 48); buttonAdd.Name = "buttonAdd"; buttonAdd.Size = new Size(94, 29); - buttonAdd.TabIndex = 1; + buttonAdd.TabIndex = 3; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; buttonAdd.Click += ButtonAdd_Click; @@ -173,7 +173,7 @@ buttonSave.Location = new Point(537, 409); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(108, 29); - buttonSave.TabIndex = 1; + buttonSave.TabIndex = 7; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; buttonSave.Click += ButtonSave_Click; @@ -183,7 +183,7 @@ buttonCancel.Location = new Point(665, 409); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(109, 29); - buttonCancel.TabIndex = 6; + buttonCancel.TabIndex = 8; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; diff --git a/SecuritySystem/SecuritySystemView/FormSecure.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecure.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormSecure.cs rename to SecuritySystem/SecuritySystemView/Secure/FormSecure.cs diff --git a/SecuritySystem/SecuritySystemView/FormSecure.resx b/SecuritySystem/SecuritySystemView/Secure/FormSecure.resx similarity index 100% rename from SecuritySystem/SecuritySystemView/FormSecure.resx rename to SecuritySystem/SecuritySystemView/Secure/FormSecure.resx diff --git a/SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.Designer.cs similarity index 96% rename from SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs rename to SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.Designer.cs index f49c86c..06d5749 100644 --- a/SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs +++ b/SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.Designer.cs @@ -61,21 +61,21 @@ comboBoxComponents.Location = new Point(109, 6); comboBoxComponents.Name = "comboBoxComponents"; comboBoxComponents.Size = new Size(315, 28); - comboBoxComponents.TabIndex = 2; + comboBoxComponents.TabIndex = 1; // // textBoxCount // textBoxCount.Location = new Point(109, 41); textBoxCount.Name = "textBoxCount"; textBoxCount.Size = new Size(315, 27); - textBoxCount.TabIndex = 3; + textBoxCount.TabIndex = 2; // // buttonSave // buttonSave.Location = new Point(230, 84); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(94, 29); - buttonSave.TabIndex = 1; + buttonSave.TabIndex = 3; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; buttonSave.Click += ButtonSave_Click; @@ -85,7 +85,7 @@ buttonCancel.Location = new Point(330, 84); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(94, 29); - buttonCancel.TabIndex = 5; + buttonCancel.TabIndex = 4; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; diff --git a/SecuritySystem/SecuritySystemView/FormSecureComponent.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormSecureComponent.cs rename to SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.cs diff --git a/SecuritySystem/SecuritySystemView/FormSecureComponent.resx b/SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.resx similarity index 100% rename from SecuritySystem/SecuritySystemView/FormSecureComponent.resx rename to SecuritySystem/SecuritySystemView/Secure/FormSecureComponent.resx diff --git a/SecuritySystem/SecuritySystemView/FormSecures.Designer.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecures.Designer.cs similarity index 97% rename from SecuritySystem/SecuritySystemView/FormSecures.Designer.cs rename to SecuritySystem/SecuritySystemView/Secure/FormSecures.Designer.cs index b3ac3b4..06698ee 100644 --- a/SecuritySystem/SecuritySystemView/FormSecures.Designer.cs +++ b/SecuritySystem/SecuritySystemView/Secure/FormSecures.Designer.cs @@ -56,7 +56,7 @@ buttonRefresh.Location = new Point(739, 162); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(94, 29); - buttonRefresh.TabIndex = 8; + buttonRefresh.TabIndex = 4; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += ButtonRefreshSecures_Click; @@ -67,7 +67,7 @@ buttonDelete.Location = new Point(739, 114); buttonDelete.Name = "buttonDelete"; buttonDelete.Size = new Size(94, 29); - buttonDelete.TabIndex = 7; + buttonDelete.TabIndex = 3; buttonDelete.Text = "Удалить"; buttonDelete.UseVisualStyleBackColor = true; buttonDelete.Click += ButtonDeleteSecure_Click; @@ -78,7 +78,7 @@ buttonEdit.Location = new Point(739, 64); buttonEdit.Name = "buttonEdit"; buttonEdit.Size = new Size(94, 29); - buttonEdit.TabIndex = 6; + buttonEdit.TabIndex = 2; buttonEdit.Text = "Изменить"; buttonEdit.UseVisualStyleBackColor = true; buttonEdit.Click += ButtonEditSecure_Click; diff --git a/SecuritySystem/SecuritySystemView/FormSecures.cs b/SecuritySystem/SecuritySystemView/Secure/FormSecures.cs similarity index 100% rename from SecuritySystem/SecuritySystemView/FormSecures.cs rename to SecuritySystem/SecuritySystemView/Secure/FormSecures.cs diff --git a/SecuritySystem/SecuritySystemView/FormSecures.resx b/SecuritySystem/SecuritySystemView/Secure/FormSecures.resx similarity index 100% rename from SecuritySystem/SecuritySystemView/FormSecures.resx rename to SecuritySystem/SecuritySystemView/Secure/FormSecures.resx diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShop.Designer.cs b/SecuritySystem/SecuritySystemView/Shop/FormShop.Designer.cs new file mode 100644 index 0000000..75efaa7 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShop.Designer.cs @@ -0,0 +1,219 @@ +namespace SecuritySystemView +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelAddress = new Label(); + labelOpeningDate = new Label(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + dateTimePickerOpeningDate = new DateTimePicker(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + colorDialog1 = new ColorDialog(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelMaxCount = new Label(); + numericUpDownCapacity = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(80, 20); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(12, 41); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(54, 20); + labelAddress.TabIndex = 1; + labelAddress.Text = "Адрес:"; + // + // labelOpeningDate + // + labelOpeningDate.AutoSize = true; + labelOpeningDate.Location = new Point(12, 75); + labelOpeningDate.Name = "labelOpeningDate"; + labelOpeningDate.Size = new Size(113, 20); + labelOpeningDate.TabIndex = 2; + labelOpeningDate.Text = "Дата открытия:"; + // + // textBoxName + // + textBoxName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxName.Location = new Point(98, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(562, 27); + textBoxName.TabIndex = 1; + // + // textBoxAddress + // + textBoxAddress.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxAddress.Location = new Point(98, 38); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(562, 27); + textBoxAddress.TabIndex = 2; + // + // dateTimePickerOpeningDate + // + dateTimePickerOpeningDate.Location = new Point(131, 71); + dateTimePickerOpeningDate.Name = "dateTimePickerOpeningDate"; + dateTimePickerOpeningDate.Size = new Size(185, 27); + dateTimePickerOpeningDate.TabIndex = 3; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Location = new Point(12, 104); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(517, 334); + dataGridView.TabIndex = 6; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Изделие"; + ColumnName.MinimumWidth = 6; + ColumnName.Name = "ColumnName"; + // + // ColumnCount + // + ColumnCount.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader; + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.Width = 119; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonSave.Location = new Point(549, 145); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonCancel.Location = new Point(549, 219); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Закрыть"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // labelMaxCount + // + labelMaxCount.AutoSize = true; + labelMaxCount.Location = new Point(397, 76); + labelMaxCount.Name = "labelMaxCount"; + labelMaxCount.Size = new Size(100, 20); + labelMaxCount.TabIndex = 7; + labelMaxCount.Text = "Вместимость"; + // + // numericUpDownCapacity + // + numericUpDownCapacity.Location = new Point(503, 73); + numericUpDownCapacity.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownCapacity.Name = "numericUpDownCapacity"; + numericUpDownCapacity.Size = new Size(150, 27); + numericUpDownCapacity.TabIndex = 8; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(672, 450); + Controls.Add(numericUpDownCapacity); + Controls.Add(labelMaxCount); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(dataGridView); + Controls.Add(dateTimePickerOpeningDate); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Controls.Add(labelOpeningDate); + Controls.Add(labelAddress); + Controls.Add(labelName); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelAddress; + private Label labelOpeningDate; + private TextBox textBoxName; + private TextBox textBoxAddress; + private DateTimePicker dateTimePickerOpeningDate; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + private ColorDialog colorDialog1; + private Button buttonSave; + private Button buttonCancel; + private Label labelMaxCount; + private NumericUpDown numericUpDownCapacity; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShop.cs b/SecuritySystem/SecuritySystemView/Shop/FormShop.cs new file mode 100644 index 0000000..321f180 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShop.cs @@ -0,0 +1,127 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemView +{ + public partial class FormShop : Form + { + private readonly IShopLogic _logic; + private readonly ILogger _logger; + private Dictionary _shopSecures; + private int? _id; + public int Id { set { _id = value; } } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopSecures = new(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Loading shop"); + + try + { + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + + if (view != null) + { + textBoxName.Text = view.Name; + textBoxAddress.Text = view.Address; + dateTimePickerOpeningDate.Value = view.OpeningDate; + _shopSecures = view.ShopSecures ?? new Dictionary(); + numericUpDownCapacity.Value = view.MaxSecuresCount; + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка магазина"); + + try + { + if (_shopSecures != null) + { + dataGridView.Rows.Clear(); + foreach (var secure in _shopSecures) + { + dataGridView.Rows.Add(new object[] { secure.Key, secure.Value.Item1.SecureName, secure.Value.Item2 }); + } + } + } + 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(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение магазина"); + + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + Address = textBoxAddress.Text, + OpeningDate = dateTimePickerOpeningDate.Value.Date, + ShopSecures = _shopSecures, + MaxSecuresCount = (int)numericUpDownCapacity.Value + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _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(); + } + } +} diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShop.resx b/SecuritySystem/SecuritySystemView/Shop/FormShop.resx new file mode 100644 index 0000000..cceb94b --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShop.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + + 17, 17 + + \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShopSell.Designer.cs b/SecuritySystem/SecuritySystemView/Shop/FormShopSell.Designer.cs new file mode 100644 index 0000000..a162169 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShopSell.Designer.cs @@ -0,0 +1,125 @@ +namespace SecuritySystemView.Shop +{ + partial class FormShopSell + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonSell = new Button(); + buttonCancel = new Button(); + comboBoxSecure = new ComboBox(); + numericUpDownCount = new NumericUpDown(); + labelSecure = new Label(); + labelCount = new Label(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); + SuspendLayout(); + // + // buttonSell + // + buttonSell.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSell.Location = new Point(573, 89); + buttonSell.Name = "buttonSell"; + buttonSell.Size = new Size(94, 29); + buttonSell.TabIndex = 0; + buttonSell.Text = "Продать"; + buttonSell.UseVisualStyleBackColor = true; + buttonSell.Click += buttonSell_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(673, 89); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // comboBoxSecure + // + comboBoxSecure.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSecure.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSecure.FormattingEnabled = true; + comboBoxSecure.Location = new Point(84, 9); + comboBoxSecure.Name = "comboBoxSecure"; + comboBoxSecure.Size = new Size(683, 28); + comboBoxSecure.TabIndex = 2; + // + // numericUpDownCount + // + numericUpDownCount.Location = new Point(108, 43); + numericUpDownCount.Name = "numericUpDownCount"; + numericUpDownCount.Size = new Size(150, 27); + numericUpDownCount.TabIndex = 3; + // + // labelSecure + // + labelSecure.AutoSize = true; + labelSecure.Location = new Point(12, 12); + labelSecure.Name = "labelSecure"; + labelSecure.Size = new Size(66, 20); + labelSecure.TabIndex = 4; + labelSecure.Text = "Продукт"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 45); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(90, 20); + labelCount.TabIndex = 5; + labelCount.Text = "Количество"; + // + // FormShopSell + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(779, 130); + Controls.Add(labelCount); + Controls.Add(labelSecure); + Controls.Add(numericUpDownCount); + Controls.Add(comboBoxSecure); + Controls.Add(buttonCancel); + Controls.Add(buttonSell); + Name = "FormShopSell"; + Text = "Продажа товара"; + Load += FormShopSell_Load; + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSell; + private Button buttonCancel; + private ComboBox comboBoxSecure; + private NumericUpDown numericUpDownCount; + private Label labelSecure; + private Label labelCount; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShopSell.cs b/SecuritySystem/SecuritySystemView/Shop/FormShopSell.cs new file mode 100644 index 0000000..c77f13e --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShopSell.cs @@ -0,0 +1,85 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; + +namespace SecuritySystemView.Shop +{ + public partial class FormShopSell : Form + { + private readonly IShopLogic _shopLogic; + private readonly ISecureLogic _secureLogic; + private readonly ILogger _logger; + public FormShopSell(ILogger logger, IShopLogic shopLogic, ISecureLogic secureLogic) + { + InitializeComponent(); + _logger = logger; + _shopLogic = shopLogic; + _secureLogic = secureLogic; + } + + private void FormShopSell_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка продукции для продажи"); + try + { + var list = _secureLogic.ReadList(null); + if (list != null) + { + comboBoxSecure.DisplayMember = "SecureName"; + comboBoxSecure.ValueMember = "Id"; + comboBoxSecure.DataSource = list; + comboBoxSecure.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка продукции"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSell_Click(object sender, EventArgs e) + { + if (numericUpDownCount.Value < 1) + { + MessageBox.Show("Количество продукта должно быть больше нуля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSecure.SelectedValue == null) + { + MessageBox.Show("Выберите продукт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание продажи"); + try + { + var operationResult = _shopLogic.SellSecures( + new SecureBindingModel + { + Id = Convert.ToInt32(comboBoxSecure.SelectedValue) + }, + Convert.ToInt32(numericUpDownCount.Value) + ); + 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(); + } + } +} diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShopSell.resx b/SecuritySystem/SecuritySystemView/Shop/FormShopSell.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShopSell.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.Designer.cs b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.Designer.cs new file mode 100644 index 0000000..0a99cab --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.Designer.cs @@ -0,0 +1,148 @@ +namespace SecuritySystemView +{ + partial class FormShopSupply + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + comboBoxShop = new ComboBox(); + comboBoxSecure = new ComboBox(); + labelShop = new Label(); + label2 = new Label(); + label3 = new Label(); + buttonSupply = new Button(); + buttonCancel = new Button(); + textBoxCount = new TextBox(); + SuspendLayout(); + // + // comboBoxShop + // + comboBoxShop.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxShop.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(125, 6); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(432, 28); + comboBoxShop.TabIndex = 1; + // + // comboBoxSecure + // + comboBoxSecure.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSecure.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSecure.FormattingEnabled = true; + comboBoxSecure.Location = new Point(125, 47); + comboBoxSecure.Name = "comboBoxSecure"; + comboBoxSecure.Size = new Size(432, 28); + comboBoxSecure.TabIndex = 2; + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(12, 9); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(72, 20); + labelShop.TabIndex = 3; + labelShop.Text = "Магазин:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 50); + label2.Name = "label2"; + label2.Size = new Size(71, 20); + label2.TabIndex = 4; + label2.Text = "Изделие:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 89); + label3.Name = "label3"; + label3.Size = new Size(93, 20); + label3.TabIndex = 5; + label3.Text = "Количество:"; + // + // buttonSupply + // + buttonSupply.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSupply.Location = new Point(342, 130); + buttonSupply.Name = "buttonSupply"; + buttonSupply.Size = new Size(94, 29); + buttonSupply.TabIndex = 4; + buttonSupply.Text = "Поставить"; + buttonSupply.UseVisualStyleBackColor = true; + buttonSupply.Click += buttonSupply_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(463, 130); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // textBoxCount + // + textBoxCount.Location = new Point(125, 89); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(167, 27); + textBoxCount.TabIndex = 3; + // + // FormShopSupply + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(569, 169); + Controls.Add(textBoxCount); + Controls.Add(buttonCancel); + Controls.Add(buttonSupply); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(labelShop); + Controls.Add(comboBoxSecure); + Controls.Add(comboBoxShop); + Name = "FormShopSupply"; + Text = "Поставка изделия"; + Load += FormShopSupply_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxShop; + private ComboBox comboBoxSecure; + private Label labelShop; + private Label label2; + private Label label3; + private Button buttonSupply; + private Button buttonCancel; + private TextBox textBoxCount; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.cs b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.cs new file mode 100644 index 0000000..ff14ef8 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.cs @@ -0,0 +1,117 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; + +namespace SecuritySystemView +{ + public partial class FormShopSupply : Form + { + private readonly ILogger _logger; + private readonly ISecureLogic _logicSecure; + private readonly IShopLogic _logicShop; + + public FormShopSupply(ILogger logger, ISecureLogic logicSecure, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicSecure = logicSecure; + _logicShop = logicShop; + } + + private void FormShopSupply_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка secure для пополнения"); + + try + { + var list = _logicSecure.ReadList(null); + if (list != null) + { + comboBoxSecure.DisplayMember = "SecureName"; + comboBoxSecure.ValueMember = "Id"; + comboBoxSecure.DataSource = list; + comboBoxSecure.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка secure"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка магазинов для пополнения"); + + try + { + var list = _logicShop.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "Name"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSupply_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxSecure.SelectedValue == null) + { + MessageBox.Show("Выберите secure", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Создание поставки"); + + try + { + var operationResult = _logicShop.SupplySecures( + new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue), Name = comboBoxShop.Text }, + new SecureBindingModel { Id = Convert.ToInt32(comboBoxSecure.SelectedValue), SecureName = comboBoxSecure.Text }, + Convert.ToInt32(textBoxCount.Text) + ); + + if (!operationResult) + { + throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.resx b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShopSupply.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShops.Designer.cs b/SecuritySystem/SecuritySystemView/Shop/FormShops.Designer.cs new file mode 100644 index 0000000..42e785c --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShops.Designer.cs @@ -0,0 +1,124 @@ +namespace SecuritySystemView +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(716, 406); + dataGridView.TabIndex = 1; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRefresh.Location = new Point(735, 261); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(94, 29); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonDelete.Location = new Point(735, 213); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(94, 29); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonEdit + // + buttonEdit.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonEdit.Location = new Point(735, 163); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(94, 29); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += buttonEdit_Click; + // + // buttonAdd + // + buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonAdd.Location = new Point(735, 111); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(841, 406); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShops.cs b/SecuritySystem/SecuritySystemView/Shop/FormShops.cs new file mode 100644 index 0000000..4bff54b --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShops.cs @@ -0,0 +1,111 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; + +namespace SecuritySystemView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + + public FormShops(ILogger 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["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopSecures"].Visible = false; + } + + _logger.LogInformation("Загрузка магазинов"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + + 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 buttonEdit_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 buttonDelete_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); + } + } + } + } + } +} diff --git a/SecuritySystem/SecuritySystemView/Shop/FormShops.resx b/SecuritySystem/SecuritySystemView/Shop/FormShops.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Shop/FormShops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file