lab2
This commit is contained in:
parent
d74bbe43a0
commit
a2531a745c
@ -7,16 +7,16 @@ public class RepairRequest
|
||||
public int Id { get; private set; }
|
||||
public int BusId { get; private set; }
|
||||
public BreakDownType BreakDownType { get; private set; }
|
||||
public DateTime Date { get; private set; }
|
||||
public DateTime DateTime { get; private set; }
|
||||
public int EmployeeId { get; private set; }
|
||||
public static RepairRequest CreateRepairRequest(int id, int busId, BreakDownType breakDownType, DateTime date, int employeeId)
|
||||
public static RepairRequest CreateRepairRequest(int id, int busId, BreakDownType breakDownType, DateTime dateTime, int employeeId)
|
||||
{
|
||||
return new RepairRequest
|
||||
{
|
||||
Id = id,
|
||||
BusId = busId,
|
||||
BreakDownType = breakDownType,
|
||||
Date = date,
|
||||
DateTime = dateTime,
|
||||
EmployeeId = employeeId
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
namespace TransportEnterprise.Entities.Repositories;
|
||||
|
||||
public interface IConnectionString
|
||||
{
|
||||
public string ConnectionString { get; }
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace TransportEnterprise.Entities.Repositories;
|
||||
|
||||
public class IRouteSheetEmployees
|
||||
{
|
||||
public int RouteSheetId { get; private set; }
|
||||
public int EmployeeId { get; private set; }
|
||||
}
|
@ -3,6 +3,7 @@ public interface IRouteSheetRepository
|
||||
{
|
||||
IEnumerable<RouteSheet> ReadRouteSheets();
|
||||
RouteSheet ReadRouteSheeteById(int id);
|
||||
IEnumerable<RouteSheet_Employee> ReadRouteSheets_Employee();
|
||||
void CreateRouteSheet(RouteSheet routeSheet);
|
||||
void UpdateRouteSheet(RouteSheet routeSheet);
|
||||
void DeleteRouteSheet(int id);
|
||||
|
@ -1,30 +1,119 @@
|
||||
|
||||
using TransportEnterprise.Entities.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Dapper;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
|
||||
namespace TransportEnterprise.Entities.Repositories.Implementations;
|
||||
internal class BusRepository : IBusRepository
|
||||
public class BusRepository : IBusRepository
|
||||
{
|
||||
public void CreateBus(Bus bus)
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<BusRepository> _logger;
|
||||
public BusRepository(IConnectionString connectionString, ILogger<BusRepository> logger)
|
||||
{
|
||||
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateBus(Bus bus)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(bus));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO Bus (Model, Capacity, Licenseplate, Brand, Year, Technicalcondition)
|
||||
VALUES (@Model, @Capacity, @Licenseplate, @Brand, @Year, @Technicalcondition)";
|
||||
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 Bus
|
||||
SET Model=@Model, Capacity=@Capacity, Licenseplate=@Licenseplate, Brand=@Brand, Year=@Year, Technicalcondition=@Technicalcondition
|
||||
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 Bus
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Bus ReadBusById(int id)
|
||||
{
|
||||
return Bus.CreateBus(0, string.Empty, 0, string.Empty, string.Empty, 0, TechnicalCondition.None);
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Bus
|
||||
WHERE Id=@id";
|
||||
var bus = connection.QueryFirst<Bus>(querySelect, new
|
||||
{
|
||||
id
|
||||
});
|
||||
_logger.LogDebug("Найденный объект: {json}",
|
||||
JsonConvert.SerializeObject(bus));
|
||||
return bus;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Bus> ReadBuses()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public void UpdateBus(Bus bus)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Bus";
|
||||
var buses = connection.Query<Bus>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(buses));
|
||||
return buses;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
namespace TransportEnterprise.Entities.Repositories.Implementations;
|
||||
|
||||
public class ConnectionString : IConnectionString
|
||||
{
|
||||
string IConnectionString.ConnectionString => "Server=localhost;Port=5432;Database=TransportEnterprise;User Id=postgres;Password=kuslo123;";
|
||||
}
|
@ -1,30 +1,127 @@
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Dapper;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using TransportEnterprise.Entities.Enums;
|
||||
|
||||
namespace TransportEnterprise.Entities.Repositories.Implementations;
|
||||
|
||||
public class EmployeeRepository : IEmployeeRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<EmployeeRepository> _logger;
|
||||
|
||||
public EmployeeRepository(IConnectionString connectionString, ILogger<EmployeeRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
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 Employee(Name, Number, PositionOfEmployee, PhoneNumber)
|
||||
VALUES (@Name, @Number, @PositionOfEmployee, @PhoneNumber)";
|
||||
connection.Execute(queryInsert, employee);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
public void UpdateEmployee(Employee employee)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(employee));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE Employee
|
||||
SET Name=@Name, Number=@Number, PositionOfEmployee=@PositionOfEmployee, PhoneNumber=@PhoneNumber
|
||||
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 Employee
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Employee ReadEmployeeById(int id)
|
||||
{
|
||||
return Employee.CreateEmployee(0,string.Empty,0,PositionOfEmployee.None, string.Empty);
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM Employee
|
||||
WHERE Id=@id";
|
||||
var employee = connection.QueryFirst<Employee>(querySelect, new
|
||||
{
|
||||
id
|
||||
});
|
||||
_logger.LogDebug("Найденный объект: {json}",
|
||||
JsonConvert.SerializeObject(employee));
|
||||
return employee;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Employee> ReadEmployees()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Employee";
|
||||
var employees = connection.Query<Employee>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(employees));
|
||||
return employees;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
|
||||
public void UpdateEmployee(Employee employee)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,23 +1,84 @@
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Dapper;
|
||||
using Npgsql;
|
||||
using TransportEnterprise.Entities.Enums;
|
||||
|
||||
namespace TransportEnterprise.Entities.Repositories.Implementations;
|
||||
|
||||
public class RepairRequestRepository : IRepairRequestRepository
|
||||
{
|
||||
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<RepairRequestRepository> _logger;
|
||||
public RepairRequestRepository(IConnectionString connectionString, ILogger<RepairRequestRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateRepairRequest(RepairRequest repairRequest)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(repairRequest));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO RepairRequest (EmployeeId, BusId, BreakDownType, Datetime)
|
||||
VALUES (@EmployeeId, @BusId, @BreakDownType, @Datetime)";
|
||||
connection.Execute(queryInsert, repairRequest);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public RepairRequest ReadRepairRequestById(int id)
|
||||
{
|
||||
return RepairRequest.CreateRepairRequest(0, 0, BreakDownType.None, DateTime.Now, 0);
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM RepairRequest
|
||||
WHERE Id=@id";
|
||||
var repairRequest = connection.QueryFirst<RepairRequest>(querySelect, new
|
||||
{
|
||||
id
|
||||
});
|
||||
_logger.LogDebug("Найденный объект: {json}",
|
||||
JsonConvert.SerializeObject(repairRequest));
|
||||
return repairRequest;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<RepairRequest> ReadRepairRequests()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM RepairRequest";
|
||||
var repairRequests = connection.Query<RepairRequest>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(repairRequests));
|
||||
return repairRequests;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,27 +1,120 @@
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Dapper;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
|
||||
namespace TransportEnterprise.Entities.Repositories.Implementations;
|
||||
|
||||
public class RouteRepository : IRouteRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<RouteRepository> _logger;
|
||||
public RouteRepository(IConnectionString connectionString, ILogger<RouteRepository> 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 (Name, Number, Interval, Schedule)
|
||||
VALUES (@Name, @Number, @Interval, @Schedule)";
|
||||
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 Name=@Name, Number=@Number, Interval=@Interval, Schedule=@Schedule
|
||||
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 Route
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public Route ReadRouteById(int id)
|
||||
{
|
||||
return Route.CreateRoute(0, string.Empty, 0, 0, string.Empty);
|
||||
_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> ReadRoutes()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public void UpdateRoute(Route route)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,166 @@
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Dapper;
|
||||
using Npgsql;
|
||||
using System.Transactions;
|
||||
|
||||
namespace TransportEnterprise.Entities.Repositories.Implementations;
|
||||
|
||||
public class RouteSheetRepository : IRouteSheetRepository
|
||||
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<RouteSheetRepository> _logger;
|
||||
|
||||
public RouteSheetRepository(IConnectionString connectionString, ILogger<RouteSheetRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateRouteSheet(RouteSheet routeSheet)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(routeSheet));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
|
||||
var queryInsert = @"
|
||||
INSERT INTO RouteSheet (Datetime, RouteId, BusId)
|
||||
VALUES (@Datetime, @RouteId, @BusId);
|
||||
SELECT MAX(Id) FROM RouteSheet";
|
||||
|
||||
|
||||
var routeSheetId = connection.QueryFirst<int>(queryInsert, routeSheet, transaction);
|
||||
|
||||
var querySubInsert = @"
|
||||
INSERT INTO RouteSheet_Employee (RouteSheetId, EmployeeId, Count)
|
||||
VALUES (@RouteSheetId, @EmployeeId, @Count)";
|
||||
foreach (var elem in routeSheet.RouteSheet_Employee)
|
||||
{
|
||||
connection.Execute(querySubInsert, new
|
||||
{
|
||||
routeSheetId,
|
||||
elem.EmployeeId,
|
||||
elem.Count
|
||||
}, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void UpdateRouteSheet(RouteSheet routeSheet)
|
||||
{
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(routeSheet));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"
|
||||
UPDATE RouteSheet
|
||||
SET Datetime=@Datetime, RouteId=@RouteId, BusId=@BusId
|
||||
WHERE Id=@Id";
|
||||
connection.Execute(queryUpdate, routeSheet);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteRouteSheet(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM RouteSheet
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public RouteSheet ReadRouteSheeteById(int id)
|
||||
{
|
||||
return RouteSheet.CreateRouteSheet(0, DateTime.Now, 0, 0, []);
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM RouteSheet
|
||||
WHERE Id=@id";
|
||||
var routeSheet = connection.QueryFirst<RouteSheet>(querySelect, new
|
||||
{
|
||||
id
|
||||
});
|
||||
_logger.LogDebug("Найденный объект: {json}",
|
||||
JsonConvert.SerializeObject(routeSheet));
|
||||
return routeSheet;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<RouteSheet> ReadRouteSheets()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM RouteSheet";
|
||||
var routeSheets = connection.Query<RouteSheet>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(routeSheets));
|
||||
return routeSheets;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateRouteSheet(RouteSheet routeSheet)
|
||||
public IEnumerable<RouteSheet_Employee> ReadRouteSheets_Employee()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM RouteSheet_Employee";
|
||||
var routeSheets = connection.Query<RouteSheet_Employee>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(routeSheets));
|
||||
return routeSheets;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,8 @@ public class RouteSheet
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public DateTime DateTime { get; private set; }
|
||||
public int Bus { get; private set; }
|
||||
public int Route { get; private set; }
|
||||
public int BusId { get; private set; }
|
||||
public int RouteId { get; private set; }
|
||||
public IEnumerable<RouteSheet_Employee> RouteSheet_Employee { get; private set; } = [];
|
||||
|
||||
|
||||
@ -16,8 +16,8 @@ public class RouteSheet
|
||||
{
|
||||
Id = id,
|
||||
DateTime = dateTime,
|
||||
Bus = bus,
|
||||
Route = route,
|
||||
BusId = bus,
|
||||
RouteId = route,
|
||||
RouteSheet_Employee = routeSheetEmployees
|
||||
};
|
||||
}
|
||||
|
@ -44,7 +44,7 @@
|
||||
dataGridView.AllowUserToResizeRows = false;
|
||||
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Dock = DockStyle.Fill;
|
||||
dataGridView.Dock = DockStyle.Left;
|
||||
dataGridView.Location = new Point(0, 0);
|
||||
dataGridView.MultiSelect = false;
|
||||
dataGridView.Name = "dataGridView";
|
||||
@ -52,7 +52,7 @@
|
||||
dataGridView.RowHeadersVisible = false;
|
||||
dataGridView.RowHeadersWidth = 62;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(1119, 832);
|
||||
dataGridView.Size = new Size(1113, 832);
|
||||
dataGridView.TabIndex = 3;
|
||||
//
|
||||
// panel1
|
||||
|
@ -1,5 +1,8 @@
|
||||
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using TransportEnterprise.Entities;
|
||||
using TransportEnterprise.Entities.Repositories;
|
||||
using Unity;
|
||||
|
||||
@ -38,5 +41,21 @@ public partial class FormAddingRouteSheet : Form
|
||||
MessageBox.Show(ex.Message, "Ошибка при добавлении",MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridView.DataSource = _routeSheetRepository.ReadRouteSheets();
|
||||
private void LoadList() {
|
||||
var data = _routeSheetRepository.ReadRouteSheets();
|
||||
var data1 = _routeSheetRepository.ReadRouteSheets_Employee();
|
||||
var filteredData = data.Select(rs => new
|
||||
{
|
||||
|
||||
rs.Id,
|
||||
rs.BusId,
|
||||
rs.RouteId,
|
||||
|
||||
|
||||
}).ToList();
|
||||
|
||||
dataGridView.DataSource = filteredData;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ namespace TransportEnterprise.Forms
|
||||
textBoxModel.Text = bus.Model;
|
||||
numericUpDownCapacity.Value = bus.Capacity;
|
||||
numericUpDownYear.Value = bus.Year;
|
||||
textBoxLicensePlate.Text= bus.LicensePlate;
|
||||
comboBoxTechnicalCondition.SelectedItem= bus.TechnicalCondition;
|
||||
|
||||
_busId = value;
|
||||
@ -48,7 +49,7 @@ namespace TransportEnterprise.Forms
|
||||
{
|
||||
try
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(textBoxModel.Text) || string.IsNullOrWhiteSpace(textBoxLicensePlate.Text) || comboBoxTechnicalCondition.SelectedIndex<1)
|
||||
if(string.IsNullOrWhiteSpace(textBoxModel.Text) || string.IsNullOrWhiteSpace(textBoxLicensePlate.Text) || comboBoxTechnicalCondition.SelectedIndex<0)
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public partial class FormEmployee : Form
|
||||
textBoxName.Text = employee.Name;
|
||||
numericUpDownNumber.Value = employee.Number;
|
||||
comboBoxPositionOfEmployee.SelectedItem = employee.PositionOfEmployee;
|
||||
textBoxPhoneNumber.Text = employee.PhoneNumber;
|
||||
_employeeId = value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -46,7 +47,7 @@ public partial class FormEmployee : Form
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(textBoxName.Text) || comboBoxPositionOfEmployee.SelectedIndex < 1)
|
||||
if (string.IsNullOrWhiteSpace(textBoxName.Text) || comboBoxPositionOfEmployee.SelectedIndex < 0)
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public partial class FormEmployees : Form
|
||||
}
|
||||
try
|
||||
{
|
||||
var form = _container.Resolve<FormRoute>();
|
||||
var form = _container.Resolve<FormEmployee>();
|
||||
form.Id = findId;
|
||||
form.ShowDialog();
|
||||
LoadList();
|
||||
|
@ -30,7 +30,7 @@ public partial class FormRepairRequest : Form
|
||||
{
|
||||
try
|
||||
{
|
||||
if (comboBoxBus.SelectedIndex < 1 || comboBoxEmployee.SelectedIndex < 1 || checkedListBoxBreakDownType.CheckedItems.Count == 0)
|
||||
if (comboBoxBus.SelectedIndex < 0 || comboBoxEmployee.SelectedIndex < 0 || checkedListBoxBreakDownType.CheckedItems.Count == 0)
|
||||
{
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
|
@ -111,6 +111,7 @@
|
||||
buttonSave.TabIndex = 8;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
|
@ -15,7 +15,7 @@ public partial class FormRouteSheet : Form
|
||||
comboBoxRoute.DisplayMember = "Name";
|
||||
comboBoxRoute.ValueMember = "Id";
|
||||
|
||||
ColumnName.DataSource = routeRepository.ReadRoutes();
|
||||
ColumnName.DataSource = employeeRepository.ReadEmployees();
|
||||
ColumnName.DisplayMember = "Name";
|
||||
ColumnName.ValueMember = "Id";
|
||||
|
||||
@ -55,7 +55,7 @@ public partial class FormRouteSheet : Form
|
||||
var list = new List<RouteSheet_Employee>();
|
||||
foreach (DataGridViewRow row in dataGridViewEmployees.Rows)
|
||||
{
|
||||
if (row.Cells["ColumnName"].Value == null)
|
||||
if (row.Cells["ColumnName"].Value == null || row.Cells["ColumnCount"].Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using TransportEnterprise.Entities.Repositories;
|
||||
using TransportEnterprise.Entities.Repositories.Implementations;
|
||||
using Unity;
|
||||
using Unity.Microsoft.Logging;
|
||||
|
||||
namespace TransportEnterprise
|
||||
{
|
||||
@ -22,13 +26,29 @@ namespace TransportEnterprise
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
|
||||
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||
|
||||
container.RegisterType<IBusRepository, BusRepository>();
|
||||
container.RegisterType<IEmployeeRepository, EmployeeRepository>();
|
||||
container.RegisterType<IRouteRepository, RouteRepository>();
|
||||
container.RegisterType<IRouteSheetRepository, RouteSheetRepository>();
|
||||
container.RegisterType<IRepairRequestRepository, RepairRequestRepository>();
|
||||
|
||||
container.RegisterType<IConnectionString, ConnectionString>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
@ -9,7 +9,18 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql" Version="8.0.5" />
|
||||
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
<PackageReference Include="Unity" Version="5.11.10" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -27,4 +38,10 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
15
TransportEnterprise/TransportEnterprise/appsettings.json
Normal file
15
TransportEnterprise/TransportEnterprise/appsettings.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/transportEnterprise_log.txt",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user