From 72c22e7e7abc26b3f05c5f822ce83f127f4ea94c Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Fri, 29 Nov 2024 16:20:48 +0400 Subject: [PATCH 01/10] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=20DriverRepository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FuelAndLubricants.csproj | 19 ++++ .../FuelAndLubricants/Program.cs | 21 ++++ .../Repositories/IConnectionString.cs | 6 ++ .../Implementations/CarRepository.cs | 16 ++- .../Implementations/ConnectionString.cs | 12 +++ .../Implementations/DriverRepository.cs | 98 ++++++++++++++++++- .../FuelAndLubricants/appsettings.json | 15 +++ 7 files changed, 183 insertions(+), 4 deletions(-) create mode 100644 FuelAndLubricants/FuelAndLubricants/Repositories/IConnectionString.cs create mode 100644 FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/ConnectionString.cs create mode 100644 FuelAndLubricants/FuelAndLubricants/appsettings.json diff --git a/FuelAndLubricants/FuelAndLubricants/FuelAndLubricants.csproj b/FuelAndLubricants/FuelAndLubricants/FuelAndLubricants.csproj index accbdf0..f568e1b 100644 --- a/FuelAndLubricants/FuelAndLubricants/FuelAndLubricants.csproj +++ b/FuelAndLubricants/FuelAndLubricants/FuelAndLubricants.csproj @@ -9,7 +9,20 @@ + + + + + + + + + + + + + @@ -27,4 +40,10 @@ + + + PreserveNewest + + + \ No newline at end of file diff --git a/FuelAndLubricants/FuelAndLubricants/Program.cs b/FuelAndLubricants/FuelAndLubricants/Program.cs index 5ab9ffd..8e12d8d 100644 --- a/FuelAndLubricants/FuelAndLubricants/Program.cs +++ b/FuelAndLubricants/FuelAndLubricants/Program.cs @@ -1,6 +1,10 @@ using FuelAndLubricants.Repositories; using FuelAndLubricants.Repositories.Implementations; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Serilog; using Unity; +using Unity.Microsoft.Logging; namespace FuelAndLubricants { @@ -21,6 +25,9 @@ namespace FuelAndLubricants private static UnityContainer CreateContainer() { var container = new UnityContainer(); + + container.AddExtension(new LoggingExtension(CreateLoggerFactory())); + container.RegisterType(); container.RegisterType(); @@ -28,8 +35,22 @@ namespace FuelAndLubricants container.RegisterType(); container.RegisterType(); container.RegisterType(); + container.RegisterType(); return container; } + + private static LoggerFactory CreateLoggerFactory() + { + var loggerFactory = new LoggerFactory(); + loggerFactory.AddSerilog(new LoggerConfiguration() + .ReadFrom.Configuration(new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json") + .Build()) + .CreateLogger()); + return loggerFactory; + } + } } \ No newline at end of file diff --git a/FuelAndLubricants/FuelAndLubricants/Repositories/IConnectionString.cs b/FuelAndLubricants/FuelAndLubricants/Repositories/IConnectionString.cs new file mode 100644 index 0000000..cc87de5 --- /dev/null +++ b/FuelAndLubricants/FuelAndLubricants/Repositories/IConnectionString.cs @@ -0,0 +1,6 @@ +namespace FuelAndLubricants.Repositories; + +public interface IConnectionString +{ + public string ConnectionString { get; } +} diff --git a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/CarRepository.cs b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/CarRepository.cs index 5759289..e8dccae 100644 --- a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/CarRepository.cs +++ b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/CarRepository.cs @@ -1,9 +1,23 @@ -using FuelAndLubricants.Entities; +using System.Data.SqlClient; +using Dapper; +using FuelAndLubricants.Entities; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; namespace FuelAndLubricants.Repositories.Implementations; public class CarRepository : ICarRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public CarRepository (IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateCar(Car car) { } diff --git a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/ConnectionString.cs b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/ConnectionString.cs new file mode 100644 index 0000000..0d2c8d5 --- /dev/null +++ b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/ConnectionString.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FuelAndLubricants.Repositories.Implementations; + +public class ConnectionString : IConnectionString +{ + string IConnectionString.ConnectionString => "Host=localhost;Port=5432;Username=postgres;Password=postgres;Database=postgres"; +} diff --git a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/DriverRepository.cs b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/DriverRepository.cs index 7194bc2..72936ce 100644 --- a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/DriverRepository.cs +++ b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/DriverRepository.cs @@ -1,28 +1,120 @@ -using FuelAndLubricants.Entities; +using Dapper; +using FuelAndLubricants.Entities; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; namespace FuelAndLubricants.Repositories.Implementations; public class DriverRepository : IDriverRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public DriverRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateDriver(Driver driver) { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(driver)); + + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @"INSERT INTO Driver (Firstname, Secondname, Driver_License) +VALUES (@Firstname, @Secondname, @Driver_License)"; + connection.Execute(queryInsert, driver); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } public void DeleteDriver(int id) { + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" + DELETE FROM Driver + WHERE Driver_ID=@Driver_ID"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } public Driver ReadDriverByID(int id) { - return Driver.CreateEntity(0, string.Empty, string.Empty, 0); + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" + SELECT * FROM Driver + WHERE Driver_ID=@Driver_ID"; + var driver = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(driver)); + return driver; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } public IEnumerable ReadDrivers() { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Driver"; + var drivers = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(drivers)); + return drivers; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } public void UpdateDriver(Driver driver) { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(driver)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" + UPDATE Driver + SET + Firstname=@Firstname, + Secondname=@Secondname, + Driver_License=@Driver_License + WHERE Driver_ID=@Driver_ID"; + connection.Execute(queryUpdate, driver); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } } } diff --git a/FuelAndLubricants/FuelAndLubricants/appsettings.json b/FuelAndLubricants/FuelAndLubricants/appsettings.json new file mode 100644 index 0000000..51b6135 --- /dev/null +++ b/FuelAndLubricants/FuelAndLubricants/appsettings.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/fuel_log.txt", + "rollingInterval": "Day" + } + } + ] + } +} \ No newline at end of file -- 2.25.1 From 861e71522851512bd4e77091f9b32e15261fae41 Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Mon, 2 Dec 2024 17:49:06 +0400 Subject: [PATCH 02/10] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=87=D0=B8?= =?UTF-8?q?=D0=B5=20Routes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implementations/ConnectionString.cs | 2 +- .../Implementations/RouteRepository.cs | 99 ++++++++++++++++++- 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/ConnectionString.cs b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/ConnectionString.cs index 0d2c8d5..c78633d 100644 --- a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/ConnectionString.cs +++ b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/ConnectionString.cs @@ -8,5 +8,5 @@ namespace FuelAndLubricants.Repositories.Implementations; 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=1111;Database=otplabs"; } diff --git a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/RouteRepository.cs b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/RouteRepository.cs index cc9e08e..d56faa3 100644 --- a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/RouteRepository.cs +++ b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/RouteRepository.cs @@ -1,28 +1,121 @@ -using FuelAndLubricants.Entities; +using Dapper; +using FuelAndLubricants.Entities; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; namespace FuelAndLubricants.Repositories.Implementations; public class RouteRepository : IRouteRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public RouteRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + 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 (Start_Point, End_Point, Route_Length) +VALUES (@Start_Point, @End_Point, @Route_Length)"; + connection.Execute(queryInsert, route); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } 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 Route_ID=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } public Route ReadRouteByID(int id) { - return Route.CreateEntity(0, string.Empty, string.Empty, 0); + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" + SELECT * FROM Route + WHERE Route_ID=@id"; + var route = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(route)); + return route; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } public IEnumerable ReadRoutes() { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Route"; + var routes = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(routes)); + return routes; + } + 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 + Start_Point=@Start_Point, + End_Point=@End_Point, + Route_Length=@Route_Length + WHERE Route_ID=@Route_ID"; + connection.Execute(queryUpdate, route); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } } } -- 2.25.1 From 597a48c8469716e9a437baf97931ac08522fdc56 Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Mon, 2 Dec 2024 17:54:51 +0400 Subject: [PATCH 03/10] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=87=D0=B8?= =?UTF-8?q?=D0=B9=20Driver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/Implementations/DriverRepository.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/DriverRepository.cs b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/DriverRepository.cs index 72936ce..d9cee75 100644 --- a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/DriverRepository.cs +++ b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/DriverRepository.cs @@ -46,7 +46,7 @@ VALUES (@Firstname, @Secondname, @Driver_License)"; using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var queryDelete = @" DELETE FROM Driver - WHERE Driver_ID=@Driver_ID"; + WHERE Driver_ID=@id"; connection.Execute(queryDelete, new { id }); } catch (Exception ex) @@ -65,7 +65,7 @@ VALUES (@Firstname, @Secondname, @Driver_License)"; using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var querySelect = @" SELECT * FROM Driver - WHERE Driver_ID=@Driver_ID"; + WHERE Driver_ID=@id"; var driver = connection.QueryFirst(querySelect, new { id }); _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(driver)); return driver; -- 2.25.1 From 39d93173d31d7797c336e34c5b5c075acb1a3b91 Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Mon, 2 Dec 2024 18:08:18 +0400 Subject: [PATCH 04/10] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=87=D0=B5?= =?UTF-8?q?=D0=B5=20Fuel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/FormFuel.Designer.cs | 1 + .../Implementations/FuelRepository.cs | 99 ++++++++++++++++++- 2 files changed, 97 insertions(+), 3 deletions(-) diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs index 607abe8..68ec4b5 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs @@ -120,6 +120,7 @@ numericUpDownAmount.DecimalPlaces = 2; numericUpDownAmount.Location = new Point(120, 89); numericUpDownAmount.Margin = new Padding(3, 4, 3, 4); + numericUpDownAmount.Maximum = new decimal(new int[] { 10000, 0, 0, 0 }); numericUpDownAmount.Minimum = new decimal(new int[] { 1, 0, 0, 131072 }); numericUpDownAmount.Name = "numericUpDownAmount"; numericUpDownAmount.Size = new Size(160, 27); diff --git a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/FuelRepository.cs b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/FuelRepository.cs index 54b793b..f045eff 100644 --- a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/FuelRepository.cs +++ b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/FuelRepository.cs @@ -1,28 +1,121 @@ -using FuelAndLubricants.Entities; +using Dapper; +using FuelAndLubricants.Entities; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; namespace FuelAndLubricants.Repositories.Implementations; public class FuelRepository : IFuelRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public FuelRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateFuel(Fuel_And_Lubricants fuel) { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(fuel)); + + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @"INSERT INTO Fuel_And_Lubricants (Fuel_Type, Price_Per_Liter, Amount) +VALUES (@Fuel_Type, @Price_Per_Liter, @Amount)"; + connection.Execute(queryInsert, fuel); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } + public void DeleteFuel(int id) { + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" + DELETE FROM Fuel_And_Lubricants + WHERE Fuel_ID=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } public Fuel_And_Lubricants ReadFuelByID(int id) { - return Fuel_And_Lubricants.CreateEntity(0, 0, 0, 0); + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" + SELECT * FROM Fuel_And_Lubricants + WHERE Fuel_ID=@id"; + var fuel = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(fuel)); + return fuel; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } public IEnumerable ReadFuels() { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Fuel_And_Lubricants"; + var fuels = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(fuels)); + return fuels; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } public void UpdateFuel(Fuel_And_Lubricants fuel) { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(fuel)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" + UPDATE Fuel_And_Lubricants + SET + Fuel_Type=@Fuel_Type, + Price_Per_Liter=@Price_Per_Liter, + Amount=@Amount + WHERE Fuel_ID=@Fuel_ID"; + connection.Execute(queryUpdate, fuel); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } } } -- 2.25.1 From 5c7e3cc936a35f731aa7ea28784c55ce24b8d438 Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Mon, 2 Dec 2024 18:21:11 +0400 Subject: [PATCH 05/10] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=87=D0=B0?= =?UTF-8?q?=D1=8F=20Car?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implementations/CarRepository.cs | 85 ++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/CarRepository.cs b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/CarRepository.cs index e8dccae..e6aab44 100644 --- a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/CarRepository.cs +++ b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/CarRepository.cs @@ -3,6 +3,7 @@ using Dapper; using FuelAndLubricants.Entities; using Microsoft.Extensions.Logging; using Newtonsoft.Json; +using Npgsql; namespace FuelAndLubricants.Repositories.Implementations; @@ -20,23 +21,103 @@ public class CarRepository : ICarRepository public void CreateCar(Car car) { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(car)); + + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @"INSERT INTO Car (Car_Mark, Car_Model, Car_Type, License, Consumption_Rate) +VALUES (@Car_Mark, @Car_Model, @Car_Type, @License, @Consumption_Rate)"; + connection.Execute(queryInsert, car); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } public void DeleteCar(int id) { + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" + DELETE FROM Car + WHERE Car_ID=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } public Car ReadCarByID(int id) { - return Car.CreateEntity(0, string.Empty, string.Empty, 0, 0, 0); + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" + SELECT * FROM Car + WHERE Car_ID=@id"; + var car = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(car)); + return car; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } public IEnumerable ReadCars() { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Car"; + var cars = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(cars)); + return cars; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } public void UpdateCar(Car car) { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(car)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" + UPDATE Car + SET + Car_Mark=@Car_Mark, + Car_Model=@Car_Model, + Car_Type=@Car_Type, + License=@License, + Consumption_Rate=@Consumption_Rate + WHERE Car_ID=@Car_ID"; + connection.Execute(queryUpdate, car); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } } } -- 2.25.1 From ae1b0dce468e93f58daed32f17ca309f742980ae Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Tue, 3 Dec 2024 18:47:24 +0400 Subject: [PATCH 06/10] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=87=D0=B0?= =?UTF-8?q?=D1=8F=20Refill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implementations/RefillRepository.cs | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/RefillRepository.cs b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/RefillRepository.cs index 719e34c..c87c00d 100644 --- a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/RefillRepository.cs +++ b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/RefillRepository.cs @@ -1,15 +1,55 @@ -using FuelAndLubricants.Entities; +using Dapper; +using FuelAndLubricants.Entities; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; namespace FuelAndLubricants.Repositories.Implementations; public class RefillRepository : IRefillRepository { + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + public RefillRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateRefill(Refill refill) { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(refill)); + + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @"INSERT INTO Refill (Refill_Date, Refill_Amount, Fuel_ID, Car_ID) +VALUES (@Refill_Date, @Refill_Amount, @Fuel_ID, @Car_ID)"; + connection.Execute(queryInsert, refill); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } public IEnumerable ReadRefills(DateTime? dateFrom = null, DateTime? dateTo = null, int? fuelId = null, int? carId = null) { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Refill"; + var refills = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(refills)); + return refills; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } -- 2.25.1 From bdd0edb4123e9acd0ddc1b6df4ba9bd9c241409a Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Wed, 4 Dec 2024 14:24:32 +0400 Subject: [PATCH 07/10] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20=D0=9B=D0=A02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FuelAndLubricants/Entities/Route.cs | 2 + .../FuelAndLubricants/Entities/Trip.cs | 4 +- .../FuelAndLubricants/Entities/Trip_Route.cs | 22 +++++++ .../Forms/FormTrip.Designer.cs | 16 ++--- .../FuelAndLubricants/Forms/FormTrip.cs | 36 ++++++++--- .../FuelAndLubricants/Forms/FormTrip.resx | 8 +-- .../Implementations/TripRepository.cs | 63 ++++++++++++++++++- 7 files changed, 124 insertions(+), 27 deletions(-) create mode 100644 FuelAndLubricants/FuelAndLubricants/Entities/Trip_Route.cs diff --git a/FuelAndLubricants/FuelAndLubricants/Entities/Route.cs b/FuelAndLubricants/FuelAndLubricants/Entities/Route.cs index 3087552..3ee6f75 100644 --- a/FuelAndLubricants/FuelAndLubricants/Entities/Route.cs +++ b/FuelAndLubricants/FuelAndLubricants/Entities/Route.cs @@ -7,6 +7,8 @@ public class Route public string End_Point { get; private set; } = string.Empty; public float Route_Length { get; private set; } + public string fullRoute => $"{Start_Point} {End_Point}"; + public static Route CreateEntity (int route_id, string start_point, string end_point, float length) { return new Route diff --git a/FuelAndLubricants/FuelAndLubricants/Entities/Trip.cs b/FuelAndLubricants/FuelAndLubricants/Entities/Trip.cs index 83e9614..b38c32b 100644 --- a/FuelAndLubricants/FuelAndLubricants/Entities/Trip.cs +++ b/FuelAndLubricants/FuelAndLubricants/Entities/Trip.cs @@ -11,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 Routes { get; private set; } = []; + public IEnumerable 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 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 routes) { return new Trip { diff --git a/FuelAndLubricants/FuelAndLubricants/Entities/Trip_Route.cs b/FuelAndLubricants/FuelAndLubricants/Entities/Trip_Route.cs new file mode 100644 index 0000000..4165896 --- /dev/null +++ b/FuelAndLubricants/FuelAndLubricants/Entities/Trip_Route.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FuelAndLubricants.Entities; + +public class Trip_Route +{ + public int Trip_ID { get; private set; } + public int Route_ID { get; private set; } + + public static Trip_Route CreateElement(int trip_id, int route_id) + { + return new Trip_Route + { + Trip_ID = trip_id, + Route_ID = route_id + }; + } +} diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs index c51394e..2851a7c 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs @@ -45,7 +45,7 @@ groupBox = new GroupBox(); dataGridViewRoutes = new DataGridView(); ColumnRoute = new DataGridViewComboBoxColumn(); - ColumnEndPoint = new DataGridViewTextBoxColumn(); + ColumnRouteLength = new DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).BeginInit(); groupBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).BeginInit(); @@ -209,7 +209,7 @@ dataGridViewRoutes.AllowUserToResizeColumns = false; dataGridViewRoutes.AllowUserToResizeRows = false; dataGridViewRoutes.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewRoutes.Columns.AddRange(new DataGridViewColumn[] { ColumnRoute, ColumnEndPoint }); + dataGridViewRoutes.Columns.AddRange(new DataGridViewColumn[] { ColumnRoute, ColumnRouteLength }); dataGridViewRoutes.Dock = DockStyle.Fill; dataGridViewRoutes.Location = new Point(3, 23); dataGridViewRoutes.MultiSelect = false; @@ -227,12 +227,12 @@ ColumnRoute.Name = "ColumnRoute"; ColumnRoute.Width = 125; // - // ColumnEndPoint + // ColumnRouteLength // - ColumnEndPoint.HeaderText = "Конечная точка"; - ColumnEndPoint.MinimumWidth = 6; - ColumnEndPoint.Name = "ColumnEndPoint"; - ColumnEndPoint.Width = 125; + ColumnRouteLength.HeaderText = "Длина"; + ColumnRouteLength.MinimumWidth = 6; + ColumnRouteLength.Name = "ColumnRouteLength"; + ColumnRouteLength.Width = 125; // // FormTrip // @@ -284,6 +284,6 @@ private GroupBox groupBox; private DataGridView dataGridViewRoutes; private DataGridViewComboBoxColumn ColumnRoute; - private DataGridViewTextBoxColumn ColumnEndPoint; + private DataGridViewTextBoxColumn ColumnRouteLength; } } \ No newline at end of file diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs index 62913dc..bacd894 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs @@ -15,17 +15,19 @@ namespace FuelAndLubricants.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"; ColumnRoute.DataSource = routeRepository.ReadRoutes(); - ColumnRoute.DisplayMember = "Start_Point"; + ColumnRoute.DisplayMember = "fullRoute"; ColumnRoute.ValueMember = "Route_ID"; + + comboBoxShift.DataSource = Enum.GetValues(typeof(Shift)); } private void ButtonSave_Click(object sender, EventArgs e) { @@ -45,18 +47,36 @@ namespace FuelAndLubricants.Forms } private void ButtonCancel_Click(object sender, EventArgs e) => Close(); - private List CreateListDriversFromDataGrid() + private List CreateListDriversFromDataGrid() { - var list = new List(); + var list = new List(); 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["ColumnRouteLength"].Value == null) continue; - list.Add(Route.CreateEntity(0, (string)row.Cells["ColumnRoute"].Value, (string)row.Cells["ColumnEndPoint"].Value, 0)); + //string columnFullRoute = ""; + //foreach (var elem in (List)ColumnRoute.DataSource) + //{ + // if(elem.Route_ID == (int)row.Cells["ColumnRoute"].Value) + // { + // columnFullRoute = elem.fullRoute; + // break; + // } + //} + + //string[] parts = columnFullRoute.Split(' '); + + //string part1 = parts.Length > 0 ? parts[0] : string.Empty; // Берём первую часть, если есть + //string part2 = parts.Length > 1 ? parts[1] : string.Empty; // Берём вторую часть, если есть + + //string cellValue = row.Cells["ColumnRouteLength"].Value?.ToString(); + //float length = float.Parse(cellValue); + + list.Add(Trip_Route.CreateElement(0, Convert.ToInt32(row.Cells["ColumnRoute"].Value))); + //list.Add(Route.CreateEntity(0, part1, part2, length)); } return list; } - } } diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.resx b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.resx index f557e1d..c487f49 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.resx +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.resx @@ -120,13 +120,7 @@ True - - True - - - True - - + True \ No newline at end of file diff --git a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/TripRepository.cs b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/TripRepository.cs index 9cd8e6f..68a7acf 100644 --- a/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/TripRepository.cs +++ b/FuelAndLubricants/FuelAndLubricants/Repositories/Implementations/TripRepository.cs @@ -1,15 +1,74 @@ -using FuelAndLubricants.Entities; +using Dapper; +using FuelAndLubricants.Entities; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; namespace FuelAndLubricants.Repositories.Implementations; public class TripRepository : ITripRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public TripRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateTrip(Trip trip) { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(trip)); + + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + connection.Open(); + using var transaction = connection.BeginTransaction(); + var queryInsert = @" + INSERT INTO Trip (Start_Date, End_Date, Shift, Fuel_Consumption, Car_ID, Driver_ID) + VALUES (@Start_Date, @End_Date, @Shift, @Fuel_Consumption, @Car_ID, @Driver_ID); + SELECT MAX(Trip_ID) FROM Trip"; + var tripId = connection.QueryFirst(queryInsert, trip, transaction); + var querySubInsert = @" + INSERT INTO Trip_Route (Trip_ID, Route_ID) + VALUES (@tripId, @Route_ID)"; + foreach (var elem in trip.Routes) + { + connection.Execute(querySubInsert, new + { + tripId, + elem.Route_ID + }, transaction); + } + transaction.Commit(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } public IEnumerable ReadTrips(DateTime? dateFrom = null, DateTime? dateTo = null, int? carId = null, int? driverId = null, int? routeId = null) { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Trip"; + var trips = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(trips)); + return trips; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } -- 2.25.1 From d315bb4ef88c130d8cf4bdac5e681995158b2ad7 Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Wed, 4 Dec 2024 14:53:47 +0400 Subject: [PATCH 08/10] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=20=D0=9B=D0=A02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FuelAndLubricants/Forms/FormCar.Designer.cs | 1 + .../FuelAndLubricants/Forms/FormFuel.Designer.cs | 1 + .../FuelAndLubricants/Forms/FormRefill.Designer.cs | 1 + .../FuelAndLubricants/Forms/FormRoute.Designer.cs | 1 + .../FuelAndLubricants/Forms/FormTrip.Designer.cs | 11 +---------- FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs | 2 +- .../FuelAndLubricants/Forms/FormTrip.resx | 3 --- 7 files changed, 6 insertions(+), 14 deletions(-) diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormCar.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormCar.Designer.cs index a17b551..855f7e4 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormCar.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormCar.Designer.cs @@ -148,6 +148,7 @@ numericUpDownConsumptionRate.DecimalPlaces = 2; numericUpDownConsumptionRate.Location = new Point(122, 263); numericUpDownConsumptionRate.Margin = new Padding(3, 4, 3, 4); + numericUpDownConsumptionRate.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); numericUpDownConsumptionRate.Minimum = new decimal(new int[] { 1, 0, 0, 131072 }); numericUpDownConsumptionRate.Name = "numericUpDownConsumptionRate"; numericUpDownConsumptionRate.Size = new Size(160, 27); diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs index 68ec4b5..35f1d4d 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs @@ -55,6 +55,7 @@ numericUpDownPrice.DecimalPlaces = 2; numericUpDownPrice.Location = new Point(120, 51); numericUpDownPrice.Margin = new Padding(3, 4, 3, 4); + numericUpDownPrice.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); numericUpDownPrice.Minimum = new decimal(new int[] { 1, 0, 0, 131072 }); numericUpDownPrice.Name = "numericUpDownPrice"; numericUpDownPrice.Size = new Size(160, 27); diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormRefill.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormRefill.Designer.cs index 2ba153e..f2169a1 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormRefill.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormRefill.Designer.cs @@ -107,6 +107,7 @@ numericUpDownRefillAmount.DecimalPlaces = 2; numericUpDownRefillAmount.Location = new Point(125, 52); numericUpDownRefillAmount.Margin = new Padding(3, 4, 3, 4); + numericUpDownRefillAmount.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); numericUpDownRefillAmount.Minimum = new decimal(new int[] { 1, 0, 0, 131072 }); numericUpDownRefillAmount.Name = "numericUpDownRefillAmount"; numericUpDownRefillAmount.Size = new Size(160, 27); diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormRoute.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormRoute.Designer.cs index ac63bb4..0b38288 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormRoute.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormRoute.Designer.cs @@ -54,6 +54,7 @@ numericUpDownLength.DecimalPlaces = 2; numericUpDownLength.Location = new Point(134, 91); numericUpDownLength.Margin = new Padding(3, 4, 3, 4); + numericUpDownLength.Maximum = new decimal(new int[] { 10000, 0, 0, 0 }); numericUpDownLength.Minimum = new decimal(new int[] { 1, 0, 0, 131072 }); numericUpDownLength.Name = "numericUpDownLength"; numericUpDownLength.Size = new Size(160, 27); diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs index 2851a7c..b2bc027 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs @@ -45,7 +45,6 @@ groupBox = new GroupBox(); dataGridViewRoutes = new DataGridView(); ColumnRoute = new DataGridViewComboBoxColumn(); - ColumnRouteLength = new DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).BeginInit(); groupBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).BeginInit(); @@ -209,7 +208,7 @@ dataGridViewRoutes.AllowUserToResizeColumns = false; dataGridViewRoutes.AllowUserToResizeRows = false; dataGridViewRoutes.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewRoutes.Columns.AddRange(new DataGridViewColumn[] { ColumnRoute, ColumnRouteLength }); + dataGridViewRoutes.Columns.AddRange(new DataGridViewColumn[] { ColumnRoute }); dataGridViewRoutes.Dock = DockStyle.Fill; dataGridViewRoutes.Location = new Point(3, 23); dataGridViewRoutes.MultiSelect = false; @@ -227,13 +226,6 @@ ColumnRoute.Name = "ColumnRoute"; ColumnRoute.Width = 125; // - // ColumnRouteLength - // - ColumnRouteLength.HeaderText = "Длина"; - ColumnRouteLength.MinimumWidth = 6; - ColumnRouteLength.Name = "ColumnRouteLength"; - ColumnRouteLength.Width = 125; - // // FormTrip // AutoScaleDimensions = new SizeF(8F, 20F); @@ -284,6 +276,5 @@ private GroupBox groupBox; private DataGridView dataGridViewRoutes; private DataGridViewComboBoxColumn ColumnRoute; - private DataGridViewTextBoxColumn ColumnRouteLength; } } \ No newline at end of file diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs index bacd894..562f87d 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs @@ -52,7 +52,7 @@ namespace FuelAndLubricants.Forms var list = new List(); foreach (DataGridViewRow row in dataGridViewRoutes.Rows) { - if (row.Cells["ColumnRoute"].Value == null || row.Cells["ColumnRouteLength"].Value == null) + if (row.Cells["ColumnRoute"].Value == null) continue; //string columnFullRoute = ""; diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.resx b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.resx index c487f49..411cc3c 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.resx +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.resx @@ -120,7 +120,4 @@ True - - True - \ No newline at end of file -- 2.25.1 From 00f691332ba150eb45a4954af738a2aa4aa60ad2 Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Sat, 7 Dec 2024 15:02:50 +0400 Subject: [PATCH 09/10] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D1=87=D0=B8=D1=89?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FuelAndLubricants/Forms/FormTrip.cs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs index 562f87d..9866707 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.cs @@ -55,26 +55,7 @@ namespace FuelAndLubricants.Forms if (row.Cells["ColumnRoute"].Value == null) continue; - //string columnFullRoute = ""; - //foreach (var elem in (List)ColumnRoute.DataSource) - //{ - // if(elem.Route_ID == (int)row.Cells["ColumnRoute"].Value) - // { - // columnFullRoute = elem.fullRoute; - // break; - // } - //} - - //string[] parts = columnFullRoute.Split(' '); - - //string part1 = parts.Length > 0 ? parts[0] : string.Empty; // Берём первую часть, если есть - //string part2 = parts.Length > 1 ? parts[1] : string.Empty; // Берём вторую часть, если есть - - //string cellValue = row.Cells["ColumnRouteLength"].Value?.ToString(); - //float length = float.Parse(cellValue); - list.Add(Trip_Route.CreateElement(0, Convert.ToInt32(row.Cells["ColumnRoute"].Value))); - //list.Add(Route.CreateEntity(0, part1, part2, length)); } return list; } -- 2.25.1 From cf2a8389140bf0f0d1eb33c365d3abab91a96fd3 Mon Sep 17 00:00:00 2001 From: F1rsTTeaM Date: Wed, 18 Dec 2024 13:47:35 +0400 Subject: [PATCH 10/10] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FuelAndLubricants/FuelAndLubricants/Forms/FormCar.Designer.cs | 2 +- FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs | 2 +- .../FuelAndLubricants/Forms/FormRefill.Designer.cs | 2 +- FuelAndLubricants/FuelAndLubricants/Forms/FormRoute.Designer.cs | 2 +- .../FuelAndLubricants/Forms/FormRoutes.Designer.cs | 2 +- FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormCar.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormCar.Designer.cs index 855f7e4..b1fb5eb 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormCar.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormCar.Designer.cs @@ -184,7 +184,7 @@ Margin = new Padding(3, 4, 3, 4); Name = "FormCar"; StartPosition = FormStartPosition.CenterParent; - Text = "FormCar"; + Text = "Машина"; ((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).EndInit(); ResumeLayout(false); PerformLayout(); diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs index 35f1d4d..5b4c24d 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormFuel.Designer.cs @@ -144,7 +144,7 @@ Margin = new Padding(3, 4, 3, 4); Name = "FormFuel"; StartPosition = FormStartPosition.CenterParent; - Text = "FormFuel"; + Text = "Топливо"; ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownAmount).EndInit(); ResumeLayout(false); diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormRefill.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormRefill.Designer.cs index f2169a1..0ad2a3b 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormRefill.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormRefill.Designer.cs @@ -163,7 +163,7 @@ Margin = new Padding(3, 4, 3, 4); Name = "FormRefill"; StartPosition = FormStartPosition.CenterParent; - Text = "FormRefill"; + Text = "Заправка"; ((System.ComponentModel.ISupportInitialize)numericUpDownRefillAmount).EndInit(); ResumeLayout(false); PerformLayout(); diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormRoute.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormRoute.Designer.cs index 0b38288..bc81e17 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormRoute.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormRoute.Designer.cs @@ -137,7 +137,7 @@ Margin = new Padding(3, 4, 3, 4); Name = "FormRoute"; StartPosition = FormStartPosition.CenterParent; - Text = "FormRoute"; + Text = "Маршрут"; ((System.ComponentModel.ISupportInitialize)numericUpDownLength).EndInit(); ResumeLayout(false); PerformLayout(); diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormRoutes.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormRoutes.Designer.cs index 1a91e18..27bb056 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormRoutes.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormRoutes.Designer.cs @@ -115,7 +115,7 @@ Margin = new Padding(3, 4, 3, 4); Name = "FormRoutes"; StartPosition = FormStartPosition.CenterParent; - Text = "FormRoutes"; + Text = "Маршруты"; Load += FormRoutes_Load; panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); diff --git a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs index b2bc027..3c87c88 100644 --- a/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs +++ b/FuelAndLubricants/FuelAndLubricants/Forms/FormTrip.Designer.cs @@ -249,7 +249,7 @@ Margin = new Padding(3, 4, 3, 4); Name = "FormTrip"; StartPosition = FormStartPosition.CenterParent; - Text = "FormTrip"; + Text = "Поездка"; ((System.ComponentModel.ISupportInitialize)numericUpDownConsumptionRate).EndInit(); groupBox.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).EndInit(); -- 2.25.1