diff --git a/WinFormsApp/FormProducts.Designer.cs b/WinFormsApp/FormProducts.Designer.cs index e759415..fe80499 100644 --- a/WinFormsApp/FormProducts.Designer.cs +++ b/WinFormsApp/FormProducts.Designer.cs @@ -31,6 +31,7 @@ dataGridView = new DataGridView(); buttonCreateProduct = new Button(); groupBoxControls = new GroupBox(); + buttonUpdateProduct = new Button(); groupBoxCreateProduct = new GroupBox(); numericUpDownAmount = new NumericUpDown(); numericUpDownPrice = new NumericUpDown(); @@ -38,7 +39,6 @@ buttonSaveProduct = new Button(); checkBoxIsSold = new CheckBox(); textBoxName = new TextBox(); - buttonUpdateProduct = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); groupBoxControls.SuspendLayout(); groupBoxCreateProduct.SuspendLayout(); @@ -76,6 +76,16 @@ groupBoxControls.TabStop = false; groupBoxControls.Text = "Действия"; // + // buttonUpdateProduct + // + buttonUpdateProduct.Location = new Point(69, 62); + buttonUpdateProduct.Name = "buttonUpdateProduct"; + buttonUpdateProduct.Size = new Size(139, 23); + buttonUpdateProduct.TabIndex = 2; + buttonUpdateProduct.Text = "Изменить товар"; + buttonUpdateProduct.UseVisualStyleBackColor = true; + buttonUpdateProduct.Click += buttonUpdateProduct_Click; + // // groupBoxCreateProduct // groupBoxCreateProduct.BackColor = Color.Transparent; @@ -117,6 +127,7 @@ buttonCancel.TabIndex = 5; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; // // buttonSaveProduct // @@ -145,16 +156,6 @@ textBoxName.Size = new Size(100, 23); textBoxName.TabIndex = 0; // - // buttonUpdateProduct - // - buttonUpdateProduct.Location = new Point(69, 62); - buttonUpdateProduct.Name = "buttonUpdateProduct"; - buttonUpdateProduct.Size = new Size(139, 23); - buttonUpdateProduct.TabIndex = 2; - buttonUpdateProduct.Text = "Изменить товар"; - buttonUpdateProduct.UseVisualStyleBackColor = true; - buttonUpdateProduct.Click += buttonUpdateProduct_Click; - // // FormProducts // AutoScaleDimensions = new SizeF(7F, 15F); diff --git a/WinFormsApp/FormProducts.cs b/WinFormsApp/FormProducts.cs index 87227a0..9eb0d86 100644 --- a/WinFormsApp/FormProducts.cs +++ b/WinFormsApp/FormProducts.cs @@ -85,13 +85,16 @@ namespace WinFormsApp { var model = new ProductBindingModel { + Id = _id ?? Guid.Empty, Name = textBoxName.Text, Price = Convert.ToDouble(numericUpDownPrice.Value), Amount = Convert.ToInt16(numericUpDownAmount.Value), Rate = 0.0, IsBeingSold = checkBoxIsSold.Checked, }; - var operationResult = _productLogic.Create(model); + + var operationResult = _id.HasValue ? _productLogic.Update(model) : _productLogic.Create(model); + _id = null; if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -102,6 +105,10 @@ namespace WinFormsApp groupBoxControls.Show(); groupBoxCreateProduct.Enabled = false; groupBoxCreateProduct.Hide(); + textBoxName.Text = string.Empty; + numericUpDownAmount.Value = 0; + numericUpDownPrice.Value = 0; + checkBoxIsSold.Checked = false; } catch (Exception ex) { @@ -131,5 +138,18 @@ namespace WinFormsApp numericUpDownAmount.Value = view.Amount; checkBoxIsSold.Checked = view.IsBeingSold; } + + private void buttonCancel_Click(object sender, EventArgs e) + { + _id = null; + groupBoxControls.Show(); + //groupBoxControls.Enabled = false; + groupBoxCreateProduct.Hide(); + //groupBoxCreateProduct.Enabled = true; + textBoxName.Text = string.Empty; + numericUpDownAmount.Value = 0; + numericUpDownPrice.Value = 0; + checkBoxIsSold.Checked = false; + } } }