Лабораторная работа №4
This commit is contained in:
parent
708e4683a7
commit
1532635fd0
@ -1,13 +1,19 @@
|
|||||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||||
|
|
||||||
public class Client
|
public class Client
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Имя")]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Юридическая форма")]
|
||||||
public string LegalForm { get; private set; } = string.Empty;
|
public string LegalForm { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string FullName => $"{LegalForm} {Name}";
|
||||||
|
|
||||||
public static Client CreateEntity(int id, string name, string legalForm)
|
public static Client CreateEntity(int id, string name, string legalForm)
|
||||||
{
|
{
|
||||||
return new Client
|
return new Client
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using ISEbd_22_Vasin_E.D._It_Company.Entities.Enums;
|
using ISEbd_22_Vasin_E.D._It_Company.Entities.Enums;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||||
|
|
||||||
@ -6,20 +7,36 @@ public class Contract
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int ClientId { get; private set; }
|
public int ClientId { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Заказчик")]
|
||||||
|
public string ClientName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int ContractorId { get; private set; }
|
public int ContractorId { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Исполнитель")]
|
||||||
|
public string ContractorName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Стоимость")]
|
||||||
public int Amount { get; private set; }
|
public int Amount { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Дата заключения")]
|
||||||
public DateTime StartDate { get; private set; }
|
public DateTime StartDate { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Дата Завершения")]
|
||||||
public DateTime Deadline { get; private set; }
|
public DateTime Deadline { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Тип контракта")]
|
||||||
public ContractType ContractType { get; private set; }
|
public ContractType ContractType { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public IEnumerable<ServiceContract> ServiceContracts { get; private set; } = [];
|
public IEnumerable<ServiceContract> ServiceContracts { get; private set; } = [];
|
||||||
|
|
||||||
|
[DisplayName("Услуги")]
|
||||||
|
public string Service => ServiceContracts != null ? string.Join(", ", ServiceContracts.Select(x => $"{x.ServiceName}")) : string.Empty;
|
||||||
|
|
||||||
public static Contract CreateEntity(int id, int clientId, int contractorId, int amount,
|
public static Contract CreateEntity(int id, int clientId, int contractorId, int amount,
|
||||||
DateTime deadline, ContractType contractType, IEnumerable<ServiceContract> serviceContracts)
|
DateTime deadline, ContractType contractType, IEnumerable<ServiceContract> serviceContracts)
|
||||||
{
|
{
|
||||||
@ -36,18 +53,11 @@ public class Contract
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Contract CreateEntity(TempServiceContract tempServiceContract, IEnumerable<ServiceContract> serviceContracts)
|
public void SetServiceContracts(IEnumerable<ServiceContract> serviceContracts)
|
||||||
{
|
{
|
||||||
return new Contract
|
if (serviceContracts != null && serviceContracts.Any())
|
||||||
{
|
{
|
||||||
Id = tempServiceContract.Id,
|
ServiceContracts = serviceContracts;
|
||||||
ClientId = tempServiceContract.ClientId,
|
}
|
||||||
ContractorId = tempServiceContract.ContractorId,
|
|
||||||
Amount = tempServiceContract.Amount,
|
|
||||||
StartDate = DateTime.Now,
|
|
||||||
Deadline = tempServiceContract.Deadline,
|
|
||||||
ContractType = tempServiceContract.ContractType,
|
|
||||||
ServiceContracts = serviceContracts
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||||
|
|
||||||
public class Contractor
|
public class Contractor
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Имя")]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Фамилия")]
|
||||||
public string Surname { get; private set; } = string.Empty;
|
public string Surname { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string FullName => $"{Name} {Surname}";
|
||||||
|
|
||||||
public static Contractor CreateEntity(int id, string name, string surname)
|
public static Contractor CreateEntity(int id, string name, string surname)
|
||||||
{
|
{
|
||||||
return new Contractor
|
return new Contractor
|
||||||
|
@ -1,13 +1,23 @@
|
|||||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||||
|
|
||||||
public class ContractorVacation
|
public class ContractorVacation
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int ContractorId { get; private set; }
|
public int ContractorId { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Исполнитель")]
|
||||||
|
public string ContractorName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int VacationId { get; private set; }
|
public int VacationId { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Даты отпуска")]
|
||||||
|
public string VacationDates { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public static ContractorVacation CreateElement(int id, int contractorId, int vacationId)
|
public static ContractorVacation CreateElement(int id, int contractorId, int vacationId)
|
||||||
{
|
{
|
||||||
return new ContractorVacation
|
return new ContractorVacation
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||||
|
|
||||||
public class Service
|
public class Service
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Название")]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public static Service CreateEntity(int id, string name)
|
public static Service CreateEntity(int id, string name)
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||||
|
|
||||||
public class ServiceContract
|
public class ServiceContract
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int ServiceId { get; private set; }
|
public int ServiceId { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Название услуги")]
|
||||||
|
public string ServiceName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public static ServiceContract CreateElement(int id, int serviceId)
|
public static ServiceContract CreateElement(int id, int serviceId)
|
||||||
{
|
{
|
||||||
return new ServiceContract
|
return new ServiceContract
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using ISEbd_22_Vasin_E.D._It_Company.Entities.Enums;
|
using DocumentFormat.OpenXml.Wordprocessing;
|
||||||
|
using ISEbd_22_Vasin_E.D._It_Company.Entities.Enums;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||||
|
|
||||||
@ -6,10 +8,15 @@ public class Vacation
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Дата начала")]
|
||||||
public DateTime StartDate { get; private set; }
|
public DateTime StartDate { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Дата конца")]
|
||||||
public DateTime EndDate { get; private set; }
|
public DateTime EndDate { get; private set; }
|
||||||
|
|
||||||
|
public string DisplayDate => $"{StartDate:dd.MM.yyyy} - {EndDate:dd.MM.yyyy}";
|
||||||
|
|
||||||
|
[DisplayName("Тип отпуска")]
|
||||||
public VacationType VacationType { get; private set; }
|
public VacationType VacationType { get; private set; }
|
||||||
|
|
||||||
public static Vacation CreateEntity(int id, DateTime startDate, DateTime endDate, VacationType vacationType)
|
public static Vacation CreateEntity(int id, DateTime startDate, DateTime endDate, VacationType vacationType)
|
||||||
|
@ -78,7 +78,12 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _clientRepository.ReadClients();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _clientRepository.ReadClients();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["FullName"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -15,11 +15,11 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
|||||||
_contractRepository = contractRepository ?? throw new ArgumentNullException(nameof(contractRepository));
|
_contractRepository = contractRepository ?? throw new ArgumentNullException(nameof(contractRepository));
|
||||||
|
|
||||||
comboBoxClient.DataSource = clientRepository.ReadClients();
|
comboBoxClient.DataSource = clientRepository.ReadClients();
|
||||||
comboBoxClient.DisplayMember = "Name";
|
comboBoxClient.DisplayMember = "FullName";
|
||||||
comboBoxClient.ValueMember = "Id";
|
comboBoxClient.ValueMember = "Id";
|
||||||
|
|
||||||
comboBoxContractor.DataSource = contractorRepository.ReadContractors();
|
comboBoxContractor.DataSource = contractorRepository.ReadContractors();
|
||||||
comboBoxContractor.DisplayMember = "Name";
|
comboBoxContractor.DisplayMember = "FullName";
|
||||||
comboBoxContractor.ValueMember = "Id";
|
comboBoxContractor.ValueMember = "Id";
|
||||||
|
|
||||||
ColumnServiceName.DataSource = serviceRepository.ReadServices();
|
ColumnServiceName.DataSource = serviceRepository.ReadServices();
|
||||||
|
@ -14,7 +14,7 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
|||||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||||
|
|
||||||
comboBoxClientId.DataSource = clientRepository.ReadClients();
|
comboBoxClientId.DataSource = clientRepository.ReadClients();
|
||||||
comboBoxClientId.DisplayMember = "Name";
|
comboBoxClientId.DisplayMember = "FullName";
|
||||||
comboBoxClientId.ValueMember = "Id";
|
comboBoxClientId.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,18 +15,10 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
|||||||
throw new ArgumentNullException(nameof(contractorVacationRepository));
|
throw new ArgumentNullException(nameof(contractorVacationRepository));
|
||||||
|
|
||||||
comboBoxContractor.DataSource = contractorRepository.ReadContractors();
|
comboBoxContractor.DataSource = contractorRepository.ReadContractors();
|
||||||
comboBoxContractor.DisplayMember = "Name";
|
comboBoxContractor.DisplayMember = "FullName";
|
||||||
comboBoxContractor.ValueMember = "Id";
|
comboBoxContractor.ValueMember = "Id";
|
||||||
|
|
||||||
var vacations = vacationRepository.ReadVacations()
|
comboBoxVacation.DataSource = vacationRepository.ReadVacations();
|
||||||
.Select(v => new
|
|
||||||
{
|
|
||||||
Id = v.Id,
|
|
||||||
DisplayDate =
|
|
||||||
$"{v.StartDate.ToString("dd.MM.yyyy")} - {v.EndDate.ToString("dd.MM.yyyy")}"
|
|
||||||
})
|
|
||||||
.ToList();
|
|
||||||
comboBoxVacation.DataSource = vacations;
|
|
||||||
comboBoxVacation.DisplayMember = "DisplayDate";
|
comboBoxVacation.DisplayMember = "DisplayDate";
|
||||||
comboBoxVacation.ValueMember = "Id";
|
comboBoxVacation.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,11 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _contractorVacationRepository.ReadContractorVacations();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _contractorVacationRepository.ReadContractorVacations();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -78,7 +78,12 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _contractorRepository.ReadContractors();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _contractorRepository.ReadContractors();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["FullName"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -41,6 +41,12 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _contractRepository.ReadContracts();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _contractRepository.ReadContracts();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["StartDate"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||||
|
dataGridViewData.Columns["Deadline"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,11 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _serviceRepository.ReadServices();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _serviceRepository.ReadServices();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -78,7 +78,14 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _vacationRepository.ReadVacations();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _vacationRepository.ReadVacations();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["DisplayDate"].Visible = false;
|
||||||
|
dataGridViewData.Columns["StartDate"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||||
|
dataGridViewData.Columns["EndDate"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -9,10 +9,6 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Remove="Forms\odjv2pa0.v01~" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.2.0" />
|
<PackageReference Include="DocumentFormat.OpenXml" Version="3.2.0" />
|
||||||
|
@ -23,7 +23,7 @@ internal 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,8 +38,7 @@ internal class ChartReport
|
|||||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||||
{
|
{
|
||||||
return _contractRepository
|
return _contractRepository
|
||||||
.ReadContracts()
|
.ReadContracts(deadlineFrom: dateTime, deadlineTo: dateTime.AddDays(1))
|
||||||
.Where(x => x.StartDate.Date == dateTime.Date)
|
|
||||||
.GroupBy(x => x.ContractorId, (key, group) => new
|
.GroupBy(x => x.ContractorId, (key, group) => new
|
||||||
{
|
{
|
||||||
Id = key,
|
Id = key,
|
||||||
|
@ -25,7 +25,7 @@ internal class TableReport
|
|||||||
{
|
{
|
||||||
new ExcelBuilder(filePath)
|
new ExcelBuilder(filePath)
|
||||||
.AddHeader("Сводка по заключениям контрактов", 0, 4)
|
.AddHeader("Сводка по заключениям контрактов", 0, 4)
|
||||||
.AddParagraph("за период", 0)
|
.AddParagraph($"за период с {startDate: dd.MM.yyyy} по {endDate: dd.MM.yyyy}", 0)
|
||||||
.AddTable([10, 10, 15, 15], GetData(customerId, startDate, endDate))
|
.AddTable([10, 10, 15, 15], GetData(customerId, startDate, endDate))
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
@ -41,11 +41,8 @@ internal class TableReport
|
|||||||
private List<string[]> GetData(int clientId, DateTime startDate, DateTime endDate)
|
private List<string[]> GetData(int clientId, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
var data = _contractRepository
|
var data = _contractRepository
|
||||||
.ReadContracts()
|
.ReadContracts(clientId: clientId, startDateFrom: startDate, startDateTo: endDate)
|
||||||
.Where(x => x.StartDate >= startDate
|
.GroupBy(x => x.ContractorId)
|
||||||
&& x.StartDate <= endDate
|
|
||||||
&& x.ClientId == clientId)
|
|
||||||
.GroupBy(x => x.StartDate)
|
|
||||||
.Select(x => new
|
.Select(x => new
|
||||||
{
|
{
|
||||||
x.First().ContractorId,
|
x.First().ContractorId,
|
||||||
@ -55,11 +52,8 @@ internal class TableReport
|
|||||||
})
|
})
|
||||||
.Union(
|
.Union(
|
||||||
_contractRepository
|
_contractRepository
|
||||||
.ReadContracts()
|
.ReadContracts(clientId: clientId, deadlineFrom: startDate, deadlineTo: endDate)
|
||||||
.Where(x => x.Deadline >= startDate
|
.GroupBy(x => x.ContractorId)
|
||||||
&& x.Deadline <= endDate
|
|
||||||
&& x.ClientId == clientId)
|
|
||||||
.GroupBy(x => x.Deadline)
|
|
||||||
.Select(x => new
|
.Select(x => new
|
||||||
{
|
{
|
||||||
x.First().ContractorId,
|
x.First().ContractorId,
|
||||||
@ -74,7 +68,7 @@ internal class TableReport
|
|||||||
return new List<string[]>() { item }
|
return new List<string[]>() { item }
|
||||||
.Union(data.Select(x => new string[] {
|
.Union(data.Select(x => new string[] {
|
||||||
x.ContractorId.ToString(),
|
x.ContractorId.ToString(),
|
||||||
x.Date.ToString(),
|
x.Date.ToString("dd.MM.yyyy"),
|
||||||
x.CountIn?.ToString() ?? string.Empty,
|
x.CountIn?.ToString() ?? string.Empty,
|
||||||
x.CountOut?.ToString() ?? string.Empty
|
x.CountOut?.ToString() ?? string.Empty
|
||||||
}))
|
}))
|
||||||
|
@ -65,17 +65,90 @@ VALUES (@ContractId, @ServiceId);
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (clientId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("c.ClientId = @clientId");
|
||||||
|
}
|
||||||
|
if (contractorId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("c.ContractorId = @contractorId");
|
||||||
|
}
|
||||||
|
if (amountFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("c.Amount >= @amountFrom");
|
||||||
|
}
|
||||||
|
if (amountTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("c.Amount <= @amountTo");
|
||||||
|
}
|
||||||
|
if (startDateFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("c.StartDate >= @startDateFrom");
|
||||||
|
}
|
||||||
|
if (startDateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("c.StartDate <= @startDateTo");
|
||||||
|
}
|
||||||
|
if (deadlineFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("c.Deadline >= @deadlineFrom");
|
||||||
|
}
|
||||||
|
if (deadlineTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("c.Deadline <= @deadlineTo");
|
||||||
|
}
|
||||||
|
if (contractType.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("c.ContractType = @contractType");
|
||||||
|
}
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"
|
var querySelect = @$"
|
||||||
SELECT c.*, sc.ServiceId
|
SELECT
|
||||||
|
c.*,
|
||||||
|
CONCAT(cl.LegalForm, ' ', cl.Name) as ClientName,
|
||||||
|
CONCAT(co.Name, ' ', co.Surname) as ContractorName,
|
||||||
|
sc.ServiceId,
|
||||||
|
s.Name as ServiceName
|
||||||
FROM Contracts c
|
FROM Contracts c
|
||||||
INNER JOIN ServiceContracts sc ON sc.ContractId = c.Id
|
INNER JOIN ServiceContracts sc ON sc.ContractId = c.Id
|
||||||
|
LEFT JOIN Services s ON sc.ServiceId = s.Id
|
||||||
|
LEFT JOIN Clients cl ON c.ClientId = cl.Id
|
||||||
|
LEFT JOIN Contractors co ON c.ContractorId = co.Id
|
||||||
|
{builder.Build()};
|
||||||
";
|
";
|
||||||
var contracts = connection.Query<TempServiceContract>(querySelect);
|
|
||||||
|
var contractsDict = new Dictionary<int, List<ServiceContract>>();
|
||||||
|
|
||||||
|
var contracts = connection.Query<Contract, ServiceContract, Contract>(querySelect, (contract, serviceContract) =>
|
||||||
|
{
|
||||||
|
if (!contractsDict.TryGetValue(contract.Id, out var sc))
|
||||||
|
{
|
||||||
|
sc = [];
|
||||||
|
contractsDict.Add(contract.Id, sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
sc.Add(serviceContract);
|
||||||
|
return contract;
|
||||||
|
}, splitOn: "ServiceId", param: new
|
||||||
|
{
|
||||||
|
clientId,
|
||||||
|
contractorId,
|
||||||
|
amountFrom,
|
||||||
|
amountTo,
|
||||||
|
deadlineFrom,
|
||||||
|
deadlineTo,
|
||||||
|
contractType
|
||||||
|
});
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
||||||
return contracts.GroupBy(x => x.Id, y => y, (key, value) =>
|
|
||||||
Contract.CreateEntity(value.First(), value.Select(z =>
|
return contractsDict.Select(x =>
|
||||||
ServiceContract.CreateElement(0, z.ServiceId)))).ToList();
|
{
|
||||||
|
var c = contracts.First(y => y.Id == x.Key);
|
||||||
|
c.SetServiceContracts(x.Value);
|
||||||
|
return c;
|
||||||
|
}).ToArray();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using ISEbd_22_Vasin_E.D._It_Company.Entities;
|
using ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||||
|
using ISEbd_22_Vasin_E.D._It_Company.Repositories.Implementations;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
@ -45,11 +46,28 @@ VALUES (@ContractorId, @VacationId);
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (contractorId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cv.ContractorId = @contractorId");
|
||||||
|
}
|
||||||
|
if (vacationId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("cv.VacationId = @vacationId");
|
||||||
|
}
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"
|
var querySelect = @$"
|
||||||
SELECT * FROM ContractorVacations;
|
SELECT
|
||||||
|
cv.*,
|
||||||
|
CONCAT(c.Name, ' ', c.Surname) as ContractorName,
|
||||||
|
CONCAT(TO_CHAR(v.StartDate, 'DD.MM.YYYY'), ' - ', TO_CHAR(v.EndDate, 'DD.MM.YYYY')) as VacationDates
|
||||||
|
FROM ContractorVacations cv
|
||||||
|
LEFT JOIN Contractors c ON c.Id = cv.ContractorId
|
||||||
|
LEFT JOIN Vacations v ON v.Id = cv.VacationId
|
||||||
|
{builder.Build()};
|
||||||
";
|
";
|
||||||
var contractorVacations = connection.Query<ContractorVacation>(querySelect);
|
var contractorVacations = connection.Query<ContractorVacation>(querySelect, new { contractorId, vacationId });
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contractorVacations));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contractorVacations));
|
||||||
return contractorVacations;
|
return contractorVacations;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ISEbd_22_Vasin_E.D._It_Company.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