почти все

This commit is contained in:
Baryshev Dmitry 2024-12-03 23:06:20 +04:00
parent bd528d9f0d
commit d243c03fc8
21 changed files with 458 additions and 120 deletions

View File

@ -11,9 +11,9 @@ public class Driver
{ {
public int Id { get;private set; } public int Id { get;private set; }
public string First_name { get;private set; } = string.Empty; public string Fname { get;private set; } = string.Empty;
public string Last_name { get;private set; } = string.Empty; public string Lname { get;private set; } = string.Empty;
public int TruckId { get;private set; } public int TruckId { get;private set; }
@ -22,8 +22,8 @@ public class Driver
return new Driver return new Driver
{ {
Id = id, Id = id,
First_name = fname, Fname = fname,
Last_name = lname, Lname = lname,
TruckId = tryckid TruckId = tryckid
}; };
} }

View File

@ -13,6 +13,7 @@ namespace ProjectGarage.Entities.Enums
SCANIA = 2, SCANIA = 2,
KAMAZ = 3, KAMAZ = 3,
MAN = 4, MAN = 4,
Volvo = 5 Volvo = 5,
SITRAC = 6
} }
} }

View File

@ -12,9 +12,9 @@ public class Fuel
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = string.Empty; public string FuelName { get; set; } = string.Empty;
public FuelType Type { get; set; } public FuelType FuelType { get; set; }
public int Price { get; set; } public int Price { get; set; }
@ -23,8 +23,8 @@ public class Fuel
return new Fuel return new Fuel
{ {
Id = id, Id = id,
Name = name, FuelName = name,
Type = type, FuelType = type,
Price = price Price = price
}; };
} }

View File

@ -10,21 +10,21 @@ public class Route
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = string.Empty; public string RouteName { get; set; } = string.Empty;
public string StartPoint { get; set; } = string.Empty; public string StartP { get; set; } = string.Empty;
public string FinalPoint { get; set; } = string.Empty; public string FinalP { get; set; } = string.Empty;
public int Length { get; set; } public int Length { get; set; }
public static Route CreateRoute(int id, string startp, string finalp, int len) public static Route CreateRoute(int id,string name, string startp, string finalp, int len)
{ {
return new Route() { return new Route() {
Id = id, Id = id,
Name = startp + " - " + finalp, RouteName = name,
StartPoint = startp, StartP = startp,
FinalPoint = finalp, FinalP = finalp,
Length = len Length = len
}; };
} }

View File

@ -13,7 +13,7 @@ public class Truck
public string Numbers { get; private set; } = string.Empty; public string Numbers { get; private set; } = string.Empty;
public TruckType Type { get; set; } public TruckType Truck_Type { get; set; }
public int MaxFuel { get; private set; } public int MaxFuel { get; private set; }
@ -23,7 +23,7 @@ public class Truck
{ {
Id = id, Id = id,
Numbers = numbers, Numbers = numbers,
Type = type, Truck_Type = type,
MaxFuel = maxFuel MaxFuel = maxFuel
}; };
} }

View File

