лаб 4 финиш
This commit is contained in:
parent
7de0767e00
commit
d2c14ef22c
@ -15,5 +15,5 @@ public enum Driver_License
|
||||
C = 4,
|
||||
D = 8,
|
||||
BE = 16,
|
||||
CE = 32
|
||||
}
|
||||
CE = 32,
|
||||
}
|
@ -1,47 +1,19 @@
|
||||
using System.ComponentModel;
|
||||
using ProjectFuel.Entities.Enums;
|
||||
using ProjectFuel.Entities.Enums;
|
||||
using ProjectFuel.Entities;
|
||||
using ProjectFuel.Entities.Enums;
|
||||
|
||||
namespace ProjectFuel.Entities;
|
||||
|
||||
public class Trip
|
||||
{
|
||||
public int Trip_ID { get; private set; }
|
||||
|
||||
[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; }
|
||||
public IEnumerable<TripRoute> Routes { 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)
|
||||
public static Trip CreateOperation(int trip_id, DateTime start_date, DateTime end_date, Shift shift, float consumption, int car_id, int driver_id, IEnumerable<TripRoute> routes)
|
||||
{
|
||||
return new Trip
|
||||
{
|
||||
@ -55,10 +27,4 @@ public class Trip
|
||||
Routes = routes
|
||||
};
|
||||
}
|
||||
|
||||
public void SetTrips(IEnumerable<Trip_Route> routes)
|
||||
{
|
||||
if (routes != null && routes.Any())
|
||||
Routes = routes;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,18 +6,19 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectFuel.Entities;
|
||||
|
||||
public class Trip_Route
|
||||
public class TripRoute
|
||||
{
|
||||
public int Trip_ID { get; private set; }
|
||||
public int Route_ID { get; private set; }
|
||||
public string RouteName { get; private set; } = string.Empty;
|
||||
public int Fuel_Init { get; private set; }
|
||||
|
||||
public static Trip_Route CreateElement(int trip_id, int route_id)
|
||||
public static TripRoute CreateOperation(int trip_Id, int route_ID, int fuel_Init)
|
||||
{
|
||||
return new Trip_Route
|
||||
return new TripRoute
|
||||
{
|
||||
Trip_ID = trip_id,
|
||||
Route_ID = route_id
|
||||
Trip_ID = trip_Id,
|
||||
Route_ID = route_ID,
|
||||
Fuel_Init = fuel_Init
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
141
ProjectFuel/Forms_/FormTrip.Designer.cs
generated
141
ProjectFuel/Forms_/FormTrip.Designer.cs
generated
@ -30,13 +30,11 @@
|
||||
{
|
||||
label1 = new Label();
|
||||
label2 = new Label();
|
||||
label3 = new Label();
|
||||
label4 = new Label();
|
||||
label5 = new Label();
|
||||
label6 = new Label();
|
||||
dateTimePickerStartDate = new DateTimePicker();
|
||||
dateTimePickerEndDate = new DateTimePicker();
|
||||
comboBoxShift = new ComboBox();
|
||||
numericUpDownConsumptionRate = new NumericUpDown();
|
||||
comboBoxCarID = new ComboBox();
|
||||
comboBoxDriverID = new ComboBox();
|
||||
@ -44,8 +42,10 @@
|
||||
buttonCancel = new Button();
|
||||
groupBox = new GroupBox();
|
||||
dataGridViewRoutes = new DataGridView();
|
||||
label3 = new Label();
|
||||
comboBoxShift = new ComboBox();
|
||||
ColumnRoute = new DataGridViewComboBoxColumn();
|
||||
ColumnEndPoint = new DataGridViewTextBoxColumn();
|
||||
ColumnFuelInit = new DataGridViewTextBoxColumn();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).BeginInit();
|
||||
groupBox.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).BeginInit();
|
||||
@ -54,108 +54,101 @@
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(52, 38);
|
||||
label1.Location = new Point(28, 18);
|
||||
label1.Margin = new Padding(2, 0, 2, 0);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(149, 32);
|
||||
label1.Size = new Size(74, 15);
|
||||
label1.TabIndex = 0;
|
||||
label1.Text = "Дата начала";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(61, 104);
|
||||
label2.Location = new Point(33, 49);
|
||||
label2.Margin = new Padding(2, 0, 2, 0);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(138, 32);
|
||||
label2.Size = new Size(68, 15);
|
||||
label2.TabIndex = 1;
|
||||
label2.Text = "Дата конца";
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(62, 163);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(85, 32);
|
||||
label3.TabIndex = 2;
|
||||
label3.Text = "Смена";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
label4.AutoSize = true;
|
||||
label4.Location = new Point(59, 219);
|
||||
label4.Location = new Point(32, 103);
|
||||
label4.Margin = new Padding(2, 0, 2, 0);
|
||||
label4.Name = "label4";
|
||||
label4.Size = new Size(185, 32);
|
||||
label4.Size = new Size(93, 15);
|
||||
label4.TabIndex = 3;
|
||||
label4.Text = "Расход топлива";
|
||||
//
|
||||
// label5
|
||||
//
|
||||
label5.AutoSize = true;
|
||||
label5.Location = new Point(55, 276);
|
||||
label5.Location = new Point(30, 129);
|
||||
label5.Margin = new Padding(2, 0, 2, 0);
|
||||
label5.Name = "label5";
|
||||
label5.Size = new Size(107, 32);
|
||||
label5.Size = new Size(55, 15);
|
||||
label5.TabIndex = 4;
|
||||
label5.Text = "Машина";
|
||||
//
|
||||
// label6
|
||||
//
|
||||
label6.AutoSize = true;
|
||||
label6.Location = new Point(61, 339);
|
||||
label6.Location = new Point(33, 159);
|
||||
label6.Margin = new Padding(2, 0, 2, 0);
|
||||
label6.Name = "label6";
|
||||
label6.Size = new Size(117, 32);
|
||||
label6.Size = new Size(58, 15);
|
||||
label6.TabIndex = 5;
|
||||
label6.Text = "Водитель";
|
||||
//
|
||||
// dateTimePickerStartDate
|
||||
//
|
||||
dateTimePickerStartDate.Location = new Point(303, 31);
|
||||
dateTimePickerStartDate.Location = new Point(163, 15);
|
||||
dateTimePickerStartDate.Margin = new Padding(2, 1, 2, 1);
|
||||
dateTimePickerStartDate.Name = "dateTimePickerStartDate";
|
||||
dateTimePickerStartDate.Size = new Size(400, 39);
|
||||
dateTimePickerStartDate.Size = new Size(217, 23);
|
||||
dateTimePickerStartDate.TabIndex = 6;
|
||||
//
|
||||
// dateTimePickerEndDate
|
||||
//
|
||||
dateTimePickerEndDate.Location = new Point(295, 106);
|
||||
dateTimePickerEndDate.Location = new Point(159, 50);
|
||||
dateTimePickerEndDate.Margin = new Padding(2, 1, 2, 1);
|
||||
dateTimePickerEndDate.Name = "dateTimePickerEndDate";
|
||||
dateTimePickerEndDate.Size = new Size(400, 39);
|
||||
dateTimePickerEndDate.Size = new Size(217, 23);
|
||||
dateTimePickerEndDate.TabIndex = 7;
|
||||
//
|
||||
// comboBoxShift
|
||||
//
|
||||
comboBoxShift.FormattingEnabled = true;
|
||||
comboBoxShift.Location = new Point(292, 171);
|
||||
comboBoxShift.Name = "comboBoxShift";
|
||||
comboBoxShift.Size = new Size(242, 40);
|
||||
comboBoxShift.TabIndex = 8;
|
||||
//
|
||||
// numericUpDownConsumptionRate
|
||||
//
|
||||
numericUpDownConsumptionRate.Location = new Point(288, 232);
|
||||
numericUpDownConsumptionRate.Location = new Point(155, 109);
|
||||
numericUpDownConsumptionRate.Margin = new Padding(2, 1, 2, 1);
|
||||
numericUpDownConsumptionRate.Name = "numericUpDownConsumptionRate";
|
||||
numericUpDownConsumptionRate.Size = new Size(240, 39);
|
||||
numericUpDownConsumptionRate.Size = new Size(129, 23);
|
||||
numericUpDownConsumptionRate.TabIndex = 9;
|
||||
//
|
||||
// comboBoxCarID
|
||||
//
|
||||
comboBoxCarID.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxCarID.FormattingEnabled = true;
|
||||
comboBoxCarID.Location = new Point(281, 288);
|
||||
comboBoxCarID.Location = new Point(151, 135);
|
||||
comboBoxCarID.Margin = new Padding(2, 1, 2, 1);
|
||||
comboBoxCarID.Name = "comboBoxCarID";
|
||||
comboBoxCarID.Size = new Size(242, 40);
|
||||
comboBoxCarID.Size = new Size(132, 23);
|
||||
comboBoxCarID.TabIndex = 10;
|
||||
//
|
||||
// comboBoxDriverID
|
||||
//
|
||||
comboBoxDriverID.FormattingEnabled = true;
|
||||
comboBoxDriverID.Location = new Point(274, 348);
|
||||
comboBoxDriverID.Location = new Point(148, 163);
|
||||
comboBoxDriverID.Margin = new Padding(2, 1, 2, 1);
|
||||
comboBoxDriverID.Name = "comboBoxDriverID";
|
||||
comboBoxDriverID.Size = new Size(242, 40);
|
||||
comboBoxDriverID.Size = new Size(132, 23);
|
||||
comboBoxDriverID.TabIndex = 11;
|
||||
//
|
||||
// buttonTripSave
|
||||
//
|
||||
buttonTripSave.Location = new Point(79, 649);
|
||||
buttonTripSave.Location = new Point(43, 304);
|
||||
buttonTripSave.Margin = new Padding(2, 1, 2, 1);
|
||||
buttonTripSave.Name = "buttonTripSave";
|
||||
buttonTripSave.Size = new Size(150, 46);
|
||||
buttonTripSave.Size = new Size(81, 22);
|
||||
buttonTripSave.TabIndex = 14;
|
||||
buttonTripSave.Text = "Сохранить";
|
||||
buttonTripSave.UseVisualStyleBackColor = true;
|
||||
@ -163,9 +156,10 @@
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(346, 649);
|
||||
buttonCancel.Location = new Point(186, 304);
|
||||
buttonCancel.Margin = new Padding(2, 1, 2, 1);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(150, 46);
|
||||
buttonCancel.Size = new Size(81, 22);
|
||||
buttonCancel.TabIndex = 15;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
@ -174,9 +168,11 @@
|
||||
// groupBox
|
||||
//
|
||||
groupBox.Controls.Add(dataGridViewRoutes);
|
||||
groupBox.Location = new Point(52, 421);
|
||||
groupBox.Location = new Point(28, 198);
|
||||
groupBox.Margin = new Padding(2, 1, 2, 1);
|
||||
groupBox.Name = "groupBox";
|
||||
groupBox.Size = new Size(410, 222);
|
||||
groupBox.Padding = new Padding(2, 1, 2, 1);
|
||||
groupBox.Size = new Size(308, 104);
|
||||
groupBox.TabIndex = 16;
|
||||
groupBox.TabStop = false;
|
||||
groupBox.Text = "Маршруты";
|
||||
@ -185,38 +181,58 @@
|
||||
//
|
||||
dataGridViewRoutes.AllowUserToResizeColumns = false;
|
||||
dataGridViewRoutes.AllowUserToResizeRows = false;
|
||||
dataGridViewRoutes.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridViewRoutes.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewRoutes.Columns.AddRange(new DataGridViewColumn[] { ColumnRoute, ColumnEndPoint });
|
||||
dataGridViewRoutes.Columns.AddRange(new DataGridViewColumn[] { ColumnRoute, ColumnFuelInit });
|
||||
dataGridViewRoutes.Dock = DockStyle.Fill;
|
||||
dataGridViewRoutes.Location = new Point(3, 35);
|
||||
dataGridViewRoutes.Margin = new Padding(5);
|
||||
dataGridViewRoutes.Location = new Point(2, 17);
|
||||
dataGridViewRoutes.Margin = new Padding(3, 2, 3, 2);
|
||||
dataGridViewRoutes.MultiSelect = false;
|
||||
dataGridViewRoutes.Name = "dataGridViewRoutes";
|
||||
dataGridViewRoutes.RowHeadersVisible = false;
|
||||
dataGridViewRoutes.RowHeadersWidth = 51;
|
||||
dataGridViewRoutes.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewRoutes.Size = new Size(404, 184);
|
||||
dataGridViewRoutes.Size = new Size(304, 86);
|
||||
dataGridViewRoutes.TabIndex = 1;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
label3.AutoSize = true;
|
||||
label3.Location = new Point(33, 76);
|
||||
label3.Margin = new Padding(2, 0, 2, 0);
|
||||
label3.Name = "label3";
|
||||
label3.Size = new Size(43, 15);
|
||||
label3.TabIndex = 2;
|
||||
label3.Text = "Смена";
|
||||
//
|
||||
// comboBoxShift
|
||||
//
|
||||
comboBoxShift.FormattingEnabled = true;
|
||||
comboBoxShift.Location = new Point(157, 80);
|
||||
comboBoxShift.Margin = new Padding(2, 1, 2, 1);
|
||||
comboBoxShift.Name = "comboBoxShift";
|
||||
comboBoxShift.Size = new Size(132, 23);
|
||||
comboBoxShift.TabIndex = 8;
|
||||
//
|
||||
// ColumnRoute
|
||||
//
|
||||
ColumnRoute.FillWeight = 92.25092F;
|
||||
ColumnRoute.HeaderText = "Маршрут";
|
||||
ColumnRoute.MinimumWidth = 6;
|
||||
ColumnRoute.Name = "ColumnRoute";
|
||||
ColumnRoute.Width = 125;
|
||||
//
|
||||
// ColumnEndPoint
|
||||
// ColumnFuelInit
|
||||
//
|
||||
ColumnEndPoint.HeaderText = "Конечная точка";
|
||||
ColumnEndPoint.MinimumWidth = 6;
|
||||
ColumnEndPoint.Name = "ColumnEndPoint";
|
||||
ColumnEndPoint.Width = 125;
|
||||
ColumnFuelInit.FillWeight = 107.749069F;
|
||||
ColumnFuelInit.HeaderText = "Изначальное кол-во топлива";
|
||||
ColumnFuelInit.MinimumWidth = 6;
|
||||
ColumnFuelInit.Name = "ColumnFuelInit";
|
||||
//
|
||||
// FormTrip
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(843, 745);
|
||||
ClientSize = new Size(454, 349);
|
||||
Controls.Add(groupBox);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonTripSave);
|
||||
@ -232,6 +248,7 @@
|
||||
Controls.Add(label3);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Margin = new Padding(2, 1, 2, 1);
|
||||
Name = "FormTrip";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "FormTrip";
|
||||
@ -246,13 +263,11 @@
|
||||
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private Label label3;
|
||||
private Label label4;
|
||||
private Label label5;
|
||||
private Label label6;
|
||||
private DateTimePicker dateTimePickerStartDate;
|
||||
private DateTimePicker dateTimePickerEndDate;
|
||||
private ComboBox comboBoxShift;
|
||||
private NumericUpDown numericUpDownConsumptionRate;
|
||||
private ComboBox comboBoxCarID;
|
||||
private ComboBox comboBoxDriverID;
|
||||
@ -260,7 +275,9 @@
|
||||
private Button buttonCancel;
|
||||
private GroupBox groupBox;
|
||||
private DataGridView dataGridViewRoutes;
|
||||
private Label label3;
|
||||
private ComboBox comboBoxShift;
|
||||
private DataGridViewComboBoxColumn ColumnRoute;
|
||||
private DataGridViewTextBoxColumn ColumnEndPoint;
|
||||
private DataGridViewTextBoxColumn ColumnFuelInit;
|
||||
}
|
||||
}
|
@ -11,14 +11,13 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectFuel.Repositories.Implementations;
|
||||
using ProjectFuel.Entities;
|
||||
|
||||
namespace ProjectFuel.Forms_
|
||||
{
|
||||
public partial class FormTrip : Form
|
||||
{
|
||||
private readonly ITripRepository _tripRepository;
|
||||
|
||||
|
||||
|
||||
public FormTrip(ITripRepository tripRepository, ICarRepository carRepository, IDriverRepository driverRepository, IRouteRepository routeRepository)
|
||||
{
|
||||
@ -38,7 +37,7 @@ namespace ProjectFuel.Forms_
|
||||
ColumnRoute.DisplayMember = "Start_Point";
|
||||
ColumnRoute.ValueMember = "Route_ID";
|
||||
|
||||
|
||||
comboBoxShift.DataSource = Enum.GetValues(typeof(Shift));
|
||||
|
||||
}
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
@ -60,18 +59,18 @@ namespace ProjectFuel.Forms_
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||
private List<Trip_Route> CreateListDriversFromDataGrid()
|
||||
private List<TripRoute> CreateListDriversFromDataGrid()
|
||||
{
|
||||
var list = new List<Trip_Route>();
|
||||
var list = new List<TripRoute>();
|
||||
foreach (DataGridViewRow row in dataGridViewRoutes.Rows)
|
||||
{
|
||||
if (row.Cells["ColumnRoute"].Value == null)
|
||||
if (row.Cells["ColumnRoute"].Value == null || row.Cells["ColumnFuelInit"].Value == null)
|
||||
continue;
|
||||
|
||||
list.Add(Trip_Route.CreateElement(0, Convert.ToInt32(row.Cells["ColumnRoute"].Value)));
|
||||
list.Add(TripRoute.CreateOperation(0, Convert.ToInt32(row.Cells["ColumnRoute"].Value), Convert.ToInt32(row.Cells["ColumnFuelInit"].Value)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Unity.Microsoft.Logging;
|
||||
using FuelAndLubricants.Repositories.Implementations;
|
||||
|
||||
|
||||
namespace ProjectFuel
|
||||
{
|
||||
|
@ -48,10 +48,10 @@ public class TableReport
|
||||
private List<string[]> GetData(int carId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var refills = _refillRepository
|
||||
.ReadRefills(dateFrom: startDate, dateTo: endDate, carId: carId)
|
||||
.ReadRefills()
|
||||
.Where(x => x.Refill_Date >= startDate && x.Refill_Date <= endDate && x.Car_ID == 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(dateFrom: startDate, dateTo: endDate, carId: carId)
|
||||
.ReadTrips()
|
||||
.Where(x => x.Start_Date >= startDate && x.End_Date <= endDate && x.Car_ID == carId)
|
||||
.Select(x => new
|
||||
{
|
||||
x.CarName,
|
||||
CarId = x.Car_ID,
|
||||
Date = x.Start_Date,
|
||||
RefillAmount = (float?)null,
|
||||
@ -96,4 +96,4 @@ public class TableReport
|
||||
)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -9,4 +9,4 @@ namespace ProjectFuel.Repositories;
|
||||
public class ConnectionString : IConnectionString
|
||||
{
|
||||
string IConnectionString.ConnectionString => "Server=localhost, 5432;Username=postgres;Password=postgres;Database=";
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
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);
|
||||
IEnumerable<Trip> ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? carId = null, int? driverId = null, int? routeId = null);
|
||||
|
||||
void CreateTrip(Trip trip);
|
||||
}
|
||||
|
@ -1,13 +1,11 @@
|
||||
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 FuelAndLubricants.Repositories.Implementations;
|
||||
namespace ProjectFuel.Repositories.Implementations;
|
||||
|
||||
public class TripRepository : ITripRepository
|
||||
{
|
||||
@ -20,7 +18,6 @@ public class TripRepository : ITripRepository
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateTrip(Trip trip)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
@ -37,14 +34,15 @@ public class TripRepository : ITripRepository
|
||||
SELECT MAX(Trip_ID) FROM Trip";
|
||||
var tripId = connection.QueryFirst<int>(queryInsert, trip, transaction);
|
||||
var querySubInsert = @"
|
||||
INSERT INTO Trip_Route (Trip_ID, Route_ID)
|
||||
VALUES (@tripId, @Route_ID)";
|
||||
INSERT INTO Trip_Route (Trip_ID, Route_ID, Fuel_Init)
|
||||
VALUES (@tripId, @Route_ID, @Fuel_Init)";
|
||||
foreach (var elem in trip.Routes)
|
||||
{
|
||||
connection.Execute(querySubInsert, new
|
||||
{
|
||||
tripId,
|
||||
elem.Route_ID
|
||||
elem.Route_ID,
|
||||
elem.Fuel_Init
|
||||
}, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
@ -56,57 +54,18 @@ public class TripRepository : ITripRepository
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Trip> ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? carId = null, int? driverId = null)
|
||||
|
||||
public IEnumerable<Trip> ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? carId = null, int? driverId = null, int? routeId = 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
|
||||
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 });
|
||||
var querySelect = "SELECT * FROM Trip";
|
||||
var trips = connection.Query<Trip>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(trips));
|
||||
return tripDict.Select(x =>
|
||||
{
|
||||
var t = trips.First(y => y.Trip_ID == x.Key);
|
||||
t.SetTrips(x.Value);
|
||||
return t;
|
||||
}).ToList();
|
||||
return trips;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -114,4 +73,4 @@ public class TripRepository : ITripRepository
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user