ура товар

This commit is contained in:
the 2024-06-23 14:27:50 +04:00
parent 1c2130203d
commit a2f733ce8e
2 changed files with 51 additions and 8 deletions

View File

@ -39,6 +39,7 @@
buttonSaveProduct = new Button();
checkBoxIsSold = new CheckBox();
textBoxName = new TextBox();
buttonDeleteProduct = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
groupBoxControls.SuspendLayout();
groupBoxCreateProduct.SuspendLayout();
@ -67,6 +68,7 @@
// groupBoxControls
//
groupBoxControls.BackColor = Color.Transparent;
groupBoxControls.Controls.Add(buttonDeleteProduct);
groupBoxControls.Controls.Add(buttonUpdateProduct);
groupBoxControls.Controls.Add(buttonCreateProduct);
groupBoxControls.Location = new Point(649, 12);
@ -156,6 +158,16 @@
textBoxName.Size = new Size(100, 23);
textBoxName.TabIndex = 0;
//
// buttonDeleteProduct
//
buttonDeleteProduct.Location = new Point(69, 102);
buttonDeleteProduct.Name = "buttonDeleteProduct";
buttonDeleteProduct.Size = new Size(139, 23);
buttonDeleteProduct.TabIndex = 3;
buttonDeleteProduct.Text = "Удалить товар";
buttonDeleteProduct.UseVisualStyleBackColor = true;
buttonDeleteProduct.Click += buttonDeleteProduct_Click;
//
// FormProducts
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -189,5 +201,6 @@
private NumericUpDown numericUpDownPrice;
private Button buttonCancel;
private Button buttonUpdateProduct;
private Button buttonDeleteProduct;
}
}

View File

@ -101,14 +101,6 @@ namespace WinFormsApp
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
groupBoxControls.Enabled = true;
groupBoxControls.Show();
groupBoxCreateProduct.Enabled = false;
groupBoxCreateProduct.Hide();
textBoxName.Text = string.Empty;
numericUpDownAmount.Value = 0;
numericUpDownPrice.Value = 0;
checkBoxIsSold.Checked = false;
}
catch (Exception ex)
{
@ -119,6 +111,14 @@ namespace WinFormsApp
finally
{
LoadData();
groupBoxControls.Enabled = true;
groupBoxControls.Show();
groupBoxCreateProduct.Enabled = false;
groupBoxCreateProduct.Hide();
textBoxName.Text = string.Empty;
numericUpDownAmount.Value = 0;
numericUpDownPrice.Value = 0;
checkBoxIsSold.Checked = false;
}
}
@ -151,5 +151,35 @@ namespace WinFormsApp
numericUpDownPrice.Value = 0;
checkBoxIsSold.Checked = false;
}
private void buttonDeleteProduct_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Guid id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value;
_logger.LogInformation("Удаление товара");
try
{
if (!_productLogic.Delete(new ProductBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления товара");
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}
}