From ea5ba3cf1b43693dae603cad86f9e0bd0d6a866e Mon Sep 17 00:00:00 2001 From: Salikh Date: Sat, 23 Mar 2024 02:05:58 +0400 Subject: [PATCH 1/7] FirstCommit --- MotorPlant/MotorPlant.sln | 10 +- .../BusinessLogic/ShopLogic.cs | 156 ++++++++++++++ .../BindingModels/ShopBindingModel.cs | 18 ++ .../BusinessLogicsContracts/IShopLogic.cs | 22 ++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 21 ++ .../ViewModels/ShopViewModel.cs | 29 +++ .../MotorPlantDataModels/Models/IShopModel.cs | 15 ++ .../DataListSingleton.cs | 3 + .../Implements/ShopStorage.cs | 107 ++++++++++ .../MotorPlantListImplement/Models/Shop.cs | 54 +++++ MotorPlant/MotorPlantView/FormEngines.cs | 10 +- .../MotorPlantView/FormMain.Designer.cs | 63 +++--- MotorPlant/MotorPlantView/FormMain.cs | 20 ++ .../MotorPlantView/FormShop.Designer.cs | 193 ++++++++++++++++++ MotorPlant/MotorPlantView/FormShop.cs | 122 +++++++++++ MotorPlant/MotorPlantView/FormShop.resx | 120 +++++++++++ .../MotorPlantView/FormShops.Designer.cs | 114 +++++++++++ MotorPlant/MotorPlantView/FormShops.cs | 108 ++++++++++ MotorPlant/MotorPlantView/FormShops.resx | 120 +++++++++++ .../MotorPlantView/FormSupply.Designer.cs | 147 +++++++++++++ MotorPlant/MotorPlantView/FormSupply.cs | 140 +++++++++++++ MotorPlant/MotorPlantView/FormSupply.resx | 120 +++++++++++ MotorPlant/MotorPlantView/Program.cs | 8 +- MotorPlant/ShopsForm/Form1.Designer.cs | 39 ++++ MotorPlant/ShopsForm/Form1.cs | 10 + MotorPlant/ShopsForm/Form1.resx | 120 +++++++++++ MotorPlant/ShopsForm/Program.cs | 17 ++ MotorPlant/ShopsForm/ShopsForm.csproj | 11 + 29 files changed, 1894 insertions(+), 37 deletions(-) create mode 100644 MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ShopLogic.cs create mode 100644 MotorPlant/MotorPlantContracts/BindingModels/ShopBindingModel.cs create mode 100644 MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 MotorPlant/MotorPlantContracts/SearchModels/ShopSearchModel.cs create mode 100644 MotorPlant/MotorPlantContracts/StoragesContracts/IShopStorage.cs create mode 100644 MotorPlant/MotorPlantContracts/ViewModels/ShopViewModel.cs create mode 100644 MotorPlant/MotorPlantDataModels/Models/IShopModel.cs create mode 100644 MotorPlant/MotorPlantListImplement/Implements/ShopStorage.cs create mode 100644 MotorPlant/MotorPlantListImplement/Models/Shop.cs create mode 100644 MotorPlant/MotorPlantView/FormShop.Designer.cs create mode 100644 MotorPlant/MotorPlantView/FormShop.cs create mode 100644 MotorPlant/MotorPlantView/FormShop.resx create mode 100644 MotorPlant/MotorPlantView/FormShops.Designer.cs create mode 100644 MotorPlant/MotorPlantView/FormShops.cs create mode 100644 MotorPlant/MotorPlantView/FormShops.resx create mode 100644 MotorPlant/MotorPlantView/FormSupply.Designer.cs create mode 100644 MotorPlant/MotorPlantView/FormSupply.cs create mode 100644 MotorPlant/MotorPlantView/FormSupply.resx create mode 100644 MotorPlant/ShopsForm/Form1.Designer.cs create mode 100644 MotorPlant/ShopsForm/Form1.cs create mode 100644 MotorPlant/ShopsForm/Form1.resx create mode 100644 MotorPlant/ShopsForm/Program.cs create mode 100644 MotorPlant/ShopsForm/ShopsForm.csproj diff --git a/MotorPlant/MotorPlant.sln b/MotorPlant/MotorPlant.sln index b12bd0e..60fc674 100644 --- a/MotorPlant/MotorPlant.sln +++ b/MotorPlant/MotorPlant.sln @@ -3,15 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.7.34031.279 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotorPlantView", "MotorPlantView\MotorPlantView.csproj", "{254164C1-CDF8-4F3C-8564-8C8987B7BFA1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantView", "MotorPlantView\MotorPlantView.csproj", "{254164C1-CDF8-4F3C-8564-8C8987B7BFA1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotorPlantDataModels", "MotorPlantDataModels\MotorPlantDataModels.csproj", "{F9D3BBA7-D038-4F69-911E-0A25407E4716}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantDataModels", "MotorPlantDataModels\MotorPlantDataModels.csproj", "{F9D3BBA7-D038-4F69-911E-0A25407E4716}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotorPlantContracts", "MotorPlantContracts\MotorPlantContracts.csproj", "{B2784391-936D-471E-BB99-215CB345B1CD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantContracts", "MotorPlantContracts\MotorPlantContracts.csproj", "{B2784391-936D-471E-BB99-215CB345B1CD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotorPlantListImplement", "MotorPlantListImplement\MotorPlantListImplement.csproj", "{0694ECF1-AEF8-4033-A0BF-EAA22A733F31}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantListImplement", "MotorPlantListImplement\MotorPlantListImplement.csproj", "{0694ECF1-AEF8-4033-A0BF-EAA22A733F31}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotorPlantBusinessLogic", "MotorPlantBusinessLogic\MotorPlantBusinessLogic.csproj", "{75003AA5-9D46-45B6-9EF0-BAF16E2790EA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantBusinessLogic", "MotorPlantBusinessLogic\MotorPlantBusinessLogic.csproj", "{75003AA5-9D46-45B6-9EF0-BAF16E2790EA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ShopLogic.cs b/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..a85fe49 --- /dev/null +++ b/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -0,0 +1,156 @@ +using Microsoft.Extensions.Logging; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.StoragesContracts; +using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantBusinessLogic.BusinessLogic +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + public List ReadList(ShopSearchModel model) + { + _logger.LogInformation("ReadList. ShopName:{Name}. Id:{ Id}", model?.Name, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ShopViewModel ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + 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; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Нет названия магазина", + nameof(model.ShopName)); + } + if (string.IsNullOrEmpty(model.Adress)) + { + throw new ArgumentNullException("Нет адресса магазина", + nameof(model.ShopName)); + } + if (model.DateOpen == null) + { + throw new ArgumentNullException("Нет даты открытия магазина", + nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}", model.ShopName, model.Adress, model.DateOpen, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + public bool MakeSupply(ShopSearchModel model, IEngineModel dress, int count) + { + if (model == null) + throw new ArgumentNullException(nameof(model)); + if (dress == null) + throw new ArgumentNullException(nameof(dress)); + if (count <= 0) + throw new ArgumentNullException("Количество должно быть положительным числом"); + + ShopViewModel? curModel = _shopStorage.GetElement(model); + _logger.LogInformation("Make Supply. Id: {Id}. ShopName: {Name}", model.Id, model.Name); + if (curModel == null) + throw new ArgumentNullException(nameof(curModel)); + if (curModel.ShopEngines.TryGetValue(dress.Id, out var pair)) + { + curModel.ShopEngines[dress.Id] = (pair.Item1, pair.Item2 + count); + _logger.LogInformation("Make Supply. Add Dress. DressName: {Name}. Count: {Count}", pair.Item1, count + pair.Item2); + } + else + { + curModel.ShopEngines.Add(dress.Id, (dress, count)); + _logger.LogInformation("Make Supply. Add new Dress. DressName: {Name}. Count: {Count}", pair.Item1, count); + } + + return Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + DateOpen = curModel.DateOpen, + Adress = curModel.Adress, + ShopEngines = curModel.ShopEngines, + }); + } + } +} diff --git a/MotorPlant/MotorPlantContracts/BindingModels/ShopBindingModel.cs b/MotorPlant/MotorPlantContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..855a76f --- /dev/null +++ b/MotorPlant/MotorPlantContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,18 @@ +using MotorPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } + public string Adress { get; set; } + public DateTime DateOpen { get; set; } + public Dictionary ShopEngines { get; set; } = new(); + } +} diff --git a/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs b/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..15e3fc8 --- /dev/null +++ b/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.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 MakeSupply(ShopSearchModel model, IEngineModel dress, int count); + } +} diff --git a/MotorPlant/MotorPlantContracts/SearchModels/ShopSearchModel.cs b/MotorPlant/MotorPlantContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..470bafb --- /dev/null +++ b/MotorPlant/MotorPlantContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/MotorPlant/MotorPlantContracts/StoragesContracts/IShopStorage.cs b/MotorPlant/MotorPlantContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..48c46db --- /dev/null +++ b/MotorPlant/MotorPlantContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.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); + } +} diff --git a/MotorPlant/MotorPlantContracts/ViewModels/ShopViewModel.cs b/MotorPlant/MotorPlantContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..4cd1610 --- /dev/null +++ b/MotorPlant/MotorPlantContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,29 @@ +using MotorPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес")] + + public string Adress { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + + public DateTime DateOpen { get; set; } + + public Dictionary ShopEngines { get; set; } = new(); + } +} diff --git a/MotorPlant/MotorPlantDataModels/Models/IShopModel.cs b/MotorPlant/MotorPlantDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..7552320 --- /dev/null +++ b/MotorPlant/MotorPlantDataModels/Models/IShopModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Adress { get; } + DateTime DateOpen { get; } + } +} diff --git a/MotorPlant/MotorPlantListImplement/DataListSingleton.cs b/MotorPlant/MotorPlantListImplement/DataListSingleton.cs index 4bd61f6..763c235 100644 --- a/MotorPlant/MotorPlantListImplement/DataListSingleton.cs +++ b/MotorPlant/MotorPlantListImplement/DataListSingleton.cs @@ -12,11 +12,14 @@ namespace MotorPlantListImplement public List Engines { get; set; } + public List Shops { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Engines = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() diff --git a/MotorPlant/MotorPlantListImplement/Implements/ShopStorage.cs b/MotorPlant/MotorPlantListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..6ba0064 --- /dev/null +++ b/MotorPlant/MotorPlantListImplement/Implements/ShopStorage.cs @@ -0,0 +1,107 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.StoragesContracts; +using MotorPlantContracts.ViewModels; +using MotorPlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.Name)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.Name)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.Name) && + shop.ShopName == model.Name) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + 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; + } + } +} diff --git a/MotorPlant/MotorPlantListImplement/Models/Shop.cs b/MotorPlant/MotorPlantListImplement/Models/Shop.cs new file mode 100644 index 0000000..ef03e2e --- /dev/null +++ b/MotorPlant/MotorPlantListImplement/Models/Shop.cs @@ -0,0 +1,54 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } + public string Adress { get; private set; } + public DateTime DateOpen { get; private set; } + public Dictionary ShopEngines { get; private set; } = new(); + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + DateOpen = model.DateOpen, + ShopEngines = new() + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + DateOpen = model.DateOpen; + ShopEngines = model.ShopEngines; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + DateOpen = DateOpen, + ShopEngines = ShopEngines + }; + } +} diff --git a/MotorPlant/MotorPlantView/FormEngines.cs b/MotorPlant/MotorPlantView/FormEngines.cs index 7e129dc..d686eec 100644 --- a/MotorPlant/MotorPlantView/FormEngines.cs +++ b/MotorPlant/MotorPlantView/FormEngines.cs @@ -15,11 +15,6 @@ namespace MotorPlantView.Forms _logic = logic; } - private void FormEngines_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() { try @@ -40,6 +35,11 @@ namespace MotorPlantView.Forms } } + private void FormEngines_Load(object sender, EventArgs e) + { + LoadData(); + } + private void buttonAdd_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormEngine)); diff --git a/MotorPlant/MotorPlantView/FormMain.Designer.cs b/MotorPlant/MotorPlantView/FormMain.Designer.cs index 1673d78..33f0712 100644 --- a/MotorPlant/MotorPlantView/FormMain.Designer.cs +++ b/MotorPlant/MotorPlantView/FormMain.Designer.cs @@ -32,6 +32,8 @@ toolStripDropDownButton1 = new ToolStripDropDownButton(); КомпонентыToolStripMenuItem = new ToolStripMenuItem(); ДвигателиToolStripMenuItem = new ToolStripMenuItem(); + ShopsToolStripMenuItem = new ToolStripMenuItem(); + поставкиToolStripMenuItem = new ToolStripMenuItem(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); @@ -48,41 +50,54 @@ toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1 }); toolStrip1.Location = new Point(0, 0); toolStrip1.Name = "toolStrip1"; - toolStrip1.Size = new Size(1126, 27); + toolStrip1.Size = new Size(985, 25); toolStrip1.TabIndex = 0; toolStrip1.Text = "toolStrip1"; // // toolStripDropDownButton1 // toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; - toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ДвигателиToolStripMenuItem }); + toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ДвигателиToolStripMenuItem, ShopsToolStripMenuItem, поставкиToolStripMenuItem }); toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; toolStripDropDownButton1.Name = "toolStripDropDownButton1"; - toolStripDropDownButton1.Size = new Size(108, 24); + toolStripDropDownButton1.Size = new Size(88, 22); toolStripDropDownButton1.Text = "Справочник"; // // КомпонентыToolStripMenuItem // КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; - КомпонентыToolStripMenuItem.Size = new Size(224, 26); + КомпонентыToolStripMenuItem.Size = new Size(180, 22); КомпонентыToolStripMenuItem.Text = "Компоненты"; КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; // // ДвигателиToolStripMenuItem // ДвигателиToolStripMenuItem.Name = "ДвигателиToolStripMenuItem"; - ДвигателиToolStripMenuItem.Size = new Size(224, 26); + ДвигателиToolStripMenuItem.Size = new Size(180, 22); ДвигателиToolStripMenuItem.Text = "Двигатели"; ДвигателиToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; // + // ShopsToolStripMenuItem + // + ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; + ShopsToolStripMenuItem.Size = new Size(180, 22); + ShopsToolStripMenuItem.Text = "Магазины"; + ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // поставкиToolStripMenuItem + // + поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem"; + поставкиToolStripMenuItem.Size = new Size(180, 22); + поставкиToolStripMenuItem.Text = "Поставки"; + поставкиToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; + // // buttonCreateOrder // buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonCreateOrder.BackColor = SystemColors.ControlLight; - buttonCreateOrder.Location = new Point(911, 195); - buttonCreateOrder.Margin = new Padding(3, 4, 3, 4); + buttonCreateOrder.Location = new Point(797, 146); buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(203, 40); + buttonCreateOrder.Size = new Size(178, 30); buttonCreateOrder.TabIndex = 1; buttonCreateOrder.Text = "Создать заказ"; buttonCreateOrder.UseVisualStyleBackColor = false; @@ -92,10 +107,9 @@ // buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonTakeOrderInWork.BackColor = SystemColors.ControlLight; - buttonTakeOrderInWork.Location = new Point(911, 258); - buttonTakeOrderInWork.Margin = new Padding(3, 4, 3, 4); + buttonTakeOrderInWork.Location = new Point(797, 194); buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(203, 40); + buttonTakeOrderInWork.Size = new Size(178, 30); buttonTakeOrderInWork.TabIndex = 2; buttonTakeOrderInWork.Text = "Отдать на выполнение"; buttonTakeOrderInWork.UseVisualStyleBackColor = false; @@ -105,10 +119,9 @@ // buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonOrderReady.BackColor = SystemColors.ControlLight; - buttonOrderReady.Location = new Point(911, 323); - buttonOrderReady.Margin = new Padding(3, 4, 3, 4); + buttonOrderReady.Location = new Point(797, 242); buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(203, 40); + buttonOrderReady.Size = new Size(178, 30); buttonOrderReady.TabIndex = 3; buttonOrderReady.Text = "Заказ готов"; buttonOrderReady.UseVisualStyleBackColor = false; @@ -118,10 +131,9 @@ // buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonIssuedOrder.BackColor = SystemColors.ControlLight; - buttonIssuedOrder.Location = new Point(911, 383); - buttonIssuedOrder.Margin = new Padding(3, 4, 3, 4); + buttonIssuedOrder.Location = new Point(797, 287); buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(203, 40); + buttonIssuedOrder.Size = new Size(178, 30); buttonIssuedOrder.TabIndex = 4; buttonIssuedOrder.Text = "Заказ выдан"; buttonIssuedOrder.UseVisualStyleBackColor = false; @@ -131,10 +143,9 @@ // buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonRef.BackColor = SystemColors.ControlLight; - buttonRef.Location = new Point(911, 133); - buttonRef.Margin = new Padding(3, 4, 3, 4); + buttonRef.Location = new Point(797, 100); buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(203, 40); + buttonRef.Size = new Size(178, 30); buttonRef.TabIndex = 5; buttonRef.Text = "Обновить список"; buttonRef.UseVisualStyleBackColor = false; @@ -145,21 +156,20 @@ dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; dataGridView.BackgroundColor = SystemColors.ButtonHighlight; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 35); - dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Location = new Point(11, 28); dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 24; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(891, 588); + dataGridView.Size = new Size(780, 441); dataGridView.TabIndex = 6; // // FormMain // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1126, 623); + ClientSize = new Size(985, 467); Controls.Add(dataGridView); Controls.Add(buttonRef); Controls.Add(buttonIssuedOrder); @@ -167,7 +177,6 @@ Controls.Add(buttonTakeOrderInWork); Controls.Add(buttonCreateOrder); Controls.Add(toolStrip1); - Margin = new Padding(3, 4, 3, 4); Name = "FormMain"; Text = "Моторный завод"; Load += FormMain_Load; @@ -190,5 +199,7 @@ private ToolStripDropDownButton toolStripDropDownButton1; private ToolStripMenuItem КомпонентыToolStripMenuItem; private ToolStripMenuItem ДвигателиToolStripMenuItem; + private ToolStripMenuItem ShopsToolStripMenuItem; + private ToolStripMenuItem поставкиToolStripMenuItem; } } \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormMain.cs b/MotorPlant/MotorPlantView/FormMain.cs index 06f7132..3172e11 100644 --- a/MotorPlant/MotorPlantView/FormMain.cs +++ b/MotorPlant/MotorPlantView/FormMain.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Logging; using MotorPlantContracts.BindingModels; using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantView; namespace MotorPlantView.Forms { @@ -143,5 +144,24 @@ namespace MotorPlantView.Forms { LoadData(); } + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); + + if (service is FormSupply form) + { + form.ShowDialog(); + } + } } } diff --git a/MotorPlant/MotorPlantView/FormShop.Designer.cs b/MotorPlant/MotorPlantView/FormShop.Designer.cs new file mode 100644 index 0000000..9e574fc --- /dev/null +++ b/MotorPlant/MotorPlantView/FormShop.Designer.cs @@ -0,0 +1,193 @@ +namespace MotorPlantView +{ + 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() + { + dateTimePicker = new DateTimePicker(); + textBoxName = new TextBox(); + textBoxAdress = new TextBox(); + dataGridView = new DataGridView(); + IdColumn = new DataGridViewTextBoxColumn(); + Title = new DataGridViewTextBoxColumn(); + Cost = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dateTimePicker + // + dateTimePicker.Location = new Point(714, 34); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(250, 27); + dateTimePicker.TabIndex = 0; + // + // textBoxName + // + textBoxName.Location = new Point(714, 85); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(250, 27); + textBoxName.TabIndex = 1; + // + // textBoxAdress + // + textBoxAdress.Location = new Point(714, 139); + textBoxAdress.Name = "textBoxAdress"; + textBoxAdress.Size = new Size(250, 27); + textBoxAdress.TabIndex = 2; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { IdColumn, Title, Cost, Count }); + dataGridView.Location = new Point(10, 32); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(554, 380); + dataGridView.TabIndex = 3; + // + // IdColumn + // + IdColumn.HeaderText = "Номер платья"; + IdColumn.MinimumWidth = 6; + IdColumn.Name = "IdColumn"; + IdColumn.Visible = false; + IdColumn.Width = 125; + // + // Title + // + Title.HeaderText = "Название"; + Title.MinimumWidth = 6; + Title.Name = "Title"; + Title.Width = 125; + // + // Cost + // + Cost.HeaderText = "Цена"; + Cost.MinimumWidth = 6; + Cost.Name = "Cost"; + Cost.Width = 125; + // + // Count + // + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + Count.Width = 125; + // + // buttonSave + // + buttonSave.Location = new Point(714, 219); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(870, 219); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(592, 39); + label1.Name = "label1"; + label1.Size = new Size(110, 20); + label1.TabIndex = 6; + label1.Text = "Дата создания"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(592, 88); + label2.Name = "label2"; + label2.Size = new Size(77, 20); + label2.TabIndex = 7; + label2.Text = "Название"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(592, 142); + label3.Name = "label3"; + label3.Size = new Size(51, 20); + label3.TabIndex = 8; + label3.Text = "Адрес"; + // + // ShopForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(976, 450); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(dataGridView); + Controls.Add(textBoxAdress); + Controls.Add(textBoxName); + Controls.Add(dateTimePicker); + Name = "ShopForm"; + Text = "Форма магазина"; + Load += ShopForm_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DateTimePicker dateTimePicker; + private TextBox textBoxName; + private TextBox textBoxAdress; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + private Label label3; + private DataGridViewTextBoxColumn IdColumn; + private DataGridViewTextBoxColumn Title; + private DataGridViewTextBoxColumn Cost; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormShop.cs b/MotorPlant/MotorPlantView/FormShop.cs new file mode 100644 index 0000000..a408e09 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormShop.cs @@ -0,0 +1,122 @@ +using Microsoft.Extensions.Logging; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using MotorPlantDataModels.Models; +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 MotorPlantView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public int? _id; + private Dictionary _engine; + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ShopForm_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Shop load"); + try + { + var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); + if (shop != null) + { + textBoxName.Text = shop.ShopName; + textBoxAdress.Text = shop.Adress; + dateTimePicker.Text = shop.DateOpen.ToString(); + _engine = shop.ShopEngines; + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Load shop error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Load engines"); + try + { + if (_engine != null) + { + foreach (var dress in _engine) + { + dataGridView.Rows.Add(new object[] { dress.Key, dress.Value.Item1.EngineName, dress.Value.Item1.Price, dress.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Load engines into shop error"); + 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(textBoxAdress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Save shop"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Adress = textBoxAdress.Text, + DateOpen = dateTimePicker.Value.Date, + ShopEngines = _engine + }; + 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, "Save shop error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/MotorPlant/MotorPlantView/FormShop.resx b/MotorPlant/MotorPlantView/FormShop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MotorPlant/MotorPlantView/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/MotorPlant/MotorPlantView/FormShops.Designer.cs b/MotorPlant/MotorPlantView/FormShops.Designer.cs new file mode 100644 index 0000000..b4d34e3 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormShops.Designer.cs @@ -0,0 +1,114 @@ +namespace MotorPlantView +{ + 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(); + buttonReset = new Button(); + buttonDelete = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(617, 426); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(665, 114); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(123, 45); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(665, 165); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(123, 44); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonReset + // + buttonReset.Location = new Point(665, 215); + buttonReset.Name = "buttonReset"; + buttonReset.Size = new Size(123, 48); + buttonReset.TabIndex = 3; + buttonReset.Text = "Обновить"; + buttonReset.UseVisualStyleBackColor = true; + buttonReset.Click += buttonReset_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(665, 269); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(123, 48); + buttonDelete.TabIndex = 4; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonDelete); + Controls.Add(buttonReset); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + Text = "FormShops"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonReset; + private Button buttonDelete; + } +} \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormShops.cs b/MotorPlant/MotorPlantView/FormShops.cs new file mode 100644 index 0000000..8a4cbcb --- /dev/null +++ b/MotorPlant/MotorPlantView/FormShops.cs @@ -0,0 +1,108 @@ +using Microsoft.Extensions.Logging; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantView.Forms; + +namespace MotorPlantView +{ + 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 LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Adress"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopEngines"].Visible = false; + } + _logger.LogInformation("Load shops"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Load shop error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + var tmp = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form._id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonReset_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} diff --git a/MotorPlant/MotorPlantView/FormShops.resx b/MotorPlant/MotorPlantView/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/MotorPlant/MotorPlantView/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/MotorPlant/MotorPlantView/FormSupply.Designer.cs b/MotorPlant/MotorPlantView/FormSupply.Designer.cs new file mode 100644 index 0000000..1b5719f --- /dev/null +++ b/MotorPlant/MotorPlantView/FormSupply.Designer.cs @@ -0,0 +1,147 @@ +namespace MotorPlantView +{ + partial class FormSupply + { + /// + /// 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() + { + ShopComboBox = new ComboBox(); + EngineComboBox = new ComboBox(); + CountTextBox = new TextBox(); + SaveButton = new Button(); + Cancel = new Button(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + SuspendLayout(); + // + // ShopComboBox + // + ShopComboBox.FormattingEnabled = true; + ShopComboBox.Location = new Point(136, 26); + ShopComboBox.Margin = new Padding(3, 2, 3, 2); + ShopComboBox.Name = "ShopComboBox"; + ShopComboBox.Size = new Size(279, 23); + ShopComboBox.TabIndex = 0; + // + // EngineComboBox + // + EngineComboBox.FormattingEnabled = true; + EngineComboBox.Location = new Point(136, 59); + EngineComboBox.Margin = new Padding(3, 2, 3, 2); + EngineComboBox.Name = "EngineComboBox"; + EngineComboBox.Size = new Size(279, 23); + EngineComboBox.TabIndex = 1; + // + // CountTextBox + // + CountTextBox.Location = new Point(136, 96); + CountTextBox.Margin = new Padding(3, 2, 3, 2); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(279, 23); + CountTextBox.TabIndex = 2; + // + // SaveButton + // + SaveButton.Location = new Point(220, 150); + SaveButton.Margin = new Padding(3, 2, 3, 2); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(94, 27); + SaveButton.TabIndex = 3; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // Cancel + // + Cancel.Location = new Point(319, 150); + Cancel.Margin = new Padding(3, 2, 3, 2); + Cancel.Name = "Cancel"; + Cancel.Size = new Size(94, 27); + Cancel.TabIndex = 4; + Cancel.Text = "Отмена"; + Cancel.UseVisualStyleBackColor = true; + Cancel.Click += CancelButton_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(35, 28); + label1.Name = "label1"; + label1.Size = new Size(54, 15); + label1.TabIndex = 5; + label1.Text = "Магазин"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(35, 62); + label2.Name = "label2"; + label2.Size = new Size(64, 15); + label2.TabIndex = 6; + label2.Text = "Двигатели"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(35, 98); + label3.Name = "label3"; + label3.Size = new Size(72, 15); + label3.TabIndex = 7; + label3.Text = "Количество"; + // + // FormSupply + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(443, 195); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(Cancel); + Controls.Add(SaveButton); + Controls.Add(CountTextBox); + Controls.Add(EngineComboBox); + Controls.Add(ShopComboBox); + Margin = new Padding(3, 2, 3, 2); + Name = "FormSupply"; + Text = "Форма поставки"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox ShopComboBox; + private ComboBox EngineComboBox; + private TextBox CountTextBox; + private Button SaveButton; + private Button Cancel; + private Label label1; + private Label label2; + private Label label3; + } +} \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormSupply.cs b/MotorPlant/MotorPlantView/FormSupply.cs new file mode 100644 index 0000000..fa59e52 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormSupply.cs @@ -0,0 +1,140 @@ +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; + +namespace MotorPlantView +{ + public partial class FormSupply : Form + { + private readonly List? _engineList; + private readonly List? _shopsList; + IShopLogic _shopLogic; + IEngineLogic _engineLogic; + public int ShopId + { + get + { + return Convert.ToInt32(ShopComboBox.SelectedValue); + } + set + { + ShopComboBox.SelectedValue = value; + } + } + public int EngineId + { + get + { + return Convert.ToInt32(EngineComboBox.SelectedValue); + } + set + { + EngineComboBox.SelectedValue = value; + } + } + + public IEngineModel? EngineModel + { + get + { + if (_engineList == null) + { + return null; + } + foreach (var elem in _engineList) + { + if (elem.Id == EngineId) + { + return elem; + } + } + return null; + } + } + + + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set + { CountTextBox.Text = value.ToString(); } + } + public FormSupply(IEngineLogic engineLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _engineLogic = engineLogic; + _engineList = engineLogic.ReadList(null); + _shopsList = shopLogic.ReadList(null); + if (_engineList != null) + { + EngineComboBox.DisplayMember = "EngineName"; + EngineComboBox.ValueMember = "Id"; + EngineComboBox.DataSource = _engineList; + EngineComboBox.SelectedItem = null; + } + if (_shopsList != null) + { + ShopComboBox.DisplayMember = "ShopName"; + ShopComboBox.ValueMember = "Id"; + ShopComboBox.DataSource = _shopsList; + ShopComboBox.SelectedItem = null; + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (EngineComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите двигатель", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ShopComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + int count = Convert.ToInt32(CountTextBox.Text); + + bool res = _shopLogic.MakeSupply( + new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) }, + _engineLogic.ReadElement(new() { Id = Convert.ToInt32(EngineComboBox.SelectedValue) }), + count + ); + + if (!res) + { + throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); + } + + MessageBox.Show("Пополнение прошло успешно"); + DialogResult = DialogResult.OK; + Close(); + + } + catch (Exception er) + { + MessageBox.Show("Ошибка пополнения"); + return; + } + } + + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/MotorPlant/MotorPlantView/FormSupply.resx b/MotorPlant/MotorPlantView/FormSupply.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormSupply.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/MotorPlant/MotorPlantView/Program.cs b/MotorPlant/MotorPlantView/Program.cs index 21b1eff..7f64bee 100644 --- a/MotorPlant/MotorPlantView/Program.cs +++ b/MotorPlant/MotorPlantView/Program.cs @@ -6,7 +6,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using MotorPlantBusinessLogic.BusinessLogics; -using System; +using MotorPlantBusinessLogic.BusinessLogic; +using MotorPlantView; namespace MotorPlantView { @@ -42,6 +43,8 @@ namespace MotorPlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -49,6 +52,9 @@ namespace MotorPlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/MotorPlant/ShopsForm/Form1.Designer.cs b/MotorPlant/ShopsForm/Form1.Designer.cs new file mode 100644 index 0000000..a8b8dd9 --- /dev/null +++ b/MotorPlant/ShopsForm/Form1.Designer.cs @@ -0,0 +1,39 @@ +namespace ShopsForm +{ + partial class Form1 + { + /// + /// 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.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "Form1"; + } + + #endregion + } +} \ No newline at end of file diff --git a/MotorPlant/ShopsForm/Form1.cs b/MotorPlant/ShopsForm/Form1.cs new file mode 100644 index 0000000..6be30b4 --- /dev/null +++ b/MotorPlant/ShopsForm/Form1.cs @@ -0,0 +1,10 @@ +namespace ShopsForm +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/MotorPlant/ShopsForm/Form1.resx b/MotorPlant/ShopsForm/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MotorPlant/ShopsForm/Form1.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/MotorPlant/ShopsForm/Program.cs b/MotorPlant/ShopsForm/Program.cs new file mode 100644 index 0000000..4b3f120 --- /dev/null +++ b/MotorPlant/ShopsForm/Program.cs @@ -0,0 +1,17 @@ +namespace ShopsForm +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file diff --git a/MotorPlant/ShopsForm/ShopsForm.csproj b/MotorPlant/ShopsForm/ShopsForm.csproj new file mode 100644 index 0000000..b57c89e --- /dev/null +++ b/MotorPlant/ShopsForm/ShopsForm.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + \ No newline at end of file -- 2.25.1 From 071e0a01fc0b89772d647f512f3798b340cd85ae Mon Sep 17 00:00:00 2001 From: Salikh Date: Wed, 3 Apr 2024 14:12:16 +0400 Subject: [PATCH 2/7] commit --- .../BusinessLogic/ShopLogic.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ShopLogic.cs b/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ShopLogic.cs index a85fe49..479e5c3 100644 --- a/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -119,12 +119,12 @@ namespace MotorPlantBusinessLogic.BusinessLogic throw new InvalidOperationException("Магазин с таким названием уже есть"); } } - public bool MakeSupply(ShopSearchModel model, IEngineModel dress, int count) + public bool MakeSupply(ShopSearchModel model, IEngineModel engine, int count) { if (model == null) throw new ArgumentNullException(nameof(model)); - if (dress == null) - throw new ArgumentNullException(nameof(dress)); + if (engine == null) + throw new ArgumentNullException(nameof(engine)); if (count <= 0) throw new ArgumentNullException("Количество должно быть положительным числом"); @@ -132,15 +132,15 @@ namespace MotorPlantBusinessLogic.BusinessLogic _logger.LogInformation("Make Supply. Id: {Id}. ShopName: {Name}", model.Id, model.Name); if (curModel == null) throw new ArgumentNullException(nameof(curModel)); - if (curModel.ShopEngines.TryGetValue(dress.Id, out var pair)) + if (curModel.ShopEngines.TryGetValue(engine.Id, out var pair)) { - curModel.ShopEngines[dress.Id] = (pair.Item1, pair.Item2 + count); - _logger.LogInformation("Make Supply. Add Dress. DressName: {Name}. Count: {Count}", pair.Item1, count + pair.Item2); + curModel.ShopEngines[engine.Id] = (pair.Item1, pair.Item2 + count); + _logger.LogInformation("Make Supply. Add Engine. EngineName: {Name}. Count: {Count}", pair.Item1, count + pair.Item2); } else { - curModel.ShopEngines.Add(dress.Id, (dress, count)); - _logger.LogInformation("Make Supply. Add new Dress. DressName: {Name}. Count: {Count}", pair.Item1, count); + curModel.ShopEngines.Add(engine.Id, (engine, count)); + _logger.LogInformation("Make Supply. Add new Engine. EngineName: {Name}. Count: {Count}", pair.Item1, count); } return Update(new() -- 2.25.1 From a528263511b4511626c5e295c742db446f9b4578 Mon Sep 17 00:00:00 2001 From: Salikh Date: Wed, 3 Apr 2024 15:50:05 +0400 Subject: [PATCH 3/7] commit --- .../MotorPlantFileImplement/Implements/OrderStorage.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/MotorPlant/MotorPlantFileImplement/Implements/OrderStorage.cs b/MotorPlant/MotorPlantFileImplement/Implements/OrderStorage.cs index 3bb7e5b..d79a83b 100644 --- a/MotorPlant/MotorPlantFileImplement/Implements/OrderStorage.cs +++ b/MotorPlant/MotorPlantFileImplement/Implements/OrderStorage.cs @@ -83,14 +83,8 @@ namespace MotorPlantFileImplement.Implements private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - foreach (var comp in source.Engines) - { - if (comp.Id == order.EngineId) - { - viewModel.EngineName = comp.EngineName; - break; - } - } + var engine = source.Engines.FirstOrDefault(x => x.Id == order.EngineId); + viewModel.EngineName = engine?.EngineName; return viewModel; } } -- 2.25.1 From b569dbb44587a28827065624c3c09d5876460d6a Mon Sep 17 00:00:00 2001 From: Salikh Date: Wed, 3 Apr 2024 15:57:18 +0400 Subject: [PATCH 4/7] commit2 --- MotorPlant/MotorPlantFileImplement/Models/Engine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MotorPlant/MotorPlantFileImplement/Models/Engine.cs b/MotorPlant/MotorPlantFileImplement/Models/Engine.cs index 47f3f3c..e00f328 100644 --- a/MotorPlant/MotorPlantFileImplement/Models/Engine.cs +++ b/MotorPlant/MotorPlantFileImplement/Models/Engine.cs @@ -7,7 +7,7 @@ namespace MotorPlantFileImplement.Models { public class Engine : IEngineModel { - public int Id { get; private set; } + public int Id { get; private set; } public string EngineName { get; private set; } = string.Empty; public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); -- 2.25.1 From e2f57f08a74ab1443ee8c9227f34ea681f9802e6 Mon Sep 17 00:00:00 2001 From: Salikh Date: Wed, 3 Apr 2024 16:02:34 +0400 Subject: [PATCH 5/7] finalycommit --- MotorPlant/MotorPlantListImplement/Models/Order.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/MotorPlant/MotorPlantListImplement/Models/Order.cs b/MotorPlant/MotorPlantListImplement/Models/Order.cs index 56053d1..e8196ac 100644 --- a/MotorPlant/MotorPlantListImplement/Models/Order.cs +++ b/MotorPlant/MotorPlantListImplement/Models/Order.cs @@ -49,12 +49,7 @@ namespace MotorPlantListImplement.Models { return; } - Id = model.Id; - EngineId = model.EngineId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() -- 2.25.1 From acc8780b884f05b5c90cbb8bcf0ee65e5a694332 Mon Sep 17 00:00:00 2001 From: Salikh Date: Sun, 7 Apr 2024 01:08:29 +0400 Subject: [PATCH 6/7] final commit --- .../BusinessLogicsContracts/IShopLogic.cs | 2 +- MotorPlant/MotorPlantListImplement/Models/Order.cs | 5 ----- MotorPlant/MotorPlantView/FormEngines.cs | 3 ++- MotorPlant/MotorPlantView/FormShop.cs | 4 ++-- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs b/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs index 15e3fc8..919d97f 100644 --- a/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -17,6 +17,6 @@ namespace MotorPlantContracts.BusinessLogicsContracts bool Create(ShopBindingModel? model); bool Update(ShopBindingModel? model); bool Delete(ShopBindingModel? model); - bool MakeSupply(ShopSearchModel model, IEngineModel dress, int count); + bool MakeSupply(ShopSearchModel model, IEngineModel engine, int count); } } diff --git a/MotorPlant/MotorPlantListImplement/Models/Order.cs b/MotorPlant/MotorPlantListImplement/Models/Order.cs index 56053d1..e8196ac 100644 --- a/MotorPlant/MotorPlantListImplement/Models/Order.cs +++ b/MotorPlant/MotorPlantListImplement/Models/Order.cs @@ -49,12 +49,7 @@ namespace MotorPlantListImplement.Models { return; } - Id = model.Id; - EngineId = model.EngineId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() diff --git a/MotorPlant/MotorPlantView/FormEngines.cs b/MotorPlant/MotorPlantView/FormEngines.cs index d686eec..0c6692a 100644 --- a/MotorPlant/MotorPlantView/FormEngines.cs +++ b/MotorPlant/MotorPlantView/FormEngines.cs @@ -32,7 +32,8 @@ namespace MotorPlantView.Forms catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки компонентов"); - } + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void FormEngines_Load(object sender, EventArgs e) diff --git a/MotorPlant/MotorPlantView/FormShop.cs b/MotorPlant/MotorPlantView/FormShop.cs index a408e09..e1c45bb 100644 --- a/MotorPlant/MotorPlantView/FormShop.cs +++ b/MotorPlant/MotorPlantView/FormShop.cs @@ -61,9 +61,9 @@ namespace MotorPlantView { if (_engine != null) { - foreach (var dress in _engine) + foreach (var engine in _engine) { - dataGridView.Rows.Add(new object[] { dress.Key, dress.Value.Item1.EngineName, dress.Value.Item1.Price, dress.Value.Item2 }); + dataGridView.Rows.Add(new object[] { engine.Key, engine.Value.Item1.EngineName, engine.Value.Item1.Price, engine.Value.Item2 }); } } } -- 2.25.1 From 7772cc65d2cd19457d6008d5889472f4a6cab1f6 Mon Sep 17 00:00:00 2001 From: Salikh Date: Tue, 9 Apr 2024 21:17:41 +0400 Subject: [PATCH 7/7] second commit --- .../BusinessLogic/OrderLogic.cs | 269 +++++++----- .../BusinessLogic/ShopLogic.cs | 144 ++++--- .../BindingModels/ShopBindingModel.cs | 3 +- .../BusinessLogicsContracts/IShopLogic.cs | 3 +- .../StoragesContracts/IShopStorage.cs | 4 +- .../ViewModels/ShopViewModel.cs | 6 +- .../MotorPlantDataModels/Models/IShopModel.cs | 3 +- .../DataFileSingleton.cs | 17 +- .../Implements/ShopStorage .cs | 121 ++++++ .../MotorPlantFileImplement/Models/Shop.cs | 102 +++++ .../Implements/ShopStorage.cs | 11 +- .../MotorPlantListImplement/Models/Shop.cs | 6 +- .../MotorPlantView/FormMain.Designer.cs | 403 +++++++++--------- MotorPlant/MotorPlantView/FormMain.cs | 312 +++++++------- .../MotorPlantView/FormSell.Designer.cs | 122 ++++++ MotorPlant/MotorPlantView/FormSell.cs | 120 ++++++ MotorPlant/MotorPlantView/FormSell.resx | 120 ++++++ .../MotorPlantView/FormShop.Designer.cs | 403 ++++++++++-------- MotorPlant/MotorPlantView/FormShop.cs | 203 ++++----- MotorPlant/MotorPlantView/FormShop.resx | 50 +-- MotorPlant/MotorPlantView/Program.cs | 3 +- 21 files changed, 1580 insertions(+), 845 deletions(-) create mode 100644 MotorPlant/MotorPlantFileImplement/Implements/ShopStorage .cs create mode 100644 MotorPlant/MotorPlantFileImplement/Models/Shop.cs create mode 100644 MotorPlant/MotorPlantView/FormSell.Designer.cs create mode 100644 MotorPlant/MotorPlantView/FormSell.cs create mode 100644 MotorPlant/MotorPlantView/FormSell.resx diff --git a/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/OrderLogic.cs b/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/OrderLogic.cs index 7b27063..c3322c1 100644 --- a/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/OrderLogic.cs @@ -5,128 +5,179 @@ using MotorPlantContracts.StoragesContracts; using MotorPlantContracts.ViewModels; using Microsoft.Extensions.Logging; using MotorPlantDataModels.Enums; +using MotorPlantDataModels.Models; namespace MotorPlantBusinessLogic.BusinessLogics { public class OrderLogic : IOrderLogic { - private readonly ILogger _logger; - private readonly IOrderStorage _orderStorage; + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; + private readonly IShopLogic _shopLogic; + private readonly IEngineStorage _engineStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IEngineStorage engineStorage) + { + _logger = logger; + _orderStorage = orderStorage; + _shopStorage = shopStorage; + _shopLogic = shopLogic; + _engineStorage = engineStorage; + } - public OrderLogic(ILogger logger, IOrderStorage orderStorage) - { - _logger = logger; - _orderStorage = orderStorage; - } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } - public List? ReadList(OrderSearchModel? model) - { - _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); - var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } + private void CheckModel(OrderBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество заказов должно быть больше нуля"); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Цена заказа должна быть больше нуля"); + } + _logger.LogInformation("Order. OrderId:{Id}. Sum:{Sum}", model.Id, model.Sum); + } - public bool CreateOrder(OrderBindingModel model) - { - CheckModel(model); + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; - if (model.Status != OrderStatus.Неизвестен) - return false; - model.Status = OrderStatus.Принят; + } - if (_orderStorage.Insert(model) == null) - { - model.Status = OrderStatus.Неизвестен; - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } + private bool ChangeStatus(OrderBindingModel model, OrderStatus status) + { + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Find order failed"); + return false; + } + if (element.Status != status - 1) + { + _logger.LogWarning("Status change failed"); + throw new InvalidOperationException("Невозможно перевести состояние заказа"); + } + if (status == OrderStatus.Готов) + { + var engine = _engineStorage.GetElement(new EngineSearchModel() { Id = model.EngineId }); + if (engine == null) + { + _logger.LogWarning("Status change error. Engine not found"); + return false; + } + if (!CheckSupply(engine, model.Count)) + { + _logger.LogWarning("Status change error. Shop doesnt have engines"); + return false; + } + } + model.Status = status; + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + _orderStorage.Update(model); + return true; + } - public bool TakeOrderInWork(OrderBindingModel model) - { - return ToNextStatus(model, OrderStatus.Выполняется); - } + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } - public bool FinishOrder(OrderBindingModel model) - { - return ToNextStatus(model, OrderStatus.Готов); - } + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } - public bool DeliveryOrder(OrderBindingModel model) - { - return ToNextStatus(model, OrderStatus.Выдан); - } + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } - public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus) - { - CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel() - { - Id = model.Id - }); - if (element == null) - { - throw new ArgumentNullException(nameof(element)); - } + public bool CheckSupply(IEngineModel engine, int count) + { + if (count <= 0) + { + _logger.LogWarning("Check supply operation error. Engine count < 0"); + return false; + } + int sumCapacity = _shopStorage.GetFullList().Select(x => x.MaxCount).Sum(); + int sumCount = _shopStorage.GetFullList().Select(x => x.ShopEngines.Select(y => y.Value.Item2).Sum()).Sum(); + int free = sumCapacity - sumCount; - model.EngineId = element.EngineId; - model.DateCreate = element.DateCreate; - model.DateImplement = element.DateImplement; - model.Status = element.Status; - model.Count = element.Count; - model.Sum = element.Sum; - - if (model.Status != orderStatus - 1) - { - _logger.LogWarning("Status update to " + orderStatus + " operation failed"); - return false; - } - model.Status = orderStatus; - - if (model.Status == OrderStatus.Выдан) - { - model.DateImplement = DateTime.Now; - } - - if (_orderStorage.Update(model) == null) - { - model.Status--; - _logger.LogWarning("Changing status operation faled"); - return false; - } - return true; - } - - private void CheckModel(OrderBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Count <= 0) - { - throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); - } - if (model.Sum <= 0) - { - throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); - } - if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) - { - throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} должна быть позже даты его создания {model.DateCreate}"); - } - _logger.LogInformation("Engine. EngineId:{EngineId}.Count:{Count}.Sum:{Sum}Id:{Id}", model.EngineId, model.Count, model.Sum, model.Id); - } - } + if (free < count) + { + _logger.LogWarning("Check supply error. No place for new Engines"); + return false; + } + foreach (var shop in _shopStorage.GetFullList()) + { + free = shop.MaxCount; + foreach (var doc in shop.ShopEngines) + { + free -= doc.Value.Item2; + } + if (free == 0) + { + continue; + } + if (free >= count) + { + if (_shopLogic.MakeSupply(new() + { + Id = shop.Id + }, engine, count)) + { + count = 0; + } + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + else + { + if (_shopLogic.MakeSupply(new() { Id = shop.Id }, engine, free)) + count -= free; + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + if (count <= 0) + { + return true; + } + } + return false; + } + } } diff --git a/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ShopLogic.cs b/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ShopLogic.cs index 479e5c3..35e65a1 100644 --- a/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/MotorPlant/MotorPlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -17,11 +17,13 @@ namespace MotorPlantBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IShopStorage _shopStorage; + public ShopLogic(ILogger logger, IShopStorage shopStorage) { _logger = logger; _shopStorage = shopStorage; } + public List ReadList(ShopSearchModel model) { _logger.LogInformation("ReadList. ShopName:{Name}. Id:{ Id}", model?.Name, model?.Id); @@ -34,6 +36,7 @@ namespace MotorPlantBusinessLogic.BusinessLogic _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } + public ShopViewModel ReadElement(ShopSearchModel model) { if (model == null) @@ -86,71 +89,86 @@ namespace MotorPlantBusinessLogic.BusinessLogic private void CheckModel(ShopBindingModel model, bool withParams = true) { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.ShopName)) - { - throw new ArgumentNullException("Нет названия магазина", - nameof(model.ShopName)); - } - if (string.IsNullOrEmpty(model.Adress)) - { - throw new ArgumentNullException("Нет адресса магазина", - nameof(model.ShopName)); - } - if (model.DateOpen == null) - { - throw new ArgumentNullException("Нет даты открытия магазина", - nameof(model.ShopName)); - } - _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}", model.ShopName, model.Adress, model.DateOpen, model.Id); - var element = _shopStorage.GetElement(new ShopSearchModel - { - Name = model.ShopName - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Магазин с таким названием уже есть"); - } - } - public bool MakeSupply(ShopSearchModel model, IEngineModel engine, int count) + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Нет названия магазина", + nameof(model.ShopName)); + } + if (string.IsNullOrEmpty(model.Adress)) + { + throw new ArgumentNullException("Нет адресса магазина", + nameof(model.ShopName)); + } + if (model.DateOpen == null) + { + throw new ArgumentNullException("Нет даты открытия магазина", + nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}", model.ShopName, model.Adress, model.DateOpen, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + public bool MakeSell(IEngineModel model, int count) + { + return _shopStorage.SellEngines(model, count); + } + + public bool MakeSupply(ShopSearchModel model, IEngineModel engine, int count) { - if (model == null) - throw new ArgumentNullException(nameof(model)); - if (engine == null) - throw new ArgumentNullException(nameof(engine)); - if (count <= 0) - throw new ArgumentNullException("Количество должно быть положительным числом"); + if (model == null) + throw new ArgumentNullException(nameof(model)); + if (engine == null) + throw new ArgumentNullException(nameof(engine)); + if (count <= 0) + throw new ArgumentNullException("Количество должно быть положительным числом"); - ShopViewModel? curModel = _shopStorage.GetElement(model); - _logger.LogInformation("Make Supply. Id: {Id}. ShopName: {Name}", model.Id, model.Name); - if (curModel == null) - throw new ArgumentNullException(nameof(curModel)); - if (curModel.ShopEngines.TryGetValue(engine.Id, out var pair)) - { - curModel.ShopEngines[engine.Id] = (pair.Item1, pair.Item2 + count); - _logger.LogInformation("Make Supply. Add Engine. EngineName: {Name}. Count: {Count}", pair.Item1, count + pair.Item2); - } - else - { - curModel.ShopEngines.Add(engine.Id, (engine, count)); - _logger.LogInformation("Make Supply. Add new Engine. EngineName: {Name}. Count: {Count}", pair.Item1, count); - } + ShopViewModel? curModel = _shopStorage.GetElement(model); + _logger.LogInformation("Make Supply. Id: {Id}. ShopName: {Name}", model.Id, model.Name); + if (curModel == null) + throw new ArgumentNullException(nameof(curModel)); - return Update(new() - { - Id = curModel.Id, - ShopName = curModel.ShopName, - DateOpen = curModel.DateOpen, - Adress = curModel.Adress, - ShopEngines = curModel.ShopEngines, - }); - } + var countItems = curModel.ShopEngines.Select(x => x.Value.Item2).Sum(); + if (curModel.MaxCount - countItems < count) + { + _logger.LogWarning("Shop is overflowed"); + return false; + } + + if (curModel.ShopEngines.TryGetValue(engine.Id, out var pair)) + { + curModel.ShopEngines[engine.Id] = (pair.Item1, pair.Item2 + count); + _logger.LogInformation("Make Supply. Add Dress. ShopName: {ShopName}. DressName: {Name}. Count: {Count}", curModel.ShopName, pair.Item1, count + pair.Item2); + } + else + { + curModel.ShopEngines.Add(engine.Id, (engine, count)); + _logger.LogInformation("Make Supply. Add new Dress. ShopName: {ShopName}. DressName: {Name}. Count: {Count}", curModel.ShopName, pair.Item1, count); + } + + return Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + DateOpen = curModel.DateOpen, + MaxCount = curModel.MaxCount, + Adress = curModel.Adress, + ShopEngines = curModel.ShopEngines, + }); + } } } diff --git a/MotorPlant/MotorPlantContracts/BindingModels/ShopBindingModel.cs b/MotorPlant/MotorPlantContracts/BindingModels/ShopBindingModel.cs index 855a76f..75dbc6f 100644 --- a/MotorPlant/MotorPlantContracts/BindingModels/ShopBindingModel.cs +++ b/MotorPlant/MotorPlantContracts/BindingModels/ShopBindingModel.cs @@ -13,6 +13,7 @@ namespace MotorPlantContracts.BindingModels public string ShopName { get; set; } public string Adress { get; set; } public DateTime DateOpen { get; set; } - public Dictionary ShopEngines { get; set; } = new(); + public int MaxCount { get; set; } + public Dictionary ShopEngines { get; set; } = new(); } } diff --git a/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs b/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs index 919d97f..ce4f7b0 100644 --- a/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -18,5 +18,6 @@ namespace MotorPlantContracts.BusinessLogicsContracts bool Update(ShopBindingModel? model); bool Delete(ShopBindingModel? model); bool MakeSupply(ShopSearchModel model, IEngineModel engine, int count); - } + bool MakeSell(IEngineModel model, int count); + } } diff --git a/MotorPlant/MotorPlantContracts/StoragesContracts/IShopStorage.cs b/MotorPlant/MotorPlantContracts/StoragesContracts/IShopStorage.cs index 48c46db..0fb2755 100644 --- a/MotorPlant/MotorPlantContracts/StoragesContracts/IShopStorage.cs +++ b/MotorPlant/MotorPlantContracts/StoragesContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using MotorPlantContracts.BindingModels; using MotorPlantContracts.SearchModels; using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -17,5 +18,6 @@ namespace MotorPlantContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); - } + bool SellEngines(IEngineModel model, int count); + } } diff --git a/MotorPlant/MotorPlantContracts/ViewModels/ShopViewModel.cs b/MotorPlant/MotorPlantContracts/ViewModels/ShopViewModel.cs index 4cd1610..7e595f5 100644 --- a/MotorPlant/MotorPlantContracts/ViewModels/ShopViewModel.cs +++ b/MotorPlant/MotorPlantContracts/ViewModels/ShopViewModel.cs @@ -24,6 +24,10 @@ namespace MotorPlantContracts.ViewModels public DateTime DateOpen { get; set; } - public Dictionary ShopEngines { get; set; } = new(); + [DisplayName("Вмещаемость")] + + public int MaxCount { get; set; } + + public Dictionary ShopEngines { get; set; } = new(); } } diff --git a/MotorPlant/MotorPlantDataModels/Models/IShopModel.cs b/MotorPlant/MotorPlantDataModels/Models/IShopModel.cs index 7552320..fef931e 100644 --- a/MotorPlant/MotorPlantDataModels/Models/IShopModel.cs +++ b/MotorPlant/MotorPlantDataModels/Models/IShopModel.cs @@ -11,5 +11,6 @@ namespace MotorPlantDataModels.Models string ShopName { get; } string Adress { get; } DateTime DateOpen { get; } - } + int MaxCount { get; } + } } diff --git a/MotorPlant/MotorPlantFileImplement/DataFileSingleton.cs b/MotorPlant/MotorPlantFileImplement/DataFileSingleton.cs index 8d52eb1..2d2bd6b 100644 --- a/MotorPlant/MotorPlantFileImplement/DataFileSingleton.cs +++ b/MotorPlant/MotorPlantFileImplement/DataFileSingleton.cs @@ -13,13 +13,17 @@ namespace MotorPlantFileImplement private readonly string EngineFileName = "Engine.xml"; - public List Components { get; private set; } + private readonly string ShopFileName = "Shop.xml"; + + public List Components { get; private set; } public List Orders { get; private set; } public List Engines { get; private set; } - public static DataFileSingleton GetInstance() + public List Shops { get; private set; } + + public static DataFileSingleton GetInstance() { if (instance == null) { @@ -33,14 +37,17 @@ namespace MotorPlantFileImplement public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); - private DataFileSingleton() + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); + + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Engines = LoadData(EngineFileName, "Engine", x => Engine.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) + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { if (File.Exists(filename)) { diff --git a/MotorPlant/MotorPlantFileImplement/Implements/ShopStorage .cs b/MotorPlant/MotorPlantFileImplement/Implements/ShopStorage .cs new file mode 100644 index 0000000..aefb9ca --- /dev/null +++ b/MotorPlant/MotorPlantFileImplement/Implements/ShopStorage .cs @@ -0,0 +1,121 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.StoragesContracts; +using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; +using MotorPlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantFileImplement.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.Name)) + { + return new(); + } + return _source.Shops.Where(x => x.ShopName.Contains(model.Name)).Select(x => x.GetViewModel).ToList(); + + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + return _source.Shops.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.ShopName == model.Name) || (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 component = _source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + _source.SaveShops(); + return component.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 CheckAvailability(int engineId, int count) + { + int store = _source.Shops.Select(x => x.ShopEngines.Select(y => (y.Value.Item1.Id == engineId ? y.Value.Item2 : 0)).Sum()).Sum(); + return store >= count; + } + public bool SellEngines(IEngineModel model, int count) + { + var dres = _source.Engines.FirstOrDefault(x => x.Id == model.Id); + + if (dres == null || !CheckAvailability(model.Id, count)) + { + return false; + } + + for (int i = 0; i < _source.Shops.Count; i++) + { + var shop = _source.Shops[i]; + var engines = shop.ShopEngines; + foreach (var engine in engines.Where(x => x.Value.Item1.Id == dres.Id)) + { + var selling = Math.Min(engine.Value.Item2, count); + engines[engine.Value.Item1.Id] = (engine.Value.Item1, engine.Value.Item2 - selling); + + count -= selling; + + if (count <= 0) + { + break; + } + } + shop.Update(new ShopBindingModel + { + Id = model.Id, + ShopName = shop.ShopName, + Adress = shop.Adress, + MaxCount = shop.MaxCount, + DateOpen = shop.DateOpen, + ShopEngines = engines + }); + } + _source.SaveShops(); + return true; + } + } +} diff --git a/MotorPlant/MotorPlantFileImplement/Models/Shop.cs b/MotorPlant/MotorPlantFileImplement/Models/Shop.cs new file mode 100644 index 0000000..98d151d --- /dev/null +++ b/MotorPlant/MotorPlantFileImplement/Models/Shop.cs @@ -0,0 +1,102 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace MotorPlantFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } + public string Adress { get; private set; } + public DateTime DateOpen { get; private set; } + public int MaxCount { get; private set; } + public Dictionary Engines { get; private set; } = new(); + private Dictionary? _shopEngines = null; + + public Dictionary ShopEngines + { + get + { + if (_shopEngines == null) + { + var source = DataFileSingleton.GetInstance(); + _shopEngines = Engines.ToDictionary(x => x.Key, y => ((source.Engines.FirstOrDefault(z => z.Id == y.Key) as IEngineModel)!, y.Value)); + } + return _shopEngines; + } + } + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + DateOpen = model.DateOpen, + MaxCount = model.MaxCount, + Engines = model.ShopEngines.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, + Adress = element.Element("Adress")!.Value, + MaxCount = Convert.ToInt32(element.Element("MaxCount")!.Value), + DateOpen = Convert.ToDateTime(element.Element("DateOpen")!.Value), + Engines = element.Element("ShopEngines")!.Elements("ShopEngine").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; + Adress = model.Adress; + DateOpen = model.DateOpen; + MaxCount = model.MaxCount; + if (model.ShopEngines.Count > 0) + { + Engines = model.ShopEngines.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopEngines = null; + } + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + DateOpen = DateOpen, + MaxCount = MaxCount, + ShopEngines = ShopEngines + }; + + public XElement GetXElement => new XElement("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Adress", Adress), + new XElement("DateOpen", DateOpen), + new XElement("MaxCount", MaxCount), + new XElement("ShopEngines", Engines.Select(x => new XElement("ShopEngine", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray())); + } +} diff --git a/MotorPlant/MotorPlantListImplement/Implements/ShopStorage.cs b/MotorPlant/MotorPlantListImplement/Implements/ShopStorage.cs index 6ba0064..2d61dae 100644 --- a/MotorPlant/MotorPlantListImplement/Implements/ShopStorage.cs +++ b/MotorPlant/MotorPlantListImplement/Implements/ShopStorage.cs @@ -2,6 +2,7 @@ using MotorPlantContracts.SearchModels; using MotorPlantContracts.StoragesContracts; using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; using MotorPlantListImplement.Models; using System; using System.Collections.Generic; @@ -103,5 +104,13 @@ namespace MotorPlantListImplement.Implements } return null; } - } + public bool CheckAvailability(int engineId, int count) + { + return true; + } + public bool SellEngines(IEngineModel model, int count) + { + return true; + } + } } diff --git a/MotorPlant/MotorPlantListImplement/Models/Shop.cs b/MotorPlant/MotorPlantListImplement/Models/Shop.cs index ef03e2e..05ac9bd 100644 --- a/MotorPlant/MotorPlantListImplement/Models/Shop.cs +++ b/MotorPlant/MotorPlantListImplement/Models/Shop.cs @@ -15,7 +15,8 @@ namespace MotorPlantListImplement.Models public string ShopName { get; private set; } public string Adress { get; private set; } public DateTime DateOpen { get; private set; } - public Dictionary ShopEngines { get; private set; } = new(); + public int MaxCount { get; private set; } + public Dictionary ShopEngines { get; private set; } = new(); public static Shop? Create(ShopBindingModel model) { if (model == null) @@ -28,6 +29,7 @@ namespace MotorPlantListImplement.Models ShopName = model.ShopName, Adress = model.Adress, DateOpen = model.DateOpen, + MaxCount = model.MaxCount, ShopEngines = new() }; } @@ -40,6 +42,7 @@ namespace MotorPlantListImplement.Models ShopName = model.ShopName; Adress = model.Adress; DateOpen = model.DateOpen; + MaxCount = model.MaxCount; ShopEngines = model.ShopEngines; } public ShopViewModel GetViewModel => new() @@ -48,6 +51,7 @@ namespace MotorPlantListImplement.Models ShopName = ShopName, Adress = Adress, DateOpen = DateOpen, + MaxCount = MaxCount, ShopEngines = ShopEngines }; } diff --git a/MotorPlant/MotorPlantView/FormMain.Designer.cs b/MotorPlant/MotorPlantView/FormMain.Designer.cs index 33f0712..43ec273 100644 --- a/MotorPlant/MotorPlantView/FormMain.Designer.cs +++ b/MotorPlant/MotorPlantView/FormMain.Designer.cs @@ -1,205 +1,214 @@ namespace MotorPlantView.Forms { - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormMain + { + /// + /// 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); - } + /// + /// 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 + #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() - { - toolStrip1 = new ToolStrip(); - toolStripDropDownButton1 = new ToolStripDropDownButton(); - КомпонентыToolStripMenuItem = new ToolStripMenuItem(); - ДвигателиToolStripMenuItem = new ToolStripMenuItem(); - ShopsToolStripMenuItem = new ToolStripMenuItem(); - поставкиToolStripMenuItem = new ToolStripMenuItem(); - buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonOrderReady = new Button(); - buttonIssuedOrder = new Button(); - buttonRef = new Button(); - dataGridView = new DataGridView(); - toolStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // toolStrip1 - // - toolStrip1.ImageScalingSize = new Size(20, 20); - toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1 }); - toolStrip1.Location = new Point(0, 0); - toolStrip1.Name = "toolStrip1"; - toolStrip1.Size = new Size(985, 25); - toolStrip1.TabIndex = 0; - toolStrip1.Text = "toolStrip1"; - // - // toolStripDropDownButton1 - // - toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; - toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ДвигателиToolStripMenuItem, ShopsToolStripMenuItem, поставкиToolStripMenuItem }); - toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; - toolStripDropDownButton1.Name = "toolStripDropDownButton1"; - toolStripDropDownButton1.Size = new Size(88, 22); - toolStripDropDownButton1.Text = "Справочник"; - // - // КомпонентыToolStripMenuItem - // - КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; - КомпонентыToolStripMenuItem.Size = new Size(180, 22); - КомпонентыToolStripMenuItem.Text = "Компоненты"; - КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; - // - // ДвигателиToolStripMenuItem - // - ДвигателиToolStripMenuItem.Name = "ДвигателиToolStripMenuItem"; - ДвигателиToolStripMenuItem.Size = new Size(180, 22); - ДвигателиToolStripMenuItem.Text = "Двигатели"; - ДвигателиToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; - // - // ShopsToolStripMenuItem - // - ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; - ShopsToolStripMenuItem.Size = new Size(180, 22); - ShopsToolStripMenuItem.Text = "Магазины"; - ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; - // - // поставкиToolStripMenuItem - // - поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem"; - поставкиToolStripMenuItem.Size = new Size(180, 22); - поставкиToolStripMenuItem.Text = "Поставки"; - поставкиToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; - // - // buttonCreateOrder - // - buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonCreateOrder.BackColor = SystemColors.ControlLight; - buttonCreateOrder.Location = new Point(797, 146); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(178, 30); - buttonCreateOrder.TabIndex = 1; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = false; - buttonCreateOrder.Click += buttonCreateOrder_Click; - // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonTakeOrderInWork.BackColor = SystemColors.ControlLight; - buttonTakeOrderInWork.Location = new Point(797, 194); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(178, 30); - buttonTakeOrderInWork.TabIndex = 2; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = false; - buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonOrderReady.BackColor = SystemColors.ControlLight; - buttonOrderReady.Location = new Point(797, 242); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(178, 30); - buttonOrderReady.TabIndex = 3; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = false; - buttonOrderReady.Click += buttonOrderReady_Click; - // - // buttonIssuedOrder - // - buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonIssuedOrder.BackColor = SystemColors.ControlLight; - buttonIssuedOrder.Location = new Point(797, 287); - buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(178, 30); - buttonIssuedOrder.TabIndex = 4; - buttonIssuedOrder.Text = "Заказ выдан"; - buttonIssuedOrder.UseVisualStyleBackColor = false; - buttonIssuedOrder.Click += buttonIssuedOrder_Click; - // - // buttonRef - // - buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonRef.BackColor = SystemColors.ControlLight; - buttonRef.Location = new Point(797, 100); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(178, 30); - buttonRef.TabIndex = 5; - buttonRef.Text = "Обновить список"; - buttonRef.UseVisualStyleBackColor = false; - buttonRef.Click += buttonRef_Click; - // - // dataGridView - // - dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - dataGridView.BackgroundColor = SystemColors.ButtonHighlight; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(11, 28); - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 24; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(780, 441); - dataGridView.TabIndex = 6; - // - // FormMain - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(985, 467); - Controls.Add(dataGridView); - Controls.Add(buttonRef); - Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); - Controls.Add(buttonCreateOrder); - Controls.Add(toolStrip1); - Name = "FormMain"; - Text = "Моторный завод"; - Load += FormMain_Load; - toolStrip1.ResumeLayout(false); - toolStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + toolStrip1 = new ToolStrip(); + toolStripDropDownButton1 = new ToolStripDropDownButton(); + КомпонентыToolStripMenuItem = new ToolStripMenuItem(); + ДвигателиToolStripMenuItem = new ToolStripMenuItem(); + ShopsToolStripMenuItem = new ToolStripMenuItem(); + поставкиToolStripMenuItem = new ToolStripMenuItem(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + dataGridView = new DataGridView(); + продажаToolStripMenuItem = new ToolStripMenuItem(); + toolStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // toolStrip1 + // + toolStrip1.ImageScalingSize = new Size(20, 20); + toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1 }); + toolStrip1.Location = new Point(0, 0); + toolStrip1.Name = "toolStrip1"; + toolStrip1.Size = new Size(985, 25); + toolStrip1.TabIndex = 0; + toolStrip1.Text = "toolStrip1"; + // + // toolStripDropDownButton1 + // + toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ДвигателиToolStripMenuItem, ShopsToolStripMenuItem, поставкиToolStripMenuItem, продажаToolStripMenuItem }); + toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; + toolStripDropDownButton1.Name = "toolStripDropDownButton1"; + toolStripDropDownButton1.Size = new Size(88, 22); + toolStripDropDownButton1.Text = "Справочник"; + // + // КомпонентыToolStripMenuItem + // + КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; + КомпонентыToolStripMenuItem.Size = new Size(180, 22); + КомпонентыToolStripMenuItem.Text = "Компоненты"; + КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; + // + // ДвигателиToolStripMenuItem + // + ДвигателиToolStripMenuItem.Name = "ДвигателиToolStripMenuItem"; + ДвигателиToolStripMenuItem.Size = new Size(180, 22); + ДвигателиToolStripMenuItem.Text = "Двигатели"; + ДвигателиToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; + // + // ShopsToolStripMenuItem + // + ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; + ShopsToolStripMenuItem.Size = new Size(180, 22); + ShopsToolStripMenuItem.Text = "Магазины"; + ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // поставкиToolStripMenuItem + // + поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem"; + поставкиToolStripMenuItem.Size = new Size(180, 22); + поставкиToolStripMenuItem.Text = "Поставки"; + поставкиToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; + // + // buttonCreateOrder + // + buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonCreateOrder.BackColor = SystemColors.ControlLight; + buttonCreateOrder.Location = new Point(797, 146); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(178, 30); + buttonCreateOrder.TabIndex = 1; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = false; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonTakeOrderInWork.BackColor = SystemColors.ControlLight; + buttonTakeOrderInWork.Location = new Point(797, 194); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(178, 30); + buttonTakeOrderInWork.TabIndex = 2; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = false; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonOrderReady.BackColor = SystemColors.ControlLight; + buttonOrderReady.Location = new Point(797, 242); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(178, 30); + buttonOrderReady.TabIndex = 3; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = false; + buttonOrderReady.Click += buttonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonIssuedOrder.BackColor = SystemColors.ControlLight; + buttonIssuedOrder.Location = new Point(797, 287); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(178, 30); + buttonIssuedOrder.TabIndex = 4; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = false; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRef.BackColor = SystemColors.ControlLight; + buttonRef.Location = new Point(797, 100); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(178, 30); + buttonRef.TabIndex = 5; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = false; + buttonRef.Click += buttonRef_Click; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(11, 28); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 24; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(780, 441); + dataGridView.TabIndex = 6; + // + // продажаToolStripMenuItem + // + продажаToolStripMenuItem.Name = "продажаToolStripMenuItem"; + продажаToolStripMenuItem.Size = new Size(180, 22); + продажаToolStripMenuItem.Text = "Продажа"; + продажаToolStripMenuItem.Click += SellToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(985, 467); + Controls.Add(dataGridView); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(toolStrip1); + Name = "FormMain"; + Text = "Моторный завод"; + Load += FormMain_Load; + toolStrip1.ResumeLayout(false); + toolStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private ToolStrip toolStrip1; - private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; - private Button buttonIssuedOrder; - private Button buttonRef; - private DataGridView dataGridView; - private ToolStripDropDownButton toolStripDropDownButton1; - private ToolStripMenuItem КомпонентыToolStripMenuItem; - private ToolStripMenuItem ДвигателиToolStripMenuItem; - private ToolStripMenuItem ShopsToolStripMenuItem; - private ToolStripMenuItem поставкиToolStripMenuItem; - } + private ToolStrip toolStrip1; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + private DataGridView dataGridView; + private ToolStripDropDownButton toolStripDropDownButton1; + private ToolStripMenuItem КомпонентыToolStripMenuItem; + private ToolStripMenuItem ДвигателиToolStripMenuItem; + private ToolStripMenuItem ShopsToolStripMenuItem; + private ToolStripMenuItem поставкиToolStripMenuItem; + private ToolStripMenuItem продажаToolStripMenuItem; + } } \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormMain.cs b/MotorPlant/MotorPlantView/FormMain.cs index 3172e11..e3468ed 100644 --- a/MotorPlant/MotorPlantView/FormMain.cs +++ b/MotorPlant/MotorPlantView/FormMain.cs @@ -5,163 +5,171 @@ using MotorPlantView; namespace MotorPlantView.Forms { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - _logger.LogInformation("Загрузка заказов"); - try - { - var list = _orderLogic.ReadList(null); + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["EngineId"].Visible = false; - dataGridView.Columns["EngineName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["EngineId"].Visible = false; + dataGridView.Columns["EngineName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - } - } - private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + } + } + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormEngines)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormEngines)); - if (service is FormEngines form) - { - form.ShowDialog(); - } - } - private void buttonCreateOrder_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private void buttonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id, - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void buttonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void buttonIssuedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel - { - Id = id - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void buttonRef_Click(object sender, EventArgs e) - { - LoadData(); - } - private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormEngines form) + { + form.ShowDialog(); + } + } + private void buttonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void buttonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + var engineId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["EngineId"].Value); + var count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value); + _logger.LogInformation("Order №{id}. Change status on 'Ready'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, EngineId = engineId, Count = count }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Order №{id}. Status change on 'Given'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Order №{id} given", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Change status on 'Give' error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if (service is FormShops form) - { - form.ShowDialog(); - } - } + if (service is FormShops form) + { + form.ShowDialog(); + } + } - private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); + private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); - if (service is FormSupply form) - { - form.ShowDialog(); - } - } - } + if (service is FormSupply form) + { + form.ShowDialog(); + } + } + + private void SellToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSell)); + if (service is FormSell form) + { + form.ShowDialog(); + } + } + } } diff --git a/MotorPlant/MotorPlantView/FormSell.Designer.cs b/MotorPlant/MotorPlantView/FormSell.Designer.cs new file mode 100644 index 0000000..3696490 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormSell.Designer.cs @@ -0,0 +1,122 @@ +namespace MotorPlantView +{ + partial class FormSell + { + /// + /// 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() + { + comboBoxEngine = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + label1 = new Label(); + label2 = new Label(); + // + // comboBoxEngine + // + comboBoxEngine.FormattingEnabled = true; + comboBoxEngine.Location = new Point(110, 22); + comboBoxEngine.Margin = new Padding(3, 2, 3, 2); + comboBoxEngine.Name = "comboBoxEngine"; + comboBoxEngine.Size = new Size(133, 23); + comboBoxEngine.TabIndex = 0; + // + // textBoxCount + // + textBoxCount.Location = new Point(110, 71); + textBoxCount.Margin = new Padding(3, 2, 3, 2); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(133, 23); + textBoxCount.TabIndex = 1; + // + // buttonSave + // + buttonSave.Location = new Point(39, 129); + buttonSave.Margin = new Padding(3, 2, 3, 2); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(82, 22); + buttonSave.TabIndex = 2; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(160, 129); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(82, 22); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(24, 25); + label1.Name = "label1"; + label1.Size = new Size(50, 15); + label1.TabIndex = 4; + label1.Text = "Движки"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(24, 74); + label2.Name = "label2"; + label2.Size = new Size(72, 15); + label2.TabIndex = 5; + label2.Text = "Количество"; + // + // FormSell + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(268, 176); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxEngine); + Margin = new Padding(3, 2, 3, 2); + Name = "FormSell"; + Text = "Продажа"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxEngine; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + } +} \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormSell.cs b/MotorPlant/MotorPlantView/FormSell.cs new file mode 100644 index 0000000..09d47ad --- /dev/null +++ b/MotorPlant/MotorPlantView/FormSell.cs @@ -0,0 +1,120 @@ +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; +using MotorPlantDataModels.Models; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.ViewModels; + +namespace MotorPlantView +{ + public partial class FormSell : Form + { + private readonly List? _engineList; + IShopLogic _shopLogic; + IEngineLogic _engineLogic; + public FormSell(IEngineLogic engineLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _engineLogic = engineLogic; + _engineList = engineLogic.ReadList(null); + if (_engineList != null) + { + comboBoxEngine.DisplayMember = "EngineName"; + comboBoxEngine.ValueMember = "Id"; + comboBoxEngine.DataSource = _engineList; + comboBoxEngine.SelectedItem = null; + } + } + public int EngineId + { + get + { + return Convert.ToInt32(comboBoxEngine.SelectedValue); + } + set + { + comboBoxEngine.SelectedValue = value; + } + } + + public IEngineModel? EngineModel + { + get + { + if (_engineList == null) + { + return null; + } + foreach (var elem in _engineList) + { + if (elem.Id == EngineId) + { + return elem; + } + } + return null; + } + } + + + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set + { textBoxCount.Text = value.ToString(); } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxEngine.SelectedValue == null) + { + MessageBox.Show("Выберите двигатель", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + int count = Convert.ToInt32(textBoxCount.Text); + + bool res = _shopLogic.MakeSell( + _engineLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxEngine.SelectedValue) }), + count + ); + + if (!res) + { + throw new Exception("Ошибка при продаже."); + } + + MessageBox.Show("Продажа прошла успешно"); + DialogResult = DialogResult.OK; + Close(); + + } + catch (Exception err) + { + MessageBox.Show("Ошибка продажи"); + return; + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + Close(); + } + } +} diff --git a/MotorPlant/MotorPlantView/FormSell.resx b/MotorPlant/MotorPlantView/FormSell.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormSell.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/MotorPlant/MotorPlantView/FormShop.Designer.cs b/MotorPlant/MotorPlantView/FormShop.Designer.cs index 9e574fc..a529389 100644 --- a/MotorPlant/MotorPlantView/FormShop.Designer.cs +++ b/MotorPlant/MotorPlantView/FormShop.Designer.cs @@ -1,193 +1,226 @@ namespace MotorPlantView { - partial class FormShop - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + 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); - } + /// + /// 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 + #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() - { - dateTimePicker = new DateTimePicker(); - textBoxName = new TextBox(); - textBoxAdress = new TextBox(); - dataGridView = new DataGridView(); - IdColumn = new DataGridViewTextBoxColumn(); - Title = new DataGridViewTextBoxColumn(); - Cost = new DataGridViewTextBoxColumn(); - Count = new DataGridViewTextBoxColumn(); - buttonSave = new Button(); - buttonCancel = new Button(); - label1 = new Label(); - label2 = new Label(); - label3 = new Label(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // dateTimePicker - // - dateTimePicker.Location = new Point(714, 34); - dateTimePicker.Name = "dateTimePicker"; - dateTimePicker.Size = new Size(250, 27); - dateTimePicker.TabIndex = 0; - // - // textBoxName - // - textBoxName.Location = new Point(714, 85); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(250, 27); - textBoxName.TabIndex = 1; - // - // textBoxAdress - // - textBoxAdress.Location = new Point(714, 139); - textBoxAdress.Name = "textBoxAdress"; - textBoxAdress.Size = new Size(250, 27); - textBoxAdress.TabIndex = 2; - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { IdColumn, Title, Cost, Count }); - dataGridView.Location = new Point(10, 32); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(554, 380); - dataGridView.TabIndex = 3; - // - // IdColumn - // - IdColumn.HeaderText = "Номер платья"; - IdColumn.MinimumWidth = 6; - IdColumn.Name = "IdColumn"; - IdColumn.Visible = false; - IdColumn.Width = 125; - // - // Title - // - Title.HeaderText = "Название"; - Title.MinimumWidth = 6; - Title.Name = "Title"; - Title.Width = 125; - // - // Cost - // - Cost.HeaderText = "Цена"; - Cost.MinimumWidth = 6; - Cost.Name = "Cost"; - Cost.Width = 125; - // - // Count - // - Count.HeaderText = "Количество"; - Count.MinimumWidth = 6; - Count.Name = "Count"; - Count.Width = 125; - // - // buttonSave - // - buttonSave.Location = new Point(714, 219); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(94, 29); - buttonSave.TabIndex = 4; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; - // - // buttonCancel - // - buttonCancel.Location = new Point(870, 219); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(94, 29); - buttonCancel.TabIndex = 5; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += buttonCancel_Click; - // - // label1 - // - label1.AutoSize = true; - label1.Location = new Point(592, 39); - label1.Name = "label1"; - label1.Size = new Size(110, 20); - label1.TabIndex = 6; - label1.Text = "Дата создания"; - // - // label2 - // - label2.AutoSize = true; - label2.Location = new Point(592, 88); - label2.Name = "label2"; - label2.Size = new Size(77, 20); - label2.TabIndex = 7; - label2.Text = "Название"; - // - // label3 - // - label3.AutoSize = true; - label3.Location = new Point(592, 142); - label3.Name = "label3"; - label3.Size = new Size(51, 20); - label3.TabIndex = 8; - label3.Text = "Адрес"; - // - // ShopForm - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(976, 450); - Controls.Add(label3); - Controls.Add(label2); - Controls.Add(label1); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(dataGridView); - Controls.Add(textBoxAdress); - Controls.Add(textBoxName); - Controls.Add(dateTimePicker); - Name = "ShopForm"; - Text = "Форма магазина"; - Load += ShopForm_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dateTimePicker = new DateTimePicker(); + textBoxName = new TextBox(); + textBoxAdress = new TextBox(); + dataGridView = new DataGridView(); + IdColumn = new DataGridViewTextBoxColumn(); + Title = new DataGridViewTextBoxColumn(); + Cost = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + numeric = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numeric).BeginInit(); + SuspendLayout(); + // + // dateTimePicker + // + dateTimePicker.Location = new Point(625, 26); + dateTimePicker.Margin = new Padding(3, 2, 3, 2); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(219, 23); + dateTimePicker.TabIndex = 0; + // + // textBoxName + // + textBoxName.Location = new Point(625, 64); + textBoxName.Margin = new Padding(3, 2, 3, 2); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(219, 23); + textBoxName.TabIndex = 1; + // + // textBoxAdress + // + textBoxAdress.Location = new Point(625, 104); + textBoxAdress.Margin = new Padding(3, 2, 3, 2); + textBoxAdress.Name = "textBoxAdress"; + textBoxAdress.Size = new Size(219, 23); + textBoxAdress.TabIndex = 2; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { IdColumn, Title, Cost, Count }); + dataGridView.Location = new Point(9, 24); + dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(485, 285); + dataGridView.TabIndex = 3; + // + // IdColumn + // + IdColumn.HeaderText = "Номер платья"; + IdColumn.MinimumWidth = 6; + IdColumn.Name = "IdColumn"; + IdColumn.Visible = false; + IdColumn.Width = 125; + // + // Title + // + Title.HeaderText = "Название"; + Title.MinimumWidth = 6; + Title.Name = "Title"; + Title.Width = 125; + // + // Cost + // + Cost.HeaderText = "Цена"; + Cost.MinimumWidth = 6; + Cost.Name = "Cost"; + Cost.Width = 125; + // + // Count + // + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + Count.Width = 125; + // + // buttonSave + // + buttonSave.Location = new Point(625, 179); + buttonSave.Margin = new Padding(3, 2, 3, 2); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(82, 22); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(761, 179); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(82, 22); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(518, 29); + label1.Name = "label1"; + label1.Size = new Size(85, 15); + label1.TabIndex = 6; + label1.Text = "Дата создания"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(518, 66); + label2.Name = "label2"; + label2.Size = new Size(59, 15); + label2.TabIndex = 7; + label2.Text = "Название"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(518, 106); + label3.Name = "label3"; + label3.Size = new Size(40, 15); + label3.TabIndex = 8; + label3.Text = "Адрес"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(518, 144); + label4.Name = "label4"; + label4.Size = new Size(80, 15); + label4.TabIndex = 9; + label4.Text = "Вместимость"; + label4.TextAlign = ContentAlignment.TopCenter; + // + // numeric + // + numeric.Location = new Point(625, 142); + numeric.Margin = new Padding(3, 2, 3, 2); + numeric.Name = "numeric"; + numeric.Size = new Size(131, 23); + numeric.TabIndex = 10; + // + // FormShop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(854, 338); + Controls.Add(numeric); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(dataGridView); + Controls.Add(textBoxAdress); + Controls.Add(textBoxName); + Controls.Add(dateTimePicker); + Margin = new Padding(3, 2, 3, 2); + Name = "FormShop"; + Text = "Форма магазина"; + Load += ShopForm_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numeric).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private DateTimePicker dateTimePicker; - private TextBox textBoxName; - private TextBox textBoxAdress; - private DataGridView dataGridView; - private Button buttonSave; - private Button buttonCancel; - private Label label1; - private Label label2; - private Label label3; - private DataGridViewTextBoxColumn IdColumn; - private DataGridViewTextBoxColumn Title; - private DataGridViewTextBoxColumn Cost; - private DataGridViewTextBoxColumn Count; - } + private DateTimePicker dateTimePicker; + private TextBox textBoxName; + private TextBox textBoxAdress; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + private Label label3; + private DataGridViewTextBoxColumn IdColumn; + private DataGridViewTextBoxColumn Title; + private DataGridViewTextBoxColumn Cost; + private DataGridViewTextBoxColumn Count; + private Label label4; + private NumericUpDown numeric; + } } \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormShop.cs b/MotorPlant/MotorPlantView/FormShop.cs index e1c45bb..497ffe8 100644 --- a/MotorPlant/MotorPlantView/FormShop.cs +++ b/MotorPlant/MotorPlantView/FormShop.cs @@ -15,108 +15,109 @@ using System.Windows.Forms; namespace MotorPlantView { - public partial class FormShop : Form - { - private readonly ILogger _logger; - private readonly IShopLogic _logic; - public int? _id; - private Dictionary _engine; - public FormShop(ILogger logger, IShopLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - } + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public int? _id; + private Dictionary _engines; + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } - private void ShopForm_Load(object sender, EventArgs e) - { - if (_id.HasValue) - { - _logger.LogInformation("Shop load"); - try - { - var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); - if (shop != null) - { - textBoxName.Text = shop.ShopName; - textBoxAdress.Text = shop.Adress; - dateTimePicker.Text = shop.DateOpen.ToString(); - _engine = shop.ShopEngines; - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Load shop error"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } + private void ShopForm_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Shop load"); + try + { + var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); + if (shop != null) + { + textBoxName.Text = shop.ShopName; + textBoxAdress.Text = shop.Adress; + dateTimePicker.Text = shop.DateOpen.ToString(); + numeric.Value = shop.MaxCount; + _engines = shop.ShopEngines ?? new Dictionary(); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Load shop error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } - private void LoadData() - { - _logger.LogInformation("Load engines"); - try - { - if (_engine != null) - { - foreach (var engine in _engine) - { - dataGridView.Rows.Add(new object[] { engine.Key, engine.Value.Item1.EngineName, engine.Value.Item1.Price, engine.Value.Item2 }); - } - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Load engines into shop error"); - 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(textBoxAdress.Text)) - { - MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Save shop"); - try - { - var model = new ShopBindingModel - { - Id = _id ?? 0, - ShopName = textBoxName.Text, - Adress = textBoxAdress.Text, - DateOpen = dateTimePicker.Value.Date, - ShopEngines = _engine - }; - 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, "Save shop error"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + private void LoadData() + { + _logger.LogInformation("Load engines"); + try + { + if (_engines != null) + { + foreach (var engine in _engines) + { + dataGridView.Rows.Add(new object[] { engine.Key, engine.Value.Item1.EngineName, engine.Value.Item1.Price, engine.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Load engines into shop error"); + 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(textBoxAdress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Save shop"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Adress = textBoxAdress.Text, + DateOpen = dateTimePicker.Value.Date, + MaxCount = Convert.ToInt32(numeric.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, "Save shop error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } - private void buttonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } } diff --git a/MotorPlant/MotorPlantView/FormShop.resx b/MotorPlant/MotorPlantView/FormShop.resx index 1af7de1..af32865 100644 --- a/MotorPlant/MotorPlantView/FormShop.resx +++ b/MotorPlant/MotorPlantView/FormShop.resx @@ -1,17 +1,17 @@  - diff --git a/MotorPlant/MotorPlantView/Program.cs b/MotorPlant/MotorPlantView/Program.cs index e7c5acf..088c50c 100644 --- a/MotorPlant/MotorPlantView/Program.cs +++ b/MotorPlant/MotorPlantView/Program.cs @@ -55,6 +55,7 @@ namespace MotorPlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + } } } \ No newline at end of file -- 2.25.1