лаб 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, C = 4,
D = 8, D = 8,
BE = 16, BE = 16,
CE = 32 CE = 32,
} }

View File

@ -1,5 +1,4 @@
using ProjectFuel.Entities.Enums; using ProjectFuel.Entities.Enums;
using ProjectFuel.Entities;
namespace ProjectFuel.Entities; namespace ProjectFuel.Entities;
@ -12,9 +11,9 @@ public class Trip
public float Fuel_Consumption { get; private set; } public float Fuel_Consumption { get; private set; }
public int Car_ID { get; private set; } public int Car_ID { get; private set; }
public int Driver_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 return new Trip
{ {

View File

@ -6,17 +6,19 @@ using System.Threading.Tasks;
namespace ProjectFuel.Entities; namespace ProjectFuel.Entities;
public class Trip_Route public class TripRoute
{ {
public int Trip_ID { get; private set; } public int Trip_ID { get; private set; }
public int Route_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, Trip_ID = trip_Id,
Route_ID = route_id Route_ID = route_ID,
Fuel_Init = fuel_Init
}; };
} }
} }

View File

@ -30,13 +30,11 @@
{ {
label1 = new Label(); label1 = new Label();
label2 = new Label(); label2 = new Label();
label3 = new Label();
label4 = new Label(); label4 = new Label();
label5 = new Label(); label5 = new Label();
label6 = new Label(); label6 = new Label();
dateTimePickerStartDate = new DateTimePicker(); dateTimePickerStartDate = new DateTimePicker();
dateTimePickerEndDate = new DateTimePicker(); dateTimePickerEndDate = new DateTimePicker();
comboBoxShift = new ComboBox();
numericUpDownConsumptionRate = new NumericUpDown(); numericUpDownConsumptionRate = new NumericUpDown();
comboBoxCarID = new ComboBox(); comboBoxCarID = new ComboBox();
comboBoxDriverID = new ComboBox(); comboBoxDriverID = new ComboBox();
@ -44,8 +42,10 @@
buttonCancel = new Button(); buttonCancel = new Button();
groupBox = new GroupBox(); groupBox = new GroupBox();
dataGridViewRoutes = new DataGridView(); dataGridViewRoutes = new DataGridView();
label3 = new Label();
comboBoxShift = new ComboBox();
ColumnRoute = new DataGridViewComboBoxColumn(); ColumnRoute = new DataGridViewComboBoxColumn();
ColumnEndPoint = new DataGridViewTextBoxColumn(); ColumnFuelInit = new DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).BeginInit();
groupBox.SuspendLayout(); groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).BeginInit();
@ -54,107 +54,101 @@
// label1 // label1
// //
label1.AutoSize = true; 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.Name = "label1";
label1.Size = new Size(149, 32); label1.Size = new Size(74, 15);
label1.TabIndex = 0; label1.TabIndex = 0;
label1.Text = "Дата начала"; label1.Text = "Дата начала";
// //
// label2 // label2
// //
label2.AutoSize = true; 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.Name = "label2";
label2.Size = new Size(138, 32); label2.Size = new Size(68, 15);
label2.TabIndex = 1; label2.TabIndex = 1;
label2.Text = "Дата конца"; 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
// //
label4.AutoSize = true; 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.Name = "label4";
label4.Size = new Size(185, 32); label4.Size = new Size(93, 15);
label4.TabIndex = 3; label4.TabIndex = 3;
label4.Text = "Расход топлива"; label4.Text = "Расход топлива";
// //
// label5 // label5
// //
label5.AutoSize = true; 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.Name = "label5";
label5.Size = new Size(107, 32); label5.Size = new Size(55, 15);
label5.TabIndex = 4; label5.TabIndex = 4;
label5.Text = "Машина"; label5.Text = "Машина";
// //
// label6 // label6
// //
label6.AutoSize = true; 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.Name = "label6";
label6.Size = new Size(117, 32); label6.Size = new Size(58, 15);
label6.TabIndex = 5; label6.TabIndex = 5;
label6.Text = "Водитель"; label6.Text = "Водитель";
// //
// dateTimePickerStartDate // 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.Name = "dateTimePickerStartDate";
dateTimePickerStartDate.Size = new Size(400, 39); dateTimePickerStartDate.Size = new Size(217, 23);
dateTimePickerStartDate.TabIndex = 6; dateTimePickerStartDate.TabIndex = 6;
// //
// dateTimePickerEndDate // 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.Name = "dateTimePickerEndDate";
dateTimePickerEndDate.Size = new Size(400, 39); dateTimePickerEndDate.Size = new Size(217, 23);
dateTimePickerEndDate.TabIndex = 7; 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
// //
numericUpDownConsumptionRate.Location = new Point(288, 232); numericUpDownConsumptionRate.Location = new Point(155, 109);
numericUpDownConsumptionRate.Margin = new Padding(2, 1, 2, 1);
numericUpDownConsumptionRate.Name = "numericUpDownConsumptionRate"; numericUpDownConsumptionRate.Name = "numericUpDownConsumptionRate";
numericUpDownConsumptionRate.Size = new Size(240, 39); numericUpDownConsumptionRate.Size = new Size(129, 23);
numericUpDownConsumptionRate.TabIndex = 9; numericUpDownConsumptionRate.TabIndex = 9;
// //
// comboBoxCarID // comboBoxCarID
// //
comboBoxCarID.FormattingEnabled = true; 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.Name = "comboBoxCarID";
comboBoxCarID.Size = new Size(242, 40); comboBoxCarID.Size = new Size(132, 23);
comboBoxCarID.TabIndex = 10; comboBoxCarID.TabIndex = 10;
// //
// comboBoxDriverID // comboBoxDriverID
// //
comboBoxDriverID.FormattingEnabled = true; 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.Name = "comboBoxDriverID";
comboBoxDriverID.Size = new Size(242, 40); comboBoxDriverID.Size = new Size(132, 23);
comboBoxDriverID.TabIndex = 11; comboBoxDriverID.TabIndex = 11;
// //
// buttonTripSave // 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.Name = "buttonTripSave";
buttonTripSave.Size = new Size(150, 46); buttonTripSave.Size = new Size(81, 22);
buttonTripSave.TabIndex = 14; buttonTripSave.TabIndex = 14;
buttonTripSave.Text = "Сохранить"; buttonTripSave.Text = "Сохранить";
buttonTripSave.UseVisualStyleBackColor = true; buttonTripSave.UseVisualStyleBackColor = true;
@ -162,9 +156,10 @@
// //
// buttonCancel // 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.Name = "buttonCancel";
buttonCancel.Size = new Size(150, 46); buttonCancel.Size = new Size(81, 22);
buttonCancel.TabIndex = 15; buttonCancel.TabIndex = 15;
buttonCancel.Text = "Отмена"; buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
@ -173,9 +168,11 @@
// groupBox // groupBox
// //
groupBox.Controls.Add(dataGridViewRoutes); 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.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.TabIndex = 16;
groupBox.TabStop = false; groupBox.TabStop = false;
groupBox.Text = "Маршруты"; groupBox.Text = "Маршруты";
@ -184,38 +181,58 @@
// //
dataGridViewRoutes.AllowUserToResizeColumns = false; dataGridViewRoutes.AllowUserToResizeColumns = false;
dataGridViewRoutes.AllowUserToResizeRows = false; dataGridViewRoutes.AllowUserToResizeRows = false;
dataGridViewRoutes.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewRoutes.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridViewRoutes.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewRoutes.Columns.AddRange(new DataGridViewColumn[] { ColumnRoute, ColumnEndPoint }); dataGridViewRoutes.Columns.AddRange(new DataGridViewColumn[] { ColumnRoute, ColumnFuelInit });
dataGridViewRoutes.Dock = DockStyle.Fill; dataGridViewRoutes.Dock = DockStyle.Fill;
dataGridViewRoutes.Location = new Point(3, 35); dataGridViewRoutes.Location = new Point(2, 17);
dataGridViewRoutes.Margin = new Padding(5); dataGridViewRoutes.Margin = new Padding(3, 2, 3, 2);
dataGridViewRoutes.MultiSelect = false; dataGridViewRoutes.MultiSelect = false;
dataGridViewRoutes.Name = "dataGridViewRoutes"; dataGridViewRoutes.Name = "dataGridViewRoutes";
dataGridViewRoutes.RowHeadersVisible = false; dataGridViewRoutes.RowHeadersVisible = false;
dataGridViewRoutes.RowHeadersWidth = 51; dataGridViewRoutes.RowHeadersWidth = 51;
dataGridViewRoutes.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewRoutes.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewRoutes.Size = new Size(404, 184); dataGridViewRoutes.Size = new Size(304, 86);
dataGridViewRoutes.TabIndex = 1; 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
// //
ColumnRoute.FillWeight = 92.25092F;
ColumnRoute.HeaderText = "Маршрут"; ColumnRoute.HeaderText = "Маршрут";
ColumnRoute.MinimumWidth = 6; ColumnRoute.MinimumWidth = 6;
ColumnRoute.Name = "ColumnRoute"; ColumnRoute.Name = "ColumnRoute";
ColumnRoute.Width = 125;
// //
// ColumnEndPoint // ColumnFuelInit
// //
ColumnEndPoint.HeaderText = "Конечная точка"; ColumnFuelInit.FillWeight = 107.749069F;
ColumnEndPoint.MinimumWidth = 6; ColumnFuelInit.HeaderText = "Изначальное кол-во топлива";
ColumnEndPoint.Name = "ColumnEndPoint"; ColumnFuelInit.MinimumWidth = 6;
ColumnEndPoint.Width = 125; ColumnFuelInit.Name = "ColumnFuelInit";
// //
// FormTrip // FormTrip
// //
AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(843, 745); ClientSize = new Size(454, 349);
Controls.Add(groupBox); Controls.Add(groupBox);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonTripSave); Controls.Add(buttonTripSave);
@ -231,6 +248,7 @@
Controls.Add(label3); Controls.Add(label3);
Controls.Add(label2); Controls.Add(label2);
Controls.Add(label1); Controls.Add(label1);
Margin = new Padding(2, 1, 2, 1);
Name = "FormTrip"; Name = "FormTrip";
StartPosition = FormStartPosition.CenterParent; StartPosition = FormStartPosition.CenterParent;
Text = "FormTrip"; Text = "FormTrip";
@ -245,13 +263,11 @@
private Label label1; private Label label1;
private Label label2; private Label label2;
private Label label3;
private Label label4; private Label label4;
private Label label5; private Label label5;
private Label label6; private Label label6;
private DateTimePicker dateTimePickerStartDate; private DateTimePicker dateTimePickerStartDate;
private DateTimePicker dateTimePickerEndDate; private DateTimePicker dateTimePickerEndDate;
private ComboBox comboBoxShift;
private NumericUpDown numericUpDownConsumptionRate; private NumericUpDown numericUpDownConsumptionRate;
private ComboBox comboBoxCarID; private ComboBox comboBoxCarID;
private ComboBox comboBoxDriverID; private ComboBox comboBoxDriverID;
@ -259,7 +275,9 @@
private Button buttonCancel; private Button buttonCancel;
private GroupBox groupBox; private GroupBox groupBox;
private DataGridView dataGridViewRoutes; private DataGridView dataGridViewRoutes;
private Label label3;
private ComboBox comboBoxShift;
private DataGridViewComboBoxColumn ColumnRoute; private DataGridViewComboBoxColumn ColumnRoute;
private DataGridViewTextBoxColumn ColumnEndPoint; private DataGridViewTextBoxColumn ColumnFuelInit;
} }
} }

