From cf3e7bd678185eb9fe453a39ee1d1f3029266b85 Mon Sep 17 00:00:00 2001 From: vettaql Date: Fri, 20 Dec 2024 20:48:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Atelier/Atelier/Entities/Enums/Color.cs | 17 +++++++++-------- Atelier/Atelier/Entities/Model.cs | 8 ++++++++ Atelier/Atelier/Forms/FormModel.cs | 15 ++++++++++----- Atelier/Atelier/Forms/FormOrder.cs | 2 +- .../Implementations/ModelRepository.cs | 14 +++++++++++--- .../Implementations/StorageRepository.cs | 2 +- 6 files changed, 40 insertions(+), 18 deletions(-) diff --git a/Atelier/Atelier/Entities/Enums/Color.cs b/Atelier/Atelier/Entities/Enums/Color.cs index d5f5d1d..9d06f85 100644 --- a/Atelier/Atelier/Entities/Enums/Color.cs +++ b/Atelier/Atelier/Entities/Enums/Color.cs @@ -1,13 +1,14 @@ -public enum Color +[Flags] +public enum Color { None = 0, Black = 1, Red = 2, - Blue = 3, - Green = 4, - Grey = 5, - Yellow = 6, - Pink = 7, - White = 8, - Purple = 9, + Blue = 4, + Green = 8, + Grey = 16, + Yellow = 32, + Pink = 64, + White = 128, + Purple = 256, } diff --git a/Atelier/Atelier/Entities/Model.cs b/Atelier/Atelier/Entities/Model.cs index 11fe15a..89e294b 100644 --- a/Atelier/Atelier/Entities/Model.cs +++ b/Atelier/Atelier/Entities/Model.cs @@ -18,4 +18,12 @@ public class Model }; } + + public void CreateList(IEnumerable fabricModel) + { + if (fabricModel != null) + { + FabricModel = fabricModel; + } + } } diff --git a/Atelier/Atelier/Forms/FormModel.cs b/Atelier/Atelier/Forms/FormModel.cs index 11bfbea..8554452 100644 --- a/Atelier/Atelier/Forms/FormModel.cs +++ b/Atelier/Atelier/Forms/FormModel.cs @@ -30,6 +30,10 @@ namespace Atelier.Forms } comboBoxModel.SelectedItem = model.ModelType; numericUpDownPrice.Value = (decimal)model.Price; + foreach (var fm in model.FabricModel) + { + dataGridView1.Rows.Add(new object[] { fm.FabricId, fm.Count }); + } _modelId = value; } catch (Exception ex) @@ -54,7 +58,7 @@ namespace Atelier.Forms { try { - if (numericUpDownPrice.Value < 500 || dataGridView1.RowCount < 1 || comboBoxModel.SelectedIndex < 1) + if (numericUpDownPrice.Value < 500 || dataGridView1.RowCount < 1 || comboBoxModel.SelectedIndex < 1 ) { throw new Exception("Имеются незаполненные поля"); } @@ -83,7 +87,7 @@ namespace Atelier.Forms foreach (DataGridViewRow row in dataGridView1.Rows) { - if (row.Cells["ColumnFabric"].Value == null || row.Cells["ColumnCount"].Value == null || !(bool)row.Cells["CheckBoxColumn"].Value) + if (row.Cells["ColumnFabric"].Value == null || row.Cells["ColumnCount"].Value == null) { continue; } @@ -91,11 +95,12 @@ namespace Atelier.Forms int fabricId = Convert.ToInt32(row.Cells["ColumnFabric"].Value); int count = Convert.ToInt32(row.Cells["ColumnCount"].Value); - fabricModels.Add(FabricModel.CreateElement(0, fabricId, count)); + fabricModels.Add(FabricModel.CreateElement(fabricId, 0, count)); } return Model.CreateEntity(id, (ModelType)comboBoxModel.SelectedItem!, Convert.ToDouble(numericUpDownPrice.Value), fabricModels); } - } -} + } + +} \ No newline at end of file diff --git a/Atelier/Atelier/Forms/FormOrder.cs b/Atelier/Atelier/Forms/FormOrder.cs index b30a73d..a217612 100644 --- a/Atelier/Atelier/Forms/FormOrder.cs +++ b/Atelier/Atelier/Forms/FormOrder.cs @@ -63,7 +63,7 @@ namespace Atelier.Forms continue; } list.Add(ModelOrder.CreateElement(0, - Convert.ToInt32(row.Cells["ColumnFeed"].Value), + Convert.ToInt32(row.Cells["ColumnModel"].Value), Convert.ToInt32(row.Cells["ColumnCount"].Value))); } return list; diff --git a/Atelier/Atelier/Repositories/Implementations/ModelRepository.cs b/Atelier/Atelier/Repositories/Implementations/ModelRepository.cs index c27a447..bd0914f 100644 --- a/Atelier/Atelier/Repositories/Implementations/ModelRepository.cs +++ b/Atelier/Atelier/Repositories/Implementations/ModelRepository.cs @@ -127,16 +127,22 @@ internal class ModelRepository : IModelRepository try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @" - SELECT * FROM Models - WHERE Id = @id"; + var querySelect = @"SELECT * FROM Models + WHERE Id = @id"; var model = connection.QueryFirstOrDefault(querySelect, new { id }); + var querySelectSub = @$"SELECT * + FROM FabricModel fm + WHERE ModelId = {id}"; + var fabricModel = connection.Query(querySelectSub); + model.CreateList(fabricModel); if (model == null) { _logger.LogWarning("Объект с идентификатором {id} не найден", id); throw new KeyNotFoundException($"Модель с идентификатором {id} не найдена"); } _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(model)); + + return model; } catch (Exception ex) @@ -146,6 +152,8 @@ internal class ModelRepository : IModelRepository } } + + public IEnumerable ReadModels() { _logger.LogInformation("Получение всех объектов"); diff --git a/Atelier/Atelier/Repositories/Implementations/StorageRepository.cs b/Atelier/Atelier/Repositories/Implementations/StorageRepository.cs index 091b01a..f11c111 100644 --- a/Atelier/Atelier/Repositories/Implementations/StorageRepository.cs +++ b/Atelier/Atelier/Repositories/Implementations/StorageRepository.cs @@ -42,7 +42,7 @@ VALUES (@StockMetrage, @FabricId)"; using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var queryDelete = @" -DELETE FROM Storades +DELETE FROM Storages WHERE Id=@id"; connection.Execute(queryDelete, new { id }); }