From 71f949f540b7aa6373fc8f2c56243524e4848a8c Mon Sep 17 00:00:00 2001 From: Artyom_Yashin Date: Mon, 12 Feb 2024 19:42:41 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=94=D0=B5=D0=BD=D1=8C=201960.=20=D0=9A?= =?UTF-8?q?=D0=B0=D0=BA=20=D1=8F=20=D0=B8=20=D0=BF=D0=BE=D0=BB=D0=B0=D0=B3?= =?UTF-8?q?=D0=B0=D0=BB,=20=D0=BF=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=B1=D1=8B=D0=BB=D0=B0=20=D1=81=D0=BB=D0=BE=D0=B2?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BA=D1=80=D0=B5=D1=89=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BE=D0=B3=D0=BD=D0=B5=D0=BC=20=D0=B4=D0=BB=D1=8F=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B5=D0=B3=D0=BE=20=D0=B8=D0=B7=D0=BD=D0=B5=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BC=D0=B5=D1=81=D1=8F=D1=87?= =?UTF-8?q?=D0=BD=D1=8B=D0=BC=20=D0=BE=D1=82=D0=B4=D1=8B=D1=85=D0=BE=D0=BC?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B7=D1=83=D0=BC=D0=B0.=20=D0=A3=D1=81=D0=BB?= =?UTF-8?q?=D0=BE=D0=B6=D0=BD=D0=B5=D0=BD=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B9=20=D0=BB=D0=B0=D0=B1?= =?UTF-8?q?=D1=8B=20=D0=B1=D1=8B=D0=BB=D0=B0=20=D1=81=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0=20=D1=81=20=D1=82=D0=B0=D0=BA=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=BB=D0=B5=D0=B3=D0=BA=D0=BE=D1=81=D1=82=D1=8C=D1=8E=20=D0=B8?= =?UTF-8?q?=20=D0=BD=D0=B5=D0=BF=D1=80=D0=B8=D0=BD=D1=83=D0=B6=D0=B4=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=BE=D1=81=D1=82=D1=8C=D1=8E,=20=D1=87=D1=82?= =?UTF-8?q?=D0=BE=20=D0=B4=D0=B0=D0=B6=D0=B5=20=D0=B1=D1=8B=D0=BB=D0=BE=20?= =?UTF-8?q?=D1=82=D1=80=D1=83=D0=B4=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=B8=D1=82=D1=8C,=20=D1=87=D1=82=D0=BE=20=D1=8D=D1=82?= =?UTF-8?q?=D0=BE=20=D0=B2=D0=B7=D0=B0=D0=BF=D1=80=D0=B0=D0=B2=D0=B4=D1=83?= =?UTF-8?q?.=20=D0=92=D0=BF=D0=B5=D1=80=D0=B2=D1=8B=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=D1=81=D0=BB=D0=B5=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=BE=D0=B9=20=D0=BB=D0=B0=D0=B1=D1=8B=20=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=83=D1=81=D1=82=D0=B2=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=BF=D1=80=D0=B8=D0=BB=D0=B8=D0=B2=20=D1=8D=D0=BD?= =?UTF-8?q?=D0=B4=D0=BE=D1=80=D1=84=D0=B8=D0=BD=D0=B0.=20=D0=AD=D1=82?= =?UTF-8?q?=D0=BE=20=D0=B1=D1=8B=D0=BB=20=D1=81=D0=BB=D0=BE=D0=B2=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B3=D0=BB=D0=BE=D1=82=D0=BE=D0=BA=20=D1=81=D0=B2?= =?UTF-8?q?=D0=B5=D0=B6=D0=B5=D0=B3=D0=BE=20=D0=B2=D0=BE=D0=B7=D0=B4=D1=83?= =?UTF-8?q?=D1=85=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B3=D1=80=D1=83=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=B2?= =?UTF-8?q?=D0=BE=20=D1=82=D1=8C=D0=BC=D1=83.=20=D0=98=20=D0=B8=D0=BC?= =?UTF-8?q?=D1=8F=20=D0=B5=D0=B9=20=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=20=E2=84=962...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ComputersShop/FormMain.Designer.cs | 24 ++- ComputersShop/ComputersShop/FormMain.cs | 18 ++ .../ComputersShop/FormShop.Designer.cs | 202 ++++++++++++++++++ ComputersShop/ComputersShop/FormShop.cs | 123 +++++++++++ ComputersShop/ComputersShop/FormShop.resx | 123 +++++++++++ .../ComputersShop/FormShops.Designer.cs | 119 +++++++++++ ComputersShop/ComputersShop/FormShops.cs | 118 ++++++++++ ComputersShop/ComputersShop/FormShops.resx | 120 +++++++++++ .../ComputersShop/FormSupply.Designer.cs | 113 ++++++++++ ComputersShop/ComputersShop/FormSupply.cs | 151 +++++++++++++ ComputersShop/ComputersShop/FormSupply.resx | 120 +++++++++++ ComputersShop/ComputersShop/Program.cs | 5 + .../BusinessLogics/ShopLogic.cs | 134 ++++++++++++ .../BindingModels/ShopBindingModel.cs | 18 ++ .../BisnessLogicsContracts/IShopLogic.cs | 22 ++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 23 ++ .../ViewModels/ShopViewModel.cs | 22 ++ .../ComputersShopDataModels/IShopModel.cs | 16 ++ .../DataListSingleton.cs | 3 + .../Implements/ShopStorage.cs | 139 ++++++++++++ .../ComputersShopListImplement/Models/Shop.cs | 55 +++++ 22 files changed, 1679 insertions(+), 3 deletions(-) create mode 100644 ComputersShop/ComputersShop/FormShop.Designer.cs create mode 100644 ComputersShop/ComputersShop/FormShop.cs create mode 100644 ComputersShop/ComputersShop/FormShop.resx create mode 100644 ComputersShop/ComputersShop/FormShops.Designer.cs create mode 100644 ComputersShop/ComputersShop/FormShops.cs create mode 100644 ComputersShop/ComputersShop/FormShops.resx create mode 100644 ComputersShop/ComputersShop/FormSupply.Designer.cs create mode 100644 ComputersShop/ComputersShop/FormSupply.cs create mode 100644 ComputersShop/ComputersShop/FormSupply.resx create mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs create mode 100644 ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IShopLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/SearchModels/ShopSearchModel.cs create mode 100644 ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs create mode 100644 ComputersShop/ComputersShopDataModels/IShopModel.cs create mode 100644 ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs create mode 100644 ComputersShop/ComputersShopListImplement/Models/Shop.cs diff --git a/ComputersShop/ComputersShop/FormMain.Designer.cs b/ComputersShop/ComputersShop/FormMain.Designer.cs index bd23346..b98f17a 100644 --- a/ComputersShop/ComputersShop/FormMain.Designer.cs +++ b/ComputersShop/ComputersShop/FormMain.Designer.cs @@ -32,6 +32,8 @@ справочникиToolStripMenuItem = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem(); компьютерыToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + поставкиToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); @@ -54,7 +56,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, компьютерыToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, компьютерыToolStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -62,17 +64,31 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(184, 26); + компонентыToolStripMenuItem.Size = new Size(224, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += ComponentsStripMenuItem_Click; // // компьютерыToolStripMenuItem // компьютерыToolStripMenuItem.Name = "компьютерыToolStripMenuItem"; - компьютерыToolStripMenuItem.Size = new Size(184, 26); + компьютерыToolStripMenuItem.Size = new Size(224, 26); компьютерыToolStripMenuItem.Text = "Компьютеры"; компьютерыToolStripMenuItem.Click += ComputersStripMenuItem_Click; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // поставкиToolStripMenuItem + // + поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem"; + поставкиToolStripMenuItem.Size = new Size(224, 26); + поставкиToolStripMenuItem.Text = "Поставки"; + поставкиToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; + // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -168,5 +184,7 @@ private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRefresh; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem поставкиToolStripMenuItem; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormMain.cs b/ComputersShop/ComputersShop/FormMain.cs index d55f106..d98dfac 100644 --- a/ComputersShop/ComputersShop/FormMain.cs +++ b/ComputersShop/ComputersShop/FormMain.cs @@ -69,6 +69,24 @@ namespace ComputersShop } } + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); + if (service is FormSupply form) + { + form.ShowDialog(); + } + } + private void CreateOrderButton_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); diff --git a/ComputersShop/ComputersShop/FormShop.Designer.cs b/ComputersShop/ComputersShop/FormShop.Designer.cs new file mode 100644 index 0000000..1321c68 --- /dev/null +++ b/ComputersShop/ComputersShop/FormShop.Designer.cs @@ -0,0 +1,202 @@ +namespace ComputersShop +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + DateTimePicker = new DateTimePicker(); + NameTextBox = new TextBox(); + AddressTextBox = new TextBox(); + NameLabel = new Label(); + AdressLabel = new Label(); + DateLabel = new Label(); + SaveButton = new Button(); + CancelButton = new Button(); + DataGridView = new DataGridView(); + ID = new DataGridViewTextBoxColumn(); + Name = new DataGridViewTextBoxColumn(); + Price = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DateTimePicker + // + DateTimePicker.Location = new Point(97, 93); + DateTimePicker.Margin = new Padding(3, 4, 3, 4); + DateTimePicker.Name = "DateTimePicker"; + DateTimePicker.Size = new Size(363, 27); + DateTimePicker.TabIndex = 0; + // + // NameTextBox + // + NameTextBox.Location = new Point(97, 16); + NameTextBox.Margin = new Padding(3, 4, 3, 4); + NameTextBox.Name = "NameTextBox"; + NameTextBox.Size = new Size(363, 27); + NameTextBox.TabIndex = 1; + // + // AddressTextBox + // + AddressTextBox.Location = new Point(97, 55); + AddressTextBox.Margin = new Padding(3, 4, 3, 4); + AddressTextBox.Name = "AddressTextBox"; + AddressTextBox.Size = new Size(363, 27); + AddressTextBox.TabIndex = 2; + // + // NameLabel + // + NameLabel.AutoSize = true; + NameLabel.Location = new Point(14, 20); + NameLabel.Name = "NameLabel"; + NameLabel.Size = new Size(77, 20); + NameLabel.TabIndex = 3; + NameLabel.Text = "Название"; + // + // AdressLabel + // + AdressLabel.AutoSize = true; + AdressLabel.Location = new Point(14, 59); + AdressLabel.Name = "AdressLabel"; + AdressLabel.Size = new Size(51, 20); + AdressLabel.TabIndex = 4; + AdressLabel.Text = "Адрес"; + // + // DateLabel + // + DateLabel.AutoSize = true; + DateLabel.Location = new Point(14, 101); + DateLabel.Name = "DateLabel"; + DateLabel.Size = new Size(41, 20); + DateLabel.TabIndex = 5; + DateLabel.Text = "Дата"; + // + // SaveButton + // + SaveButton.Location = new Point(282, 340); + SaveButton.Margin = new Padding(3, 4, 3, 4); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(86, 31); + SaveButton.TabIndex = 6; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // CancelButton + // + CancelButton.Location = new Point(375, 340); + CancelButton.Margin = new Padding(3, 4, 3, 4); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(86, 31); + CancelButton.TabIndex = 7; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += CancelButton_Click; + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, Name, Price, Count }); + DataGridView.Location = new Point(14, 132); + DataGridView.Margin = new Padding(3, 4, 3, 4); + DataGridView.Name = "DataGridView"; + DataGridView.RowHeadersWidth = 51; + DataGridView.Size = new Size(447, 200); + DataGridView.TabIndex = 8; + // + // ID + // + ID.HeaderText = "id"; + ID.MinimumWidth = 6; + ID.Name = "ID"; + ID.Visible = false; + ID.Width = 125; + // + // Name + // + Name.HeaderText = "Название"; + Name.MinimumWidth = 6; + Name.Name = "Name"; + Name.ReadOnly = true; + Name.Width = 150; + // + // Price + // + Price.HeaderText = "Цена"; + Price.MinimumWidth = 6; + Price.Name = "Price"; + Price.ReadOnly = true; + Price.Width = 125; + // + // Count + // + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + Count.ReadOnly = true; + Count.Width = 125; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(470, 380); + Controls.Add(DataGridView); + Controls.Add(CancelButton); + Controls.Add(SaveButton); + Controls.Add(DateLabel); + Controls.Add(AdressLabel); + Controls.Add(NameLabel); + Controls.Add(AddressTextBox); + Controls.Add(NameTextBox); + Controls.Add(DateTimePicker); + Margin = new Padding(3, 4, 3, 4); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DateTimePicker DateTimePicker; + private TextBox NameTextBox; + private TextBox AddressTextBox; + private Label NameLabel; + private Label AdressLabel; + private Label DateLabel; + private Button SaveButton; + private Button CancelButton; + private DataGridView DataGridView; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn Name; + private DataGridViewTextBoxColumn Price; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormShop.cs b/ComputersShop/ComputersShop/FormShop.cs new file mode 100644 index 0000000..34cf3f0 --- /dev/null +++ b/ComputersShop/ComputersShop/FormShop.cs @@ -0,0 +1,123 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopDataModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ComputersShop +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public int? _id; + private Dictionary _Computers; + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); + if (shop != null) + { + NameTextBox.Text = shop.ShopName; + AddressTextBox.Text = shop.Address; + DateTimePicker.Text = shop.DateOpen.ToString(); + _Computers = shop.ShopComputers; + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка товаров магазина"); + try + { + if (_Computers != null) + { + foreach (var Computer in _Computers) + { + DataGridView.Rows.Add(new object[] { Computer.Key, Computer.Value.Item1.ComputerName, Computer.Value.Item1.Price, Computer.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(NameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(AddressTextBox.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = NameTextBox.Text, + Address = AddressTextBox.Text, + DateOpen = DateTimePicker.Value.Date, + ShopComputers = _Computers + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/ComputersShop/ComputersShop/FormShop.resx b/ComputersShop/ComputersShop/FormShop.resx new file mode 100644 index 0000000..17b1a67 --- /dev/null +++ b/ComputersShop/ComputersShop/FormShop.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormShops.Designer.cs b/ComputersShop/ComputersShop/FormShops.Designer.cs new file mode 100644 index 0000000..dab691c --- /dev/null +++ b/ComputersShop/ComputersShop/FormShops.Designer.cs @@ -0,0 +1,119 @@ +namespace ComputersShop +{ + 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(); + AddButton = new Button(); + UpdateButton = new Button(); + RefreshButton = new Button(); + DeleteButton = new Button(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(14, 16); + DataGridView.Margin = new Padding(3, 4, 3, 4); + DataGridView.Name = "DataGridView"; + DataGridView.RowHeadersWidth = 51; + DataGridView.Size = new Size(449, 499); + DataGridView.TabIndex = 0; + // + // AddButton + // + AddButton.Location = new Point(470, 16); + AddButton.Margin = new Padding(3, 4, 3, 4); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(130, 31); + AddButton.TabIndex = 1; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; + // + // UpdateButton + // + UpdateButton.Location = new Point(470, 55); + UpdateButton.Margin = new Padding(3, 4, 3, 4); + UpdateButton.Name = "UpdateButton"; + UpdateButton.Size = new Size(130, 31); + UpdateButton.TabIndex = 2; + UpdateButton.Text = "Изменить"; + UpdateButton.UseVisualStyleBackColor = true; + UpdateButton.Click += UpdateButton_Click; + // + // RefreshButton + // + RefreshButton.Location = new Point(470, 93); + RefreshButton.Margin = new Padding(3, 4, 3, 4); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(130, 31); + RefreshButton.TabIndex = 3; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(470, 132); + DeleteButton.Margin = new Padding(3, 4, 3, 4); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(130, 31); + DeleteButton.TabIndex = 4; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(616, 537); + Controls.Add(DeleteButton); + Controls.Add(RefreshButton); + Controls.Add(UpdateButton); + Controls.Add(AddButton); + Controls.Add(DataGridView); + Margin = new Padding(3, 4, 3, 4); + Name = "FormShops"; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button UpdateButton; + private Button RefreshButton; + private Button DeleteButton; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormShops.cs b/ComputersShop/ComputersShop/FormShops.cs new file mode 100644 index 0000000..a938087 --- /dev/null +++ b/ComputersShop/ComputersShop/FormShops.cs @@ -0,0 +1,118 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BisnessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ComputersShop +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["ShopComputers"].Visible = false; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void AddButton_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 UpdateButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + var tmp = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + form._id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} diff --git a/ComputersShop/ComputersShop/FormShops.resx b/ComputersShop/ComputersShop/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ComputersShop/ComputersShop/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/ComputersShop/ComputersShop/FormSupply.Designer.cs b/ComputersShop/ComputersShop/FormSupply.Designer.cs new file mode 100644 index 0000000..6a51fd3 --- /dev/null +++ b/ComputersShop/ComputersShop/FormSupply.Designer.cs @@ -0,0 +1,113 @@ +namespace ComputersShop +{ + partial class FormSupply + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + ShopComboBox = new ComboBox(); + ComputerComboBox = new ComboBox(); + CountTextBox = new TextBox(); + SaveButton = new Button(); + CancelButton = new Button(); + SuspendLayout(); + // + // ShopComboBox + // + ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ShopComboBox.FormattingEnabled = true; + ShopComboBox.Location = new Point(14, 16); + ShopComboBox.Margin = new Padding(3, 4, 3, 4); + ShopComboBox.Name = "ShopComboBox"; + ShopComboBox.Size = new Size(378, 28); + ShopComboBox.TabIndex = 0; + // + // ComputerComboBox + // + ComputerComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ComputerComboBox.FormattingEnabled = true; + ComputerComboBox.Location = new Point(14, 55); + ComputerComboBox.Margin = new Padding(3, 4, 3, 4); + ComputerComboBox.Name = "ComputerComboBox"; + ComputerComboBox.Size = new Size(378, 28); + ComputerComboBox.TabIndex = 1; + // + // CountTextBox + // + CountTextBox.Location = new Point(14, 93); + CountTextBox.Margin = new Padding(3, 4, 3, 4); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(378, 27); + CountTextBox.TabIndex = 2; + // + // SaveButton + // + SaveButton.Location = new Point(214, 132); + SaveButton.Margin = new Padding(3, 4, 3, 4); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(86, 31); + SaveButton.TabIndex = 3; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // CancelButton + // + CancelButton.Location = new Point(306, 132); + CancelButton.Margin = new Padding(3, 4, 3, 4); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(86, 31); + CancelButton.TabIndex = 4; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += CancelButton_Click; + // + // FormSupply + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(406, 181); + Controls.Add(CancelButton); + Controls.Add(SaveButton); + Controls.Add(CountTextBox); + Controls.Add(ComputerComboBox); + Controls.Add(ShopComboBox); + Margin = new Padding(3, 4, 3, 4); + Name = "FormSupply"; + Text = "Поставки"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox ShopComboBox; + private ComboBox ComputerComboBox; + private TextBox CountTextBox; + private Button SaveButton; + private Button CancelButton; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormSupply.cs b/ComputersShop/ComputersShop/FormSupply.cs new file mode 100644 index 0000000..9e3b534 --- /dev/null +++ b/ComputersShop/ComputersShop/FormSupply.cs @@ -0,0 +1,151 @@ +using ComputersShopContracts.BisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; +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 ComputersShop +{ + public partial class FormSupply : Form + { + private readonly List? _ComputerList; + private readonly List? _shopsList; + IShopLogic _shopLogic; + IComputerLogic _ComputerLogic; + public int ShopId + { + get + { + return + Convert.ToInt32(ShopComboBox.SelectedValue); + } + set + { + ShopComboBox.SelectedValue = value; + } + } + public int ComputerId + { + get + { + return + Convert.ToInt32(ComputerComboBox.SelectedValue); + } + set + { + ComputerComboBox.SelectedValue = value; + } + } + + public IComputerModel? ComputerModel + { + get + { + if (_ComputerList == null) + { + return null; + } + foreach (var elem in _ComputerList) + { + if (elem.Id == ComputerId) + { + return elem; + } + } + return null; + } + } + + + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set + { CountTextBox.Text = value.ToString(); } + } + public FormSupply(IComputerLogic ComputerLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _ComputerLogic = ComputerLogic; + _ComputerList = ComputerLogic.ReadList(null); + _shopsList = shopLogic.ReadList(null); + if (_ComputerList != null) + { + ComputerComboBox.DisplayMember = "ComputerName"; + ComputerComboBox.ValueMember = "Id"; + ComputerComboBox.DataSource = _ComputerList; + ComputerComboBox.SelectedItem = null; + } + if (_shopsList != null) + { + ShopComboBox.DisplayMember = "ShopName"; + ShopComboBox.ValueMember = "Id"; + ShopComboBox.DataSource = _shopsList; + ShopComboBox.SelectedItem = null; + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ComputerComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите мороженное", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ShopComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + int count = Convert.ToInt32(CountTextBox.Text); + + bool res = _shopLogic.MakeSupply( + new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) }, + _ComputerLogic.ReadElement(new() { Id = Convert.ToInt32(ComputerComboBox.SelectedValue) }), + count + ); + + if (!res) + { + throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); + } + + MessageBox.Show("Пополнение прошло успешно"); + DialogResult = DialogResult.OK; + Close(); + + } + catch (Exception err) + { + MessageBox.Show("Ошибка пополнения"); + return; + } + } + + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/ComputersShop/ComputersShop/FormSupply.resx b/ComputersShop/ComputersShop/FormSupply.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ComputersShop/ComputersShop/FormSupply.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ComputersShop/ComputersShop/Program.cs b/ComputersShop/ComputersShop/Program.cs index 978e7b7..05f680d 100644 --- a/ComputersShop/ComputersShop/Program.cs +++ b/ComputersShop/ComputersShop/Program.cs @@ -41,6 +41,8 @@ namespace ComputersShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -48,6 +50,9 @@ namespace ComputersShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..26e3887 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,134 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopBusinessLogic.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:{Name}. Id:{ Id}", model?.Name, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + + } + + public bool MakeSupply(ShopSearchModel model, IComputerModel Computer, int count) + { + if (model == null) + return false; + return _shopStorage.SupplyComputer(model, Computer, count); + } + + public ShopViewModel ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Нет названия магазина", + nameof(model.ShopName)); + } + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Нет адресса магазина", + nameof(model.ShopName)); + } + if (model.DateOpen == null) + { + throw new ArgumentNullException("Нет даты открытия магазина", + nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}", model.ShopName, model.Address, model.DateOpen, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..babdad9 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,18 @@ +using ComputersShopDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } + public string Address { get; set; } + public DateTime DateOpen { get; set; } + public Dictionary ShopComputers { get; set; } = new(); + } +} diff --git a/ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IShopLogic.cs b/ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..72ca341 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BisnessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.BisnessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool MakeSupply(ShopSearchModel model, IComputerModel computer, int count); + } +} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/ShopSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..228bd84 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..2627905 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,23 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? GetElement(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + bool SupplyComputer(ShopSearchModel model, IComputerModel computer, int Count); + } +} diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..3c39f56 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,22 @@ +using ComputersShopDataModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название магазина")] + public string ShopName { get; set; } + [DisplayName("Адрес магазина")] + public string Address { get; set; } + [DisplayName("Дата открытия")] + public DateTime DateOpen { get; set; } + public Dictionary ShopComputers { get; set; } = new(); + } +} diff --git a/ComputersShop/ComputersShopDataModels/IShopModel.cs b/ComputersShop/ComputersShopDataModels/IShopModel.cs new file mode 100644 index 0000000..c6f0d48 --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/IShopModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataModels +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Address { get; } + DateTime DateOpen { get; } + Dictionary ShopComputers { get; } + } +} diff --git a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs index 1b0012b..a84abe3 100644 --- a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs +++ b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs @@ -8,11 +8,14 @@ namespace ComputersShopListImplement public List Components { get; set; } public List Orders { get; set; } public List Computers { get; set; } + public List Shops { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Computers = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..c3d6b48 --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs @@ -0,0 +1,139 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; +using ComputersShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.Name)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.Name)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.Name) && + shop.ShopName == model.Name) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public bool SupplyComputer(ShopSearchModel model, IComputerModel Computer, int count) + { + if (model == null) + throw new ArgumentNullException(nameof(model)); + if (Computer == null) + throw new ArgumentNullException(nameof(Computer)); + if (count <= 0) + throw new ArgumentNullException("Количество должно быть положительным числом"); + + ShopViewModel curModel = GetElement(model); + if (curModel == null) + throw new ArgumentNullException(nameof(curModel)); + if (curModel.ShopComputers.TryGetValue(Computer.Id, out var pair)) + { + curModel.ShopComputers[Computer.Id] = (pair.Item1, pair.Item2 + count); + } + else + { + curModel.ShopComputers.Add(Computer.Id, (Computer, count)); + } + Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + DateOpen = curModel.DateOpen, + Address = curModel.Address, + ShopComputers = curModel.ShopComputers, + }); + return true; + } + } +} diff --git a/ComputersShop/ComputersShopListImplement/Models/Shop.cs b/ComputersShop/ComputersShopListImplement/Models/Shop.cs new file mode 100644 index 0000000..0b0f3b5 --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Models/Shop.cs @@ -0,0 +1,55 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } + public string Address { get; private set; } + public DateTime DateOpen { get; private set; } + public Dictionary ShopComputers { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + return null; + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + ShopComputers = new() + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + ShopComputers = model.ShopComputers; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + ShopComputers = ShopComputers + }; + } +} From 1fc37afcb68ea77e4244c8a806d1eacbbe4da310 Mon Sep 17 00:00:00 2001 From: Artyom_Yashin Date: Mon, 12 Feb 2024 19:52:24 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=92=D0=B5=D1=87=D0=B5=D1=80=20=D1=82?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=B6=D0=B5=20=D0=B4=D0=BD=D1=8F.=20?= =?UTF-8?q?=D0=9A=D0=BE=D0=BB=D0=B5=D1=81=D0=BE=20=D1=81=D0=B0=D0=BD=D1=81?= =?UTF-8?q?=D0=B0=D1=80=D1=8B=20=D1=81=D0=BE=D0=B2=D0=B5=D1=80=D1=88=D0=B8?= =?UTF-8?q?=D0=BB=D0=BE=20=D0=BE=D0=B1=D0=BE=D1=80=D0=BE=D1=82.=20=D0=93?= =?UTF-8?q?=D0=BB=D1=83=D0=BF=D1=8B=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B8,=20=D0=B2=D0=BB=D0=B5=D0=BA=D1=83=D1=89=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B7=D0=B0=20=D1=81=D0=BE=D0=B1=D0=BE=D0=B9=20=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D1=8C=D0=B5=D0=B7=D0=BD=D1=8B=D0=B5=20=D0=BF=D0=BE=D1=81?= =?UTF-8?q?=D0=BB=D0=B5=D0=B4=D1=81=D1=82=D0=B2=D0=B8=D1=8F.=20=D0=90=20?= =?UTF-8?q?=D0=BA=D0=B0=D0=BA=20=D0=B8=D0=BD=D0=B0=D1=87=D0=B5,=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=B3=D0=B4=D0=B0=20=D0=BA=D0=B0=D0=B6=D0=B4=D1=8B=D0=B9?= =?UTF-8?q?=20=D0=B1=D0=B0=D0=BB=D0=BB=20=D0=BD=D0=B0=20=D1=81=D1=87=D0=B5?= =?UTF-8?q?=D1=82=D1=83...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ComputersShop/FormSupply.Designer.cs | 48 ++++++++++++++++--- ComputersShop/ComputersShop/FormSupply.cs | 2 +- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/ComputersShop/ComputersShop/FormSupply.Designer.cs b/ComputersShop/ComputersShop/FormSupply.Designer.cs index 6a51fd3..96a26b4 100644 --- a/ComputersShop/ComputersShop/FormSupply.Designer.cs +++ b/ComputersShop/ComputersShop/FormSupply.Designer.cs @@ -33,13 +33,16 @@ CountTextBox = new TextBox(); SaveButton = new Button(); CancelButton = new Button(); + labelShop = new Label(); + labelComputer = new Label(); + labelCount = new Label(); SuspendLayout(); // // ShopComboBox // ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList; ShopComboBox.FormattingEnabled = true; - ShopComboBox.Location = new Point(14, 16); + ShopComboBox.Location = new Point(176, 21); ShopComboBox.Margin = new Padding(3, 4, 3, 4); ShopComboBox.Name = "ShopComboBox"; ShopComboBox.Size = new Size(378, 28); @@ -49,7 +52,7 @@ // ComputerComboBox.DropDownStyle = ComboBoxStyle.DropDownList; ComputerComboBox.FormattingEnabled = true; - ComputerComboBox.Location = new Point(14, 55); + ComputerComboBox.Location = new Point(176, 60); ComputerComboBox.Margin = new Padding(3, 4, 3, 4); ComputerComboBox.Name = "ComputerComboBox"; ComputerComboBox.Size = new Size(378, 28); @@ -57,7 +60,7 @@ // // CountTextBox // - CountTextBox.Location = new Point(14, 93); + CountTextBox.Location = new Point(176, 98); CountTextBox.Margin = new Padding(3, 4, 3, 4); CountTextBox.Name = "CountTextBox"; CountTextBox.Size = new Size(378, 27); @@ -65,7 +68,7 @@ // // SaveButton // - SaveButton.Location = new Point(214, 132); + SaveButton.Location = new Point(376, 137); SaveButton.Margin = new Padding(3, 4, 3, 4); SaveButton.Name = "SaveButton"; SaveButton.Size = new Size(86, 31); @@ -76,7 +79,7 @@ // // CancelButton // - CancelButton.Location = new Point(306, 132); + CancelButton.Location = new Point(468, 137); CancelButton.Margin = new Padding(3, 4, 3, 4); CancelButton.Name = "CancelButton"; CancelButton.Size = new Size(86, 31); @@ -85,11 +88,41 @@ CancelButton.UseVisualStyleBackColor = true; CancelButton.Click += CancelButton_Click; // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(40, 24); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(69, 20); + labelShop.TabIndex = 5; + labelShop.Text = "Магазин"; + // + // labelComputer + // + labelComputer.AutoSize = true; + labelComputer.Location = new Point(40, 63); + labelComputer.Name = "labelComputer"; + labelComputer.Size = new Size(90, 20); + labelComputer.TabIndex = 6; + labelComputer.Text = "Компьютер"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(40, 101); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(90, 20); + labelCount.TabIndex = 7; + labelCount.Text = "Количество"; + // // FormSupply // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(406, 181); + ClientSize = new Size(607, 181); + Controls.Add(labelCount); + Controls.Add(labelComputer); + Controls.Add(labelShop); Controls.Add(CancelButton); Controls.Add(SaveButton); Controls.Add(CountTextBox); @@ -109,5 +142,8 @@ private TextBox CountTextBox; private Button SaveButton; private Button CancelButton; + private Label labelShop; + private Label labelComputer; + private Label labelCount; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShop/FormSupply.cs b/ComputersShop/ComputersShop/FormSupply.cs index 9e3b534..7986576 100644 --- a/ComputersShop/ComputersShop/FormSupply.cs +++ b/ComputersShop/ComputersShop/FormSupply.cs @@ -104,7 +104,7 @@ namespace ComputersShop } if (ComputerComboBox.SelectedValue == null) { - MessageBox.Show("Выберите мороженное", "Ошибка", + MessageBox.Show("Выберите компьютер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } From f7acd30e651d679c422853d8707e398971cf7cb3 Mon Sep 17 00:00:00 2001 From: Artyom_Yashin Date: Mon, 12 Feb 2024 20:03:21 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D0=A2=D1=8B=20(=D0=BD=D0=B5)=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D1=88=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ComputersShop/ComputersShop/FormShop.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ComputersShop/ComputersShop/FormShop.cs b/ComputersShop/ComputersShop/FormShop.cs index 34cf3f0..36f59bf 100644 --- a/ComputersShop/ComputersShop/FormShop.cs +++ b/ComputersShop/ComputersShop/FormShop.cs @@ -69,7 +69,7 @@ namespace ComputersShop } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + _logger.LogError(ex, "Ошибка загрузки компьютеров магазина"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } From 32e642dc9087e90407766480f3c7114872a42f06 Mon Sep 17 00:00:00 2001 From: Artyom_Yashin Date: Wed, 14 Feb 2024 15:12:25 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ComputersShop/FormShop.Designer.cs | 18 +++++++++--------- .../BusinessLogics/ShopLogic.cs | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ComputersShop/ComputersShop/FormShop.Designer.cs b/ComputersShop/ComputersShop/FormShop.Designer.cs index 1321c68..7341591 100644 --- a/ComputersShop/ComputersShop/FormShop.Designer.cs +++ b/ComputersShop/ComputersShop/FormShop.Designer.cs @@ -38,7 +38,7 @@ CancelButton = new Button(); DataGridView = new DataGridView(); ID = new DataGridViewTextBoxColumn(); - Name = new DataGridViewTextBoxColumn(); + ComputerName = new DataGridViewTextBoxColumn(); Price = new DataGridViewTextBoxColumn(); Count = new DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); @@ -120,7 +120,7 @@ // DataGridView // DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - DataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, Name, Price, Count }); + DataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ComputerName, Price, Count }); DataGridView.Location = new Point(14, 132); DataGridView.Margin = new Padding(3, 4, 3, 4); DataGridView.Name = "DataGridView"; @@ -136,13 +136,13 @@ ID.Visible = false; ID.Width = 125; // - // Name + // ComputerName // - Name.HeaderText = "Название"; - Name.MinimumWidth = 6; - Name.Name = "Name"; - Name.ReadOnly = true; - Name.Width = 150; + ComputerName.HeaderText = "Название"; + ComputerName.MinimumWidth = 6; + ComputerName.Name = "ComputerName"; + ComputerName.ReadOnly = true; + ComputerName.Width = 150; // // Price // @@ -195,7 +195,7 @@ private Button CancelButton; private DataGridView DataGridView; private DataGridViewTextBoxColumn ID; - private DataGridViewTextBoxColumn Name; + private DataGridViewTextBoxColumn ComputerName; private DataGridViewTextBoxColumn Price; private DataGridViewTextBoxColumn Count; } diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs index 26e3887..6d92da1 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -113,12 +113,12 @@ namespace ComputersShopBusinessLogic.BusinessLogics if (string.IsNullOrEmpty(model.Address)) { throw new ArgumentNullException("Нет адресса магазина", - nameof(model.ShopName)); + nameof(model.Address)); } if (model.DateOpen == null) { throw new ArgumentNullException("Нет даты открытия магазина", - nameof(model.ShopName)); + nameof(model.DateOpen)); } _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}", model.ShopName, model.Address, model.DateOpen, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel From bec7a3a706f8d328335489ec8fae6165d68977d6 Mon Sep 17 00:00:00 2001 From: Artyom_Yashin Date: Wed, 28 Feb 2024 16:52:11 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=9C=D0=B5=D0=B3=D0=B0=D0=B4=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ShopLogic.cs | 41 ++++++++++++++++++- .../StoragesContracts/IShopStorage.cs | 1 - .../Implements/ShopStorage.cs | 31 -------------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs index 6d92da1..37b155d 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -40,9 +40,46 @@ namespace ComputersShopBusinessLogic.BusinessLogics public bool MakeSupply(ShopSearchModel model, IComputerModel Computer, int count) { + _logger.LogInformation("Try to supply shop. ShopName:{ShopName}. Id:{Id}", model.Name, model.Id); if (model == null) - return false; - return _shopStorage.SupplyComputer(model, Computer, count); + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(model)); + } + if (Computer == null) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(Computer)); + } + if (count <= 0) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException("Количество должно быть положительным числом"); + } + ShopViewModel curModel = ReadElement(model); + if (curModel == null) + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(curModel)); + } + if (curModel.ShopComputers.TryGetValue(Computer.Id, out var pair)) + { + curModel.ShopComputers[Computer.Id] = (pair.Item1, pair.Item2 + count); + } + else + { + curModel.ShopComputers.Add(Computer.Id, (Computer, count)); + } + Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + DateOpen = curModel.DateOpen, + Address = curModel.Address, + ShopComputers = curModel.ShopComputers, + }); + _logger.LogInformation("Success. ComputerName:{ComputerName}. Id:{Id}. Supply:{count}", Computer.ComputerName, Computer.Id, count); + return true; } public ShopViewModel ReadElement(ShopSearchModel model) diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs index 2627905..28a54dc 100644 --- a/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IShopStorage.cs @@ -18,6 +18,5 @@ namespace ComputersShopContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); - bool SupplyComputer(ShopSearchModel model, IComputerModel computer, int Count); } } diff --git a/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs index c3d6b48..2af4d05 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/ShopStorage.cs @@ -104,36 +104,5 @@ namespace ComputersShopListImplement.Implements } return null; } - - public bool SupplyComputer(ShopSearchModel model, IComputerModel Computer, int count) - { - if (model == null) - throw new ArgumentNullException(nameof(model)); - if (Computer == null) - throw new ArgumentNullException(nameof(Computer)); - if (count <= 0) - throw new ArgumentNullException("Количество должно быть положительным числом"); - - ShopViewModel curModel = GetElement(model); - if (curModel == null) - throw new ArgumentNullException(nameof(curModel)); - if (curModel.ShopComputers.TryGetValue(Computer.Id, out var pair)) - { - curModel.ShopComputers[Computer.Id] = (pair.Item1, pair.Item2 + count); - } - else - { - curModel.ShopComputers.Add(Computer.Id, (Computer, count)); - } - Update(new() - { - Id = curModel.Id, - ShopName = curModel.ShopName, - DateOpen = curModel.DateOpen, - Address = curModel.Address, - ShopComputers = curModel.ShopComputers, - }); - return true; - } } }