Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b3e7566669 | |||
| 09194c7bf9 |
@@ -1,6 +1,5 @@
|
|||||||
using ProjectTransportation.Entities;
|
using ProjectTransportation.Entities.Enums;
|
||||||
using System.Reflection;
|
using System.ComponentModel;
|
||||||
using System.Runtime.InteropServices.JavaScript;
|
|
||||||
|
|
||||||
namespace ProjectTransportation.Entities;
|
namespace ProjectTransportation.Entities;
|
||||||
|
|
||||||
@@ -8,9 +7,14 @@ public class Bus
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Госномер")]
|
||||||
public string Licence_plate { get; private set; } = string.Empty;
|
public string Licence_plate { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Модель автобуса")]
|
||||||
public string Model { get; private set; } = string.Empty;
|
public string Model { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Model_and_plate => $"{Model} {Licence_plate}";
|
||||||
|
|
||||||
public static Bus CreateEntity(int id, string licencePlate, string model)
|
public static Bus CreateEntity(int id, string licencePlate, string model)
|
||||||
{
|
{
|
||||||
return new Bus
|
return new Bus
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using ProjectTransportation.Entities.Enums;
|
using DocumentFormat.OpenXml.Wordprocessing;
|
||||||
|
using ProjectTransportation.Entities.Enums;
|
||||||
using ProjectTransportation.Entities;
|
using ProjectTransportation.Entities;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace ProjectTransportation.Entities;
|
namespace ProjectTransportation.Entities;
|
||||||
|
|
||||||
@@ -7,10 +9,15 @@ public class Employee
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Имя")]
|
||||||
public string First_name { get; private set; } = string.Empty;
|
public string First_name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Фамилия")]
|
||||||
public string Last_name { get; private set; } = string.Empty;
|
public string Last_name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Full_name => $"{Last_name} {First_name}";
|
||||||
|
|
||||||
|
[DisplayName("Должность")]
|
||||||
public EmployeePost Post { get; private set; }
|
public EmployeePost Post { get; private set; }
|
||||||
|
|
||||||
public static Employee CreateEntity(int id, string first, string last, EmployeePost post)
|
public static Employee CreateEntity(int id, string first, string last, EmployeePost post)
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
namespace ProjectTransportation.Entities;
|
|
||||||
|
|
||||||
public class TempStartingShiftEmployee
|
|
||||||
{
|
|
||||||
public int Starting_shift_id { get; private set; }
|
|
||||||
|
|
||||||
public int Employee_id { get; private set; }
|
|
||||||
|
|
||||||
public int Route_list_id { get; private set; }
|
|
||||||
|
|
||||||
public int Bus_id { get; private set; }
|
|
||||||
|
|
||||||
public DateTime Date { get; private set; }
|
|
||||||
|
|
||||||
public int Work_time { get; private set; }
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using ProjectTransportation.Entities.Enums;
|
using ProjectTransportation.Entities.Enums;
|
||||||
using System;
|
using ProjectTransportation.Entities.Enums;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace ProjectTransportation.Entities;
|
namespace ProjectTransportation.Entities;
|
||||||
|
|
||||||
@@ -7,20 +8,27 @@ public class GoToService
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
public DateTime Date { get; private set; }
|
[Browsable(false)]
|
||||||
|
|
||||||
public BrokenElements Broken_elements { get; private set; }
|
|
||||||
|
|
||||||
public int Price { get; private set; }
|
|
||||||
|
|
||||||
public int Bus_id { get; private set; }
|
public int Bus_id { get; private set; }
|
||||||
|
|
||||||
public static GoToService CreateOperation(int id, BrokenElements brokenElements, int price, int busId, DateTime date)
|
[DisplayName("Автобус")]
|
||||||
|
public string Bus_name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Сломанные элементы")]
|
||||||
|
public BrokenElements Broken_elements { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Стоимость")]
|
||||||
|
public int Price { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Дата тех обслуживания")]
|
||||||
|
public DateTime Date { get; private set; }
|
||||||
|
|
||||||
|
public static GoToService CreateOperation(int id, BrokenElements brokenElements, int price, int busId)
|
||||||
{
|
{
|
||||||
return new GoToService
|
return new GoToService
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Date = date,
|
Date = DateTime.Now,
|
||||||
Broken_elements = brokenElements,
|
Broken_elements = brokenElements,
|
||||||
Price = price,
|
Price = price,
|
||||||
Bus_id = busId
|
Bus_id = busId
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
namespace ProjectTransportation.Entities;
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ProjectTransportation.Entities;
|
||||||
|
|
||||||
public class RouteList
|
public class RouteList
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Начало маршрута")]
|
||||||
public TimeSpan Route_start { get; private set; }
|
public TimeSpan Route_start { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Конец маршрута")]
|
||||||
public TimeSpan Route_finish { get; private set; }
|
public TimeSpan Route_finish { get; private set; }
|
||||||
|
|
||||||
|
public string Route_time => $"{Route_start}-{Route_finish}";
|
||||||
|
|
||||||
public static RouteList CreateEntity(int id, TimeSpan start, TimeSpan finish)
|
public static RouteList CreateEntity(int id, TimeSpan start, TimeSpan finish)
|
||||||
{
|
{
|
||||||
return new RouteList
|
return new RouteList
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using ProjectTransportation.Entities;
|
using ProjectTransportation.Entities;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace ProjectTransportation.Entities;
|
namespace ProjectTransportation.Entities;
|
||||||
|
|
||||||
@@ -6,12 +7,26 @@ public class StartingShift
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
public DateTime Date { get; private set; }
|
[Browsable(false)]
|
||||||
|
|
||||||
public int Route_list_id { get; private set; }
|
public int Route_list_id { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int Bus_id { get; private set; }
|
public int Bus_id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Маршрутный лист")]
|
||||||
|
public string Route_list_name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Автобус")]
|
||||||
|
public string Bus_name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Дата смены")]
|
||||||
|
public DateTime Date { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Работники")]
|
||||||
|
public string Employee => Starting_shift_employees != null ?
|
||||||
|
string.Join(", ", Starting_shift_employees.Select(x => $"{x.Employee_name} {x.Work_time}")) : string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public IEnumerable<StartingShiftEmployee> Starting_shift_employees { get; private set; } = [];
|
public IEnumerable<StartingShiftEmployee> Starting_shift_employees { get; private set; } = [];
|
||||||
|
|
||||||
public static StartingShift CreateOperation(int id, int routeListId, int busId,
|
public static StartingShift CreateOperation(int id, int routeListId, int busId,
|
||||||
@@ -27,16 +42,11 @@ public class StartingShift
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StartingShift CreateOperation(TempStartingShiftEmployee tempStartingShiftEmployee,
|
public void SetStartingShiftEmployee(IEnumerable<StartingShiftEmployee> startingShiftEmployee)
|
||||||
IEnumerable<StartingShiftEmployee> startingShiftEmployee)
|
|
||||||
{
|
{
|
||||||
return new StartingShift
|
if (startingShiftEmployee != null && startingShiftEmployee.Any())
|
||||||
{
|
{
|
||||||
Id = tempStartingShiftEmployee.Starting_shift_id,
|
Starting_shift_employees = startingShiftEmployee;
|
||||||
Date = tempStartingShiftEmployee.Date,
|
}
|
||||||
Route_list_id = tempStartingShiftEmployee.Route_list_id,
|
|
||||||
Bus_id = tempStartingShiftEmployee.Bus_id,
|
|
||||||
Starting_shift_employees = startingShiftEmployee
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace ProjectTransportation.Entities;
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ProjectTransportation.Entities;
|
||||||
|
|
||||||
public class StartingShiftEmployee
|
public class StartingShiftEmployee
|
||||||
{
|
{
|
||||||
@@ -6,6 +8,8 @@ public class StartingShiftEmployee
|
|||||||
|
|
||||||
public int Employee_id { get; private set; }
|
public int Employee_id { get; private set; }
|
||||||
|
|
||||||
|
public string Employee_name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public int Work_time { get; private set; }
|
public int Work_time { get; private set; }
|
||||||
|
|
||||||
public static StartingShiftEmployee CreateElement(int startingShiftId, int employeeId, int workTime)
|
public static StartingShiftEmployee CreateElement(int startingShiftId, int employeeId, int workTime)
|
||||||
|
|||||||
@@ -85,7 +85,12 @@ namespace ProjectTransportation.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _busRepository.ReadBuses();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _busRepository.ReadBuses();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["Model_and_plate"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -85,7 +85,12 @@ namespace ProjectTransportation.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _employeeRepository.ReadEmployees();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _employeeRepository.ReadEmployees();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["Full_name"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using ProjectTransportation.Entities;
|
using ProjectTransportation.Entities;
|
||||||
using ProjectTransportation.Entities.Enums;
|
using ProjectTransportation.Entities.Enums;
|
||||||
using ProjectTransportation.Repositories;
|
using ProjectTransportation.Repositories;
|
||||||
|
using ProjectTransportation.Entities.Enums;
|
||||||
|
using ProjectTransportation.Entities;
|
||||||
using ProjectTransportation.Repositories;
|
using ProjectTransportation.Repositories;
|
||||||
|
|
||||||
namespace ProjectTransportation.Forms
|
namespace ProjectTransportation.Forms
|
||||||
@@ -14,7 +16,7 @@ namespace ProjectTransportation.Forms
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_goToServiceRepository = goToServiceRepository ?? throw new ArgumentNullException(nameof(goToServiceRepository));
|
_goToServiceRepository = goToServiceRepository ?? throw new ArgumentNullException(nameof(goToServiceRepository));
|
||||||
comboBoxBus.DataSource = busRepository.ReadBuses();
|
comboBoxBus.DataSource = busRepository.ReadBuses();
|
||||||
comboBoxBus.DisplayMember = "LicensePlate";
|
comboBoxBus.DisplayMember = "Model_and_plate";
|
||||||
comboBoxBus.ValueMember = "Id";
|
comboBoxBus.ValueMember = "Id";
|
||||||
foreach (var elem in Enum.GetValues(typeof(BrokenElements)))
|
foreach (var elem in Enum.GetValues(typeof(BrokenElements)))
|
||||||
{
|
{
|
||||||
@@ -37,16 +39,12 @@ namespace ProjectTransportation.Forms
|
|||||||
brokenElements |= (BrokenElements)elem;
|
brokenElements |= (BrokenElements)elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime selectedDate = dateTimePickerServiceDate.Value.Date;
|
|
||||||
|
|
||||||
_goToServiceRepository.CreateGoToService(GoToService.CreateOperation(0,
|
_goToServiceRepository.CreateGoToService(GoToService.CreateOperation(0,
|
||||||
brokenElements,
|
brokenElements,
|
||||||
Convert.ToInt32(numericUpDownPrice.Value),
|
Convert.ToInt32(numericUpDownPrice.Value),
|
||||||
(int)comboBoxBus.SelectedValue!,
|
(int)comboBoxBus.SelectedValue!));
|
||||||
selectedDate));
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
|||||||
@@ -65,7 +65,13 @@ public partial class FormGoToServices : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _goToServiceRepository.ReadServices();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _goToServiceRepository.ReadServices();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["Date"].DefaultCellStyle.Format = "dd.MM.yyyy";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -85,7 +85,12 @@ namespace ProjectTransportation.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _routeListRepository.ReadRouteLists();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _routeListRepository.ReadRouteLists();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["Route_time"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ namespace ProjectTransportation.Forms
|
|||||||
comboBoxRouteList.DisplayMember = "Id";
|
comboBoxRouteList.DisplayMember = "Id";
|
||||||
comboBoxRouteList.ValueMember = "Id";
|
comboBoxRouteList.ValueMember = "Id";
|
||||||
comboBoxBus.DataSource = busRepository.ReadBuses();
|
comboBoxBus.DataSource = busRepository.ReadBuses();
|
||||||
comboBoxBus.DisplayMember = "Licence_plate";
|
comboBoxBus.DisplayMember = "Model_and_plate";
|
||||||
comboBoxBus.ValueMember = "Id";
|
comboBoxBus.ValueMember = "Id";
|
||||||
ColumnEmployees.DataSource = employeeRepository.ReadEmployees();
|
ColumnEmployees.DataSource = employeeRepository.ReadEmployees();
|
||||||
ColumnEmployees.DisplayMember = "First_name";
|
ColumnEmployees.DisplayMember = "Full_name";
|
||||||
ColumnEmployees.ValueMember = "Id";
|
ColumnEmployees.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,5 +42,10 @@ public partial class FormStartingShifts : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _startingShiftRepository.ReadShifts();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _startingShiftRepository.ReadShifts();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["Date"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ namespace ProjectTransportation.Forms
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||||
comboBoxEmployee.DataSource = employeeRepository.ReadEmployees();
|
comboBoxEmployee.DataSource = employeeRepository.ReadEmployees();
|
||||||
comboBoxEmployee.DisplayMember = "First_name";
|
comboBoxEmployee.DisplayMember = "Full_name";
|
||||||
comboBoxEmployee.ValueMember = "Id";
|
comboBoxEmployee.ValueMember = "Id";
|
||||||
comboBoxBus.DataSource = busRepository.ReadBuses();
|
comboBoxBus.DataSource = busRepository.ReadBuses();
|
||||||
comboBoxBus.DisplayMember = "Licence_plate";
|
comboBoxBus.DisplayMember = "Model_and_plate";
|
||||||
comboBoxBus.ValueMember = "Id";
|
comboBoxBus.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using ProjectTransportation.Repositories;
|
using ProjectTransportation.Repositories;
|
||||||
|
using ProjectTransportation.Reports;
|
||||||
using ProjectTransportation.Repositories;
|
using ProjectTransportation.Repositories;
|
||||||
using System.Reflection.PortableExecutable;
|
|
||||||
|
|
||||||
namespace ProjectTransportation.Reports;
|
namespace ProjectTransportation.Reports;
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ public class ChartReport
|
|||||||
{
|
{
|
||||||
new PdfBuilder(filePath)
|
new PdfBuilder(filePath)
|
||||||
.AddHeader("Тех обслуживание")
|
.AddHeader("Тех обслуживание")
|
||||||
.AddPieChart("Количество неисправных элементов", GetData(dateTime))
|
.AddPieChart($"Количество неисправных элементов на {dateTime:dd MMMM yyyy}", GetData(dateTime))
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -38,9 +38,9 @@ public class ChartReport
|
|||||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||||
{
|
{
|
||||||
return _goToServiceRepository
|
return _goToServiceRepository
|
||||||
.ReadServices()
|
.ReadServices(dateFrom: dateTime.Date, dateTo: dateTime.Date.AddDays(1))
|
||||||
.Where(x => x.Date.Date == dateTime.Date)
|
.Where(x => x.Date.Date == dateTime.Date)
|
||||||
.GroupBy(x => x.Bus_id, (key, group) => new {
|
.GroupBy(x => x.Bus_name, (key, group) => new {
|
||||||
Id = key,
|
Id = key,
|
||||||
Elements = group.Sum(x => (double)x.Broken_elements)
|
Elements = group.Sum(x => (double)x.Broken_elements)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using MigraDoc.DocumentObjectModel;
|
using MigraDoc.DocumentObjectModel;
|
||||||
using MigraDoc.DocumentObjectModel.Shapes.Charts;
|
using MigraDoc.DocumentObjectModel.Shapes.Charts;
|
||||||
using MigraDoc.Rendering;
|
using MigraDoc.Rendering;
|
||||||
using System.Text;
|
using System.Text; /// вот тут спрятан класс stringbuilder
|
||||||
|
|
||||||
namespace ProjectTransportation.Reports;
|
namespace ProjectTransportation.Reports;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using ProjectTransportation.Repositories;
|
using ProjectTransportation.Repositories;
|
||||||
using ProjectTransportation.Reports;
|
using ProjectTransportation.Reports;
|
||||||
using ProjectTransportation.Repositories;
|
using ProjectTransportation.Repositories;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace ProjectTransportation.Reports;
|
namespace ProjectTransportation.Reports;
|
||||||
|
|
||||||
@@ -28,8 +29,8 @@ public class TableReport
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
new ExcelBuilder(filePath)
|
new ExcelBuilder(filePath)
|
||||||
.AddHeader("Таблица по работникам и автобусам", 0, 5)
|
.AddHeader("Сводка по работникам и автобусам", 0, 5)
|
||||||
.AddParagraph("за период", 0)
|
.AddParagraph($"за период c {startDate:dd.MM.yyyy} по {endDate: dd.MM.yyyy}", 0)
|
||||||
.AddTable([10, 10, 10, 15, 15], GetData(employeeId, busId, startDate, endDate))
|
.AddTable([10, 10, 10, 15, 15], GetData(employeeId, busId, startDate, endDate))
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
@@ -44,11 +45,11 @@ public class TableReport
|
|||||||
private List<string[]> GetData(int employeeId, int busId, DateTime startDate, DateTime endDate)
|
private List<string[]> GetData(int employeeId, int busId, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
var data = _startingShiftRepository
|
var data = _startingShiftRepository
|
||||||
.ReadShifts()
|
.ReadShifts(dateFrom: startDate, dateTo: endDate, employeeId: employeeId, busId: busId)
|
||||||
.Where(x => x.Date >= startDate && x.Date <= endDate && x.Starting_shift_employees.Any(y => y.Employee_id == employeeId))
|
.Where(x => x.Date >= startDate && x.Date <= endDate && x.Starting_shift_employees.Any(y => y.Employee_id == employeeId))
|
||||||
.Select(x => new {
|
.Select(x => new {
|
||||||
EmployeeId = (int?)employeeId,
|
EmployeeId = x.Starting_shift_employees.FirstOrDefault(y => y.Employee_id == employeeId)?.Employee_name,
|
||||||
BusId = (int?)null,
|
BusId = (string?)null,
|
||||||
x.Date,
|
x.Date,
|
||||||
WorkHours = x.Starting_shift_employees.FirstOrDefault(y => y.Employee_id == employeeId)?.Work_time,
|
WorkHours = x.Starting_shift_employees.FirstOrDefault(y => y.Employee_id == employeeId)?.Work_time,
|
||||||
Price = (int?)null
|
Price = (int?)null
|
||||||
@@ -57,22 +58,23 @@ public class TableReport
|
|||||||
.ReadServices()
|
.ReadServices()
|
||||||
.Where(x => x.Date >= startDate && x.Date <= endDate && x.Bus_id == busId)
|
.Where(x => x.Date >= startDate && x.Date <= endDate && x.Bus_id == busId)
|
||||||
.Select(x => new {
|
.Select(x => new {
|
||||||
EmployeeId = (int?)null,
|
EmployeeId = (string?)null,
|
||||||
BusId = (int?)busId,
|
BusId = (string?)x.Bus_name,
|
||||||
x.Date,
|
x.Date,
|
||||||
WorkHours = (int?)null,
|
WorkHours = (int?)null,
|
||||||
Price = (int?)x.Price
|
Price = (int?)x.Price
|
||||||
}))
|
}))
|
||||||
.OrderBy(x => x.Date);
|
.OrderBy(x => x.Date);
|
||||||
|
|
||||||
return new List<string[]>() { item }
|
return new List<string[]>() { item }
|
||||||
.Union(data
|
.Union(data
|
||||||
.Select(x => new string[] {
|
.Select(x => new string[] {
|
||||||
x.EmployeeId.ToString() ?? string.Empty,
|
x.EmployeeId ?? string.Empty,
|
||||||
x.BusId.ToString() ?? string.Empty,
|
x.BusId ?? string.Empty,
|
||||||
x.Date.ToString(),
|
x.Date.ToString("dd.MM.yyyy"),
|
||||||
x.WorkHours?.ToString() ?? string.Empty,
|
x.WorkHours?.ToString("N0") ?? string.Empty,
|
||||||
x.Price?.ToString() ?? string.Empty}))
|
x.Price?.ToString("N0") ?? string.Empty}))
|
||||||
.Union([["Всего", "", "", data.Sum(x => x.WorkHours ?? 0).ToString(), data.Sum(x => x.Price ?? 0).ToString()]])
|
.Union([["Всего", "", "", data.Sum(x => x.WorkHours ?? 0).ToString("N0"), data.Sum(x => x.Price ?? 0).ToString("N0")]])
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,14 +63,38 @@ WHERE id=@id";
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<GoToService> ReadServices(DateTime? dateFrom = null, DateTime? dateTo = null,
|
public IEnumerable<GoToService> ReadServices(DateTime? dateFrom = null, DateTime? dateTo = null,
|
||||||
BrokenElements BrokenElements = BrokenElements.None, int? price = null, int? busId = null)
|
BrokenElements broken_elements = BrokenElements.None, int? price = null, int? bus_id = null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("gts.date >= @dateFrom");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("gts.date <= @dateTo");
|
||||||
|
}
|
||||||
|
if (price.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("gts.price = @price");
|
||||||
|
}
|
||||||
|
if (bus_id.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("gts.bus_id = @bus_id");
|
||||||
|
}
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT * FROM go_to_service";
|
var querySelect = @$"
|
||||||
var services = connection.Query<GoToService>(querySelect);
|
SELECT
|
||||||
|
gts.*,
|
||||||
|
b.licence_plate as Bus_name
|
||||||
|
FROM go_to_service gts
|
||||||
|
LEFT JOIN bus b on b.id = gts.bus_id
|
||||||
|
{builder.Build()}";
|
||||||
|
var services = connection.Query<GoToService>(querySelect, new { dateFrom, dateTo, broken_elements, price, bus_id });
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(services));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(services));
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ProjectTransportation.Repositories.Implementations;
|
||||||
|
|
||||||
|
public 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}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ using Newtonsoft.Json;
|
|||||||
using Npgsql;
|
using Npgsql;
|
||||||
using ProjectTransportation.Entities;
|
using ProjectTransportation.Entities;
|
||||||
using ProjectTransportation.Entities;
|
using ProjectTransportation.Entities;
|
||||||
|
using ProjectTransportation.Repositories.Implementations;
|
||||||
using ProjectTransportation.Repositories;
|
using ProjectTransportation.Repositories;
|
||||||
|
|
||||||
namespace ProjectTransportation.Repositories.Implementations;
|
namespace ProjectTransportation.Repositories.Implementations;
|
||||||
@@ -52,20 +53,71 @@ VALUES (@Starting_shift_id, @Employee_id, @Work_time)";
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<StartingShift> ReadShifts(DateTime? dateFrom = null, DateTime? dateTo = null,
|
public IEnumerable<StartingShift> ReadShifts(DateTime? dateFrom = null, DateTime? dateTo = null,
|
||||||
int? routeListId = null, int? employeeId = null, int? busId = null)
|
int? route_list_id = null, int? employee_id = null, int? bus_id = null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("ss.date >= @dateFrom");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("ss.date <= @dateTo");
|
||||||
|
}
|
||||||
|
if (route_list_id.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("ss.route_list_id = @route_list_id");
|
||||||
|
}
|
||||||
|
if (bus_id.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("ss.bus_id = @bus_id");
|
||||||
|
}
|
||||||
|
if (employee_id.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("sse.employee_id = @employee_id");
|
||||||
|
}
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"
|
var querySelect = @$"
|
||||||
SELECT sse.starting_shift_id, ss.date, ss.route_list_id, ss.bus_id, sse.employee_id, sse.work_time FROM starting_shift ss
|
SELECT
|
||||||
INNER JOIN starting_shift_employee sse ON sse.starting_shift_id = ss.id";
|
ss.id,
|
||||||
var startingShifts = connection.Query<TempStartingShiftEmployee>(querySelect);
|
ss.date,
|
||||||
|
CONCAT(rl.route_start, '-', rl.route_finish) as Route_list_name,
|
||||||
|
CONCAT(b.model, ' ', b.licence_plate) as Bus_name,
|
||||||
|
CONCAT(e.first_name, ' ', e.last_name) as Employee_name,
|
||||||
|
sse.employee_id,
|
||||||
|
sse.work_time
|
||||||
|
FROM starting_shift ss
|
||||||
|
LEFT JOIN route_list rl on rl.id = ss.route_list_id
|
||||||
|
LEFT JOIN bus b on b.id = ss.bus_id
|
||||||
|
INNER JOIN starting_shift_employee sse ON sse.starting_shift_id = ss.id
|
||||||
|
LEFT JOIN employee e on e.id = sse.employee_id
|
||||||
|
{builder.Build()}";
|
||||||
|
|
||||||
|
var startingShiftDict = new Dictionary<int, List<StartingShiftEmployee>>();
|
||||||
|
|
||||||
|
var startingShifts = connection.Query<StartingShift, StartingShiftEmployee, StartingShift>(querySelect, (startingShift, startingShifts) =>
|
||||||
|
{
|
||||||
|
if (!startingShiftDict.TryGetValue(startingShift.Id, out var sse))
|
||||||
|
{
|
||||||
|
sse = [];
|
||||||
|
startingShiftDict.Add(startingShift.Id, sse);
|
||||||
|
}
|
||||||
|
sse.Add(startingShifts);
|
||||||
|
return startingShift;
|
||||||
|
}, splitOn: "Employee_name", param: new { dateFrom, dateTo, route_list_id, employee_id, bus_id });
|
||||||
|
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(startingShifts));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(startingShifts));
|
||||||
return startingShifts.GroupBy(x => x.Starting_shift_id, y => y,
|
|
||||||
(key, value) => StartingShift.CreateOperation(value.First(),
|
return startingShiftDict.Select(x =>
|
||||||
value.Select(z => StartingShiftEmployee.CreateElement(0, z.Employee_id, z.Work_time)))).ToList();
|
{
|
||||||
|
var ss = startingShifts.First(y => y.Id == x.Key);
|
||||||
|
ss.SetStartingShiftEmployee(x.Value);
|
||||||
|
return ss;
|
||||||
|
}).ToArray();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user