From 1532635fd0f4a752972de4150d376500334e36ab Mon Sep 17 00:00:00 2001 From: egorvasin01 Date: Sat, 14 Dec 2024 16:53:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/Client.cs | 8 +- .../Entities/Contract.cs | 32 ++++--- .../Entities/Contractor.cs | 8 +- .../Entities/ContractorVacation.cs | 12 ++- .../Entities/Service.cs | 5 +- .../Entities/ServiceContract.cs | 8 +- .../Entities/Vacation.cs | 9 +- .../Forms/FormClients.cs | 7 +- .../Forms/FormContract.cs | 4 +- .../Forms/FormContractConclusionsReport.cs | 2 +- .../Forms/FormContractorVacation.cs | 12 +-- .../Forms/FormContractorVacations.cs | 6 +- .../Forms/FormContractors.cs | 7 +- .../Forms/FormContracts.cs | 8 +- .../Forms/FormServices.cs | 6 +- .../Forms/FormVacations.cs | 9 +- .../ISEbd-22_Vasin_E.D._It_Company.csproj | 4 - .../Reports/ChartReport.cs | 5 +- .../Reports/TableReport.cs | 18 ++-- .../Implementations/ContractRepository.cs | 85 +++++++++++++++++-- .../ContractorVacationRepository.cs | 24 +++++- .../Implementations/QueryBuilder.cs | 35 ++++++++ 22 files changed, 250 insertions(+), 64 deletions(-) create mode 100644 ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Repositories/Implementations/QueryBuilder.cs diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Client.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Client.cs index a26004a..8b0846a 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Client.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Client.cs @@ -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 int Id { get; private set; } + [DisplayName("Имя")] public string Name { get; private set; } = string.Empty; + [DisplayName("Юридическая форма")] public string LegalForm { get; private set; } = string.Empty; + public string FullName => $"{LegalForm} {Name}"; + public static Client CreateEntity(int id, string name, string legalForm) { return new Client diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Contract.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Contract.cs index 9bffa77..4a8b270 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Contract.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Contract.cs @@ -1,4 +1,5 @@ using ISEbd_22_Vasin_E.D._It_Company.Entities.Enums; +using System.ComponentModel; namespace ISEbd_22_Vasin_E.D._It_Company.Entities; @@ -6,20 +7,36 @@ public class Contract { public int Id { get; private set; } + [Browsable(false)] public int ClientId { get; private set; } + [DisplayName("Заказчик")] + public string ClientName { get; private set; } = string.Empty; + + [Browsable(false)] public int ContractorId { get; private set; } + [DisplayName("Исполнитель")] + public string ContractorName { get; private set; } = string.Empty; + + [DisplayName("Стоимость")] public int Amount { get; private set; } + [DisplayName("Дата заключения")] public DateTime StartDate { get; private set; } + [DisplayName("Дата Завершения")] public DateTime Deadline { get; private set; } + [DisplayName("Тип контракта")] public ContractType ContractType { get; private set; } + [Browsable(false)] public IEnumerable 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, DateTime deadline, ContractType contractType, IEnumerable serviceContracts) { @@ -36,18 +53,11 @@ public class Contract }; } - public static Contract CreateEntity(TempServiceContract tempServiceContract, IEnumerable serviceContracts) + public void SetServiceContracts(IEnumerable serviceContracts) { - return new Contract + if (serviceContracts != null && serviceContracts.Any()) { - Id = tempServiceContract.Id, - ClientId = tempServiceContract.ClientId, - ContractorId = tempServiceContract.ContractorId, - Amount = tempServiceContract.Amount, - StartDate = DateTime.Now, - Deadline = tempServiceContract.Deadline, - ContractType = tempServiceContract.ContractType, - ServiceContracts = serviceContracts - }; + ServiceContracts = serviceContracts; + } } } diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Contractor.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Contractor.cs index dcb235f..131caad 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Contractor.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Contractor.cs @@ -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 int Id { get; private set; } + [DisplayName("Имя")] public string Name { get; private set; } = string.Empty; + [DisplayName("Фамилия")] public string Surname { get; private set; } = string.Empty; + public string FullName => $"{Name} {Surname}"; + public static Contractor CreateEntity(int id, string name, string surname) { return new Contractor diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/ContractorVacation.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/ContractorVacation.cs index d6ff5bc..425a4b0 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/ContractorVacation.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/ContractorVacation.cs @@ -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 int Id { get; private set; } + [Browsable(false)] public int ContractorId { get; private set; } + [DisplayName("Исполнитель")] + public string ContractorName { get; private set; } = string.Empty; + + [Browsable(false)] 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) { return new ContractorVacation diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Service.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Service.cs index 053a170..644364d 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Service.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Service.cs @@ -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 int Id { get; private set; } + [DisplayName("Название")] public string Name { get; private set; } = string.Empty; public static Service CreateEntity(int id, string name) diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/ServiceContract.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/ServiceContract.cs index c95b004..477667f 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/ServiceContract.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/ServiceContract.cs @@ -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 int Id { get; private set; } + [Browsable(false)] public int ServiceId { get; private set; } + [DisplayName("Название услуги")] + public string ServiceName { get; private set; } = string.Empty; + public static ServiceContract CreateElement(int id, int serviceId) { return new ServiceContract diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Vacation.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Vacation.cs index 07946ae..47b3a95 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Vacation.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Entities/Vacation.cs @@ -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; @@ -6,10 +8,15 @@ public class Vacation { public int Id { get; private set; } + [DisplayName("Дата начала")] public DateTime StartDate { get; private set; } + [DisplayName("Дата конца")] 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 static Vacation CreateEntity(int id, DateTime startDate, DateTime endDate, VacationType vacationType) diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormClients.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormClients.cs index 92609f2..e3c3181 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormClients.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormClients.cs @@ -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) { diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContract.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContract.cs index a32164c..bc35cfc 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContract.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContract.cs @@ -15,11 +15,11 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms _contractRepository = contractRepository ?? throw new ArgumentNullException(nameof(contractRepository)); comboBoxClient.DataSource = clientRepository.ReadClients(); - comboBoxClient.DisplayMember = "Name"; + comboBoxClient.DisplayMember = "FullName"; comboBoxClient.ValueMember = "Id"; comboBoxContractor.DataSource = contractorRepository.ReadContractors(); - comboBoxContractor.DisplayMember = "Name"; + comboBoxContractor.DisplayMember = "FullName"; comboBoxContractor.ValueMember = "Id"; ColumnServiceName.DataSource = serviceRepository.ReadServices(); diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractConclusionsReport.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractConclusionsReport.cs index 1f3a562..b939ff0 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractConclusionsReport.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractConclusionsReport.cs @@ -14,7 +14,7 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms _container = container ?? throw new ArgumentNullException(nameof(container)); comboBoxClientId.DataSource = clientRepository.ReadClients(); - comboBoxClientId.DisplayMember = "Name"; + comboBoxClientId.DisplayMember = "FullName"; comboBoxClientId.ValueMember = "Id"; } diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractorVacation.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractorVacation.cs index a304267..e63f094 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractorVacation.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractorVacation.cs @@ -15,18 +15,10 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms throw new ArgumentNullException(nameof(contractorVacationRepository)); comboBoxContractor.DataSource = contractorRepository.ReadContractors(); - comboBoxContractor.DisplayMember = "Name"; + comboBoxContractor.DisplayMember = "FullName"; comboBoxContractor.ValueMember = "Id"; - var vacations = 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.DataSource = vacationRepository.ReadVacations(); comboBoxVacation.DisplayMember = "DisplayDate"; comboBoxVacation.ValueMember = "Id"; } diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractorVacations.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractorVacations.cs index a68c1f2..d0f955e 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractorVacations.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractorVacations.cs @@ -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) { diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractors.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractors.cs index c2496e6..e3a5068 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractors.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContractors.cs @@ -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) { diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContracts.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContracts.cs index 7fa9efe..903b960 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContracts.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormContracts.cs @@ -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"; + } } } diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormServices.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormServices.cs index e06be63..b3e225e 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormServices.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormServices.cs @@ -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) { diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormVacations.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormVacations.cs index 0aef19f..107adf5 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormVacations.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Forms/FormVacations.cs @@ -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) { diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company.csproj b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company.csproj index 2f80992..a02d6f7 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company.csproj +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company.csproj @@ -9,10 +9,6 @@ enable - - - - diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Reports/ChartReport.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Reports/ChartReport.cs index 630f6f5..8cb2311 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Reports/ChartReport.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Reports/ChartReport.cs @@ -23,7 +23,7 @@ internal class ChartReport { new PdfBuilder(filePath) .AddHeader("Распределение услуг на исполнителя") - .AddPieChart("Услуги", GetData(dateTime)) + .AddPieChart($"Услуги на {dateTime:dd MMMM yyyy}", GetData(dateTime)) .Build(); return true; @@ -38,8 +38,7 @@ internal class ChartReport private List<(string Caption, double Value)> GetData(DateTime dateTime) { return _contractRepository - .ReadContracts() - .Where(x => x.StartDate.Date == dateTime.Date) + .ReadContracts(deadlineFrom: dateTime, deadlineTo: dateTime.AddDays(1)) .GroupBy(x => x.ContractorId, (key, group) => new { Id = key, diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Reports/TableReport.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Reports/TableReport.cs index 8caa1eb..fcde25b 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Reports/TableReport.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Reports/TableReport.cs @@ -25,7 +25,7 @@ internal class TableReport { new ExcelBuilder(filePath) .AddHeader("Сводка по заключениям контрактов", 0, 4) - .AddParagraph("за период", 0) + .AddParagraph($"за период с {startDate: dd.MM.yyyy} по {endDate: dd.MM.yyyy}", 0) .AddTable([10, 10, 15, 15], GetData(customerId, startDate, endDate)) .Build(); @@ -41,11 +41,8 @@ internal class TableReport private List GetData(int clientId, DateTime startDate, DateTime endDate) { var data = _contractRepository - .ReadContracts() - .Where(x => x.StartDate >= startDate - && x.StartDate <= endDate - && x.ClientId == clientId) - .GroupBy(x => x.StartDate) + .ReadContracts(clientId: clientId, startDateFrom: startDate, startDateTo: endDate) + .GroupBy(x => x.ContractorId) .Select(x => new { x.First().ContractorId, @@ -55,11 +52,8 @@ internal class TableReport }) .Union( _contractRepository - .ReadContracts() - .Where(x => x.Deadline >= startDate - && x.Deadline <= endDate - && x.ClientId == clientId) - .GroupBy(x => x.Deadline) + .ReadContracts(clientId: clientId, deadlineFrom: startDate, deadlineTo: endDate) + .GroupBy(x => x.ContractorId) .Select(x => new { x.First().ContractorId, @@ -74,7 +68,7 @@ internal class TableReport return new List() { item } .Union(data.Select(x => new string[] { x.ContractorId.ToString(), - x.Date.ToString(), + x.Date.ToString("dd.MM.yyyy"), x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty })) diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Repositories/Implementations/ContractRepository.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Repositories/Implementations/ContractRepository.cs index a8e3177..85b0720 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Repositories/Implementations/ContractRepository.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Repositories/Implementations/ContractRepository.cs @@ -65,17 +65,90 @@ VALUES (@ContractId, @ServiceId); 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); - var querySelect = @" -SELECT c.*, sc.ServiceId + var querySelect = @$" +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 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(querySelect); + + var contractsDict = new Dictionary>(); + + var contracts = connection.Query(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)); - return contracts.GroupBy(x => x.Id, y => y, (key, value) => - Contract.CreateEntity(value.First(), value.Select(z => - ServiceContract.CreateElement(0, z.ServiceId)))).ToList(); + + return contractsDict.Select(x => + { + var c = contracts.First(y => y.Id == x.Key); + c.SetServiceContracts(x.Value); + return c; + }).ToArray(); } catch (Exception ex) { diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Repositories/Implementations/ContractorVacationRepository.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Repositories/Implementations/ContractorVacationRepository.cs index 057a1ba..8794472 100644 --- a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Repositories/Implementations/ContractorVacationRepository.cs +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Repositories/Implementations/ContractorVacationRepository.cs @@ -1,5 +1,6 @@ using Dapper; using ISEbd_22_Vasin_E.D._It_Company.Entities; +using ISEbd_22_Vasin_E.D._It_Company.Repositories.Implementations; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Npgsql; @@ -45,11 +46,28 @@ VALUES (@ContractorId, @VacationId); 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); - var querySelect = @" -SELECT * FROM ContractorVacations; + var querySelect = @$" +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(querySelect); + var contractorVacations = connection.Query(querySelect, new { contractorId, vacationId }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contractorVacations)); return contractorVacations; } diff --git a/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Repositories/Implementations/QueryBuilder.cs b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Repositories/Implementations/QueryBuilder.cs new file mode 100644 index 0000000..f97ea28 --- /dev/null +++ b/ISEbd-22_Vasin_E.D._It_Company/ISEbd-22_Vasin_E.D._It_Company/Repositories/Implementations/QueryBuilder.cs @@ -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}"; + } +} \ No newline at end of file