LabWork 4.1.0 (Итог)
This commit is contained in:
parent
a5d0da4b75
commit
c178331965
@ -1,4 +1,5 @@
|
||||
using ProjectAutoenterprise.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
namespace ProjectAutoenterprise.Entities;
|
||||
|
||||
/// <summary>
|
||||
@ -7,8 +8,14 @@ namespace ProjectAutoenterprise.Entities;
|
||||
public class Bus
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Марка")]
|
||||
public string Brand { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Вместимость")]
|
||||
public int Capacity { get; private set; }
|
||||
|
||||
[DisplayName("Цвета")]
|
||||
public BusColors BusColors { get; private set; }
|
||||
|
||||
public static Bus CreateEntity(int id, string brand, int capacity, BusColors busColors)
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace ProjectAutoenterprise.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectAutoenterprise.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Сущность-операция "Ремонт автобуса"
|
||||
@ -6,8 +8,17 @@
|
||||
public class BusRepair
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int BusId { get; private set; }
|
||||
|
||||
[DisplayName("Марка автобуса")]
|
||||
public string BusBrand { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата ремонта")]
|
||||
public DateTime RepairDate { get; private set; }
|
||||
|
||||
[DisplayName("Описание")]
|
||||
public string Description { get; private set; } = string.Empty;
|
||||
|
||||
public static BusRepair CreateOperation(int id, int busId, string description)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ProjectAutoenterprise.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
namespace ProjectAutoenterprise.Entities;
|
||||
|
||||
/// <summary>
|
||||
@ -7,9 +8,19 @@ namespace ProjectAutoenterprise.Entities;
|
||||
public class Employee
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Имя")]
|
||||
public string FirstName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Фамилия")]
|
||||
public string LastName { get; private set; } = string.Empty;
|
||||
|
||||
public string FullName => $"{LastName} {FirstName}";
|
||||
|
||||
[DisplayName("Дата рождения")]
|
||||
public DateTime BirthDate { get; private set; }
|
||||
|
||||
[DisplayName("Должность")]
|
||||
public EmployeePost EmployeePost { get; private set; }
|
||||
|
||||
public static Employee CreateEntity(int id, string firstName, string lastName, DateTime birthDate, EmployeePost employeePost)
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace ProjectAutoenterprise.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectAutoenterprise.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Сущность-операция "Маршрутный лист"
|
||||
@ -6,11 +8,36 @@
|
||||
public class Itinerary
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int BusId { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public IEnumerable<ItineraryRoute> ItineraryRoutes { get; private set; } = [];
|
||||
|
||||
[Browsable(false)]
|
||||
public int DriverId { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int ConductorId { get; private set; }
|
||||
|
||||
[DisplayName("Марка автобуса")]
|
||||
public string BusBrand { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Полное имя водителя")]
|
||||
public string DriverFullName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Полное имя кондуктора")]
|
||||
public string ConductorFullName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Маршруты")]
|
||||
public string Routes => ItineraryRoutes != null ?
|
||||
string.Join(", ", ItineraryRoutes.Select(x => $"{x.RouteId}")) : string.Empty;
|
||||
|
||||
[DisplayName("Дата")]
|
||||
public DateTime ItineraryDate { get; private set; }
|
||||
|
||||
[DisplayName("Описание")]
|
||||
public string Description { get; private set; } = string.Empty;
|
||||
|
||||
public static Itinerary CreateOperation(int id, int busId, int driverId, int conductorId, DateTime itineraryDate, string description,
|
||||
@ -27,7 +54,16 @@ public class Itinerary
|
||||
Description = description ?? string.Empty
|
||||
};
|
||||
}
|
||||
public static Itinerary CreateOpeartion(TempItineraryRoute tempItineraryRoute, IEnumerable<ItineraryRoute> itineraryRoutes)
|
||||
|
||||
public void SetItineraryRoutes(IEnumerable<ItineraryRoute> itineraryRoutes)
|
||||
{
|
||||
if (itineraryRoutes != null && itineraryRoutes.Any())
|
||||
{
|
||||
ItineraryRoutes = itineraryRoutes;
|
||||
}
|
||||
}
|
||||
|
||||
/*public static Itinerary CreateOpeartion(TempItineraryRoute tempItineraryRoute, IEnumerable<ItineraryRoute> itineraryRoutes)
|
||||
{
|
||||
return new Itinerary
|
||||
{
|
||||
@ -39,5 +75,5 @@ public class Itinerary
|
||||
Description = tempItineraryRoute.Description,
|
||||
ItineraryRoutes = itineraryRoutes
|
||||
};
|
||||
}
|
||||
}*/
|
||||
}
|
@ -8,6 +8,8 @@ public class ItineraryRoute
|
||||
public int ItineraryId { get; private set; }
|
||||
public int RouteId { get; private set; }
|
||||
|
||||
public string RoutePoints { get; private set; } = string.Empty;
|
||||
|
||||
public static ItineraryRoute CreateElement(int itineraryId, int routeId)
|
||||
{
|
||||
return new ItineraryRoute
|
||||
|
@ -1,4 +1,7 @@
|
||||
namespace ProjectAutoenterprise.Entities;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectAutoenterprise.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Сущность-справочник "Маршрут"
|
||||
@ -6,9 +9,15 @@
|
||||
public class Route
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Начальная точка маршрута")]
|
||||
public string BeginRoutePoint { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Конечная точка маршрута")]
|
||||
public string EndRoutePoint { get; private set; } = string.Empty;
|
||||
|
||||
public string RoutePoints => $"{BeginRoutePoint} - {EndRoutePoint}";
|
||||
|
||||
public static Route CreateEntity(int id, string beginRoutePoint, string endRoutePoint)
|
||||
{
|
||||
return new Route
|
||||
|
@ -9,9 +9,9 @@ public partial class FormBusRepair : Form
|
||||
{
|
||||
InitializeComponent();
|
||||
_busRepairRepository = busRepairRepository ??
|
||||
throw new ArgumentNullException(nameof(busRepairRepository));
|
||||
throw new ArgumentNullException(nameof(busRepairRepository));
|
||||
comboBoxBus.DataSource = busRepository.ReadBuses();
|
||||
comboBoxBus.DisplayMember = "Id";
|
||||
comboBoxBus.DisplayMember = "BusBrand";
|
||||
comboBoxBus.ValueMember = "Id";
|
||||
}
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
|
@ -10,9 +10,9 @@ public partial class FormBusRepairs : Form
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
_busRepairRepository = busRepairRepository ??
|
||||
throw new ArgumentNullException(nameof(busRepairRepository));
|
||||
throw new ArgumentNullException(nameof(busRepairRepository));
|
||||
}
|
||||
private void FormBusRepairs_Load(object sender, EventArgs e)
|
||||
{
|
||||
@ -37,5 +37,9 @@ public partial class FormBusRepairs : Form
|
||||
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _busRepairRepository.ReadBusRepairs();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _busRepairRepository.ReadBusRepairs();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
}
|
||||
}
|
@ -75,7 +75,12 @@ public partial class FormBuses : Form
|
||||
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _busRepository.ReadBuses();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _busRepository.ReadBuses();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -76,7 +76,13 @@ public partial class FormEmployees : Form
|
||||
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridViewData.DataSource = _employeeRepository.ReadEmployees();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _employeeRepository.ReadEmployees();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["FullName"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -10,9 +10,9 @@ public partial class FormItineraries : Form
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
_itineraryRepository = itineraryRepository ??
|
||||
throw new ArgumentNullException(nameof(itineraryRepository));
|
||||
throw new ArgumentNullException(nameof(itineraryRepository));
|
||||
}
|
||||
|
||||
private void FormItinerarys_Load(object sender, EventArgs e)
|
||||
@ -61,7 +61,12 @@ public partial class FormItineraries : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _itineraryRepository.ReadItinerary();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _itineraryRepository.ReadItinerary();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["RoutePoints"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -30,6 +30,7 @@
|
||||
{
|
||||
groupBoxRoutes = new GroupBox();
|
||||
dataGridViewRoutes = new DataGridView();
|
||||
ColumnRoute = new DataGridViewComboBoxColumn();
|
||||
comboBoxBus = new ComboBox();
|
||||
label1 = new Label();
|
||||
comboBoxDriver = new ComboBox();
|
||||
@ -42,7 +43,6 @@
|
||||
label5 = new Label();
|
||||
buttonCancel = new Button();
|
||||
buttonSave = new Button();
|
||||
ColumnRoute = new DataGridViewComboBoxColumn();
|
||||
groupBoxRoutes.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewRoutes).BeginInit();
|
||||
SuspendLayout();
|
||||
@ -51,9 +51,9 @@
|
||||
//
|
||||
groupBoxRoutes.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
groupBoxRoutes.Controls.Add(dataGridViewRoutes);
|
||||
groupBoxRoutes.Location = new Point(333, 12);
|
||||
groupBoxRoutes.Location = new Point(17, 251);
|
||||
groupBoxRoutes.Name = "groupBoxRoutes";
|
||||
groupBoxRoutes.Size = new Size(259, 202);
|
||||
groupBoxRoutes.Size = new Size(575, 235);
|
||||
groupBoxRoutes.TabIndex = 0;
|
||||
groupBoxRoutes.TabStop = false;
|
||||
groupBoxRoutes.Text = "Маршруты";
|
||||
@ -66,9 +66,15 @@
|
||||
dataGridViewRoutes.Dock = DockStyle.Fill;
|
||||
dataGridViewRoutes.Location = new Point(3, 19);
|
||||
dataGridViewRoutes.Name = "dataGridViewRoutes";
|
||||
dataGridViewRoutes.Size = new Size(253, 180);
|
||||
dataGridViewRoutes.Size = new Size(569, 213);
|
||||
dataGridViewRoutes.TabIndex = 0;
|
||||
//
|
||||
// ColumnRoute
|
||||
//
|
||||
ColumnRoute.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
ColumnRoute.HeaderText = "Маршрут";
|
||||
ColumnRoute.Name = "ColumnRoute";
|
||||
//
|
||||
// comboBoxBus
|
||||
//
|
||||
comboBoxBus.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
@ -147,17 +153,17 @@
|
||||
// textBoxDescription
|
||||
//
|
||||
textBoxDescription.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
textBoxDescription.Location = new Point(122, 251);
|
||||
textBoxDescription.Location = new Point(338, 43);
|
||||
textBoxDescription.Multiline = true;
|
||||
textBoxDescription.Name = "textBoxDescription";
|
||||
textBoxDescription.Size = new Size(467, 108);
|
||||
textBoxDescription.Size = new Size(254, 177);
|
||||
textBoxDescription.TabIndex = 20;
|
||||
//
|
||||
// label5
|
||||
//
|
||||
label5.AutoSize = true;
|
||||
label5.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204);
|
||||
label5.Location = new Point(32, 249);
|
||||
label5.Location = new Point(423, 9);
|
||||
label5.Name = "label5";
|
||||
label5.Size = new Size(84, 21);
|
||||
label5.TabIndex = 19;
|
||||
@ -166,7 +172,7 @@
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCancel.Location = new Point(477, 399);
|
||||
buttonCancel.Location = new Point(477, 492);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(112, 30);
|
||||
buttonCancel.TabIndex = 22;
|
||||
@ -177,7 +183,7 @@
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonSave.Location = new Point(17, 399);
|
||||
buttonSave.Location = new Point(17, 492);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(111, 30);
|
||||
buttonSave.TabIndex = 21;
|
||||
@ -185,17 +191,11 @@
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// ColumnRoute
|
||||
//
|
||||
ColumnRoute.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
ColumnRoute.HeaderText = "Маршрут";
|
||||
ColumnRoute.Name = "ColumnRoute";
|
||||
//
|
||||
// FormItinerary
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(604, 441);
|
||||
ClientSize = new Size(604, 534);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(textBoxDescription);
|
||||
@ -209,7 +209,7 @@
|
||||
Controls.Add(comboBoxBus);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(groupBoxRoutes);
|
||||
MaximumSize = new Size(800, 500);
|
||||
MaximumSize = new Size(800, 900);
|
||||
MinimumSize = new Size(620, 480);
|
||||
Name = "FormItinerary";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
|
@ -18,15 +18,15 @@ public partial class FormItinerary : Form
|
||||
comboBoxBus.ValueMember = "Id";
|
||||
|
||||
comboBoxDriver.DataSource = employeeRepository.ReadEmployees(EmployeePost.Driver);
|
||||
comboBoxDriver.DisplayMember = "FirstName";
|
||||
comboBoxDriver.DisplayMember = "FullName";
|
||||
comboBoxDriver.ValueMember = "Id";
|
||||
|
||||
comboBoxConductor.DataSource = employeeRepository.ReadEmployees(EmployeePost.Conductor);
|
||||
comboBoxConductor.DisplayMember = "FirstName";
|
||||
comboBoxConductor.DisplayMember = "FullName";
|
||||
comboBoxConductor.ValueMember = "Id";
|
||||
|
||||
ColumnRoute.DataSource = routeRepository.ReadRoutes();
|
||||
ColumnRoute.DisplayMember = "Id";
|
||||
ColumnRoute.DisplayMember = "RoutePoints";
|
||||
ColumnRoute.ValueMember = "Id";
|
||||
}
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
|
@ -81,7 +81,11 @@ public partial class FormRoutes : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _routeRepository.ReadRoutes();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _routeRepository.ReadRoutes();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ internal class ChartReport
|
||||
{
|
||||
new PdfBuilder(filePath)
|
||||
.AddHeader("Ремонт автобусов")
|
||||
.AddPieChart("Отремонтированные автобусы", GetData(startDate, endDate))
|
||||
.AddPieChart($"за период c {startDate:dd.MM.yyyy} по {endDate: dd.MM.yyyy}", GetData(startDate, endDate))
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
@ -33,10 +33,9 @@ internal class ChartReport
|
||||
private List<(string Caption, double Value)> GetData(DateTime startDate, DateTime endDate)
|
||||
{
|
||||
return _busRepairRepository
|
||||
.ReadBusRepairs()
|
||||
.Where(x => x.RepairDate >= startDate && x.RepairDate <= endDate)
|
||||
.GroupBy(x => x.BusId, (key, group) => new { Id = key, Count = group.Count() })
|
||||
.Select(x => (x.Id.ToString(), (double)x.Count))
|
||||
.ReadBusRepairs(startDate, endDate)
|
||||
.GroupBy(x => x.BusBrand, (key, group) => new { BusBrand = key, Count = group.Count() })
|
||||
.Select(x => (x.BusBrand.ToString(), (double)x.Count))
|
||||
.ToList();
|
||||
}
|
||||
}
|
@ -67,7 +67,7 @@ internal class DocReport
|
||||
return [
|
||||
["Имя", "Фамилия", "Дата рождения", "Должность"],
|
||||
.. _employeeRepository.ReadEmployees().Select(x => new string[]
|
||||
{ x.FirstName, x.LastName, x.BirthDate.ToString("dd-MM-yyyy"), x.EmployeePost.ToString()}),
|
||||
{ x.FirstName, x.LastName, x.BirthDate.ToString("dd.MM.yyyy"), x.EmployeePost.ToString()}),
|
||||
];
|
||||
}
|
||||
private List<string[]> GetBuses()
|
||||
|
@ -8,7 +8,6 @@ namespace ProjectAutoenterprise.Reports;
|
||||
internal class TableReport
|
||||
{
|
||||
private readonly IItineraryRepository _itineraryRepository;
|
||||
private readonly IBusRepository _busRepository;
|
||||
private readonly ILogger<TableReport> _logger;
|
||||
internal static readonly string[] item = ["Дата", "Id Автобуса", "Id Водителя", "Id Кондуктора", "Кол-во маршрутов"];
|
||||
public TableReport(IItineraryRepository itineraryRepository,
|
||||
@ -16,8 +15,6 @@ internal class TableReport
|
||||
{
|
||||
_itineraryRepository = itineraryRepository ??
|
||||
throw new ArgumentNullException(nameof(itineraryRepository));
|
||||
_busRepository = busRepository ??
|
||||
throw new ArgumentNullException(nameof(busRepository));
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
@ -28,7 +25,7 @@ internal class TableReport
|
||||
{
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader("Сводка по поездкам автобуса", 0, 5)
|
||||
.AddParagraph("за период", 0)
|
||||
.AddParagraph($"за период c {startDate:dd.MM.yyyy} по { endDate: dd.MM.yyyy}", 0)
|
||||
.AddTable([10, 10, 10, 10, 10], GetData(busId, startDate, endDate))
|
||||
.Build();
|
||||
return true;
|
||||
@ -43,8 +40,7 @@ internal class TableReport
|
||||
{
|
||||
|
||||
var data = _itineraryRepository
|
||||
.ReadItinerary()
|
||||
.Where(x => x.ItineraryDate >= startDate && x.ItineraryDate <= endDate && x.BusId == busId)
|
||||
.ReadItinerary(startDate, endDate, busId)
|
||||
.Select(x => new
|
||||
{
|
||||
Date = x.ItineraryDate,
|
||||
@ -58,7 +54,7 @@ internal class TableReport
|
||||
new List<string[]>() { item }
|
||||
.Union(
|
||||
data
|
||||
.Select(x => new string[] { x.Date.ToString("dd-MM-yyyy"), x.BusId.ToString(), x.DriverId.ToString(), x.ConductorId.ToString(), x.CountRoutes.ToString()}))
|
||||
.Select(x => new string[] { x.Date.ToString("dd.MM.yyyy"), x.BusId.ToString(), x.DriverId.ToString(), x.ConductorId.ToString(), x.CountRoutes.ToString()}))
|
||||
.Union(
|
||||
[["Всего", "", "", "", data.Sum(x => x.CountRoutes ?? 0).ToString()]])
|
||||
.ToList();
|
||||
|
@ -5,5 +5,5 @@ public interface IBusRepairRepository
|
||||
{
|
||||
void CreateBusRepair(BusRepair busRepair);
|
||||
IEnumerable<BusRepair> ReadBusRepairs(DateTime? dateForm = null, DateTime? dateTo = null,
|
||||
int? busId = null, string? description = null);
|
||||
int? busId = null);
|
||||
}
|
@ -4,7 +4,7 @@ namespace ProjectAutoenterprise.Repositories;
|
||||
public interface IItineraryRepository
|
||||
{
|
||||
IEnumerable<Itinerary> ReadItinerary(DateTime? dateForm = null, DateTime? dateTo = null,
|
||||
int? driverId = null, int? conductorId = null);
|
||||
int? busId = null, int? driverId = null, int? conductorId = null, int? routeId = null);
|
||||
void CreateItinerary(Itinerary itinerary);
|
||||
void DeleteItinerary(int id);
|
||||
}
|
@ -3,7 +3,6 @@ using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectAutoenterprise.Entities;
|
||||
using System.Data.SqlClient;
|
||||
namespace ProjectAutoenterprise.Repositories.Implementations;
|
||||
|
||||
internal class BusRepairRepository : IBusRepairRepository
|
||||
@ -35,14 +34,31 @@ VALUES (@BusId, @RepairDate, @Description)";
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public IEnumerable<BusRepair> ReadBusRepairs(DateTime? dateForm = null, DateTime? dateTo = null, int? busId = null, string? description = null)
|
||||
public IEnumerable<BusRepair> ReadBusRepairs(DateTime? dateForm = null, DateTime? dateTo = null, int? busId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (dateForm.HasValue)
|
||||
{
|
||||
builder.AddCondition("br.RepairDate >= @dateForm");
|
||||
}
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("br.RepairDate <= @dateTo");
|
||||
}
|
||||
if (busId.HasValue)
|
||||
{
|
||||
builder.AddCondition("br.BusId = @busId");
|
||||
}
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM BusRepairs";
|
||||
var busRepairss = connection.Query<BusRepair>(querySelect);
|
||||
var querySelect = $@"
|
||||
SELECT br.*, b.Brand as BusBrand
|
||||
FROM BusRepairs br
|
||||
LEFT JOIN Buses b on b.Id = br.BusId
|
||||
{builder.Build()}";
|
||||
var busRepairss = connection.Query<BusRepair>(querySelect, new { dateForm, dateTo, busId });
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(busRepairss));
|
||||
return busRepairss;
|
||||
}
|
||||
|
@ -67,16 +67,82 @@ WHERE Id=@id";
|
||||
}
|
||||
|
||||
public IEnumerable<Itinerary> ReadItinerary(
|
||||
DateTime? dateForm = null, DateTime? dateTo = null, int? driverId = null, int? conductorId = null)
|
||||
DateTime? dateForm = null, DateTime? dateTo = null, int? busId = null, int? driverId = null, int? conductorId = null, int? routeId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (dateForm.HasValue)
|
||||
{
|
||||
builder.AddCondition("i.ItineraryDate >= @dateForm");
|
||||
}
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("i.ItineraryDate <= @dateTo");
|
||||
}
|
||||
if (driverId.HasValue)
|
||||
{
|
||||
builder.AddCondition("i.DriverId = @driverId");
|
||||
}
|
||||
if (conductorId.HasValue)
|
||||
{
|
||||
builder.AddCondition("i.ConductorId = @conductorId");
|
||||
}
|
||||
if (busId.HasValue)
|
||||
{
|
||||
builder.AddCondition("i.BusId = @busId");
|
||||
}
|
||||
if (routeId.HasValue)
|
||||
{
|
||||
builder.AddCondition("ir.RouteId = @routeId");
|
||||
}
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT it.*, itr.RouteId FROM Itineraries it
|
||||
INNER JOIN ItineraryRoutes itr ON itr.ItineraryId = it.Id";
|
||||
var itineraries = connection.Query<TempItineraryRoute>(querySelect);
|
||||
var querySelect = $@"
|
||||
SELECT
|
||||
i.*,
|
||||
b.Brand as BusBrand,
|
||||
CONCAT(d.LastName, ' ', d.FirstName) as DriverFullName,
|
||||
CONCAT(c.LastName, ' ', c.FirstName) as ConductorFullName,
|
||||
ir.RouteId,
|
||||
CONCAT(r.BeginRoutePoint, ' - ', r.EndRoutePoint) as RoutePoints
|
||||
FROM Itineraries i
|
||||
LEFT JOIN Buses b ON b.Id = i.BusId
|
||||
LEFT JOIN Employees d ON d.Id = i.DriverId AND d.EmployeePost = 'Driver'
|
||||
LEFT JOIN Employees c ON c.Id = i.ConductorId AND c.EmployeePost = 'Conductor'
|
||||
INNER JOIN ItineraryRoutes ir ON ir.ItineraryId = i.Id
|
||||
LEFT JOIN Routes r ON r.Id = ir.RouteId
|
||||
{builder.Build()}";
|
||||
var itineraryDict = new Dictionary<int, List<ItineraryRoute>>();
|
||||
var itineraries = connection.Query<Itinerary, ItineraryRoute, Itinerary>(querySelect,
|
||||
(itinerary, itineraries) =>
|
||||
{
|
||||
if (!itineraryDict.TryGetValue(itinerary.Id, out var ir))
|
||||
{
|
||||
ir = [];
|
||||
itineraryDict.Add(itinerary.Id, ir);
|
||||
}
|
||||
ir.Add(itineraries);
|
||||
return itinerary;
|
||||
},
|
||||
splitOn: "RouteId",
|
||||
param: new { dateForm, dateTo, driverId, conductorId, routeId });
|
||||
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(itineraries));
|
||||
return itineraryDict.Select(x =>
|
||||
{
|
||||
var i = itineraries.First(y => y.Id == x.Key);
|
||||
i.SetItineraryRoutes(x.Value);
|
||||
return i;
|
||||
}).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
/*
|
||||
var itineraries = connection.Query<TempItineraryRoute>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(itineraries));
|
||||
|
||||
return itineraries.GroupBy(x => x.Id, y => y, (key, value) => Itinerary.CreateOpeartion(
|
||||
@ -86,6 +152,6 @@ INNER JOIN ItineraryRoutes itr ON itr.ItineraryId = it.Id";
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
using System.Text;
|
||||
|
||||
namespace ProjectAutoenterprise.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}";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user