похер сойдёт
This commit is contained in:
parent
ac6ab33e2c
commit
6d686b4851
@ -14,7 +14,7 @@ namespace Contracts.StorageContracts
|
||||
List<SupplyViewModel> GetFullList();
|
||||
List<SupplyViewModel> GetFilteredList(SupplySearchModel model);
|
||||
SupplyViewModel? GetElement(SupplySearchModel model);
|
||||
SupplyViewModel? Insert(SupplyBindingModel model);
|
||||
bool? Insert(SupplyBindingModel model);
|
||||
bool? Update(SupplyBindingModel model);
|
||||
SupplyViewModel? Delete(SupplyBindingModel model);
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ namespace DatabaseImplement.Implements
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public SupplyViewModel? Insert(SupplyBindingModel model)
|
||||
public bool? Insert(SupplyBindingModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
var newProduct = Supply.Create(context, model);
|
||||
@ -124,7 +124,7 @@ namespace DatabaseImplement.Implements
|
||||
{
|
||||
Debug.WriteLine(ex);
|
||||
}
|
||||
return newProduct.GetViewModel;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool? Update(SupplyBindingModel model)
|
||||
|
209
WinFormsApp/FormSupplier.Designer.cs
generated
Normal file
209
WinFormsApp/FormSupplier.Designer.cs
generated
Normal file
@ -0,0 +1,209 @@
|
||||
namespace WinFormsApp
|
||||
{
|
||||
partial class FormSupplier
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonCancel = new Button();
|
||||
buttonSave = new Button();
|
||||
label1 = new Label();
|
||||
groupBoxProducts = new GroupBox();
|
||||
buttonDeleteProduct = new Button();
|
||||
buttonUpdateProduct = new Button();
|
||||
buttonAddProduct = new Button();
|
||||
dataGridView = new DataGridView();
|
||||
ProductId = new DataGridViewTextBoxColumn();
|
||||
ProductName = new DataGridViewTextBoxColumn();
|
||||
ProductAmount = new DataGridViewTextBoxColumn();
|
||||
textBoxName = new TextBox();
|
||||
numericUpDownDeals = new NumericUpDown();
|
||||
label2 = new Label();
|
||||
groupBoxProducts.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownDeals).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(307, 83);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(75, 23);
|
||||
buttonCancel.TabIndex = 12;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(307, 35);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(75, 23);
|
||||
buttonSave.TabIndex = 11;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(18, 18);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(215, 15);
|
||||
label1.TabIndex = 10;
|
||||
label1.Text = "Имя/название компании поставщика";
|
||||
//
|
||||
// groupBoxProducts
|
||||
//
|
||||
groupBoxProducts.Controls.Add(buttonDeleteProduct);
|
||||
groupBoxProducts.Controls.Add(buttonUpdateProduct);
|
||||
groupBoxProducts.Controls.Add(buttonAddProduct);
|
||||
groupBoxProducts.Controls.Add(dataGridView);
|
||||
groupBoxProducts.Location = new Point(12, 145);
|
||||
groupBoxProducts.Name = "groupBoxProducts";
|
||||
groupBoxProducts.Size = new Size(776, 288);
|
||||
groupBoxProducts.TabIndex = 9;
|
||||
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;
|
||||
//
|
||||
// buttonUpdateProduct
|
||||
//
|
||||
buttonUpdateProduct.Location = new Point(435, 77);
|
||||
buttonUpdateProduct.Name = "buttonUpdateProduct";
|
||||
buttonUpdateProduct.Size = new Size(126, 49);
|
||||
buttonUpdateProduct.TabIndex = 3;
|
||||
buttonUpdateProduct.Text = "Изменить";
|
||||
buttonUpdateProduct.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// 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;
|
||||
//
|
||||
// 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;
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
textBoxName.Location = new Point(18, 36);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(215, 23);
|
||||
textBoxName.TabIndex = 8;
|
||||
//
|
||||
// numericUpDownDeals
|
||||
//
|
||||
numericUpDownDeals.Location = new Point(18, 85);
|
||||
numericUpDownDeals.Name = "numericUpDownDeals";
|
||||
numericUpDownDeals.Size = new Size(120, 23);
|
||||
numericUpDownDeals.TabIndex = 13;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(18, 67);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(87, 15);
|
||||
label2.TabIndex = 14;
|
||||
label2.Text = "Кол-во сделок";
|
||||
//
|
||||
// FormSupplier
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(numericUpDownDeals);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(groupBoxProducts);
|
||||
Controls.Add(textBoxName);
|
||||
Name = "FormSupplier";
|
||||
Text = "FormSupplier";
|
||||
Load += FormSupplier_Load;
|
||||
groupBoxProducts.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownDeals).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonCancel;
|
||||
private Button buttonSave;
|
||||
private Label label1;
|
||||
private GroupBox groupBoxProducts;
|
||||
private Button buttonDeleteProduct;
|
||||
private Button buttonUpdateProduct;
|
||||
private Button buttonAddProduct;
|
||||
private DataGridView dataGridView;
|
||||
private DataGridViewTextBoxColumn ProductId;
|
||||
private DataGridViewTextBoxColumn ProductName;
|
||||
private DataGridViewTextBoxColumn ProductAmount;
|
||||
private TextBox textBoxName;
|
||||
private NumericUpDown numericUpDownDeals;
|
||||
private Label label2;
|
||||
}
|
||||
}
|
143
WinFormsApp/FormSupplier.cs
Normal file
143
WinFormsApp/FormSupplier.cs
Normal file
@ -0,0 +1,143 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.BusinessLogicContracts;
|
||||
using Contracts.SearchModels;
|
||||
using DatabaseImplement.Models;
|
||||
using DataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
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 FormSupplier : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISupplierLogic _logic;
|
||||
private Guid? _id;
|
||||
private Dictionary<Guid, (IProduct, int)> _supplierProducts;
|
||||
public Guid Id { set { _id = value; } }
|
||||
public FormSupplier(ILogger<FormSupply> logger, ISupplierLogic supplierLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_supplierProducts = new Dictionary<Guid, (IProduct, int)>();
|
||||
_logic = supplierLogic;
|
||||
}
|
||||
private void FormSupplier_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
_logger.LogInformation("Загрузка изделия");
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new SupplierSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
if (view != null)
|
||||
{
|
||||
textBoxName.Text = view.Name;
|
||||
_supplierProducts = view.AvailibleProducts ?? new Dictionary<Guid, (IProduct, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки изделия");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка компонент изделия");
|
||||
try
|
||||
{
|
||||
if (_supplierProducts != null)
|
||||
{
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var pc in _supplierProducts)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.Name, pc.Value.Item2 });
|
||||
}
|
||||
}
|
||||
}
|
||||
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(FormSupplierProduct));
|
||||
if (service is FormSupplierProduct form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (form.ProductModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Добавление нового компонента");
|
||||
if (_supplierProducts.ContainsKey(form.Id))
|
||||
{
|
||||
_supplierProducts[form.Id] = (form.ProductModel, form.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
_supplierProducts.Add(form.Id, (form.ProductModel, form.Count));
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните информацию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (_supplierProducts == null || _supplierProducts.Count == 0)
|
||||
{
|
||||
MessageBox.Show("Заполните товары", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение изделия");
|
||||
try
|
||||
{
|
||||
var model = new SupplierBindingModel
|
||||
{
|
||||
Id = _id ?? Guid.NewGuid(),
|
||||
Name = textBoxName.Text,
|
||||
AvailibleProducts = _supplierProducts,
|
||||
Deals = Convert.ToInt32(numericUpDownDeals.Value),
|
||||
};
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
129
WinFormsApp/FormSupplier.resx
Normal file
129
WinFormsApp/FormSupplier.resx
Normal file
@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="ProductId.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ProductName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ProductAmount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
95
WinFormsApp/FormSupplierProduct.Designer.cs
generated
Normal file
95
WinFormsApp/FormSupplierProduct.Designer.cs
generated
Normal file
@ -0,0 +1,95 @@
|
||||
namespace WinFormsApp
|
||||
{
|
||||
partial class FormSupplierProduct
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonCancel = new Button();
|
||||
buttonSave = new Button();
|
||||
comboBoxProduct = new ComboBox();
|
||||
numericUpDownCount = new NumericUpDown();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(179, 77);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(75, 23);
|
||||
buttonCancel.TabIndex = 8;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(179, 53);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(75, 23);
|
||||
buttonSave.TabIndex = 7;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// comboBoxProduct
|
||||
//
|
||||
comboBoxProduct.FormattingEnabled = true;
|
||||
comboBoxProduct.Location = new Point(12, 12);
|
||||
comboBoxProduct.Name = "comboBoxProduct";
|
||||
comboBoxProduct.Size = new Size(121, 23);
|
||||
comboBoxProduct.TabIndex = 6;
|
||||
//
|
||||
// numericUpDownCount
|
||||
//
|
||||
numericUpDownCount.Location = new Point(13, 55);
|
||||
numericUpDownCount.Name = "numericUpDownCount";
|
||||
numericUpDownCount.Size = new Size(120, 23);
|
||||
numericUpDownCount.TabIndex = 5;
|
||||
//
|
||||
// FormSupplierProduct
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(291, 123);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(comboBoxProduct);
|
||||
Controls.Add(numericUpDownCount);
|
||||
Name = "FormSupplierProduct";
|
||||
Text = "FormSupplierProduct";
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonCancel;
|
||||
private Button buttonSave;
|
||||
private ComboBox comboBoxProduct;
|
||||
private NumericUpDown numericUpDownCount;
|
||||
}
|
||||
}
|
88
WinFormsApp/FormSupplierProduct.cs
Normal file
88
WinFormsApp/FormSupplierProduct.cs
Normal file
@ -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 FormSupplierProduct : Form
|
||||
{
|
||||
private readonly List<ProductViewModel>? _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 FormSupplierProduct(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();
|
||||
}
|
||||
}
|
||||
}
|
120
WinFormsApp/FormSupplierProduct.resx
Normal file
120
WinFormsApp/FormSupplierProduct.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
295
WinFormsApp/FormSuppliers.Designer.cs
generated
295
WinFormsApp/FormSuppliers.Designer.cs
generated
@ -28,308 +28,59 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxCreateSupplier = new GroupBox();
|
||||
label4 = new Label();
|
||||
label3 = new Label();
|
||||
numericUpDownDeals = new NumericUpDown();
|
||||
groupBoxSupplierProducts = new GroupBox();
|
||||
buttonDeleteProduct = new Button();
|
||||
label2 = new Label();
|
||||
buttonCancel = new Button();
|
||||
label1 = new Label();
|
||||
buttonSaveSupplier = new Button();
|
||||
numericUpDownCount = new NumericUpDown();
|
||||
comboBoxProducts = new ComboBox();
|
||||
dataGridViewProducts = new DataGridView();
|
||||
buttonAddSupplierProduct = new Button();
|
||||
textBoxName = new TextBox();
|
||||
groupBoxControls = new GroupBox();
|
||||
buttonDeleteSupplier = new Button();
|
||||
buttonUpdateSupplier = new Button();
|
||||
buttonCreateSupplier = new Button();
|
||||
dataGridView = new DataGridView();
|
||||
ColumnId = new DataGridViewTextBoxColumn();
|
||||
Column = new DataGridViewTextBoxColumn();
|
||||
Column2 = new DataGridViewTextBoxColumn();
|
||||
groupBoxCreateSupplier.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownDeals).BeginInit();
|
||||
groupBoxSupplierProducts.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).BeginInit();
|
||||
groupBoxControls.SuspendLayout();
|
||||
buttonAdd = new Button();
|
||||
buttonEdit = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxCreateSupplier
|
||||
//
|
||||
groupBoxCreateSupplier.BackColor = Color.Transparent;
|
||||
groupBoxCreateSupplier.Controls.Add(label4);
|
||||
groupBoxCreateSupplier.Controls.Add(label3);
|
||||
groupBoxCreateSupplier.Controls.Add(numericUpDownDeals);
|
||||
groupBoxCreateSupplier.Controls.Add(groupBoxSupplierProducts);
|
||||
groupBoxCreateSupplier.Controls.Add(textBoxName);
|
||||
groupBoxCreateSupplier.Dock = DockStyle.Right;
|
||||
groupBoxCreateSupplier.Location = new Point(288, 0);
|
||||
groupBoxCreateSupplier.Name = "groupBoxCreateSupplier";
|
||||
groupBoxCreateSupplier.Size = new Size(367, 637);
|
||||
groupBoxCreateSupplier.TabIndex = 6;
|
||||
groupBoxCreateSupplier.TabStop = false;
|
||||
groupBoxCreateSupplier.Text = "Создание/изменение поставщика";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(17, 93);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(87, 15);
|
||||
label4.TabIndex = 15;
|
||||
label4.Text = "Кол-во сделок";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(6, 54);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(101, 15);
|
||||
label3.TabIndex = 14;
|
||||
label3.Text = "Имя поставщика";
|
||||
//
|
||||
// numericUpDownDeals
|
||||
//
|
||||
numericUpDownDeals.Location = new Point(110, 91);
|
||||
numericUpDownDeals.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
|
||||
numericUpDownDeals.Name = "numericUpDownDeals";
|
||||
numericUpDownDeals.Size = new Size(245, 23);
|
||||
numericUpDownDeals.TabIndex = 14;
|
||||
//
|
||||
// groupBoxSupplierProducts
|
||||
//
|
||||
groupBoxSupplierProducts.Controls.Add(buttonDeleteProduct);
|
||||
groupBoxSupplierProducts.Controls.Add(label2);
|
||||
groupBoxSupplierProducts.Controls.Add(buttonCancel);
|
||||
groupBoxSupplierProducts.Controls.Add(label1);
|
||||
groupBoxSupplierProducts.Controls.Add(buttonSaveSupplier);
|
||||
groupBoxSupplierProducts.Controls.Add(numericUpDownCount);
|
||||
groupBoxSupplierProducts.Controls.Add(comboBoxProducts);
|
||||
groupBoxSupplierProducts.Controls.Add(dataGridViewProducts);
|
||||
groupBoxSupplierProducts.Controls.Add(buttonAddSupplierProduct);
|
||||
groupBoxSupplierProducts.Location = new Point(0, 149);
|
||||
groupBoxSupplierProducts.Name = "groupBoxSupplierProducts";
|
||||
groupBoxSupplierProducts.Size = new Size(361, 482);
|
||||
groupBoxSupplierProducts.TabIndex = 10;
|
||||
groupBoxSupplierProducts.TabStop = false;
|
||||
groupBoxSupplierProducts.Text = "Доступные товары поставщика";
|
||||
//
|
||||
// buttonDeleteProduct
|
||||
//
|
||||
buttonDeleteProduct.Location = new Point(58, 307);
|
||||
buttonDeleteProduct.Name = "buttonDeleteProduct";
|
||||
buttonDeleteProduct.Size = new Size(81, 23);
|
||||
buttonDeleteProduct.TabIndex = 15;
|
||||
buttonDeleteProduct.Text = "Удалить";
|
||||
buttonDeleteProduct.UseVisualStyleBackColor = true;
|
||||
buttonDeleteProduct.Click += buttonDeleteProduct_Click;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(6, 251);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(46, 15);
|
||||
label2.TabIndex = 13;
|
||||
label2.Text = "Кол-во";
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(262, 453);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(75, 23);
|
||||
buttonCancel.TabIndex = 5;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(13, 223);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(39, 15);
|
||||
label1.TabIndex = 12;
|
||||
label1.Text = "Товар";
|
||||
//
|
||||
// buttonSaveSupplier
|
||||
//
|
||||
buttonSaveSupplier.Location = new Point(29, 453);
|
||||
buttonSaveSupplier.Name = "buttonSaveSupplier";
|
||||
buttonSaveSupplier.Size = new Size(75, 23);
|
||||
buttonSaveSupplier.TabIndex = 4;
|
||||
buttonSaveSupplier.Text = "Сохранить";
|
||||
buttonSaveSupplier.UseVisualStyleBackColor = true;
|
||||
buttonSaveSupplier.Click += buttonSaveProduct_Click;
|
||||
//
|
||||
// numericUpDownCount
|
||||
//
|
||||
numericUpDownCount.Location = new Point(58, 249);
|
||||
numericUpDownCount.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
|
||||
numericUpDownCount.Name = "numericUpDownCount";
|
||||
numericUpDownCount.Size = new Size(297, 23);
|
||||
numericUpDownCount.TabIndex = 11;
|
||||
//
|
||||
// comboBoxProducts
|
||||
//
|
||||
comboBoxProducts.FormattingEnabled = true;
|
||||
comboBoxProducts.Location = new Point(58, 220);
|
||||
comboBoxProducts.Name = "comboBoxProducts";
|
||||
comboBoxProducts.Size = new Size(297, 23);
|
||||
comboBoxProducts.TabIndex = 10;
|
||||
//
|
||||
// dataGridViewProducts
|
||||
//
|
||||
dataGridViewProducts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewProducts.Columns.AddRange(new DataGridViewColumn[] { ColumnId, Column, Column2 });
|
||||
dataGridViewProducts.Dock = DockStyle.Top;
|
||||
dataGridViewProducts.Location = new Point(3, 19);
|
||||
dataGridViewProducts.Name = "dataGridViewProducts";
|
||||
dataGridViewProducts.Size = new Size(355, 195);
|
||||
dataGridViewProducts.TabIndex = 8;
|
||||
//
|
||||
// buttonAddSupplierProduct
|
||||
//
|
||||
buttonAddSupplierProduct.Location = new Point(58, 278);
|
||||
buttonAddSupplierProduct.Name = "buttonAddSupplierProduct";
|
||||
buttonAddSupplierProduct.Size = new Size(81, 23);
|
||||
buttonAddSupplierProduct.TabIndex = 9;
|
||||
buttonAddSupplierProduct.Text = "Добавить";
|
||||
buttonAddSupplierProduct.UseVisualStyleBackColor = true;
|
||||
buttonAddSupplierProduct.Click += buttonAddSupplierProduct_Click;
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
textBoxName.Location = new Point(110, 51);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(245, 23);
|
||||
textBoxName.TabIndex = 0;
|
||||
//
|
||||
// groupBoxControls
|
||||
//
|
||||
groupBoxControls.BackColor = Color.Transparent;
|
||||
groupBoxControls.Controls.Add(buttonDeleteSupplier);
|
||||
groupBoxControls.Controls.Add(buttonUpdateSupplier);
|
||||
groupBoxControls.Controls.Add(buttonCreateSupplier);
|
||||
groupBoxControls.Dock = DockStyle.Right;
|
||||
groupBoxControls.Location = new Point(655, 0);
|
||||
groupBoxControls.Name = "groupBoxControls";
|
||||
groupBoxControls.Size = new Size(264, 637);
|
||||
groupBoxControls.TabIndex = 5;
|
||||
groupBoxControls.TabStop = false;
|
||||
groupBoxControls.Text = "Действия";
|
||||
//
|
||||
// buttonDeleteSupplier
|
||||
//
|
||||
buttonDeleteSupplier.Location = new Point(69, 120);
|
||||
buttonDeleteSupplier.Name = "buttonDeleteSupplier";
|
||||
buttonDeleteSupplier.Size = new Size(139, 23);
|
||||
buttonDeleteSupplier.TabIndex = 3;
|
||||
buttonDeleteSupplier.Text = "Удалить поставщика";
|
||||
buttonDeleteSupplier.UseVisualStyleBackColor = true;
|
||||
buttonDeleteSupplier.Click += buttonDeleteSupplier_Click;
|
||||
//
|
||||
// buttonUpdateSupplier
|
||||
//
|
||||
buttonUpdateSupplier.Location = new Point(46, 51);
|
||||
buttonUpdateSupplier.Name = "buttonUpdateSupplier";
|
||||
buttonUpdateSupplier.Size = new Size(179, 63);
|
||||
buttonUpdateSupplier.TabIndex = 2;
|
||||
buttonUpdateSupplier.Text = "Редактировать информацию о поставщике";
|
||||
buttonUpdateSupplier.UseVisualStyleBackColor = true;
|
||||
buttonUpdateSupplier.Click += buttonUpdateSupplier_Click;
|
||||
//
|
||||
// buttonCreateSupplier
|
||||
//
|
||||
buttonCreateSupplier.Location = new Point(69, 22);
|
||||
buttonCreateSupplier.Name = "buttonCreateSupplier";
|
||||
buttonCreateSupplier.Size = new Size(139, 23);
|
||||
buttonCreateSupplier.TabIndex = 1;
|
||||
buttonCreateSupplier.Text = "Добавить поставщика";
|
||||
buttonCreateSupplier.UseVisualStyleBackColor = true;
|
||||
buttonCreateSupplier.Click += buttonCreateSupplier_Click;
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Dock = DockStyle.Left;
|
||||
dataGridView.Location = new Point(0, 0);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.Size = new Size(392, 637);
|
||||
dataGridView.Size = new Size(615, 637);
|
||||
dataGridView.TabIndex = 4;
|
||||
//
|
||||
// ColumnId
|
||||
// buttonAdd
|
||||
//
|
||||
ColumnId.HeaderText = "Id";
|
||||
ColumnId.Name = "ColumnId";
|
||||
ColumnId.ReadOnly = true;
|
||||
buttonAdd.Location = new Point(635, 50);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(75, 23);
|
||||
buttonAdd.TabIndex = 5;
|
||||
buttonAdd.Text = "Добавить";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
//
|
||||
// Column
|
||||
// buttonEdit
|
||||
//
|
||||
Column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
Column.HeaderText = "Продукт";
|
||||
Column.Name = "Column";
|
||||
Column.ReadOnly = true;
|
||||
//
|
||||
// Column2
|
||||
//
|
||||
Column2.HeaderText = "Кол-во";
|
||||
Column2.Name = "Column2";
|
||||
Column2.ReadOnly = true;
|
||||
buttonEdit.Location = new Point(648, 115);
|
||||
buttonEdit.Name = "buttonEdit";
|
||||
buttonEdit.Size = new Size(122, 23);
|
||||
buttonEdit.TabIndex = 6;
|
||||
buttonEdit.Text = "Редактировать";
|
||||
buttonEdit.UseVisualStyleBackColor = true;
|
||||
buttonEdit.Click += buttonEdit_Click;
|
||||
//
|
||||
// FormSuppliers
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(919, 637);
|
||||
Controls.Add(groupBoxCreateSupplier);
|
||||
Controls.Add(groupBoxControls);
|
||||
Controls.Add(buttonEdit);
|
||||
Controls.Add(buttonAdd);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormSuppliers";
|
||||
Text = "FormSuppliers";
|
||||
Load += FormSuppliers_Load;
|
||||
groupBoxCreateSupplier.ResumeLayout(false);
|
||||
groupBoxCreateSupplier.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownDeals).EndInit();
|
||||
groupBoxSupplierProducts.ResumeLayout(false);
|
||||
groupBoxSupplierProducts.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).EndInit();
|
||||
groupBoxControls.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxCreateSupplier;
|
||||
private Button buttonCancel;
|
||||
private Button buttonSaveSupplier;
|
||||
private TextBox textBoxName;
|
||||
private GroupBox groupBoxControls;
|
||||
private Button buttonDeleteSupplier;
|
||||
private Button buttonUpdateSupplier;
|
||||
private Button buttonCreateSupplier;
|
||||
private DataGridView dataGridView;
|
||||
private DataGridView dataGridViewProducts;
|
||||
private GroupBox groupBoxSupplierProducts;
|
||||
private Button buttonAddSupplierProduct;
|
||||
private ComboBox comboBoxProducts;
|
||||
private Label label2;
|
||||
private Label label1;
|
||||
private NumericUpDown numericUpDownCount;
|
||||
private Label label4;
|
||||
private Label label3;
|
||||
private NumericUpDown numericUpDownDeals;
|
||||
private Button buttonDeleteProduct;
|
||||
private DataGridViewTextBoxColumn ColumnId;
|
||||
private DataGridViewTextBoxColumn Column;
|
||||
private DataGridViewTextBoxColumn Column2;
|
||||
private Button buttonAdd;
|
||||
private Button buttonEdit;
|
||||
}
|
||||
}
|
@ -22,48 +22,24 @@ namespace WinFormsApp
|
||||
{
|
||||
public partial class FormSuppliers : Form
|
||||
{
|
||||
private Guid? _id;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISupplierLogic _supplierLogic;
|
||||
private readonly IProductLogic _productLogic;
|
||||
private Dictionary<Guid, (IProduct, int)> _supplierProducts;
|
||||
private List<ProductViewModel> _productList;
|
||||
public FormSuppliers(ILogger<FormMain> logger, ISupplierLogic supplierLogic, IProductLogic productLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_supplierLogic = supplierLogic;
|
||||
_logger = logger;
|
||||
_productLogic = productLogic;
|
||||
_supplierProducts = new Dictionary<Guid, (IProduct, int)>();
|
||||
_productList = _productLogic.ReadList(null);
|
||||
if (_productList != null)
|
||||
{
|
||||
comboBoxProducts.DisplayMember = "Name";
|
||||
comboBoxProducts.ValueMember = "Id";
|
||||
comboBoxProducts.DataSource = _productList;
|
||||
comboBoxProducts.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void FormSuppliers_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
groupBoxCreateSupplier.Hide();
|
||||
//groupBoxCreateProduct.Enabled = false;
|
||||
}
|
||||
|
||||
private void LoadSupplierData()
|
||||
{
|
||||
dataGridViewProducts.Rows.Clear();
|
||||
foreach (var pc in _supplierProducts)
|
||||
{
|
||||
dataGridViewProducts.Rows.Add(new object[] { pc.Value.Item1.Id, pc.Value.Item1.Name, pc.Value.Item2 });
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Загрузка поставщиков");
|
||||
try
|
||||
{
|
||||
var list = _supplierLogic.ReadList(null);
|
||||
@ -71,197 +47,41 @@ namespace WinFormsApp
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
}
|
||||
_logger.LogInformation("Загрузка поставщиков");
|
||||
_logger.LogInformation("Загрузка компьютеров");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки поставщиков");
|
||||
_logger.LogError(ex, "Ошибка загрузки компьютеров");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCreateSupplier_Click(object sender, EventArgs e)
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
//надо сделать че нибудь с фронтом а то всё грустно
|
||||
groupBoxControls.Hide();
|
||||
//groupBoxControls.Enabled = false;
|
||||
groupBoxCreateSupplier.Show();
|
||||
//groupBoxCreateProduct.Enabled = true;
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSupplier));
|
||||
if (service is FormSupplier form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonUpdateSupplier_Click(object sender, EventArgs e)
|
||||
private void buttonEdit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count <= 0) return;
|
||||
_id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value;
|
||||
groupBoxControls.Hide();
|
||||
groupBoxCreateSupplier.Show();
|
||||
_logger.LogInformation("Получение поставщика");
|
||||
var view = _supplierLogic.ReadElement(new SupplierSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
_supplierProducts = view.AvailibleProducts;
|
||||
textBoxName.Text = view.Name;
|
||||
numericUpDownDeals.Value = view.Deals;
|
||||
LoadSupplierData();
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
_id = null;
|
||||
_supplierProducts.Clear();
|
||||
groupBoxControls.Show();
|
||||
//groupBoxControls.Enabled = false;
|
||||
groupBoxCreateSupplier.Hide();
|
||||
//groupBoxCreateProduct.Enabled = true;
|
||||
textBoxName.Text = string.Empty;
|
||||
}
|
||||
|
||||
private void buttonDeleteSupplier_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSupplier));
|
||||
if (service is FormSupplier form)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IProduct? ProductModel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_productList == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var elem in _productList)
|
||||
{
|
||||
if (elem.Id == Id)
|
||||
{
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Guid Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Guid)comboBoxProducts.SelectedValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
comboBoxProducts.SelectedValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonAddSupplierProduct_Click(object sender, EventArgs e)
|
||||
{
|
||||
Debug.WriteLine(comboBoxProducts.SelectedValue);
|
||||
if (_supplierProducts.ContainsKey(Id))
|
||||
{
|
||||
_supplierProducts[Id] = (ProductModel, Convert.ToInt16(numericUpDownCount.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
_supplierProducts.Add(Id, (ProductModel, Convert.ToInt16(numericUpDownCount.Value)));
|
||||
}
|
||||
|
||||
LoadSupplierData();
|
||||
}
|
||||
|
||||
private void buttonSaveProduct_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните имя поставщика", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение поставщика");
|
||||
try
|
||||
{
|
||||
var model = new SupplierBindingModel
|
||||
{
|
||||
Id = _id ?? Guid.Empty,
|
||||
Name = textBoxName.Text,
|
||||
Deals = Convert.ToInt32(numericUpDownDeals.Value),
|
||||
AvailibleProducts = _supplierProducts
|
||||
};
|
||||
|
||||
var operationResult = _id.HasValue ? _supplierLogic.Update(model) : _supplierLogic.Create(model);
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения поставщика");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
finally
|
||||
form.Id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value;
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
_id = null;
|
||||
_supplierProducts = new Dictionary<Guid, (IProduct, int)>();
|
||||
textBoxName.Text = string.Empty;
|
||||
numericUpDownDeals.Value = 0;
|
||||
//groupBoxControls.Enabled = true;
|
||||
groupBoxControls.Show();
|
||||
//groupBoxCreateSupplier.Enabled = false;
|
||||
groupBoxCreateSupplier.Hide();
|
||||
textBoxName.Text = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonDeleteProduct_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridViewProducts.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Удаление продукта из списка доступных продуктов поставщика");
|
||||
Debug.WriteLine(_supplierProducts.Keys);
|
||||
Debug.WriteLine(_supplierProducts.Values);
|
||||
Debug.WriteLine((Guid)dataGridView.SelectedRows[0].Cells[0].Value);
|
||||
_supplierProducts?.Remove((Guid)dataGridView.SelectedRows[0].Cells[0].Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
LoadSupplierData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,13 +117,4 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="ColumnId.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Column.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
@ -47,8 +47,11 @@ namespace WinFormsApp
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormProducts>();
|
||||
services.AddTransient<FormSuppliers>();
|
||||
services.AddTransient<FormSupplier>();
|
||||
services.AddTransient<FormSupply>();
|
||||
services.AddTransient<FormSupplyProduct>();
|
||||
services.AddTransient<FormSupplierProduct>();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user