From 2d7190b3f8831366c47832be272148dcca9a9c8f Mon Sep 17 00:00:00 2001 From: Timourka Date: Fri, 23 Feb 2024 16:11:13 +0400 Subject: [PATCH 1/8] =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ShopLogic.cs | 183 ++++++++++++++++++ .../BindingModels/ShopBindingModel.cs | 26 +++ .../BusinessLogicsContracts/IShopLogic.cs | 22 +++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 21 ++ .../ViewModels/ShopViewModel.cs | 22 +++ .../Models/IShopModel.cs | 16 ++ .../Models/Order.cs | 5 - .../Models/Shop.cs | 59 ++++++ 9 files changed, 363 insertions(+), 5 deletions(-) create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/BindingModels/ShopBindingModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/SearchModels/ShopSearchModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IShopStorage.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/ViewModels/ShopViewModel.cs create mode 100644 AutomobilePlant/AutomobilePlantDataModels/Models/IShopModel.cs create mode 100644 AutomobilePlant/AutomobilePlantListImplement/Models/Shop.cs diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..f19ea43 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,183 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Shop Name:{0}, ID:{1}", model.Name, model.Id); + + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement. element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. Shop Name:{0}, ID:{1} ", model?.Name, model?.Id); + + var list = (model == null) ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + public bool SupplyCars(ShopSearchModel model, ICarModel car, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (car == null) + { + throw new ArgumentNullException(nameof(car)); + } + + if (count <= 0) + { + throw new ArgumentNullException("Count of cars in supply must be more than 0", nameof(count)); + } + + var shopElement = _shopStorage.GetElement(model); + if (shopElement == null) + { + _logger.LogWarning("Required shop element not found in storage"); + return false; + } + + _logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name); + + if (shopElement.ShopCars.TryGetValue(car.Id, out var sameCar)) + { + shopElement.ShopCars[car.Id] = (car, sameCar.Item2 + count); + _logger.LogInformation("Same car found by supply. Added {0} of {1} in {2} shop", count, car.CarName, shopElement.Name); + } + else + { + shopElement.ShopCars[car.Id] = (car, count); + _logger.LogInformation("New car added by supply. Added {0} of {1} in {2} shop", count, car.CarName, shopElement.Name); + } + + _shopStorage.Update(new() + { + Id = shopElement.Id, + Name = shopElement.Name, + Address = shopElement.Address, + OpeningDate = shopElement.OpeningDate, + ShopCars = shopElement.ShopCars + }); + + return true; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия магазина!", nameof(model.Name)); + } + + _logger.LogInformation("Shop. Name: {0}, Address: {1}, ID: {2}", model.Name, model.Address, model.Id); + + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.Name + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/BindingModels/ShopBindingModel.cs b/AutomobilePlant/AutomobilePlantContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..a0e0340 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,26 @@ +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + + public string Name { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime OpeningDate { get; set; } + + public Dictionary ShopCars + { + get; + set; + } = new(); + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..34fcc4d --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + ShopViewModel? ReadElement(ShopSearchModel model); + List? ReadList(ShopSearchModel? model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool SupplyCars(ShopSearchModel model, ICarModel car, int count); + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/SearchModels/ShopSearchModel.cs b/AutomobilePlant/AutomobilePlantContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..9af1a3d --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IShopStorage.cs b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..c93f7de --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.StoragesContracts +{ + public interface IShopStorage + { + ShopViewModel? GetElement(ShopSearchModel model); + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ShopViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..f93ef75 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,22 @@ +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Shop's name")] + public string Name { get; set; } = string.Empty; + [DisplayName("Address")] + public string Address { get; set; } = string.Empty; + [DisplayName("Opening date")] + public DateTime OpeningDate { get; set; } + public Dictionary ShopCars { get; set; } = new(); + } +} diff --git a/AutomobilePlant/AutomobilePlantDataModels/Models/IShopModel.cs b/AutomobilePlant/AutomobilePlantDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..8ee298b --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDataModels/Models/IShopModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantDataModels.Models +{ + public interface IShopModel : IId + { + string Name { get; } + string Address { get; } + DateTime OpeningDate { get; } + Dictionary ShopCars { get; } + } +} diff --git a/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs b/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs index 6250a8e..2d8b684 100644 --- a/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs +++ b/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs @@ -50,12 +50,7 @@ namespace AutomobilePlantListImplement.Models { return; } - Id = model.Id; - CarId = model.CarId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } diff --git a/AutomobilePlant/AutomobilePlantListImplement/Models/Shop.cs b/AutomobilePlant/AutomobilePlantListImplement/Models/Shop.cs new file mode 100644 index 0000000..167007d --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/Models/Shop.cs @@ -0,0 +1,59 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string Name { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary ShopCars { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + { + return null; + } + + return new Shop() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + OpeningDate = model.OpeningDate, + ShopCars = new() + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + + Name = model.Name; + Address = model.Address; + OpeningDate = model.OpeningDate; + ShopCars = model.ShopCars; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + OpeningDate = OpeningDate, + ShopCars = ShopCars + }; + } +} -- 2.25.1 From 402314d5302a01c46be7a35e395dd8f794032313 Mon Sep 17 00:00:00 2001 From: Timourka Date: Fri, 23 Feb 2024 18:38:25 +0400 Subject: [PATCH 2/8] forms --- .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 126 ++++++++++++ .../AutomobilePlantView/FormMain.Designer.cs | 20 +- .../AutomobilePlantView/FormMain.cs | 20 +- .../AutomobilePlantView/FormShop.Designer.cs | 182 ++++++++++++++++++ .../AutomobilePlantView/FormShop.cs | 134 +++++++++++++ .../AutomobilePlantView/FormShop.resx | 138 +++++++++++++ .../FormShopSupply.Designer.cs | 143 ++++++++++++++ .../AutomobilePlantView/FormShopSupply.cs | 126 ++++++++++++ .../AutomobilePlantView/FormShopSupply.resx | 120 ++++++++++++ .../AutomobilePlantView/FormShops.Designer.cs | 113 +++++++++++ .../AutomobilePlantView/FormShops.cs | 120 ++++++++++++ .../AutomobilePlantView/FormShops.resx | 120 ++++++++++++ .../AutomobilePlantView/Program.cs | 5 + 14 files changed, 1367 insertions(+), 2 deletions(-) create mode 100644 AutomobilePlant/AutomobilePlantListImplement/Implements/ShopStorage.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormShop.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormShop.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormShop.resx create mode 100644 AutomobilePlant/AutomobilePlantView/FormShopSupply.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormShopSupply.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormShopSupply.resx create mode 100644 AutomobilePlant/AutomobilePlantView/FormShops.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormShops.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormShops.resx diff --git a/AutomobilePlant/AutomobilePlantListImplement/DataListSingleton.cs b/AutomobilePlant/AutomobilePlantListImplement/DataListSingleton.cs index 2406e38..a54bf05 100644 --- a/AutomobilePlant/AutomobilePlantListImplement/DataListSingleton.cs +++ b/AutomobilePlant/AutomobilePlantListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace AutomobilePlantListImplement public List Components { get; set; } public List Orders { get; set; } public List Cars { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Cars = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/AutomobilePlant/AutomobilePlantListImplement/Implements/ShopStorage.cs b/AutomobilePlant/AutomobilePlantListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..1d4a4bd --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/Implements/ShopStorage.cs @@ -0,0 +1,126 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.Name) && shop.Name == model.Name) || (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + + return null; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.Name)) + { + return result; + } + + foreach (var shop in _source.Shops) + { + if (shop.Name.Contains(model.Name)) + { + result.Add(shop.GetViewModel); + } + } + + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + + return result; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + + var newShop = Shop.Create(model); + + if (newShop == null) + { + return null; + } + + _source.Shops.Add(newShop); + + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + + return null; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs index e5d1a4e..08dcb1f 100644 --- a/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs +++ b/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs @@ -38,6 +38,8 @@ buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRefresh = new Button(); + shopsToolStripMenuItem = new ToolStripMenuItem(); + shopsSupplyToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -53,7 +55,7 @@ // // toolStripMenuItemCatalogs // - toolStripMenuItemCatalogs.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemComponents, toolStripMenuItemCars }); + toolStripMenuItemCatalogs.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemComponents, toolStripMenuItemCars, shopsToolStripMenuItem, shopsSupplyToolStripMenuItem }); toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; toolStripMenuItemCatalogs.Size = new Size(65, 20); toolStripMenuItemCatalogs.Text = "Catalogs"; @@ -131,6 +133,20 @@ buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += ButtonRef_Click; // + // shopsToolStripMenuItem + // + shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; + shopsToolStripMenuItem.Size = new Size(180, 22); + shopsToolStripMenuItem.Text = "Shops"; + shopsToolStripMenuItem.Click += shopsToolStripMenuItem_Click; + // + // shopsSupplyToolStripMenuItem + // + shopsSupplyToolStripMenuItem.Name = "shopsSupplyToolStripMenuItem"; + shopsSupplyToolStripMenuItem.Size = new Size(180, 22); + shopsSupplyToolStripMenuItem.Text = "Shop's supply"; + shopsSupplyToolStripMenuItem.Click += shopsSupplyToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); @@ -165,5 +181,7 @@ private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRefresh; + private ToolStripMenuItem shopsToolStripMenuItem; + private ToolStripMenuItem shopsSupplyToolStripMenuItem; } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormMain.cs b/AutomobilePlant/AutomobilePlantView/FormMain.cs index 3321de7..21457ef 100644 --- a/AutomobilePlant/AutomobilePlantView/FormMain.cs +++ b/AutomobilePlant/AutomobilePlantView/FormMain.cs @@ -125,7 +125,7 @@ namespace AutomobilePlantView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -157,6 +157,24 @@ namespace AutomobilePlantView { 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 shopsSupplyToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply)); + if (service is FormShopSupply form) + { + form.ShowDialog(); + } + } } } diff --git a/AutomobilePlant/AutomobilePlantView/FormShop.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormShop.Designer.cs new file mode 100644 index 0000000..dbe21c2 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormShop.Designer.cs @@ -0,0 +1,182 @@ +namespace AutomobilePlantView +{ + 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() + { + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + openingDateTimePicker = new DateTimePicker(); + labelName = new Label(); + labelAdress = new Label(); + labelOpeningDate = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + dataGridView = new DataGridView(); + IdCol = new DataGridViewTextBoxColumn(); + CarCol = new DataGridViewTextBoxColumn(); + CountCol = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // textBoxName + // + textBoxName.Location = new Point(100, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(378, 23); + textBoxName.TabIndex = 0; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(100, 35); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(378, 23); + textBoxAddress.TabIndex = 1; + // + // openingDateTimePicker + // + openingDateTimePicker.Location = new Point(100, 64); + openingDateTimePicker.Name = "openingDateTimePicker"; + openingDateTimePicker.Size = new Size(378, 23); + openingDateTimePicker.TabIndex = 3; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(42, 15); + labelName.TabIndex = 4; + labelName.Text = "Name:"; + // + // labelAdress + // + labelAdress.AutoSize = true; + labelAdress.Location = new Point(12, 38); + labelAdress.Name = "labelAdress"; + labelAdress.Size = new Size(45, 15); + labelAdress.TabIndex = 5; + labelAdress.Text = "Adress:"; + // + // labelOpeningDate + // + labelOpeningDate.AutoSize = true; + labelOpeningDate.Location = new Point(12, 70); + labelOpeningDate.Name = "labelOpeningDate"; + labelOpeningDate.Size = new Size(82, 15); + labelOpeningDate.TabIndex = 6; + labelOpeningDate.Text = "Opening date:"; + // + // buttonSave + // + buttonSave.Location = new Point(322, 334); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 7; + buttonSave.Text = "Save"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(403, 334); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { IdCol, CarCol, CountCol }); + dataGridView.Location = new Point(12, 93); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(466, 235); + dataGridView.TabIndex = 9; + // + // IdCol + // + IdCol.HeaderText = "Id"; + IdCol.Name = "IdCol"; + IdCol.Visible = false; + // + // CarCol + // + CarCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + CarCol.HeaderText = "Car"; + CarCol.Name = "CarCol"; + // + // CountCol + // + CountCol.HeaderText = "Count"; + CountCol.Name = "CountCol"; + // + // FormShop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(490, 369); + Controls.Add(dataGridView); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelOpeningDate); + Controls.Add(labelAdress); + Controls.Add(labelName); + Controls.Add(openingDateTimePicker); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Name = "FormShop"; + Text = "FormShop"; + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxName; + private TextBox textBoxAddress; + private DateTimePicker openingDateTimePicker; + private Label labelName; + private Label labelAdress; + private Label labelOpeningDate; + private Button buttonSave; + private Button buttonCancel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn IdCol; + private DataGridViewTextBoxColumn CarCol; + private DataGridViewTextBoxColumn CountCol; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormShop.cs b/AutomobilePlant/AutomobilePlantView/FormShop.cs new file mode 100644 index 0000000..cfcfaa6 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormShop.cs @@ -0,0 +1,134 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AutomobilePlantView +{ + public partial class FormShop : Form + { + private readonly IShopLogic _logic; + private readonly ILogger _logger; + private Dictionary _shopCars; + private int? _id; + public int Id { set { _id = value; } } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopCars = new(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Loading shop"); + + try + { + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + + if (view != null) + { + textBoxName.Text = view.Name; + textBoxAddress.Text = view.Address; + openingDateTimePicker.Value = view.OpeningDate; + _shopCars = view.ShopCars ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка авто магазина"); + + try + { + if (_shopCars != null) + { + dataGridView.Rows.Clear(); + foreach (var car in _shopCars) + { + dataGridView.Rows.Add(new object[] { car.Key, car.Value.Item1.CarName, car.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки авто магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение магазина"); + + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + Address = textBoxAddress.Text, + OpeningDate = openingDateTimePicker.Value.Date, + ShopCars = _shopCars + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при сохранении магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormShop.resx b/AutomobilePlant/AutomobilePlantView/FormShop.resx new file mode 100644 index 0000000..8e413d1 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormShop.resx @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormShopSupply.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormShopSupply.Designer.cs new file mode 100644 index 0000000..3daea26 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormShopSupply.Designer.cs @@ -0,0 +1,143 @@ +namespace AutomobilePlantView +{ + partial class FormShopSupply + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + comboBoxCar = new ComboBox(); + comboBoxShop = new ComboBox(); + textBoxCount = new TextBox(); + labelCar = new Label(); + labelShop = new Label(); + labelCount = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxCar + // + comboBoxCar.FormattingEnabled = true; + comboBoxCar.Location = new Point(61, 6); + comboBoxCar.Name = "comboBoxCar"; + comboBoxCar.Size = new Size(275, 23); + comboBoxCar.TabIndex = 0; + // + // comboBoxShop + // + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(61, 35); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(275, 23); + comboBoxShop.TabIndex = 1; + // + // textBoxCount + // + textBoxCount.Location = new Point(61, 64); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(275, 23); + textBoxCount.TabIndex = 2; + // + // labelCar + // + labelCar.AutoSize = true; + labelCar.BackColor = SystemColors.Control; + labelCar.Location = new Point(12, 9); + labelCar.Name = "labelCar"; + labelCar.Size = new Size(28, 15); + labelCar.TabIndex = 3; + labelCar.Text = "Car:"; + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(12, 38); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(37, 15); + labelShop.TabIndex = 4; + labelShop.Text = "Shop:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 67); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(43, 15); + labelCount.TabIndex = 5; + labelCount.Text = "Count:"; + // + // buttonSave + // + buttonSave.Location = new Point(180, 93); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Save"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(261, 93); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormShopSupply + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(348, 127); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCount); + Controls.Add(labelShop); + Controls.Add(labelCar); + Controls.Add(textBoxCount); + Controls.Add(comboBoxShop); + Controls.Add(comboBoxCar); + Name = "FormShopSupply"; + Text = "Shop's supply"; + Load += FormShopSupply_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxCar; + private ComboBox comboBoxShop; + private TextBox textBoxCount; + private Label labelCar; + private Label labelShop; + private Label labelCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormShopSupply.cs b/AutomobilePlant/AutomobilePlantView/FormShopSupply.cs new file mode 100644 index 0000000..3d2340d --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormShopSupply.cs @@ -0,0 +1,126 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AutomobilePlantView +{ + public partial class FormShopSupply : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logicCar; + private readonly IShopLogic _logicShop; + + public FormShopSupply(ILogger logger, ICarLogic logicCar, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicCar = logicCar; + _logicShop = logicShop; + } + + private void FormShopSupply_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка авто для пополнения"); + + try + { + var list = _logicCar.ReadList(null); + if (list != null) + { + comboBoxCar.DisplayMember = "CarName"; + comboBoxCar.ValueMember = "Id"; + comboBoxCar.DataSource = list; + comboBoxCar.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка авто"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка магазинов для пополнения"); + + try + { + var list = _logicShop.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "Name"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxCar.SelectedValue == null) + { + MessageBox.Show("Выберите авто", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Создание поставки"); + + try + { + var operationResult = _logicShop.SupplyCars( + new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue), Name = comboBoxShop.Text }, + new CarBindingModel { Id = Convert.ToInt32(comboBoxCar.SelectedValue), CarName = comboBoxCar.Text }, + Convert.ToInt32(textBoxCount.Text) + ); + + if (!operationResult) + { + throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormShopSupply.resx b/AutomobilePlant/AutomobilePlantView/FormShopSupply.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormShopSupply.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormShops.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormShops.Designer.cs new file mode 100644 index 0000000..9400149 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormShops.Designer.cs @@ -0,0 +1,113 @@ +namespace AutomobilePlantView +{ + 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() + { + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonRefresh + // + buttonRefresh.Location = new Point(678, 105); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(116, 23); + buttonRefresh.TabIndex = 9; + buttonRefresh.Text = "Refresh"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(678, 76); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(116, 23); + buttonDelete.TabIndex = 8; + buttonDelete.Text = "Delete"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(678, 47); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(116, 23); + buttonUpdate.TabIndex = 7; + buttonUpdate.Text = "Update"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(678, 18); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(116, 23); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Add"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(6, 6); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(666, 438); + dataGridView.TabIndex = 5; + // + // FormShops + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + Text = "Shops"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormShops.cs b/AutomobilePlant/AutomobilePlantView/FormShops.cs new file mode 100644 index 0000000..b440af7 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormShops.cs @@ -0,0 +1,120 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AutomobilePlantView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopCars"].Visible = false; + } + + _logger.LogInformation("Загрузка магазинов"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + + if (service is FormShop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить магазин?", "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + + try + { + if (!_logic.Delete(new ShopBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormShops.resx b/AutomobilePlant/AutomobilePlantView/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/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/AutomobilePlant/AutomobilePlantView/Program.cs b/AutomobilePlant/AutomobilePlantView/Program.cs index cc61535..bf966c0 100644 --- a/AutomobilePlant/AutomobilePlantView/Program.cs +++ b/AutomobilePlant/AutomobilePlantView/Program.cs @@ -40,6 +40,8 @@ namespace AutomobilePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -47,6 +49,9 @@ namespace AutomobilePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file -- 2.25.1 From a20c777d88d67692893619d05478626c16e3dc37 Mon Sep 17 00:00:00 2001 From: Timourka Date: Fri, 23 Feb 2024 23:58:19 +0400 Subject: [PATCH 3/8] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutomobilePlant/AutomobilePlantView/FormCar.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AutomobilePlant/AutomobilePlantView/FormCar.cs b/AutomobilePlant/AutomobilePlantView/FormCar.cs index 45bc080..118c17f 100644 --- a/AutomobilePlant/AutomobilePlantView/FormCar.cs +++ b/AutomobilePlant/AutomobilePlantView/FormCar.cs @@ -133,7 +133,7 @@ namespace AutomobilePlantView { try { - _logger.LogInformation("Удаление компонента: { ComponentName} - { Count} ", dataGridView.SelectedRows[0].Cells[1].Value); + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count} ", dataGridView.SelectedRows[0].Cells[1].Value, dataGridView.SelectedRows[0].Cells[2].Value); _carComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); } catch (Exception ex) -- 2.25.1 From 10e694172f06f5bdff0c33e79a91831a5c461a39 Mon Sep 17 00:00:00 2001 From: Timourka Date: Sun, 25 Feb 2024 13:56:48 +0400 Subject: [PATCH 4/8] fix storage before --- .../DataFileSingleton.cs | 4 + .../Implements/ShopStorage.cs | 147 ++++++++++++++++++ .../Models/Shop.cs | 110 +++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 AutomobilePlant/AutomobilePlantFileImplement/Implements/ShopStorage.cs create mode 100644 AutomobilePlant/AutomobilePlantFileImplement/Models/Shop.cs diff --git a/AutomobilePlant/AutomobilePlantFileImplement/DataFileSingleton.cs b/AutomobilePlant/AutomobilePlantFileImplement/DataFileSingleton.cs index e118e9d..5423dd3 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/DataFileSingleton.cs +++ b/AutomobilePlant/AutomobilePlantFileImplement/DataFileSingleton.cs @@ -14,9 +14,11 @@ namespace AutomobilePlantFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string CarFileName = "Car.xml"; + private readonly string ShopFileName = "Shop.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Cars { get; private set; } + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -28,11 +30,13 @@ namespace AutomobilePlantFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveCars() => SaveData(Cars, CarFileName, "Cars", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Cars = LoadData(CarFileName, "Car", x => Car.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Implements/ShopStorage.cs b/AutomobilePlant/AutomobilePlantFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..fc6eaf4 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,147 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Models; +using AutomobilePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + return source.Shops + .Select(x => x.GetViewModel) + .Where(x => x.Name.Contains(model.Name ?? string.Empty)) + .ToList(); + } + + public List GetFullList() + { + return source.Shops.Select(shop => shop.GetViewModel).ToList(); + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + source.Shops.Remove(shop); + source.SaveShops(); + return shop.GetViewModel; + } + + public bool SellCar(ICarModel model, int count) + { + var car = source.Cars.FirstOrDefault(x => x.Id == model.Id); + + if (car == null) + { + return false; + } + + var countStore = count; + + var shopCars = source.Shops.SelectMany(shop => shop.ShopCars.Where(c => c.Value.Item1.Id == car.Id)); + + foreach (var c in shopCars) + { + count -= c.Value.Item2; + + if (count <= 0) + { + break; + } + } + + if (count > 0) + { + return false; + } + + count = countStore; + + foreach (var shop in source.Shops) + { + var cars = shop.ShopCars; + + foreach (var c in cars.Where(x => x.Value.Item1.Id == car.Id)) + { + var min = Math.Min(c.Value.Item2, count); + cars[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min); + count -= min; + + if (count <= 0) + { + break; + } + } + + shop.Update(new ShopBindingModel + { + Id = shop.Id, + Name = shop.Name, + Address = shop.Address, + OpeningDate = shop.OpeningDate, + ShopCars = cars + }); + + source.SaveShops(); + + if (count <= 0) break; + } + + return count <= 0; + } + } +} diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Models/Shop.cs b/AutomobilePlant/AutomobilePlantFileImplement/Models/Shop.cs new file mode 100644 index 0000000..91f0e4d --- /dev/null +++ b/AutomobilePlant/AutomobilePlantFileImplement/Models/Shop.cs @@ -0,0 +1,110 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace AutomobilePlantFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string Name { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary Cars { get; private set; } = new(); + private Dictionary? _shopCars = null; + + public Dictionary ShopCars + { + get + { + if (_shopCars == null) + { + var source = DataFileSingleton.GetInstance(); + _shopCars = Cars.ToDictionary( + x => x.Key, + y => ((source.Cars.FirstOrDefault(z => z.Id == y.Key) as ICarModel)!, y.Value) + ); + } + return _shopCars; + } + } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + OpeningDate = model.OpeningDate, + Cars = model.ShopCars.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Name = element.Element("Name")!.Value, + Address = element.Element("Address")!.Value, + OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value), + Cars = element.Element("ShopCars")!.Elements("ShopCar").ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value) + ) + }; + } + + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + Address = model.Address; + OpeningDate = model.OpeningDate; + if (model.ShopCars.Count > 0) + { + Cars = model.ShopCars.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopCars = null; + } + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + OpeningDate = OpeningDate, + ShopCars = ShopCars, + }; + + public XElement GetXElement => new( + "Shop", + new XAttribute("Id", Id), + new XElement("Name", Name), + new XElement("Address", Address), + new XElement("OpeningDate", OpeningDate.ToString()), + new XElement("ShopCars", Cars.Select(x => + new XElement("ShopCar", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} -- 2.25.1 From 5c4d7d410e9da4b7edf8c162299f54403c85f3d7 Mon Sep 17 00:00:00 2001 From: Timourka Date: Mon, 26 Feb 2024 00:36:11 +0400 Subject: [PATCH 5/8] laba2coml mb done no test --- .../BusinessLogics/OrderLogic.cs | 92 +++++++++++++- .../BusinessLogics/ShopLogic.cs | 50 ++++++-- .../BindingModels/ShopBindingModel.cs | 2 + .../BusinessLogicsContracts/IShopLogic.cs | 1 + .../StoragesContracts/IShopStorage.cs | 2 + .../ViewModels/ShopViewModel.cs | 7 + .../Models/IShopModel.cs | 1 + .../Implements/ShopStorage.cs | 27 ++-- .../Models/Shop.cs | 6 + .../Implements/ShopStorage.cs | 5 + .../Models/Shop.cs | 1 + .../AutomobilePlantView/FormMain.Designer.cs | 39 +++--- .../AutomobilePlantView/FormMain.cs | 46 ++++--- .../AutomobilePlantView/FormShop.Designer.cs | 44 +++++-- .../AutomobilePlantView/FormShop.cs | 8 ++ .../AutomobilePlantView/FormShop.resx | 9 -- .../FormShopSell.Designer.cs | 119 +++++++++++++++++ .../AutomobilePlantView/FormShopSell.cs | 95 ++++++++++++++ .../AutomobilePlantView/FormShopSell.resx | 120 ++++++++++++++++++ .../AutomobilePlantView/Program.cs | 1 + 20 files changed, 587 insertions(+), 88 deletions(-) create mode 100644 AutomobilePlant/AutomobilePlantView/FormShopSell.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormShopSell.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormShopSell.resx diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs index 215cdf4..9af33ef 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs @@ -4,6 +4,7 @@ using AutomobilePlantContracts.SearchModels; using AutomobilePlantContracts.StoragesContracts; using AutomobilePlantContracts.ViewModels; using AutomobilePlantDataModels.Enums; +using AutomobilePlantDataModels.Models; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -17,11 +18,17 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; + private readonly IShopLogic _shopLogic; + private readonly ICarStorage _carStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, ICarStorage carStorage, IShopStorage shopStorage) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _carStorage = carStorage; + _shopStorage = shopStorage; } public List? ReadList(OrderSearchModel? model) @@ -40,16 +47,80 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics public bool CreateOrder(OrderBindingModel model) { CheckModel(model); - if (model.Status != OrderStatus.Неизвестен) return false; + 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; } + public bool CheckThenSupplyMany(ICarModel car, int count) + { + if (count <= 0) + { + _logger.LogWarning("Check then supply operation error. Car count < 0."); + return false; + } + + int freeSpace = 0; + foreach (var shop in _shopStorage.GetFullList()) + { + freeSpace += shop.MaxCountCars; + foreach (var c in shop.ShopCars) + { + freeSpace -= c.Value.Item2; + } + } + + if (freeSpace < count) + { + _logger.LogWarning("Check then supply operation error. There's no place for new cars in shops."); + return false; + } + + foreach (var shop in _shopStorage.GetFullList()) + { + freeSpace = shop.MaxCountCars; + + foreach (var c in shop.ShopCars) + freeSpace -= c.Value.Item2; + + if (freeSpace <= 0) + continue; + + if (freeSpace >= count) + { + if (_shopLogic.SupplyCars(new ShopSearchModel() { Id = shop.Id }, car, count)) + count = 0; + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + if (freeSpace < count) + { + if (_shopLogic.SupplyCars(new ShopSearchModel() { Id = shop.Id }, car, freeSpace)) + count -= freeSpace; + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + if (count <= 0) + { + return true; + } + } + return false; + } + public bool ChangeStatus(OrderBindingModel model, OrderStatus status) { CheckModel(model, false); @@ -64,6 +135,23 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics _logger.LogWarning("Status change operation failed"); throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } + + if (status == OrderStatus.Готов) + { + var car = _carStorage.GetElement(new CarSearchModel() { Id = model.CarId }); + if (car == null) + { + _logger.LogWarning("Status change operation failed. Car not found."); + return false; + } + + if (!CheckThenSupplyMany(car, model.Count)) + { + _logger.LogWarning("Status change operation failed. Shop supply error."); + return false; + } + } + OrderStatus oldStatus = model.Status; model.Status = status; if (model.Status == OrderStatus.Выдан) diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs index f19ea43..97578c8 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs @@ -88,25 +88,37 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics _logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name); - if (shopElement.ShopCars.TryGetValue(car.Id, out var sameCar)) + int countCars = 0; + foreach (var c in shopElement.ShopCars) + countCars += c.Value.Item2; + + if (countCars > shopElement.MaxCountCars - countCars) { - shopElement.ShopCars[car.Id] = (car, sameCar.Item2 + count); - _logger.LogInformation("Same car found by supply. Added {0} of {1} in {2} shop", count, car.CarName, shopElement.Name); + _logger.LogWarning("Required shop will be overflowed"); + return false; } else { - shopElement.ShopCars[car.Id] = (car, count); - _logger.LogInformation("New car added by supply. Added {0} of {1} in {2} shop", count, car.CarName, shopElement.Name); - } + if (shopElement.ShopCars.TryGetValue(car.Id, out var sameCar)) + { + shopElement.ShopCars[car.Id] = (car, sameCar.Item2 + count); + _logger.LogInformation("Same car found by supply. Added {0} of {1} in {2} shop", count, car.CarName, shopElement.Name); + } + else + { + shopElement.ShopCars[car.Id] = (car, count); + _logger.LogInformation("New car added by supply. Added {0} of {1} in {2} shop", count, car.CarName, shopElement.Name); + } - _shopStorage.Update(new() - { - Id = shopElement.Id, - Name = shopElement.Name, - Address = shopElement.Address, - OpeningDate = shopElement.OpeningDate, - ShopCars = shopElement.ShopCars - }); + _shopStorage.Update(new() + { + Id = shopElement.Id, + Name = shopElement.Name, + Address = shopElement.Address, + OpeningDate = shopElement.OpeningDate, + ShopCars = shopElement.ShopCars + }); + } return true; } @@ -167,6 +179,11 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics throw new ArgumentNullException("Нет названия магазина!", nameof(model.Name)); } + if (model.MaxCountCars < 0) + { + throw new InvalidOperationException("Отрицательное максимальное количество авто!"); + } + _logger.LogInformation("Shop. Name: {0}, Address: {1}, ID: {2}", model.Name, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel @@ -179,5 +196,10 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics throw new InvalidOperationException("Магазин с таким названием уже есть"); } } + + public bool SellCar(ICarModel car, int count) + { + return _shopStorage.SellCar(car, count); + } } } diff --git a/AutomobilePlant/AutomobilePlantContracts/BindingModels/ShopBindingModel.cs b/AutomobilePlant/AutomobilePlantContracts/BindingModels/ShopBindingModel.cs index a0e0340..4ee41b3 100644 --- a/AutomobilePlant/AutomobilePlantContracts/BindingModels/ShopBindingModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/BindingModels/ShopBindingModel.cs @@ -15,6 +15,8 @@ namespace AutomobilePlantContracts.BindingModels public string Address { get; set; } = string.Empty; + public int MaxCountCars { get; set; } + public DateTime OpeningDate { get; set; } public Dictionary ShopCars diff --git a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IShopLogic.cs index 34fcc4d..ae81414 100644 --- a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -18,5 +18,6 @@ namespace AutomobilePlantContracts.BusinessLogicsContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool SupplyCars(ShopSearchModel model, ICarModel car, int count); + bool SellCar(ICarModel car, int count); } } diff --git a/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IShopStorage.cs b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IShopStorage.cs index c93f7de..2397c7e 100644 --- a/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IShopStorage.cs +++ b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.SearchModels; using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -17,5 +18,6 @@ namespace AutomobilePlantContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool SellCar(ICarModel model, int count); } } diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ShopViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ShopViewModel.cs index f93ef75..66472a4 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ShopViewModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ShopViewModel.cs @@ -11,12 +11,19 @@ namespace AutomobilePlantContracts.ViewModels public class ShopViewModel : IShopModel { public int Id { get; set; } + [DisplayName("Shop's name")] public string Name { get; set; } = string.Empty; + [DisplayName("Address")] public string Address { get; set; } = string.Empty; + + [DisplayName("Maximum cars' count in shop")] + public int MaxCountCars { get; set; } + [DisplayName("Opening date")] public DateTime OpeningDate { get; set; } + public Dictionary ShopCars { get; set; } = new(); } } diff --git a/AutomobilePlant/AutomobilePlantDataModels/Models/IShopModel.cs b/AutomobilePlant/AutomobilePlantDataModels/Models/IShopModel.cs index 8ee298b..176cdcb 100644 --- a/AutomobilePlant/AutomobilePlantDataModels/Models/IShopModel.cs +++ b/AutomobilePlant/AutomobilePlantDataModels/Models/IShopModel.cs @@ -10,6 +10,7 @@ namespace AutomobilePlantDataModels.Models { string Name { get; } string Address { get; } + int MaxCountCars { get; } DateTime OpeningDate { get; } Dictionary ShopCars { get; } } diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Implements/ShopStorage.cs b/AutomobilePlant/AutomobilePlantFileImplement/Implements/ShopStorage.cs index fc6eaf4..a44e3d3 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/Implements/ShopStorage.cs +++ b/AutomobilePlant/AutomobilePlantFileImplement/Implements/ShopStorage.cs @@ -90,26 +90,16 @@ namespace AutomobilePlantFileImplement.Implements return false; } - var countStore = count; var shopCars = source.Shops.SelectMany(shop => shop.ShopCars.Where(c => c.Value.Item1.Id == car.Id)); - foreach (var c in shopCars) - { - count -= c.Value.Item2; + int countStore = 0; - if (count <= 0) - { - break; - } - } + foreach (var it in shopCars) + countStore += it.Value.Item2; - if (count > 0) - { + if (count > countStore) return false; - } - - count = countStore; foreach (var shop in source.Shops) { @@ -117,14 +107,12 @@ namespace AutomobilePlantFileImplement.Implements foreach (var c in cars.Where(x => x.Value.Item1.Id == car.Id)) { - var min = Math.Min(c.Value.Item2, count); + int min = Math.Min(c.Value.Item2, count); cars[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min); count -= min; if (count <= 0) - { break; - } } shop.Update(new ShopBindingModel @@ -138,10 +126,11 @@ namespace AutomobilePlantFileImplement.Implements source.SaveShops(); - if (count <= 0) break; + if (count <= 0) + return true; } - return count <= 0; + return true; } } } diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Models/Shop.cs b/AutomobilePlant/AutomobilePlantFileImplement/Models/Shop.cs index 91f0e4d..172b6c8 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/Models/Shop.cs +++ b/AutomobilePlant/AutomobilePlantFileImplement/Models/Shop.cs @@ -15,6 +15,7 @@ namespace AutomobilePlantFileImplement.Models public int Id { get; private set; } public string Name { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty; + public int MaxCountCars { get; private set; } public DateTime OpeningDate { get; private set; } public Dictionary Cars { get; private set; } = new(); private Dictionary? _shopCars = null; @@ -46,6 +47,7 @@ namespace AutomobilePlantFileImplement.Models Id = model.Id, Name = model.Name, Address = model.Address, + MaxCountCars = model.MaxCountCars, OpeningDate = model.OpeningDate, Cars = model.ShopCars.ToDictionary(x => x.Key, x => x.Value.Item2) }; @@ -62,6 +64,7 @@ namespace AutomobilePlantFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), Name = element.Element("Name")!.Value, Address = element.Element("Address")!.Value, + MaxCountCars = Convert.ToInt32(element.Element("MaxCountCars")!.Value), OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value), Cars = element.Element("ShopCars")!.Elements("ShopCar").ToDictionary( x => Convert.ToInt32(x.Element("Key")?.Value), @@ -79,6 +82,7 @@ namespace AutomobilePlantFileImplement.Models } Name = model.Name; Address = model.Address; + MaxCountCars = model.MaxCountCars; OpeningDate = model.OpeningDate; if (model.ShopCars.Count > 0) { @@ -91,6 +95,7 @@ namespace AutomobilePlantFileImplement.Models Id = Id, Name = Name, Address = Address, + MaxCountCars = MaxCountCars, OpeningDate = OpeningDate, ShopCars = ShopCars, }; @@ -100,6 +105,7 @@ namespace AutomobilePlantFileImplement.Models new XAttribute("Id", Id), new XElement("Name", Name), new XElement("Address", Address), + new XElement("MaxCountCars", MaxCountCars), new XElement("OpeningDate", OpeningDate.ToString()), new XElement("ShopCars", Cars.Select(x => new XElement("ShopCar", diff --git a/AutomobilePlant/AutomobilePlantListImplement/Implements/ShopStorage.cs b/AutomobilePlant/AutomobilePlantListImplement/Implements/ShopStorage.cs index 1d4a4bd..a45d459 100644 --- a/AutomobilePlant/AutomobilePlantListImplement/Implements/ShopStorage.cs +++ b/AutomobilePlant/AutomobilePlantListImplement/Implements/ShopStorage.cs @@ -2,6 +2,7 @@ using AutomobilePlantContracts.SearchModels; using AutomobilePlantContracts.StoragesContracts; using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Models; using AutomobilePlantListImplement.Models; using System; using System.Collections.Generic; @@ -13,6 +14,10 @@ namespace AutomobilePlantListImplement.Implements { public class ShopStorage : IShopStorage { + public bool SellCar(ICarModel car, int count) + { + throw new NotImplementedException(); + } private readonly DataListSingleton _source; public ShopStorage() diff --git a/AutomobilePlant/AutomobilePlantListImplement/Models/Shop.cs b/AutomobilePlant/AutomobilePlantListImplement/Models/Shop.cs index 167007d..c1e3c81 100644 --- a/AutomobilePlant/AutomobilePlantListImplement/Models/Shop.cs +++ b/AutomobilePlant/AutomobilePlantListImplement/Models/Shop.cs @@ -14,6 +14,7 @@ namespace AutomobilePlantListImplement.Models public int Id { get; private set; } public string Name { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty; + public int MaxCountCars { get; private set; } public DateTime OpeningDate { get; private set; } public Dictionary ShopCars { get; private set; } = new(); diff --git a/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs index 08dcb1f..77820d5 100644 --- a/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs +++ b/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs @@ -32,14 +32,15 @@ toolStripMenuItemCatalogs = new ToolStripMenuItem(); toolStripMenuItemComponents = new ToolStripMenuItem(); toolStripMenuItemCars = new ToolStripMenuItem(); + shopsToolStripMenuItem = new ToolStripMenuItem(); + shopsSupplyToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRefresh = new Button(); - shopsToolStripMenuItem = new ToolStripMenuItem(); - shopsSupplyToolStripMenuItem = new ToolStripMenuItem(); + sellCarsToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -55,7 +56,7 @@ // // toolStripMenuItemCatalogs // - toolStripMenuItemCatalogs.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemComponents, toolStripMenuItemCars, shopsToolStripMenuItem, shopsSupplyToolStripMenuItem }); + toolStripMenuItemCatalogs.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemComponents, toolStripMenuItemCars, shopsToolStripMenuItem, shopsSupplyToolStripMenuItem, sellCarsToolStripMenuItem }); toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; toolStripMenuItemCatalogs.Size = new Size(65, 20); toolStripMenuItemCatalogs.Text = "Catalogs"; @@ -74,6 +75,20 @@ toolStripMenuItemCars.Text = "Cars"; toolStripMenuItemCars.Click += CarsToolStripMenuItem_Click; // + // shopsToolStripMenuItem + // + shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; + shopsToolStripMenuItem.Size = new Size(180, 22); + shopsToolStripMenuItem.Text = "Shops"; + shopsToolStripMenuItem.Click += shopsToolStripMenuItem_Click; + // + // shopsSupplyToolStripMenuItem + // + shopsSupplyToolStripMenuItem.Name = "shopsSupplyToolStripMenuItem"; + shopsSupplyToolStripMenuItem.Size = new Size(180, 22); + shopsSupplyToolStripMenuItem.Text = "Shop's supply"; + shopsSupplyToolStripMenuItem.Click += shopsSupplyToolStripMenuItem_Click; + // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -133,19 +148,12 @@ buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += ButtonRef_Click; // - // shopsToolStripMenuItem + // sellCarsToolStripMenuItem // - shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; - shopsToolStripMenuItem.Size = new Size(180, 22); - shopsToolStripMenuItem.Text = "Shops"; - shopsToolStripMenuItem.Click += shopsToolStripMenuItem_Click; - // - // shopsSupplyToolStripMenuItem - // - shopsSupplyToolStripMenuItem.Name = "shopsSupplyToolStripMenuItem"; - shopsSupplyToolStripMenuItem.Size = new Size(180, 22); - shopsSupplyToolStripMenuItem.Text = "Shop's supply"; - shopsSupplyToolStripMenuItem.Click += shopsSupplyToolStripMenuItem_Click; + sellCarsToolStripMenuItem.Name = "sellCarsToolStripMenuItem"; + sellCarsToolStripMenuItem.Size = new Size(180, 22); + sellCarsToolStripMenuItem.Text = "Sell Cars"; + sellCarsToolStripMenuItem.Click += sellCarsToolStripMenuItem_Click; // // FormMain // @@ -183,5 +191,6 @@ private Button buttonRefresh; private ToolStripMenuItem shopsToolStripMenuItem; private ToolStripMenuItem shopsSupplyToolStripMenuItem; + private ToolStripMenuItem sellCarsToolStripMenuItem; } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormMain.cs b/AutomobilePlant/AutomobilePlantView/FormMain.cs index 21457ef..79fb19f 100644 --- a/AutomobilePlant/AutomobilePlantView/FormMain.cs +++ b/AutomobilePlant/AutomobilePlantView/FormMain.cs @@ -38,7 +38,6 @@ namespace AutomobilePlantView { dataGridView.DataSource = list; dataGridView.Columns["CarId"].Visible = false; - } _logger.LogInformation("Загрузка заказов"); } @@ -48,6 +47,8 @@ namespace AutomobilePlantView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + // управление менюшкой private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); @@ -64,6 +65,32 @@ namespace AutomobilePlantView form.ShowDialog(); } } + private void shopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void shopsSupplyToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply)); + if (service is FormShopSupply form) + { + form.ShowDialog(); + } + } + private void sellCarsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopSell)); + if (service is FormShopSell form) + { + form.ShowDialog(); + } + } + + // управление заказами private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); @@ -158,23 +185,6 @@ namespace AutomobilePlantView 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 shopsSupplyToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply)); - if (service is FormShopSupply form) - { - form.ShowDialog(); - } - } } } diff --git a/AutomobilePlant/AutomobilePlantView/FormShop.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormShop.Designer.cs index dbe21c2..21d05f3 100644 --- a/AutomobilePlant/AutomobilePlantView/FormShop.Designer.cs +++ b/AutomobilePlant/AutomobilePlantView/FormShop.Designer.cs @@ -40,26 +40,28 @@ IdCol = new DataGridViewTextBoxColumn(); CarCol = new DataGridViewTextBoxColumn(); CountCol = new DataGridViewTextBoxColumn(); + textBoxMaxCountCars = new TextBox(); + labelMaxCountCars = new Label(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // // textBoxName // - textBoxName.Location = new Point(100, 6); + textBoxName.Location = new Point(60, 6); textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(378, 23); + textBoxName.Size = new Size(418, 23); textBoxName.TabIndex = 0; // // textBoxAddress // - textBoxAddress.Location = new Point(100, 35); + textBoxAddress.Location = new Point(60, 35); textBoxAddress.Name = "textBoxAddress"; - textBoxAddress.Size = new Size(378, 23); + textBoxAddress.Size = new Size(418, 23); textBoxAddress.TabIndex = 1; // // openingDateTimePicker // - openingDateTimePicker.Location = new Point(100, 64); + openingDateTimePicker.Location = new Point(100, 93); openingDateTimePicker.Name = "openingDateTimePicker"; openingDateTimePicker.Size = new Size(378, 23); openingDateTimePicker.TabIndex = 3; @@ -85,7 +87,7 @@ // labelOpeningDate // labelOpeningDate.AutoSize = true; - labelOpeningDate.Location = new Point(12, 70); + labelOpeningDate.Location = new Point(12, 99); labelOpeningDate.Name = "labelOpeningDate"; labelOpeningDate.Size = new Size(82, 15); labelOpeningDate.TabIndex = 6; @@ -93,7 +95,7 @@ // // buttonSave // - buttonSave.Location = new Point(322, 334); + buttonSave.Location = new Point(322, 363); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(75, 23); buttonSave.TabIndex = 7; @@ -103,7 +105,7 @@ // // buttonCancel // - buttonCancel.Location = new Point(403, 334); + buttonCancel.Location = new Point(403, 363); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(75, 23); buttonCancel.TabIndex = 8; @@ -119,7 +121,7 @@ dataGridView.AllowUserToResizeRows = false; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Columns.AddRange(new DataGridViewColumn[] { IdCol, CarCol, CountCol }); - dataGridView.Location = new Point(12, 93); + dataGridView.Location = new Point(12, 122); dataGridView.Name = "dataGridView"; dataGridView.RowTemplate.Height = 25; dataGridView.Size = new Size(466, 235); @@ -142,11 +144,29 @@ CountCol.HeaderText = "Count"; CountCol.Name = "CountCol"; // + // textBoxMaxCountCars + // + textBoxMaxCountCars.Location = new Point(144, 64); + textBoxMaxCountCars.Name = "textBoxMaxCountCars"; + textBoxMaxCountCars.Size = new Size(334, 23); + textBoxMaxCountCars.TabIndex = 10; + // + // labelMaxCountCars + // + labelMaxCountCars.AutoSize = true; + labelMaxCountCars.Location = new Point(12, 67); + labelMaxCountCars.Name = "labelMaxCountCars"; + labelMaxCountCars.Size = new Size(126, 15); + labelMaxCountCars.TabIndex = 11; + labelMaxCountCars.Text = "Maximum cars' count:"; + // // FormShop // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(490, 369); + ClientSize = new Size(490, 396); + Controls.Add(labelMaxCountCars); + Controls.Add(textBoxMaxCountCars); Controls.Add(dataGridView); Controls.Add(buttonCancel); Controls.Add(buttonSave); @@ -157,7 +177,7 @@ Controls.Add(textBoxAddress); Controls.Add(textBoxName); Name = "FormShop"; - Text = "FormShop"; + Text = "Shop"; Load += FormShop_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); @@ -178,5 +198,7 @@ private DataGridViewTextBoxColumn IdCol; private DataGridViewTextBoxColumn CarCol; private DataGridViewTextBoxColumn CountCol; + private TextBox textBoxMaxCountCars; + private Label labelMaxCountCars; } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormShop.cs b/AutomobilePlant/AutomobilePlantView/FormShop.cs index cfcfaa6..bd97051 100644 --- a/AutomobilePlant/AutomobilePlantView/FormShop.cs +++ b/AutomobilePlant/AutomobilePlantView/FormShop.cs @@ -45,6 +45,7 @@ namespace AutomobilePlantView { textBoxName.Text = view.Name; textBoxAddress.Text = view.Address; + textBoxMaxCountCars.Text = view.MaxCountCars.ToString(); openingDateTimePicker.Value = view.OpeningDate; _shopCars = view.ShopCars ?? new Dictionary(); LoadData(); @@ -94,6 +95,12 @@ namespace AutomobilePlantView return; } + if (string.IsNullOrEmpty(textBoxMaxCountCars.Text)) + { + MessageBox.Show("Заполните макс. количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); try @@ -103,6 +110,7 @@ namespace AutomobilePlantView Id = _id ?? 0, Name = textBoxName.Text, Address = textBoxAddress.Text, + MaxCountCars = Convert.ToInt32(textBoxMaxCountCars.Text), OpeningDate = openingDateTimePicker.Value.Date, ShopCars = _shopCars }; diff --git a/AutomobilePlant/AutomobilePlantView/FormShop.resx b/AutomobilePlant/AutomobilePlantView/FormShop.resx index 8e413d1..118309e 100644 --- a/AutomobilePlant/AutomobilePlantView/FormShop.resx +++ b/AutomobilePlant/AutomobilePlantView/FormShop.resx @@ -126,13 +126,4 @@ True - - True - - - True - - - True - \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormShopSell.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormShopSell.Designer.cs new file mode 100644 index 0000000..14f9ed9 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormShopSell.Designer.cs @@ -0,0 +1,119 @@ +namespace AutomobilePlantView +{ + partial class FormShopSell + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelCar = new Label(); + labelCount = new Label(); + comboBoxCar = new ComboBox(); + textBoxCount = new TextBox(); + buttonCancel = new Button(); + buttonSell = new Button(); + SuspendLayout(); + // + // labelCar + // + labelCar.AutoSize = true; + labelCar.Location = new Point(12, 9); + labelCar.Name = "labelCar"; + labelCar.Size = new Size(28, 15); + labelCar.TabIndex = 0; + labelCar.Text = "Car:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 38); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(43, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Count:"; + // + // comboBoxCar + // + comboBoxCar.FormattingEnabled = true; + comboBoxCar.Location = new Point(61, 6); + comboBoxCar.Name = "comboBoxCar"; + comboBoxCar.Size = new Size(324, 23); + comboBoxCar.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(61, 35); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(324, 23); + textBoxCount.TabIndex = 3; + // + // buttonCancel + // + buttonCancel.Location = new Point(229, 64); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSell + // + buttonSell.Location = new Point(310, 64); + buttonSell.Name = "buttonSell"; + buttonSell.Size = new Size(75, 23); + buttonSell.TabIndex = 5; + buttonSell.Text = "Sell"; + buttonSell.UseVisualStyleBackColor = true; + buttonSell.Click += buttonSell_Click; + // + // FormShopSell + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(397, 93); + Controls.Add(buttonSell); + Controls.Add(buttonCancel); + Controls.Add(textBoxCount); + Controls.Add(comboBoxCar); + Controls.Add(labelCount); + Controls.Add(labelCar); + Name = "FormShopSell"; + Text = "Sell"; + Load += FormShopSell_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelCar; + private Label labelCount; + private ComboBox comboBoxCar; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSell; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormShopSell.cs b/AutomobilePlant/AutomobilePlantView/FormShopSell.cs new file mode 100644 index 0000000..5d0cd15 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormShopSell.cs @@ -0,0 +1,95 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AutomobilePlantView +{ + public partial class FormShopSell : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logicCar; + private readonly IShopLogic _logicShop; + + public FormShopSell(ILogger logger, ICarLogic logicCar, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicCar = logicCar; + _logicShop = logicShop; + } + + private void FormShopSell_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка авто для продажи"); + try + { + var list = _logicCar.ReadList(null); + if (list != null) + { + comboBoxCar.DisplayMember = "CarName"; + comboBoxCar.ValueMember = "Id"; + comboBoxCar.DataSource = list; + comboBoxCar.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка авто"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSell_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxCar.SelectedValue == null) + { + MessageBox.Show("Выберите авто", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание продажи"); + try + { + var operationResult = _logicShop.SellCar( + new CarBindingModel + { + Id = Convert.ToInt32(comboBoxCar.SelectedValue) + }, + Convert.ToInt32(textBoxCount.Text) + ); + if (!operationResult) + { + throw new Exception("Ошибка при создании продажи. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания продажи"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormShopSell.resx b/AutomobilePlant/AutomobilePlantView/FormShopSell.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormShopSell.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/Program.cs b/AutomobilePlant/AutomobilePlantView/Program.cs index 0f6e74d..eff8d71 100644 --- a/AutomobilePlant/AutomobilePlantView/Program.cs +++ b/AutomobilePlant/AutomobilePlantView/Program.cs @@ -52,6 +52,7 @@ namespace AutomobilePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file -- 2.25.1 From 619391572bde70efb8b9b39e1bc3ccd6af991733 Mon Sep 17 00:00:00 2001 From: Timourka Date: Mon, 26 Feb 2024 00:37:41 +0400 Subject: [PATCH 6/8] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B1=D1=8B=D0=BB=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutomobilePlant/AutomobilePlantView/FormShop.Designer.cs | 2 +- AutomobilePlant/AutomobilePlantView/FormShop.resx | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/AutomobilePlant/AutomobilePlantView/FormShop.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormShop.Designer.cs index dbe21c2..5bff31e 100644 --- a/AutomobilePlant/AutomobilePlantView/FormShop.Designer.cs +++ b/AutomobilePlant/AutomobilePlantView/FormShop.Designer.cs @@ -157,7 +157,7 @@ Controls.Add(textBoxAddress); Controls.Add(textBoxName); Name = "FormShop"; - Text = "FormShop"; + Text = "Shop"; Load += FormShop_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); diff --git a/AutomobilePlant/AutomobilePlantView/FormShop.resx b/AutomobilePlant/AutomobilePlantView/FormShop.resx index 8e413d1..118309e 100644 --- a/AutomobilePlant/AutomobilePlantView/FormShop.resx +++ b/AutomobilePlant/AutomobilePlantView/FormShop.resx @@ -126,13 +126,4 @@ True - - True - - - True - - - True - \ No newline at end of file -- 2.25.1 From 054c0232bf5b2b8d5b77c4339191b674378a14e1 Mon Sep 17 00:00:00 2001 From: Timourka Date: Mon, 26 Feb 2024 01:06:09 +0400 Subject: [PATCH 7/8] =?UTF-8?q?2C=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BE=D1=87?= =?UTF-8?q?=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs index 9af33ef..0c8aa1a 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs @@ -136,7 +136,7 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } - if (status == OrderStatus.Готов) + if (status == OrderStatus.Выдан) { var car = _carStorage.GetElement(new CarSearchModel() { Id = model.CarId }); if (car == null) -- 2.25.1 From 7841ed642e89bc3d3c2fb63f8d45092b9cb4fc8a Mon Sep 17 00:00:00 2001 From: Timourka Date: Mon, 26 Feb 2024 01:32:41 +0400 Subject: [PATCH 8/8] =?UTF-8?q?LC2=20=D0=BF=D0=BE=D1=87=D0=B8=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B1=D0=B0=D0=B3=D0=BE=D0=B2=D0=B8=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs | 3 ++- .../AutomobilePlantFileImplement/Implements/ShopStorage.cs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs index 97578c8..509d525 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ShopLogic.cs @@ -92,7 +92,7 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics foreach (var c in shopElement.ShopCars) countCars += c.Value.Item2; - if (countCars > shopElement.MaxCountCars - countCars) + if (count > shopElement.MaxCountCars - countCars) { _logger.LogWarning("Required shop will be overflowed"); return false; @@ -115,6 +115,7 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics Id = shopElement.Id, Name = shopElement.Name, Address = shopElement.Address, + MaxCountCars = shopElement.MaxCountCars, OpeningDate = shopElement.OpeningDate, ShopCars = shopElement.ShopCars }); diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Implements/ShopStorage.cs b/AutomobilePlant/AutomobilePlantFileImplement/Implements/ShopStorage.cs index a44e3d3..af31910 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/Implements/ShopStorage.cs +++ b/AutomobilePlant/AutomobilePlantFileImplement/Implements/ShopStorage.cs @@ -120,6 +120,7 @@ namespace AutomobilePlantFileImplement.Implements Id = shop.Id, Name = shop.Name, Address = shop.Address, + MaxCountCars = shop.MaxCountCars, OpeningDate = shop.OpeningDate, ShopCars = cars }); -- 2.25.1