This commit is contained in:
elizaveta 2024-11-27 10:11:56 +04:00
parent 4269c81538
commit 23b750a62c
4 changed files with 136 additions and 74 deletions

View File

@ -1,9 +1,10 @@
namespace CarpentryWorkshop.Entities.Enums;
[Flags]
public enum ProductType
{
None = 0,
Wardrobe = 1,
Table = 2,
Bench = 3
Wardrobe = 1 << 0,
Table = 1 << 1,
Bench = 1 << 2
}

View File

@ -38,8 +38,8 @@
labelType = new Label();
labelCountInWarehouse = new Label();
textBoxName = new TextBox();
comboBoxProduct = new ComboBox();
numericUpDownCount = new NumericUpDown();
checkedListBox1 = new CheckedListBox();
groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
@ -48,9 +48,11 @@
// groupBox
//
groupBox.Controls.Add(dataGridView);
groupBox.Location = new Point(12, 171);
groupBox.Location = new Point(22, 365);
groupBox.Margin = new Padding(6);
groupBox.Name = "groupBox";
groupBox.Size = new Size(567, 267);
groupBox.Padding = new Padding(6);
groupBox.Size = new Size(1053, 570);
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(6, 38);
dataGridView.Margin = new Padding(6);
dataGridView.MultiSelect = false;
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 82;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(561, 245);
dataGridView.Size = new Size(1041, 526);
dataGridView.TabIndex = 0;
//
// ColumnMaterials
//
ColumnMaterials.HeaderText = "Materials";
ColumnMaterials.MinimumWidth = 10;
ColumnMaterials.Name = "ColumnMaterials";
ColumnMaterials.Resizable = DataGridViewTriState.True;
ColumnMaterials.SortMode = DataGridViewColumnSortMode.Automatic;
@ -78,14 +83,16 @@
// ColumnCount
//
ColumnCount.HeaderText = "Count";
ColumnCount.MinimumWidth = 10;
ColumnCount.Name = "ColumnCount";
//
// buttonAdd
//
buttonAdd.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonAdd.Location = new Point(84, 447);
buttonAdd.Location = new Point(156, 954);
buttonAdd.Margin = new Padding(6);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(125, 23);
buttonAdd.Size = new Size(232, 49);
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(659, 954);
buttonCancel.Margin = new Padding(6);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(125, 23);
buttonCancel.Size = new Size(232, 49);
buttonCancel.TabIndex = 2;
buttonCancel.Text = "Cancel";
buttonCancel.UseVisualStyleBackColor = true;
@ -105,60 +113,66 @@
// labelName
//
labelName.AutoSize = true;
labelName.Location = new Point(31, 31);
labelName.Location = new Point(58, 66);
labelName.Margin = new Padding(6, 0, 6, 0);
labelName.Name = "labelName";
labelName.Size = new Size(39, 15);
labelName.Size = new Size(78, 32);
labelName.TabIndex = 3;
labelName.Text = "Name";
//
// labelType
//
labelType.AutoSize = true;
labelType.Location = new Point(31, 78);
labelType.Location = new Point(58, 166);
labelType.Margin = new Padding(6, 0, 6, 0);
labelType.Name = "labelType";
labelType.Size = new Size(76, 15);
labelType.Size = new Size(154, 32);
labelType.TabIndex = 4;
labelType.Text = "Product Type";
//
// labelCountInWarehouse
//
labelCountInWarehouse.AutoSize = true;
labelCountInWarehouse.Location = new Point(31, 130);
labelCountInWarehouse.Location = new Point(58, 277);
labelCountInWarehouse.Margin = new Padding(6, 0, 6, 0);
labelCountInWarehouse.Name = "labelCountInWarehouse";
labelCountInWarehouse.Size = new Size(113, 15);
labelCountInWarehouse.Size = new Size(228, 32);
labelCountInWarehouse.TabIndex = 5;
labelCountInWarehouse.Text = "Count in warehouse";
//
// textBoxName
//
textBoxName.Location = new Point(188, 28);
textBoxName.Location = new Point(349, 60);
textBoxName.Margin = new Padding(6);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(141, 23);
textBoxName.Size = new Size(258, 39);
textBoxName.TabIndex = 6;
//
// comboBoxProduct
//
comboBoxProduct.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxProduct.FormattingEnabled = true;
comboBoxProduct.Location = new Point(188, 78);
comboBoxProduct.Name = "comboBoxProduct";
comboBoxProduct.Size = new Size(141, 23);
comboBoxProduct.TabIndex = 7;
//
// numericUpDownCount
//
numericUpDownCount.Location = new Point(188, 130);
numericUpDownCount.Location = new Point(349, 277);
numericUpDownCount.Margin = new Padding(6);
numericUpDownCount.Name = "numericUpDownCount";
numericUpDownCount.Size = new Size(141, 23);
numericUpDownCount.Size = new Size(262, 39);
numericUpDownCount.TabIndex = 8;
//
// FormMaterialConsumption
// checkedListBox1
//
AutoScaleDimensions = new SizeF(7F, 15F);
checkedListBox1.FormattingEnabled = true;
checkedListBox1.Items.AddRange(new object[] { "Wardrobe", "Table", "Bench" });
checkedListBox1.Location = new Point(349, 132);
checkedListBox1.Name = "checkedListBox1";
checkedListBox1.Size = new Size(262, 112);
checkedListBox1.TabIndex = 9;
checkedListBox1.SelectedIndexChanged += checkedListBox1_SelectedIndexChanged;
//
// FormProductMaterial
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(591, 482);
ClientSize = new Size(1098, 1028);
Controls.Add(checkedListBox1);
Controls.Add(numericUpDownCount);
Controls.Add(comboBoxProduct);
Controls.Add(textBoxName);
Controls.Add(labelCountInWarehouse);
Controls.Add(labelType);
@ -166,7 +180,8 @@
Controls.Add(buttonCancel);
Controls.Add(buttonAdd);
Controls.Add(groupBox);
Name = "FormMaterialConsumption";
Margin = new Padding(6);
Name = "FormProductMaterial";
Text = "FormMaterialConsumption";
groupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
@ -187,7 +202,7 @@
private Label labelType;
private Label labelCountInWarehouse;
private TextBox textBoxName;
private ComboBox comboBoxProduct;
private NumericUpDown numericUpDownCount;
private CheckedListBox checkedListBox1;
}
}

