изменение по лабе 2
This commit is contained in:
parent
7580a38655
commit
7ebcb8e97d
@ -8,7 +8,7 @@ public class Product
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public ProductType Type { get; private set; }
|
||||
public int CountInWarehouse { get; private set; }
|
||||
public IEnumerable<ProductMaterial> ProductMaterial { get; private set; } = [];
|
||||
public IEnumerable<ProductMaterial> ProductMaterial { get; set; } = [];
|
||||
public static Product CreateEntity(int id, string name, ProductType type, int countInWarehouse, IEnumerable<ProductMaterial> productMaterial)
|
||||
{
|
||||
return new Product
|
||||
|
@ -3,8 +3,8 @@
|
||||
public class ProductMaterial
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int MaterialId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public int MaterialId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public static ProductMaterial CreateOperation(int id, int materialId, int count)
|
||||
{
|
||||
return new ProductMaterial
|
||||
|
@ -34,14 +34,17 @@
|
||||
labelCount = new Label();
|
||||
textBoxName = new TextBox();
|
||||
numericUpDownCount = new NumericUpDown();
|
||||
comboBoxMaterial = new ComboBox();
|
||||
labelMaterial = new Label();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.Location = new Point(33, 164);
|
||||
buttonAdd.Location = new Point(38, 219);
|
||||
buttonAdd.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(75, 23);
|
||||
buttonAdd.Size = new Size(86, 31);
|
||||
buttonAdd.TabIndex = 1;
|
||||
buttonAdd.Text = "Add";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
@ -49,9 +52,10 @@
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(199, 164);
|
||||
buttonCancel.Location = new Point(227, 219);
|
||||
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(75, 23);
|
||||
buttonCancel.Size = new Size(86, 31);
|
||||
buttonCancel.TabIndex = 2;
|
||||
buttonCancel.Text = "Cancel";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
@ -60,47 +64,71 @@
|
||||
// labelName
|
||||
//
|
||||
labelName.AutoSize = true;
|
||||
labelName.Location = new Point(33, 46);
|
||||
labelName.Location = new Point(38, 25);
|
||||
labelName.Name = "labelName";
|
||||
labelName.Size = new Size(39, 15);
|
||||
labelName.Size = new Size(49, 20);
|
||||
labelName.TabIndex = 3;
|
||||
labelName.Text = "Name";
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
labelCount.AutoSize = true;
|
||||
labelCount.Location = new Point(33, 97);
|
||||
labelCount.Location = new Point(38, 129);
|
||||
labelCount.Name = "labelCount";
|
||||
labelCount.Size = new Size(40, 15);
|
||||
labelCount.Size = new Size(48, 20);
|
||||
labelCount.TabIndex = 4;
|
||||
labelCount.Text = "Count";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
textBoxName.Location = new Point(124, 46);
|
||||
textBoxName.Location = new Point(142, 22);
|
||||
textBoxName.Margin = new Padding(3, 4, 3, 4);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(120, 23);
|
||||
textBoxName.Size = new Size(137, 27);
|
||||
textBoxName.TabIndex = 7;
|
||||
//
|
||||
// numericUpDownCount
|
||||
//
|
||||
numericUpDownCount.Location = new Point(124, 97);
|
||||
numericUpDownCount.Location = new Point(142, 129);
|
||||
numericUpDownCount.Margin = new Padding(3, 4, 3, 4);
|
||||
numericUpDownCount.Name = "numericUpDownCount";
|
||||
numericUpDownCount.Size = new Size(120, 23);
|
||||
numericUpDownCount.Size = new Size(137, 27);
|
||||
numericUpDownCount.TabIndex = 8;
|
||||
//
|
||||
// FormMaterialSpent
|
||||
// comboBoxMaterial
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
comboBoxMaterial.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxMaterial.FormattingEnabled = true;
|
||||
comboBoxMaterial.Location = new Point(142, 70);
|
||||
comboBoxMaterial.Margin = new Padding(3, 4, 3, 4);
|
||||
comboBoxMaterial.Name = "comboBoxMaterial";
|
||||
comboBoxMaterial.Size = new Size(137, 28);
|
||||
comboBoxMaterial.TabIndex = 9;
|
||||
//
|
||||
// labelMaterial
|
||||
//
|
||||
labelMaterial.AutoSize = true;
|
||||
labelMaterial.Location = new Point(37, 73);
|
||||
labelMaterial.Name = "labelMaterial";
|
||||
labelMaterial.Size = new Size(64, 20);
|
||||
labelMaterial.TabIndex = 10;
|
||||
labelMaterial.Text = "Material";
|
||||
//
|
||||
// FormMaterialReplenishment
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(304, 204);
|
||||
ClientSize = new Size(347, 272);
|
||||
Controls.Add(labelMaterial);
|
||||
Controls.Add(comboBoxMaterial);
|
||||
Controls.Add(numericUpDownCount);
|
||||
Controls.Add(textBoxName);
|
||||
Controls.Add(labelCount);
|
||||
Controls.Add(labelName);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonAdd);
|
||||
Name = "FormMaterialSpent";
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormMaterialReplenishment";
|
||||
Text = "FormMaterialSpent";
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
|
||||
ResumeLayout(false);
|
||||
@ -115,5 +143,7 @@
|
||||
private Label labelCount;
|
||||
private TextBox textBoxName;
|
||||
private NumericUpDown numericUpDownCount;
|
||||
private ComboBox comboBoxMaterial;
|
||||
private Label labelMaterial;
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using CarpentryWorkshop.Entities;
|
||||
using CarpentryWorkshop.Entities.Enums;
|
||||
using CarpentryWorkshop.Repositories;
|
||||
|
||||
namespace CarpentryWorkshop.Forms
|
||||
@ -29,10 +30,13 @@ namespace CarpentryWorkshop.Forms
|
||||
}
|
||||
}
|
||||
}
|
||||
public FormMaterialReplenishment(IMaterialReplenishmentRepository materialSpentRepository)
|
||||
public FormMaterialReplenishment(IMaterialReplenishmentRepository materialSpentRepository, IMaterialRepository materialRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_materialSpentRepository = materialSpentRepository ?? throw new ArgumentNullException(nameof(materialSpentRepository));
|
||||
comboBoxMaterial.DataSource = materialRepository.ReadMaterials();
|
||||
comboBoxMaterial.DisplayMember = "Name";
|
||||
comboBoxMaterial.ValueMember = "Id";
|
||||
}
|
||||
private MaterialReplenishment CreateMaterialSpent(int id) => MaterialReplenishment.CreateOperation(id, textBoxName.Text, Convert.ToInt32(numericUpDownCount.Value));
|
||||
private void buttonAdd_Click_1(object sender, EventArgs e)
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
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
|
||||
|
@ -48,9 +48,11 @@
|
||||
// groupBox
|
||||
//
|
||||
groupBox.Controls.Add(dataGridView);
|
||||
groupBox.Location = new Point(12, 171);
|
||||
groupBox.Location = new Point(14, 228);
|
||||
groupBox.Margin = new Padding(3, 4, 3, 4);
|
||||
groupBox.Name = "groupBox";
|
||||
groupBox.Size = new Size(567, 267);
|
||||
groupBox.Padding = new Padding(3, 4, 3, 4);
|
||||
groupBox.Size = new Size(648, 356);
|
||||
groupBox.TabIndex = 0;
|
||||
groupBox.TabStop = false;
|
||||
groupBox.Text = "groupBox";
|
||||
@ -61,16 +63,19 @@
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnMaterials, ColumnCount });
|
||||
dataGridView.Dock = DockStyle.Fill;
|
||||
dataGridView.Location = new Point(3, 19);
|
||||
dataGridView.Location = new Point(3, 24);
|
||||
dataGridView.Margin = new Padding(3, 4, 3, 4);
|
||||
dataGridView.MultiSelect = false;
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(561, 245);
|
||||
dataGridView.Size = new Size(642, 328);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// ColumnMaterials
|
||||
//
|
||||
ColumnMaterials.HeaderText = "Materials";
|
||||
ColumnMaterials.MinimumWidth = 6;
|
||||
ColumnMaterials.Name = "ColumnMaterials";
|
||||
ColumnMaterials.Resizable = DataGridViewTriState.True;
|
||||
ColumnMaterials.SortMode = DataGridViewColumnSortMode.Automatic;
|
||||
@ -78,14 +83,16 @@
|
||||
// ColumnCount
|
||||
//
|
||||
ColumnCount.HeaderText = "Count";
|
||||
ColumnCount.MinimumWidth = 6;
|
||||
ColumnCount.Name = "ColumnCount";
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonAdd.Location = new Point(84, 447);
|
||||
buttonAdd.Location = new Point(96, 596);
|
||||
buttonAdd.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(125, 23);
|
||||
buttonAdd.Size = new Size(143, 31);
|
||||
buttonAdd.TabIndex = 1;
|
||||
buttonAdd.Text = "Add";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
@ -94,9 +101,10 @@
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCancel.Location = new Point(355, 447);
|
||||
buttonCancel.Location = new Point(406, 596);
|
||||
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(125, 23);
|
||||
buttonCancel.Size = new Size(143, 31);
|
||||
buttonCancel.TabIndex = 2;
|
||||
buttonCancel.Text = "Cancel";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
@ -105,58 +113,61 @@
|
||||
// labelName
|
||||
//
|
||||
labelName.AutoSize = true;
|
||||
labelName.Location = new Point(31, 31);
|
||||
labelName.Location = new Point(35, 41);
|
||||
labelName.Name = "labelName";
|
||||
labelName.Size = new Size(39, 15);
|
||||
labelName.Size = new Size(49, 20);
|
||||
labelName.TabIndex = 3;
|
||||
labelName.Text = "Name";
|
||||
//
|
||||
// labelType
|
||||
//
|
||||
labelType.AutoSize = true;
|
||||
labelType.Location = new Point(31, 78);
|
||||
labelType.Location = new Point(35, 104);
|
||||
labelType.Name = "labelType";
|
||||
labelType.Size = new Size(76, 15);
|
||||
labelType.Size = new Size(95, 20);
|
||||
labelType.TabIndex = 4;
|
||||
labelType.Text = "Product Type";
|
||||
//
|
||||
// labelCountInWarehouse
|
||||
//
|
||||
labelCountInWarehouse.AutoSize = true;
|
||||
labelCountInWarehouse.Location = new Point(31, 130);
|
||||
labelCountInWarehouse.Location = new Point(35, 173);
|
||||
labelCountInWarehouse.Name = "labelCountInWarehouse";
|
||||
labelCountInWarehouse.Size = new Size(113, 15);
|
||||
labelCountInWarehouse.Size = new Size(139, 20);
|
||||
labelCountInWarehouse.TabIndex = 5;
|
||||
labelCountInWarehouse.Text = "Count in warehouse";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
textBoxName.Location = new Point(188, 28);
|
||||
textBoxName.Location = new Point(215, 37);
|
||||
textBoxName.Margin = new Padding(3, 4, 3, 4);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(141, 23);
|
||||
textBoxName.Size = new Size(161, 27);
|
||||
textBoxName.TabIndex = 6;
|
||||
//
|
||||
// comboBoxProduct
|
||||
//
|
||||
comboBoxProduct.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxProduct.FormattingEnabled = true;
|
||||
comboBoxProduct.Location = new Point(188, 78);
|
||||
comboBoxProduct.Location = new Point(215, 104);
|
||||
comboBoxProduct.Margin = new Padding(3, 4, 3, 4);
|
||||
comboBoxProduct.Name = "comboBoxProduct";
|
||||
comboBoxProduct.Size = new Size(141, 23);
|
||||
comboBoxProduct.Size = new Size(161, 28);
|
||||
comboBoxProduct.TabIndex = 7;
|
||||
//
|
||||
// numericUpDownCount
|
||||
//
|
||||
numericUpDownCount.Location = new Point(188, 130);
|
||||
numericUpDownCount.Location = new Point(215, 173);
|
||||
numericUpDownCount.Margin = new Padding(3, 4, 3, 4);
|
||||
numericUpDownCount.Name = "numericUpDownCount";
|
||||
numericUpDownCount.Size = new Size(141, 23);
|
||||
numericUpDownCount.Size = new Size(161, 27);
|
||||
numericUpDownCount.TabIndex = 8;
|
||||
//
|
||||
// FormMaterialConsumption
|
||||
// FormProductMaterial
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(591, 482);
|
||||
ClientSize = new Size(675, 643);
|
||||
Controls.Add(numericUpDownCount);
|
||||
Controls.Add(comboBoxProduct);
|
||||
Controls.Add(textBoxName);
|
||||
@ -166,7 +177,8 @@
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonAdd);
|
||||
Controls.Add(groupBox);
|
||||
Name = "FormMaterialConsumption";
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormProductMaterial";
|
||||
Text = "FormMaterialConsumption";
|
||||
groupBox.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
|
@ -7,6 +7,7 @@ namespace CarpentryWorkshop.Forms
|
||||
public partial class FormProductMaterial : Form
|
||||
{
|
||||
private readonly IProductRepository _productRepository;
|
||||
private readonly IMaterialRepository _materialRepository;
|
||||
private int? _productId;
|
||||
public int Id
|
||||
{
|
||||
@ -23,6 +24,20 @@ namespace CarpentryWorkshop.Forms
|
||||
comboBoxProduct.SelectedItem = product.Type;
|
||||
numericUpDownCount.Value = product.CountInWarehouse;
|
||||
_productId = value;
|
||||
dataGridView.Rows.Clear();
|
||||
var rows = new List<DataGridViewRow>();
|
||||
|
||||
foreach (var productMaterial in product.ProductMaterial)
|
||||
{
|
||||
var material = _materialRepository.ReadMaterialById(productMaterial.MaterialId);
|
||||
if (material != null)
|
||||
{
|
||||
var row = new DataGridViewRow();
|
||||
row.CreateCells(dataGridView,material.Id, productMaterial.Count);
|
||||
rows.Add(row);
|
||||
}
|
||||
}
|
||||
dataGridView.Rows.AddRange(rows.ToArray());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -35,7 +50,7 @@ namespace CarpentryWorkshop.Forms
|
||||
{
|
||||
InitializeComponent();
|
||||
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
|
||||
|
||||
_materialRepository = materialRepository ?? throw new ArgumentNullException(nameof(materialRepository));
|
||||
comboBoxProduct.DataSource = Enum.GetValues(typeof(ProductType));
|
||||
|
||||
ColumnMaterials.DataSource = materialRepository.ReadMaterials();
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
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
|
||||
|
@ -93,8 +93,22 @@ public class ProductRepository : IProductRepository
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @" SELECT * FROM Products WHERE Id = @Id";
|
||||
var product = connection.QueryFirstOrDefault<Product>(querySelect, new { Id = id });
|
||||
var querySelect = @"
|
||||
SELECT * FROM Products WHERE Id = @Id;
|
||||
SELECT m.*, pm.Count FROM Materials m
|
||||
JOIN Products_Materials pm ON m.Id = pm.MaterialId
|
||||
WHERE pm.ProductId = @Id";
|
||||
using var multi = connection.QueryMultiple(querySelect, new { Id = id });
|
||||
var product = multi.Read<Product>().FirstOrDefault();
|
||||
if (product != null)
|
||||
{
|
||||
var materials = multi.Read<Material>().ToList();
|
||||
product.ProductMaterial = materials.Select(m => new ProductMaterial
|
||||
{
|
||||
MaterialId = m.Id,
|
||||
Count = m.Count
|
||||
}).ToList();
|
||||
}
|
||||
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(product));
|
||||
return product;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user