@ -32,8 +32,6 @@
textBoxFirstName = new TextBox(); textBoxFirstName = new TextBox();
textBoxLastName = new TextBox(); textBoxLastName = new TextBox();
labelLastName = new Label(); labelLastName = new Label();
textBoxPhoneNum = new TextBox();
labelPhoneNum = new Label();
labelTruckID = new Label(); labelTruckID = new Label();
buttonSaveDriver = new Button(); buttonSaveDriver = new Button();
buttonCancelDriver = new Button(); buttonCancelDriver = new Button();
@ -72,27 +70,10 @@
labelLastName.TabIndex = 2; labelLastName.TabIndex = 2;
labelLastName.Text = "Фамилия"; labelLastName.Text = "Фамилия";
// //
// textBoxPhoneNum
//
textBoxPhoneNum.Location = new Point(120, 115);
textBoxPhoneNum.Name = "textBoxPhoneNum";
textBoxPhoneNum.Size = new Size(183, 27);
textBoxPhoneNum.TabIndex = 5;
textBoxPhoneNum.Text = "+7";
//
// labelPhoneNum
//
labelPhoneNum.AutoSize = true;
labelPhoneNum.Location = new Point(20, 118);
labelPhoneNum.Name = "labelPhoneNum";
labelPhoneNum.Size = new Size(69, 20);
labelPhoneNum.TabIndex = 4;
labelPhoneNum.Text = "Телефон";
//
// labelTruckID // labelTruckID
// //
labelTruckID.AutoSize = true; labelTruckID.AutoSize = true;
labelTruckID.Location = new Point(34, 164); labelTruckID.Location = new Point(34, 121);
labelTruckID.Name = "labelTruckID"; labelTruckID.Name = "labelTruckID";
labelTruckID.Size = new Size(44, 20); labelTruckID.Size = new Size(44, 20);
labelTruckID.TabIndex = 6; labelTruckID.TabIndex = 6;
@ -100,7 +81,7 @@
// //
// buttonSaveDriver // buttonSaveDriver
// //
buttonSaveDriver.Location = new Point(20, 231); buttonSaveDriver.Location = new Point(20, 158);
buttonSaveDriver.Name = "buttonSaveDriver"; buttonSaveDriver.Name = "buttonSaveDriver";
buttonSaveDriver.Size = new Size(128, 39); buttonSaveDriver.Size = new Size(128, 39);
buttonSaveDriver.TabIndex = 8; buttonSaveDriver.TabIndex = 8;
@ -110,7 +91,7 @@
// //
// buttonCancelDriver // buttonCancelDriver
// //
buttonCancelDriver.Location = new Point(175, 231); buttonCancelDriver.Location = new Point(175, 158);
buttonCancelDriver.Name = "buttonCancelDriver"; buttonCancelDriver.Name = "buttonCancelDriver";
buttonCancelDriver.Size = new Size(128, 39); buttonCancelDriver.Size = new Size(128, 39);
buttonCancelDriver.TabIndex = 9; buttonCancelDriver.TabIndex = 9;
@ -122,7 +103,7 @@
// //
comboBoxTruckID.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxTruckID.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxTruckID.FormattingEnabled = true; comboBoxTruckID.FormattingEnabled = true;
comboBoxTruckID.Location = new Point(120, 156); comboBoxTruckID.Location = new Point(120, 113);
comboBoxTruckID.Name = "comboBoxTruckID"; comboBoxTruckID.Name = "comboBoxTruckID";
comboBoxTruckID.Size = new Size(183, 28); comboBoxTruckID.Size = new Size(183, 28);
comboBoxTruckID.TabIndex = 10; comboBoxTruckID.TabIndex = 10;
@ -131,13 +112,11 @@
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(333, 302); ClientSize = new Size(333, 218);
Controls.Add(comboBoxTruckID); Controls.Add(comboBoxTruckID);
Controls.Add(buttonCancelDriver); Controls.Add(buttonCancelDriver);
Controls.Add(buttonSaveDriver); Controls.Add(buttonSaveDriver);
Controls.Add(labelTruckID); Controls.Add(labelTruckID);
Controls.Add(textBoxPhoneNum);
Controls.Add(labelPhoneNum);
Controls.Add(textBoxLastName); Controls.Add(textBoxLastName);
Controls.Add(labelLastName); Controls.Add(labelLastName);
Controls.Add(textBoxFirstName); Controls.Add(textBoxFirstName);
@ -155,8 +134,6 @@
private TextBox textBoxFirstName; private TextBox textBoxFirstName;
private TextBox textBoxLastName; private TextBox textBoxLastName;
private Label labelLastName; private Label labelLastName;
private TextBox textBoxPhoneNum;
private Label labelPhoneNum;
private Label labelTruckID; private Label labelTruckID;
private Button buttonSaveDriver; private Button buttonSaveDriver;
private Button buttonCancelDriver; private Button buttonCancelDriver;

View File

