diff --git a/CarpentryWorkshop/CarpentryWorkshop/Entities/Enums/ProductType.cs b/CarpentryWorkshop/CarpentryWorkshop/Entities/Enums/ProductType.cs index bf0e504..c26813a 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/Entities/Enums/ProductType.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/Entities/Enums/ProductType.cs @@ -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 } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/Forms/FormProductMaterial.Designer.cs b/CarpentryWorkshop/CarpentryWorkshop/Forms/FormProductMaterial.Designer.cs index afe0394..5a5f044 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/Forms/FormProductMaterial.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/Forms/FormProductMaterial.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/Forms/FormProductMaterial.cs b/CarpentryWorkshop/CarpentryWorkshop/Forms/FormProductMaterial.cs index 0657d43..ecc9bcb 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/Forms/FormProductMaterial.cs +++ b/CarpentryWorkshop/CarpentryWorkshop/Forms/FormProductMaterial.cs @@ -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 CreateListMaterialFromDataGrid() { var list = new List(); @@ -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}"); + } } -} +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshop/Forms/FormProductMaterial.resx b/CarpentryWorkshop/CarpentryWorkshop/Forms/FormProductMaterial.resx index 1af7de1..8b2ff64 100644 --- a/CarpentryWorkshop/CarpentryWorkshop/Forms/FormProductMaterial.resx +++ b/CarpentryWorkshop/CarpentryWorkshop/Forms/FormProductMaterial.resx @@ -1,17 +1,17 @@  -