4 лабараторная
This commit is contained in:
parent
495cc259ca
commit
f8ebb5c74b
@ -1,6 +1,7 @@
|
|||||||
using PIbd_24_EredavkinRA_BusBusiness.Entities.Enums;
|
using PIbd_24_EredavkinRA_BusBusiness.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -10,9 +11,14 @@ namespace PIbd_24_EredavkinRA_BusBusiness.Entities;
|
|||||||
public class Bus
|
public class Bus
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[DisplayName("Модель автобуса")]
|
||||||
public ModelType ModelType { get; private set; }
|
public ModelType ModelType { get; private set; }
|
||||||
|
[DisplayName("Номерной знак")]
|
||||||
public string N_Z { get; private set; } = string.Empty;
|
public string N_Z { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Вместимость автобуса")]
|
||||||
|
|
||||||
public int Capacity { get; private set; }
|
public int Capacity { get; private set; }
|
||||||
|
[DisplayName("Пробег")]
|
||||||
public double Bus_mileage { get; private set; }
|
public double Bus_mileage { get; private set; }
|
||||||
|
|
||||||
public static Bus CreateEntity(int id, ModelType modeltype, string n_z, double bus_mileage, int capacity)
|
public static Bus CreateEntity(int id, ModelType modeltype, string n_z, double bus_mileage, int capacity)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,10 +10,13 @@ namespace PIbd_24_EredavkinRA_BusBusiness.Entities;
|
|||||||
public class Rout
|
public class Rout
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[DisplayName("Начальная остановка")]
|
||||||
public string StartStop { get; private set; } = string.Empty;
|
public string StartStop { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Конечная остановка")]
|
||||||
public string EndStop { get; private set; } = string.Empty;
|
public string EndStop { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Номер Маршрута")]
|
||||||
public int NumberRout { get; private set; }
|
public int NumberRout { get; private set; }
|
||||||
|
public string FullRout => $"{NumberRout} {StartStop} {EndStop}";
|
||||||
public static Rout CreateEntity(int id, string startstop, string endstop, int numberrout)
|
public static Rout CreateEntity(int id, string startstop, string endstop, int numberrout)
|
||||||
{
|
{
|
||||||
return new Rout
|
return new Rout
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using DocumentFormat.OpenXml.Bibliography;
|
using DocumentFormat.OpenXml.Bibliography;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -10,12 +11,23 @@ namespace PIbd_24_EredavkinRA_BusBusiness.Entities;
|
|||||||
public class RoutSheet
|
public class RoutSheet
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[Browsable(false)]
|
||||||
public int DriverId { get; private set; }
|
public int DriverId { get; private set; }
|
||||||
|
[Browsable(false)]
|
||||||
public int ConductorId { get; private set; }
|
public int ConductorId { get; private set; }
|
||||||
|
[Browsable(false)]
|
||||||
public int RoutId { get; private set; }
|
public int RoutId { get; private set; }
|
||||||
|
[DisplayName("Водитель")]
|
||||||
|
public string EmployeeNameDriver { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Кондуктор")]
|
||||||
|
public string EmployeeNameConductor { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Маршрут")]
|
||||||
|
public string RoutName { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Автобусы")]
|
||||||
|
public string Bus => RoutSheetBus != null ? string.Join(", ", RoutSheetBus.Select(x => $"{x.BusName}")) : string.Empty;
|
||||||
|
[Browsable(false)]
|
||||||
public IEnumerable<RoutSheetBus> RoutSheetBus { get; private set; } = [];
|
public IEnumerable<RoutSheetBus> RoutSheetBus { get; private set; } = [];
|
||||||
|
[DisplayName("Дата Выезда")]
|
||||||
public DateTime BusDate { get; private set; }
|
public DateTime BusDate { get; private set; }
|
||||||
public static RoutSheet CreatOpeartion(int id, int driverid, int conductorid, int routid, DateTime busDate, IEnumerable<RoutSheetBus> RoutSheetBus)
|
public static RoutSheet CreatOpeartion(int id, int driverid, int conductorid, int routid, DateTime busDate, IEnumerable<RoutSheetBus> RoutSheetBus)
|
||||||
{
|
{
|
||||||
@ -30,17 +42,12 @@ public class RoutSheet
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RoutSheet CreatOpeartion(TempRoutSheetBus tempRoutSheetBus, IEnumerable<RoutSheetBus> RoutSheetBus)
|
public void SetRoutSheetBus(IEnumerable<RoutSheetBus> routSheetBus)
|
||||||
{
|
{
|
||||||
return new RoutSheet
|
if (routSheetBus != null && routSheetBus.Any())
|
||||||
{
|
{
|
||||||
Id = tempRoutSheetBus.Id,
|
RoutSheetBus = routSheetBus;
|
||||||
DriverId = tempRoutSheetBus.DriverId,
|
}
|
||||||
ConductorId = tempRoutSheetBus.ConductorId,
|
|
||||||
RoutId = tempRoutSheetBus.RoutId,
|
|
||||||
RoutSheetBus = RoutSheetBus,
|
|
||||||
BusDate = tempRoutSheetBus.BusDate
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ public class RoutSheetBus
|
|||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public int BusID { get; private set; }
|
public int BusID { get; private set; }
|
||||||
|
|
||||||
|
public string BusName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
|
||||||
public static RoutSheetBus CreateElement(int id, int busid)
|
public static RoutSheetBus CreateElement(int id, int busid)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using PIbd_24_EredavkinRA_BusBusiness.Entities.Enums;
|
using PIbd_24_EredavkinRA_BusBusiness.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -10,9 +11,12 @@ namespace PIbd_24_EredavkinRA_BusBusiness.Entities;
|
|||||||
public class Staff
|
public class Staff
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[DisplayName("Имя")]
|
||||||
public string FirstName { get; private set; } = string.Empty;
|
public string FirstName { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Фамилия")]
|
||||||
public string LastName { get; private set; } = string.Empty;
|
public string LastName { get; private set; } = string.Empty;
|
||||||
|
public string FullName => $"{LastName} {FirstName}";
|
||||||
|
[DisplayName("Должность")]
|
||||||
public EmployeePost EmployeePost { get; private set; }
|
public EmployeePost EmployeePost { get; private set; }
|
||||||
public static Staff CreatEntity(int id, string first, string last, EmployeePost employeePost)
|
public static Staff CreatEntity(int id, string first, string last, EmployeePost employeePost)
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using PIbd_24_EredavkinRA_BusBusiness.Entities.Enums;
|
using PIbd_24_EredavkinRA_BusBusiness.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -11,11 +12,19 @@ namespace PIbd_24_EredavkinRA_BusBusiness.Entities;
|
|||||||
public class To
|
public class To
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[Browsable(false)]
|
||||||
public int BusID { get; private set; }
|
public int BusID { get; private set; }
|
||||||
|
[Browsable(false)]
|
||||||
public int StaffID { get; private set; }
|
public int StaffID { get; private set; }
|
||||||
|
[DisplayName("Автобус")]
|
||||||
|
public string BusName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Механик")]
|
||||||
|
public string StaffName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Описание")]
|
||||||
public string Discription { get; private set; } = string.Empty;
|
public string Discription { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Стоимость Ремонта")]
|
||||||
public double Cost { get; private set; }
|
public double Cost { get; private set; }
|
||||||
|
[DisplayName("Дата дня")]
|
||||||
public DateTime DateTo { get; private set; }
|
public DateTime DateTo { get; private set; }
|
||||||
|
|
||||||
public static To CreatOperation(int id, string discription, double cost, DateTime dateTo, int busid, int staffid)
|
public static To CreatOperation(int id, string discription, double cost, DateTime dateTo, int busid, int staffid)
|
||||||
|
@ -99,7 +99,12 @@ public partial class FormBuses : Form
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _busRepository.ReadBus();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _busRepository.ReadBus();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -13,15 +13,15 @@ public partial class FormRoutSheet : Form
|
|||||||
_routSheetRepository = routSheetRepository ?? throw new ArgumentNullException(nameof(routSheetRepository));
|
_routSheetRepository = routSheetRepository ?? throw new ArgumentNullException(nameof(routSheetRepository));
|
||||||
|
|
||||||
comboBoxDriver.DataSource = staffRepositories.ReadStaff();
|
comboBoxDriver.DataSource = staffRepositories.ReadStaff();
|
||||||
comboBoxDriver.DisplayMember = "LastName";
|
comboBoxDriver.DisplayMember = "FullName";
|
||||||
comboBoxDriver.ValueMember = "Id";
|
comboBoxDriver.ValueMember = "Id";
|
||||||
|
|
||||||
comboBoxConductor.DataSource = staffRepositories.ReadStaff();
|
comboBoxConductor.DataSource = staffRepositories.ReadStaff();
|
||||||
comboBoxConductor.DisplayMember = "LastName";
|
comboBoxConductor.DisplayMember = "FullName";
|
||||||
comboBoxConductor.ValueMember = "Id";
|
comboBoxConductor.ValueMember = "Id";
|
||||||
|
|
||||||
comboBoxRout.DataSource = routRepositories.ReadRout();
|
comboBoxRout.DataSource = routRepositories.ReadRout();
|
||||||
comboBoxRout.DisplayMember = "NumberRout";
|
comboBoxRout.DisplayMember = "FullRout";
|
||||||
comboBoxRout.ValueMember = "Id";
|
comboBoxRout.ValueMember = "Id";
|
||||||
|
|
||||||
ColumnBus.DataSource = busRepository.ReadBus();
|
ColumnBus.DataSource = busRepository.ReadBus();
|
||||||
|
@ -47,7 +47,10 @@ public partial class FormRoutSheetes : Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private void LoadList() => dataGridViewData.DataSource = _routSheetRepository.ReadRoutSheet();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _routSheetRepository.ReadRoutSheet();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["BusDate"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,13 @@ public partial class FormRoutes : Form
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _routRepository.ReadRout();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _routRepository.ReadRout();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["FullRout"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -89,7 +89,13 @@ namespace PIbd_24_EredavkinRA_BusBusiness.Forms
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _staffRepository.ReadStaff();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _staffRepository.ReadStaff();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["FullName"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -15,7 +15,7 @@ public partial class FormTO : Form
|
|||||||
_toRepository = toRepository ?? throw new ArgumentNullException(nameof(toRepository));
|
_toRepository = toRepository ?? throw new ArgumentNullException(nameof(toRepository));
|
||||||
|
|
||||||
comboBoxStaff.DataSource = staffRepositories.ReadStaff();
|
comboBoxStaff.DataSource = staffRepositories.ReadStaff();
|
||||||
comboBoxStaff.DisplayMember = "LastName";
|
comboBoxStaff.DisplayMember = "FullName";
|
||||||
comboBoxStaff.ValueMember = "Id";
|
comboBoxStaff.ValueMember = "Id";
|
||||||
|
|
||||||
comboBoxBus.DataSource = busRepository.ReadBus();
|
comboBoxBus.DataSource = busRepository.ReadBus();
|
||||||
|
@ -81,7 +81,13 @@ public partial class FormTOes : Form
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _toRepository.ReadTo();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _toRepository.ReadTo();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["DateTo"].DefaultCellStyle.Format = "dd.MM.yyyy";
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -27,7 +27,7 @@ internal class ChartReport
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
new PdfBuilder(filePath)
|
new PdfBuilder(filePath)
|
||||||
.AddHeader("Количество Обслуживаний Автобуса за день")
|
.AddHeader($"Количество Обслуживаний Автобусов на {dateTime:dd MMMM yyyy}")
|
||||||
.AddPieChart("Автобусы", GetData(dateTime))
|
.AddPieChart("Автобусы", GetData(dateTime))
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
@ -43,10 +43,9 @@ internal class ChartReport
|
|||||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||||
{
|
{
|
||||||
return _toRepository
|
return _toRepository
|
||||||
.ReadTo()
|
.ReadTo(dateForm: dateTime.Date, dateTo: dateTime.Date.AddDays(1))
|
||||||
.Where(x => x.DateTo.Date == dateTime.Date)
|
.GroupBy(x => x.BusName, (key, cost) => new { BusName = key, Count = cost.Count() })
|
||||||
.GroupBy(x => x.BusID, (key, cost) => new { Id = key, Count = cost.Count() })
|
.Select(x => (x.BusName, (double)x.Count))
|
||||||
.Select(x => (x.Id.ToString(), (double)x.Count))
|
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ internal class TableReport
|
|||||||
{
|
{
|
||||||
new ExcelBuilder(filePath)
|
new ExcelBuilder(filePath)
|
||||||
.AddHeader("Общая сводка за Автобусами", 0, 3)
|
.AddHeader("Общая сводка за Автобусами", 0, 3)
|
||||||
.AddParagraph("за период", 0)
|
.AddParagraph($"за период c {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0)
|
||||||
.AddTable([15, 10, 10], GetData(busId, startDate, endDate))
|
.AddTable([15, 10, 10], GetData(busId, startDate, endDate))
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
@ -58,20 +58,18 @@ internal class TableReport
|
|||||||
public List<string[]> GetData(int busId, DateTime startDate, DateTime endDate)
|
public List<string[]> GetData(int busId, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
var data = _routsheetRepository
|
var data = _routsheetRepository
|
||||||
.ReadRoutSheet()
|
.ReadRoutSheet(dateForm: startDate, dateTo: endDate, busid: busId)
|
||||||
.Where(x => x.BusDate >= startDate && x.BusDate <= endDate && x.RoutSheetBus.Any(y => y.BusID == busId))
|
|
||||||
.Select(x => new {
|
.Select(x => new {
|
||||||
Date = x.BusDate,
|
Date = x.BusDate,
|
||||||
Rout = (int?)x.RoutId,
|
Rout = x.RoutName ?? string.Empty,
|
||||||
Cost = (decimal?)null
|
Cost = (decimal?)null
|
||||||
})
|
})
|
||||||
.Union(
|
.Union(
|
||||||
_toRepository
|
_toRepository
|
||||||
.ReadTo()
|
.ReadTo(dateForm: startDate, dateTo: endDate, busid: busId)
|
||||||
.Where(x => x.DateTo >= startDate && x.DateTo <= endDate && x.BusID == busId)
|
|
||||||
.Select(x => new {
|
.Select(x => new {
|
||||||
Date = x.DateTo,
|
Date = x.DateTo,
|
||||||
Rout = (int?)null,
|
Rout = string.Empty,
|
||||||
Cost = (decimal?)x.Cost
|
Cost = (decimal?)x.Cost
|
||||||
}))
|
}))
|
||||||
.OrderBy(x => x.Date);
|
.OrderBy(x => x.Date);
|
||||||
@ -82,9 +80,9 @@ internal class TableReport
|
|||||||
{
|
{
|
||||||
x.Date.ToString("dd.MM.yyyy"),
|
x.Date.ToString("dd.MM.yyyy"),
|
||||||
x.Rout?.ToString() ?? string.Empty,
|
x.Rout?.ToString() ?? string.Empty,
|
||||||
x.Cost?.ToString() ?? string.Empty
|
x.Cost?.ToString("N0") ?? string.Empty
|
||||||
}))
|
}))
|
||||||
.Union(new[] { new string[] { "Всего", "", data.Sum(x => x.Cost ?? 0).ToString() } })
|
.Union(new[] { new string[] { "Всего", "", data.Sum(x => x.Cost ?? 0).ToString("N0") } })
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PIbd_24_EredavkinRA_BusBusiness.Repositories.Implementations;
|
||||||
|
|
||||||
|
internal class QueryBuilder
|
||||||
|
{
|
||||||
|
private readonly StringBuilder _builder;
|
||||||
|
|
||||||
|
public QueryBuilder()
|
||||||
|
{
|
||||||
|
_builder = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryBuilder AddCondition(string condition)
|
||||||
|
{
|
||||||
|
if (_builder.Length > 0)
|
||||||
|
{
|
||||||
|
_builder.Append(" AND ");
|
||||||
|
}
|
||||||
|
|
||||||
|
_builder.Append(condition);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Build()
|
||||||
|
{
|
||||||
|
if (_builder.Length == 0)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $" WHERE {_builder}";
|
||||||
|
}
|
||||||
|
}
|
@ -58,12 +58,70 @@ public class RoutSheetRepository : IRoutSheetRepository
|
|||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateForm.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cs.BusDate >= @dateForm");
|
||||||
|
}
|
||||||
|
if (dateBus.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cs.BusDate <= @dateBus");
|
||||||
|
}
|
||||||
|
if (driverid.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cs.DriverId = @driverid");
|
||||||
|
}
|
||||||
|
if (conductorid.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cs.ConductorId = @conductorid");
|
||||||
|
}
|
||||||
|
if (busid.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("rsh.BusId = @busid");
|
||||||
|
}
|
||||||
|
if (routId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cs.RoutId = @routid");
|
||||||
|
}
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT cs.*, dcs.BusId FROM RoutSheet cs
|
var querySelect = $@"
|
||||||
INNER JOIN RoutSheetBus dcs ON dcs.RoutSheetId = cs.Id";
|
SELECT
|
||||||
var routsheet = connection.Query<TempRoutSheetBus>(querySelect);
|
cs.*,
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(routsheet));
|
CONCAT(s.FirstName, ' ', s.LastName) AS EmployeeNameDriver,
|
||||||
return routsheet.GroupBy(x => x.Id, y => y, (key, value) => RoutSheet.CreatOpeartion(value.First(), value.Select(z => RoutSheetBus.CreateElement(0, z.BusId)))).ToList();
|
CONCAT(c.FirstName, ' ', c.LastName) AS EmployeeNameConductor,
|
||||||
|
CONCAT(ro.NumberRout, ' ', ro.StartStop, ' ', ro.EndStop) AS RoutName,
|
||||||
|
rsh.BusId,
|
||||||
|
b.N_Z AS BusName
|
||||||
|
FROM RoutSheet cs
|
||||||
|
LEFT JOIN Staff s ON s.Id = cs.DriverId
|
||||||
|
LEFT JOIN Staff c ON c.Id = cs.ConductorId
|
||||||
|
LEFT JOIN Rout ro ON ro.Id = cs.RoutId
|
||||||
|
INNER JOIN RoutSheetBus rsh ON rsh.RoutSheetId = cs.Id
|
||||||
|
LEFT JOIN Bus b ON b.Id = rsh.BusId
|
||||||
|
{builder.Build()}";
|
||||||
|
var supplementDict = new Dictionary<int, List<RoutSheetBus>>();
|
||||||
|
|
||||||
|
var curriculumSupplements = connection.Query<RoutSheet, RoutSheetBus, RoutSheet>(querySelect,
|
||||||
|
(supplement, curriculumSupplements) =>
|
||||||
|
{
|
||||||
|
if (!supplementDict.TryGetValue(supplement.Id, out var rsh))
|
||||||
|
{
|
||||||
|
rsh = [];
|
||||||
|
supplementDict.Add(supplement.Id, rsh);
|
||||||
|
}
|
||||||
|
|
||||||
|
rsh.Add(curriculumSupplements);
|
||||||
|
return supplement;
|
||||||
|
}, splitOn: "BusId", param: new { dateForm, dateBus, routId, busid, driverid, conductorid });
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(curriculumSupplements));
|
||||||
|
|
||||||
|
return supplementDict.Select(x =>
|
||||||
|
{
|
||||||
|
var cs = curriculumSupplements.First(y => y.Id == x.Key);
|
||||||
|
cs.SetRoutSheetBus(x.Value);
|
||||||
|
return cs;
|
||||||
|
}).ToArray();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -3,11 +3,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
using PIbd_24_EredavkinRA_BusBusiness.Entities;
|
using PIbd_24_EredavkinRA_BusBusiness.Entities;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace PIbd_24_EredavkinRA_BusBusiness.Repositories.Implementations;
|
namespace PIbd_24_EredavkinRA_BusBusiness.Repositories.Implementations;
|
||||||
|
|
||||||
@ -65,9 +61,37 @@ public class ToRepository : IToRepository
|
|||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateForm.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cs.DateTo >= @dateForm");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cs.DateTo <= @dateTo");
|
||||||
|
}
|
||||||
|
if (staffid.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cs.StaffId = @staffid");
|
||||||
|
}
|
||||||
|
if (busid.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cs.BusId = @busid");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = "SELECT * FROM TOs";
|
var querySelect = $@"
|
||||||
var compilingSchedules = connection.Query<To>(querySelect);
|
SELECT
|
||||||
|
cs.*,
|
||||||
|
CONCAT(s.FirstName, ' ', s.LastName) AS StaffName,
|
||||||
|
b.N_Z AS BusName
|
||||||
|
FROM TOs cs
|
||||||
|
LEFT JOIN Bus b ON b.Id = cs.BusId
|
||||||
|
LEFT JOIN Staff s ON s.Id = cs.StaffId
|
||||||
|
{builder.Build()}";
|
||||||
|
|
||||||
|
var compilingSchedules = connection.Query<To>(querySelect, new { dateForm, dateTo, busid, staffid});
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(compilingSchedules));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(compilingSchedules));
|
||||||
return compilingSchedules;
|
return compilingSchedules;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user