@ -24,15 +24,14 @@ namespace ProjectGarage.Forms
{ {
try try
{ {
var driver = _driverRepository.ReadDriverByID(value); var driver = _driverRepository.ReadDriverByID(value);
if (driver == null) if (driver == null)
{ {
throw new throw new
InvalidDataException(nameof(driver)); InvalidDataException(nameof(driver));
} }
textBoxFirstName.Text = driver.First_name; textBoxFirstName.Text = driver.Fname;
textBoxLastName.Text = driver.Last_name; textBoxLastName.Text = driver.Lname;
//comboBoxTruckID.SelectedItem = driver.TruckId; //comboBoxTruckID.SelectedItem = driver.TruckId;
_driverId = value; _driverId = value;
} }
@ -48,7 +47,7 @@ namespace ProjectGarage.Forms
{ {
InitializeComponent(); InitializeComponent();
_driverRepository = driverRepository ?? throw new ArgumentNullException(nameof(driverRepository)); _driverRepository = driverRepository ?? throw new ArgumentNullException(nameof(driverRepository));
comboBoxTruckID.DataSource = truckRepository.ReadTrucks();// comboBoxTruckID.DataSource = truckRepository.ReadTrucks();
comboBoxTruckID.DisplayMember = "Numbers"; comboBoxTruckID.DisplayMember = "Numbers";
comboBoxTruckID.ValueMember = "Id"; comboBoxTruckID.ValueMember = "Id";
} }
@ -58,7 +57,7 @@ namespace ProjectGarage.Forms
try try
{ {
if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || string.IsNullOrWhiteSpace(textBoxLastName.Text) if (string.IsNullOrWhiteSpace(textBoxFirstName.Text) || string.IsNullOrWhiteSpace(textBoxLastName.Text)
|| comboBoxTruckID.SelectedIndex < 0)// || comboBoxTruckID.SelectedIndex < 0)
{ {
throw new Exception("Имеются незаполненные поля"); throw new Exception("Имеются незаполненные поля");
} }
@ -82,6 +81,6 @@ namespace ProjectGarage.Forms
private void ButtonCancelDriver_Click(object sender, EventArgs e) => Close(); private void ButtonCancelDriver_Click(object sender, EventArgs e) => Close();
private Driver CreateDriver(int id) => Driver.CreateDriver(id, textBoxFirstName.Text, private Driver CreateDriver(int id) => Driver.CreateDriver(id, textBoxFirstName.Text,
textBoxLastName.Text, (int)comboBoxTruckID.SelectedIndex!);// textBoxLastName.Text, (int)comboBoxTruckID.SelectedIndex!);
} }
} }

View File

@ -33,12 +33,12 @@ namespace ProjectGarage.Forms
} }
foreach (FuelType elem in Enum.GetValues(typeof(FuelType))) foreach (FuelType elem in Enum.GetValues(typeof(FuelType)))
{ {
if ((elem & fuel.Type) != 0) if ((elem & fuel.FuelType) != 0)
{ {
checkedListBoxFuel.SetItemChecked(checkedListBoxFuel.Items.IndexOf(elem), true); checkedListBoxFuel.SetItemChecked(checkedListBoxFuel.Items.IndexOf(elem), true);
} }
} }
textBoxFuelName.Text = fuel.Name; textBoxFuelName.Text = fuel.FuelName;
_fuelId = value; _fuelId = value;
} }
catch (Exception ex) catch (Exception ex)

View File

