From 1262146e7aebef2f766b529676accf92b4cb27ed Mon Sep 17 00:00:00 2001
From: 1yuee <lisnik79@yandex.ru>
Date: Tue, 7 Feb 2023 11:03:47 +0400
Subject: [PATCH] fix

---
 ConfectionaryBusinessLogic/ShopLogic.cs  | 11 +++++++++--
 ConfectionaryListImplement/Shop.cs       |  2 +-
 Confectionery/FormComponents.Designer.cs |  1 +
 Confectionery/FormMain.Designer.cs       |  1 +
 Confectionery/FormMain.cs                |  3 ++-
 Confectionery/FormPastry.Designer.cs     |  1 +
 Confectionery/FormShop.cs                |  7 -------
 Confectionery/FormViewPastry.Designer.cs |  1 +
 8 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/ConfectionaryBusinessLogic/ShopLogic.cs b/ConfectionaryBusinessLogic/ShopLogic.cs
index 4c06d09..36d618a 100644
--- a/ConfectionaryBusinessLogic/ShopLogic.cs
+++ b/ConfectionaryBusinessLogic/ShopLogic.cs
@@ -68,7 +68,6 @@ namespace ConfectioneryBusinessLogic
                 throw new ArgumentNullException("Нет названия магазина",
                 nameof(model.Name));
             }
-            model.Pastries = new();
             if (_shopStorage.Update(model) == null)
             {
                 _logger.LogWarning("Update operation failed");
@@ -137,7 +136,7 @@ namespace ConfectioneryBusinessLogic
             
             if (element.Pastries.TryGetValue(pastry.Id, out var pair))
             {
-                pair.Item2 += count;
+                element.Pastries[pastry.Id] = (pastry, count + pair.Item2);
                 _logger.LogInformation(
                     "AddPastryInShop. Has been added {count} {pastry} in {ShopName}", 
                     count, pastry.PastryName, element.Name);
@@ -149,6 +148,14 @@ namespace ConfectioneryBusinessLogic
                     "AddPastryInShop. Has been added {count} new Pastry {pastry} in {ShopName}", 
                     count, pastry.PastryName, element.Name);
             }
+            _shopStorage.Update(new()
+            {
+                Id = element.Id,
+                Address = element.Address,
+                Name = element.Name,
+                DateOpening = element.DateOpening,
+                Pastries = element.Pastries
+            });
             return true;
         }
     }
diff --git a/ConfectionaryListImplement/Shop.cs b/ConfectionaryListImplement/Shop.cs
index fcce77b..93e754c 100644
--- a/ConfectionaryListImplement/Shop.cs
+++ b/ConfectionaryListImplement/Shop.cs
@@ -33,7 +33,7 @@ namespace ConfectioneryListImplement
                 Name = model.Name,
                 Address = model.Address,
                 DateOpening = model.DateOpening,
-                Pastries = model.Pastries
+                Pastries = new()
             };
         }
         public void Update(ShopBindingModel? model)
diff --git a/Confectionery/FormComponents.Designer.cs b/Confectionery/FormComponents.Designer.cs
index dd31844..967f22a 100644
--- a/Confectionery/FormComponents.Designer.cs
+++ b/Confectionery/FormComponents.Designer.cs
@@ -104,6 +104,7 @@
             this.Controls.Add(this.dataGridView);
             this.Name = "FormComponents";
             this.Text = "Редактирование компонентов";
+            this.Load += new System.EventHandler(this.FormComponents_Load);
             ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
             this.ResumeLayout(false);
 
diff --git a/Confectionery/FormMain.Designer.cs b/Confectionery/FormMain.Designer.cs
index d43b97b..0710300 100644
--- a/Confectionery/FormMain.Designer.cs
+++ b/Confectionery/FormMain.Designer.cs
@@ -179,6 +179,7 @@
             this.MainMenuStrip = this.menuStrip1;
             this.Name = "FormMain";
             this.Text = "Кондитерская";
+            this.Load += new System.EventHandler(this.FormMain_Load);
             this.menuStrip1.ResumeLayout(false);
             this.menuStrip1.PerformLayout();
             ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
diff --git a/Confectionery/FormMain.cs b/Confectionery/FormMain.cs
index 92e771a..3c6c955 100644
--- a/Confectionery/FormMain.cs
+++ b/Confectionery/FormMain.cs
@@ -29,7 +29,8 @@ namespace ConfectioneryView
                 if (list != null)
                 {
                     dataGridView.DataSource = list;
-                    dataGridView.Columns["Id"].Visible = false;
+                    dataGridView.Columns["Id"].HeaderText = "����� ������";
+                    dataGridView.Columns["PastryId"].Visible = false;
                     dataGridView.Columns["PastryName"].AutoSizeMode =
                     DataGridViewAutoSizeColumnMode.Fill;
                 }
diff --git a/Confectionery/FormPastry.Designer.cs b/Confectionery/FormPastry.Designer.cs
index ba07aee..1c6ecaf 100644
--- a/Confectionery/FormPastry.Designer.cs
+++ b/Confectionery/FormPastry.Designer.cs
@@ -207,6 +207,7 @@
             this.Controls.Add(this.label1);
             this.Name = "FormPastry";
             this.Text = "Кондитерское изделие";
+            this.Load += new System.EventHandler(this.FormPastry_Load);
             this.groupBox1.ResumeLayout(false);
             ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
             this.ResumeLayout(false);
diff --git a/Confectionery/FormShop.cs b/Confectionery/FormShop.cs
index 4700625..c755270 100644
--- a/Confectionery/FormShop.cs
+++ b/Confectionery/FormShop.cs
@@ -70,13 +70,6 @@ namespace ConfectioneryView
                     comboBoxShop.Text = model.Name;
                     textBoxAddress.Text = model.Address;
                     textBoxDateOpening.Text = Convert.ToString(model.DateOpening);
-                    
-                        textBoxAddress.Text = vmodel.Address;
-                        textBoxDateOpening.Text = Convert.ToString(vmodel.DateOpening);
-                    }
-                        textBoxAddress.Text = vmodel.Address;
-                        textBoxDateOpening.Text = Convert.ToString(vmodel.DateOpening);
-                    }
                     dataGridView.Rows.Clear();
                     foreach (var el in model.Pastries.Values)
                     {
diff --git a/Confectionery/FormViewPastry.Designer.cs b/Confectionery/FormViewPastry.Designer.cs
index 3417617..67d3480 100644
--- a/Confectionery/FormViewPastry.Designer.cs
+++ b/Confectionery/FormViewPastry.Designer.cs
@@ -104,6 +104,7 @@
             this.Controls.Add(this.dataGridView);
             this.Name = "FormViewPastry";
             this.Text = "Редактирование изделий";
+            this.Load += new System.EventHandler(this.FormViewPastry_Load);
             ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
             this.ResumeLayout(false);