diff --git a/FurnitureAssembly/FurnitureAssembly.sln b/FurnitureAssembly/FurnitureAssembly.sln index f8ab1b3..b4611de 100644 --- a/FurnitureAssembly/FurnitureAssembly.sln +++ b/FurnitureAssembly/FurnitureAssembly.sln @@ -13,7 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyListImplem EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyView", "FurnitureAssemblyView\FurnitureAssemblyView.csproj", "{77944C5A-53FC-437B-A563-E7C09C769859}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyFileImplement", "FurnitureAssemblyFileImplement\FurnitureAssemblyFileImplement.csproj", "{2EF175D6-B6BD-442B-B81E-67E368553726}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyFileImplement", "FurnitureAssemblyFileImplement\FurnitureAssemblyFileImplement.csproj", "{C987B2B5-56C1-434F-BBCF-6453CF6E5193}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -41,10 +41,10 @@ Global {77944C5A-53FC-437B-A563-E7C09C769859}.Debug|Any CPU.Build.0 = Debug|Any CPU {77944C5A-53FC-437B-A563-E7C09C769859}.Release|Any CPU.ActiveCfg = Release|Any CPU {77944C5A-53FC-437B-A563-E7C09C769859}.Release|Any CPU.Build.0 = Release|Any CPU - {2EF175D6-B6BD-442B-B81E-67E368553726}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2EF175D6-B6BD-442B-B81E-67E368553726}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2EF175D6-B6BD-442B-B81E-67E368553726}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2EF175D6-B6BD-442B-B81E-67E368553726}.Release|Any CPU.Build.0 = Release|Any CPU + {C987B2B5-56C1-434F-BBCF-6453CF6E5193}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C987B2B5-56C1-434F-BBCF-6453CF6E5193}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C987B2B5-56C1-434F-BBCF-6453CF6E5193}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C987B2B5-56C1-434F-BBCF-6453CF6E5193}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/OrderLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/OrderLogic.cs index e2d03fb..73bd581 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/OrderLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/OrderLogic.cs @@ -20,11 +20,17 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic private readonly IOrderStorage _orderStorage; + private readonly IShopLogic _shopLogic; + + private readonly IFurnitureStorage _furnitureStorage; + // Конструктор - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, IFurnitureStorage furnitureStorage) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _furnitureStorage = furnitureStorage; } // Вывод отфильтрованного списка компонентов @@ -35,7 +41,7 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic // list хранит весь список в случае, если model пришло со значением null на вход метода var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - if(list == null) + if (list == null) { _logger.LogWarning("ReadList return null list"); @@ -52,7 +58,7 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic { CheckModel(model); - if(model.Status != OrderStatus.Неизвестен) + if (model.Status != OrderStatus.Неизвестен) { _logger.LogWarning("Insert operation failed, incorrect order status"); return false; @@ -60,7 +66,7 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic model.Status = OrderStatus.Принят; - if(_orderStorage.Insert(model) == null) + if (_orderStorage.Insert(model) == null) { model.Status = OrderStatus.Неизвестен; _logger.LogWarning("Insert operation failed"); @@ -100,30 +106,30 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic } // Проверка на наличие товаров в заказе - if(model.Count <= 0) + if (model.Count <= 0) { throw new ArgumentNullException("В заказе не может быть 0 изделий", nameof(model.Count)); } // Проверка на наличие нормальной суммарной стоимости чека - if(model.Sum <= 0) + if (model.Sum <= 0) { throw new ArgumentNullException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum)); } // Проверка корректности id у изделий - if(model.FurnitureId < 0) + if (model.FurnitureId < 0) { throw new ArgumentNullException("Некорректный id у изделия", nameof(model.FurnitureId)); } // Проверка корректности дат - if(model.DateCreate > model.DateImplement) + if (model.DateCreate > model.DateImplement) { throw new InvalidOperationException("Дата создания должна быть более ранней, нежели дата завершения"); } - _logger.LogInformation("Order. OrderId:{Id}, Sum:{Sum}. FurnitureId:{Id}", model.Id, model.Sum, model.FurnitureId); + _logger.LogInformation("Order. OrderId:{Id}, Sum:{Sum}. FurnitureId:{Id}. Sum:{Sum}", model.Id, model.Sum, model.FurnitureId, model.Sum); } // Обновление статуса заказа @@ -132,13 +138,13 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); // Если не смогли найти указанный заказ по его Id - if(viewModel == null) + if (viewModel == null) { throw new ArgumentNullException(nameof(model)); } // Проверка на возможность обновления статуса на следующий - if(viewModel.Status + 1 != newOrderStatus) + if (viewModel.Status + 1 != newOrderStatus) { _logger.LogWarning("Status update operation failed. New status " + newOrderStatus.ToString() + "incorrect"); return false; @@ -147,9 +153,21 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic model.Status = newOrderStatus; // Проверка на выдачу - if(model.Status == OrderStatus.Выдан) + if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; + + var furniture = _furnitureStorage.GetElement(new() { Id = viewModel.FurnitureId }); + + if (furniture == null) + { + throw new ArgumentNullException(nameof(furniture)); + } + + if (!_shopLogic.AddFurnitures(furniture, viewModel.Count)) + { + throw new Exception($"Невозможно выдать изделия, магазины переполнены. Operation failed. Shop is full."); + } } else { @@ -159,7 +177,7 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic CheckModel(model, false); // Финальная проверка на возможность обновления - if(_orderStorage.Update(model) == null) + if (_orderStorage.Update(model) == null) { model.Status--; diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/ShopLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/ShopLogic.cs new file mode 100644 index 0000000..7b0a4f0 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BussinessLogic/ShopLogic.cs @@ -0,0 +1,266 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic.BussinessLogic +{ + // Класс, реализующий логику для магазинов + 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. ShopName:{ShopName}. Id:{Id}", model.ShopName, 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 List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); + + // list хранит весь список в случае, если model пришло со значением null на вход метода + 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 AddFurniture(ShopSearchModel model, IFurnitureModel furniture, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (count <= 0) + { + throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0", nameof(count)); + } + + _logger.LogInformation("AddFurniture. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); + var shop = _shopStorage.GetElement(model); + + if (shop == null) + { + _logger.LogWarning("Add Furniture operation failed"); + + return false; + } + + if (shop.MaxCountFurnitures - shop.Furnitures.Select(x => x.Value.Item2).Sum() < count) + { + throw new ArgumentNullException("Слишком много изделий для одного магазина", nameof(count)); + } + + if (!shop.Furnitures.ContainsKey(furniture.Id)) + { + shop.Furnitures[furniture.Id] = (furniture, count); + } + else + { + shop.Furnitures[furniture.Id] = (furniture, shop.Furnitures[furniture.Id].Item2 + count); + } + + _shopStorage.Update(new ShopBindingModel() + { + ShopName = shop.ShopName, + Address = shop.Address, + DateOpen = shop.DateOpen, + MaxCountFurnitures = shop.MaxCountFurnitures, + Furnitures = shop.Furnitures + }); + + return true; + } + + // Создание магазина + 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); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + + return false; + } + + return true; + } + + // Проверка входного аргумента для методов Insert, Update и Delete + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + // При удалении передаём как параметр false + if (!withParams) + { + return; + } + + // Проверка на наличие названия магазина + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Отсутствует названия магазина", nameof(model.ShopName)); + } + + // Проверка на наличие адреса у магазина + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Отсутствует адреса магазина", nameof(model.Address)); + } + + _logger.LogInformation("Shop. ShopName:{ShopName}. Address:{Address}. Id: {Id}", model.ShopName, model.Address, model.Id); + + // Проверка на наличие такого же магазина в списке + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + + // Если элемент найден и его Id не совпадает с Id переданного объекта + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + + public bool AddFurnitures(IFurnitureModel model, int count) + { + if (count <= 0) + { + throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0", nameof(count)); + } + + _logger.LogInformation("AddFurnitures. Furniture: {Furniture}. Count: {Count}", model?.FurnitureName, count); + + var capacity = _shopStorage.GetFullList().Select(x => x.MaxCountFurnitures - x.Furnitures.Select(x => x.Value.Item2).Sum()).Sum() - count; + + if (capacity < 0) + { + _logger.LogWarning("AddFurnitures operation failed. Sell {count} Furnitures ", -capacity); + return false; + } + + foreach (var shop in _shopStorage.GetFullList()) + { + if (shop.MaxCountFurnitures - shop.Furnitures.Select(x => x.Value.Item2).Sum() < count) + { + if (!AddFurniture(new() { Id = shop.Id }, model, shop.MaxCountFurnitures - shop.Furnitures.Select(x => x.Value.Item2).Sum())) + { + _logger.LogWarning("AddFurnitures operation failed."); + + return false; + } + + count -= shop.MaxCountFurnitures - shop.Furnitures.Select(x => x.Value.Item2).Sum(); + } + else + { + if (!AddFurniture(new() { Id = shop.Id }, model, count)) + { + _logger.LogWarning("AddFurnitures operation failed."); + + return false; + } + + count -= count; + } + + if (count == 0) + { + return true; + } + } + + return true; + } + + public bool SellFurnitures(IFurnitureModel model, int count) + { + return _shopStorage.SellFurnitures(model, count); + } + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ShopBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..e2a97e8 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,25 @@ +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.BindingModels +{ + // Реализация сущности "Магазин" + public class ShopBindingModel : IShopModel + { + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpen { get; set; } = DateTime.Now; + + public Dictionary Furnitures { get; set; } = new(); + + public int Id { get; set; } + + public int MaxCountFurnitures { get; set; } + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/WorkPieceBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/WorkPieceBindingModel.cs index ac6fd32..6a0b2ae 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/WorkPieceBindingModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/WorkPieceBindingModel.cs @@ -15,4 +15,4 @@ namespace FurnitureAssemblyContracts.BindingModels public double Cost { get; set; } } -} +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IShopLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..93bd241 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,32 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.BusinessLogicsContracts +{ + // Бизнес-логика для магазина + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + + ShopViewModel? ReadElement(ShopSearchModel model); + + bool Create(ShopBindingModel model); + + bool Update(ShopBindingModel model); + + bool Delete(ShopBindingModel model); + + bool AddFurniture(ShopSearchModel model, IFurnitureModel furniture, int count); + + bool SellFurnitures(IFurnitureModel model, int count); + + bool AddFurnitures(IFurnitureModel model, int count); + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ShopSearchModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..1bd651a --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.SearchModels +{ + // Для поиска сущности "Магазин" + public class ShopSearchModel + { + // Для поиска по идентификатору + public int? Id { get; set; } + + // Для поиска по названию + public string? ShopName { get; set; } + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..ad33710 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,30 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.StoragesContracts +{ + // Класс для хранилища магазинов + public interface IShopStorage + { + List GetFullList(); + + List GetFilteredList(ShopSearchModel model); + + ShopViewModel? GetElement(ShopSearchModel model); + + ShopViewModel? Insert(ShopBindingModel model); + + ShopViewModel? Update(ShopBindingModel model); + + ShopViewModel? Delete(ShopBindingModel model); + + bool SellFurnitures(IFurnitureModel model, int count); + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..72c9f13 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,30 @@ +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.ViewModels +{ + // Класс для отображения пользователю информации о магазинах + public class ShopViewModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpen { get; set; } = DateTime.Now; + + public Dictionary Furnitures { get; set; } = new(); + + [DisplayName("Вместимость магазина")] + public int MaxCountFurnitures { get; set; } + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IShopModel.cs b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..ac9366d --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IShopModel.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDataModels.Models +{ + // Интерфейс сущности "Магазин" + public interface IShopModel : IId + { + // Название магазина + string ShopName { get; } + + // Адрес магазина + string Address { get; } + + // Дата открытия магазина + DateTime DateOpen { get; } + + //максимальное кол-во изделий в магазине + int MaxCountFurnitures { get; } + + // Изделия в магазине + Dictionary Furnitures { get; } + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/DataFileSingleton.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/DataFileSingleton.cs index c23286f..dae08a9 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/DataFileSingleton.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/DataFileSingleton.cs @@ -18,12 +18,16 @@ namespace FurnitureAssemblyFileImplement private readonly string FurnitureFileName = "Furniture.xml"; + private readonly string ShopFileName = "Shop.xml"; + public List WorkPieces { get; private set; } public List Orders { get; private set; } public List Furnitures { get; private set; } + public List Shops { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) @@ -40,12 +44,14 @@ namespace FurnitureAssemblyFileImplement public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { WorkPieces = LoadData(WorkPieceFileName, "WorkPiece", x => WorkPiece.Create(x)!)!; Furnitures = LoadData(FurnitureFileName, "Furniture", x => Furniture.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/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/ShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..d171793 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,139 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyFileImplement.Implements +{ + // Реализация интерфейса хранилища магазинов + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton _source; + + public ShopStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return _source.Shops.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + + return _source.Shops.Where(x => x.ShopName.Contains(model.ShopName)) + .Select(x => x.GetViewModel).ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + + return _source.Shops.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) + || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = _source.Shops.Count > 0 ? _source.Shops.Max(x => x.Id) + 1 : 1; + + var newShop = Shop.Create(model); + + if (newShop == null) + { + return null; + } + + _source.Shops.Add(newShop); + _source.SaveShops(); + + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = _source.Shops.FirstOrDefault(x => x.ShopName.Contains(model.ShopName) || x.Id == model.Id); + + if (shop == null) + { + return null; + } + + shop.Update(model); + _source.SaveShops(); + + return shop.GetViewModel; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + var element = _source.Shops.FirstOrDefault(x => x.Id == model.Id); + + if (element != null) + { + _source.Shops.Remove(element); + _source.SaveShops(); + + return element.GetViewModel; + } + + return null; + } + + public bool SellFurnitures(IFurnitureModel model, int count) + { + if (_source.Shops.Select(x => x.Furnitures.FirstOrDefault(x => x.Key == model.Id).Value.Item2).Sum() < count) + { + return false; + } + + var list = _source.Shops.Where(x => x.Furnitures.ContainsKey(model.Id)); + + foreach (var shop in list) + { + if (shop.Furnitures[model.Id].Item2 < count) + { + count -= shop.Furnitures[model.Id].Item2; + shop.Furnitures[model.Id] = (shop.Furnitures[model.Id].Item1, 0); + } + else + { + shop.Furnitures[model.Id] = (shop.Furnitures[model.Id].Item1, shop.Furnitures[model.Id].Item2 - count); + count -= count; + } + + Update(new() + { + ShopName = shop.ShopName, + Address = shop.Address, + DateOpen = shop.DateOpen, + MaxCountFurnitures = shop.MaxCountFurnitures, + Furnitures = shop.Furnitures + }); + + if (count == 0) + { + return true; + } + } + + return true; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Shop.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Shop.cs new file mode 100644 index 0000000..8047f0f --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Shop.cs @@ -0,0 +1,111 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace FurnitureAssemblyFileImplement.Models +{ + // Класс, реализующий интерфейс модели магазина + public class Shop : IShopModel + { + public int Id { get; set; } + + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpen { get; set; } + + public int MaxCountFurnitures { get; set; } + + public Dictionary countFurniture { get; private set; } = new(); + + public Dictionary _furnitures = null; + + public Dictionary Furnitures + { + get + { + if (_furnitures == null) + { + var source = DataFileSingleton.GetInstance(); + _furnitures = countFurniture.ToDictionary(x => x.Key, y => ((source.Furnitures.FirstOrDefault(z => z.Id == y.Key) as IFurnitureModel)!, y.Value)); + } + + return _furnitures; + } + } + + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + MaxCountFurnitures = model.MaxCountFurnitures, + countFurniture = model.Furnitures.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Shop? Create(XElement element) + + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + DateOpen = Convert.ToDateTime(element.Element("DateOpen")!.Value), + MaxCountFurnitures = Convert.ToInt32(element.Element("MaxCountFurnitures")!.Value), + countFurniture = element.Element("Furnitures")!.Elements("Furnitures").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + MaxCountFurnitures = model.MaxCountFurnitures; + countFurniture = model.Furnitures.ToDictionary(x => x.Key, x => x.Value.Item2); + _furnitures = null; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + MaxCountFurnitures = MaxCountFurnitures, + Furnitures = Furnitures + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpen", DateOpen.ToString()), + new XElement("MaxCountFurnitures", MaxCountFurnitures.ToString()), + new XElement("Furnitures", countFurniture.Select(x => new XElement("Furnitures", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs index 1e72d6b..4740bc0 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs @@ -21,11 +21,15 @@ namespace FurnitureAssemblyListImplement // Список для хранения заказов public List Orders { get; set; } + //список для хранения Магазинов + public List Shops { get; set; } + public DataListSingleton() { WorkPiece = new List(); Furnitures = new List(); Orders = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..226151e --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ShopStorage.cs @@ -0,0 +1,143 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using FurnitureAssemblyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyListImplement.Implements +{ + // Класс, реализующий интерфейс хранилища магазинов + public class ShopStorage : IShopStorage + { + // Поле для работы со списком магазинов + private readonly DataListSingleton _source; + + // Получение в конструкторе объекта DataListSingleton + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + // Получение элемента из списка заготовок + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (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.ShopName)) + { + return result; + } + + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + 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; + } + + // При создании магазина определяем для него новый id: ищем max id и прибавляем к нему 1 + 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 SellFurnitures(IFurnitureModel model, int count) + { + throw new NotImplementedException(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs index 92db798..2fccf76 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs @@ -28,6 +28,7 @@ namespace FurnitureAssemblyListImplement.Models public DateTime? DateImplement { get; private set; } + // Метод для создания объекта от класса-компонента на основе класса-BindingModel public static Order? Create(OrderBindingModel? model) { if(model == null) diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs new file mode 100644 index 0000000..70c476b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Shop.cs @@ -0,0 +1,71 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyListImplement.Models +{ + // Класс, реализующий интерфейс модели магазина + public class Shop : IShopModel + { + // Методы set сделали приватными, чтобы исключить неразрешённые манипуляции + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpen { get; private set; } + + public int Id { get; private set; } + + public int MaxCountFurnitures { get; set; } + + public Dictionary Furnitures { get; private set; } = + new Dictionary(); + + // Метод для создания объекта от класса-компонента на основе класса-BindingModel + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + Furnitures = model.Furnitures + }; + } + + // Метод изменения существующего объекта + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + Furnitures = model.Furnitures; + } + + // Метод для создания объекта класса ViewModel на основе данных объекта класса-компонента + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + Furnitures = Furnitures + }; + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.Designer.cs new file mode 100644 index 0000000..104793d --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.Designer.cs @@ -0,0 +1,151 @@ +namespace FurnitureAssemblyView +{ + partial class FormAddFurniture + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelFurniture = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelShop = new System.Windows.Forms.Label(); + this.comboBoxFurniture = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // labelFurniture + // + this.labelFurniture.AutoSize = true; + this.labelFurniture.Location = new System.Drawing.Point(28, 58); + this.labelFurniture.Name = "labelFurniture"; + this.labelFurniture.Size = new System.Drawing.Size(56, 15); + this.labelFurniture.TabIndex = 0; + this.labelFurniture.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(28, 91); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(28, 23); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(57, 15); + this.labelShop.TabIndex = 2; + this.labelShop.Text = "Магазин:"; + // + // comboBoxFurniture + // + this.comboBoxFurniture.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxFurniture.FormattingEnabled = true; + this.comboBoxFurniture.Location = new System.Drawing.Point(149, 55); + this.comboBoxFurniture.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxFurniture.Name = "comboBoxFurniture"; + this.comboBoxFurniture.Size = new System.Drawing.Size(230, 23); + this.comboBoxFurniture.TabIndex = 3; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(149, 88); + this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(230, 23); + this.textBoxCount.TabIndex = 4; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(209, 123); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(82, 22); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(297, 123); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // comboBoxShop + // + this.comboBoxShop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(149, 23); + this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(230, 23); + this.comboBoxShop.TabIndex = 8; + // + // FormAddFurniture + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(394, 159); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxFurniture); + this.Controls.Add(this.labelShop); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelFurniture); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormAddFurniture"; + this.Text = "Пополнение магазина"; + this.Load += new System.EventHandler(this.FormAddFurniture_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelFurniture; + private Label labelCount; + private Label labelShop; + private ComboBox comboBoxFurniture; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxShop; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.cs b/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.cs new file mode 100644 index 0000000..7ff52b0 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.cs @@ -0,0 +1,128 @@ +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +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 FurnitureAssemblyView +{ + public partial class FormAddFurniture : Form + { + private readonly ILogger _logger; + private readonly IFurnitureLogic _logicI; + private readonly IShopLogic _logicS; + + public FormAddFurniture(ILogger logger, IFurnitureLogic logicI, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicI = logicI; + _logicS = logicS; + } + + private void FormAddFurniture_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка списка изделий для пополнения"); + + try + { + var list = _logicI.ReadList(null); + + if (list != null) + { + comboBoxFurniture.DisplayMember = "FurnitureName"; + comboBoxFurniture.ValueMember = "Id"; + comboBoxFurniture.DataSource = list; + comboBoxFurniture.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка списка магазинов для пополнения"); + try + { + var list = _logicS.ReadList(null); + + if (list != null) + { + comboBoxShop.DisplayMember = "ShopName"; + 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 ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxFurniture.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Пополнение магазина"); + + try + { + var operationResult = _logicS.AddFurniture(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }, + + _logicI.ReadElement(new FurnitureSearchModel() + { + Id = Convert.ToInt32(comboBoxFurniture.SelectedValue) + })!, 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/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.resx b/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormAddFurniture.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.Designer.cs index e7b3465..0200b5a 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.Designer.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.Designer.cs @@ -28,82 +28,83 @@ /// private void InitializeComponent() { - labelWorkPiece = new Label(); - labelCount = new Label(); - comboBoxWorkPiece = new ComboBox(); - textBoxCount = new TextBox(); - buttonSave = new Button(); - buttonCancel = new Button(); - SuspendLayout(); + this.labelWorkPiece = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxWorkPiece = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); // // labelWorkPiece // - labelWorkPiece.AutoSize = true; - labelWorkPiece.Location = new Point(31, 33); - labelWorkPiece.Name = "labelWorkPiece"; - labelWorkPiece.Size = new Size(81, 20); - labelWorkPiece.TabIndex = 0; - labelWorkPiece.Text = "Заготовка:"; + this.labelWorkPiece.AutoSize = true; + this.labelWorkPiece.Location = new System.Drawing.Point(31, 33); + this.labelWorkPiece.Name = "labelWorkPiece"; + this.labelWorkPiece.Size = new System.Drawing.Size(81, 20); + this.labelWorkPiece.TabIndex = 0; + this.labelWorkPiece.Text = "Заготовка:"; // // labelCount // - labelCount.AutoSize = true; - labelCount.Location = new Point(31, 79); - labelCount.Name = "labelCount"; - labelCount.Size = new Size(93, 20); - labelCount.TabIndex = 1; - labelCount.Text = "Количество:"; + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(31, 79); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; // // comboBoxWorkPiece // - comboBoxWorkPiece.FormattingEnabled = true; - comboBoxWorkPiece.Location = new Point(156, 30); - comboBoxWorkPiece.Name = "comboBoxWorkPiece"; - comboBoxWorkPiece.Size = new Size(320, 28); - comboBoxWorkPiece.TabIndex = 2; + this.comboBoxWorkPiece.FormattingEnabled = true; + this.comboBoxWorkPiece.Location = new System.Drawing.Point(156, 30); + this.comboBoxWorkPiece.Name = "comboBoxWorkPiece"; + this.comboBoxWorkPiece.Size = new System.Drawing.Size(320, 28); + this.comboBoxWorkPiece.TabIndex = 2; // // textBoxCount // - textBoxCount.Location = new Point(156, 76); - textBoxCount.Name = "textBoxCount"; - textBoxCount.Size = new Size(320, 27); - textBoxCount.TabIndex = 3; + this.textBoxCount.Location = new System.Drawing.Point(156, 76); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(320, 27); + this.textBoxCount.TabIndex = 3; // // buttonSave // - buttonSave.Location = new Point(236, 118); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(110, 38); - buttonSave.TabIndex = 4; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; + this.buttonSave.Location = new System.Drawing.Point(235, 118); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // // buttonCancel // - buttonCancel.Location = new Point(363, 118); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(113, 38); - buttonCancel.TabIndex = 5; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; + this.buttonCancel.Location = new System.Drawing.Point(353, 118); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // // FormFurnitureWorkPiece // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(526, 168); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(textBoxCount); - Controls.Add(comboBoxWorkPiece); - Controls.Add(labelCount); - Controls.Add(labelWorkPiece); - Name = "FormFurnitureWorkPiece"; - Text = "Заготовки для изделия"; - ResumeLayout(false); - PerformLayout(); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(526, 168); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxWorkPiece); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelWorkPiece); + this.Name = "FormFurnitureWorkPiece"; + this.Text = "Заготовки для изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.cs b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.cs index 4d8c935..ba1eb37 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.cs @@ -18,24 +18,21 @@ namespace FurnitureAssemblyView { private readonly List? _list; - public int Id - { - get { return Convert.ToInt32(comboBoxWorkPiece.SelectedValue); } - set { comboBoxWorkPiece.SelectedValue = value; } - } + public int Id { get { return Convert.ToInt32(comboBoxWorkPiece.SelectedValue); } + set { comboBoxWorkPiece.SelectedValue = value; } } public IWorkPieceModel? WorkPieceModel { get { - if (_list == null) + if(_list == null) { return null; } - foreach (var elem in _list) + foreach(var elem in _list) { - if (elem.Id == Id) + if(elem.Id == Id) { return elem; } @@ -45,14 +42,8 @@ namespace FurnitureAssemblyView } } - public int Count - { - get { return Convert.ToInt32(textBoxCount.Text); } - set - { - textBoxCount.Text = value.ToString(); - } - } + public int Count { get { return Convert.ToInt32(textBoxCount.Text); } set { + textBoxCount.Text = value.ToString(); } } public FormFurnitureWorkPiece(IWorkPieceLogic logic) { @@ -60,7 +51,7 @@ namespace FurnitureAssemblyView _list = logic.ReadList(null); - if (_list != null) + if(_list != null) { comboBoxWorkPiece.DisplayMember = "WorkPieceName"; comboBoxWorkPiece.ValueMember = "Id"; @@ -74,14 +65,14 @@ namespace FurnitureAssemblyView if (string.IsNullOrEmpty(textBoxCount.Text)) { MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - + return; } if (comboBoxWorkPiece.SelectedValue == null) { MessageBox.Show("Выберите заготовку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - + return; } diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.resx b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.resx index af32865..f298a7b 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.resx +++ b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitureWorkPiece.resx @@ -1,64 +1,4 @@ - - - + diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitures.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitures.Designer.cs index d234812..6fec1fc 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormFurnitures.Designer.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormFurnitures.Designer.cs @@ -66,7 +66,7 @@ buttonDelete.UseVisualStyleBackColor = true; buttonDelete.Click += ButtonDelete_Click; // - // buttonRef + // buttonRefresh // buttonRefresh.Location = new Point(640, 245); buttonRefresh.Name = "buttonRef"; diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormMain.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormMain.Designer.cs index 285c4e7..ce999eb 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormMain.Designer.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormMain.Designer.cs @@ -38,6 +38,9 @@ toolStripMenuItem = new ToolStripMenuItem(); workPieceToolStripMenuItem = new ToolStripMenuItem(); furnitureToolStripMenuItem = new ToolStripMenuItem(); + shopToolStripMenuItem = new ToolStripMenuItem(); + addFurnitureToolStripMenuItem = new ToolStripMenuItem(); + buttonSellFurniture = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip.SuspendLayout(); SuspendLayout(); @@ -45,18 +48,20 @@ // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(11, 36); + dataGridView.Location = new Point(10, 27); + dataGridView.Margin = new Padding(3, 2, 3, 2); dataGridView.Name = "dataGridView"; dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(937, 403); + dataGridView.Size = new Size(820, 302); dataGridView.TabIndex = 0; // // buttonCreateOrder // - buttonCreateOrder.Location = new Point(1014, 67); + buttonCreateOrder.Location = new Point(887, 38); + buttonCreateOrder.Margin = new Padding(3, 2, 3, 2); buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(235, 46); + buttonCreateOrder.Size = new Size(216, 36); buttonCreateOrder.TabIndex = 1; buttonCreateOrder.Text = "Создать заказ"; buttonCreateOrder.UseVisualStyleBackColor = true; @@ -64,9 +69,10 @@ // // buttonTakeOrderInWork // - buttonTakeOrderInWork.Location = new Point(1014, 143); + buttonTakeOrderInWork.Location = new Point(887, 96); + buttonTakeOrderInWork.Margin = new Padding(3, 2, 3, 2); buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(235, 48); + buttonTakeOrderInWork.Size = new Size(216, 34); buttonTakeOrderInWork.TabIndex = 2; buttonTakeOrderInWork.Text = "Отдать на выполнение"; buttonTakeOrderInWork.UseVisualStyleBackColor = true; @@ -74,9 +80,10 @@ // // buttonOrderReady // - buttonOrderReady.Location = new Point(1014, 220); + buttonOrderReady.Location = new Point(887, 148); + buttonOrderReady.Margin = new Padding(3, 2, 3, 2); buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(235, 41); + buttonOrderReady.Size = new Size(216, 33); buttonOrderReady.TabIndex = 3; buttonOrderReady.Text = "Заказ готов"; buttonOrderReady.UseVisualStyleBackColor = true; @@ -84,9 +91,10 @@ // // buttonIssuedOrder // - buttonIssuedOrder.Location = new Point(1014, 289); + buttonIssuedOrder.Location = new Point(887, 201); + buttonIssuedOrder.Margin = new Padding(3, 2, 3, 2); buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(235, 44); + buttonIssuedOrder.Size = new Size(216, 32); buttonIssuedOrder.TabIndex = 4; buttonIssuedOrder.Text = "Заказ выдан"; buttonIssuedOrder.UseVisualStyleBackColor = true; @@ -94,13 +102,14 @@ // // buttonRefresh // - buttonRefresh.Location = new Point(1014, 359); + buttonRefresh.Location = new Point(887, 250); + buttonRefresh.Margin = new Padding(3, 2, 3, 2); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(235, 39); + buttonRefresh.Size = new Size(216, 31); buttonRefresh.TabIndex = 5; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRef_Click; + buttonRefresh.Click += ButtonRefresh_Click; // // menuStrip // @@ -108,37 +117,63 @@ menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Padding = new Padding(6, 3, 0, 3); - menuStrip.Size = new Size(1297, 30); + menuStrip.Padding = new Padding(5, 2, 0, 2); + menuStrip.Size = new Size(1135, 24); menuStrip.TabIndex = 6; menuStrip.Text = "menuStrip"; // // toolStripMenuItem // - toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { workPieceToolStripMenuItem, furnitureToolStripMenuItem }); + toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { workPieceToolStripMenuItem, furnitureToolStripMenuItem, shopToolStripMenuItem, addFurnitureToolStripMenuItem }); toolStripMenuItem.Name = "toolStripMenuItem"; - toolStripMenuItem.Size = new Size(117, 24); + toolStripMenuItem.Size = new Size(94, 20); toolStripMenuItem.Text = "Справочники"; // // workPieceToolStripMenuItem // workPieceToolStripMenuItem.Name = "workPieceToolStripMenuItem"; - workPieceToolStripMenuItem.Size = new Size(224, 26); + workPieceToolStripMenuItem.Size = new Size(198, 22); workPieceToolStripMenuItem.Text = "Заготовки"; workPieceToolStripMenuItem.Click += WorkPieceToolStripMenuItem_Click; // // furnitureToolStripMenuItem // furnitureToolStripMenuItem.Name = "furnitureToolStripMenuItem"; - furnitureToolStripMenuItem.Size = new Size(224, 26); + furnitureToolStripMenuItem.Size = new Size(198, 22); furnitureToolStripMenuItem.Text = "Изделия"; furnitureToolStripMenuItem.Click += FurnitureToolStripMenuItem_Click; // + // shopToolStripMenuItem + // + shopToolStripMenuItem.Name = "shopToolStripMenuItem"; + shopToolStripMenuItem.Size = new Size(198, 22); + shopToolStripMenuItem.Text = "Магазины"; + shopToolStripMenuItem.Click += ShopToolStripMenuItem_Click; + // + // addFurnitureToolStripMenuItem + // + addFurnitureToolStripMenuItem.Name = "addFurnitureToolStripMenuItem"; + addFurnitureToolStripMenuItem.Size = new Size(198, 22); + addFurnitureToolStripMenuItem.Text = "Пополнение магазина"; + addFurnitureToolStripMenuItem.Click += AddFurnitureToolStripMenuItem_Click; + // + // buttonSellFurniture + // + buttonSellFurniture.Location = new Point(887, 297); + buttonSellFurniture.Margin = new Padding(3, 2, 3, 2); + buttonSellFurniture.Name = "buttonSellFurniture"; + buttonSellFurniture.Size = new Size(216, 30); + buttonSellFurniture.TabIndex = 8; + buttonSellFurniture.Text = "Продажа изделий"; + buttonSellFurniture.UseVisualStyleBackColor = true; + buttonSellFurniture.Click += ButtonSellFurniture_Click; + // // FormMain // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1297, 451); + ClientSize = new Size(1135, 338); + Controls.Add(buttonSellFurniture); Controls.Add(buttonRefresh); Controls.Add(buttonIssuedOrder); Controls.Add(buttonOrderReady); @@ -147,6 +182,7 @@ Controls.Add(dataGridView); Controls.Add(menuStrip); MainMenuStrip = menuStrip; + Margin = new Padding(3, 2, 3, 2); Name = "FormMain"; Text = "Сборка мебели"; Load += FormMain_Load; @@ -169,5 +205,8 @@ private ToolStripMenuItem toolStripMenuItem; private ToolStripMenuItem workPieceToolStripMenuItem; private ToolStripMenuItem furnitureToolStripMenuItem; + private ToolStripMenuItem shopToolStripMenuItem; + private ToolStripMenuItem addFurnitureToolStripMenuItem; + private Button buttonSellFurniture; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormMain.cs b/FurnitureAssembly/FurnitureAssemblyView/FormMain.cs index fcbb570..0a48241 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormMain.cs @@ -177,9 +177,41 @@ namespace FurnitureAssemblyView } } - private void ButtonRef_Click(object sender, EventArgs e) + private void ButtonRefresh_Click(object sender, EventArgs e) { LoadData(); } + + private void ShopToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + + private void AddFurnitureToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddFurniture)); + + if (service is FormAddFurniture form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void ButtonSellFurniture_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellFurniture)); + if (service is FormSellFurniture form) + { + form.ShowDialog(); + LoadData(); + } + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.Designer.cs new file mode 100644 index 0000000..405e88c --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.Designer.cs @@ -0,0 +1,125 @@ +namespace FurnitureAssemblyView +{ + partial class FormSellFurniture + { + /// + /// 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() + { + labelFurniture = new Label(); + labelCount = new Label(); + comboBoxFurniture = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelFurniture + // + labelFurniture.AutoSize = true; + labelFurniture.Location = new Point(28, 24); + labelFurniture.Name = "labelFurniture"; + labelFurniture.Size = new Size(56, 15); + labelFurniture.TabIndex = 0; + labelFurniture.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(30, 64); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // comboBoxFurniture + // + comboBoxFurniture.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxFurniture.FormattingEnabled = true; + comboBoxFurniture.Location = new Point(149, 24); + comboBoxFurniture.Margin = new Padding(3, 2, 3, 2); + comboBoxFurniture.Name = "comboBoxFurniture"; + comboBoxFurniture.Size = new Size(230, 23); + comboBoxFurniture.TabIndex = 3; + // + // textBoxCount + // + textBoxCount.Location = new Point(149, 64); + textBoxCount.Margin = new Padding(3, 2, 3, 2); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(230, 23); + textBoxCount.TabIndex = 4; + // + // buttonSave + // + buttonSave.Location = new Point(169, 102); + buttonSave.Margin = new Padding(3, 2, 3, 2); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 26); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(282, 102); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(97, 26); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormSellFurniture + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(385, 135); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxFurniture); + Controls.Add(labelCount); + Controls.Add(labelFurniture); + Margin = new Padding(3, 2, 3, 2); + Name = "FormSellFurniture"; + Text = "Продажа изделий"; + Load += FormSellFurniture_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelFurniture; + private Label labelCount; + private ComboBox comboBoxFurniture; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.cs b/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.cs new file mode 100644 index 0000000..260913d --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.cs @@ -0,0 +1,100 @@ +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +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 FurnitureAssemblyView +{ + public partial class FormSellFurniture : Form + { + private readonly ILogger _logger; + + private readonly IFurnitureLogic _logicI; + + private readonly IShopLogic _logicS; + + public FormSellFurniture(ILogger logger, IFurnitureLogic logicI, IShopLogic logicS) + { + InitializeComponent(); + + _logger = logger; + _logicI = logicI; + _logicS = logicS; + } + + private void FormSellFurniture_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка списка изделий для продажи"); + + try + { + var list = _logicI.ReadList(null); + if (list != null) + { + comboBoxFurniture.DisplayMember = "FurnitureName"; + comboBoxFurniture.ValueMember = "Id"; + comboBoxFurniture.DataSource = list; + comboBoxFurniture.SelectedItem = null; + } + } + 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(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxFurniture.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Продажа изделия"); + + try + { + var operationResult = _logicS.SellFurnitures(_logicI.ReadElement(new FurnitureSearchModel() + { + Id = Convert.ToInt32(comboBoxFurniture.SelectedValue) + })!, 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/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.resx b/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormSellFurniture.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/FurnitureAssembly/FurnitureAssemblyView/FormShop.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormShop.Designer.cs new file mode 100644 index 0000000..0bfb5a5 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormShop.Designer.cs @@ -0,0 +1,231 @@ +namespace FurnitureAssemblyView +{ + 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(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + groupBoxFurniture = new GroupBox(); + dataGridView = new DataGridView(); + ID = new DataGridViewTextBoxColumn(); + ColumnFurnitureName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelDate = new Label(); + dateTimePickerDate = new DateTimePicker(); + labelCount = new Label(); + numericUpDownCount = new NumericUpDown(); + groupBoxFurniture.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(18, 10); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(266, 9); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(43, 15); + labelAddress.TabIndex = 1; + labelAddress.Text = "Адрес:"; + // + // textBoxName + // + textBoxName.Location = new Point(94, 8); + textBoxName.Margin = new Padding(3, 2, 3, 2); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(138, 23); + textBoxName.TabIndex = 2; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(318, 7); + textBoxAddress.Margin = new Padding(3, 2, 3, 2); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(138, 23); + textBoxAddress.TabIndex = 3; + // + // groupBoxFurniture + // + groupBoxFurniture.Controls.Add(dataGridView); + groupBoxFurniture.Location = new Point(12, 70); + groupBoxFurniture.Margin = new Padding(3, 2, 3, 2); + groupBoxFurniture.Name = "groupBoxFurniture"; + groupBoxFurniture.Padding = new Padding(3, 2, 3, 2); + groupBoxFurniture.Size = new Size(720, 206); + groupBoxFurniture.TabIndex = 4; + groupBoxFurniture.TabStop = false; + groupBoxFurniture.Text = "Изделия"; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ColumnFurnitureName, ColumnCount }); + dataGridView.Location = new Point(5, 20); + dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(709, 182); + dataGridView.TabIndex = 0; + // + // ID + // + ID.HeaderText = "ID"; + ID.MinimumWidth = 6; + ID.Name = "ID"; + ID.Visible = false; + ID.Width = 125; + // + // ColumnFurnitureName + // + ColumnFurnitureName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnFurnitureName.HeaderText = "Изделие"; + ColumnFurnitureName.MinimumWidth = 6; + ColumnFurnitureName.Name = "ColumnFurnitureName"; + ColumnFurnitureName.Resizable = DataGridViewTriState.True; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.Width = 125; + // + // buttonSave + // + buttonSave.Location = new Point(396, 286); + buttonSave.Margin = new Padding(3, 2, 3, 2); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(151, 33); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(569, 286); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(146, 33); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(492, 9); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(90, 15); + labelDate.TabIndex = 7; + labelDate.Text = "Дата открытия:"; + // + // dateTimePickerDate + // + dateTimePickerDate.Location = new Point(596, 7); + dateTimePickerDate.Name = "dateTimePickerDate"; + dateTimePickerDate.Size = new Size(127, 23); + dateTimePickerDate.TabIndex = 9; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(18, 41); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(137, 15); + labelCount.TabIndex = 10; + labelCount.Text = "Вместимость магазина:"; + // + // numericUpDownCount + // + numericUpDownCount.Location = new Point(175, 40); + numericUpDownCount.Name = "numericUpDownCount"; + numericUpDownCount.Size = new Size(127, 23); + numericUpDownCount.TabIndex = 11; + // + // FormShop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(744, 330); + Controls.Add(numericUpDownCount); + Controls.Add(labelCount); + Controls.Add(dateTimePickerDate); + Controls.Add(labelDate); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxFurniture); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Controls.Add(labelAddress); + Controls.Add(labelName); + Margin = new Padding(3, 2, 3, 2); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + groupBoxFurniture.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelAddress; + private TextBox textBoxName; + private TextBox textBoxAddress; + private GroupBox groupBoxFurniture; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private Label labelDate; + private DateTimePicker dateTimePickerDate; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ColumnFurnitureName; + private DataGridViewTextBoxColumn ColumnCount; + private Label labelCount; + private NumericUpDown numericUpDownCount; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormShop.cs b/FurnitureAssembly/FurnitureAssemblyView/FormShop.cs new file mode 100644 index 0000000..b5f9a8a --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormShop.cs @@ -0,0 +1,139 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +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 FurnitureAssemblyView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + private int? _id; + + private Dictionary _shopFurnitures; + + public int Id { set { _id = value; } } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + + _logger = logger; + _logic = logic; + _shopFurnitures = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address.ToString(); + dateTimePickerDate.Value = view.DateOpen; + numericUpDownCount.Value = view.MaxCountFurnitures; + _shopFurnitures = view.Furnitures ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий в магазине"); + try + { + if (_shopFurnitures != null) + { + dataGridView.Rows.Clear(); + foreach (var element in _shopFurnitures) + { + dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.FurnitureName, element.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, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpen = dateTimePickerDate.Value.Date, + Furnitures = _shopFurnitures, + MaxCountFurnitures = (int)numericUpDownCount.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/FurnitureAssembly/FurnitureAssemblyView/FormShop.resx b/FurnitureAssembly/FurnitureAssemblyView/FormShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormShop.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/FurnitureAssembly/FurnitureAssemblyView/FormShops.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormShops.Designer.cs new file mode 100644 index 0000000..0b35002 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormShops.Designer.cs @@ -0,0 +1,120 @@ +namespace FurnitureAssemblyView +{ + 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(); + buttonAdd = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(10, 9); + dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(444, 320); + dataGridView.TabIndex = 1; + // + // buttonAdd + // + buttonAdd.Location = new Point(465, 24); + buttonAdd.Margin = new Padding(3, 2, 3, 2); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(133, 35); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(465, 108); + buttonUpdate.Margin = new Padding(3, 2, 3, 2); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(133, 33); + buttonUpdate.TabIndex = 3; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(465, 183); + buttonDelete.Margin = new Padding(3, 2, 3, 2); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(133, 36); + buttonDelete.TabIndex = 4; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(465, 261); + buttonRefresh.Margin = new Padding(3, 2, 3, 2); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(133, 35); + buttonRefresh.TabIndex = 5; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(610, 338); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Margin = new Padding(3, 2, 3, 2); + Name = "FormShops"; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormShops.cs b/FurnitureAssembly/FurnitureAssemblyView/FormShops.cs new file mode 100644 index 0000000..bab28f9 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/FormShops.cs @@ -0,0 +1,117 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +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 FurnitureAssemblyView +{ + 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["Furnitures"].Visible = false; + dataGridView.Columns["ShopName"].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 ButtonUpdate_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); + } + } + } + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormShops.resx b/FurnitureAssembly/FurnitureAssemblyView/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyView/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 diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.Designer.cs index 287673e..ef8faab 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.Designer.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.Designer.cs @@ -28,83 +28,87 @@ /// private void InitializeComponent() { - this.labelName = new System.Windows.Forms.Label(); - this.labelPrice = new System.Windows.Forms.Label(); - this.textBoxName = new System.Windows.Forms.TextBox(); - this.textBoxCost = new System.Windows.Forms.TextBox(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.buttonSave = new System.Windows.Forms.Button(); - this.SuspendLayout(); + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); // // labelName // - this.labelName.AutoSize = true; - this.labelName.Location = new System.Drawing.Point(30, 24); - this.labelName.Name = "labelName"; - this.labelName.Size = new System.Drawing.Size(80, 20); - this.labelName.TabIndex = 0; - this.labelName.Text = "Название:"; + labelName.AutoSize = true; + labelName.Location = new Point(26, 18); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; // // labelPrice // - this.labelPrice.AutoSize = true; - this.labelPrice.Location = new System.Drawing.Point(30, 65); - this.labelPrice.Name = "labelPrice"; - this.labelPrice.Size = new System.Drawing.Size(48, 20); - this.labelPrice.TabIndex = 1; - this.labelPrice.Text = "Цена:"; + labelPrice.AutoSize = true; + labelPrice.Location = new Point(26, 49); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(38, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена:"; // // textBoxName // - this.textBoxName.Location = new System.Drawing.Point(127, 21); - this.textBoxName.Name = "textBoxName"; - this.textBoxName.Size = new System.Drawing.Size(293, 27); - this.textBoxName.TabIndex = 2; + textBoxName.Location = new Point(111, 16); + textBoxName.Margin = new Padding(3, 2, 3, 2); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(257, 23); + textBoxName.TabIndex = 2; // // textBoxCost // - this.textBoxCost.Location = new System.Drawing.Point(127, 62); - this.textBoxCost.Name = "textBoxCost"; - this.textBoxCost.Size = new System.Drawing.Size(179, 27); - this.textBoxCost.TabIndex = 3; + textBoxCost.Location = new Point(111, 46); + textBoxCost.Margin = new Padding(3, 2, 3, 2); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(157, 23); + textBoxCost.TabIndex = 3; // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(326, 104); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(94, 29); - this.buttonCancel.TabIndex = 4; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + buttonCancel.Location = new Point(289, 78); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(105, 26); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(212, 104); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(94, 29); - this.buttonSave.TabIndex = 5; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + buttonSave.Location = new Point(171, 78); + buttonSave.Margin = new Padding(3, 2, 3, 2); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(97, 26); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; // // FormWorkPiece // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(464, 153); - this.Controls.Add(this.buttonSave); - this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.textBoxCost); - this.Controls.Add(this.textBoxName); - this.Controls.Add(this.labelPrice); - this.Controls.Add(this.labelName); - this.Name = "FormWorkPiece"; - this.Text = "Заготовка"; - this.Load += new System.EventHandler(this.FormWorkPiece_Load); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(406, 115); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Margin = new Padding(3, 2, 3, 2); + Name = "FormWorkPiece"; + Text = "Заготовка"; + Load += FormWorkPiece_Load; + ResumeLayout(false); + PerformLayout(); } #endregion diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.resx b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.resx index f298a7b..af32865 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.resx +++ b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPiece.resx @@ -1,4 +1,64 @@ - + + + diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.Designer.cs b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.Designer.cs index 876791a..531cab9 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.Designer.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.Designer.cs @@ -38,9 +38,10 @@ // // buttonAdd // - buttonAdd.Location = new Point(641, 36); + buttonAdd.Location = new Point(561, 27); + buttonAdd.Margin = new Padding(3, 2, 3, 2); buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(116, 47); + buttonAdd.Size = new Size(100, 38); buttonAdd.TabIndex = 0; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; @@ -48,9 +49,10 @@ // // buttonUpdate // - buttonUpdate.Location = new Point(641, 102); + buttonUpdate.Location = new Point(561, 85); + buttonUpdate.Margin = new Padding(3, 2, 3, 2); buttonUpdate.Name = "buttonUpdate"; - buttonUpdate.Size = new Size(116, 47); + buttonUpdate.Size = new Size(100, 36); buttonUpdate.TabIndex = 1; buttonUpdate.Text = "Изменить"; buttonUpdate.UseVisualStyleBackColor = true; @@ -58,9 +60,10 @@ // // buttonDelete // - buttonDelete.Location = new Point(641, 168); + buttonDelete.Location = new Point(561, 143); + buttonDelete.Margin = new Padding(3, 2, 3, 2); buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(116, 47); + buttonDelete.Size = new Size(100, 34); buttonDelete.TabIndex = 2; buttonDelete.Text = "Удалить"; buttonDelete.UseVisualStyleBackColor = true; @@ -68,9 +71,10 @@ // // buttonRefresh // - buttonRefresh.Location = new Point(641, 239); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(116, 47); + buttonRefresh.Location = new Point(561, 197); + buttonRefresh.Margin = new Padding(3, 2, 3, 2); + buttonRefresh.Name = "buttonRef"; + buttonRefresh.Size = new Size(100, 34); buttonRefresh.TabIndex = 3; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -79,23 +83,25 @@ // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(12, 12); + dataGridView.Location = new Point(10, 9); + dataGridView.Margin = new Padding(3, 2, 3, 2); dataGridView.Name = "dataGridView"; dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(604, 426); + dataGridView.Size = new Size(528, 320); dataGridView.TabIndex = 4; // // FormWorkPieces // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(781, 450); + ClientSize = new Size(683, 338); Controls.Add(dataGridView); Controls.Add(buttonRefresh); Controls.Add(buttonDelete); Controls.Add(buttonUpdate); Controls.Add(buttonAdd); + Margin = new Padding(3, 2, 3, 2); Name = "FormWorkPieces"; Text = "Заготовки"; Load += FormWorkPiece_Load; diff --git a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.cs b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.cs index 303f88b..6fedeeb 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/FormWorkPieces.cs @@ -76,7 +76,7 @@ namespace FurnitureAssemblyView if (dataGridView.SelectedRows.Count == 1) { var service = Program.ServiceProvider?.GetService(typeof(FormWorkPiece)); - + if (service is FormWorkPiece form) { form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/FurnitureAssembly/FurnitureAssemblyView/Program.cs b/FurnitureAssembly/FurnitureAssemblyView/Program.cs index 6fc4d21..94d6e56 100644 --- a/FurnitureAssembly/FurnitureAssemblyView/Program.cs +++ b/FurnitureAssembly/FurnitureAssemblyView/Program.cs @@ -41,10 +41,12 @@ namespace FurnitureAssemblyView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -53,6 +55,10 @@ namespace FurnitureAssemblyView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file