лаб 3 полностью готовая

This commit is contained in:
Anya 2025-01-31 11:12:39 +04:00
parent 8885033aab
commit 50dfcd1c51
6 changed files with 106 additions and 85 deletions

View File

@ -15,5 +15,5 @@ public enum Driver_License
C = 4,
D = 8,
BE = 16,
CE = 32
CE = 32,
}

View File

@ -1,5 +1,4 @@
using ProjectFuel.Entities.Enums;
using ProjectFuel.Entities;
namespace ProjectFuel.Entities;
@ -12,9 +11,9 @@ public class Trip
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 IEnumerable<TripRoute> 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<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
{
@ -28,4 +27,4 @@ public class Trip
Routes = routes
};
}
}
}

View File

@ -6,17 +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 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
};
}
}

View File

@ -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,107 +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.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;
@ -162,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;
@ -173,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 = "Маршруты";
@ -184,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);
@ -231,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";
@ -245,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;
@ -259,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;
}
}

View File

@ -17,7 +17,7 @@ namespace ProjectFuel.Forms_
public partial class FormTrip : Form
{
private readonly ITripRepository _tripRepository;
public FormTrip(ITripRepository tripRepository, ICarRepository carRepository, IDriverRepository driverRepository, IRouteRepository routeRepository)
{
@ -25,11 +25,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";
@ -37,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)
@ -59,18 +59,18 @@ namespace ProjectFuel.Forms_
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private List<Route> CreateListDriversFromDataGrid()
private List<TripRoute> CreateListDriversFromDataGrid()
{
var list = new List<Route>();
var list = new List<TripRoute>();
foreach (DataGridViewRow row in dataGridViewRoutes.Rows)
{
if (row.Cells["ColumnRoute"].Value == null || row.Cells["ColumnEndPoint"].Value == null)
if (row.Cells["ColumnRoute"].Value == null || row.Cells["ColumnFuelInit"].Value == null)
continue;
list.Add(Route.CreateEntity(0, (string)row.Cells["ColumnRoute"].Value, (string)row.Cells["ColumnEndPoint"].Value, 0));
list.Add(TripRoute.CreateOperation(0, Convert.ToInt32(row.Cells["ColumnRoute"].Value), Convert.ToInt32(row.Cells["ColumnFuelInit"].Value)));
}
return list;
}
}
}
}

View File

@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectFuel.Entities;
using ProjectFuel.Entities;
using ProjectFuel.Repositories;
namespace ProjectFuel.Repositories.Implementations;
@ -34,14 +35,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();
@ -52,7 +54,7 @@ public class TripRepository : ITripRepository
throw;
}
}
public IEnumerable<Trip> ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? carId = null, int? driverId = null, int? routeId = null)
{
@ -72,4 +74,4 @@ public class TripRepository : ITripRepository
throw;
}
}
}
}