@ -36,13 +36,15 @@
buttonRouteFinal = new Button(); buttonRouteFinal = new Button();
textBoxRouteStart = new TextBox(); textBoxRouteStart = new TextBox();
textBoxRouteFinal = new TextBox(); textBoxRouteFinal = new TextBox();
textBoxRouteName = new TextBox();
labelRouteName = new Label();
((System.ComponentModel.ISupportInitialize)numericUpDownRouteLen).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownRouteLen).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// labelRouteStart // labelRouteStart
// //
labelRouteStart.AutoSize = true; labelRouteStart.AutoSize = true;
labelRouteStart.Location = new Point(12, 20); labelRouteStart.Location = new Point(22, 62);
labelRouteStart.Name = "labelRouteStart"; labelRouteStart.Name = "labelRouteStart";
labelRouteStart.Size = new Size(135, 20); labelRouteStart.Size = new Size(135, 20);
labelRouteStart.TabIndex = 0; labelRouteStart.TabIndex = 0;
@ -51,7 +53,7 @@
// labelRouteFinal // labelRouteFinal
// //
labelRouteFinal.AutoSize = true; labelRouteFinal.AutoSize = true;
labelRouteFinal.Location = new Point(12, 62); labelRouteFinal.Location = new Point(22, 104);
labelRouteFinal.Name = "labelRouteFinal"; labelRouteFinal.Name = "labelRouteFinal";
labelRouteFinal.Size = new Size(127, 20); labelRouteFinal.Size = new Size(127, 20);
labelRouteFinal.TabIndex = 1; labelRouteFinal.TabIndex = 1;
@ -59,7 +61,8 @@
// //
// numericUpDownRouteLen // numericUpDownRouteLen
// //
numericUpDownRouteLen.Location = new Point(160, 103); numericUpDownRouteLen.Location = new Point(170, 145);
numericUpDownRouteLen.Maximum = new decimal(new int[] { 10000, 0, 0, 0 });
numericUpDownRouteLen.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); numericUpDownRouteLen.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
numericUpDownRouteLen.Name = "numericUpDownRouteLen"; numericUpDownRouteLen.Name = "numericUpDownRouteLen";
numericUpDownRouteLen.Size = new Size(150, 27); numericUpDownRouteLen.Size = new Size(150, 27);
@ -69,7 +72,7 @@
// labelRouteLen // labelRouteLen
// //
labelRouteLen.AutoSize = true; labelRouteLen.AutoSize = true;
labelRouteLen.Location = new Point(12, 103); labelRouteLen.Location = new Point(22, 145);
labelRouteLen.Name = "labelRouteLen"; labelRouteLen.Name = "labelRouteLen";
labelRouteLen.Size = new Size(127, 20); labelRouteLen.Size = new Size(127, 20);
labelRouteLen.TabIndex = 3; labelRouteLen.TabIndex = 3;
@ -77,7 +80,7 @@
// //
// buttonRouteSave // buttonRouteSave
// //
buttonRouteSave.Location = new Point(12, 149); buttonRouteSave.Location = new Point(22, 191);
buttonRouteSave.Name = "buttonRouteSave"; buttonRouteSave.Name = "buttonRouteSave";
buttonRouteSave.Size = new Size(135, 29); buttonRouteSave.Size = new Size(135, 29);
buttonRouteSave.TabIndex = 4; buttonRouteSave.TabIndex = 4;
@ -87,7 +90,7 @@
// //
// buttonRouteFinal // buttonRouteFinal
// //
buttonRouteFinal.Location = new Point(160, 149); buttonRouteFinal.Location = new Point(170, 191);
buttonRouteFinal.Name = "buttonRouteFinal"; buttonRouteFinal.Name = "buttonRouteFinal";
buttonRouteFinal.Size = new Size(150, 29); buttonRouteFinal.Size = new Size(150, 29);
buttonRouteFinal.TabIndex = 5; buttonRouteFinal.TabIndex = 5;
@ -97,23 +100,41 @@
// //
// textBoxRouteStart // textBoxRouteStart
// //
textBoxRouteStart.Location = new Point(160, 20); textBoxRouteStart.Location = new Point(170, 62);
textBoxRouteStart.Name = "textBoxRouteStart"; textBoxRouteStart.Name = "textBoxRouteStart";
textBoxRouteStart.Size = new Size(150, 27); textBoxRouteStart.Size = new Size(150, 27);
textBoxRouteStart.TabIndex = 6; textBoxRouteStart.TabIndex = 6;
// //
// textBoxRouteFinal // textBoxRouteFinal
// //
textBoxRouteFinal.Location = new Point(160, 62); textBoxRouteFinal.Location = new Point(170, 104);
textBoxRouteFinal.Name = "textBoxRouteFinal"; textBoxRouteFinal.Name = "textBoxRouteFinal";
textBoxRouteFinal.Size = new Size(150, 27); textBoxRouteFinal.Size = new Size(150, 27);
textBoxRouteFinal.TabIndex = 7; textBoxRouteFinal.TabIndex = 7;
// //
// textBoxRouteName
//
textBoxRouteName.Location = new Point(179, 12);
textBoxRouteName.Name = "textBoxRouteName";
textBoxRouteName.Size = new Size(141, 27);
textBoxRouteName.TabIndex = 9;
//
// labelRouteName
//
labelRouteName.AutoSize = true;
labelRouteName.Location = new Point(22, 19);
labelRouteName.Name = "labelRouteName";
labelRouteName.Size = new Size(151, 20);
labelRouteName.TabIndex = 8;
labelRouteName.Text = "Название маршрута";
//
// FormRoute // FormRoute
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(332, 199); ClientSize = new Size(332, 240);
Controls.Add(textBoxRouteName);
Controls.Add(labelRouteName);
Controls.Add(textBoxRouteFinal); Controls.Add(textBoxRouteFinal);
Controls.Add(textBoxRouteStart); Controls.Add(textBoxRouteStart);
Controls.Add(buttonRouteFinal); Controls.Add(buttonRouteFinal);
@ -139,5 +160,7 @@
private Button buttonRouteFinal; private Button buttonRouteFinal;
private TextBox textBoxRouteStart; private TextBox textBoxRouteStart;
private TextBox textBoxRouteFinal; private TextBox textBoxRouteFinal;
private TextBox textBoxRouteName;
private Label labelRouteName;
} }
} }

