diff --git a/ProjectGarage/Entities/FuelFuelReplenishment.cs b/ProjectGarage/Entities/FuelFuelReplenishment.cs index 87e71b9..48c40f0 100644 --- a/ProjectGarage/Entities/FuelFuelReplenishment.cs +++ b/ProjectGarage/Entities/FuelFuelReplenishment.cs @@ -11,6 +11,7 @@ public class FuelFuelReplenishment public int Id { get; private set; } public int FuelId { get; private set; } public int Amount { get; private set; } + public string FuelName { get; private set; } = string.Empty; public static FuelFuelReplenishment CreateElement(int id, int fuelId, int amount) { return new FuelFuelReplenishment diff --git a/ProjectGarage/Entities/FuelReplenishment.cs b/ProjectGarage/Entities/FuelReplenishment.cs index 4d7bb28..0c00964 100644 --- a/ProjectGarage/Entities/FuelReplenishment.cs +++ b/ProjectGarage/Entities/FuelReplenishment.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,10 +10,23 @@ namespace ProjectGarage.Entities; public class FuelReplenishment { public int Id { get; private set; } + + [Browsable(false)] public int DriverId { get; private set; } + + [DisplayName("Водитель")] + public string DriverName { get; private set; } = string.Empty; + + [DisplayName("Дата поставки")] public DateTime ReplenishmentDate { get; private set; } + + [DisplayName("Топлива")] + public string Fuel => FuelFuelReplenishments != null ? +string.Join(", ", FuelFuelReplenishments.Select(x => $"{x.FuelName} {x.Amount}")) : string.Empty; + public IEnumerable FuelFuelReplenishments { get; private set;} = []; + [Browsable(false)] public static FuelReplenishment CreateOpeartion(int id, int driverId, IEnumerable fuelFuelReplenishments) { return new FuelReplenishment @@ -24,14 +38,11 @@ public class FuelReplenishment }; } - public static FuelReplenishment CreateOpeartion(TempFuelReplenishment tempFuelReplenishment, IEnumerable fuelFuelReplenishments) + public void SetFuelFuelReplenishments(IEnumerable fuelFuelReplenishments) { - return new FuelReplenishment + if (fuelFuelReplenishments != null && fuelFuelReplenishments.Any()) { - Id = tempFuelReplenishment.Id, - DriverId = tempFuelReplenishment.DriverId, - ReplenishmentDate = tempFuelReplenishment.ReplenishmentDate, - FuelFuelReplenishments = fuelFuelReplenishments - }; + FuelFuelReplenishments = fuelFuelReplenishments; + } } } diff --git a/ProjectGarage/Entities/Transportation.cs b/ProjectGarage/Entities/Transportation.cs index 0aa3408..e5d55c2 100644 --- a/ProjectGarage/Entities/Transportation.cs +++ b/ProjectGarage/Entities/Transportation.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,15 +11,29 @@ public class Transportation { public int Id { get; set; } + [Browsable(false)] public int FuelId { get; set; } + [Browsable(false)] public int RouteId { get; set; } + [Browsable(false)] public int DriverId { get; set; } - public int Amount { get; set; } + [DisplayName("Топливо")] + public string FuelName { get; private set; } = string.Empty; - public DateTime TransportationDate { get; set; } + [DisplayName("Водитель")] + public string DriverName { get; private set; } = string.Empty; + + [DisplayName("Маршрут")] + public string RouteName { get; private set; } = string.Empty; + + [DisplayName("Дата кормежки")] + public DateTime TransportationDate { get; private set; } + + [DisplayName("Кол-во топлива")] + public int Amount { get; set; } public static Transportation CreateTransportation(int id, int fuel_id, int route_id, int driver_id, int amount) { diff --git a/ProjectGarage/Reports/ExcelBuilder.cs b/ProjectGarage/Reports/ExcelBuilder.cs index c6afc71..9768a12 100644 --- a/ProjectGarage/Reports/ExcelBuilder.cs +++ b/ProjectGarage/Reports/ExcelBuilder.cs @@ -35,11 +35,10 @@ public class ExcelBuilder public ExcelBuilder AddHeader(string header, int startIndex, int count) { CreateCell(startIndex, _rowIndex, header, - StyleIndex.SimpleTextWithoutBorder); + StyleIndex.BoldTextWithBorder); for (int i = startIndex + 1; i < startIndex + count; ++i) { - CreateCell(i, _rowIndex, "", - StyleIndex.SimpleTextWithoutBorder); + CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder); } _mergeCells.Append(new MergeCell() { @@ -54,7 +53,7 @@ public class ExcelBuilder public ExcelBuilder AddParagraph(string text, int columnIndex) { CreateCell(columnIndex, _rowIndex++, text, - StyleIndex.SimpleTextWithoutBorder); + StyleIndex.SimpleTextWithBorder); return this; } public ExcelBuilder AddTable(int[] columnsWidths, List data) @@ -83,7 +82,7 @@ public class ExcelBuilder for (var j = 0; j < data.First().Length; ++j) { CreateCell(j, _rowIndex, data.First()[j], - StyleIndex.SimpleTextWithoutBorder); + StyleIndex.BoldTextWithBorder); } _rowIndex++; for (var i = 1; i < data.Count - 1; ++i) @@ -91,14 +90,14 @@ public class ExcelBuilder for (var j = 0; j < data[i].Length; ++j) { CreateCell(j, _rowIndex, data[i][j], - StyleIndex.SimpleTextWithoutBorder); + StyleIndex.SimpleTextWithBorder); } _rowIndex++; } for (var j = 0; j < data.Last().Length; ++j) { CreateCell(j, _rowIndex, data.Last()[j], - StyleIndex.SimpleTextWithoutBorder); + StyleIndex.BoldTextWithBorder); } _rowIndex++; return this; diff --git a/ProjectGarage/Repositories/Implementations/ReplenishmentRepository.cs b/ProjectGarage/Repositories/Implementations/ReplenishmentRepository.cs index 03a1752..6ba6f5e 100644 --- a/ProjectGarage/Repositories/Implementations/ReplenishmentRepository.cs +++ b/ProjectGarage/Repositories/Implementations/ReplenishmentRepository.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; +using System.Runtime.Intrinsics.X86; using System.Text; using System.Threading.Tasks; @@ -78,23 +79,46 @@ VALUES (@ReplenishmentId, @FuelId, @Amount)"; } } -public IEnumerable ReadFuelReplenishment(DateTime? dateForm = null, - DateTime? dateTo = null, int? fuelId = null, int? driverId = null, int? routeId = null) + public IEnumerable ReadFuelReplenishment(DateTime? dateForm = null, + DateTime? dateTo = null, int? fuelId = null, int? driverId = null, int? routeId = null) { _logger.LogInformation("Получение всех объектов"); try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT fr.*, ffr.FuelId, ffr.Amount + var querySelect = @"SELECT +fr.*, +CONCAT(d.Fname, ' ', d.Lname) as DriverName, +ffr.FuelId, +ffr.Amount, +CONCAT(f.FuelName, ' ', f.Price) as FuelName FROM fuelreplenishment fr -INNER JOIN fuel_fuelReplenishment ffr ON ffr.ReplenishmentId = fr.Id"; - var replenishments = connection.Query(querySelect); - _logger.LogDebug("Полученные объекты: {json}", - JsonConvert.SerializeObject(replenishments)); - return replenishments.GroupBy(x => x.Id, y => y, - (key, value) => FuelReplenishment.CreateOpeartion(value.First(), - value.Select(z => FuelFuelReplenishment.CreateElement(0, z.FuelId, z.Amount)))).ToList(); +LEFT JOIN driver d on d.Id = fr.DriverId +INNER JOIN fuel_fuelreplenishment ffr ON ffr.ReplenishmentId = fr.Id +LEFT JOIN fuel f on f.Id = ffr.FuelId"; + var replenishmentDict = new Dictionary>(); + + var fuelReplenishment = connection.Query(querySelect, + (replenishment, fuelReplenishments) => + { + if (!replenishmentDict.TryGetValue(replenishment.Id, out var ffr)) + { + ffr = []; + replenishmentDict.Add(replenishment.Id, ffr); + } + + ffr.Add(fuelReplenishments); + return replenishment; + }, splitOn: "FuelId", param: new { dateForm, dateTo, fuelId, driverId }); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(fuelReplenishment)); + + return replenishmentDict.Select(x => + { + var fr = fuelReplenishment.First(y => y.Id == x.Key); + fr.SetFuelFuelReplenishments(x.Value); + return fr; + }).ToArray(); } catch (Exception ex) { diff --git a/ProjectGarage/Repositories/Implementations/TransportationRepository.cs b/ProjectGarage/Repositories/Implementations/TransportationRepository.cs index 06e8a90..a96fa45 100644 --- a/ProjectGarage/Repositories/Implementations/TransportationRepository.cs +++ b/ProjectGarage/Repositories/Implementations/TransportationRepository.cs @@ -51,7 +51,15 @@ VALUES (@DriverId, @RouteId, @FuelId, @Amount, @TransportationDate)"; try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = "SELECT * FROM transportation"; + var querySelect = @"SELECT + t.*, + r.RouteName as RouteName, + CONCAT(d.Fname, ' ', d.Lname) as DriverName, + CONCAT(f.FuelName, ' ', f.Price) as FuelName +FROM transportation t +LEFT JOIN driver d ON d.Id = t.DriverId +LEFT JOIN fuel f ON f.Id = t.FuelId +LEFT JOIN route r ON r.Id = t.RouteId"; var transportations = connection.Query(querySelect); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(transportations)); diff --git a/Отчеты_лаб3/all.docx b/Отчеты_лаб3/all.docx deleted file mode 100644 index fd56112..0000000 Binary files a/Отчеты_лаб3/all.docx and /dev/null differ diff --git a/Отчеты_лаб3/fs.pdf b/Отчеты_лаб3/fs.pdf deleted file mode 100644 index a679224..0000000 Binary files a/Отчеты_лаб3/fs.pdf and /dev/null differ diff --git a/Отчеты_лаб3/дтл.xlsx b/Отчеты_лаб3/дтл.xlsx deleted file mode 100644 index 653f695..0000000 Binary files a/Отчеты_лаб3/дтл.xlsx and /dev/null differ