View File

@ -1,7 +1,10 @@
using CarpentryWorkshop.Entities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using CarpentryWorkshop.Entities;
using CarpentryWorkshop.Entities.Enums;
using CarpentryWorkshop.Repositories;
using System.Windows.Forms;
namespace CarpentryWorkshop.Forms
{
@ -9,6 +12,8 @@ namespace CarpentryWorkshop.Forms
{
private readonly IProductRepository _productRepository;
private int? _productId;
private ProductType selectedProducts = ProductType.None;
public int Id
{
set
@ -21,37 +26,49 @@ namespace CarpentryWorkshop.Forms
throw new InvalidDataException(nameof(product));
}
textBoxName.Text = product.Name;
comboBoxProduct.SelectedItem = product.Type;
numericUpDownCount.Value = product.CountInWarehouse;
_productId = value;
// Устанавливаем выбранные продукты в checkedListBox1
checkedListBox1.SetItemChecked(0, product.Type.HasFlag(ProductType.Wardrobe));
checkedListBox1.SetItemChecked(1, product.Type.HasFlag(ProductType.Table));
checkedListBox1.SetItemChecked(2, product.Type.HasFlag(ProductType.Bench));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при полученииданных", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormProductMaterial(IProductRepository productRepository, IMaterialRepository materialRepository)
{
InitializeComponent();
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
comboBoxProduct.DataSource = Enum.GetValues(typeof(ProductType));
ColumnMaterials.DataSource = materialRepository.ReadMaterials();
ColumnMaterials.DisplayMember = "Name";
ColumnMaterials.ValueMember = "Id";
// Пример заполнения CheckedListBox
checkedListBox1.Items.AddRange(new object[]
{
"Wardrobe",
"Table",
"Bench"
});
}
private void buttonAdd_Click(object sender, EventArgs e)
{
if (dataGridView.RowCount < 1)
{
throw new Exception("Имеются незаполненны поля");
throw new Exception("Имеются незаполненные поля");
}
try
{
if (string.IsNullOrWhiteSpace(textBoxName.Text) || comboBoxProduct.SelectedIndex < 1)
if (string.IsNullOrWhiteSpace(textBoxName.Text))
{
throw new Exception("Имеются незаполненные поля");
}
@ -70,7 +87,9 @@ namespace CarpentryWorkshop.Forms
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e) => Close();
private List<ProductMaterial> CreateListMaterialFromDataGrid()
{
var list = new List<ProductMaterial>();
@ -84,6 +103,33 @@ namespace CarpentryWorkshop.Forms
}
return list;
}
private Product CreateProduct(int id) => Product.CreateEntity(id, textBoxName.Text, (ProductType)comboBoxProduct.SelectedItem!, Convert.ToInt32(numericUpDownCount.Value), CreateListMaterialFromDataGrid());
private Product CreateProduct(int id) => Product.CreateEntity(id, textBoxName.Text, selectedProducts, Convert.ToInt32(numericUpDownCount.Value), CreateListMaterialFromDataGrid());
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
// Сбрасываем выбранные продукты
selectedProducts = ProductType.None;
// Проходим по всем выбранным элементам
foreach (var item in checkedListBox1.CheckedItems)
{
switch (item.ToString())
{
case "Wardrobe":
selectedProducts |= ProductType.Wardrobe;
break;
case "Table":
selectedProducts |= ProductType.Table;
break;
case "Bench":
selectedProducts |= ProductType.Bench;
break;
}
}
// Выводим выбранные продукты для демонстрации
MessageBox.Show($"Selected products: {selectedProducts}");
}
}
}
}

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
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
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>
@ -26,36 +26,36 @@
<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
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
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
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
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
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
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
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->