View File

@ -25,11 +25,11 @@ namespace ProjectFuel.Forms_
_tripRepository = tripRepository ?? _tripRepository = tripRepository ??
throw new ArgumentNullException(nameof(tripRepository)); throw new ArgumentNullException(nameof(tripRepository));
comboBoxCarID.DataSource = tripRepository.ReadTrips(); comboBoxCarID.DataSource = carRepository.ReadCars();
comboBoxCarID.DisplayMember = "Car_Mark"; comboBoxCarID.DisplayMember = "Car_Mark";
comboBoxCarID.ValueMember = "Car_ID"; comboBoxCarID.ValueMember = "Car_ID";
comboBoxDriverID.DataSource = tripRepository.ReadTrips(); comboBoxDriverID.DataSource = driverRepository.ReadDrivers();
comboBoxDriverID.DisplayMember = "Firstname"; comboBoxDriverID.DisplayMember = "Firstname";
comboBoxDriverID.ValueMember = "Driver_ID"; comboBoxDriverID.ValueMember = "Driver_ID";
@ -37,7 +37,7 @@ namespace ProjectFuel.Forms_
ColumnRoute.DisplayMember = "Start_Point"; ColumnRoute.DisplayMember = "Start_Point";
ColumnRoute.ValueMember = "Route_ID"; ColumnRoute.ValueMember = "Route_ID";
comboBoxShift.DataSource = Enum.GetValues(typeof(Shift));
} }
private void ButtonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
@ -59,15 +59,15 @@ namespace ProjectFuel.Forms_
} }
private void ButtonCancel_Click(object sender, EventArgs e) => Close(); 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) 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; 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; return list;
} }