View File

@ -31,8 +31,8 @@ namespace ProjectGarage.Forms
throw new InvalidDataException(nameof(route)); throw new InvalidDataException(nameof(route));
} }
textBoxRouteStart.Text = route.StartPoint; textBoxRouteStart.Text = route.StartP;
textBoxRouteFinal.Text = route.FinalPoint; textBoxRouteFinal.Text = route.FinalP;
numericUpDownRouteLen.Value = route.Length; numericUpDownRouteLen.Value = route.Length;
_routeId = value; _routeId = value;
} }
@ -79,7 +79,7 @@ namespace ProjectGarage.Forms
private void ButtonRouteFinal_Click(object sender, EventArgs e) => Close(); private void ButtonRouteFinal_Click(object sender, EventArgs e) => Close();
private Route CreateRoute(int id) => Route.CreateRoute(id, textBoxRouteStart.Text, private Route CreateRoute(int id) => Route.CreateRoute(id, textBoxRouteName.Text, textBoxRouteStart.Text,
textBoxRouteFinal.Text, Convert.ToInt32(numericUpDownRouteLen.Value)); textBoxRouteFinal.Text, Convert.ToInt32(numericUpDownRouteLen.Value));
} }
} }

View File

@ -25,15 +25,15 @@ namespace ProjectGarage.Forms
throw new ArgumentNullException(nameof(transportationRepository)); throw new ArgumentNullException(nameof(transportationRepository));
comboBoxDriver.DataSource = driverRepository.ReadDrivers(); comboBoxDriver.DataSource = driverRepository.ReadDrivers();
comboBoxDriver.DisplayMember = "First_name"; comboBoxDriver.DisplayMember = "Fname";
comboBoxDriver.ValueMember = "Id"; comboBoxDriver.ValueMember = "Id";
comboBoxFuel.DataSource = fuelRepository.ReadFuels(); comboBoxFuel.DataSource = fuelRepository.ReadFuels();
comboBoxFuel.DisplayMember = "Name"; comboBoxFuel.DisplayMember = "FuelName";
comboBoxFuel.ValueMember = "Id"; comboBoxFuel.ValueMember = "Id";
comboBoxRoute.DataSource = routeRepository.ReadRoute(); comboBoxRoute.DataSource = routeRepository.ReadRoute();
comboBoxRoute.DisplayMember = "Name"; comboBoxRoute.DisplayMember = "RouteName";
comboBoxRoute.ValueMember = "Id"; comboBoxRoute.ValueMember = "Id";
} }

View File

