diff --git a/ProjectWarehouse/ProjectWarehouse/Entities/Components.cs b/ProjectWarehouse/ProjectWarehouse/Entities/Components.cs index 515d71c..4b824a6 100644 --- a/ProjectWarehouse/ProjectWarehouse/Entities/Components.cs +++ b/ProjectWarehouse/ProjectWarehouse/Entities/Components.cs @@ -1,4 +1,5 @@ using ProjectWarehouse.Entities.Enums; +using System.ComponentModel; namespace ProjectWarehouse.Entities; @@ -6,12 +7,16 @@ public class Components { public int Id { get; private set; } + [DisplayName("Название")] public string Name { get; private set; } = string.Empty; + [DisplayName("Цена")] public decimal Price { get; private set; } + [DisplayName("Количество")] public double Count { get; private set; } + [DisplayName("Тип компонента")] public Type_Components TypeComponentsId { get; private set; } public static Components CreateEntity(int id, string name, decimal price, double count, Type_Components typeComponentsId) diff --git a/ProjectWarehouse/ProjectWarehouse/Entities/Components_Production.cs b/ProjectWarehouse/ProjectWarehouse/Entities/Components_Production.cs index d9c4219..0e11a45 100644 --- a/ProjectWarehouse/ProjectWarehouse/Entities/Components_Production.cs +++ b/ProjectWarehouse/ProjectWarehouse/Entities/Components_Production.cs @@ -1,22 +1,33 @@ -namespace ProjectWarehouse.Entities; +using System.ComponentModel; + +namespace ProjectWarehouse.Entities; public class Components_Production { public int Id { get; set; } + [Browsable(false)] public int ProductionId { get; private set; } + [Browsable(false)] public int ComponentsId { get; private set; } + [DisplayName("Продукция")] + public string ProductionName { get; private set; } = string.Empty; + + [DisplayName("Комплекующие")] + public string ComponentsName { get; private set; } = string.Empty; + + [DisplayName("Количество")] public int Count { get; private set; } - public static Components_Production CreateElement(int id, int componentsID, int count) + public static Components_Production CreateElement(int id, int productionId, int componentsId, int count) { return new Components_Production { Id = id, - ProductionId = componentsID, - ComponentsId = componentsID, + ProductionId = productionId, + ComponentsId = componentsId, Count = count }; } diff --git a/ProjectWarehouse/ProjectWarehouse/Entities/Employee.cs b/ProjectWarehouse/ProjectWarehouse/Entities/Employee.cs index cf86b31..0f47473 100644 --- a/ProjectWarehouse/ProjectWarehouse/Entities/Employee.cs +++ b/ProjectWarehouse/ProjectWarehouse/Entities/Employee.cs @@ -1,4 +1,5 @@ using ProjectWarehouse.Entities.Enums; +using System.ComponentModel; namespace ProjectWarehouse.Entities; @@ -6,10 +7,15 @@ public class Employee { public int Id { get; private set; } + [DisplayName("Имя")] public string FirstName { get; private set; } = string.Empty; + [DisplayName("Фамилия")] public string LastName { get; private set; } = string.Empty; + public string FullName => $"{LastName} {FirstName}"; + + [DisplayName("Должность")] public EmployeePost EmployeePostId { get; private set; } public static Employee CreateEntity(int id, string first, string last, diff --git a/ProjectWarehouse/ProjectWarehouse/Entities/Inventory.cs b/ProjectWarehouse/ProjectWarehouse/Entities/Inventory.cs index 538727b..8a43b47 100644 --- a/ProjectWarehouse/ProjectWarehouse/Entities/Inventory.cs +++ b/ProjectWarehouse/ProjectWarehouse/Entities/Inventory.cs @@ -1,15 +1,23 @@ -namespace ProjectWarehouse.Entities; +using System.ComponentModel; + +namespace ProjectWarehouse.Entities; public class Inventory { public int Id { get; private set; } + [DisplayName("Количество")] public double Quantity { get; private set; } + [DisplayName("Брак")] public bool IsDefect { get; private set; } public int ComponentsId { get; private set; } + [DisplayName("Компонент")] + public string ComponentsName { get; private set; } = string.Empty; + + [DisplayName("Дата")] public DateTime Date { get; set; } public static Inventory CreateEntity(int id, double quantity, bool isDefect, int ComponentsID) diff --git a/ProjectWarehouse/ProjectWarehouse/Entities/OrderRequest.cs b/ProjectWarehouse/ProjectWarehouse/Entities/OrderRequest.cs index 976e02a..0da7bb9 100644 --- a/ProjectWarehouse/ProjectWarehouse/Entities/OrderRequest.cs +++ b/ProjectWarehouse/ProjectWarehouse/Entities/OrderRequest.cs @@ -1,15 +1,22 @@ -namespace ProjectWarehouse.Entities; +using System.ComponentModel; + +namespace ProjectWarehouse.Entities; public class OrderRequest { public int Id { get; private set; } + [DisplayName("Количество")] public double Quantity { get; private set; } + [DisplayName("Дата заявки")] public DateTime DateOrder { get; private set; } public int ComponentsId { get; private set; } + [DisplayName("Компонент")] + public string ComponentsName { get; private set; } = string.Empty; + public static OrderRequest CreateEntity(int id, double quantity, int componentsID) { return new OrderRequest diff --git a/ProjectWarehouse/ProjectWarehouse/Entities/Production.cs b/ProjectWarehouse/ProjectWarehouse/Entities/Production.cs index d67de7f..d8b3704 100644 --- a/ProjectWarehouse/ProjectWarehouse/Entities/Production.cs +++ b/ProjectWarehouse/ProjectWarehouse/Entities/Production.cs @@ -1,17 +1,31 @@ -namespace ProjectWarehouse.Entities; +using System.ComponentModel; + +namespace ProjectWarehouse.Entities; public class Production { public int Id { get; private set; } + [DisplayName("Название")] public string Name { get; private set; } = string.Empty; + [DisplayName("Описание")] public string Description { get; private set; } = string.Empty; public int EmployeeId { get; private set; } + [DisplayName("Сотрудник")] + public string EmployeeName { get; private set; } = string.Empty; + + [DisplayName("Дата")] public DateTime Date { get; set; } + [DisplayName("Компоненты")] + public string Components => Components_Productions != null ? + string.Join(", ", Components_Productions.Select(x => $"{x.ProductionName} {x.ComponentsName} {x.Count}")) : + string.Empty; + + [Browsable(false)] public IEnumerable Components_Productions { get; private set; } = []; public static Production CreateEntity(int id, string name, string description, int employeeId, IEnumerable components_Productions) @@ -27,13 +41,11 @@ public class Production }; } - public static Production CreateEntity(TempComponents_Production tempComponents_Production, IEnumerable components_Productions) + public void SetComponents_Production(IEnumerable components_Productions) { - return new Production + if (components_Productions != null && components_Productions.Any()) { - Id = tempComponents_Production.Id, - Date = tempComponents_Production.Date, - Components_Productions = components_Productions - }; + Components_Productions = components_Productions; + } } } diff --git a/ProjectWarehouse/ProjectWarehouse/Entities/TempComponents_Production.cs b/ProjectWarehouse/ProjectWarehouse/Entities/TempComponents_Production.cs deleted file mode 100644 index 0a70c97..0000000 --- a/ProjectWarehouse/ProjectWarehouse/Entities/TempComponents_Production.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace ProjectWarehouse.Entities; - -public class TempComponents_Production -{ - public int Id { get; private set; } - - public DateTime Date { get; private set; } - - public int ComponentsId { get; private set; } - - public int Count { get; private set; } -} diff --git a/ProjectWarehouse/ProjectWarehouse/Forms/FormComponents.cs b/ProjectWarehouse/ProjectWarehouse/Forms/FormComponents.cs index 2740e7d..da1d861 100644 --- a/ProjectWarehouse/ProjectWarehouse/Forms/FormComponents.cs +++ b/ProjectWarehouse/ProjectWarehouse/Forms/FormComponents.cs @@ -86,7 +86,11 @@ namespace ProjectWarehouse.Forms } } - private void LoadList() => dataGridViewData.DataSource = _componentsRepository.ReadComponents(); + private void LoadList() + { + dataGridViewData.DataSource = _componentsRepository.ReadComponents(); + dataGridViewData.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectWarehouse/ProjectWarehouse/Forms/FormEmployees.cs b/ProjectWarehouse/ProjectWarehouse/Forms/FormEmployees.cs index 0c89eaa..27163fb 100644 --- a/ProjectWarehouse/ProjectWarehouse/Forms/FormEmployees.cs +++ b/ProjectWarehouse/ProjectWarehouse/Forms/FormEmployees.cs @@ -86,7 +86,12 @@ namespace ProjectWarehouse.Forms } } - private void LoadList() => dataGridViewData.DataSource = _employeeRepository.ReadEmployees(); + private void LoadList() + { + dataGridViewData.DataSource = _employeeRepository.ReadEmployees(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["FullName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectWarehouse/ProjectWarehouse/Forms/FormInventorys.cs b/ProjectWarehouse/ProjectWarehouse/Forms/FormInventorys.cs index 57de7c2..3c38ec9 100644 --- a/ProjectWarehouse/ProjectWarehouse/Forms/FormInventorys.cs +++ b/ProjectWarehouse/ProjectWarehouse/Forms/FormInventorys.cs @@ -44,7 +44,12 @@ namespace ProjectWarehouse.Forms } } - private void LoadList() => dataGridViewData.DataSource = _inventoryRepository.ReadInventory(); + private void LoadList() + { + dataGridViewData.DataSource = _inventoryRepository.ReadInventory(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["Date"].DefaultCellStyle.Format = "dd MMMM yyyy"; + } private void ButtonUpd_Click(object sender, EventArgs e) { diff --git a/ProjectWarehouse/ProjectWarehouse/Forms/FormOrderRequests.cs b/ProjectWarehouse/ProjectWarehouse/Forms/FormOrderRequests.cs index c1d092b..86c1dee 100644 --- a/ProjectWarehouse/ProjectWarehouse/Forms/FormOrderRequests.cs +++ b/ProjectWarehouse/ProjectWarehouse/Forms/FormOrderRequests.cs @@ -43,6 +43,10 @@ namespace ProjectWarehouse.Forms } } - private void LoadList() => dataGridViewData.DataSource = _orderRequestRepository.ReadOrderRequest(); + private void LoadList() + { + dataGridViewData.DataSource = _orderRequestRepository.ReadOrderRequest(); + dataGridViewData.Columns["Id"].Visible = false; + } } } diff --git a/ProjectWarehouse/ProjectWarehouse/Forms/FormProduction.cs b/ProjectWarehouse/ProjectWarehouse/Forms/FormProduction.cs index 0f1c271..c966fb2 100644 --- a/ProjectWarehouse/ProjectWarehouse/Forms/FormProduction.cs +++ b/ProjectWarehouse/ProjectWarehouse/Forms/FormProduction.cs @@ -16,7 +16,7 @@ namespace ProjectWarehouse.Forms throw new ArgumentNullException(nameof(productionRepository)); comboBoxEmployee.DataSource = employeeRepository.ReadEmployees(); - comboBoxEmployee.DisplayMember = "FirstName"; + comboBoxEmployee.DisplayMember = "FullName"; comboBoxEmployee.ValueMember = "Id"; ColumnComponents.DataSource = componentsRepository.ReadComponents(); @@ -55,12 +55,12 @@ namespace ProjectWarehouse.Forms { continue; } - list.Add(Components_Production.CreateElement(0, + list.Add(Components_Production.CreateElement(0, 0, Convert.ToInt32(row.Cells["ColumnComponents"].Value), Convert.ToInt32(row.Cells["ColumnCount"].Value))); } return list.GroupBy(x => x.ComponentsId, x => x.Count, (id, counts) => - Components_Production.CreateElement(0, id, counts.Sum())).ToList(); + Components_Production.CreateElement(0, 0, id, counts.Sum())).ToList(); } } } \ No newline at end of file diff --git a/ProjectWarehouse/ProjectWarehouse/Forms/FormProductions.cs b/ProjectWarehouse/ProjectWarehouse/Forms/FormProductions.cs index d803ba2..5326021 100644 --- a/ProjectWarehouse/ProjectWarehouse/Forms/FormProductions.cs +++ b/ProjectWarehouse/ProjectWarehouse/Forms/FormProductions.cs @@ -66,7 +66,11 @@ namespace ProjectWarehouse.Forms } } - private void LoadList() => dataGridViewData.DataSource = _productionRepository.ReadProduction(); + private void LoadList() + { + dataGridViewData.DataSource = _productionRepository.ReadProduction(); + dataGridViewData.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectWarehouse/ProjectWarehouse/Reports/ChartReport.cs b/ProjectWarehouse/ProjectWarehouse/Reports/ChartReport.cs index 12f994a..5c89f20 100644 --- a/ProjectWarehouse/ProjectWarehouse/Reports/ChartReport.cs +++ b/ProjectWarehouse/ProjectWarehouse/Reports/ChartReport.cs @@ -1,4 +1,6 @@ -using Microsoft.Extensions.Logging; +using DocumentFormat.OpenXml.Wordprocessing; +using Microsoft.Extensions.Logging; +using ProjectWarehouse.Entities; using ProjectWarehouse.Repositories; namespace ProjectWarehouse.Reports; @@ -22,9 +24,10 @@ internal class ChartReport try { new PdfBuilder(filePath) - .AddHeader("Пополнение склада") - .AddPieChart("Полученные компоненты", GetData(dateTime)) - .Build(); + .AddHeader("Пополнение склада") + .AddPieChart($"Полученные компоненты на {dateTime:dd MMMM yyyy}", GetData(dateTime)) + .Build(); + return true; } catch (Exception ex) @@ -37,9 +40,8 @@ internal class ChartReport private List<(string Caption, double Value)> GetData(DateTime dateTime) { return _inventoryRepository - .ReadInventory() - .Where(x => x.Date.Date == dateTime.Date) - .GroupBy(x => x.ComponentsId) + .ReadInventory(dateFrom: dateTime.Date, dateTo: dateTime.Date.AddDays(1)) + .GroupBy(x => x.ComponentsName) .Select(group => ( Caption: $"Компонент {group.Key}", Value: group.Sum(x => x.Quantity) diff --git a/ProjectWarehouse/ProjectWarehouse/Reports/TableReport.cs b/ProjectWarehouse/ProjectWarehouse/Reports/TableReport.cs index 05322a5..674d44f 100644 --- a/ProjectWarehouse/ProjectWarehouse/Reports/TableReport.cs +++ b/ProjectWarehouse/ProjectWarehouse/Reports/TableReport.cs @@ -43,8 +43,9 @@ internal class TableReport { new ExcelBuilder(filePath) .AddHeader("Сводка по движению комлектующих", 0, 4) - .AddParagraph("за период", 0). - AddTable([10, 10, 15, 15], GetData(componentsId, startDate, endDate)).Build(); + .AddParagraph($"за период с {startDate:dd.MM.yyyy} по {endDate: dd.MM.yyyy}", 0) + .AddTable([10, 10, 15, 15], GetData(componentsId, startDate, endDate)) + .Build(); return true; } @@ -60,8 +61,7 @@ internal class TableReport { // Получаем данные по приходам (Production) var productionData = _productionRepository - .ReadProduction() - .Where(x => x.Date >= startDate && x.Date <= endDate && x.Components_Productions.Any(y => y.ComponentsId == componentsId)) + .ReadProduction(dateFrom: startDate, dateTo: endDate, componentsId: componentsId) .Select(x => new MovementData { Date = x.Date, @@ -71,7 +71,7 @@ internal class TableReport .ToList(); var orderRequestData = _orderRequestRepository - .ReadOrderRequest() + .ReadOrderRequest(dateFrom: startDate, dateTo: endDate, componentsId: componentsId) .Where(x => x.DateOrder >= startDate && x.DateOrder <= endDate && x.ComponentsId == componentsId) .Select(x => new MovementData { @@ -82,7 +82,7 @@ internal class TableReport .ToList(); var inventoryData = _inventoryRepository - .ReadInventory() + .ReadInventory(dateFrom: startDate, dateTo: endDate, componentsId: componentsId) .Where(x => x.Date >= startDate && x.Date <= endDate && x.ComponentsId == componentsId) .Select(x => new MovementData { @@ -106,17 +106,17 @@ internal class TableReport combinedData.Select(x => new string[] { "", - x.Date.ToString("yyyy-MM-dd"), - x.CountIn?.ToString("F2") ?? string.Empty, - x.CountOut?.ToString("F2") ?? string.Empty + x.Date.ToString("dd.MM.yyyy"), + x.CountIn?.ToString("N0") ?? string.Empty, + x.CountOut?.ToString("N0") ?? string.Empty }) ) .Union(new[] { new string[] { "Всего", "", - combinedData.Sum(x => x.CountIn ?? 0).ToString("F2"), - combinedData.Sum(x => x.CountOut ?? 0).ToString("F2") + combinedData.Sum(x => x.CountIn ?? 0).ToString("N0"), + combinedData.Sum(x => x.CountOut ?? 0).ToString("N0") } }) .ToList(); diff --git a/ProjectWarehouse/ProjectWarehouse/Repositories/IInventoryRepository.cs b/ProjectWarehouse/ProjectWarehouse/Repositories/IInventoryRepository.cs index 79641df..95d4492 100644 --- a/ProjectWarehouse/ProjectWarehouse/Repositories/IInventoryRepository.cs +++ b/ProjectWarehouse/ProjectWarehouse/Repositories/IInventoryRepository.cs @@ -4,7 +4,7 @@ namespace ProjectWarehouse.Repositories; public interface IInventoryRepository { - IEnumerable ReadInventory(); + IEnumerable ReadInventory(DateTime? dateFrom = null, DateTime? dateTo = null, int? componentsId = null, int? employeeId = null); Inventory ReadInventoryById(int id); diff --git a/ProjectWarehouse/ProjectWarehouse/Repositories/IOrderRequestRepository.cs b/ProjectWarehouse/ProjectWarehouse/Repositories/IOrderRequestRepository.cs index 91f7d16..0714c7d 100644 --- a/ProjectWarehouse/ProjectWarehouse/Repositories/IOrderRequestRepository.cs +++ b/ProjectWarehouse/ProjectWarehouse/Repositories/IOrderRequestRepository.cs @@ -4,7 +4,7 @@ namespace ProjectWarehouse.Repositories; public interface IOrderRequestRepository { - IEnumerable ReadOrderRequest(DateTime? dateForm = null, DateTime? dateTo = null, double? quantity = null, int? componentsID = null); + IEnumerable ReadOrderRequest(DateTime? dateFrom = null, DateTime? dateTo = null, double? quantity = null, int? componentsId = null); void CreateOrderRequest(OrderRequest orderRequest); } \ No newline at end of file diff --git a/ProjectWarehouse/ProjectWarehouse/Repositories/IProductionRepository.cs b/ProjectWarehouse/ProjectWarehouse/Repositories/IProductionRepository.cs index 7adafdb..b904788 100644 --- a/ProjectWarehouse/ProjectWarehouse/Repositories/IProductionRepository.cs +++ b/ProjectWarehouse/ProjectWarehouse/Repositories/IProductionRepository.cs @@ -4,7 +4,7 @@ namespace ProjectWarehouse.Repositories; public interface IProductionRepository { - IEnumerable ReadProduction(); + IEnumerable ReadProduction(DateTime? dateFrom = null, DateTime? dateTo = null, int? componentsId = null, int? employeeId = null); void CreateProduction(Production production); diff --git a/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/InventoryRepository.cs b/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/InventoryRepository.cs index f05dd71..7df7aaa 100644 --- a/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/InventoryRepository.cs +++ b/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/InventoryRepository.cs @@ -102,7 +102,7 @@ public class InventoryRepository : IInventoryRepository } } - public IEnumerable ReadInventory() + public IEnumerable ReadInventory(DateTime? dateFrom = null, DateTime? dateTo = null, int? componentsId = null, int? employeeId = null) { _logger.LogInformation("Получение всех объектов"); try diff --git a/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/OrderRequestRepository.cs b/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/OrderRequestRepository.cs index d0baacc..314f43b 100644 --- a/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/OrderRequestRepository.cs +++ b/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/OrderRequestRepository.cs @@ -36,7 +36,7 @@ public class OrderRequestRepository : IOrderRequestRepository } } - public IEnumerable ReadOrderRequest(DateTime? dateForm = null, DateTime? dateTo = null, double? quantity = null, int? componentsID = null) + public IEnumerable ReadOrderRequest(DateTime? dateFrom = null, DateTime? dateTo = null, double? quantity = null, int? componentsId = null) { _logger.LogInformation("Получение всех объектов"); try diff --git a/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/ProductionRepository.cs b/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/ProductionRepository.cs index 1489808..5a6f120 100644 --- a/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/ProductionRepository.cs +++ b/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/ProductionRepository.cs @@ -32,8 +32,8 @@ public class ProductionRepository : IProductionRepository SELECT MAX(id) FROM Production"; var productionId = connection.QueryFirst(queryInsert, production, transaction); var querySubInsert = @" - INSERT INTO Components_Production (ComponentsId, Count) - VALUES (@ComponentsId, @Count)"; + INSERT INTO Components_Production (ProductionId, ComponentsId, Count) + VALUES (@ProductionId, @ComponentsId, @Count)"; foreach (var elem in production.Components_Productions) { connection.Execute(querySubInsert, new @@ -73,20 +73,64 @@ public class ProductionRepository : IProductionRepository } - public IEnumerable ReadProduction() + public IEnumerable ReadProduction(DateTime? dateFrom = null, DateTime? dateTo = null, int? componentsId = null, int? employeeId = null) { _logger.LogInformation("Получение всех объектов"); try { + var builder = new QueryBuilder(); + if (dateFrom.HasValue) + { + builder.AddCondition("fr.Date >= @dateFrom"); + } + if (dateTo.HasValue) + { + builder.AddCondition("fr.Date <= @dateTo"); + } + if (componentsId.HasValue) + { + builder.AddCondition("fr.FeedId = @feedId"); + } + if (employeeId.HasValue) + { + builder.AddCondition("fr.EmployeeId = @employeeId"); + } + using var connection = new Npgsql.NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @" - SELECT fr.*, ffr.ComponentsId, ffr.Count FROM Production fr - INNER JOIN Components_Production ffr ON ffr.ProductionId = fr.Id"; - var production = connection.Query(querySelect); + var querySelect = $@"SELECT + fr.*, + CONCAT(e.LastName, ' ', e.FirstName) as EmployeeName, + ffr.ProductionId, + ffr.ComponentsId, + ffr.Count, + f.Name as 'ComponentsName' + FROM Production fr + LEFT JOIN Employees e on e.Id = fr.EmployeeId + INNER JOIN Components_Production ffr ON ffr.ProductionId = fr.Id + LEFT JOIN Components f on f.Id = ffr.ComponentsId + {builder.Build()}"; + var productionDict = new Dictionary>(); + + var production = connection.Query(querySelect, + (productions, production) => + { + if (!productionDict.TryGetValue(productions.Id, out var frr)) + { + frr = []; + productionDict.Add(productions.Id, frr); + } + + frr.Add(production); + return productions; + }, splitOn: "ComponentsId", param: new { dateFrom, dateTo, componentsId, employeeId }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(production)); - return production.GroupBy(x => x.Id, y => y, - (key, value) => Production.CreateEntity(value.First(), - value.Select(z => Components_Production.CreateElement(0, z.ComponentsId, z.Count)))).ToList(); + + return productionDict.Select(x => + { + var fr = production.First(y => y.Id == x.Key); + fr.SetComponents_Production(x.Value); + return fr; + }).ToArray(); } catch (Exception ex) { diff --git a/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/QueryBuilder.cs b/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/QueryBuilder.cs new file mode 100644 index 0000000..8ffb4fb --- /dev/null +++ b/ProjectWarehouse/ProjectWarehouse/Repositories/Implementations/QueryBuilder.cs @@ -0,0 +1,32 @@ +using System.Text; + +namespace ProjectWarehouse.Repositories.Implementations; + +internal class QueryBuilder +{ + private readonly StringBuilder _builder; + + public QueryBuilder() + { + _builder = new(); + } + + public QueryBuilder AddCondition(string condition) + { + if (_builder.Length > 0) + { + _builder.Append(" AND "); + } + _builder.Append(condition); + return this; + } + + public string Build() + { + if (_builder.Length == 0) + { + return string.Empty; + } + return $"WHERE {_builder}"; + } +} \ No newline at end of file