diff --git a/ConfectionaryBusinessLogic/ShopLogic.cs b/ConfectionaryBusinessLogic/ShopLogic.cs index d127dfa..3974880 100644 --- a/ConfectionaryBusinessLogic/ShopLogic.cs +++ b/ConfectionaryBusinessLogic/ShopLogic.cs @@ -101,6 +101,13 @@ namespace ConfectioneryBusinessLogic throw new ArgumentNullException("Нет названия магазина", nameof(model.Name)); } + if (model.MaxCountPastries < 0) + { + throw new ArgumentException( + "Максимальное количество изделий в магазине не должно быть отрицательным", + nameof(model.MaxCountPastries)); + } + _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", model.Name, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel @@ -133,27 +140,24 @@ namespace ConfectioneryBusinessLogic } _logger.LogInformation("AddPastryInShop find. Id:{Id}", element.Id); - if (element.MaxCountPastries < 0) + var currentCountPasties = element.Pastries.Select(x => x.Value.Item2).Sum(); + if (currentCountPasties + count > element.MaxCountPastries) { - throw new ArgumentException( - "Максимальное количество изделий в магазине не должно быть отрицательным", - nameof(element.MaxCountPastries)); + _logger.LogWarning("AddPastryInShop. The number of pastry {count} exceeds maximum {max}", + currentCountPasties + count, element.MaxCountPastries); + return false; } - if (element.Pastries.TryGetValue(pastry.Id, out var pair)) { element.Pastries[pastry.Id] = (pastry, count + pair.Item2); - _logger.LogInformation( - "AddPastryInShop. Has been added {count} {pastry} in {ShopName}", - count, pastry.PastryName, element.Name); } else { element.Pastries[pastry.Id] = (pastry, count); - _logger.LogInformation( - "AddPastryInShop. Has been added {count} new Pastry {pastry} in {ShopName}", - count, pastry.PastryName, element.Name); } + _logger.LogInformation( + "AddPastryInShop. Has been added {count} {pastry} in {ShopName}", + count, pastry.PastryName, element.Name); _shopStorage.Update(new() { Id = element.Id, diff --git a/Confectionery/FormShop.Designer.cs b/Confectionery/FormShop.Designer.cs index 694a22f..3a9ec82 100644 --- a/Confectionery/FormShop.Designer.cs +++ b/Confectionery/FormShop.Designer.cs @@ -40,7 +40,10 @@ this.textBoxDateOpening = new System.Windows.Forms.TextBox(); this.buttonCancel = new System.Windows.Forms.Button(); this.buttonSave = new System.Windows.Forms.Button(); + this.label4 = new System.Windows.Forms.Label(); + this.numericUpDownMaxPastry = new System.Windows.Forms.NumericUpDown(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxPastry)).BeginInit(); this.SuspendLayout(); // // label1 @@ -74,7 +77,7 @@ this.dataGridView.Location = new System.Drawing.Point(12, 64); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(583, 213); + this.dataGridView.Size = new System.Drawing.Size(640, 213); this.dataGridView.TabIndex = 2; // // PastryName @@ -105,7 +108,7 @@ // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(386, 9); + this.label3.Location = new System.Drawing.Point(366, 9); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(100, 15); this.label3.TabIndex = 4; @@ -115,20 +118,20 @@ // this.textBoxAddress.Location = new System.Drawing.Point(159, 27); this.textBoxAddress.Name = "textBoxAddress"; - this.textBoxAddress.Size = new System.Drawing.Size(221, 23); + this.textBoxAddress.Size = new System.Drawing.Size(201, 23); this.textBoxAddress.TabIndex = 5; // // textBoxDateOpening // - this.textBoxDateOpening.Location = new System.Drawing.Point(386, 27); + this.textBoxDateOpening.Location = new System.Drawing.Point(366, 27); this.textBoxDateOpening.Name = "textBoxDateOpening"; - this.textBoxDateOpening.Size = new System.Drawing.Size(209, 23); + this.textBoxDateOpening.Size = new System.Drawing.Size(160, 23); this.textBoxDateOpening.TabIndex = 6; // // buttonCancel // this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonCancel.Location = new System.Drawing.Point(492, 283); + this.buttonCancel.Location = new System.Drawing.Point(549, 283); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(103, 23); this.buttonCancel.TabIndex = 7; @@ -139,7 +142,7 @@ // buttonSave // this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonSave.Location = new System.Drawing.Point(366, 284); + this.buttonSave.Location = new System.Drawing.Point(423, 284); this.buttonSave.Name = "buttonSave"; this.buttonSave.Size = new System.Drawing.Size(120, 22); this.buttonSave.TabIndex = 8; @@ -147,11 +150,34 @@ this.buttonSave.UseVisualStyleBackColor = true; this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(530, 9); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(118, 15); + this.label4.TabIndex = 9; + this.label4.Text = "Максимум изделий:"; + // + // numericUpDownMaxPastry + // + this.numericUpDownMaxPastry.Location = new System.Drawing.Point(532, 27); + this.numericUpDownMaxPastry.Maximum = new decimal(new int[] { + 10000000, + 0, + 0, + 0}); + this.numericUpDownMaxPastry.Name = "numericUpDownMaxPastry"; + this.numericUpDownMaxPastry.Size = new System.Drawing.Size(120, 23); + this.numericUpDownMaxPastry.TabIndex = 10; + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(607, 317); + this.ClientSize = new System.Drawing.Size(664, 317); + this.Controls.Add(this.numericUpDownMaxPastry); + this.Controls.Add(this.label4); this.Controls.Add(this.buttonSave); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.textBoxDateOpening); @@ -165,6 +191,7 @@ this.Text = "Просмотр изделий магазина"; this.Load += new System.EventHandler(this.FormShop_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxPastry)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -184,5 +211,7 @@ private DataGridViewTextBoxColumn PastryName; private DataGridViewTextBoxColumn Price; private DataGridViewTextBoxColumn Count; + private Label label4; + private NumericUpDown numericUpDownMaxPastry; } } \ No newline at end of file diff --git a/Confectionery/FormShop.cs b/Confectionery/FormShop.cs index c755270..fa5c0f5 100644 --- a/Confectionery/FormShop.cs +++ b/Confectionery/FormShop.cs @@ -66,7 +66,8 @@ namespace ConfectioneryView { var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.SelectedValue)); if (model != null) - { + { + numericUpDownMaxPastry.Value = model.MaxCountPastries; comboBoxShop.Text = model.Name; textBoxAddress.Text = model.Address; textBoxDateOpening.Text = Convert.ToString(model.DateOpening); @@ -113,7 +114,8 @@ namespace ConfectioneryView { Name = comboBoxShop.Text, Address = textBoxAddress.Text, - DateOpening = dateTime + DateOpening = dateTime, + MaxCountPastries = (int)numericUpDownMaxPastry.Value, }; var vmodel = GetShop(Id); bool operationResult = false; diff --git a/Confectionery/FormShop.resx b/Confectionery/FormShop.resx index c4ce247..5191e62 100644 --- a/Confectionery/FormShop.resx +++ b/Confectionery/FormShop.resx @@ -66,4 +66,13 @@ True + + True + + + True + + + True + \ No newline at end of file