This commit is contained in:
the 2024-06-23 14:21:59 +04:00
parent 86a0b43a9a
commit 1c2130203d
2 changed files with 33 additions and 12 deletions

View File

@ -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);

View File

@ -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;
}
}
}