From c335f2267abf98f69351d322fb24102e02acb57d Mon Sep 17 00:00:00 2001 From: K Date: Thu, 18 Apr 2024 21:10:02 +0300 Subject: [PATCH 1/7] lab1Hard --- .../BusinessLogic/ShopLogic.cs | 171 ++++++++++++++ .../BindingModels/ShopBindingModel.cs | 26 +++ .../BusinessLogicsContracts/IShopLogic.cs | 27 +++ .../SearchModels/ShopSearchModel.cs | 15 ++ .../StoragesContracts/IShopStorage.cs | 26 +++ .../ViewModels/ShopViewModel.cs | 30 +++ .../Models/IShopModel.cs | 19 ++ .../DataListSingleton.cs | 8 +- .../Implements/ShopStorage.cs | 114 +++++++++ .../Models/Shop.cs | 65 ++++++ .../PrecastConcretePlantView/FormMain.cs | 16 ++ .../FormShop.Designer.cs | 221 ++++++++++++++++++ .../PrecastConcretePlantView/FormShop.cs | 127 ++++++++++ .../PrecastConcretePlantView/FormShop.resx | 120 ++++++++++ .../FormShopRefill.Designer.cs | 145 ++++++++++++ .../FormShopRefill.cs | 126 ++++++++++ .../FormShopRefill.resx | 120 ++++++++++ 17 files changed, 1370 insertions(+), 6 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.resx diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..35ddc6b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -0,0 +1,171 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + + private readonly IShopStorage _shopStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName: {ShopName}. Id: {Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName: {ShopName}. Id: {Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool ReplenishShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count) + { + if (shopModel == null) + { + throw new ArgumentNullException(nameof(shopModel)); + } + if (reinforced == null) + { + throw new ArgumentNullException(nameof(reinforced)); + } + if (count <= 0) + { + throw new ArgumentException("В магазине должен быть хотя бы один товар", nameof(count)); + } + _logger.LogInformation("ReplenishShop(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); + var shop = _shopStorage.GetElement(shopModel); + if (shop == null) + { + _logger.LogWarning("ReplenishShop(GetElement). Element not found"); + return false; + } + if (shop.ShopReinforceds.ContainsKey(reinforced.Id)) + { + var shopR = shop.ShopReinforceds[reinforced.Id]; + shopR.Item2 += count; + shop.ShopReinforceds[reinforced.Id] = shopR; + _logger.LogInformation("ReplenishShop. Added {count} '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, + shop.ShopName); + } + else + { + shop.ShopReinforceds.Add(reinforced.Id, (reinforced, count)); + _logger.LogInformation("ReplenishShop. Added {count} new '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, + shop.ShopName); + } + if (_shopStorage.Update(new ShopBindingModel() + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpening = shop.DateOpening, + ShopReinforceds = shop.ShopReinforceds, + }) == null) + { + _logger.LogWarning("ReplenishShop. Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName)); + } + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Нет адреса магазина", nameof(model.Address)); + } + _logger.LogInformation("Shop. ShopName: {ShopName}. Address: {Address}. Id: {Id}", model.ShopName, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..b7d7bd5 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PrecastConcretePlantDataModels.Models; + +namespace PrecastConcretePlantContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ShopReinforceds + { + get; + set; + } = new(); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..624250e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,27 @@ +using PrecastConcretePlantContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; + +namespace PrecastConcretePlantContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + + ShopViewModel? ReadElement(ShopSearchModel model); + + bool Create(ShopBindingModel model); + + bool Update(ShopBindingModel model); + + bool Delete(ShopBindingModel model); + + bool ReplenishShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..9844954 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + + public string? ShopName { get; set; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..e6da5e5 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,26 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + + List GetFilteredList(ShopSearchModel model); + + ShopViewModel? GetElement(ShopSearchModel model); + + ShopViewModel? Insert(ShopBindingModel model); + + ShopViewModel? Update(ShopBindingModel model); + + ShopViewModel? Delete(ShopBindingModel model); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..7d3bc7f --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,30 @@ +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ShopReinforceds + { + get; + set; + } = new(); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..d315a48 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + + string Address { get; } + + DateTime DateOpening { get; } + + Dictionary ShopReinforceds { get; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs index 04a9ff5..0f98719 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs @@ -1,9 +1,4 @@ using PrecastConcretePlantListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace PrecastConcretePlantListImplement { @@ -13,11 +8,13 @@ namespace PrecastConcretePlantListImplement public List Components { get; set; } public List Orders { get; set; } public List Reinforceds { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Reinforceds = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { @@ -27,6 +24,5 @@ namespace PrecastConcretePlantListImplement } return _instance; } - } } diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..9c4e7a5 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs @@ -0,0 +1,114 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && + shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public 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/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs new file mode 100644 index 0000000..ad0ea97 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs @@ -0,0 +1,65 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + + public Dictionary ShopReinforceds + { + get; + private set; + } = new Dictionary(); + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + ShopReinforceds = model.ShopReinforceds + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + ShopReinforceds = model.ShopReinforceds; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + ShopReinforceds = ShopReinforceds + }; + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs index 6c6534f..7de9f87 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs @@ -63,6 +63,22 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenishment)); + if (service is FormShopReplenishment form) + { + form.ShowDialog(); + } + } private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs new file mode 100644 index 0000000..78f5a73 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs @@ -0,0 +1,221 @@ +namespace PrecastConcretePlantView +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + textBoxName = new TextBox(); + labelAddress = new Label(); + textBoxAddress = new TextBox(); + dateTimePicker = new DateTimePicker(); + labelOpeningDate = new Label(); + groupBoxReinforceds = new GroupBox(); + dataGridView = new DataGridView(); + buttonSave = new Button(); + buttonCancel = new Button(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + groupBoxReinforceds.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(16, 13); + labelName.Margin = new Padding(5, 0, 5, 0); + labelName.Name = "labelName"; + labelName.Size = new Size(84, 20); + labelName.TabIndex = 1; + labelName.Text = "Название :"; + // + // textBoxName + // + textBoxName.Location = new Point(105, 9); + textBoxName.Margin = new Padding(5, 4, 5, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(287, 27); + textBoxName.TabIndex = 2; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(16, 53); + labelAddress.Margin = new Padding(5, 0, 5, 0); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(58, 20); + labelAddress.TabIndex = 3; + labelAddress.Text = "Адрес :"; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(105, 49); + textBoxAddress.Margin = new Padding(5, 4, 5, 4); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(287, 27); + textBoxAddress.TabIndex = 4; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(144, 88); + dateTimePicker.Margin = new Padding(3, 4, 3, 4); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(249, 27); + dateTimePicker.TabIndex = 5; + // + // labelOpeningDate + // + labelOpeningDate.AutoSize = true; + labelOpeningDate.Location = new Point(16, 92); + labelOpeningDate.Margin = new Padding(5, 0, 5, 0); + labelOpeningDate.Name = "labelOpeningDate"; + labelOpeningDate.Size = new Size(117, 20); + labelOpeningDate.TabIndex = 6; + labelOpeningDate.Text = "Дата открытия :"; + // + // groupBoxReinforceds + // + groupBoxReinforceds.Controls.Add(dataGridView); + groupBoxReinforceds.Location = new Point(5, 133); + groupBoxReinforceds.Margin = new Padding(5, 4, 5, 4); + groupBoxReinforceds.Name = "groupBoxReinforceds"; + groupBoxReinforceds.Padding = new Padding(5, 4, 5, 4); + groupBoxReinforceds.Size = new Size(536, 384); + groupBoxReinforceds.TabIndex = 7; + groupBoxReinforceds.TabStop = false; + groupBoxReinforceds.Text = "Изделие"; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(5, 24); + dataGridView.Margin = new Padding(5, 4, 5, 4); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(522, 356); + dataGridView.TabIndex = 0; + // + // buttonSave + // + buttonSave.Location = new Point(291, 525); + buttonSave.Margin = new Padding(5, 4, 5, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(410, 525); + buttonCancel.Margin = new Padding(5, 4, 5, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + ColumnId.Width = 125; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Название изделия"; + ColumnName.MinimumWidth = 6; + ColumnName.Name = "ColumnName"; + ColumnName.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 125; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(546, 576); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxReinforceds); + Controls.Add(labelOpeningDate); + Controls.Add(dateTimePicker); + Controls.Add(textBoxAddress); + Controls.Add(labelAddress); + Controls.Add(textBoxName); + Controls.Add(labelName); + Margin = new Padding(3, 4, 3, 4); + Name = "FormShop"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Магазин"; + Load += FormShop_Load; + groupBoxReinforceds.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private Label labelAddress; + private TextBox textBoxAddress; + private DateTimePicker dateTimePicker; + private Label labelOpeningDate; + private GroupBox groupBoxReinforceds; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs new file mode 100644 index 0000000..ef06f7e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs @@ -0,0 +1,127 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantDataModels.Models; +using Microsoft.Extensions.Logging; +using PrecastConcretePlantListImplement.Models; +using System.Windows.Forms; + +namespace PrecastConcretePlantView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + private int? _id; + + private Dictionary _shopReinforceds; + + public int Id { set { _id = value; } } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopReinforceds = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Shop loading"); + try + { + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Value = view.DateOpening; + _shopReinforceds = view.ShopReinforceds ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Shop reinforceds loading"); + try + { + if (_shopReinforceds != null) + { + dataGridView.Rows.Clear(); + foreach (var reinforced in _shopReinforceds) + { + dataGridView.Rows.Add(new object[] { reinforced.Key, reinforced.Value.Item1.ReinforcedName, reinforced.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop reinforceds loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(dateTimePicker.Text)) + { + MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop saving"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value, + ShopReinforceds = _shopReinforceds + }; + 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, "Shop saving error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.Designer.cs new file mode 100644 index 0000000..1db9299 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.Designer.cs @@ -0,0 +1,145 @@ +namespace PrecastConcretePlantView +{ + partial class FormShopReplenishment + { + /// + /// 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() + { + labelShop = new Label(); + labelReinforced = new Label(); + labelCount = new Label(); + comboBoxShop = new ComboBox(); + comboBoxReinforced = new ComboBox(); + textBoxCount = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(27, 29); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(72, 20); + labelShop.TabIndex = 0; + labelShop.Text = "Магазин:"; + // + // labelReinforced + // + labelReinforced.AutoSize = true; + labelReinforced.Location = new Point(27, 73); + labelReinforced.Name = "labelReinforced"; + labelReinforced.Size = new Size(71, 20); + labelReinforced.TabIndex = 1; + labelReinforced.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(27, 118); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(93, 20); + labelCount.TabIndex = 2; + labelCount.Text = "Количество:"; + // + // comboBoxShop + // + comboBoxShop.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(136, 29); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(239, 28); + comboBoxShop.TabIndex = 3; + // + // comboBoxReinforced + // + comboBoxReinforced.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxReinforced.FormattingEnabled = true; + comboBoxReinforced.Location = new Point(136, 73); + comboBoxReinforced.Name = "comboBoxReinforced"; + comboBoxReinforced.Size = new Size(239, 28); + comboBoxReinforced.TabIndex = 4; + // + // textBoxCount + // + textBoxCount.Location = new Point(136, 118); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(239, 27); + textBoxCount.TabIndex = 5; + // + // buttonCancel + // + buttonCancel.Location = new Point(282, 162); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(93, 29); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(182, 162); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // FormShopReplenishment + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(422, 203); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxCount); + Controls.Add(comboBoxReinforced); + Controls.Add(comboBoxShop); + Controls.Add(labelCount); + Controls.Add(labelReinforced); + Controls.Add(labelShop); + Name = "FormShopRefill"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Пополнение магазина"; + Load += FormShopReplenishment_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelShop; + private Label labelReinforced; + private Label labelCount; + private ComboBox comboBoxShop; + private ComboBox comboBoxReinforced; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs new file mode 100644 index 0000000..8a7ea68 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs @@ -0,0 +1,126 @@ +using Microsoft.Extensions.Logging; + +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PrecastConcretePlantView +{ + public partial class FormShopReplenishment : Form + { + private readonly ILogger _logger; + + private readonly IReinforcedLogic _logicReinforced; + + private readonly IShopLogic _logicShop; + + public FormShopReplenishment(ILogger logger, IReinforcedLogic logicReinforced, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicReinforced = logicReinforced; + _logicShop = logicShop; + } + + private void FormShopReplenishment_Load(object sender, EventArgs e) + { + _logger.LogInformation("Reinforceds loading"); + try + { + var list = _logicReinforced.ReadList(null); + if (list != null) + { + comboBoxReinforced.DisplayMember = "ReinforcedName"; + comboBoxReinforced.ValueMember = "Id"; + comboBoxReinforced.DataSource = list; + comboBoxReinforced.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Reinforceds loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + _logger.LogInformation("Shops loading"); + try + { + var list = _logicShop.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxReinforced.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop replenishment"); + try + { + var reinforced = _logicReinforced.ReadElement(new ReinforcedSearchModel + { Id = Convert.ToInt32(comboBoxReinforced.SelectedValue) }); + if (reinforced == null) + { + throw new Exception("Изделие не найдено."); + } + var operationResult = _logicShop.ReplenishShop(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }, + reinforced, 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, "Shop replenishment error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.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 From b9e4c4c59db184a4e6fa2121da4b76fceebf1b78 Mon Sep 17 00:00:00 2001 From: K Date: Thu, 18 Apr 2024 21:17:24 +0300 Subject: [PATCH 2/7] Revert "lab1Hard" This reverts commit c335f2267abf98f69351d322fb24102e02acb57d. --- .../BusinessLogic/ShopLogic.cs | 171 -------------- .../BindingModels/ShopBindingModel.cs | 26 --- .../BusinessLogicsContracts/IShopLogic.cs | 27 --- .../SearchModels/ShopSearchModel.cs | 15 -- .../StoragesContracts/IShopStorage.cs | 26 --- .../ViewModels/ShopViewModel.cs | 30 --- .../Models/IShopModel.cs | 19 -- .../DataListSingleton.cs | 8 +- .../Implements/ShopStorage.cs | 114 --------- .../Models/Shop.cs | 65 ------ .../PrecastConcretePlantView/FormMain.cs | 16 -- .../FormShop.Designer.cs | 221 ------------------ .../PrecastConcretePlantView/FormShop.cs | 127 ---------- .../PrecastConcretePlantView/FormShop.resx | 120 ---------- .../FormShopRefill.Designer.cs | 145 ------------ .../FormShopRefill.cs | 126 ---------- .../FormShopRefill.resx | 120 ---------- 17 files changed, 6 insertions(+), 1370 deletions(-) delete mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx delete mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.Designer.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs delete mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.resx diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs deleted file mode 100644 index 35ddc6b..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs +++ /dev/null @@ -1,171 +0,0 @@ -using Microsoft.Extensions.Logging; -using PrecastConcretePlantContracts.BindingModels; -using PrecastConcretePlantContracts.BusinessLogicsContracts; -using PrecastConcretePlantContracts.SearchModels; -using PrecastConcretePlantContracts.StoragesContracts; -using PrecastConcretePlantContracts.ViewModels; -using PrecastConcretePlantDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PrecastConcretePlantBusinessLogic.BusinessLogics -{ - public class ShopLogic : IShopLogic - { - private readonly ILogger _logger; - - private readonly IShopStorage _shopStorage; - - public ShopLogic(ILogger logger, IShopStorage shopStorage) - { - _logger = logger; - _shopStorage = shopStorage; - } - - public List? ReadList(ShopSearchModel? model) - { - _logger.LogInformation("ReadList. ShopName: {ShopName}. Id: {Id}", model?.ShopName, model?.Id); - var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count: {Count}", list.Count); - return list; - } - - public ShopViewModel? ReadElement(ShopSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. ShopName: {ShopName}. Id: {Id}", model.ShopName, model.Id); - var element = _shopStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); - return element; - } - - public bool Create(ShopBindingModel model) - { - CheckModel(model); - if (_shopStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - - public bool Update(ShopBindingModel model) - { - CheckModel(model); - if (_shopStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - - public bool Delete(ShopBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id: {Id}", model.Id); - if (_shopStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - - public bool ReplenishShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count) - { - if (shopModel == null) - { - throw new ArgumentNullException(nameof(shopModel)); - } - if (reinforced == null) - { - throw new ArgumentNullException(nameof(reinforced)); - } - if (count <= 0) - { - throw new ArgumentException("В магазине должен быть хотя бы один товар", nameof(count)); - } - _logger.LogInformation("ReplenishShop(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); - var shop = _shopStorage.GetElement(shopModel); - if (shop == null) - { - _logger.LogWarning("ReplenishShop(GetElement). Element not found"); - return false; - } - if (shop.ShopReinforceds.ContainsKey(reinforced.Id)) - { - var shopR = shop.ShopReinforceds[reinforced.Id]; - shopR.Item2 += count; - shop.ShopReinforceds[reinforced.Id] = shopR; - _logger.LogInformation("ReplenishShop. Added {count} '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, - shop.ShopName); - } - else - { - shop.ShopReinforceds.Add(reinforced.Id, (reinforced, count)); - _logger.LogInformation("ReplenishShop. Added {count} new '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, - shop.ShopName); - } - if (_shopStorage.Update(new ShopBindingModel() - { - Id = shop.Id, - ShopName = shop.ShopName, - Address = shop.Address, - DateOpening = shop.DateOpening, - ShopReinforceds = shop.ShopReinforceds, - }) == null) - { - _logger.LogWarning("ReplenishShop. Update operation failed"); - return false; - } - return true; - } - - private void CheckModel(ShopBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.ShopName)) - { - throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName)); - } - if (string.IsNullOrEmpty(model.Address)) - { - throw new ArgumentNullException("Нет адреса магазина", nameof(model.Address)); - } - _logger.LogInformation("Shop. ShopName: {ShopName}. Address: {Address}. Id: {Id}", model.ShopName, model.Address, model.Id); - var element = _shopStorage.GetElement(new ShopSearchModel - { - ShopName = model.ShopName - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Магазин с таким названием уже есть"); - } - } - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs deleted file mode 100644 index b7d7bd5..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using PrecastConcretePlantDataModels.Models; - -namespace PrecastConcretePlantContracts.BindingModels -{ - public class ShopBindingModel : IShopModel - { - public int Id { get; set; } - - public string ShopName { get; set; } = string.Empty; - - public string Address { get; set; } = string.Empty; - - public DateTime DateOpening { get; set; } = DateTime.Now; - - public Dictionary ShopReinforceds - { - get; - set; - } = new(); - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs deleted file mode 100644 index 624250e..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ /dev/null @@ -1,27 +0,0 @@ -using PrecastConcretePlantContracts.BindingModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using PrecastConcretePlantContracts.SearchModels; -using PrecastConcretePlantContracts.ViewModels; -using PrecastConcretePlantDataModels.Models; - -namespace PrecastConcretePlantContracts.BusinessLogicsContracts -{ - public interface IShopLogic - { - List? ReadList(ShopSearchModel? model); - - ShopViewModel? ReadElement(ShopSearchModel model); - - bool Create(ShopBindingModel model); - - bool Update(ShopBindingModel model); - - bool Delete(ShopBindingModel model); - - bool ReplenishShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count); - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs deleted file mode 100644 index 9844954..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PrecastConcretePlantContracts.SearchModels -{ - public class ShopSearchModel - { - public int? Id { get; set; } - - public string? ShopName { get; set; } - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs deleted file mode 100644 index e6da5e5..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs +++ /dev/null @@ -1,26 +0,0 @@ -using PrecastConcretePlantContracts.BindingModels; -using PrecastConcretePlantContracts.SearchModels; -using PrecastConcretePlantContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PrecastConcretePlantContracts.StoragesContracts -{ - public interface IShopStorage - { - List GetFullList(); - - List GetFilteredList(ShopSearchModel model); - - ShopViewModel? GetElement(ShopSearchModel model); - - ShopViewModel? Insert(ShopBindingModel model); - - ShopViewModel? Update(ShopBindingModel model); - - ShopViewModel? Delete(ShopBindingModel model); - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs deleted file mode 100644 index 7d3bc7f..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs +++ /dev/null @@ -1,30 +0,0 @@ -using PrecastConcretePlantDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PrecastConcretePlantContracts.ViewModels -{ - public class ShopViewModel : IShopModel - { - public int Id { get; set; } - - [DisplayName("Название магазина")] - public string ShopName { get; set; } = string.Empty; - - [DisplayName("Адрес")] - public string Address { get; set; } = string.Empty; - - [DisplayName("Дата открытия")] - public DateTime DateOpening { get; set; } = DateTime.Now; - - public Dictionary ShopReinforceds - { - get; - set; - } = new(); - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs deleted file mode 100644 index d315a48..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PrecastConcretePlantDataModels.Models -{ - public interface IShopModel : IId - { - string ShopName { get; } - - string Address { get; } - - DateTime DateOpening { get; } - - Dictionary ShopReinforceds { get; } - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs index 0f98719..04a9ff5 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs @@ -1,4 +1,9 @@ using PrecastConcretePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace PrecastConcretePlantListImplement { @@ -8,13 +13,11 @@ namespace PrecastConcretePlantListImplement public List Components { get; set; } public List Orders { get; set; } public List Reinforceds { get; set; } - public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Reinforceds = new List(); - Shops = new List(); } public static DataListSingleton GetInstance() { @@ -24,5 +27,6 @@ namespace PrecastConcretePlantListImplement } return _instance; } + } } diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs deleted file mode 100644 index 9c4e7a5..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs +++ /dev/null @@ -1,114 +0,0 @@ -using PrecastConcretePlantContracts.BindingModels; -using PrecastConcretePlantContracts.SearchModels; -using PrecastConcretePlantContracts.StoragesContracts; -using PrecastConcretePlantContracts.ViewModels; -using PrecastConcretePlantListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PrecastConcretePlantListImplement.Implements -{ - public class ShopStorage : IShopStorage - { - private readonly DataListSingleton _source; - - public ShopStorage() - { - _source = DataListSingleton.GetInstance(); - } - - public List GetFullList() - { - var result = new List(); - foreach (var shop in _source.Shops) - { - result.Add(shop.GetViewModel); - } - return result; - } - - public List GetFilteredList(ShopSearchModel model) - { - var result = new List(); - if (string.IsNullOrEmpty(model.ShopName)) - { - return result; - } - foreach (var shop in _source.Shops) - { - if (shop.ShopName.Contains(model.ShopName)) - { - result.Add(shop.GetViewModel); - } - } - return result; - } - - public ShopViewModel? GetElement(ShopSearchModel model) - { - if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) - { - return null; - } - foreach (var shop in _source.Shops) - { - if ((!string.IsNullOrEmpty(model.ShopName) && - shop.ShopName == model.ShopName) || - (model.Id.HasValue && shop.Id == model.Id)) - { - return shop.GetViewModel; - } - } - return null; - } - - public 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/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs deleted file mode 100644 index ad0ea97..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs +++ /dev/null @@ -1,65 +0,0 @@ -using PrecastConcretePlantContracts.BindingModels; -using PrecastConcretePlantContracts.ViewModels; -using PrecastConcretePlantDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PrecastConcretePlantListImplement.Models -{ - public class Shop : IShopModel - { - public int Id { get; private set; } - - public string ShopName { get; private set; } = string.Empty; - - public string Address { get; private set; } = string.Empty; - - public DateTime DateOpening { get; private set; } - - public Dictionary ShopReinforceds - { - get; - private set; - } = new Dictionary(); - - public static Shop? Create(ShopBindingModel? model) - { - if (model == null) - { - return null; - } - return new Shop() - { - Id = model.Id, - ShopName = model.ShopName, - Address = model.Address, - DateOpening = model.DateOpening, - ShopReinforceds = model.ShopReinforceds - }; - } - - public void Update(ShopBindingModel? model) - { - if (model == null) - { - return; - } - ShopName = model.ShopName; - Address = model.Address; - DateOpening = model.DateOpening; - ShopReinforceds = model.ShopReinforceds; - } - - public ShopViewModel GetViewModel => new() - { - Id = Id, - ShopName = ShopName, - Address = Address, - DateOpening = DateOpening, - ShopReinforceds = ShopReinforceds - }; - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs index 7de9f87..6c6534f 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs @@ -63,22 +63,6 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } - private void ToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if (service is FormShops form) - { - form.ShowDialog(); - } - } - private void ToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenishment)); - if (service is FormShopReplenishment form) - { - form.ShowDialog(); - } - } private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs deleted file mode 100644 index 78f5a73..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs +++ /dev/null @@ -1,221 +0,0 @@ -namespace PrecastConcretePlantView -{ - partial class FormShop - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - labelName = new Label(); - textBoxName = new TextBox(); - labelAddress = new Label(); - textBoxAddress = new TextBox(); - dateTimePicker = new DateTimePicker(); - labelOpeningDate = new Label(); - groupBoxReinforceds = new GroupBox(); - dataGridView = new DataGridView(); - buttonSave = new Button(); - buttonCancel = new Button(); - ColumnId = new DataGridViewTextBoxColumn(); - ColumnName = new DataGridViewTextBoxColumn(); - ColumnCount = new DataGridViewTextBoxColumn(); - groupBoxReinforceds.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(16, 13); - labelName.Margin = new Padding(5, 0, 5, 0); - labelName.Name = "labelName"; - labelName.Size = new Size(84, 20); - labelName.TabIndex = 1; - labelName.Text = "Название :"; - // - // textBoxName - // - textBoxName.Location = new Point(105, 9); - textBoxName.Margin = new Padding(5, 4, 5, 4); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(287, 27); - textBoxName.TabIndex = 2; - // - // labelAddress - // - labelAddress.AutoSize = true; - labelAddress.Location = new Point(16, 53); - labelAddress.Margin = new Padding(5, 0, 5, 0); - labelAddress.Name = "labelAddress"; - labelAddress.Size = new Size(58, 20); - labelAddress.TabIndex = 3; - labelAddress.Text = "Адрес :"; - // - // textBoxAddress - // - textBoxAddress.Location = new Point(105, 49); - textBoxAddress.Margin = new Padding(5, 4, 5, 4); - textBoxAddress.Name = "textBoxAddress"; - textBoxAddress.Size = new Size(287, 27); - textBoxAddress.TabIndex = 4; - // - // dateTimePicker - // - dateTimePicker.Location = new Point(144, 88); - dateTimePicker.Margin = new Padding(3, 4, 3, 4); - dateTimePicker.Name = "dateTimePicker"; - dateTimePicker.Size = new Size(249, 27); - dateTimePicker.TabIndex = 5; - // - // labelOpeningDate - // - labelOpeningDate.AutoSize = true; - labelOpeningDate.Location = new Point(16, 92); - labelOpeningDate.Margin = new Padding(5, 0, 5, 0); - labelOpeningDate.Name = "labelOpeningDate"; - labelOpeningDate.Size = new Size(117, 20); - labelOpeningDate.TabIndex = 6; - labelOpeningDate.Text = "Дата открытия :"; - // - // groupBoxReinforceds - // - groupBoxReinforceds.Controls.Add(dataGridView); - groupBoxReinforceds.Location = new Point(5, 133); - groupBoxReinforceds.Margin = new Padding(5, 4, 5, 4); - groupBoxReinforceds.Name = "groupBoxReinforceds"; - groupBoxReinforceds.Padding = new Padding(5, 4, 5, 4); - groupBoxReinforceds.Size = new Size(536, 384); - groupBoxReinforceds.TabIndex = 7; - groupBoxReinforceds.TabStop = false; - groupBoxReinforceds.Text = "Изделие"; - // - // dataGridView - // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.BackgroundColor = SystemColors.ControlLightLight; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); - dataGridView.Dock = DockStyle.Left; - dataGridView.Location = new Point(5, 24); - dataGridView.Margin = new Padding(5, 4, 5, 4); - dataGridView.MultiSelect = false; - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersVisible = false; - dataGridView.RowHeadersWidth = 51; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(522, 356); - dataGridView.TabIndex = 0; - // - // buttonSave - // - buttonSave.Location = new Point(291, 525); - buttonSave.Margin = new Padding(5, 4, 5, 4); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(101, 36); - buttonSave.TabIndex = 8; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; - // - // buttonCancel - // - buttonCancel.Location = new Point(410, 525); - buttonCancel.Margin = new Padding(5, 4, 5, 4); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(101, 36); - buttonCancel.TabIndex = 9; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; - // - // ColumnId - // - ColumnId.HeaderText = "Id"; - ColumnId.MinimumWidth = 6; - ColumnId.Name = "ColumnId"; - ColumnId.ReadOnly = true; - ColumnId.Visible = false; - ColumnId.Width = 125; - // - // ColumnName - // - ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - ColumnName.HeaderText = "Название изделия"; - ColumnName.MinimumWidth = 6; - ColumnName.Name = "ColumnName"; - ColumnName.ReadOnly = true; - // - // ColumnCount - // - ColumnCount.HeaderText = "Количество"; - ColumnCount.MinimumWidth = 6; - ColumnCount.Name = "ColumnCount"; - ColumnCount.ReadOnly = true; - ColumnCount.Width = 125; - // - // FormShop - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(546, 576); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(groupBoxReinforceds); - Controls.Add(labelOpeningDate); - Controls.Add(dateTimePicker); - Controls.Add(textBoxAddress); - Controls.Add(labelAddress); - Controls.Add(textBoxName); - Controls.Add(labelName); - Margin = new Padding(3, 4, 3, 4); - Name = "FormShop"; - StartPosition = FormStartPosition.CenterScreen; - Text = "Магазин"; - Load += FormShop_Load; - groupBoxReinforceds.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Label labelName; - private TextBox textBoxName; - private Label labelAddress; - private TextBox textBoxAddress; - private DateTimePicker dateTimePicker; - private Label labelOpeningDate; - private GroupBox groupBoxReinforceds; - private DataGridView dataGridView; - private Button buttonSave; - private Button buttonCancel; - private DataGridViewTextBoxColumn ColumnId; - private DataGridViewTextBoxColumn ColumnName; - private DataGridViewTextBoxColumn ColumnCount; - } -} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs deleted file mode 100644 index ef06f7e..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs +++ /dev/null @@ -1,127 +0,0 @@ -using PrecastConcretePlantContracts.BindingModels; -using PrecastConcretePlantContracts.BusinessLogicsContracts; -using PrecastConcretePlantContracts.SearchModels; -using PrecastConcretePlantDataModels.Models; -using Microsoft.Extensions.Logging; -using PrecastConcretePlantListImplement.Models; -using System.Windows.Forms; - -namespace PrecastConcretePlantView -{ - public partial class FormShop : Form - { - private readonly ILogger _logger; - - private readonly IShopLogic _logic; - - private int? _id; - - private Dictionary _shopReinforceds; - - public int Id { set { _id = value; } } - - public FormShop(ILogger logger, IShopLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - _shopReinforceds = new Dictionary(); - } - - private void FormShop_Load(object sender, EventArgs e) - { - if (_id.HasValue) - { - _logger.LogInformation("Shop loading"); - try - { - var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); - if (view != null) - { - textBoxName.Text = view.ShopName; - textBoxAddress.Text = view.Address; - dateTimePicker.Value = view.DateOpening; - _shopReinforceds = view.ShopReinforceds ?? new Dictionary(); - LoadData(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Shop loading error"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - - private void LoadData() - { - _logger.LogInformation("Shop reinforceds loading"); - try - { - if (_shopReinforceds != null) - { - dataGridView.Rows.Clear(); - foreach (var reinforced in _shopReinforceds) - { - dataGridView.Rows.Add(new object[] { reinforced.Key, reinforced.Value.Item1.ReinforcedName, reinforced.Value.Item2 }); - } - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Shop reinforceds loading error"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void ButtonSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxName.Text)) - { - MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (string.IsNullOrEmpty(textBoxAddress.Text)) - { - MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (string.IsNullOrEmpty(dateTimePicker.Text)) - { - MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Shop saving"); - try - { - var model = new ShopBindingModel - { - Id = _id ?? 0, - ShopName = textBoxName.Text, - Address = textBoxAddress.Text, - DateOpening = dateTimePicker.Value, - ShopReinforceds = _shopReinforceds - }; - 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, "Shop saving error"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void ButtonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } -} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx deleted file mode 100644 index 1af7de1..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.Designer.cs deleted file mode 100644 index 1db9299..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.Designer.cs +++ /dev/null @@ -1,145 +0,0 @@ -namespace PrecastConcretePlantView -{ - partial class FormShopReplenishment - { - /// - /// 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() - { - labelShop = new Label(); - labelReinforced = new Label(); - labelCount = new Label(); - comboBoxShop = new ComboBox(); - comboBoxReinforced = new ComboBox(); - textBoxCount = new TextBox(); - buttonCancel = new Button(); - buttonSave = new Button(); - SuspendLayout(); - // - // labelShop - // - labelShop.AutoSize = true; - labelShop.Location = new Point(27, 29); - labelShop.Name = "labelShop"; - labelShop.Size = new Size(72, 20); - labelShop.TabIndex = 0; - labelShop.Text = "Магазин:"; - // - // labelReinforced - // - labelReinforced.AutoSize = true; - labelReinforced.Location = new Point(27, 73); - labelReinforced.Name = "labelReinforced"; - labelReinforced.Size = new Size(71, 20); - labelReinforced.TabIndex = 1; - labelReinforced.Text = "Изделие:"; - // - // labelCount - // - labelCount.AutoSize = true; - labelCount.Location = new Point(27, 118); - labelCount.Name = "labelCount"; - labelCount.Size = new Size(93, 20); - labelCount.TabIndex = 2; - labelCount.Text = "Количество:"; - // - // comboBoxShop - // - comboBoxShop.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxShop.FormattingEnabled = true; - comboBoxShop.Location = new Point(136, 29); - comboBoxShop.Name = "comboBoxShop"; - comboBoxShop.Size = new Size(239, 28); - comboBoxShop.TabIndex = 3; - // - // comboBoxReinforced - // - comboBoxReinforced.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxReinforced.FormattingEnabled = true; - comboBoxReinforced.Location = new Point(136, 73); - comboBoxReinforced.Name = "comboBoxReinforced"; - comboBoxReinforced.Size = new Size(239, 28); - comboBoxReinforced.TabIndex = 4; - // - // textBoxCount - // - textBoxCount.Location = new Point(136, 118); - textBoxCount.Name = "textBoxCount"; - textBoxCount.Size = new Size(239, 27); - textBoxCount.TabIndex = 5; - // - // buttonCancel - // - buttonCancel.Location = new Point(282, 162); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(93, 29); - buttonCancel.TabIndex = 6; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; - // - // buttonSave - // - buttonSave.Location = new Point(182, 162); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(94, 29); - buttonSave.TabIndex = 7; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; - // - // FormShopReplenishment - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(422, 203); - Controls.Add(buttonSave); - Controls.Add(buttonCancel); - Controls.Add(textBoxCount); - Controls.Add(comboBoxReinforced); - Controls.Add(comboBoxShop); - Controls.Add(labelCount); - Controls.Add(labelReinforced); - Controls.Add(labelShop); - Name = "FormShopRefill"; - StartPosition = FormStartPosition.CenterScreen; - Text = "Пополнение магазина"; - Load += FormShopReplenishment_Load; - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Label labelShop; - private Label labelReinforced; - private Label labelCount; - private ComboBox comboBoxShop; - private ComboBox comboBoxReinforced; - private TextBox textBoxCount; - private Button buttonCancel; - private Button buttonSave; - } -} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs deleted file mode 100644 index 8a7ea68..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs +++ /dev/null @@ -1,126 +0,0 @@ -using Microsoft.Extensions.Logging; - -using PrecastConcretePlantContracts.BusinessLogicsContracts; -using PrecastConcretePlantContracts.SearchModels; -using PrecastConcretePlantListImplement.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace PrecastConcretePlantView -{ - public partial class FormShopReplenishment : Form - { - private readonly ILogger _logger; - - private readonly IReinforcedLogic _logicReinforced; - - private readonly IShopLogic _logicShop; - - public FormShopReplenishment(ILogger logger, IReinforcedLogic logicReinforced, IShopLogic logicShop) - { - InitializeComponent(); - _logger = logger; - _logicReinforced = logicReinforced; - _logicShop = logicShop; - } - - private void FormShopReplenishment_Load(object sender, EventArgs e) - { - _logger.LogInformation("Reinforceds loading"); - try - { - var list = _logicReinforced.ReadList(null); - if (list != null) - { - comboBoxReinforced.DisplayMember = "ReinforcedName"; - comboBoxReinforced.ValueMember = "Id"; - comboBoxReinforced.DataSource = list; - comboBoxReinforced.SelectedItem = null; - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Reinforceds loading error"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - _logger.LogInformation("Shops loading"); - try - { - var list = _logicShop.ReadList(null); - if (list != null) - { - comboBoxShop.DisplayMember = "ShopName"; - comboBoxShop.ValueMember = "Id"; - comboBoxShop.DataSource = list; - comboBoxShop.SelectedItem = null; - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Shops loading error"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void ButtonSave_Click(object sender, EventArgs e) - { - if (comboBoxShop.SelectedValue == null) - { - MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (comboBoxReinforced.SelectedValue == null) - { - MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (string.IsNullOrEmpty(textBoxCount.Text)) - { - MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Shop replenishment"); - try - { - var reinforced = _logicReinforced.ReadElement(new ReinforcedSearchModel - { Id = Convert.ToInt32(comboBoxReinforced.SelectedValue) }); - if (reinforced == null) - { - throw new Exception("Изделие не найдено."); - } - var operationResult = _logicShop.ReplenishShop(new ShopSearchModel - { - Id = Convert.ToInt32(comboBoxShop.SelectedValue) - }, - reinforced, 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, "Shop replenishment error"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - DialogResult = DialogResult.OK; - Close(); - } - - private void ButtonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.resx deleted file mode 100644 index 1af7de1..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 From 066f2f0b262676bbcd492f43cd1f020b92e3aee4 Mon Sep 17 00:00:00 2001 From: K Date: Thu, 18 Apr 2024 22:41:30 +0300 Subject: [PATCH 3/7] lab1Hard --- .../BusinessLogic/ShopLogic.cs | 171 ++++++++++++++ .../BindingModels/ShopBindingModel.cs | 26 +++ .../BusinessLogicsContracts/IShopLogic.cs | 27 +++ .../SearchModels/ShopSearchModel.cs | 15 ++ .../StoragesContracts/IShopStorage.cs | 26 +++ .../ViewModels/ShopViewModel.cs | 30 +++ .../Models/IShopModel.cs | 19 ++ .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 114 +++++++++ .../Models/Shop.cs | 65 ++++++ .../FormMain.Designer.cs | 26 ++- .../PrecastConcretePlantView/FormMain.cs | 16 ++ .../FormShop.Designer.cs | 221 ++++++++++++++++++ .../PrecastConcretePlantView/FormShop.cs | 127 ++++++++++ .../PrecastConcretePlantView/FormShop.resx | 120 ++++++++++ .../FormShopRefill.Designer.cs | 145 ++++++++++++ .../FormShopRefill.cs | 126 ++++++++++ .../FormShopRefill.resx | 120 ++++++++++ .../PrecastConcretePlantView/FormShopS.cs | 105 +++++++++ .../FormShops.Designer.cs | 126 ++++++++++ .../PrecastConcretePlantView/FormShops.resx | 120 ++++++++++ .../PrecastConcretePlantView.csproj | 1 + .../PrecastConcretePlantView/Program.cs | 5 + 23 files changed, 1749 insertions(+), 4 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShopS.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShops.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShops.resx diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..35ddc6b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -0,0 +1,171 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + + private readonly IShopStorage _shopStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName: {ShopName}. Id: {Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName: {ShopName}. Id: {Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool ReplenishShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count) + { + if (shopModel == null) + { + throw new ArgumentNullException(nameof(shopModel)); + } + if (reinforced == null) + { + throw new ArgumentNullException(nameof(reinforced)); + } + if (count <= 0) + { + throw new ArgumentException("В магазине должен быть хотя бы один товар", nameof(count)); + } + _logger.LogInformation("ReplenishShop(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); + var shop = _shopStorage.GetElement(shopModel); + if (shop == null) + { + _logger.LogWarning("ReplenishShop(GetElement). Element not found"); + return false; + } + if (shop.ShopReinforceds.ContainsKey(reinforced.Id)) + { + var shopR = shop.ShopReinforceds[reinforced.Id]; + shopR.Item2 += count; + shop.ShopReinforceds[reinforced.Id] = shopR; + _logger.LogInformation("ReplenishShop. Added {count} '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, + shop.ShopName); + } + else + { + shop.ShopReinforceds.Add(reinforced.Id, (reinforced, count)); + _logger.LogInformation("ReplenishShop. Added {count} new '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, + shop.ShopName); + } + if (_shopStorage.Update(new ShopBindingModel() + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpening = shop.DateOpening, + ShopReinforceds = shop.ShopReinforceds, + }) == null) + { + _logger.LogWarning("ReplenishShop. Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName)); + } + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Нет адреса магазина", nameof(model.Address)); + } + _logger.LogInformation("Shop. ShopName: {ShopName}. Address: {Address}. Id: {Id}", model.ShopName, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..b7d7bd5 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PrecastConcretePlantDataModels.Models; + +namespace PrecastConcretePlantContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ShopReinforceds + { + get; + set; + } = new(); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..624250e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,27 @@ +using PrecastConcretePlantContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; + +namespace PrecastConcretePlantContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + + ShopViewModel? ReadElement(ShopSearchModel model); + + bool Create(ShopBindingModel model); + + bool Update(ShopBindingModel model); + + bool Delete(ShopBindingModel model); + + bool ReplenishShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..9844954 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + + public string? ShopName { get; set; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..e6da5e5 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,26 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + + List GetFilteredList(ShopSearchModel model); + + ShopViewModel? GetElement(ShopSearchModel model); + + ShopViewModel? Insert(ShopBindingModel model); + + ShopViewModel? Update(ShopBindingModel model); + + ShopViewModel? Delete(ShopBindingModel model); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..7d3bc7f --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,30 @@ +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ShopReinforceds + { + get; + set; + } = new(); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..d315a48 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + + string Address { get; } + + DateTime DateOpening { get; } + + Dictionary ShopReinforceds { get; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs index 04a9ff5..a8879b8 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace PrecastConcretePlantListImplement public List Components { get; set; } public List Orders { get; set; } public List Reinforceds { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Reinforceds = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..9c4e7a5 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs @@ -0,0 +1,114 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && + shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public 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/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs new file mode 100644 index 0000000..ad0ea97 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs @@ -0,0 +1,65 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + + public Dictionary ShopReinforceds + { + get; + private set; + } = new Dictionary(); + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + ShopReinforceds = model.ShopReinforceds + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + ShopReinforceds = model.ShopReinforceds; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + ShopReinforceds = ShopReinforceds + }; + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs index 760d5b2..4f2a32a 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs @@ -38,6 +38,8 @@ buttonTakeOrderInWork = new Button(); buttonCreateOrder = new Button(); dataGridView = new DataGridView(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -45,7 +47,7 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem, пополнениеМагазинаToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Padding = new Padding(6, 3, 0, 3); @@ -55,7 +57,7 @@ // // справочникToolStripMenuItem // - справочникToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem }); + справочникToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, магазиныToolStripMenuItem }); справочникToolStripMenuItem.Name = "справочникToolStripMenuItem"; справочникToolStripMenuItem.Size = new Size(117, 24); справочникToolStripMenuItem.Text = "Справочники"; @@ -63,14 +65,14 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(182, 26); + компонентыToolStripMenuItem.Size = new Size(224, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; // // изделияToolStripMenuItem // изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - изделияToolStripMenuItem.Size = new Size(182, 26); + изделияToolStripMenuItem.Size = new Size(224, 26); изделияToolStripMenuItem.Text = "Изделия"; изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; // @@ -134,6 +136,20 @@ dataGridView.Size = new Size(925, 374); dataGridView.TabIndex = 18; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click; + // + // пополнениеМагазинаToolStripMenuItem + // + пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24); + пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + пополнениеМагазинаToolStripMenuItem.Click += ПополнениеМагазинаToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -169,5 +185,7 @@ private Button buttonTakeOrderInWork; private Button buttonCreateOrder; private DataGridView dataGridView; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs index 6c6534f..9486b04 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs @@ -63,6 +63,22 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopRefill)); + if (service is FormShopRefill form) + { + form.ShowDialog(); + } + } private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs new file mode 100644 index 0000000..78f5a73 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs @@ -0,0 +1,221 @@ +namespace PrecastConcretePlantView +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + textBoxName = new TextBox(); + labelAddress = new Label(); + textBoxAddress = new TextBox(); + dateTimePicker = new DateTimePicker(); + labelOpeningDate = new Label(); + groupBoxReinforceds = new GroupBox(); + dataGridView = new DataGridView(); + buttonSave = new Button(); + buttonCancel = new Button(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + groupBoxReinforceds.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(16, 13); + labelName.Margin = new Padding(5, 0, 5, 0); + labelName.Name = "labelName"; + labelName.Size = new Size(84, 20); + labelName.TabIndex = 1; + labelName.Text = "Название :"; + // + // textBoxName + // + textBoxName.Location = new Point(105, 9); + textBoxName.Margin = new Padding(5, 4, 5, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(287, 27); + textBoxName.TabIndex = 2; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(16, 53); + labelAddress.Margin = new Padding(5, 0, 5, 0); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(58, 20); + labelAddress.TabIndex = 3; + labelAddress.Text = "Адрес :"; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(105, 49); + textBoxAddress.Margin = new Padding(5, 4, 5, 4); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(287, 27); + textBoxAddress.TabIndex = 4; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(144, 88); + dateTimePicker.Margin = new Padding(3, 4, 3, 4); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(249, 27); + dateTimePicker.TabIndex = 5; + // + // labelOpeningDate + // + labelOpeningDate.AutoSize = true; + labelOpeningDate.Location = new Point(16, 92); + labelOpeningDate.Margin = new Padding(5, 0, 5, 0); + labelOpeningDate.Name = "labelOpeningDate"; + labelOpeningDate.Size = new Size(117, 20); + labelOpeningDate.TabIndex = 6; + labelOpeningDate.Text = "Дата открытия :"; + // + // groupBoxReinforceds + // + groupBoxReinforceds.Controls.Add(dataGridView); + groupBoxReinforceds.Location = new Point(5, 133); + groupBoxReinforceds.Margin = new Padding(5, 4, 5, 4); + groupBoxReinforceds.Name = "groupBoxReinforceds"; + groupBoxReinforceds.Padding = new Padding(5, 4, 5, 4); + groupBoxReinforceds.Size = new Size(536, 384); + groupBoxReinforceds.TabIndex = 7; + groupBoxReinforceds.TabStop = false; + groupBoxReinforceds.Text = "Изделие"; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(5, 24); + dataGridView.Margin = new Padding(5, 4, 5, 4); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(522, 356); + dataGridView.TabIndex = 0; + // + // buttonSave + // + buttonSave.Location = new Point(291, 525); + buttonSave.Margin = new Padding(5, 4, 5, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(410, 525); + buttonCancel.Margin = new Padding(5, 4, 5, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + ColumnId.Width = 125; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Название изделия"; + ColumnName.MinimumWidth = 6; + ColumnName.Name = "ColumnName"; + ColumnName.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 125; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(546, 576); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxReinforceds); + Controls.Add(labelOpeningDate); + Controls.Add(dateTimePicker); + Controls.Add(textBoxAddress); + Controls.Add(labelAddress); + Controls.Add(textBoxName); + Controls.Add(labelName); + Margin = new Padding(3, 4, 3, 4); + Name = "FormShop"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Магазин"; + Load += FormShop_Load; + groupBoxReinforceds.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private Label labelAddress; + private TextBox textBoxAddress; + private DateTimePicker dateTimePicker; + private Label labelOpeningDate; + private GroupBox groupBoxReinforceds; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs new file mode 100644 index 0000000..8c3ed32 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs @@ -0,0 +1,127 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantDataModels.Models; +using Microsoft.Extensions.Logging; +using PrecastConcretePlantListImplement.Models; +using System.Windows.Forms; + +namespace PrecastConcretePlantView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + private int? _id; + + private Dictionary _shopReinforceds; + + public int Id { set { _id = value; } } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopReinforceds = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Shop loading"); + try + { + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Value = view.DateOpening; + _shopReinforceds = view.ShopReinforceds ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Shop reinforceds loading"); + try + { + if (_shopReinforceds != null) + { + dataGridView.Rows.Clear(); + foreach (var reinforced in _shopReinforceds) + { + dataGridView.Rows.Add(new object[] { reinforced.Key, reinforced.Value.Item1.ReinforcedName, reinforced.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop reinforceds loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(dateTimePicker.Text)) + { + MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop saving"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value, + ShopReinforceds = _shopReinforceds + }; + 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, "Shop saving error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.Designer.cs new file mode 100644 index 0000000..786beb6 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.Designer.cs @@ -0,0 +1,145 @@ +namespace PrecastConcretePlantView +{ + partial class FormShopRefill + { + /// + /// 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() + { + labelShop = new Label(); + labelReinforced = new Label(); + labelCount = new Label(); + comboBoxShop = new ComboBox(); + comboBoxReinforced = new ComboBox(); + textBoxCount = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(27, 29); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(72, 20); + labelShop.TabIndex = 0; + labelShop.Text = "Магазин:"; + // + // labelReinforced + // + labelReinforced.AutoSize = true; + labelReinforced.Location = new Point(27, 73); + labelReinforced.Name = "labelReinforced"; + labelReinforced.Size = new Size(71, 20); + labelReinforced.TabIndex = 1; + labelReinforced.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(27, 118); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(93, 20); + labelCount.TabIndex = 2; + labelCount.Text = "Количество:"; + // + // comboBoxShop + // + comboBoxShop.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(136, 29); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(239, 28); + comboBoxShop.TabIndex = 3; + // + // comboBoxReinforced + // + comboBoxReinforced.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxReinforced.FormattingEnabled = true; + comboBoxReinforced.Location = new Point(136, 73); + comboBoxReinforced.Name = "comboBoxReinforced"; + comboBoxReinforced.Size = new Size(239, 28); + comboBoxReinforced.TabIndex = 4; + // + // textBoxCount + // + textBoxCount.Location = new Point(136, 118); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(239, 27); + textBoxCount.TabIndex = 5; + // + // buttonCancel + // + buttonCancel.Location = new Point(282, 162); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(93, 29); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(182, 162); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // FormShopRefill + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(422, 203); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxCount); + Controls.Add(comboBoxReinforced); + Controls.Add(comboBoxShop); + Controls.Add(labelCount); + Controls.Add(labelReinforced); + Controls.Add(labelShop); + Name = "FormShopRefill"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Пополнение магазина"; + Load += FormShopRefill_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelShop; + private Label labelReinforced; + private Label labelCount; + private ComboBox comboBoxShop; + private ComboBox comboBoxReinforced; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs new file mode 100644 index 0000000..fd340ab --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs @@ -0,0 +1,126 @@ +using Microsoft.Extensions.Logging; + +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PrecastConcretePlantView +{ + public partial class FormShopRefill : Form + { + private readonly ILogger _logger; + + private readonly IReinforcedLogic _logicReinforced; + + private readonly IShopLogic _logicShop; + + public FormShopRefill(ILogger logger, IReinforcedLogic logicReinforced, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicReinforced = logicReinforced; + _logicShop = logicShop; + } + + private void FormShopRefill_Load(object sender, EventArgs e) + { + _logger.LogInformation("Reinforceds loading"); + try + { + var list = _logicReinforced.ReadList(null); + if (list != null) + { + comboBoxReinforced.DisplayMember = "ReinforcedName"; + comboBoxReinforced.ValueMember = "Id"; + comboBoxReinforced.DataSource = list; + comboBoxReinforced.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Reinforceds loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + _logger.LogInformation("Shops loading"); + try + { + var list = _logicShop.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxReinforced.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop Refill"); + try + { + var reinforced = _logicReinforced.ReadElement(new ReinforcedSearchModel + { Id = Convert.ToInt32(comboBoxReinforced.SelectedValue) }); + if (reinforced == null) + { + throw new Exception("Изделие не найдено."); + } + var operationResult = _logicShop.ReplenishShop(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }, + reinforced, 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, "Shop Refill error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.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/PrecastConcretePlant/PrecastConcretePlantView/FormShopS.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShopS.cs new file mode 100644 index 0000000..2ecf768 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopS.cs @@ -0,0 +1,105 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + +namespace PrecastConcretePlantView +{ + 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["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopReinforceds"].Visible = false; + } + _logger.LogInformation("Shops loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Deletion of shop"); + try + { + if (!_logic.Delete(new ShopBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShops.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShops.Designer.cs new file mode 100644 index 0000000..66be0ba --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShops.Designer.cs @@ -0,0 +1,126 @@ +namespace PrecastConcretePlantView +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(408, 360); + dataGridView.TabIndex = 2; + // + // buttonUpd + // + buttonUpd.Location = new Point(432, 152); + buttonUpd.Margin = new Padding(4, 3, 4, 3); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(88, 27); + buttonUpd.TabIndex = 12; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(432, 105); + buttonDel.Margin = new Padding(4, 3, 4, 3); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(88, 27); + buttonDel.TabIndex = 11; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(432, 58); + buttonEdit.Margin = new Padding(4, 3, 4, 3); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(88, 27); + buttonEdit.TabIndex = 10; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(432, 14); + buttonAdd.Margin = new Padding(4, 3, 4, 3); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(88, 27); + buttonAdd.TabIndex = 9; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(541, 360); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShops.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormShops.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/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/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj b/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj index cb3c1f6..d532501 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj +++ b/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj @@ -10,6 +10,7 @@ + diff --git a/PrecastConcretePlant/PrecastConcretePlantView/Program.cs b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs index 5fbed1a..e4725c4 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs @@ -38,10 +38,12 @@ namespace PrecastConcretePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -50,6 +52,9 @@ namespace PrecastConcretePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file From 0e8c49cbe4382334596dbaa96f73d5f8d6425417 Mon Sep 17 00:00:00 2001 From: K Date: Fri, 3 May 2024 00:58:13 +0300 Subject: [PATCH 4/7] lab1hard --- .../BusinessLogic/ShopLogic.cs | 20 ++++++++++--------- .../BusinessLogicsContracts/IShopLogic.cs | 2 +- .../FormShopRefill.cs | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs index 35ddc6b..1e2707b 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -88,8 +88,8 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics } return true; } - - public bool ReplenishShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count) + //логика пополнения магазина + public bool RefillShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count) { if (shopModel == null) { @@ -103,25 +103,27 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics { throw new ArgumentException("В магазине должен быть хотя бы один товар", nameof(count)); } - _logger.LogInformation("ReplenishShop(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); + _logger.LogInformation("RefillShop(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); + var shop = _shopStorage.GetElement(shopModel); + if (shop == null) { - _logger.LogWarning("ReplenishShop(GetElement). Element not found"); + _logger.LogWarning("RefillShop(GetElement). Element not found"); return false; } - if (shop.ShopReinforceds.ContainsKey(reinforced.Id)) + if (shop.ShopReinforceds.ContainsKey(reinforced.Id))//если есть товар то плюс { var shopR = shop.ShopReinforceds[reinforced.Id]; shopR.Item2 += count; shop.ShopReinforceds[reinforced.Id] = shopR; - _logger.LogInformation("ReplenishShop. Added {count} '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, + _logger.LogInformation("RefillShop. Added {count} '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, shop.ShopName); } - else + else//если нет то просто добавляем { shop.ShopReinforceds.Add(reinforced.Id, (reinforced, count)); - _logger.LogInformation("ReplenishShop. Added {count} new '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, + _logger.LogInformation("RefillShop. Added {count} new '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, shop.ShopName); } if (_shopStorage.Update(new ShopBindingModel() @@ -133,7 +135,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics ShopReinforceds = shop.ShopReinforceds, }) == null) { - _logger.LogWarning("ReplenishShop. Update operation failed"); + _logger.LogWarning("RefillShop. Update operation failed"); return false; } return true; diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs index 624250e..156fa96 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -22,6 +22,6 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts bool Delete(ShopBindingModel model); - bool ReplenishShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count); + bool RefillShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs index fd340ab..c272b61 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs @@ -95,7 +95,7 @@ namespace PrecastConcretePlantView { throw new Exception("Изделие не найдено."); } - var operationResult = _logicShop.ReplenishShop(new ShopSearchModel + var operationResult = _logicShop.RefillShop(new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue) }, From a023f3b24a9b6f96f25105a736050a747c94ee75 Mon Sep 17 00:00:00 2001 From: K Date: Thu, 16 May 2024 21:48:52 +0400 Subject: [PATCH 5/7] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/OrderLogic.cs | 145 +++++++++++------- .../BusinessLogic/ShopLogic.cs | 88 +++++++++-- .../BindingModels/ShopBindingModel.cs | 1 + .../BusinessLogicsContracts/IShopLogic.cs | 6 +- .../StoragesContracts/IShopStorage.cs | 3 + .../ViewModels/ShopViewModel.cs | 3 + .../Models/IShopModel.cs | 1 + .../DataFileSingleton.cs | 18 +-- .../Implements/ShopStorage.cs | 138 +++++++++++++++++ .../Models/Shop.cs | 113 ++++++++++++++ .../DataListSingleton.cs | 6 - .../Implements/ShopStorage.cs | 5 + .../Models/Shop.cs | 2 + .../PrecastConcretePlantView/FormMain.cs | 95 ++++++------ 14 files changed, 495 insertions(+), 129 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs index 29765fb..fbed065 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs @@ -16,24 +16,21 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics public class OrderLogic : IOrderLogic { private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + + private readonly IReinforcedStorage _reinforcedStorage; + + private readonly IShopLogic _shopLogic; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IReinforcedStorage reinforcedStorage, IShopLogic shopLogic) { _logger = logger; _orderStorage = orderStorage; + _reinforcedStorage = reinforcedStorage; + _shopLogic = shopLogic; } - public List? ReadList(OrderSearchModel? model) - { - _logger.LogInformation("ReadList. Id: {Id}", model?.Id); - var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count: {Count}", list.Count); - return list; - } + public bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -50,54 +47,35 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics } return true; } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId: {Id}.", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public bool TakeOrderInWork(OrderBindingModel model) { - CheckModel(model, false); - if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Принят) - { - _logger.LogWarning("Invalid order status"); - return false; - } - model.Status = OrderStatus.Выполняется; - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - } - return true; + return ChangeStatus(model, OrderStatus.Выполняется); } + public bool FinishOrder(OrderBindingModel model) { - CheckModel(model, false); - if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Выполняется) - { - _logger.LogWarning("Invalid order status"); - return false; - } - model.Status = OrderStatus.Готов; - model.DateImplement = DateTime.Now; - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - } - return true; + return ChangeStatus(model, OrderStatus.Готов); } + public bool DeliveryOrder(OrderBindingModel model) { - CheckModel(model, false); - var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - if (order?.Status != OrderStatus.Готов) - { - _logger.LogWarning("Invalid order status"); - return false; - } - model.Status = OrderStatus.Выдан; - model.DateImplement = order.DateImplement; - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - } - return true; + return ChangeStatus(model, OrderStatus.Выдан); } + private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) @@ -108,16 +86,67 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics { return; } + if (model.ReinforcedId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.ReinforcedId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("В заказе должно быть хотя бы одно изделие", nameof(model.Count)); + } if (model.Sum <= 0) { - throw new ArgumentNullException("Стоимость должна быть больше 0", nameof(model.Sum)); + throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum)); } - _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. ReinforcedId: {ReinforcedId}", model.Id, model.Sum, model.ReinforcedId); - var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - if (element != null && element.Id == model.Id) + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. ReinforcedId: {ReinforcedId}. ReinforcedCount: {Count}", model.Id, model.Sum, + model.ReinforcedId, model.Count); + } + + private bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model, false); + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (order == null) { - throw new InvalidOperationException("Заказ с таким номером уже есть"); + _logger.LogWarning("Change status operation failed. Order not found"); + return false; } + if (order.Status + 1 != newStatus) + { + _logger.LogWarning("Change status operation failed. Incorrect new status: {newStatus}. Current status: {currStatus}", + newStatus, order.Status); + return false; + } + //наверное тут вопрос 3 тип если изделий нема то и выдать нечего + if (newStatus == OrderStatus.Выдан) + { + var reinforced = _reinforcedStorage.GetElement(new ReinforcedSearchModel() { Id = order.ReinforcedId }); + if (reinforced == null) + { + _logger.LogWarning("Change status operation failed. Reinforced not found"); + return false; + } + if (!_shopLogic.DeliverReinforceds(reinforced, order.Count)) + { + _logger.LogWarning("Change status operation failed. Reinforceds delivery operation failed"); + return false; + } + } + model.Status = newStatus; + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = order.DateImplement; + } + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + return true; } } -} \ No newline at end of file +} diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs index 1e2707b..f47fcf2 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ShopLogic.cs @@ -88,8 +88,8 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics } return true; } - //логика пополнения магазина - public bool RefillShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count) + + public bool ReplenishShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count) { if (shopModel == null) { @@ -103,27 +103,30 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics { throw new ArgumentException("В магазине должен быть хотя бы один товар", nameof(count)); } - _logger.LogInformation("RefillShop(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); - + _logger.LogInformation("ReplenishShop(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); var shop = _shopStorage.GetElement(shopModel); - if (shop == null) { - _logger.LogWarning("RefillShop(GetElement). Element not found"); + _logger.LogWarning("ReplenishShop(GetElement). Element not found"); return false; } - if (shop.ShopReinforceds.ContainsKey(reinforced.Id))//если есть товар то плюс + if (shop.ReinforcedsMax - shop.ShopReinforceds.Sum(x => x.Value.Item2) < count) + { + _logger.LogWarning("ReplenishShop error. No space for new reinforceds"); + return false; + } + if (shop.ShopReinforceds.ContainsKey(reinforced.Id)) { var shopR = shop.ShopReinforceds[reinforced.Id]; shopR.Item2 += count; shop.ShopReinforceds[reinforced.Id] = shopR; - _logger.LogInformation("RefillShop. Added {count} '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, + _logger.LogInformation("ReplenishShop. Added {count} '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, shop.ShopName); } - else//если нет то просто добавляем + else { shop.ShopReinforceds.Add(reinforced.Id, (reinforced, count)); - _logger.LogInformation("RefillShop. Added {count} new '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, + _logger.LogInformation("ReplenishShop. Added {count} new '{reinforced}' to '{ShopName}' shop", count, reinforced.ReinforcedName, shop.ShopName); } if (_shopStorage.Update(new ShopBindingModel() @@ -132,15 +135,78 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics ShopName = shop.ShopName, Address = shop.Address, DateOpening = shop.DateOpening, + ReinforcedsMax = shop.ReinforcedsMax, ShopReinforceds = shop.ShopReinforceds, }) == null) { - _logger.LogWarning("RefillShop. Update operation failed"); + _logger.LogWarning("ReplenishShop. Update operation failed"); return false; } return true; } + public bool MakeSale(IReinforcedModel model, int count) + { + return _shopStorage.MakeSale(model, count); + } + + public bool DeliverReinforceds(IReinforcedModel reinforced, int count) + { + if (count <= 0) + { + _logger.LogWarning("Reinforceds delivery operation failed. Reinforced count <= 0"); + return false; + } + + var shopList = _shopStorage.GetFullList(); + int shopsCapacity = shopList.Sum(x => x.ReinforcedsMax); + int currentReinforceds = shopList.Select(x => x.ShopReinforceds.Sum(y => y.Value.Item2)).Sum(); + int freePlaces = shopsCapacity - currentReinforceds; + + if (freePlaces < count) + { + _logger.LogWarning("Reinforceds delivery operation failed. No space for new кeinforceds"); + return false; + } + + foreach (var shop in shopList) + { + freePlaces = shop.ReinforcedsMax - shop.ShopReinforceds.Sum(x => x.Value.Item2); + if (freePlaces == 0) + { + continue; + } + if (freePlaces >= count) + { + if (ReplenishShop(new() { Id = shop.Id }, reinforced, count)) + { + count = 0; + } + else + { + _logger.LogWarning("Reinforceds delivery operation failed"); + return false; + } + } + else + { + if (ReplenishShop(new() { Id = shop.Id }, reinforced, freePlaces)) + { + count -= freePlaces; + } + else + { + _logger.LogWarning("Reinforceds delivery operation failed"); + return false; + } + } + if (count == 0) + { + return true; + } + } + return false; + } private void CheckModel(ShopBindingModel model, bool withParams = true) { if (model == null) diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs index b7d7bd5..1c1108d 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -22,5 +22,6 @@ namespace PrecastConcretePlantContracts.BindingModels get; set; } = new(); + public int ReinforcedsMax { get; set; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs index 156fa96..07aee37 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -22,6 +22,10 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts bool Delete(ShopBindingModel model); - bool RefillShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count); + bool ReplenishShop(ShopSearchModel shopModel, IReinforcedModel reinforced, int count); + + bool MakeSale(IReinforcedModel model, int count); + + bool DeliverReinforceds(IReinforcedModel model, int count); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs index e6da5e5..f793af8 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -22,5 +23,7 @@ namespace PrecastConcretePlantContracts.StoragesContracts ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + + bool MakeSale(IReinforcedModel model, int count); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs index 7d3bc7f..1f4b9c3 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -26,5 +26,8 @@ namespace PrecastConcretePlantContracts.ViewModels get; set; } = new(); + + [DisplayName("Максимальное количество изделий")] + public int ReinforcedsMax { get; set; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs index d315a48..591bf5c 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IShopModel.cs @@ -15,5 +15,6 @@ namespace PrecastConcretePlantDataModels.Models DateTime DateOpening { get; } Dictionary ShopReinforceds { get; } + int ReinforcedsMax { get; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs index 587388c..577dc01 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs @@ -1,22 +1,19 @@ -using PrecastConcretePlantFileImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; +using System.Xml.Linq; +using PrecastConcretePlantFileImplement.Models; namespace PrecastConcretePlantFileImplement { - public class DataFileSingleton + internal class DataFileSingleton { private static DataFileSingleton? instance; private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string ReinforcedFileName = "Reinforced.xml"; + private readonly string ShopFileName = "Shop.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Reinforceds { get; private set; } + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -28,18 +25,19 @@ namespace PrecastConcretePlantFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveReinforceds() => SaveData(Reinforceds, ReinforcedFileName, "Reinforceds", 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)!)!; Reinforceds = LoadData(ReinforcedFileName, "Reinforced", x => Reinforced.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) { if (File.Exists(filename)) { - return - XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); } return new List(); } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..2bf21ca --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,138 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using PrecastConcretePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Shops + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + return source.Shops + .Where(x => x.ShopName.Contains(model.ShopName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + return source.Shops + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + var element = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Shops.Remove(element); + source.SaveShops(); + return element.GetViewModel; + } + return null; + } + + //логика продажи изделий с магазинов + public bool MakeSale(IReinforcedModel model, int count) + { + var reinforced = source.Reinforceds.FirstOrDefault(x => x.Id == model.Id); + int countInShops = source.Shops.SelectMany(x => x.ShopReinforceds).Sum(y => y.Key == model.Id ? y.Value.Item2 : 0); + + if (reinforced == null || countInShops < count) + { + return false; + } + + foreach (var shop in source.Shops) + { + var shopReinforceds = shop.ShopReinforceds.Where(x => x.Key == model.Id); + if (shopReinforceds.Any()) + { + var shopReinforced = shopReinforceds.First(); + int min = Math.Min(shopReinforced.Value.Item2, count); + if (min == shopReinforced.Value.Item2) + { + shop.ShopReinforceds.Remove(shopReinforced.Key); + } + else + { + shop.ShopReinforceds[shopReinforced.Key] = (shopReinforced.Value.Item1, shopReinforced.Value.Item2 - min); + } + shop.Update(new ShopBindingModel + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpening = shop.DateOpening, + ShopReinforceds = shop.ShopReinforceds, + ReinforcedsMax = shop.ReinforcedsMax + }); + count -= min; + if (count <= 0) + { + break; + } + } + } + source.SaveShops(); + return true; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs new file mode 100644 index 0000000..4766e15 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Shop.cs @@ -0,0 +1,113 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + + public Dictionary Reinforceds { get; private set; } = new(); + + private Dictionary? _shopReinforceds = null; + + public Dictionary ShopReinforceds + { + get + { + if (_shopReinforceds == null) + { + var source = DataFileSingleton.GetInstance(); + _shopReinforceds = Reinforceds.ToDictionary(x => x.Key, + y => ((source.Reinforceds.FirstOrDefault(z => z.Id == y.Key) as IReinforcedModel)!, y.Value)); + } + return _shopReinforceds; + } + } + + public int ReinforcedsMax { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + Reinforceds = model.ShopReinforceds.ToDictionary(x => x.Key, x => x.Value.Item2), + ReinforcedsMax = model.ReinforcedsMax + }; + } + + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), + ReinforcedsMax = Convert.ToInt32(element.Element("ReinforcedsMax")!.Value), + Reinforceds = element.Element("ShopReinforceds")!.Elements("ShopReinforced") + .ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + ReinforcedsMax = model.ReinforcedsMax; + Reinforceds = model.ShopReinforceds.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopReinforceds = null; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + ShopReinforceds = ShopReinforceds, + ReinforcedsMax = ReinforcedsMax + }; + + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpening", DateOpening.ToString()), + new XElement("ReinforcedsMax", ReinforcedsMax.ToString()), + new XElement("ShopReinforceds", + Reinforceds.Select(x => new XElement("ShopReinforced", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs index a8879b8..0f98719 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs @@ -1,9 +1,4 @@ using PrecastConcretePlantListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace PrecastConcretePlantListImplement { @@ -29,6 +24,5 @@ namespace PrecastConcretePlantListImplement } return _instance; } - } } diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs index 9c4e7a5..28a77ee 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ShopStorage.cs @@ -2,6 +2,7 @@ using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.StoragesContracts; using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; using PrecastConcretePlantListImplement.Models; using System; using System.Collections.Generic; @@ -110,5 +111,9 @@ namespace PrecastConcretePlantListImplement.Implements } return null; } + public bool MakeSale(IReinforcedModel model, int count) + { + throw new NotImplementedException(); + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs index ad0ea97..d07d16a 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Shop.cs @@ -19,6 +19,8 @@ namespace PrecastConcretePlantListImplement.Models public DateTime DateOpening { get; private set; } + public int ReinforcedsMax { get; set; } + public Dictionary ShopReinforceds { get; diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs index 9486b04..ff7d4d3 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; using System; @@ -36,26 +36,27 @@ namespace PrecastConcretePlantView { dataGridView.DataSource = list; dataGridView.Columns["ReinforcedId"].Visible = false; - dataGridView.Columns["ReinforcedName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["reinforcedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } - _logger.LogInformation(" "); + _logger.LogInformation("青沭箸赅 玎赅珙"); } catch (Exception ex) { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "硒栳赅 玎沭箸觇 玎赅珙"); + MessageBox.Show(ex.Message, "硒栳赅", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ToolStripMenuItem_Click(object sender, EventArgs e) + private void 暑祜铐屙螓ToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormComponentS)); + var service = + Program.ServiceProvider?.GetService(typeof(FormComponentS)); if (service is FormComponentS form) { form.ShowDialog(); } } - private void ToolStripMenuItem_Click(object sender, EventArgs e) + private void 如溴腓ToolStripMenuItem_Click(object sender, EventArgs e) + { var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedS)); if (service is FormReinforcedS form) @@ -63,7 +64,7 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } - private void ToolStripMenuItem_Click(object sender, EventArgs e) + private void 锑汔玷睇ToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShops)); if (service is FormShops form) @@ -71,17 +72,26 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } - private void ToolStripMenuItem_Click(object sender, EventArgs e) + private void 项镱腠屙桢锑汔玷磬ToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormShopRefill)); - if (service is FormShopRefill form) + var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenishment)); + if (service is FormShopReplenishment form) + { + form.ShowDialog(); + } + } + private void 橡钿噫嗳玟咫栝ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedSale)); + if (service is FormReinforcedSale form) { form.ShowDialog(); } } private void ButtonCreateOrder_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + var service = + Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); if (service is FormCreateOrder form) { form.ShowDialog(); @@ -92,24 +102,23 @@ namespace PrecastConcretePlantView { if (dataGridView.SelectedRows.Count == 1) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation(" No{id}. ' '", id); + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("青赅 箋id}. 体<> 耱囹篑 磬 '<27> 疣犷蝈'", id); try { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id - }); + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); if (!operationResult) { - throw new Exception(" . ."); + throw new Exception("硒栳赅 镳<> 耦躔囗屙梃.念镱腠栩咫 桧纛痨圉 <20> 腩汔."); } LoadData(); } catch (Exception ex) { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "硒栳赅 镥疱溧麒 玎赅玎 <20> 疣犷蝮"); + MessageBox.Show(ex.Message, "硒栳赅", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } } @@ -117,24 +126,25 @@ namespace PrecastConcretePlantView { if (dataGridView.SelectedRows.Count == 1) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation(" No{id}. ''", id); + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("青赅 箋id}. 体<> 耱囹篑 磬 '妙蝾'", + id); try { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { - Id = id - }); + var operationResult = _orderLogic.FinishOrder(new + OrderBindingModel + { Id = id }); if (!operationResult) { - throw new Exception(" . ."); + throw new Exception("硒栳赅 镳<> 耦躔囗屙梃. 念镱腠栩咫 桧纛痨圉 <20> 腩汔."); } LoadData(); } catch (Exception ex) { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "硒栳赅 铗戾蜿 <20> 泐蝾忭铖蜩 玎赅玎"); + MessageBox.Show(ex.Message, "硒栳赅", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } @@ -142,29 +152,28 @@ namespace PrecastConcretePlantView { if (dataGridView.SelectedRows.Count == 1) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation(" No{id}. ''", id); + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("青赅 箋id}. 体<> 耱囹篑 磬 '蔓溧'", id); try { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel - { - Id = id - }); + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); if (!operationResult) { - throw new Exception(" . ."); + throw new Exception("硒栳赅"); } - _logger.LogInformation(" No{id} ", id); + _logger.LogInformation("青赅 箋id} 恹溧", id); LoadData(); } catch (Exception ex) { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "硒栳赅 铗戾蜿 <20> 恹溧麒 玎赅玎"); + MessageBox.Show(ex.Message, "硒栳赅", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } } - private void ButtonRef_Click(object sender, EventArgs e) + private void ButtonUpd_Click(object sender, EventArgs e) { LoadData(); } From e83c6ee11f82d71d051c0b332e66ce316bc99bf5 Mon Sep 17 00:00:00 2001 From: K Date: Thu, 16 May 2024 21:59:54 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=20=D1=85=D0=B0?= =?UTF-8?q?=D1=80=D0=B4=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BB=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMain.Designer.cs | 45 +++--- .../PrecastConcretePlantView/FormMain.cs | 43 +++--- .../FormReinforcedSale.Designer.cs | 128 ++++++++++++++++ .../FormReinforcedSale.cs | 87 +++++++++++ .../FormReinforcedSale.resx | 120 +++++++++++++++ .../FormShop.Designer.cs | 84 ++++++---- .../PrecastConcretePlantView/FormShop.cs | 8 +- .../FormShopRefill.cs | 2 +- .../FormShopReplenishment.Designer.cs | 145 ++++++++++++++++++ .../FormShopReplenishment.cs | 126 +++++++++++++++ .../FormShopReplenishment.resx | 120 +++++++++++++++ .../PrecastConcretePlantView/FormShopS.cs | 1 - .../PrecastConcretePlantView/Program.cs | 14 +- 13 files changed, 842 insertions(+), 81 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedSale.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedSale.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedSale.resx create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShopReplenishment.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShopReplenishment.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantView/FormShopReplenishment.resx diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs index 4f2a32a..2299c79 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs @@ -32,14 +32,15 @@ справочникToolStripMenuItem = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem(); изделияToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem(); + продажаИзделийToolStripMenuItem = new ToolStripMenuItem(); buttonRef = new Button(); buttonIssuedOrder = new Button(); buttonOrderReady = new Button(); buttonTakeOrderInWork = new Button(); buttonCreateOrder = new Button(); dataGridView = new DataGridView(); - магазиныToolStripMenuItem = new ToolStripMenuItem(); - пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -47,7 +48,7 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem, пополнениеМагазинаToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem, пополнениеМагазинаToolStripMenuItem, продажаИзделийToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Padding = new Padding(6, 3, 0, 3); @@ -76,6 +77,27 @@ изделияToolStripMenuItem.Text = "Изделия"; изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click; + // + // пополнениеМагазинаToolStripMenuItem + // + пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24); + пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + пополнениеМагазинаToolStripMenuItem.Click += ПополнениеМагазинаToolStripMenuItem_Click; + // + // продажаИзделийToolStripMenuItem + // + продажаИзделийToolStripMenuItem.Name = "продажаИзделийToolStripMenuItem"; + продажаИзделийToolStripMenuItem.Size = new Size(149, 24); + продажаИзделийToolStripMenuItem.Text = "Продажа изделий"; + продажаИзделийToolStripMenuItem.Click += ПродажаИзделийToolStripMenuItem_Click; + // // buttonRef // buttonRef.Location = new Point(931, 273); @@ -84,7 +106,7 @@ buttonRef.TabIndex = 23; buttonRef.Text = "Обновить список"; buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += ButtonRef_Click; + buttonRef.Click += ButtonUpd_Click; // // buttonIssuedOrder // @@ -136,20 +158,6 @@ dataGridView.Size = new Size(925, 374); dataGridView.TabIndex = 18; // - // магазиныToolStripMenuItem - // - магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - магазиныToolStripMenuItem.Size = new Size(224, 26); - магазиныToolStripMenuItem.Text = "Магазины"; - магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click; - // - // пополнениеМагазинаToolStripMenuItem - // - пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; - пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24); - пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; - пополнениеМагазинаToolStripMenuItem.Click += ПополнениеМагазинаToolStripMenuItem_Click; - // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -187,5 +195,6 @@ private DataGridView dataGridView; private ToolStripMenuItem магазиныToolStripMenuItem; private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; + private ToolStripMenuItem продажаИзделийToolStripMenuItem; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs index ff7d4d3..79aed03 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs @@ -38,15 +38,15 @@ namespace PrecastConcretePlantView dataGridView.Columns["ReinforcedId"].Visible = false; dataGridView.Columns["reinforcedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } - _logger.LogInformation("青沭箸赅 玎赅珙"); + _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) { - _logger.LogError(ex, "硒栳赅 玎沭箸觇 玎赅珙"); - MessageBox.Show(ex.Message, "硒栳赅", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void 暑祜铐屙螓ToolStripMenuItem_Click(object sender, EventArgs e) + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormComponentS)); @@ -55,8 +55,7 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } - private void 如溴腓ToolStripMenuItem_Click(object sender, EventArgs e) - + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedS)); if (service is FormReinforcedS form) @@ -64,7 +63,7 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } - private void 锑汔玷睇ToolStripMenuItem_Click(object sender, EventArgs e) + private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShops)); if (service is FormShops form) @@ -72,7 +71,7 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } - private void 项镱腠屙桢锑汔玷磬ToolStripMenuItem_Click(object sender, EventArgs e) + private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenishment)); if (service is FormShopReplenishment form) @@ -80,7 +79,7 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } - private void 橡钿噫嗳玟咫栝ToolStripMenuItem_Click(object sender, EventArgs e) + private void ПродажаИзделийToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormReinforcedSale)); if (service is FormReinforcedSale form) @@ -104,20 +103,20 @@ namespace PrecastConcretePlantView { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("青赅 箋id}. 体<> 耱囹篑 磬 '<27> 疣犷蝈'", id); + _logger.LogInformation("Заказ {id}. Меняется статус на 'В работе'", id); try { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); if (!operationResult) { - throw new Exception("硒栳赅 镳<> 耦躔囗屙梃.念镱腠栩咫 桧纛痨圉 <20> 腩汔."); + throw new Exception("Ошибка при сохранении.Дополнительная информация в логах."); } LoadData(); } catch (Exception ex) { - _logger.LogError(ex, "硒栳赅 镥疱溧麒 玎赅玎 <20> 疣犷蝮"); - MessageBox.Show(ex.Message, "硒栳赅", MessageBoxButtons.OK, + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -128,7 +127,7 @@ namespace PrecastConcretePlantView { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("青赅 箋id}. 体<> 耱囹篑 磬 '妙蝾'", + _logger.LogInformation("Заказ {id}. Меняется статус на 'Готов'", id); try { @@ -137,14 +136,14 @@ namespace PrecastConcretePlantView { Id = id }); if (!operationResult) { - throw new Exception("硒栳赅 镳<> 耦躔囗屙梃. 念镱腠栩咫 桧纛痨圉 <20> 腩汔."); + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } LoadData(); } catch (Exception ex) { - _logger.LogError(ex, "硒栳赅 铗戾蜿 <20> 泐蝾忭铖蜩 玎赅玎"); - MessageBox.Show(ex.Message, "硒栳赅", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } @@ -154,21 +153,21 @@ namespace PrecastConcretePlantView { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("青赅 箋id}. 体<> 耱囹篑 磬 '蔓溧'", id); + _logger.LogInformation("Заказ {id}. Меняется статус на 'Выдан'", id); try { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); if (!operationResult) { - throw new Exception("硒栳赅"); + throw new Exception("Ошибка"); } - _logger.LogInformation("青赅 箋id} 恹溧", id); + _logger.LogInformation("Заказ {id} выдан", id); LoadData(); } catch (Exception ex) { - _logger.LogError(ex, "硒栳赅 铗戾蜿 <20> 恹溧麒 玎赅玎"); - MessageBox.Show(ex.Message, "硒栳赅", MessageBoxButtons.OK, + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedSale.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedSale.Designer.cs new file mode 100644 index 0000000..c36794e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedSale.Designer.cs @@ -0,0 +1,128 @@ +namespace PrecastConcretePlantView +{ + partial class FormReinforcedSale + { + /// + /// 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() + { + buttonCancel = new Button(); + buttonSale = new Button(); + textBoxCount = new TextBox(); + labelCount = new Label(); + comboBoxReinforced = new ComboBox(); + labelReinforced = new Label(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Location = new Point(289, 111); + buttonCancel.Margin = new Padding(5, 4, 5, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 17; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSale + // + buttonSale.Location = new Point(182, 111); + buttonSale.Margin = new Padding(5, 4, 5, 4); + buttonSale.Name = "buttonSale"; + buttonSale.Size = new Size(101, 36); + buttonSale.TabIndex = 16; + buttonSale.Text = "Продать"; + buttonSale.UseVisualStyleBackColor = true; + buttonSale.Click += ButtonSale_Click; + // + // textBoxCount + // + textBoxCount.Location = new Point(115, 68); + textBoxCount.Margin = new Padding(5, 4, 5, 4); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(287, 27); + textBoxCount.TabIndex = 15; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(15, 72); + labelCount.Margin = new Padding(5, 0, 5, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(93, 20); + labelCount.TabIndex = 14; + labelCount.Text = "Количество:"; + // + // comboBoxReinforced + // + comboBoxReinforced.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxReinforced.FormattingEnabled = true; + comboBoxReinforced.Location = new Point(115, 20); + comboBoxReinforced.Margin = new Padding(5, 4, 5, 4); + comboBoxReinforced.Name = "comboBoxReinforced"; + comboBoxReinforced.Size = new Size(287, 28); + comboBoxReinforced.TabIndex = 13; + // + // labelReinforced + // + labelReinforced.AutoSize = true; + labelReinforced.Location = new Point(15, 25); + labelReinforced.Margin = new Padding(5, 0, 5, 0); + labelReinforced.Name = "labelReinforced"; + labelReinforced.Size = new Size(71, 20); + labelReinforced.TabIndex = 12; + labelReinforced.Text = "Изделие:"; + // + // FormReinforcedSale + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(426, 164); + Controls.Add(buttonCancel); + Controls.Add(buttonSale); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(comboBoxReinforced); + Controls.Add(labelReinforced); + Margin = new Padding(3, 4, 3, 4); + Name = "FormReinforcedSale"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Продажа изделий"; + Load += FormReinforcedSale_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCancel; + private Button buttonSale; + private TextBox textBoxCount; + private Label labelCount; + private ComboBox comboBoxReinforced; + private Label labelReinforced; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedSale.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedSale.cs new file mode 100644 index 0000000..238f726 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedSale.cs @@ -0,0 +1,87 @@ +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.BindingModels; +using Microsoft.Extensions.Logging; + +namespace PrecastConcretePlantView +{ + public partial class FormReinforcedSale : Form + { + private readonly ILogger _logger; + + private readonly IReinforcedLogic _logicReinforced; + + private readonly IShopLogic _logicShop; + + public FormReinforcedSale(ILogger logger, IReinforcedLogic logicReinforced, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicReinforced = logicReinforced; + _logicShop = logicShop; + } + + private void FormReinforcedSale_Load(object sender, EventArgs e) + { + _logger.LogInformation("Reinforceds loading"); + try + { + var list = _logicReinforced.ReadList(null); + if (list != null) + { + comboBoxReinforced.DisplayMember = "ReinforcedName"; + comboBoxReinforced.ValueMember = "Id"; + comboBoxReinforced.DataSource = list; + comboBoxReinforced.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Reinforceds loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSale_Click(object sender, EventArgs e) + { + if (comboBoxReinforced.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Reinforced sale"); + try + { + var operationResult = _logicShop.MakeSale( + new ReinforcedBindingModel + { + Id = Convert.ToInt32(comboBoxReinforced.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, "Reinforced sale error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedSale.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedSale.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormReinforcedSale.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/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs index 78f5a73..1e9c361 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.Designer.cs @@ -36,11 +36,13 @@ labelOpeningDate = new Label(); groupBoxReinforceds = new GroupBox(); dataGridView = new DataGridView(); - buttonSave = new Button(); - buttonCancel = new Button(); ColumnId = new DataGridViewTextBoxColumn(); ColumnName = new DataGridViewTextBoxColumn(); ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + textBoxMax = new Label(); + textBoxMaximum = new TextBox(); groupBoxReinforceds.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -60,7 +62,7 @@ textBoxName.Location = new Point(105, 9); textBoxName.Margin = new Padding(5, 4, 5, 4); textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(287, 27); + textBoxName.Size = new Size(302, 27); textBoxName.TabIndex = 2; // // labelAddress @@ -78,7 +80,7 @@ textBoxAddress.Location = new Point(105, 49); textBoxAddress.Margin = new Padding(5, 4, 5, 4); textBoxAddress.Name = "textBoxAddress"; - textBoxAddress.Size = new Size(287, 27); + textBoxAddress.Size = new Size(302, 27); textBoxAddress.TabIndex = 4; // // dateTimePicker @@ -86,7 +88,7 @@ dateTimePicker.Location = new Point(144, 88); dateTimePicker.Margin = new Padding(3, 4, 3, 4); dateTimePicker.Name = "dateTimePicker"; - dateTimePicker.Size = new Size(249, 27); + dateTimePicker.Size = new Size(263, 27); dateTimePicker.TabIndex = 5; // // labelOpeningDate @@ -102,11 +104,11 @@ // groupBoxReinforceds // groupBoxReinforceds.Controls.Add(dataGridView); - groupBoxReinforceds.Location = new Point(5, 133); + groupBoxReinforceds.Location = new Point(5, 183); groupBoxReinforceds.Margin = new Padding(5, 4, 5, 4); groupBoxReinforceds.Name = "groupBoxReinforceds"; groupBoxReinforceds.Padding = new Padding(5, 4, 5, 4); - groupBoxReinforceds.Size = new Size(536, 384); + groupBoxReinforceds.Size = new Size(536, 395); groupBoxReinforceds.TabIndex = 7; groupBoxReinforceds.TabStop = false; groupBoxReinforceds.Text = "Изделие"; @@ -127,31 +129,9 @@ dataGridView.RowHeadersVisible = false; dataGridView.RowHeadersWidth = 51; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(522, 356); + dataGridView.Size = new Size(522, 367); dataGridView.TabIndex = 0; // - // buttonSave - // - buttonSave.Location = new Point(291, 525); - buttonSave.Margin = new Padding(5, 4, 5, 4); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(101, 36); - buttonSave.TabIndex = 8; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; - // - // buttonCancel - // - buttonCancel.Location = new Point(410, 525); - buttonCancel.Margin = new Padding(5, 4, 5, 4); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(101, 36); - buttonCancel.TabIndex = 9; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; - // // ColumnId // ColumnId.HeaderText = "Id"; @@ -177,11 +157,51 @@ ColumnCount.ReadOnly = true; ColumnCount.Width = 125; // + // buttonSave + // + buttonSave.Location = new Point(306, 586); + buttonSave.Margin = new Padding(5, 4, 5, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(417, 586); + buttonCancel.Margin = new Padding(5, 4, 5, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // textBoxMax + // + textBoxMax.AutoSize = true; + textBoxMax.Location = new Point(16, 141); + textBoxMax.Name = "textBoxMax"; + textBoxMax.Size = new Size(270, 20); + textBoxMax.TabIndex = 10; + textBoxMax.Text = "Максимальное колличество изделий:"; + // + // textBoxMaximum + // + textBoxMaximum.Location = new Point(306, 138); + textBoxMaximum.Name = "textBoxMaximum"; + textBoxMaximum.Size = new Size(101, 27); + textBoxMaximum.TabIndex = 11; + // // FormShop // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(546, 576); + ClientSize = new Size(546, 635); + Controls.Add(textBoxMaximum); + Controls.Add(textBoxMax); Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(groupBoxReinforceds); @@ -217,5 +237,7 @@ private DataGridViewTextBoxColumn ColumnId; private DataGridViewTextBoxColumn ColumnName; private DataGridViewTextBoxColumn ColumnCount; + private Label textBoxMax; + private TextBox textBoxMaximum; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs index 8c3ed32..f02ac17 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShop.cs @@ -4,7 +4,6 @@ using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantDataModels.Models; using Microsoft.Extensions.Logging; using PrecastConcretePlantListImplement.Models; -using System.Windows.Forms; namespace PrecastConcretePlantView { @@ -41,6 +40,7 @@ namespace PrecastConcretePlantView textBoxName.Text = view.ShopName; textBoxAddress.Text = view.Address; dateTimePicker.Value = view.DateOpening; + textBoxMaximum.Text = view.ReinforcedsMax.ToString(); _shopReinforceds = view.ShopReinforceds ?? new Dictionary(); LoadData(); } @@ -91,6 +91,11 @@ namespace PrecastConcretePlantView MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (string.IsNullOrEmpty(textBoxMaximum.Text)) + { + MessageBox.Show("Заполните максимальное количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Shop saving"); try { @@ -100,6 +105,7 @@ namespace PrecastConcretePlantView ShopName = textBoxName.Text, Address = textBoxAddress.Text, DateOpening = dateTimePicker.Value, + ReinforcedsMax = Convert.ToInt32(textBoxMaximum.Text), ShopReinforceds = _shopReinforceds }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs index c272b61..fd340ab 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopRefill.cs @@ -95,7 +95,7 @@ namespace PrecastConcretePlantView { throw new Exception("Изделие не найдено."); } - var operationResult = _logicShop.RefillShop(new ShopSearchModel + var operationResult = _logicShop.ReplenishShop(new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue) }, diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopReplenishment.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShopReplenishment.Designer.cs new file mode 100644 index 0000000..1114748 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopReplenishment.Designer.cs @@ -0,0 +1,145 @@ +namespace PrecastConcretePlantView +{ + partial class FormShopReplenishment + { + /// + /// 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() + { + labelShop = new Label(); + labelReinforced = new Label(); + labelCount = new Label(); + comboBoxShop = new ComboBox(); + comboBoxReinforced = new ComboBox(); + textBoxCount = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(27, 29); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(72, 20); + labelShop.TabIndex = 0; + labelShop.Text = "Магазин:"; + // + // labelReinforced + // + labelReinforced.AutoSize = true; + labelReinforced.Location = new Point(27, 73); + labelReinforced.Name = "labelReinforced"; + labelReinforced.Size = new Size(71, 20); + labelReinforced.TabIndex = 1; + labelReinforced.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(27, 118); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(93, 20); + labelCount.TabIndex = 2; + labelCount.Text = "Количество:"; + // + // comboBoxShop + // + comboBoxShop.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(136, 29); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(239, 28); + comboBoxShop.TabIndex = 3; + // + // comboBoxReinforced + // + comboBoxReinforced.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxReinforced.FormattingEnabled = true; + comboBoxReinforced.Location = new Point(136, 73); + comboBoxReinforced.Name = "comboBoxReinforced"; + comboBoxReinforced.Size = new Size(239, 28); + comboBoxReinforced.TabIndex = 4; + // + // textBoxCount + // + textBoxCount.Location = new Point(136, 118); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(239, 27); + textBoxCount.TabIndex = 5; + // + // buttonCancel + // + buttonCancel.Location = new Point(282, 162); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(93, 29); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(182, 162); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // FormShopReplenishment + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(422, 203); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxCount); + Controls.Add(comboBoxReinforced); + Controls.Add(comboBoxShop); + Controls.Add(labelCount); + Controls.Add(labelReinforced); + Controls.Add(labelShop); + Name = "FormShopReplenishment"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Пополнение магазина"; + Load += FormShopReplenishment_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelShop; + private Label labelReinforced; + private Label labelCount; + private ComboBox comboBoxShop; + private ComboBox comboBoxReinforced; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopReplenishment.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShopReplenishment.cs new file mode 100644 index 0000000..8a7ea68 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopReplenishment.cs @@ -0,0 +1,126 @@ +using Microsoft.Extensions.Logging; + +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PrecastConcretePlantView +{ + public partial class FormShopReplenishment : Form + { + private readonly ILogger _logger; + + private readonly IReinforcedLogic _logicReinforced; + + private readonly IShopLogic _logicShop; + + public FormShopReplenishment(ILogger logger, IReinforcedLogic logicReinforced, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicReinforced = logicReinforced; + _logicShop = logicShop; + } + + private void FormShopReplenishment_Load(object sender, EventArgs e) + { + _logger.LogInformation("Reinforceds loading"); + try + { + var list = _logicReinforced.ReadList(null); + if (list != null) + { + comboBoxReinforced.DisplayMember = "ReinforcedName"; + comboBoxReinforced.ValueMember = "Id"; + comboBoxReinforced.DataSource = list; + comboBoxReinforced.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Reinforceds loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + _logger.LogInformation("Shops loading"); + try + { + var list = _logicShop.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxReinforced.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop replenishment"); + try + { + var reinforced = _logicReinforced.ReadElement(new ReinforcedSearchModel + { Id = Convert.ToInt32(comboBoxReinforced.SelectedValue) }); + if (reinforced == null) + { + throw new Exception("Изделие не найдено."); + } + var operationResult = _logicShop.ReplenishShop(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }, + reinforced, 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, "Shop replenishment error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormShopReplenishment.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormShopReplenishment.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopReplenishment.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/PrecastConcretePlant/PrecastConcretePlantView/FormShopS.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormShopS.cs index 2ecf768..ac07dd0 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormShopS.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormShopS.cs @@ -1,7 +1,6 @@ using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; -using System.Windows.Forms; namespace PrecastConcretePlantView { diff --git a/PrecastConcretePlant/PrecastConcretePlantView/Program.cs b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs index 81aca21..9cdcd31 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs @@ -1,11 +1,11 @@ +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantBusinessLogic.BusinessLogics; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -using PrecastConcretePlantBusinessLogic.BusinessLogics; -using PrecastConcretePlantContracts.BusinessLogicsContracts; -using PrecastConcretePlantContracts.StoragesContracts; -using PrecastConcretePlantFileImplement.Implements; -using System; + namespace PrecastConcretePlantView { @@ -34,7 +34,6 @@ namespace PrecastConcretePlantView option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); - services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -54,7 +53,8 @@ namespace PrecastConcretePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file From 29a989cc6c9ebc4843dd01c4bb70f37d7e6d78d0 Mon Sep 17 00:00:00 2001 From: K Date: Fri, 17 May 2024 00:03:34 +0400 Subject: [PATCH 7/7] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ComponentStorage.cs | 4 +- .../Implements/OrderStorage.cs | 4 +- .../Implements/ReinforcedStorage.cs | 4 +- .../Implements/ShopStorage.cs | 147 ++++++++++ .../20240404165842_InitialCreate.Designer.cs | 26 +- .../20240404165842_InitialCreate.cs | 2 +- .../20240516193152_initial.Designer.cs | 250 ++++++++++++++++++ .../Migrations/20240516193152_initial.cs | 78 ++++++ ...ecastConcretePlantDataBaseModelSnapshot.cs | 105 +++++++- .../Models/Component.cs | 2 +- .../Models/Order.cs | 2 +- .../Models/Reinforced.cs | 5 +- .../Models/ReinforcedComponent.cs | 2 +- .../Models/Shop.cs | 110 ++++++++ .../Models/ShopReinforced.cs | 22 ++ .../PrecastConcretePlantDatabase.cs | 9 +- .../PrecastConcretePlantView.csproj | 2 +- .../PrecastConcretePlantView/Program.cs | 3 + 18 files changed, 735 insertions(+), 42 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240516193152_initial.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240516193152_initial.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/ShopReinforced.cs diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ComponentStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ComponentStorage.cs index 9bfd4fd..c7697d6 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ComponentStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ComponentStorage.cs @@ -2,14 +2,14 @@ using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.StoragesContracts; using PrecastConcretePlantContracts.ViewModels; -using PrecastConcretePlantDatabaseImplement.Models; +using PrecastConcretePlantDataBaseImplement.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace PrecastConcretePlantDatabaseImplement.Implements +namespace PrecastConcretePlantDataBaseImplement.Implements { public class ComponentStorage : IComponentStorage { diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/OrderStorage.cs index ca07814..6783f5a 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/OrderStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/OrderStorage.cs @@ -3,14 +3,14 @@ using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.StoragesContracts; using PrecastConcretePlantContracts.ViewModels; -using PrecastConcretePlantDatabaseImplement.Models; +using PrecastConcretePlantDataBaseImplement.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace PrecastConcretePlantDatabaseImplement.Implements +namespace PrecastConcretePlantDataBaseImplement.Implements { public class OrderStorage : IOrderStorage { diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ReinforcedStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ReinforcedStorage.cs index 8040823..0d99201 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ReinforcedStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ReinforcedStorage.cs @@ -3,7 +3,7 @@ using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.StoragesContracts; using PrecastConcretePlantContracts.ViewModels; -using PrecastConcretePlantDatabaseImplement.Models; +using PrecastConcretePlantDataBaseImplement.Models; using System; using System.Collections.Generic; using System.Diagnostics; @@ -11,7 +11,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace PrecastConcretePlantDatabaseImplement.Implements +namespace PrecastConcretePlantDataBaseImplement.Implements { public class ReinforcedStorage : IReinforcedStorage { diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..68f0da4 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ShopStorage.cs @@ -0,0 +1,147 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataBaseImplement.Models; +using PrecastConcretePlantDataModels.Models; +using Microsoft.EntityFrameworkCore; + +namespace PrecastConcretePlantDataBaseImplement.Implements +{ + public class ShopStorage : IShopStorage + { + public List GetFullList() + { + using var context = new PrecastConcretePlantDataBase(); + return context.Shops + .Include(x => x.Reinforceds) + .ThenInclude(x => x.Reinforced) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + using var context = new PrecastConcretePlantDataBase(); + return context.Shops + .Include(x => x.Reinforceds) + .ThenInclude(x => x.Reinforced) + .Where(x => x.ShopName.Contains(model.ShopName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + using var context = new PrecastConcretePlantDataBase(); + return context.Shops + .Include(x => x.Reinforceds) + .ThenInclude(x => x.Reinforced) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + using var context = new PrecastConcretePlantDataBase(); + var newShop = Shop.Create(context, model); + if (newShop == null) + { + return null; + } + context.Shops.Add(newShop); + context.SaveChanges(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + using var context = new PrecastConcretePlantDataBase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var shop = context.Shops.FirstOrDefault(rec => rec.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + context.SaveChanges(); + shop.UpdateReinforceds(context, model); + transaction.Commit(); + return shop.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + using var context = new PrecastConcretePlantDataBase(); + var element = context.Shops + .Include(x => x.Reinforceds) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Shops.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + //продажа изделий + public bool MakeSale(IReinforcedModel model, int count) + { + using var context = new PrecastConcretePlantDataBase(); + using var transaction = context.Database.BeginTransaction(); + try + { + foreach (var shop in context.Shops.Include(x => x.Reinforceds).ThenInclude(x => x.Reinforced) + .Where(x => x.Reinforceds.Any(x => x.ReinforcedId == model.Id)) + .ToList()) + { + var reinforced = shop.ShopReinforceds[model.Id]; + int min = Math.Min(reinforced.Item2, count); + if (min == reinforced.Item2) + { + shop.ShopReinforceds.Remove(model.Id); + } + else + { + shop.ShopReinforceds[model.Id] = (reinforced.Item1, reinforced.Item2 - min); + } + shop.UpdateReinforceds(context, new() { Id = shop.Id, ShopReinforceds = shop.ShopReinforceds }); + count -= min; + if (count == 0) + { + context.SaveChanges(); + transaction.Commit(); + return true; + } + } + transaction.Rollback(); + return false; + } + catch + { + transaction.Rollback(); + throw; + } + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240404165842_InitialCreate.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240404165842_InitialCreate.Designer.cs index 482e1e4..15d6415 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240404165842_InitialCreate.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240404165842_InitialCreate.Designer.cs @@ -5,11 +5,11 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using PrecastConcretePlantDatabaseImplement; +using PrecastConcretePlantDataBaseImplement; #nullable disable -namespace PrecastConcretePlantDatabaseImplement.Migrations +namespace PrecastConcretePlantDataBaseImplement.Migrations { [DbContext(typeof(PrecastConcretePlantDataBase))] [Migration("20240404165842_InitialCreate")] @@ -25,7 +25,7 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Component", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -45,7 +45,7 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.ToTable("Components"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Order", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -78,7 +78,7 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.ToTable("Orders"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Reinforced", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -98,7 +98,7 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.ToTable("Reinforceds"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.ReinforcedComponent", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -124,9 +124,9 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.ToTable("ReinforcedComponents"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Order", b => { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + b.HasOne("PrecastConcretePlantDataBaseImplement.Models.Reinforced", "Reinforced") .WithMany("Orders") .HasForeignKey("ReinforcedId") .OnDelete(DeleteBehavior.Cascade) @@ -135,15 +135,15 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Navigation("Reinforced"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.ReinforcedComponent", b => { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component") + b.HasOne("PrecastConcretePlantDataBaseImplement.Models.Component", "Component") .WithMany("ReinforcedComponents") .HasForeignKey("ComponentId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + b.HasOne("PrecastConcretePlantDataBaseImplement.Models.Reinforced", "Reinforced") .WithMany("Components") .HasForeignKey("ReinforcedId") .OnDelete(DeleteBehavior.Cascade) @@ -154,12 +154,12 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Navigation("Reinforced"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Component", b => { b.Navigation("ReinforcedComponents"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Reinforced", b => { b.Navigation("Components"); diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240404165842_InitialCreate.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240404165842_InitialCreate.cs index cd4beed..eaed367 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240404165842_InitialCreate.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240404165842_InitialCreate.cs @@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations; #nullable disable -namespace PrecastConcretePlantDatabaseImplement.Migrations +namespace PrecastConcretePlantDataBaseImplement.Migrations { /// public partial class InitialCreate : Migration diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240516193152_initial.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240516193152_initial.Designer.cs new file mode 100644 index 0000000..0685bff --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240516193152_initial.Designer.cs @@ -0,0 +1,250 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using PrecastConcretePlantDataBaseImplement; + +#nullable disable + +namespace PrecastConcretePlantDataBaseImplement.Migrations +{ + [DbContext(typeof(PrecastConcretePlantDataBase))] + [Migration("20240516193152_initial")] + partial class initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Reinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Reinforceds"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.ReinforcedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpening") + .HasColumnType("datetime2"); + + b.Property("ReinforcedsMax") + .HasColumnType("int"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.ShopReinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ReinforcedId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopReinforceds"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Order", b => + { + b.HasOne("PrecastConcretePlantDataBaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Orders") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.ReinforcedComponent", b => + { + b.HasOne("PrecastConcretePlantDataBaseImplement.Models.Component", "Component") + .WithMany("ReinforcedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDataBaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Components") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.ShopReinforced", b => + { + b.HasOne("PrecastConcretePlantDataBaseImplement.Models.Reinforced", "Reinforced") + .WithMany("ShopReinforceds") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDataBaseImplement.Models.Shop", "Shop") + .WithMany("Reinforceds") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Reinforced"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Component", b => + { + b.Navigation("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Reinforced", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + + b.Navigation("ShopReinforceds"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Shop", b => + { + b.Navigation("Reinforceds"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240516193152_initial.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240516193152_initial.cs new file mode 100644 index 0000000..049fe2d --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240516193152_initial.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PrecastConcretePlantDataBaseImplement.Migrations +{ + /// + public partial class initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopName = table.Column(type: "nvarchar(max)", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: false), + DateOpening = table.Column(type: "datetime2", nullable: false), + ReinforcedsMax = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ShopReinforceds", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopId = table.Column(type: "int", nullable: false), + ReinforcedId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopReinforceds", x => x.Id); + table.ForeignKey( + name: "FK_ShopReinforceds_Reinforceds_ReinforcedId", + column: x => x.ReinforcedId, + principalTable: "Reinforceds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopReinforceds_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ShopReinforceds_ReinforcedId", + table: "ShopReinforceds", + column: "ReinforcedId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopReinforceds_ShopId", + table: "ShopReinforceds", + column: "ShopId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ShopReinforceds"); + + migrationBuilder.DropTable( + name: "Shops"); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs index 49f864c..a58218f 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs @@ -4,11 +4,11 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using PrecastConcretePlantDatabaseImplement; +using PrecastConcretePlantDataBaseImplement; #nullable disable -namespace PrecastConcretePlantDatabaseImplement.Migrations +namespace PrecastConcretePlantDataBaseImplement.Migrations { [DbContext(typeof(PrecastConcretePlantDataBase))] partial class PrecastConcretePlantDataBaseModelSnapshot : ModelSnapshot @@ -22,7 +22,7 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Component", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -42,7 +42,7 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.ToTable("Components"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Order", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -75,7 +75,7 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.ToTable("Orders"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Reinforced", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -95,7 +95,7 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.ToTable("Reinforceds"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.ReinforcedComponent", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -121,9 +121,62 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.ToTable("ReinforcedComponents"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Shop", b => { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpening") + .HasColumnType("datetime2"); + + b.Property("ReinforcedsMax") + .HasColumnType("int"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.ShopReinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ReinforcedId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopReinforceds"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Order", b => + { + b.HasOne("PrecastConcretePlantDataBaseImplement.Models.Reinforced", "Reinforced") .WithMany("Orders") .HasForeignKey("ReinforcedId") .OnDelete(DeleteBehavior.Cascade) @@ -132,15 +185,15 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Navigation("Reinforced"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.ReinforcedComponent", b => { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component") + b.HasOne("PrecastConcretePlantDataBaseImplement.Models.Component", "Component") .WithMany("ReinforcedComponents") .HasForeignKey("ComponentId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + b.HasOne("PrecastConcretePlantDataBaseImplement.Models.Reinforced", "Reinforced") .WithMany("Components") .HasForeignKey("ReinforcedId") .OnDelete(DeleteBehavior.Cascade) @@ -151,16 +204,42 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Navigation("Reinforced"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.ShopReinforced", b => + { + b.HasOne("PrecastConcretePlantDataBaseImplement.Models.Reinforced", "Reinforced") + .WithMany("ShopReinforceds") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDataBaseImplement.Models.Shop", "Shop") + .WithMany("Reinforceds") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Reinforced"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Component", b => { b.Navigation("ReinforcedComponents"); }); - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Reinforced", b => { b.Navigation("Components"); b.Navigation("Orders"); + + b.Navigation("ShopReinforceds"); + }); + + modelBuilder.Entity("PrecastConcretePlantDataBaseImplement.Models.Shop", b => + { + b.Navigation("Reinforceds"); }); #pragma warning restore 612, 618 } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Component.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Component.cs index bf70c0e..02fd5ca 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Component.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Component.cs @@ -9,7 +9,7 @@ using PrecastConcretePlantDataModels.Models; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.ViewModels; -namespace PrecastConcretePlantDatabaseImplement.Models +namespace PrecastConcretePlantDataBaseImplement.Models { public class Component : IComponentModel { diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs index 026b549..0c2b8d7 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs @@ -9,7 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace PrecastConcretePlantDatabaseImplement.Models +namespace PrecastConcretePlantDataBaseImplement.Models { public class Order : IOrderModel { diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Reinforced.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Reinforced.cs index 33a4d2e..072a32c 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Reinforced.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Reinforced.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.ViewModels; -namespace PrecastConcretePlantDatabaseImplement.Models +namespace PrecastConcretePlantDataBaseImplement.Models { public class Reinforced : IReinforcedModel { @@ -45,6 +45,9 @@ namespace PrecastConcretePlantDatabaseImplement.Models [ForeignKey("ReinforcedId")] public virtual List Orders { get; set; } = new(); + [ForeignKey("ReinforcedId")] + public virtual List ShopReinforceds { get; set; } = new(); + public static Reinforced Create(PrecastConcretePlantDataBase context, ReinforcedBindingModel model) { return new Reinforced() diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/ReinforcedComponent.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/ReinforcedComponent.cs index ccf8a49..933bdbd 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/ReinforcedComponent.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/ReinforcedComponent.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace PrecastConcretePlantDatabaseImplement.Models +namespace PrecastConcretePlantDataBaseImplement.Models { public class ReinforcedComponent { diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs new file mode 100644 index 0000000..d7a7901 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Shop.cs @@ -0,0 +1,110 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; + +namespace PrecastConcretePlantDataBaseImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; set; } + + [Required] + public string ShopName { get; set; } = string.Empty; + + [Required] + public string Address { get; set; } = string.Empty; + + [Required] + public DateTime DateOpening { get; set; } + + [Required] + public int ReinforcedsMax { get; set; } + + private Dictionary? _shopReinforceds = null; + + [NotMapped] + public Dictionary ShopReinforceds + { + get + { + if (_shopReinforceds == null) + { + _shopReinforceds = Reinforceds + .ToDictionary(x => x.ReinforcedId, x => (x.Reinforced as IReinforcedModel, x.Count)); + } + return _shopReinforceds; + } + } + //3ий вопрос + [ForeignKey("ShopId")]//список записей класса-связи + public virtual List Reinforceds { get; set; } = new(); + + public static Shop Create(PrecastConcretePlantDataBase context, ShopBindingModel model) + { + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + ReinforcedsMax = model.ReinforcedsMax, + Reinforceds = model.ShopReinforceds.Select(x => new ShopReinforced + { + Reinforced = context.Reinforceds.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + + public void Update(ShopBindingModel model) + { + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + ReinforcedsMax = model.ReinforcedsMax; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + ReinforcedsMax = ReinforcedsMax, + ShopReinforceds = ShopReinforceds + }; + + public void UpdateReinforceds(PrecastConcretePlantDataBase context, ShopBindingModel model) + { + var shopReinforceds = context.ShopReinforceds.Where(rec => rec.ShopId == model.Id).ToList(); + if (shopReinforceds != null && shopReinforceds.Count > 0) + { + context.ShopReinforceds.RemoveRange(shopReinforceds.Where(rec => !model.ShopReinforceds.ContainsKey(rec.ReinforcedId))); + context.SaveChanges(); + foreach (var updateReinforced in shopReinforceds) + { + if (model.ShopReinforceds.ContainsKey(updateReinforced.ReinforcedId)) + { + updateReinforced.Count = model.ShopReinforceds[updateReinforced.ReinforcedId].Item2; + model.ShopReinforceds.Remove(updateReinforced.ReinforcedId); + } + } + context.SaveChanges(); + } + var shop = context.Shops.First(x => x.Id == Id); + foreach (var ic in model.ShopReinforceds) + { + context.ShopReinforceds.Add(new ShopReinforced + { + Shop = shop, + Reinforced = context.Reinforceds.First(x => x.Id == ic.Key), + Count = ic.Value.Item2 + }); + context.SaveChanges(); + } + _shopReinforceds = null; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/ShopReinforced.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/ShopReinforced.cs new file mode 100644 index 0000000..7350452 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/ShopReinforced.cs @@ -0,0 +1,22 @@ +using System.ComponentModel.DataAnnotations; + +namespace PrecastConcretePlantDataBaseImplement.Models +{ + public class ShopReinforced + { + public int Id { get; set; } + + [Required] + public int ShopId { get; set; } + + [Required] + public int ReinforcedId { get; set; } + + [Required] + public int Count { get; set; } + + public virtual Reinforced Reinforced { get; set; } = new(); + + public virtual Shop Shop { get; set; } = new(); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabase.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabase.cs index ee2f033..d31bc68 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabase.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabase.cs @@ -1,5 +1,5 @@ using Microsoft.EntityFrameworkCore; -using PrecastConcretePlantDatabaseImplement.Models; +using PrecastConcretePlantDataBaseImplement.Models; using System; using System.Collections.Generic; using System.Diagnostics; @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace PrecastConcretePlantDatabaseImplement +namespace PrecastConcretePlantDataBaseImplement { public class PrecastConcretePlantDataBase : DbContext { @@ -15,7 +15,7 @@ namespace PrecastConcretePlantDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=PRETTYNAME;Initial Catalog=PrecastConcretePlantDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=PRETTYNAME;Initial Catalog=PrecastConcretePlantDataBaseHard;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } @@ -23,6 +23,7 @@ namespace PrecastConcretePlantDatabaseImplement public virtual DbSet Reinforceds { set; get; } public virtual DbSet ReinforcedComponents { set; get; } public virtual DbSet Orders { set; get; } - + public virtual DbSet Shops { set; get; } + public virtual DbSet ShopReinforceds { set; get; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj b/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj index 5db35b1..bf7ef5d 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj +++ b/PrecastConcretePlant/PrecastConcretePlantView/PrecastConcretePlantView.csproj @@ -27,7 +27,7 @@ - + diff --git a/PrecastConcretePlant/PrecastConcretePlantView/Program.cs b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs index d1dbea4..bdbf122 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs @@ -3,6 +3,9 @@ using PrecastConcretePlantBusinessLogic.BusinessLogics; using PrecastConcretePlantContracts.StoragesContracts; using PrecastConcretePlantFileImplement.Implements; using System; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; namespace PrecastConcretePlantView {