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(); dataGridView = new DataGridView();
buttonCreateProduct = new Button(); buttonCreateProduct = new Button();
groupBoxControls = new GroupBox(); groupBoxControls = new GroupBox();
buttonUpdateProduct = new Button();
groupBoxCreateProduct = new GroupBox(); groupBoxCreateProduct = new GroupBox();
numericUpDownAmount = new NumericUpDown(); numericUpDownAmount = new NumericUpDown();
numericUpDownPrice = new NumericUpDown(); numericUpDownPrice = new NumericUpDown();
@ -38,7 +39,6 @@
buttonSaveProduct = new Button(); buttonSaveProduct = new Button();
checkBoxIsSold = new CheckBox(); checkBoxIsSold = new CheckBox();
textBoxName = new TextBox(); textBoxName = new TextBox();
buttonUpdateProduct = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
groupBoxControls.SuspendLayout(); groupBoxControls.SuspendLayout();
groupBoxCreateProduct.SuspendLayout(); groupBoxCreateProduct.SuspendLayout();
@ -76,6 +76,16 @@
groupBoxControls.TabStop = false; groupBoxControls.TabStop = false;
groupBoxControls.Text = "Действия"; 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
// //
groupBoxCreateProduct.BackColor = Color.Transparent; groupBoxCreateProduct.BackColor = Color.Transparent;
@ -117,6 +127,7 @@
buttonCancel.TabIndex = 5; buttonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена"; buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
// //
// buttonSaveProduct // buttonSaveProduct
// //
@ -145,16 +156,6 @@
textBoxName.Size = new Size(100, 23); textBoxName.Size = new Size(100, 23);
textBoxName.TabIndex = 0; 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 // FormProducts
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);

View File

@ -85,13 +85,16 @@ namespace WinFormsApp
{ {
var model = new ProductBindingModel var model = new ProductBindingModel
{ {
Id = _id ?? Guid.Empty,
Name = textBoxName.Text, Name = textBoxName.Text,
Price = Convert.ToDouble(numericUpDownPrice.Value), Price = Convert.ToDouble(numericUpDownPrice.Value),
Amount = Convert.ToInt16(numericUpDownAmount.Value), Amount = Convert.ToInt16(numericUpDownAmount.Value),
Rate = 0.0, Rate = 0.0,
IsBeingSold = checkBoxIsSold.Checked, IsBeingSold = checkBoxIsSold.Checked,
}; };
var operationResult = _productLogic.Create(model);
var operationResult = _id.HasValue ? _productLogic.Update(model) : _productLogic.Create(model);
_id = null;
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
@ -102,6 +105,10 @@ namespace WinFormsApp
groupBoxControls.Show(); groupBoxControls.Show();
groupBoxCreateProduct.Enabled = false; groupBoxCreateProduct.Enabled = false;
groupBoxCreateProduct.Hide(); groupBoxCreateProduct.Hide();
textBoxName.Text = string.Empty;
numericUpDownAmount.Value = 0;
numericUpDownPrice.Value = 0;
checkBoxIsSold.Checked = false;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -131,5 +138,18 @@ namespace WinFormsApp
numericUpDownAmount.Value = view.Amount; numericUpDownAmount.Value = view.Amount;
checkBoxIsSold.Checked = view.IsBeingSold; 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;
}
} }
} }