Лабараторная 2 конечная
This commit is contained in:
parent
261d9f15c6
commit
ba0ecef360
@ -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("Имеются не заполненые поля");
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -11,5 +11,5 @@ public interface IRoutSheetRepository
|
||||
{
|
||||
IEnumerable<RoutSheet> 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);
|
||||
|
||||
}
|
||||
|
@ -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<int>(queryInsert, routsheet, transaction);
|
||||
var routsheetId = connection.QueryFirst<int>(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<RoutSheet> 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<RoutSheet>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(curriculumSupplements));
|
||||
return curriculumSupplements;
|
||||
var routsheet = connection.Query<RoutSheet>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(routsheet));
|
||||
return routsheet;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user