@ -61,14 +61,14 @@
dataGridViewTransportations.RowHeadersVisible = false; dataGridViewTransportations.RowHeadersVisible = false;
dataGridViewTransportations.RowHeadersWidth = 51; dataGridViewTransportations.RowHeadersWidth = 51;
dataGridViewTransportations.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewTransportations.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewTransportations.Size = new Size(639, 450); dataGridViewTransportations.Size = new Size(847, 450);
dataGridViewTransportations.TabIndex = 7; dataGridViewTransportations.TabIndex = 7;
// //
// panelFormTransportationsButtons // panelFormTransportationsButtons
// //
panelFormTransportationsButtons.Controls.Add(buttonAddTransportation); panelFormTransportationsButtons.Controls.Add(buttonAddTransportation);
panelFormTransportationsButtons.Dock = DockStyle.Right; panelFormTransportationsButtons.Dock = DockStyle.Right;
panelFormTransportationsButtons.Location = new Point(639, 0); panelFormTransportationsButtons.Location = new Point(847, 0);
panelFormTransportationsButtons.Name = "panelFormTransportationsButtons"; panelFormTransportationsButtons.Name = "panelFormTransportationsButtons";
panelFormTransportationsButtons.Size = new Size(161, 450); panelFormTransportationsButtons.Size = new Size(161, 450);
panelFormTransportationsButtons.TabIndex = 6; panelFormTransportationsButtons.TabIndex = 6;
@ -77,7 +77,7 @@
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(1008, 450);
Controls.Add(dataGridViewTransportations); Controls.Add(dataGridViewTransportations);
Controls.Add(panelFormTransportationsButtons); Controls.Add(panelFormTransportationsButtons);
Name = "FormTransportations"; Name = "FormTransportations";

View File

@ -76,6 +76,7 @@
// numericUpDownMaxFuel // numericUpDownMaxFuel
// //
numericUpDownMaxFuel.Location = new Point(158, 115); numericUpDownMaxFuel.Location = new Point(158, 115);
numericUpDownMaxFuel.Maximum = new decimal(new int[] { 3000, 0, 0, 0 });
numericUpDownMaxFuel.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); numericUpDownMaxFuel.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
numericUpDownMaxFuel.Name = "numericUpDownMaxFuel"; numericUpDownMaxFuel.Name = "numericUpDownMaxFuel";
numericUpDownMaxFuel.Size = new Size(183, 27); numericUpDownMaxFuel.Size = new Size(183, 27);

View File

@ -22,7 +22,7 @@ namespace ProjectGarage.Forms
} }
textBoxTruckNumbers.Text = truck.Numbers; textBoxTruckNumbers.Text = truck.Numbers;
comboBoxTruckType.SelectedItem = truck.Type; comboBoxTruckType.SelectedItem = truck.Truck_Type;
numericUpDownMaxFuel.Value = truck.MaxFuel; numericUpDownMaxFuel.Value = truck.MaxFuel;
_truckId = value; _truckId = value;
} }

View File

@ -12,6 +12,4 @@ public interface ITransportationRepository
IEnumerable<Transportation> ReadTransportation(DateTime? dateForm = null, DateTime? dateTo = null, int? fuelId = null, IEnumerable<Transportation> ReadTransportation(DateTime? dateForm = null, DateTime? dateTo = null, int? fuelId = null,
int? driverId = null, int? routeId = null); int? driverId = null, int? routeId = null);
void CreateTransportation(Transportation transportation); void CreateTransportation(Transportation transportation);
void DeleteTransportation(int id);
} }

View File

@ -8,5 +8,5 @@ namespace ProjectGarage.Repositories.Implementations;
public class ConnectionString : IConnectionString public class ConnectionString : IConnectionString
{ {
string IConnectionString.ConnectionString => "Host=localhost;Port=5432;Username=postgres;Password=postgres;Database=postgres"; string IConnectionString.ConnectionString => "Host=localhost;Port=5432;Username=postgres;Password=postgres;Database=garage";
} }

View File

