diff --git a/ProjectGarage/Entities/Driver.cs b/ProjectGarage/Entities/Driver.cs index 8909ff8..0994a6b 100644 --- a/ProjectGarage/Entities/Driver.cs +++ b/ProjectGarage/Entities/Driver.cs @@ -6,6 +6,7 @@ using ProjectGarage.Entities.Enums; using ProjectGarage.Repositories; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -14,14 +15,22 @@ namespace ProjectGarage.Entities; public class Driver { - public int Id { get;private set; } + public int Id { get; private set; } + [DisplayName("Фамилия")] public string Fname { get;private set; } = string.Empty; - + + [DisplayName("Имя")] public string Lname { get;private set; } = string.Empty; + public string FullName => $"{Fname} {Lname}"; + + [Browsable(false)] public int TruckId { get;private set; } + [DisplayName("Номера фуры")] + public string TruckNum { get;private set; } = string.Empty; + public static Driver CreateDriver(int id, string fname, string lname, int truckid) { return new Driver diff --git a/ProjectGarage/Entities/Fuel.cs b/ProjectGarage/Entities/Fuel.cs index 5721b4c..38b1eb3 100644 --- a/ProjectGarage/Entities/Fuel.cs +++ b/ProjectGarage/Entities/Fuel.cs @@ -1,6 +1,7 @@ using ProjectGarage.Entities.Enums; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Reflection.Metadata.Ecma335; using System.Text; @@ -12,10 +13,13 @@ public class Fuel { public int Id { get; set; } + [DisplayName("Название топлива")] public string FuelName { get; set; } = string.Empty; + [DisplayName("Вид топлива")] public FuelType FuelType { get; set; } + [DisplayName("Цена за литр")] public int Price { get; set; } public static Fuel CreateFuel(int id, string name, FuelType type, int price) 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..dc50e91 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,24 @@ 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; + + [Browsable(false)] public IEnumerable FuelFuelReplenishments { get; private set;} = []; + public static FuelReplenishment CreateOpeartion(int id, int driverId, IEnumerable fuelFuelReplenishments) { return new FuelReplenishment @@ -24,14 +39,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/Route.cs b/ProjectGarage/Entities/Route.cs index 7d60fd8..d25023a 100644 --- a/ProjectGarage/Entities/Route.cs +++ b/ProjectGarage/Entities/Route.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,12 +11,16 @@ public class Route { public int Id { get; set; } + [DisplayName("Название маршрута")] public string RouteName { get; set; } = string.Empty; + [DisplayName("Начальная т.")] public string StartP { get; set; } = string.Empty; + [DisplayName("Конечная т.")] public string FinalP { get; set; } = string.Empty; + [DisplayName("Протяженность")] public int Length { get; set; } public static Route CreateRoute(int id,string name, string startp, string finalp, int len) diff --git a/ProjectGarage/Entities/Transportation.cs b/ProjectGarage/Entities/Transportation.cs index 0aa3408..2fc281d 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/Entities/Truck.cs b/ProjectGarage/Entities/Truck.cs index c412dc4..5d66def 100644 --- a/ProjectGarage/Entities/Truck.cs +++ b/ProjectGarage/Entities/Truck.cs @@ -1,6 +1,7 @@ using ProjectGarage.Entities.Enums; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,12 +12,17 @@ public class Truck { public int Id { get; private set; } + [DisplayName("Номера фуры")] public string Numbers { get; private set; } = string.Empty; + [DisplayName("Марка фуры")] public TruckType Truck_Type { get; set; } + [DisplayName("Вместимость цистерны")] public int MaxFuel { get; private set; } + public string TruckInfo => $"{Numbers} {Truck_Type.ToString()}"; + public static Truck CreateTruck(int id,string numbers, TruckType type, int maxFuel) { return new Truck() diff --git a/ProjectGarage/Forms/FormDriver.cs b/ProjectGarage/Forms/FormDriver.cs index 75dae1f..8a760b5 100644 --- a/ProjectGarage/Forms/FormDriver.cs +++ b/ProjectGarage/Forms/FormDriver.cs @@ -49,7 +49,7 @@ namespace ProjectGarage.Forms InitializeComponent(); _driverRepository = driverRepository ?? throw new ArgumentNullException(nameof(driverRepository)); comboBoxTruckID.DataSource = truckRepository.ReadTrucks(); - comboBoxTruckID.DisplayMember = "Numbers"; + comboBoxTruckID.DisplayMember = "TruckInfo"; comboBoxTruckID.ValueMember = "Id"; } diff --git a/ProjectGarage/Forms/FormDrivers.cs b/ProjectGarage/Forms/FormDrivers.cs index e5fdf57..783a52c 100644 --- a/ProjectGarage/Forms/FormDrivers.cs +++ b/ProjectGarage/Forms/FormDrivers.cs @@ -94,7 +94,12 @@ namespace ProjectGarage.Forms } - private void LoadList() => dataGridViewDrivers.DataSource = _driverRepository.ReadDrivers(); + private void LoadList() + { + dataGridViewDrivers.DataSource = _driverRepository.ReadDrivers(); + dataGridViewDrivers.Columns["Id"].Visible = false; + dataGridViewDrivers.Columns["FullName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectGarage/Forms/FormFuels.cs b/ProjectGarage/Forms/FormFuels.cs index 893dc14..688f211 100644 --- a/ProjectGarage/Forms/FormFuels.cs +++ b/ProjectGarage/Forms/FormFuels.cs @@ -96,7 +96,11 @@ namespace ProjectGarage.Forms } } - private void LoadList() => dataGridViewFuels.DataSource = _fuelRepository.ReadFuels(); + private void LoadList() + { + dataGridViewFuels.DataSource = _fuelRepository.ReadFuels(); + dataGridViewFuels.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectGarage/Forms/FormReplenishment.cs b/ProjectGarage/Forms/FormReplenishment.cs index 62a7950..c482f24 100644 --- a/ProjectGarage/Forms/FormReplenishment.cs +++ b/ProjectGarage/Forms/FormReplenishment.cs @@ -25,7 +25,7 @@ namespace ProjectGarage.Forms _replenishmentRepository = replenishmentRepository ?? throw new ArgumentNullException(nameof(replenishmentRepository)); comboBoxReplenishmentDriver.DataSource = driverRepository.ReadDrivers(); - comboBoxReplenishmentDriver.DisplayMember = "Fname"; + comboBoxReplenishmentDriver.DisplayMember = "FullName"; comboBoxReplenishmentDriver.ValueMember = "Id"; ColumnFuel.DataSource = fuelRepository.ReadFuels(); ColumnFuel.DisplayMember = "FuelName"; diff --git a/ProjectGarage/Forms/FormReplenishments.cs b/ProjectGarage/Forms/FormReplenishments.cs index efefa42..86e2fd8 100644 --- a/ProjectGarage/Forms/FormReplenishments.cs +++ b/ProjectGarage/Forms/FormReplenishments.cs @@ -77,8 +77,13 @@ namespace ProjectGarage.Forms MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void LoadList() => dataGridViewReplenishments.DataSource = _replenishmentRepository.ReadFuelReplenishment(); - + private void LoadList() + { + dataGridViewReplenishments.DataSource = _replenishmentRepository.ReadFuelReplenishment(); + dataGridViewReplenishments.Columns["Id"].Visible = false; + dataGridViewReplenishments.Columns["ReplenishmentDate"].DefaultCellStyle.Format = "dd.MM.yyyy"; + } + private bool TryGetIdentifierFromSelectedRow(out int id) { id = 0; diff --git a/ProjectGarage/Forms/FormRoutes.cs b/ProjectGarage/Forms/FormRoutes.cs index 7f7a62a..08629c0 100644 --- a/ProjectGarage/Forms/FormRoutes.cs +++ b/ProjectGarage/Forms/FormRoutes.cs @@ -96,7 +96,11 @@ namespace ProjectGarage.Forms } } - private void LoadList() => dataGridViewRoutes.DataSource = _routeRepository.ReadRoute(); + private void LoadList() + { + dataGridViewRoutes.DataSource = _routeRepository.ReadRoute(); + dataGridViewRoutes.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectGarage/Forms/FormTransportation.cs b/ProjectGarage/Forms/FormTransportation.cs index 8bb7fc5..b7a057f 100644 --- a/ProjectGarage/Forms/FormTransportation.cs +++ b/ProjectGarage/Forms/FormTransportation.cs @@ -25,7 +25,7 @@ namespace ProjectGarage.Forms throw new ArgumentNullException(nameof(transportationRepository)); comboBoxDriver.DataSource = driverRepository.ReadDrivers(); - comboBoxDriver.DisplayMember = "Fname"; + comboBoxDriver.DisplayMember = "FullName"; comboBoxDriver.ValueMember = "Id"; comboBoxFuel.DataSource = fuelRepository.ReadFuels(); diff --git a/ProjectGarage/Forms/FormTransportations.cs b/ProjectGarage/Forms/FormTransportations.cs index 7c423a5..bbee316 100644 --- a/ProjectGarage/Forms/FormTransportations.cs +++ b/ProjectGarage/Forms/FormTransportations.cs @@ -52,6 +52,11 @@ namespace ProjectGarage.Forms } } - private void LoadList() => dataGridViewTransportations.DataSource = _transportationRepository.ReadTransportation(); + private void LoadList() + { + dataGridViewTransportations.DataSource = _transportationRepository.ReadTransportation(); + dataGridViewTransportations.Columns["Id"].Visible = false; + dataGridViewTransportations.Columns["TransportationDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm"; + } } } diff --git a/ProjectGarage/Forms/FormTrucks.cs b/ProjectGarage/Forms/FormTrucks.cs index 41a2e7f..b58e98f 100644 --- a/ProjectGarage/Forms/FormTrucks.cs +++ b/ProjectGarage/Forms/FormTrucks.cs @@ -92,7 +92,12 @@ namespace ProjectGarage.Forms } } - private void LoadList() => dataGridViewTrucks.DataSource = _truckRepository.ReadTrucks(); + private void LoadList() + { + dataGridViewTrucks.DataSource = _truckRepository.ReadTrucks(); + dataGridViewTrucks.Columns["Id"].Visible = false; + dataGridViewTrucks.Columns["TruckInfo"].Visible = false; + } private bool TryGetIDFromSelectedRow(out int id) { diff --git a/ProjectGarage/Reports/ChartReport.cs b/ProjectGarage/Reports/ChartReport.cs index f9fd92e..81f74e0 100644 --- a/ProjectGarage/Reports/ChartReport.cs +++ b/ProjectGarage/Reports/ChartReport.cs @@ -25,7 +25,7 @@ public class ChartReport { new PdfBuilder(filePath) .AddHeader("Транспортировка топлива") - .AddPieChart("Отправленное топливо", GetData(dateTime)) + .AddPieChart($"Отправленное топливо на {dateTime:dd MMMM yyyy}", GetData(dateTime)) .Build(); return true; } @@ -38,13 +38,13 @@ public class ChartReport private List<(string Caption, double Value)> GetData(DateTime dateTime) { return _transportationRepository - .ReadTransportation() + .ReadTransportation(dateForm: dateTime.Date, dateTo: dateTime.Date.AddDays(1)) .Where(x => x.TransportationDate.Date == dateTime.Date) - .GroupBy(x => x.FuelId, (key, group) => new { - Id = key, + .GroupBy(x => x.FuelName, (key, group) => new { + FuelName = key, Amount = group.Sum(x => x.Amount) }) - .Select(x => (x.Id.ToString(), (double)x.Amount)) + .Select(x => (x.FuelName, (double)x.Amount)) .ToList(); } 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/Reports/TableReport.cs b/ProjectGarage/Reports/TableReport.cs index 777acfd..f4e6c22 100644 --- a/ProjectGarage/Reports/TableReport.cs +++ b/ProjectGarage/Reports/TableReport.cs @@ -13,7 +13,7 @@ public class TableReport private readonly IReplenishmentRepository _replenishmentRepository; private readonly ITransportationRepository _transportationRepository; private readonly ILogger _logger; - internal static readonly string[] item = ["Водитель", "Дата", " пришло", "Количество ушло"]; + internal static readonly string[] item = ["Водитель", "Дата", "Кол-во пришло", "Кол-во ушло"]; public TableReport(IReplenishmentRepository replenishmentRepository, ITransportationRepository transportationRepository, ILogger logger) { @@ -28,11 +28,10 @@ public class TableReport try { new ExcelBuilder(filePath) - .AddHeader("Сводка по движению топлива", 0, 4) - .AddParagraph("за период", 0) - .AddTable([10, 10, 15, 15], GetData(fuelId, startDate, - endDate)) - .Build(); + .AddHeader("Сводка по движению топлива", 0, 4) + .AddParagraph($"за период c {startDate:dd.MM.yyyy} по {endDate: dd.MM.yyyy}", 0) + .AddTable([10, 10, 15, 15], GetData(fuelId, startDate, endDate)) + .Build(); return true; } catch (Exception ex) @@ -42,15 +41,12 @@ public class TableReport } } - private List GetData(int fuelId, DateTime startDate, DateTime - endDate) + private List GetData(int fuelId, DateTime startDate, DateTime endDate) { var data = _replenishmentRepository - .ReadFuelReplenishment() - .Where(x => x.ReplenishmentDate >= startDate && x.ReplenishmentDate <= endDate && - x.FuelFuelReplenishments.Any(y => y.FuelId == fuelId)) + .ReadFuelReplenishment(dateForm: startDate, dateTo: endDate, fuelId: fuelId) .Select(x => new { - x.DriverId, + x.DriverName, Date = x.ReplenishmentDate, CountIn = x.FuelFuelReplenishments. FirstOrDefault(y => y.FuelId == fuelId)?.Amount, @@ -58,11 +54,11 @@ public class TableReport }) .Union( _transportationRepository - .ReadTransportation() + .ReadTransportation(dateForm: startDate, dateTo: endDate, fuelId: fuelId) .Where(x => x.TransportationDate >= startDate && x.TransportationDate <= endDate && x.FuelId == fuelId) .Select(x => new { - x.DriverId, + x.DriverName, Date = x.TransportationDate, CountIn = (int?)null, CountOut = (int?)x.Amount @@ -73,11 +69,11 @@ public class TableReport .Union( data .Select(x => new string[] { - x.DriverId.ToString(), x.Date.ToString(), x.CountIn?.ToString() ?? - string.Empty, x.CountOut?.ToString() ?? string.Empty})) + x.DriverName.ToString(), x.Date.ToString("dd.MM.yyyy"), x.CountIn?.ToString("N0") ?? + string.Empty, x.CountOut?.ToString("N0") ?? string.Empty})) .Union( - [["Всего", "", data.Sum(x => x.CountIn ?? 0).ToString(), - data.Sum(x => x.CountOut ?? 0).ToString()]]) + [["Всего", "", data.Sum(x => x.CountIn ?? 0).ToString("N0"), + data.Sum(x => x.CountOut ?? 0).ToString("N0")]]) .ToList(); } } diff --git a/ProjectGarage/Repositories/Implementations/DriverRepository.cs b/ProjectGarage/Repositories/Implementations/DriverRepository.cs index ac99747..a29ded2 100644 --- a/ProjectGarage/Repositories/Implementations/DriverRepository.cs +++ b/ProjectGarage/Repositories/Implementations/DriverRepository.cs @@ -117,7 +117,10 @@ WHERE Id=@id"; try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT * FROM driver"; + var querySelect = @"SELECT d.*, +CONCAT(t.Numbers, '') as TruckNum +FROM driver d +JOIN Truck t ON d.TruckID = t.Id"; var drivers = connection.Query(querySelect); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(drivers)); return drivers; diff --git a/ProjectGarage/Repositories/Implementations/QueryBuilder.cs b/ProjectGarage/Repositories/Implementations/QueryBuilder.cs new file mode 100644 index 0000000..8e1d82f --- /dev/null +++ b/ProjectGarage/Repositories/Implementations/QueryBuilder.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGarage.Repositories.Implementations; + +public 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}"; + } +} diff --git a/ProjectGarage/Repositories/Implementations/ReplenishmentRepository.cs b/ProjectGarage/Repositories/Implementations/ReplenishmentRepository.cs index 03a1752..dd0eec9 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,65 @@ 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 { + var builder = new QueryBuilder(); + if (dateForm.HasValue) + { + builder.AddCondition("fr.ReplenishmentDate >= @dateForm"); + } + if (dateTo.HasValue) + { + builder.AddCondition("fr.ReplenishmentDate <= @dateTo"); + } + if (driverId.HasValue) + { + builder.AddCondition("fr.DriverId = @driverId"); + } + if (fuelId.HasValue) + { + builder.AddCondition("ffr.FuelId = @fuelId"); + } + 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 +{builder.Build()}"; + 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..d498157 100644 --- a/ProjectGarage/Repositories/Implementations/TransportationRepository.cs +++ b/ProjectGarage/Repositories/Implementations/TransportationRepository.cs @@ -50,9 +50,39 @@ VALUES (@DriverId, @RouteId, @FuelId, @Amount, @TransportationDate)"; _logger.LogInformation("Получение всех объектов"); try { + var builder = new QueryBuilder(); + if (dateForm.HasValue) + { + builder.AddCondition("t.TransportationDate >= @dateForm"); + } + if (dateTo.HasValue) + { + builder.AddCondition("t.TransportationDate <= @dateTo"); + } + if (fuelId.HasValue) + { + builder.AddCondition("t.FuelId = @fuelId"); + } + if (driverId.HasValue) + { + builder.AddCondition("t.DriverId = @driverId"); + } + if (routeId.HasValue) + { + builder.AddCondition("t.RouteId = @routeId"); + } using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = "SELECT * FROM transportation"; - var transportations = connection.Query(querySelect); + 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 +{builder.Build()}"; + var transportations = connection.Query(querySelect, new {dateForm, dateTo, fuelId, driverId, routeId }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(transportations)); return 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