From 85cf278f6251508c4c9fae92f011f9a84f233a1b Mon Sep 17 00:00:00 2001 From: Aidar Date: Thu, 5 Dec 2024 18:29:07 +0400 Subject: [PATCH 1/4] =?UTF-8?q?LabWork=202.0.1=20(=D0=9F=D0=BE=D0=B4=D0=BA?= =?UTF-8?q?=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B8=D0=B1?= =?UTF-8?q?=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/FormBusRepair.Designer.cs | 1 - .../ProjectAutoenterprise/Program.cs | 2 ++ .../ProjectAutoenterprise.csproj | 16 ++++++++++++++++ .../Repositories/IConnectionString.cs | 6 ++++++ .../Implementations/ConnectionString.cs | 6 ++++++ .../Implementations/RouteRepository.cs | 7 +++++++ .../ProjectAutoenterprise/appsettings.json | 15 +++++++++++++++ 7 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 ProjectAutoenterprise/ProjectAutoenterprise/Repositories/IConnectionString.cs create mode 100644 ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ConnectionString.cs create mode 100644 ProjectAutoenterprise/ProjectAutoenterprise/appsettings.json diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBusRepair.Designer.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBusRepair.Designer.cs index 8423dd5..dd7762b 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBusRepair.Designer.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBusRepair.Designer.cs @@ -145,7 +145,6 @@ private Label label1; private Label label2; private Label label3; - private NumericUpDown numericUpDown1; private DateTimePicker dateTimePickerRepairDate; private TextBox textBoxDescription; private Button buttonCancel; diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Program.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Program.cs index 7ddbc3e..dca5fca 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Program.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Program.cs @@ -26,6 +26,8 @@ namespace ProjectAutoenterprise container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); + + container.RegisterType(new TransientLifetimeManager()); return container; } } diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/ProjectAutoenterprise.csproj b/ProjectAutoenterprise/ProjectAutoenterprise/ProjectAutoenterprise.csproj index accbdf0..1de707e 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/ProjectAutoenterprise.csproj +++ b/ProjectAutoenterprise/ProjectAutoenterprise/ProjectAutoenterprise.csproj @@ -9,7 +9,17 @@ + + + + + + + + + + @@ -27,4 +37,10 @@ + + + PreserveNewest + + + \ No newline at end of file diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/IConnectionString.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/IConnectionString.cs new file mode 100644 index 0000000..fe0a905 --- /dev/null +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/IConnectionString.cs @@ -0,0 +1,6 @@ +namespace ProjectAutoenterprise.Repositories; + +internal interface IConnectionString +{ + string ConnectionString { get; } +} \ No newline at end of file diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ConnectionString.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ConnectionString.cs new file mode 100644 index 0000000..15eaea7 --- /dev/null +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ConnectionString.cs @@ -0,0 +1,6 @@ +namespace ProjectAutoenterprise.Repositories.Implementations; + +internal class ConnectionString : IConnectionString +{ + string IConnectionString.ConnectionString => ""; +} \ No newline at end of file diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/RouteRepository.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/RouteRepository.cs index 2a4bb07..242b39c 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/RouteRepository.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/RouteRepository.cs @@ -3,6 +3,13 @@ namespace ProjectAutoenterprise.Repositories.Implementations; internal class RouteRepository : IRouteRepository { + private readonly IConnectionString _connectionString; + + public RouteRepository(IConnectionString connectionString) + { + _connectionString = connectionString; + } + public void CreateRoute(Route route) { } diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/appsettings.json b/ProjectAutoenterprise/ProjectAutoenterprise/appsettings.json new file mode 100644 index 0000000..e9d90f9 --- /dev/null +++ b/ProjectAutoenterprise/ProjectAutoenterprise/appsettings.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/autoenterprise_log.txt", + "rollingInterval": "Day" + } + } + ] + } +} \ No newline at end of file -- 2.25.1 From 3335f9ec1a72e16018108a122be813f5ee689557 Mon Sep 17 00:00:00 2001 From: Aidar Date: Thu, 5 Dec 2024 18:46:42 +0400 Subject: [PATCH 2/4] =?UTF-8?q?LabWork=202.0.2=20(=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B3?= =?UTF-8?q?=D0=B5=D1=80=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectAutoenterprise/Program.cs | 20 ++++++++++++++++++- .../Implementations/BusRepairRepository.cs | 15 ++++++++++++-- .../Implementations/BusRepository.cs | 15 ++++++++++++-- .../Implementations/EmployeeRepository.cs | 13 +++++++++++- .../Implementations/ItineraryRepository.cs | 15 ++++++++++++-- .../Implementations/RouteRepository.cs | 8 ++++++-- 6 files changed, 76 insertions(+), 10 deletions(-) diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Program.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Program.cs index dca5fca..d8bac2a 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Program.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Program.cs @@ -2,6 +2,10 @@ using ProjectAutoenterprise.Repositories.Implementations; using ProjectAutoenterprise.Repositories; using Unity; using Unity.Lifetime; +using Unity.Microsoft.Logging; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Serilog; namespace ProjectAutoenterprise { @@ -21,14 +25,28 @@ namespace ProjectAutoenterprise private static IUnityContainer CreateContainer() { var container = new UnityContainer(); + container.AddExtension(new LoggingExtension(CreateLoggerFactory())); + + container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); - container.RegisterType(new TransientLifetimeManager()); 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/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepairRepository.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepairRepository.cs index b62c689..e17307b 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepairRepository.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepairRepository.cs @@ -1,9 +1,20 @@ -using ProjectAutoenterprise.Entities; +using Microsoft.Extensions.Logging; +using ProjectAutoenterprise.Entities; namespace ProjectAutoenterprise.Repositories.Implementations; internal class BusRepairRepository : IBusRepairRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public BusRepairRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateBusRepair(BusRepair busRepair) { } @@ -12,4 +23,4 @@ internal class BusRepairRepository : IBusRepairRepository { return []; } -} +} \ No newline at end of file diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepository.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepository.cs index 471f8cd..bfa7c29 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepository.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepository.cs @@ -1,8 +1,19 @@ -using ProjectAutoenterprise.Entities; +using Microsoft.Extensions.Logging; +using ProjectAutoenterprise.Entities; namespace ProjectAutoenterprise.Repositories.Implementations; internal class BusRepository : IBusRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public BusRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateBus(Bus bus) { } @@ -20,4 +31,4 @@ internal class BusRepository : IBusRepository public void UpdateBus(Bus bus) { } -} +} \ No newline at end of file diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/EmployeeRepository.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/EmployeeRepository.cs index c9bc573..fd511a0 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/EmployeeRepository.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/EmployeeRepository.cs @@ -1,9 +1,20 @@ -using ProjectAutoenterprise.Entities; +using Microsoft.Extensions.Logging; +using ProjectAutoenterprise.Entities; using ProjectAutoenterprise.Entities.Enums; namespace ProjectAutoenterprise.Repositories.Implementations; internal class EmployeeRepository : IEmployeeRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public EmployeeRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateEmployee(Employee employee) { diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ItineraryRepository.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ItineraryRepository.cs index 3686668..6dde6d9 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ItineraryRepository.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ItineraryRepository.cs @@ -1,9 +1,20 @@ -using ProjectAutoenterprise.Entities; +using Microsoft.Extensions.Logging; +using ProjectAutoenterprise.Entities; namespace ProjectAutoenterprise.Repositories.Implementations; internal class ItineraryRepository : IItineraryRepository { + private readonly IConnectionString _connectionString; + + private readonly ILogger _logger; + + public ItineraryRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateItinerary(Itinerary itinerary) { } @@ -15,4 +26,4 @@ internal class ItineraryRepository : IItineraryRepository { return []; } -} +} \ No newline at end of file diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/RouteRepository.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/RouteRepository.cs index 242b39c..0aca689 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/RouteRepository.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/RouteRepository.cs @@ -1,13 +1,17 @@ -using ProjectAutoenterprise.Entities; +using Microsoft.Extensions.Logging; +using ProjectAutoenterprise.Entities; namespace ProjectAutoenterprise.Repositories.Implementations; internal class RouteRepository : IRouteRepository { private readonly IConnectionString _connectionString; - public RouteRepository(IConnectionString connectionString) + private readonly ILogger _logger; + + public RouteRepository(IConnectionString connectionString, ILogger logger) { _connectionString = connectionString; + _logger = logger; } public void CreateRoute(Route route) -- 2.25.1 From 4c93a225d9c557c930344ae58c5b3c8b3b4fa903 Mon Sep 17 00:00:00 2001 From: Aidar Date: Fri, 6 Dec 2024 21:37:27 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=20LabWork=202.1.0=20(=D0=9F=D0=BE=D0=B4?= =?UTF-8?q?=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=20?= =?UTF-8?q?=D0=91=D0=94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/Enums/BusColors.cs | 11 +- .../Entities/Itinerary.cs | 6 +- .../Forms/FormBusRepairs.Designer.cs | 1 + .../Forms/FormBuses.Designer.cs | 1 + .../Forms/FormEmployees.Designer.cs | 1 + .../Forms/FormEmployees.cs | 1 + .../Forms/FormItineraries.Designer.cs | 1 + .../Forms/FormRoutes.Designer.cs | 1 + .../ProjectAutoenterprise.csproj | 2 + .../Implementations/BusRepairRepository.cs | 44 +++++- .../Implementations/BusRepository.cs | 108 ++++++++++++-- .../Implementations/ConnectionString.cs | 2 +- .../Implementations/EmployeeRepository.cs | 138 ++++++++++++++---- .../Implementations/ItineraryRepository.cs | 69 ++++++++- .../Implementations/RouteRepository.cs | 111 ++++++++++++-- 15 files changed, 422 insertions(+), 75 deletions(-) diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Entities/Enums/BusColors.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Entities/Enums/BusColors.cs index aed0daa..10a71d3 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Entities/Enums/BusColors.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Entities/Enums/BusColors.cs @@ -3,9 +3,10 @@ [Flags] public enum BusColors { - White = 0, - Yellow = 1, - Black = 2, - Blue = 4, - Green = 8 + None = 0, + White = 1, + Yellow = 2, + Black = 4, + Blue = 8, + Green = 16 } \ No newline at end of file diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Entities/Itinerary.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Entities/Itinerary.cs index f39a68b..dcf4aac 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Entities/Itinerary.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Entities/Itinerary.cs @@ -7,20 +7,20 @@ public class Itinerary { public int Id { get; private set; } public int BusId { get; private set; } - public IEnumerable ItineraryRoute { get; private set; } = []; + public IEnumerable ItineraryRoutes { get; private set; } = []; public int DriverId { get; private set; } public int ConductorId { get; private set; } public DateTime ItineraryDate { get; private set; } public string Description { get; private set; } = string.Empty; public static Itinerary CreateOperation(int id, int busId, int driverId, int conductorId, DateTime itineraryDate, string description, - IEnumerable itineraryRoute) + IEnumerable itineraryRoutes) { return new Itinerary { Id = id, BusId = busId, - ItineraryRoute = itineraryRoute, + ItineraryRoutes = itineraryRoutes, DriverId = driverId, ConductorId = conductorId, ItineraryDate = itineraryDate, diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBusRepairs.Designer.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBusRepairs.Designer.cs index eb71e7f..e8b8e86 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBusRepairs.Designer.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBusRepairs.Designer.cs @@ -70,6 +70,7 @@ dataGridViewData.Name = "dataGridViewData"; dataGridViewData.ReadOnly = true; dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewData.Size = new Size(682, 411); dataGridViewData.TabIndex = 3; // diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBuses.Designer.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBuses.Designer.cs index a55c9e3..56bdd3d 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBuses.Designer.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBuses.Designer.cs @@ -96,6 +96,7 @@ dataGridViewData.Name = "dataGridViewData"; dataGridViewData.ReadOnly = true; dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewData.Size = new Size(682, 411); dataGridViewData.TabIndex = 2; // diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormEmployees.Designer.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormEmployees.Designer.cs index 112e9c5..e13357e 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormEmployees.Designer.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormEmployees.Designer.cs @@ -96,6 +96,7 @@ dataGridViewData.Name = "dataGridViewData"; dataGridViewData.ReadOnly = true; dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewData.Size = new Size(682, 411); dataGridViewData.TabIndex = 1; // diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormEmployees.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormEmployees.cs index 339e587..81b956b 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormEmployees.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormEmployees.cs @@ -14,6 +14,7 @@ public partial class FormEmployees : Form _employeeRepository = employeeRepository ?? throw new ArgumentNullException(nameof(employeeRepository)); } + private void FormEmployees_Load(object sender, EventArgs e) { try diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormItineraries.Designer.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormItineraries.Designer.cs index 5d64ac1..45d6d9b 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormItineraries.Designer.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormItineraries.Designer.cs @@ -83,6 +83,7 @@ dataGridViewData.Name = "dataGridViewData"; dataGridViewData.ReadOnly = true; dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewData.Size = new Size(682, 411); dataGridViewData.TabIndex = 3; // diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormRoutes.Designer.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormRoutes.Designer.cs index 9d776cc..2d22552 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormRoutes.Designer.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormRoutes.Designer.cs @@ -52,6 +52,7 @@ dataGridViewData.Name = "dataGridViewData"; dataGridViewData.ReadOnly = true; dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridViewData.Size = new Size(681, 411); dataGridViewData.TabIndex = 0; // diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/ProjectAutoenterprise.csproj b/ProjectAutoenterprise/ProjectAutoenterprise/ProjectAutoenterprise.csproj index 1de707e..ebed082 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/ProjectAutoenterprise.csproj +++ b/ProjectAutoenterprise/ProjectAutoenterprise/ProjectAutoenterprise.csproj @@ -13,6 +13,8 @@ + + diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepairRepository.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepairRepository.cs index e17307b..f8facd2 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepairRepository.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepairRepository.cs @@ -1,14 +1,15 @@ -using Microsoft.Extensions.Logging; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; using ProjectAutoenterprise.Entities; - +using System.Data.SqlClient; namespace ProjectAutoenterprise.Repositories.Implementations; internal class BusRepairRepository : IBusRepairRepository { private readonly IConnectionString _connectionString; - private readonly ILogger _logger; - public BusRepairRepository(IConnectionString connectionString, ILogger logger) { _connectionString = connectionString; @@ -17,10 +18,39 @@ internal class BusRepairRepository : IBusRepairRepository public void CreateBusRepair(BusRepair busRepair) { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(busRepair)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" +INSERT INTO BusRepairs (BusId, RepairDate, Description) +VALUES (@BusId, @RepairDate, @Description)"; + connection.Execute(queryInsert, busRepair); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } - public IEnumerable ReadBusRepairs(DateTime? dateForm = null, DateTime? dateTo = null, - int? busId = null, string? description = null) + public IEnumerable ReadBusRepairs( + DateTime? dateForm = null, DateTime? dateTo = null, int? busId = null, string? description = null) { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM BusRepairs"; + var busRepairss = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(busRepairss)); + return busRepairss; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } \ No newline at end of file diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepository.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepository.cs index bfa7c29..0198a34 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepository.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/BusRepository.cs @@ -1,13 +1,14 @@ -using Microsoft.Extensions.Logging; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; using ProjectAutoenterprise.Entities; namespace ProjectAutoenterprise.Repositories.Implementations; internal class BusRepository : IBusRepository { private readonly IConnectionString _connectionString; - private readonly ILogger _logger; - public BusRepository(IConnectionString connectionString, ILogger logger) { _connectionString = connectionString; @@ -16,19 +17,98 @@ internal class BusRepository : IBusRepository public void CreateBus(Bus bus) { - } - public void DeleteBus(int id) - { - } - public Bus ReadBusById(int id) - { - return Bus.CreateEntity(0, string.Empty, 0, 0); - } - public IEnumerable ReadBuses() - { - return []; + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(bus)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" +INSERT INTO Buses (Brand, Capacity, BusColors) +VALUES (@Brand, @Capacity, @BusColors)"; + connection.Execute(queryInsert, bus); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } public void UpdateBus(Bus bus) { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(bus)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" +UPDATE Buses +SET +Brand=@Brand, +Capacity=@Capacity, +BusColors=@BusColors +WHERE Id=@Id"; + connection.Execute(queryUpdate, bus); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } + } + public void DeleteBus(int id) + { + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" +DELETE FROM Buses +WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } + } + public Bus ReadBusById(int id) + { + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" +SELECT * FROM Buses +WHERE Id=@id"; + var bus = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(bus)); + return bus; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } + } + public IEnumerable ReadBuses() + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Buses"; + var buses = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(buses)); + return buses; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } \ No newline at end of file diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ConnectionString.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ConnectionString.cs index 15eaea7..86c8ccf 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ConnectionString.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ConnectionString.cs @@ -2,5 +2,5 @@ internal class ConnectionString : IConnectionString { - string IConnectionString.ConnectionString => ""; + string IConnectionString.ConnectionString => "Host=localhost;Port=5432;Username=postgres;Password=postgres;Database=autoenterprise"; } \ No newline at end of file diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/EmployeeRepository.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/EmployeeRepository.cs index fd511a0..2907bdb 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/EmployeeRepository.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/EmployeeRepository.cs @@ -1,14 +1,16 @@ -using Microsoft.Extensions.Logging; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; using ProjectAutoenterprise.Entities; using ProjectAutoenterprise.Entities.Enums; +using System.Data.SqlClient; namespace ProjectAutoenterprise.Repositories.Implementations; internal class EmployeeRepository : IEmployeeRepository { private readonly IConnectionString _connectionString; - private readonly ILogger _logger; - public EmployeeRepository(IConnectionString connectionString, ILogger logger) { _connectionString = connectionString; @@ -17,31 +19,115 @@ internal class EmployeeRepository : IEmployeeRepository public void CreateEmployee(Employee employee) { - + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(employee)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" +INSERT INTO Employees (FirstName, LastName, BirthDate, EmployeePost) +VALUES (@FirstName, @LastName, @BirthDate, @EmployeePost)"; + connection.Execute(queryInsert, employee); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } - - public void DeleteEmployee(int id) - { - - } - - public Employee ReadEmployeeById(int id) - { - return Employee.CreateEntity(0, string.Empty, string.Empty, DateTime.MinValue, EmployeePost.None); - } - - public IEnumerable ReadEmployees() - { - return []; - } - - public IEnumerable ReadEmployees(EmployeePost employeePost) - { - return []; - } - public void UpdateEmployee(Employee employee) { - + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(employee)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" +UPDATE Employees +SET +FirstName=@FirstName, +LastName=@LastName, +BirthDate=@BirthDate, +EmployeePost=@EmployeePost +WHERE Id=@Id"; + connection.Execute(queryUpdate, employee); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } + } + public void DeleteEmployee(int id) + { + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" +DELETE FROM Employees +WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } + } + public Employee ReadEmployeeById(int id) + { + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" +SELECT * FROM Employees +WHERE Id=@id"; + var employee = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(employee)); + return employee; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } + } + public IEnumerable ReadEmployees() + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Employees"; + var employees = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(employees)); + return employees; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } + } + public IEnumerable ReadEmployees(EmployeePost employeePost) + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Employees WHERE EmployeePost='" + employeePost.ToString()+"'"; + var employees = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(employees)); + return employees; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } \ No newline at end of file diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ItineraryRepository.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ItineraryRepository.cs index 6dde6d9..d90d2fe 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ItineraryRepository.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/ItineraryRepository.cs @@ -1,6 +1,8 @@ -using Microsoft.Extensions.Logging; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; using ProjectAutoenterprise.Entities; - namespace ProjectAutoenterprise.Repositories.Implementations; internal class ItineraryRepository : IItineraryRepository @@ -17,13 +19,70 @@ internal class ItineraryRepository : IItineraryRepository public void CreateItinerary(Itinerary itinerary) { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(itinerary)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + connection.Open(); + using var transaction = connection.BeginTransaction(); + var queryInsert = @" +INSERT INTO Itineraries (BusId, DriverId, ConductorId, ItineraryDate, Description) +VALUES (@BusId, @DriverId, @ConductorId, @ItineraryDate, @Description); +SELECT MAX(Id) FROM Itineraries"; + var itineraryId = connection.QueryFirst(queryInsert, itinerary, transaction); + var querySubInsert = @" +INSERT INTO ItineraryRoutes (ItineraryId, RouteId) +VALUES (@ItineraryId, @RouteId)"; + foreach (var elem in itinerary.ItineraryRoutes) + { + connection.Execute(querySubInsert, new { itineraryId, elem.RouteId }, transaction); + } + transaction.Commit(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } + public void DeleteItinerary(int id) { + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" +DELETE FROM Itineraries +WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } - public IEnumerable ReadItinerary(DateTime? dateForm = null, DateTime? dateTo = null, - int? driverId = null, int? conductorId = null) + + public IEnumerable ReadItinerary( + DateTime? dateForm = null, DateTime? dateTo = null, int? driverId = null, int? conductorId = null) { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @"SELECT * FROM Itineraries"; + var itineraries = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(itineraries)); + return itineraries; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } \ No newline at end of file diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/RouteRepository.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/RouteRepository.cs index 0aca689..4db1c21 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/RouteRepository.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Repositories/Implementations/RouteRepository.cs @@ -1,13 +1,15 @@ -using Microsoft.Extensions.Logging; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; using ProjectAutoenterprise.Entities; +using System.Data.SqlClient; namespace ProjectAutoenterprise.Repositories.Implementations; internal class RouteRepository : IRouteRepository { private readonly IConnectionString _connectionString; - private readonly ILogger _logger; - public RouteRepository(IConnectionString connectionString, ILogger logger) { _connectionString = connectionString; @@ -16,19 +18,100 @@ internal class RouteRepository : IRouteRepository 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 Routes (BeginRoutePoint, EndRoutePoint) +VALUES (@BeginRoutePoint, @EndRoutePoint)"; + connection.Execute(queryInsert, route); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } - public void DeleteRoute(int id) - { - } - public Route ReadRouteById(int id) - { - return Route.CreateEntity(0, string.Empty, string.Empty); - } - public IEnumerable ReadRoutes() - { - return []; - } + public void UpdateRoute(Route route) { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(route)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" +UPDATE Routes +SET +BeginRoutePoint=@BeginRoutePoint, +EndRoutePoint=@EndRoutePoint +WHERE Id=@Id"; + connection.Execute(queryUpdate, 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 Routes +WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } + } + + public Route ReadRouteById(int id) + { + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" +SELECT * FROM Routes +WHERE 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() + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Routes"; + var routes = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(routes)); + return routes; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } \ No newline at end of file -- 2.25.1 From 24053628fd45d83899711c30d3d2da343b6eff05 Mon Sep 17 00:00:00 2001 From: Aidar Date: Tue, 17 Dec 2024 19:23:42 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=20LabWork=202.1.1=20(=D0=98=D1=81=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBus.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBus.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBus.cs index a11287e..5070e7f 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBus.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormBus.cs @@ -74,7 +74,7 @@ public partial class FormBus : Form private void ButtonCancel_Click(object sender, EventArgs e) => Close(); private Bus CreateBus(int id) { - BusColors busColors = BusColors.White; + BusColors busColors = BusColors.None; foreach (var elem in checkedListBoxBusColors.CheckedItems) { busColors |= (BusColors)elem; -- 2.25.1