View File

@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Npgsql; using Npgsql;
using ProjectFuel.Entities; using ProjectFuel.Entities;
using ProjectFuel.Entities;
using ProjectFuel.Repositories; using ProjectFuel.Repositories;
namespace ProjectFuel.Repositories.Implementations; namespace ProjectFuel.Repositories.Implementations;
@ -34,14 +35,15 @@ public class TripRepository : ITripRepository
SELECT MAX(Trip_ID) FROM Trip"; SELECT MAX(Trip_ID) FROM Trip";
var tripId = connection.QueryFirst<int>(queryInsert, trip, transaction); var tripId = connection.QueryFirst<int>(queryInsert, trip, transaction);
var querySubInsert = @" var querySubInsert = @"
INSERT INTO Trip_Route (Trip_ID, Route_ID) INSERT INTO Trip_Route (Trip_ID, Route_ID, Fuel_Init)
VALUES (@tripId, @Route_ID)"; VALUES (@tripId, @Route_ID, @Fuel_Init)";
foreach (var elem in trip.Routes) foreach (var elem in trip.Routes)
{ {
connection.Execute(querySubInsert, new connection.Execute(querySubInsert, new
{ {
tripId, tripId,
elem.Route_ID elem.Route_ID,
elem.Fuel_Init
}, transaction); }, transaction);
} }
transaction.Commit(); transaction.Commit();