@ -32,10 +32,9 @@ public class DriverRepository : IDriverRepository
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open();
var queryInsert = @" var queryInsert = @"
INSERT INTO driver (driver_fname, driver_lname, id_truck) VALUES INSERT INTO driver (Fname, Lname, TruckId) VALUES
(@First_name, @Last_name, @TruckID);"; (@Fname, @Lname, @TruckId);";
connection.Execute(queryInsert, driver); connection.Execute(queryInsert, driver);
} }
catch (Exception ex) catch (Exception ex)
@ -56,10 +55,10 @@ INSERT INTO driver (driver_fname, driver_lname, id_truck) VALUES
var queryUpdate = @" var queryUpdate = @"
UPDATE driver UPDATE driver
SET SET
driver_fname=@First_name, Fname=@Fname,
driver_lname=@Last_name, Lname=@Lname,
id_truck=@TruckID TruckId=@TruckId
WHERE id_driver=@Id"; WHERE Id=@Id";
connection.Execute(queryUpdate, driver); connection.Execute(queryUpdate, driver);
} }
catch (Exception ex) catch (Exception ex)
@ -69,18 +68,18 @@ WHERE id_driver=@Id";
} }
} }
public void DeleteDriver(int driverId) public void DeleteDriver(int id)
{ {
_logger.LogInformation("Удаление объекта"); _logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", driverId); _logger.LogDebug("Объект: {id}", id);
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @" var queryDelete = @"
DELETE FROM driver DELETE FROM driver
WHERE id_driver=@driverId"; WHERE Id=@id";
connection.Execute(queryDelete, new { driverId }); connection.Execute(queryDelete, new { id });
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -89,18 +88,18 @@ WHERE id_driver=@driverId";
} }
} }
public Driver ReadDriverByID(int driverId) public Driver ReadDriverByID(int id)
{ {
_logger.LogInformation("Получение объекта по идентификатору"); _logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", driverId); _logger.LogDebug("Объект: {id}", id);
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @" var querySelect = @"
SELECT * FROM driver SELECT * FROM driver
WHERE id_driver=@driverId"; WHERE Id=@id";
var driver = connection.QueryFirst<Driver>(querySelect, new { driverId }); var driver = connection.QueryFirst<Driver>(querySelect, new { id });
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(driver)); _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(driver));
return driver; return driver;

View File

@ -1,4 +1,8 @@
using ProjectGarage.Entities; using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectGarage.Entities;
using ProjectGarage.Entities.Enums; using ProjectGarage.Entities.Enums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -10,19 +14,116 @@ namespace ProjectGarage.Repositories.Implementations;
public class FuelRepository : IFuelRepository public class FuelRepository : IFuelRepository
{ {
public readonly IConnectionString _connectionString;
private readonly ILogger<FuelRepository> _logger;
public FuelRepository(IConnectionString connectionString, ILogger<FuelRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateFuel(Fuel fuel) public void CreateFuel(Fuel fuel)
{ {
_logger.LogInformation("Добавление объект");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(fuel));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO fuel (FuelName, FuelType, Price) VALUES
(@FuelName, @FuelType, @Price);";
connection.Execute(queryInsert, fuel);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void UpdateFuel(Fuel fuel)
{
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(fuel));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE fuel
SET
FuelName=@FuelName,
FuelType=@Startp,
Price=@Price
WHERE Id=@Id";
connection.Execute(queryUpdate, fuel);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
} }
public void DeleteFuel(int id) public void DeleteFuel(int id)
{ {
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM fuel
WHERE Id=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
} }
public Fuel ReadFuelByID(int id) => Fuel.CreateFuel(0, string.Empty, FuelType.None, 0); public Fuel ReadFuelByID(int id)
public IEnumerable<Fuel> ReadFuels() => [];
public void UpdateFuel(Fuel fuel)
{ {
_logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM fuel
WHERE Id=@id";
var fuel = connection.QueryFirst<Fuel>(querySelect, new { id });
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(fuel));
return fuel;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
}
public IEnumerable<Fuel> ReadFuels()
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM fuel";
var fuels = connection.Query<Fuel>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(fuels));
return fuels;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
} }
} }

View File

@ -1,4 +1,8 @@
using ProjectGarage.Entities; using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectGarage.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -9,26 +13,117 @@ namespace ProjectGarage.Repositories.Implementations;
public class RouteRepository : IRouteRepository public class RouteRepository : IRouteRepository
{ {
public void CreateFuelReplenishment(FuelReplenishment fuelReplenishment) public readonly IConnectionString _connectionString;
{
}
private readonly ILogger<RouteRepository> _logger;
public RouteRepository(IConnectionString connectionString, ILogger<RouteRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateRoute(Route route) public void CreateRoute(Route route)
{ {
_logger.LogInformation("Добавление объект");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(route));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO route (RouteName, Startp, Finalp, Length) VALUES
(@RouteName, @Startp, @Finalp, @Length);";
connection.Execute(queryInsert, route);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void UpdateRoute(Route route)
{
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(route));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE route
SET
RouteName=@RouteName,
Startp=@Startp,
Finalp=@Finalp,
Length=@Length
WHERE Id=@Id";
connection.Execute(queryUpdate, route);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
} }
public void DeleteRoute(int id) public void DeleteRoute(int id)
{ {
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM route
WHERE Id=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
} }
public Route ReadRouteByID(int id) => Route.CreateRoute(0, string.Empty, string.Empty, 0); public Route ReadRouteByID(int id)
{
_logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM route
WHERE Id=@id";
var route = connection.QueryFirst<Route>(querySelect, new { id });
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(route));
return route;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
}
public IEnumerable<Route> ReadRoute(string? startPoint = null, string? finalPoint = null) public IEnumerable<Route> ReadRoute(string? startPoint = null, string? finalPoint = null)
{ {
return []; _logger.LogInformation("Получение всех объектов");
} try
{
public void UpdateRoute(Route route) using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
{ var querySelect = @"SELECT * FROM route";
var routes = connection.Query<Route>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(routes));
return routes;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
} }
} }

