From ba0ecef360d03b01b9aa404f534b411c0bda3f2a Mon Sep 17 00:00:00 2001 From: RomaEredavkin <145482422+RomaEredavkin@users.noreply.github.com> Date: Sat, 14 Dec 2024 16:40:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=B0=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=202=20=D0=BA=D0=BE=D0=BD=D0=B5?= =?UTF-8?q?=D1=87=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/FormRoutSheet.cs | 2 +- .../Forms/FormTO.cs | 2 +- .../Repositories/IRoutSheetRepository.cs | 2 +- .../Implementations/RoutSheetRepository.cs | 29 ++++--------------- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.cs index c35c980..4c0651f 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormRoutSheet.cs @@ -36,7 +36,7 @@ public partial class FormRoutSheet : Form { try { - if (dataGridViewRoutSheet.RowCount < 0 || comboBoxDriver.SelectedIndex < 0 || comboBoxRout.SelectedIndex < 0) + if (dataGridViewRoutSheet.RowCount < 1 || comboBoxDriver.SelectedIndex < 0 || comboBoxRout.SelectedIndex < 0) { throw new Exception("Имеются не заполненые поля"); } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormTO.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormTO.cs index e1c6601..2fa5203 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormTO.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Forms/FormTO.cs @@ -15,7 +15,7 @@ public partial class FormTO : Form _toRepository = toRepository ?? throw new ArgumentNullException(nameof(toRepository)); comboBoxStaff.DataSource = staffRepositories.ReadStaff(); - comboBoxStaff.DisplayMember = "FirstName"; + comboBoxStaff.DisplayMember = "LastName"; comboBoxStaff.ValueMember = "Id"; comboBoxBus.DataSource = busRepository.ReadBus(); diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/IRoutSheetRepository.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/IRoutSheetRepository.cs index 52d6e5e..774cf87 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/IRoutSheetRepository.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/IRoutSheetRepository.cs @@ -11,5 +11,5 @@ public interface IRoutSheetRepository { IEnumerable ReadRoutSheet(DateTime? dateForm = null, DateTime? dateTo = null, int? routId = null, int? busid = null, int? driverid = null, int? conductorid = null); void CreateRoutSheet(RoutSheet routsheet); - void DeleteRoutSheet(int id); + } diff --git a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/RoutSheetRepository.cs b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/RoutSheetRepository.cs index 3729370..f689175 100644 --- a/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/RoutSheetRepository.cs +++ b/PIbd-24_EredavkinRA_BusBusiness/PIbd-24_EredavkinRA_BusBusiness/Repositories/Implementations/RoutSheetRepository.cs @@ -31,14 +31,14 @@ public class RoutSheetRepository : IRoutSheetRepository INSERT INTO RoutSheet (RoutId, DriverId, ConductorId, BusDate) VALUES (@RoutId, @DriverId, @ConductorID, @BusDate); SELECT MAX(Id) FROM RoutSheet"; - var curriculumSupplementId = connection.QueryFirst(queryInsert, routsheet, transaction); + var routsheetId = connection.QueryFirst(queryInsert, routsheet, transaction); var querySubInsert = @" INSERT INTO RoutSheetBus (RoutSheetId, BusId) VALUES (@RoutSheetId, @BusId)"; foreach (var elem in routsheet.RoutSheetBus) { - connection.Execute(querySubInsert, new { curriculumSupplementId, elem.BusID }, transaction); + connection.Execute(querySubInsert, new { routsheetId, elem.BusID }, transaction); } transaction.Commit(); @@ -50,24 +50,7 @@ public class RoutSheetRepository : IRoutSheetRepository } } - public void DeleteRoutSheet(int id) - { - _logger.LogInformation("Удаление объекта"); - _logger.LogDebug("Объект: {id}", id); - try - { - using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var queryDelete = @" - DELETE FROM RoutSheet - WHERE Id=@id"; - connection.Execute(queryDelete, new { id }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка при удалении объекта"); - throw; - } - } + public IEnumerable ReadRoutSheet(DateTime? dateForm = null, DateTime? dateBus = null, int? routId = null, int? busid = null, int? driverid = null, int? conductorid = null) { @@ -76,9 +59,9 @@ public class RoutSheetRepository : IRoutSheetRepository { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); var querySelect = "SELECT * FROM RoutSheet"; - var curriculumSupplements = connection.Query(querySelect); - _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(curriculumSupplements)); - return curriculumSupplements; + var routsheet = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(routsheet)); + return routsheet; } catch (Exception ex) {