diff --git a/DatabaseImplement/Implements/SupplyStorage.cs b/DatabaseImplement/Implements/SupplyStorage.cs
index 64d3c8f..b1f5ec9 100644
--- a/DatabaseImplement/Implements/SupplyStorage.cs
+++ b/DatabaseImplement/Implements/SupplyStorage.cs
@@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -115,7 +116,14 @@ namespace DatabaseImplement.Implements
return null;
}
context.Supplies.Add(newProduct);
- context.SaveChanges();
+ try
+ {
+ context.SaveChanges();
+ }
+ catch (Exception ex)
+ {
+ Debug.WriteLine(ex);
+ }
return newProduct.GetViewModel;
}
diff --git a/DatabaseImplement/Models/Supplier.cs b/DatabaseImplement/Models/Supplier.cs
index 247731b..74a6479 100644
--- a/DatabaseImplement/Models/Supplier.cs
+++ b/DatabaseImplement/Models/Supplier.cs
@@ -59,7 +59,7 @@ namespace DatabaseImplement.Models
Deals = model.Deals;
Debug.WriteLine(model.AvailibleProducts.Keys);
Products = model.AvailibleProducts.Select(x => new
- SupplierProduct
+ SupplierProduct
{
Product = context.Products.First(y => y.Id == x.Value.Item1.Id),
Count = x.Value.Item2
@@ -81,6 +81,7 @@ namespace DatabaseImplement.Models
}
public void UpdateProducts(Database context, SupplierBindingModel model)
{
+ var test = context.SupplierProducts.ToList();
var supplierProducts = context.SupplierProducts.Where(rec => rec.SupplierId == model.Id).ToList();
if (supplierProducts != null && supplierProducts.Count > model.AvailibleProducts.Count)
{
diff --git a/DatabaseImplement/Models/Supply.cs b/DatabaseImplement/Models/Supply.cs
index 64e75f4..f66b0dd 100644
--- a/DatabaseImplement/Models/Supply.cs
+++ b/DatabaseImplement/Models/Supply.cs
@@ -59,7 +59,8 @@ namespace DatabaseImplement.Models
{
Product = context.Products.First(y => y.Id == x.Key),
Count = x.Value.Item2
- }).ToList()
+ }).ToList(),
+ Status = SupplyStatus.Pending,
};
}
public void Update(SupplyBindingModel model)
diff --git a/WinFormsApp/FormMain.Designer.cs b/WinFormsApp/FormMain.Designer.cs
index e5feb1c..ecf603f 100644
--- a/WinFormsApp/FormMain.Designer.cs
+++ b/WinFormsApp/FormMain.Designer.cs
@@ -48,12 +48,13 @@
//
// buttonCreateSupply
//
- buttonCreateSupply.Location = new Point(706, 12);
+ buttonCreateSupply.Location = new Point(706, 24);
buttonCreateSupply.Name = "buttonCreateSupply";
buttonCreateSupply.Size = new Size(154, 23);
buttonCreateSupply.TabIndex = 1;
buttonCreateSupply.Text = "Оформить поставку";
buttonCreateSupply.UseVisualStyleBackColor = true;
+ buttonCreateSupply.Click += buttonCreateSupply_Click;
//
// menuStrip1
//
diff --git a/WinFormsApp/FormMain.cs b/WinFormsApp/FormMain.cs
index a7fd7da..16b881f 100644
--- a/WinFormsApp/FormMain.cs
+++ b/WinFormsApp/FormMain.cs
@@ -68,5 +68,14 @@ namespace WinFormsApp
form.ShowDialog();
}
}
+
+ private void buttonCreateSupply_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormSupply));
+ if (service is FormSupply form)
+ {
+ form.ShowDialog();
+ }
+ }
}
}
diff --git a/WinFormsApp/FormSuppliers.cs b/WinFormsApp/FormSuppliers.cs
index 9702ec8..08d3367 100644
--- a/WinFormsApp/FormSuppliers.cs
+++ b/WinFormsApp/FormSuppliers.cs
@@ -57,7 +57,7 @@ namespace WinFormsApp
dataGridViewProducts.Rows.Clear();
foreach (var pc in _supplierProducts)
{
- dataGridViewProducts.Rows.Add(new object[] { pc.Key, pc.Value.Item1.Name, pc.Value.Item2 });
+ dataGridViewProducts.Rows.Add(new object[] { pc.Value.Item1.Id, pc.Value.Item1.Name, pc.Value.Item2 });
}
}
diff --git a/WinFormsApp/FormSupply.Designer.cs b/WinFormsApp/FormSupply.Designer.cs
new file mode 100644
index 0000000..e64a27c
--- /dev/null
+++ b/WinFormsApp/FormSupply.Designer.cs
@@ -0,0 +1,210 @@
+namespace WinFormsApp
+{
+ partial class FormSupply
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ textBoxName = new TextBox();
+ dataGridView = new DataGridView();
+ ProductId = new DataGridViewTextBoxColumn();
+ ProductName = new DataGridViewTextBoxColumn();
+ ProductAmount = new DataGridViewTextBoxColumn();
+ groupBoxProducts = new GroupBox();
+ buttonDeleteProduct = new Button();
+ buttonUpdateProduct = new Button();
+ buttonAddProduct = new Button();
+ label1 = new Label();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ textBoxPrice = new TextBox();
+ comboBoxSupplier = new ComboBox();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ groupBoxProducts.SuspendLayout();
+ SuspendLayout();
+ //
+ // textBoxName
+ //
+ textBoxName.Location = new Point(18, 41);
+ textBoxName.Multiline = true;
+ textBoxName.Name = "textBoxName";
+ textBoxName.Size = new Size(434, 103);
+ textBoxName.TabIndex = 0;
+ //
+ // dataGridView
+ //
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Columns.AddRange(new DataGridViewColumn[] { ProductId, ProductName, ProductAmount });
+ dataGridView.Location = new Point(6, 22);
+ dataGridView.Name = "dataGridView";
+ dataGridView.Size = new Size(423, 241);
+ dataGridView.TabIndex = 1;
+ //
+ // ProductId
+ //
+ ProductId.HeaderText = "Id";
+ ProductId.Name = "ProductId";
+ ProductId.ReadOnly = true;
+ ProductId.Visible = false;
+ //
+ // ProductName
+ //
+ ProductName.HeaderText = "Название";
+ ProductName.Name = "ProductName";
+ ProductName.ReadOnly = true;
+ //
+ // ProductAmount
+ //
+ ProductAmount.HeaderText = "Количество";
+ ProductAmount.Name = "ProductAmount";
+ ProductAmount.ReadOnly = true;
+ //
+ // groupBoxProducts
+ //
+ groupBoxProducts.Controls.Add(buttonDeleteProduct);
+ groupBoxProducts.Controls.Add(buttonUpdateProduct);
+ groupBoxProducts.Controls.Add(buttonAddProduct);
+ groupBoxProducts.Controls.Add(dataGridView);
+ groupBoxProducts.Location = new Point(12, 150);
+ groupBoxProducts.Name = "groupBoxProducts";
+ groupBoxProducts.Size = new Size(776, 288);
+ groupBoxProducts.TabIndex = 2;
+ groupBoxProducts.TabStop = false;
+ groupBoxProducts.Text = "Товары";
+ //
+ // buttonDeleteProduct
+ //
+ buttonDeleteProduct.Location = new Point(435, 132);
+ buttonDeleteProduct.Name = "buttonDeleteProduct";
+ buttonDeleteProduct.Size = new Size(126, 49);
+ buttonDeleteProduct.TabIndex = 4;
+ buttonDeleteProduct.Text = "Удалить";
+ buttonDeleteProduct.UseVisualStyleBackColor = true;
+ buttonDeleteProduct.Click += buttonDeleteProduct_Click;
+ //
+ // buttonUpdateProduct
+ //
+ buttonUpdateProduct.Location = new Point(435, 77);
+ buttonUpdateProduct.Name = "buttonUpdateProduct";
+ buttonUpdateProduct.Size = new Size(126, 49);
+ buttonUpdateProduct.TabIndex = 3;
+ buttonUpdateProduct.Text = "Изменить";
+ buttonUpdateProduct.UseVisualStyleBackColor = true;
+ buttonUpdateProduct.Click += buttonUpdateProduct_Click;
+ //
+ // buttonAddProduct
+ //
+ buttonAddProduct.Location = new Point(435, 22);
+ buttonAddProduct.Name = "buttonAddProduct";
+ buttonAddProduct.Size = new Size(126, 49);
+ buttonAddProduct.TabIndex = 2;
+ buttonAddProduct.Text = "Добавить";
+ buttonAddProduct.UseVisualStyleBackColor = true;
+ buttonAddProduct.Click += buttonAddProduct_Click;
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(18, 23);
+ label1.Name = "label1";
+ label1.Size = new Size(100, 15);
+ label1.TabIndex = 3;
+ label1.Text = "Общие сведения";
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(654, 40);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 4;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(654, 88);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 5;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ //
+ // textBoxPrice
+ //
+ textBoxPrice.Enabled = false;
+ textBoxPrice.Location = new Point(473, 88);
+ textBoxPrice.Name = "textBoxPrice";
+ textBoxPrice.Size = new Size(100, 23);
+ textBoxPrice.TabIndex = 6;
+ //
+ // comboBoxSupplier
+ //
+ comboBoxSupplier.FormattingEnabled = true;
+ comboBoxSupplier.Location = new Point(473, 41);
+ comboBoxSupplier.Name = "comboBoxSupplier";
+ comboBoxSupplier.Size = new Size(121, 23);
+ comboBoxSupplier.TabIndex = 7;
+ //
+ // FormSupply
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(comboBoxSupplier);
+ Controls.Add(textBoxPrice);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(label1);
+ Controls.Add(groupBoxProducts);
+ Controls.Add(textBoxName);
+ Name = "FormSupply";
+ Text = "FormSupply";
+ Load += FormSupply_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ groupBoxProducts.ResumeLayout(false);
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private TextBox textBoxName;
+ private DataGridView dataGridView;
+ private DataGridViewTextBoxColumn ProductId;
+ private DataGridViewTextBoxColumn ProductName;
+ private DataGridViewTextBoxColumn ProductAmount;
+ private GroupBox groupBoxProducts;
+ private Button buttonAddProduct;
+ private Label label1;
+ private Button buttonUpdateProduct;
+ private Button buttonDeleteProduct;
+ private Button buttonSave;
+ private Button buttonCancel;
+ private TextBox textBoxPrice;
+ private ComboBox comboBoxSupplier;
+ }
+}
\ No newline at end of file
diff --git a/WinFormsApp/FormSupply.cs b/WinFormsApp/FormSupply.cs
new file mode 100644
index 0000000..bf6394d
--- /dev/null
+++ b/WinFormsApp/FormSupply.cs
@@ -0,0 +1,222 @@
+using Contracts.BindingModels;
+using Contracts.BusinessLogicContracts;
+using Contracts.SearchModels;
+using DataModels.Models;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Diagnostics;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace WinFormsApp
+{
+ public partial class FormSupply : Form
+ {
+ private readonly ILogger _logger;
+ private readonly ISupplyLogic _logic;
+ private readonly ISupplierLogic _supplierLogic;
+ private Guid? _id;
+ private Dictionary _supplyProducts;
+ public Guid Id { set { _id = value; } }
+ public FormSupply(ILogger logger, ISupplyLogic logic, ISupplierLogic supplierLogic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _supplyProducts = new Dictionary();
+ _supplierLogic = supplierLogic;
+ }
+ private void FormSupply_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ _logger.LogInformation("Загрузка изделия");
+ try
+ {
+ var view = _logic.ReadElement(new SupplySearchModel
+ {
+ Id = _id.Value
+ });
+ if (view != null)
+ {
+ textBoxName.Text = view.Name;
+ _supplyProducts = view.Products ?? new Dictionary();
+ LoadData();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ try
+ {
+ var list = _supplierLogic.ReadList(null);
+ if (list != null)
+ {
+ comboBoxSupplier.DisplayMember = "Name";
+ comboBoxSupplier.ValueMember = "Id";
+ comboBoxSupplier.DataSource = list;
+ comboBoxSupplier.SelectedItem = null;
+ }
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки списка клиентов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка компонент изделия");
+ try
+ {
+ if (_supplyProducts != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var pc in _supplyProducts)
+ {
+ dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.Name, pc.Value.Item2 });
+ }
+ textBoxPrice.Text = CalcPrice().ToString();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки компонент изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonAddProduct_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormSupplyProduct));
+ if (service is FormSupplyProduct form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ProductModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Добавление нового компонента");
+ if (_supplyProducts.ContainsKey(form.Id))
+ {
+ _supplyProducts[form.Id] = (form.ProductModel, form.Count);
+ }
+ else
+ {
+ _supplyProducts.Add(form.Id, (form.ProductModel, form.Count));
+ }
+ LoadData();
+ }
+ }
+ }
+
+ private void buttonUpdateProduct_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service =
+ Program.ServiceProvider?.GetService(typeof(FormSupplyProduct));
+ if (service is FormSupplyProduct form)
+ {
+ Guid id = (Guid)dataGridView.SelectedRows[0].Cells[0].Value;
+ form.Id = id;
+ form.Count = _supplyProducts[id].Item2;
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ProductModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Изменение компонента");
+ _supplyProducts[form.Id] = (form.ProductModel, form.Count);
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void buttonDeleteProduct_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ try
+ {
+ _logger.LogInformation("Удаление компонента");
+ _supplyProducts?.Remove((Guid)dataGridView.SelectedRows[0].Cells[0].Value);
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ LoadData();
+ }
+ }
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxName.Text))
+ {
+ MessageBox.Show("Заполните информацию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (_supplyProducts == null || _supplyProducts.Count == 0)
+ {
+ MessageBox.Show("Заполните товары", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение изделия");
+ try
+ {
+ var model = new SupplyBindingModel
+ {
+ Id = _id ?? Guid.NewGuid(),
+ Name = textBoxName.Text,
+ Date = DateTime.UtcNow,
+ Price = Convert.ToDouble(textBoxPrice.Text),
+ SupplierId = (Guid)comboBoxSupplier.SelectedValue,
+ SupplyProducts = _supplyProducts,
+
+ };
+ var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения изделия"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private double CalcPrice()
+ {
+ double price = 0;
+ foreach (var elem in _supplyProducts)
+ {
+ price += ((elem.Value.Item1?.Price ?? 0) * elem.Value.Item2);
+ }
+ return Math.Round(price * 1.1, 2);
+ }
+ }
+}
diff --git a/WinFormsApp/FormSupply.resx b/WinFormsApp/FormSupply.resx
new file mode 100644
index 0000000..3f4c598
--- /dev/null
+++ b/WinFormsApp/FormSupply.resx
@@ -0,0 +1,129 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ True
+
+
+ True
+
+
+ True
+
+
\ No newline at end of file
diff --git a/WinFormsApp/FormSupplyProduct.Designer.cs b/WinFormsApp/FormSupplyProduct.Designer.cs
new file mode 100644
index 0000000..a8ac46f
--- /dev/null
+++ b/WinFormsApp/FormSupplyProduct.Designer.cs
@@ -0,0 +1,94 @@
+namespace WinFormsApp
+{
+ partial class FormSupplyProduct
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ numericUpDownCount = new NumericUpDown();
+ comboBoxProduct = new ComboBox();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
+ SuspendLayout();
+ //
+ // numericUpDownCount
+ //
+ numericUpDownCount.Location = new Point(26, 76);
+ numericUpDownCount.Name = "numericUpDownCount";
+ numericUpDownCount.Size = new Size(120, 23);
+ numericUpDownCount.TabIndex = 1;
+ //
+ // comboBoxProduct
+ //
+ comboBoxProduct.FormattingEnabled = true;
+ comboBoxProduct.Location = new Point(25, 33);
+ comboBoxProduct.Name = "comboBoxProduct";
+ comboBoxProduct.Size = new Size(121, 23);
+ comboBoxProduct.TabIndex = 2;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(192, 74);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 3;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += ButtonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(192, 98);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 4;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
+ //
+ // FormSupplyProduct
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(287, 138);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(comboBoxProduct);
+ Controls.Add(numericUpDownCount);
+ Name = "FormSupplyProduct";
+ Text = "FormSupplyProduct";
+ ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+ private NumericUpDown numericUpDownCount;
+ private ComboBox comboBoxProduct;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/WinFormsApp/FormSupplyProduct.cs b/WinFormsApp/FormSupplyProduct.cs
new file mode 100644
index 0000000..9d3b8dd
--- /dev/null
+++ b/WinFormsApp/FormSupplyProduct.cs
@@ -0,0 +1,88 @@
+using Contracts.BusinessLogicContracts;
+using Contracts.ViewModels;
+using DataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace WinFormsApp
+{
+ public partial class FormSupplyProduct : Form
+ {
+ private readonly List? _list;
+ public Guid Id
+ {
+ get
+ {
+ return (Guid)comboBoxProduct.SelectedValue;
+ }
+ set
+ {
+ comboBoxProduct.SelectedValue = value;
+ }
+ }
+
+ public IProduct? ProductModel
+ {
+ get
+ {
+ if (_list == null)
+ {
+ return null;
+ }
+ foreach (var elem in _list)
+ {
+ if (elem.Id == Id)
+ {
+ return elem;
+ }
+ }
+ return null;
+ }
+ }
+
+ public int Count
+ {
+ get { return Convert.ToInt32(numericUpDownCount.Value); }
+ set { numericUpDownCount.Value = value; }
+ }
+ public FormSupplyProduct(IProductLogic logic)
+ {
+ InitializeComponent();
+ _list = logic.ReadList(null);
+ if (_list != null)
+ {
+ comboBoxProduct.DisplayMember = "Name";
+ comboBoxProduct.ValueMember = "Id";
+ comboBoxProduct.DataSource = _list;
+ comboBoxProduct.SelectedItem = null;
+ }
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (numericUpDownCount.Value == null || numericUpDownCount.Value <= 0)
+ {
+ MessageBox.Show("Кол-во товаров должно иметь значение больше 0", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxProduct.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите товар", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/WinFormsApp/FormSupplyProduct.resx b/WinFormsApp/FormSupplyProduct.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/WinFormsApp/FormSupplyProduct.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/WinFormsApp/Program.cs b/WinFormsApp/Program.cs
index 3297ebc..ee6b2c4 100644
--- a/WinFormsApp/Program.cs
+++ b/WinFormsApp/Program.cs
@@ -47,6 +47,8 @@ namespace WinFormsApp
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file