почти
This commit is contained in:
parent
8885033aab
commit
7de0767e00
@ -1,14 +1,27 @@
|
||||
using ProjectFuel.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectFuel.Entities;
|
||||
|
||||
public class Car
|
||||
{
|
||||
public int Car_ID { get; private set; }
|
||||
|
||||
[DisplayName("Марка машины")]
|
||||
public string Car_Mark { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Модель машины")]
|
||||
public string Car_Model { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Тип машины")]
|
||||
public Car_Type Car_Type { get; private set; }
|
||||
|
||||
public string FullCar => $"{Car_Mark} {Car_Model}";
|
||||
|
||||
[DisplayName("Водительская категория")]
|
||||
public Driver_License License { get; private set; }
|
||||
|
||||
[DisplayName("Потребление Топлива")]
|
||||
public float Consumption_Rate { get; private set; }
|
||||
|
||||
public static Car CreateEntity(int car_ID, string car_mark, string car_model, Car_Type car_type, Driver_License license, float consumption)
|
||||
|
@ -1,12 +1,19 @@
|
||||
using ProjectFuel.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectFuel.Entities;
|
||||
|
||||
public class Driver
|
||||
{
|
||||
public int Driver_ID { get; private set; }
|
||||
|
||||
[DisplayName("Имя водителя")]
|
||||
public string Firstname { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Фамилия водителя")]
|
||||
public string Secondname { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Категория прав")]
|
||||
public Driver_License Driver_License { get; private set; }
|
||||
|
||||
public static Driver CreateEntity(int driver_ID, string firstname, string secondname, Driver_License license)
|
||||
|
@ -1,12 +1,19 @@
|
||||
using ProjectFuel.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectFuel.Entities;
|
||||
|
||||
public class Fuel
|
||||
{
|
||||
public int Fuel_ID { get; private set; }
|
||||
|
||||
[DisplayName("Тип топлива")]
|
||||
public Fuel_Type Fuel_Type { get; private set; }
|
||||
|
||||
[DisplayName("Цена за литр")]
|
||||
public float Price_Per_Liter { get; private set; }
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public float Amount { get; private set; }
|
||||
|
||||
public static Fuel CreateEntity(int fuel_id, Fuel_Type type, float price, float amount)
|
||||
|
@ -1,13 +1,29 @@
|
||||
namespace ProjectFuel.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectFuel.Entities;
|
||||
|
||||
public class Refill
|
||||
{
|
||||
public int Refill_ID { get; private set; }
|
||||
|
||||
[DisplayName("Дата заправки")]
|
||||
public DateTime Refill_Date { get; private set; }
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public float Refill_Amount { get; private set; }
|
||||
|
||||
[DisplayName("Топливо")]
|
||||
public string FuelName { get; private set; } = string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public int Fuel_ID { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int Car_ID { get; private set; }
|
||||
|
||||
[DisplayName("Машина")]
|
||||
public string CarName { get; private set; } = string.Empty;
|
||||
|
||||
public static Refill CreateOperation(int refill_ID, DateTime refill_date, float refill_amount, int fuel_id, int car_id)
|
||||
{
|
||||
return new Refill
|
||||
|
@ -1,12 +1,22 @@
|
||||
namespace ProjectFuel.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectFuel.Entities;
|
||||
|
||||
public class Route
|
||||
{
|
||||
public int Route_ID { get; private set; }
|
||||
|
||||
[DisplayName("Начальная точка")]
|
||||
public string Start_Point { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Конечная точка")]
|
||||
public string End_Point { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Длина маршрута")]
|
||||
public float Route_Length { get; private set; }
|
||||
|
||||
public string RouteName { get; set; }
|
||||
|
||||
public string fullRoute => $"{Start_Point} {End_Point}";
|
||||
public static Route CreateEntity(int route_id, string start_point, string end_point, float length)
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
using ProjectFuel.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
using ProjectFuel.Entities.Enums;
|
||||
using ProjectFuel.Entities.Enums;
|
||||
using ProjectFuel.Entities;
|
||||
|
||||
namespace ProjectFuel.Entities;
|
||||
@ -6,15 +8,40 @@ namespace ProjectFuel.Entities;
|
||||
public class Trip
|
||||
{
|
||||
public int Trip_ID { get; private set; }
|
||||
public DateTime Start_Date { get; private set; }
|
||||
public DateTime End_Date { get; private set; }
|
||||
public Shift Shift { get; private set; }
|
||||
public float Fuel_Consumption { get; private set; }
|
||||
public int Car_ID { get; private set; }
|
||||
public int Driver_ID { get; private set; }
|
||||
public IEnumerable<Route> Routes { get; private set; } = new List<Route>();
|
||||
|
||||
public static Trip CreateOperation(int trip_id, DateTime start_date, DateTime end_date, Shift shift, float consumption, int car_id, int driver_id, IEnumerable<Route> routes)
|
||||
[DisplayName("Дата начала")]
|
||||
public DateTime Start_Date { get; private set; }
|
||||
|
||||
[DisplayName("Дата конца")]
|
||||
public DateTime End_Date { get; private set; }
|
||||
|
||||
[DisplayName("Смена")]
|
||||
public Shift Shift { get; private set; }
|
||||
|
||||
[DisplayName("Израсходованное топливо")]
|
||||
public float Fuel_Consumption { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int Car_ID { get; private set; }
|
||||
|
||||
[DisplayName("Автомобиль")]
|
||||
public string CarName { get; private set; } = string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public int Driver_ID { get; private set; }
|
||||
|
||||
[DisplayName("Водитель")]
|
||||
public string DriverName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Маршруты")]
|
||||
public string Route => Routes != null ?
|
||||
string.Join(", ", Routes.Select(x => $"{x.RouteName}")) :
|
||||
string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public IEnumerable<Trip_Route> Routes { get; private set; } = [];
|
||||
|
||||
public static Trip CreateOperation(int trip_id, DateTime start_date, DateTime end_date, Shift shift, float consumption, int car_id, int driver_id, IEnumerable<Trip_Route> routes)
|
||||
{
|
||||
return new Trip
|
||||
{
|
||||
@ -28,4 +55,10 @@ public class Trip
|
||||
Routes = routes
|
||||
};
|
||||
}
|
||||
|
||||
public void SetTrips(IEnumerable<Trip_Route> routes)
|
||||
{
|
||||
if (routes != null && routes.Any())
|
||||
Routes = routes;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ public class Trip_Route
|
||||
{
|
||||
public int Trip_ID { get; private set; }
|
||||
public int Route_ID { get; private set; }
|
||||
public string RouteName { get; private set; } = string.Empty;
|
||||
|
||||
public static Trip_Route CreateElement(int trip_id, int route_id)
|
||||
{
|
||||
|
@ -86,7 +86,12 @@ namespace ProjectFuel.Forms_
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _carRepository.ReadCars();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _carRepository.ReadCars();
|
||||
dataGridView.Columns["Car_ID"].Visible = false;
|
||||
dataGridView.Columns["FullCar"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -87,7 +87,12 @@ namespace ProjectFuel.Forms_
|
||||
}
|
||||
|
||||
}
|
||||
private void LoadList() => dataGridView.DataSource = _driverRepository.ReadDrivers();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _driverRepository.ReadDrivers();
|
||||
dataGridView.Columns["Driver_ID"].Visible = false;
|
||||
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -86,7 +86,11 @@ namespace ProjectFuel.Forms_
|
||||
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridView.DataSource = _fuelRepository.ReadFuels();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _fuelRepository.ReadFuels();
|
||||
dataGridView.Columns["Fuel_ID"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -53,12 +53,16 @@ namespace ProjectFuel.Forms_
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _refillRepository.ReadRefills();
|
||||
|
||||
|
||||
|
||||
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _refillRepository.ReadRefills();
|
||||
dataGridView.Columns["Refill_ID"].Visible = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,12 @@ namespace ProjectFuel.Forms_
|
||||
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridView.DataSource = _routeRepository.ReadRoutes();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _routeRepository.ReadRoutes();
|
||||
dataGridView.Columns["Route_ID"].Visible = false;
|
||||
dataGridView.Columns["FullRoute"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
1
ProjectFuel/Forms_/FormTrip.Designer.cs
generated
1
ProjectFuel/Forms_/FormTrip.Designer.cs
generated
@ -136,6 +136,7 @@
|
||||
//
|
||||
// comboBoxCarID
|
||||
//
|
||||
comboBoxCarID.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxCarID.FormattingEnabled = true;
|
||||
comboBoxCarID.Location = new Point(281, 288);
|
||||
comboBoxCarID.Name = "comboBoxCarID";
|
||||
|
@ -11,6 +11,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectFuel.Repositories.Implementations;
|
||||
using ProjectFuel.Entities;
|
||||
|
||||
namespace ProjectFuel.Forms_
|
||||
{
|
||||
@ -25,11 +26,11 @@ namespace ProjectFuel.Forms_
|
||||
_tripRepository = tripRepository ??
|
||||
throw new ArgumentNullException(nameof(tripRepository));
|
||||
|
||||
comboBoxCarID.DataSource = tripRepository.ReadTrips();
|
||||
comboBoxCarID.DataSource = carRepository.ReadCars();
|
||||
comboBoxCarID.DisplayMember = "Car_Mark";
|
||||
comboBoxCarID.ValueMember = "Car_ID";
|
||||
|
||||
comboBoxDriverID.DataSource = tripRepository.ReadTrips();
|
||||
comboBoxDriverID.DataSource = driverRepository.ReadDrivers();
|
||||
comboBoxDriverID.DisplayMember = "Firstname";
|
||||
comboBoxDriverID.ValueMember = "Driver_ID";
|
||||
|
||||
@ -59,15 +60,15 @@ namespace ProjectFuel.Forms_
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||
private List<Route> CreateListDriversFromDataGrid()
|
||||
private List<Trip_Route> CreateListDriversFromDataGrid()
|
||||
{
|
||||
var list = new List<Route>();
|
||||
var list = new List<Trip_Route>();
|
||||
foreach (DataGridViewRow row in dataGridViewRoutes.Rows)
|
||||
{
|
||||
if (row.Cells["ColumnRoute"].Value == null || row.Cells["ColumnEndPoint"].Value == null)
|
||||
if (row.Cells["ColumnRoute"].Value == null)
|
||||
continue;
|
||||
|
||||
list.Add(Route.CreateEntity(0, (string)row.Cells["ColumnRoute"].Value, (string)row.Cells["ColumnEndPoint"].Value, 0));
|
||||
list.Add(Trip_Route.CreateElement(0, Convert.ToInt32(row.Cells["ColumnRoute"].Value)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ProjectFuel.Repositories;
|
||||
using ProjectFuel.Repositories.Implementations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -52,6 +53,12 @@ namespace ProjectFuel.Forms_
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewTrips.DataSource = _tripRepository.ReadTrips();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewTrips.DataSource = _tripRepository.ReadTrips();
|
||||
dataGridViewTrips.Columns["Trip_ID"].Visible = false;
|
||||
dataGridViewTrips.Columns["Start_Date"].DefaultCellStyle.Format = "dd.MM.yyyy";
|
||||
dataGridViewTrips.Columns["End_Date"].DefaultCellStyle.Format = "dd.MM.yyyy";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Unity.Microsoft.Logging;
|
||||
using FuelAndLubricants.Repositories.Implementations;
|
||||
|
||||
namespace ProjectFuel
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ public class ChartReport
|
||||
{
|
||||
new PdfBuilder(filePath)
|
||||
.AddHeader("Отчет по заправкам")
|
||||
.AddPieChart("Объем заправленного топлива по автомобилям", GetData(dateTime))
|
||||
.AddPieChart($"Объем заправленного топлива по автомобилям {dateTime: dd MMMM yyyy}", GetData(dateTime))
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
@ -44,13 +44,13 @@ public class ChartReport
|
||||
.ReadRefills()
|
||||
.Where(x => x.Refill_Date.Date == dateTime.Date)
|
||||
.GroupBy(
|
||||
x => x.Car_ID,
|
||||
x => x.CarName,
|
||||
(key, group) => new
|
||||
{
|
||||
CarId = key,
|
||||
CarName = key,
|
||||
TotalRefill = group.Sum(y => y.Refill_Amount)
|
||||
})
|
||||
.Select(x => ($"Автомобиль {x.CarId}", (double)x.TotalRefill))
|
||||
.Select(x => ($"{x.CarName}", (double)x.TotalRefill))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
@ -48,10 +48,10 @@ public class TableReport
|
||||
private List<string[]> GetData(int carId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var refills = _refillRepository
|
||||
.ReadRefills()
|
||||
.Where(x => x.Refill_Date >= startDate && x.Refill_Date <= endDate && x.Car_ID == carId)
|
||||
.ReadRefills(dateFrom: startDate, dateTo: endDate, carId: carId)
|
||||
.Select(x => new
|
||||
{
|
||||
x.CarName,
|
||||
CarId = x.Car_ID,
|
||||
Date = x.Refill_Date,
|
||||
RefillAmount = (float?)x.Refill_Amount,
|
||||
@ -60,10 +60,10 @@ public class TableReport
|
||||
.AsEnumerable();
|
||||
|
||||
var trips = _tripRepository
|
||||
.ReadTrips()
|
||||
.Where(x => x.Start_Date >= startDate && x.End_Date <= endDate && x.Car_ID == carId)
|
||||
.ReadTrips(dateFrom: startDate, dateTo: endDate, carId: carId)
|
||||
.Select(x => new
|
||||
{
|
||||
x.CarName,
|
||||
CarId = x.Car_ID,
|
||||
Date = x.Start_Date,
|
||||
RefillAmount = (float?)null,
|
||||
|
@ -1,11 +1,12 @@
|
||||
using ProjectFuel.Entities;
|
||||
using ProjectFuel.Entities;
|
||||
|
||||
|
||||
namespace ProjectFuel.Repositories;
|
||||
|
||||
public interface ITripRepository
|
||||
{
|
||||
IEnumerable<Trip> ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? carId = null, int? driverId = null, int? routeId = null);
|
||||
IEnumerable<Trip> ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? carId = null, int? driverId = null);
|
||||
|
||||
void CreateTrip(Trip trip);
|
||||
}
|
||||
|
35
ProjectFuel/Repositories/Implementations/QuerryBuilder.cs
Normal file
35
ProjectFuel/Repositories/Implementations/QuerryBuilder.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectFuel.Repositories.Implementations;
|
||||
|
||||
public class QuerryBuilder
|
||||
{
|
||||
private readonly StringBuilder _builder;
|
||||
|
||||
public QuerryBuilder()
|
||||
{
|
||||
_builder = new();
|
||||
}
|
||||
|
||||
public QuerryBuilder 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}";
|
||||
}
|
||||
}
|
@ -40,8 +40,29 @@ VALUES (@Refill_Date, @Refill_Amount, @Fuel_ID, @Car_ID)";
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QuerryBuilder();
|
||||
|
||||
if (dateFrom.HasValue)
|
||||
builder.AddCondition("r.Refill_Date >= @dateFrom");
|
||||
if (dateTo.HasValue)
|
||||
builder.AddCondition("r.Refill_Date <= @dateTo");
|
||||
if (fuelId.HasValue)
|
||||
builder.AddCondition("r.Fuel_ID = @fuelId");
|
||||
if (carId.HasValue)
|
||||
builder.AddCondition("r.Car_ID = @carId");
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Refill";
|
||||
var querySelect = $@"SELECT
|
||||
r.*,
|
||||
CONCAT(c.Car_Mark, ' ', c.Car_Model) AS CarName,
|
||||
CASE f.Fuel_Type :: int
|
||||
WHEN 1 THEN 'Бензин'
|
||||
WHEN 2 THEN 'Дизель'
|
||||
ELSE 'Unknown'
|
||||
END AS FuelName
|
||||
FROM Refill r
|
||||
LEFT JOIN Fuel_And_Lubricants f ON r.Fuel_ID = f.Fuel_ID
|
||||
LEFT JOIN Car c ON r.Car_ID = c.Car_ID
|
||||
{builder.Build()}";
|
||||
var refills = connection.Query<Refill>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(refills));
|
||||
return refills;
|
||||
|
@ -1,11 +1,13 @@
|
||||
using Dapper;
|
||||
using ProjectFuel.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectFuel.Entities;
|
||||
using ProjectFuel.Repositories.Implementations;
|
||||
using ProjectFuel.Repositories;
|
||||
|
||||
namespace ProjectFuel.Repositories.Implementations;
|
||||
namespace FuelAndLubricants.Repositories.Implementations;
|
||||
|
||||
public class TripRepository : ITripRepository
|
||||
{
|
||||
@ -18,6 +20,7 @@ public class TripRepository : ITripRepository
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateTrip(Trip trip)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
@ -52,19 +55,58 @@ public class TripRepository : ITripRepository
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<Trip> ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? carId = null, int? driverId = null, int? routeId = null)
|
||||
public IEnumerable<Trip> ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? carId = null, int? driverId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QuerryBuilder();
|
||||
|
||||
if (dateFrom != null)
|
||||
builder.AddCondition("t.Start_Date >= @dateFrom");
|
||||
if (dateTo != null)
|
||||
builder.AddCondition("t.End_Date <= @dateTo");
|
||||
if (carId != null)
|
||||
builder.AddCondition("t.Car_ID = @carId");
|
||||
if (driverId != null)
|
||||
builder.AddCondition("t.Driver_ID = @driverId");
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Trip";
|
||||
var trips = connection.Query<Trip>(querySelect);
|
||||
var querySelect = $@"SELECT
|
||||
t.*,
|
||||
CONCAT(c.Car_Mark, ' ', c.Car_Model) AS CarName,
|
||||
CONCAT(d.Firstname, ' ', d.Secondname) AS DriverName,
|
||||
tr.Route_ID,
|
||||
CONCAT(r.Start_Point, ' ', r.End_Point) AS RouteName
|
||||
FROM Trip t
|
||||
LEFT JOIN Car c ON t.Car_ID = c.Car_ID
|
||||
LEFT JOIN Driver d ON t.Driver_ID = d.Driver_ID
|
||||
INNER JOIN Trip_Route tr ON t.Trip_ID = tr.Trip_ID
|
||||
LEFT JOIN Route r ON r.Route_ID = tr.Route_ID
|
||||
{builder.Build()}";
|
||||
var tripDict = new Dictionary<int, List<Trip_Route>>();
|
||||
|
||||
var trips = connection.Query<Trip, Trip_Route, Trip>(querySelect,
|
||||
(trip, tripRoute) =>
|
||||
{
|
||||
if (!tripDict.TryGetValue(trip.Trip_ID, out var tr))
|
||||
{
|
||||
tr = new List<Trip_Route>();
|
||||
tripDict.Add(trip.Trip_ID, tr);
|
||||
}
|
||||
|
||||
tr.Add(tripRoute);
|
||||
return trip;
|
||||
}, splitOn: "Route_ID", param: new { dateFrom, dateTo, carId, driverId });
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(trips));
|
||||
return trips;
|
||||
return tripDict.Select(x =>
|
||||
{
|
||||
var t = trips.First(y => y.Trip_ID == x.Key);
|
||||
t.SetTrips(x.Value);
|
||||
return t;
|
||||
}).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user