View File

@ -1,6 +1,11 @@
using ProjectGarage.Entities; using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectGarage.Entities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -9,17 +14,54 @@ namespace ProjectGarage.Repositories.Implementations;
public class TransportationRepository : ITransportationRepository public class TransportationRepository : ITransportationRepository
{ {
private readonly IConnectionString _connectionString;
private readonly ILogger<TransportationRepository> _logger;
public TransportationRepository(IConnectionString connectionString, ILogger<TransportationRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateTransportation(Transportation transportation) public void CreateTransportation(Transportation transportation)
{ {
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(transportation));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO transportation (DriverId, RouteId, FuelId, Amount, TransportationDate)
VALUES (@DriverId, @RouteId, @FuelId, @Amount, @TransportationDate)";
connection.Execute(queryInsert, transportation);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
} }
public void DeleteTransportation(int id) public IEnumerable<Transportation> ReadTransportation(DateTime? dateForm = null, DateTime? dateTo = null,
int? fuelId = null, int? driverId = null, int? routeId = null)
{ {
throw new NotImplementedException(); _logger.LogInformation("Получение всех объектов");
} try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM transportation";
var transportations = connection.Query<Transportation>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(transportations));
return transportations;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
public IEnumerable<Transportation> ReadTransportation(DateTime? dateForm = null, DateTime? dateTo = null, int? fuelId = null, int? driverId = null, int? routeId = null)
{
return [];
} }
} }

View File

@ -1,4 +1,8 @@
using ProjectGarage.Entities; using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectGarage.Entities;
using ProjectGarage.Entities.Enums; using ProjectGarage.Entities.Enums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -10,19 +14,117 @@ namespace ProjectGarage.Repositories.Implementations;
public class TruckRepository : ITruckRepository public class TruckRepository : ITruckRepository
{ {
public readonly IConnectionString _connectionString;
private readonly ILogger<TruckRepository> _logger;
public TruckRepository(IConnectionString connectionString, ILogger<TruckRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateTruck(Truck truck) public void CreateTruck(Truck truck)
{ {
_logger.LogInformation("Добавление объект");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(truck));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO truck (Numbers, Truck_Type, MaxFuel) VALUES
(@Numbers, @Truck_Type, @MaxFuel);";
connection.Execute(queryInsert, truck);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void UpdateTruck(Truck truck)
{
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}",
JsonConvert.SerializeObject(truck));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE truck
SET
Numbers=@Numbers,
Truck_Type=@Truck_Type,
MaxFuel=@MaxFuel
WHERE Id=@Id";
connection.Execute(queryUpdate, truck);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
} }
public void DeleteTruck(int id) public void DeleteTruck(int id)
{ {
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM truck
WHERE Id=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
} }
public Truck ReadTruckByID(int id) => Truck.CreateTruck(0, string.Empty, TruckType.None, 0); public Truck ReadTruckByID(int id)
public IEnumerable<Truck> ReadTrucks() => [];
public void UpdateTruck(Truck truck)
{ {
_logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM truck
WHERE Id=@id";
var truck = connection.QueryFirst<Truck>(querySelect, new { id });
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(truck));
return truck;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
}
public IEnumerable<Truck> ReadTrucks()
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM truck";
var trucks = connection.Query<Truck>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(trucks));
return trucks;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
} }
} }