From 4bec98204dd656318bb500511ea6087bff656db7 Mon Sep 17 00:00:00 2001 From: artur-kalimullin <144933634+artur-kalimullin@users.noreply.github.com> Date: Mon, 16 Dec 2024 20:14:51 +0400 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 --- .../ProjectSchedule/Entities/Audience.cs | 4 ++ .../Entities/CompilingSchedule.cs | 22 +++++++ .../Entities/CurriculumSupplement.cs | 33 +++++++---- .../ProjectSchedule/Entities/Discipline.cs | 5 +- .../DisciplineCurriculumSupplement.cs | 2 + .../ProjectSchedule/Entities/Educator.cs | 9 ++- .../ProjectSchedule/Entities/GroupStudents.cs | 9 ++- .../TempDisciplineCurriculumSupplement.cs | 20 ------- .../ProjectSchedule/Forms/FormAudiences.cs | 6 +- .../Forms/FormCompilingSchedule.cs | 4 +- .../Forms/FormCompilingSchedules.cs | 7 ++- .../Forms/FormCurriculumSupplement.cs | 2 +- .../Forms/FormCurriculumSupplements.cs | 6 +- .../ProjectSchedule/Forms/FormDisciplines.cs | 6 +- .../ProjectSchedule/Forms/FormEducators.cs | 7 ++- .../Forms/FormGroupsStudents.cs | 7 ++- .../ProjectSchedule/Reports/ChartReport.cs | 9 ++- .../ProjectSchedule/Reports/TableReport.cs | 25 ++++---- .../ICurriculumSupplementRepository.cs | 2 +- .../CompilingScheduleRepository.cs | 43 +++++++++++++- .../CurriculumSupplementRepository.cs | 58 ++++++++++++++++--- .../Implementations/QueryBuilder.cs | 35 +++++++++++ 22 files changed, 247 insertions(+), 74 deletions(-) delete mode 100644 ProjectSchedule/ProjectSchedule/Entities/TempDisciplineCurriculumSupplement.cs create mode 100644 ProjectSchedule/ProjectSchedule/Repositories/Implementations/QueryBuilder.cs diff --git a/ProjectSchedule/ProjectSchedule/Entities/Audience.cs b/ProjectSchedule/ProjectSchedule/Entities/Audience.cs index c981830..503d596 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/Audience.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/Audience.cs @@ -1,4 +1,5 @@ using ProjectSchedule.Entities.Enums; +using System.ComponentModel; namespace ProjectSchedule.Entities; @@ -6,10 +7,13 @@ public class Audience { public int Id { get; private set; } + [DisplayName("Номер аудитории")] public string NumberAudience { get; private set; } = string.Empty; + [DisplayName("Тип аудитории")] public TypeAudience TypeAudience { get; private set; } + [DisplayName("Количество мест")] public int QuantitySeats { get; private set; } public static Audience CreateEntity(int id, string numberAudience, TypeAudience typeAudience, int quantitySeats) diff --git a/ProjectSchedule/ProjectSchedule/Entities/CompilingSchedule.cs b/ProjectSchedule/ProjectSchedule/Entities/CompilingSchedule.cs index f9646b6..9858911 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/CompilingSchedule.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/CompilingSchedule.cs @@ -1,4 +1,5 @@ using ProjectSchedule.Entities.Enums; +using System.ComponentModel; namespace ProjectSchedule.Entities; @@ -6,22 +7,43 @@ public class CompilingSchedule { public int Id { get; private set; } + [Browsable(false)] public int EducatorId { get; private set; } + [Browsable(false)] public int DisciplineId { get; private set; } + [Browsable(false)] public int GroupStudentsId { get; private set; } + [Browsable(false)] public int AudienceId { get; private set; } + [DisplayName("Преподаватель")] + public string EducatorName { get; private set; } = string.Empty; + + [DisplayName("Название дисциплины")] + public string NameDiscipline { get; private set; } = string.Empty; + + [DisplayName("Группа студентов")] + public string NameGroup { get; private set; } = string.Empty; + + [DisplayName("Номер аудитории")] + public string NumberAudience { get; private set; } = string.Empty; + + [DisplayName("Дата дня")] public DateTime DateDay { get; private set; } + [DisplayName("Номер недели")] public TypeWeek TypeWeek { get; private set; } + [DisplayName("Номер дня")] public int NumberDay { get; private set; } + [DisplayName("Номер пары")] public int NumberPair { get; private set; } + [DisplayName("Тип занятия")] public TypeActivity TypeActivity { get; private set; } public static CompilingSchedule CreateOperation(int id, int educatorId, int disciplineId, int groupStudentsId, int audienceId, diff --git a/ProjectSchedule/ProjectSchedule/Entities/CurriculumSupplement.cs b/ProjectSchedule/ProjectSchedule/Entities/CurriculumSupplement.cs index 101db46..25f45e0 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/CurriculumSupplement.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/CurriculumSupplement.cs @@ -1,17 +1,32 @@ -namespace ProjectSchedule.Entities; +using System.ComponentModel; + +namespace ProjectSchedule.Entities; public class CurriculumSupplement { public int Id { get; private set; } + [Browsable(false)] public int GroupStudentsId { get; private set; } + [DisplayName("Группа студентов")] + public string NameGroup { get; private set; } = string.Empty; + + [DisplayName("Название учебного плана")] public string NameCurriculum { get; private set; } = string.Empty; - + + [DisplayName("Семестр")] public string Semester { get; private set; } = string.Empty; + [DisplayName("Дата принятия плана")] public DateTime DateAdoptionPlan { get; private set; } + [DisplayName("Дисциплины")] + public string Discipline => DisciplineCurriculumSupplements != null ? + string.Join(", ", DisciplineCurriculumSupplements.Select(x => $"{x.NameDiscipline} {x.QuantityLectures} {x.QuantityPractices}")) : + string.Empty; + + [Browsable(false)] public IEnumerable DisciplineCurriculumSupplements { get; private set; } = []; public static CurriculumSupplement CreateOperation(int id, int groupStudentsId, string nameCurriculum, @@ -28,17 +43,11 @@ public class CurriculumSupplement }; } - public static CurriculumSupplement CreateOpeartion(TempDisciplineCurriculumSupplement tempDisciplineCurriculumSupplement, - IEnumerable disciplineCurriculumSupplements) + public void SetDisciplineCurriculumSupplements(IEnumerable disciplineCurriculumSupplements) { - return new CurriculumSupplement + if (disciplineCurriculumSupplements != null && disciplineCurriculumSupplements.Any()) { - Id = tempDisciplineCurriculumSupplement.Id, - GroupStudentsId = tempDisciplineCurriculumSupplement.GroupStudentsId, - NameCurriculum = tempDisciplineCurriculumSupplement.NameCurriculum, - Semester = tempDisciplineCurriculumSupplement.Semester, - DateAdoptionPlan = tempDisciplineCurriculumSupplement.DateAdoptionPlan, - DisciplineCurriculumSupplements = disciplineCurriculumSupplements - }; + DisciplineCurriculumSupplements = disciplineCurriculumSupplements; + } } } \ No newline at end of file diff --git a/ProjectSchedule/ProjectSchedule/Entities/Discipline.cs b/ProjectSchedule/ProjectSchedule/Entities/Discipline.cs index 5b1df40..ac1cdc8 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/Discipline.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/Discipline.cs @@ -1,9 +1,12 @@ -namespace ProjectSchedule.Entities; +using System.ComponentModel; + +namespace ProjectSchedule.Entities; public class Discipline { public int Id { get; private set; } + [DisplayName("Название дисциплины")] public string NameDiscipline { get; private set; } = string.Empty; public static Discipline CreateEntity(int id, string nameDiscipline) diff --git a/ProjectSchedule/ProjectSchedule/Entities/DisciplineCurriculumSupplement.cs b/ProjectSchedule/ProjectSchedule/Entities/DisciplineCurriculumSupplement.cs index 2ff4e0b..ca10f77 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/DisciplineCurriculumSupplement.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/DisciplineCurriculumSupplement.cs @@ -6,6 +6,8 @@ public class DisciplineCurriculumSupplement public int DisciplineId { get; private set; } + public string NameDiscipline { get; private set; } = string.Empty; + public int QuantityLectures { get; private set; } public int QuantityPractices { get; private set; } diff --git a/ProjectSchedule/ProjectSchedule/Entities/Educator.cs b/ProjectSchedule/ProjectSchedule/Entities/Educator.cs index 9d1501b..398219e 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/Educator.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/Educator.cs @@ -1,15 +1,22 @@ -namespace ProjectSchedule.Entities; +using System.ComponentModel; + +namespace ProjectSchedule.Entities; public class Educator { public int Id { get; private set; } + [DisplayName("Фамилия")] public string Surname { get; private set; } = string.Empty; + [DisplayName("Имя")] public string Name { get; private set; } = string.Empty; + [DisplayName("Отчество")] public string Patronymic { get; private set; } = string.Empty; + public string FullName => $"{Surname} {Name} {Patronymic}"; + public static Educator CreateEntity(int id, string surname, string name, string patronymic) { return new Educator diff --git a/ProjectSchedule/ProjectSchedule/Entities/GroupStudents.cs b/ProjectSchedule/ProjectSchedule/Entities/GroupStudents.cs index ffce5c2..1671b92 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/GroupStudents.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/GroupStudents.cs @@ -1,13 +1,20 @@ -namespace ProjectSchedule.Entities; +using System.ComponentModel; + +namespace ProjectSchedule.Entities; public class GroupStudents { public int Id { get; private set; } + [DisplayName("Аббревиатура группы")] public string AbbreviationGroup { get; private set; } = string.Empty; + [DisplayName("Номер группы")] public string GroupNumber { get; private set; } = string.Empty; + public string NameGroup => $"{AbbreviationGroup}-{GroupNumber}"; + + [DisplayName("Количество студентов")] public int QuantityStudents { get; private set; } public static GroupStudents CreateEntity(int id, string abbreviationGroup, string groupNumber, int quantityStudents) diff --git a/ProjectSchedule/ProjectSchedule/Entities/TempDisciplineCurriculumSupplement.cs b/ProjectSchedule/ProjectSchedule/Entities/TempDisciplineCurriculumSupplement.cs deleted file mode 100644 index 88375ac..0000000 --- a/ProjectSchedule/ProjectSchedule/Entities/TempDisciplineCurriculumSupplement.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace ProjectSchedule.Entities; - -public class TempDisciplineCurriculumSupplement -{ - public int Id { get; private set; } - - public int GroupStudentsId { get; private set; } - - public string NameCurriculum { get; private set; } = string.Empty; - - public string Semester { get; private set; } = string.Empty; - - public DateTime DateAdoptionPlan { get; private set; } - - public int DisciplineId { get; private set; } - - public int QuantityLectures { get; private set; } - - public int QuantityPractices { get; private set; } -} \ No newline at end of file diff --git a/ProjectSchedule/ProjectSchedule/Forms/FormAudiences.cs b/ProjectSchedule/ProjectSchedule/Forms/FormAudiences.cs index 4c24825..f827f66 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormAudiences.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormAudiences.cs @@ -86,7 +86,11 @@ namespace ProjectSchedule.Forms } } - private void LoadList() => dataGridViewData.DataSource = _audienceRepository.ReadAudiences(); + private void LoadList() + { + dataGridViewData.DataSource = _audienceRepository.ReadAudiences(); + dataGridViewData.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectSchedule/ProjectSchedule/Forms/FormCompilingSchedule.cs b/ProjectSchedule/ProjectSchedule/Forms/FormCompilingSchedule.cs index 7874bdb..f2b7397 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormCompilingSchedule.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormCompilingSchedule.cs @@ -17,7 +17,7 @@ namespace ProjectSchedule.Forms throw new ArgumentNullException(nameof(сompilingScheduleRepository)); comboBoxEducator.DataSource = educatorRepository.ReadEducators(); - comboBoxEducator.DisplayMember = "Surname"; + comboBoxEducator.DisplayMember = "FullName"; comboBoxEducator.ValueMember = "Id"; comboBoxDiscipline.DataSource = disciplineRepository.ReadDisciplines(); @@ -25,7 +25,7 @@ namespace ProjectSchedule.Forms comboBoxDiscipline.ValueMember = "Id"; comboBoxGroupStudents.DataSource = groupStudentsRepository.ReadGroupsStudents(); - comboBoxGroupStudents.DisplayMember = "AbbreviationGroup"; + comboBoxGroupStudents.DisplayMember = "NameGroup"; comboBoxGroupStudents.ValueMember = "Id"; comboBoxAudience.DataSource = audienceRepository.ReadAudiences(); diff --git a/ProjectSchedule/ProjectSchedule/Forms/FormCompilingSchedules.cs b/ProjectSchedule/ProjectSchedule/Forms/FormCompilingSchedules.cs index a5cdd44..4e5c86d 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormCompilingSchedules.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormCompilingSchedules.cs @@ -43,6 +43,11 @@ namespace ProjectSchedule.Forms } } - private void LoadList() => dataGridViewData.DataSource = _сompilingScheduleRepository.ReadCompilingSchedules(); + private void LoadList() + { + dataGridViewData.DataSource = _сompilingScheduleRepository.ReadCompilingSchedules(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["DateDay"].DefaultCellStyle.Format = "dd.MM.yyyy"; + } } } \ No newline at end of file diff --git a/ProjectSchedule/ProjectSchedule/Forms/FormCurriculumSupplement.cs b/ProjectSchedule/ProjectSchedule/Forms/FormCurriculumSupplement.cs index 1318d3c..3c90ca4 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormCurriculumSupplement.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormCurriculumSupplement.cs @@ -15,7 +15,7 @@ namespace ProjectSchedule.Forms throw new ArgumentNullException(nameof(curriculumSupplementRepository)); comboBoxGroupStudents.DataSource = groupStudentsRepository.ReadGroupsStudents(); - comboBoxGroupStudents.DisplayMember = "AbbreviationGroup"; + comboBoxGroupStudents.DisplayMember = "NameGroup"; comboBoxGroupStudents.ValueMember = "Id"; ColumnDiscipline.DataSource = disciplineRepository.ReadDisciplines(); diff --git a/ProjectSchedule/ProjectSchedule/Forms/FormCurriculumSupplements.cs b/ProjectSchedule/ProjectSchedule/Forms/FormCurriculumSupplements.cs index ebefab8..90f9a3f 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormCurriculumSupplements.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormCurriculumSupplements.cs @@ -67,8 +67,12 @@ namespace ProjectSchedule.Forms } } - private void LoadList() => + private void LoadList() + { dataGridViewData.DataSource = _curriculumSupplementRepository.ReadCurriculumSupplements(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["DateAdoptionPlan"].DefaultCellStyle.Format = "dd MMMM yyyy"; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectSchedule/ProjectSchedule/Forms/FormDisciplines.cs b/ProjectSchedule/ProjectSchedule/Forms/FormDisciplines.cs index a8bdced..eca1519 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormDisciplines.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormDisciplines.cs @@ -86,7 +86,11 @@ namespace ProjectSchedule.Forms } } - private void LoadList() => dataGridViewData.DataSource = _disciplineRepository.ReadDisciplines(); + private void LoadList() + { + dataGridViewData.DataSource = _disciplineRepository.ReadDisciplines(); + dataGridViewData.Columns["Id"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectSchedule/ProjectSchedule/Forms/FormEducators.cs b/ProjectSchedule/ProjectSchedule/Forms/FormEducators.cs index f565951..a93c0d6 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormEducators.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormEducators.cs @@ -86,7 +86,12 @@ namespace ProjectSchedule.Forms } } - private void LoadList() => dataGridViewData.DataSource = _educatorRepository.ReadEducators(); + private void LoadList() + { + dataGridViewData.DataSource = _educatorRepository.ReadEducators(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["FullName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectSchedule/ProjectSchedule/Forms/FormGroupsStudents.cs b/ProjectSchedule/ProjectSchedule/Forms/FormGroupsStudents.cs index 0e4a0b8..4502beb 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormGroupsStudents.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormGroupsStudents.cs @@ -86,7 +86,12 @@ namespace ProjectSchedule.Forms } } - private void LoadList() => dataGridViewData.DataSource = _groupStudentsRepository.ReadGroupsStudents(); + private void LoadList() + { + dataGridViewData.DataSource = _groupStudentsRepository.ReadGroupsStudents(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["NameGroup"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectSchedule/ProjectSchedule/Reports/ChartReport.cs b/ProjectSchedule/ProjectSchedule/Reports/ChartReport.cs index 2b1f35d..0b18b13 100644 --- a/ProjectSchedule/ProjectSchedule/Reports/ChartReport.cs +++ b/ProjectSchedule/ProjectSchedule/Reports/ChartReport.cs @@ -22,7 +22,7 @@ internal class ChartReport try { new PdfBuilder(filePath) - .AddHeader("Количество пар") + .AddHeader($"Количество пар на {dateTime:dd MMMM yyyy}") .AddPieChart("Группы студентов", GetData(dateTime)) .Build(); @@ -38,10 +38,9 @@ internal class ChartReport private List<(string Caption, double Value)> GetData(DateTime dateTime) { return _compilingScheduleRepository - .ReadCompilingSchedules() - .Where(x => x.DateDay.Date == dateTime.Date) - .GroupBy(x => x.GroupStudentsId, (key, group) => new { Id = key, Count = group.Count() }) - .Select(x => (x.Id.ToString(), (double)x.Count)) + .ReadCompilingSchedules(dateForm: dateTime.Date, dateTo: dateTime.Date.AddDays(1)) + .GroupBy(x => x.NameGroup, (key, group) => new { NameGroup = key, Count = group.Count() }) + .Select(x => (x.NameGroup, (double)x.Count)) .ToList(); } } \ No newline at end of file diff --git a/ProjectSchedule/ProjectSchedule/Reports/TableReport.cs b/ProjectSchedule/ProjectSchedule/Reports/TableReport.cs index bd43e3f..7ef55b0 100644 --- a/ProjectSchedule/ProjectSchedule/Reports/TableReport.cs +++ b/ProjectSchedule/ProjectSchedule/Reports/TableReport.cs @@ -33,7 +33,7 @@ internal class TableReport { new ExcelBuilder(filePath) .AddHeader("Сводка по прохождению дисциплин", 0, 7) - .AddParagraph("за период", 0) + .AddParagraph($"за период c {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0) .AddTable([15, 15, 15, 10, 10, 10, 10], GetData(disciplineId, startDate, endDate)) .Build(); @@ -49,18 +49,17 @@ internal class TableReport private List GetData(int disciplineId, DateTime startDate, DateTime endDate) { var data = _curriculumSupplementRepository - .ReadCurriculumSupplements() - .Where(x => x.DateAdoptionPlan <= startDate && x.DisciplineCurriculumSupplements.Any(y => y.DisciplineId == disciplineId)) - .Select(x => new { Date = x.DateAdoptionPlan, Discipline = disciplineId, x.GroupStudentsId, + .ReadCurriculumSupplements(dateForm: startDate, disciplineId: disciplineId) + .Select(x => new { Date = x.DateAdoptionPlan, + Discipline = x.DisciplineCurriculumSupplements.FirstOrDefault(y => y.DisciplineId == disciplineId)?.NameDiscipline ?? string.Empty, x.NameGroup, CountLectures = x.DisciplineCurriculumSupplements.FirstOrDefault(y => y.DisciplineId == disciplineId)?.QuantityLectures, CountPractices = x.DisciplineCurriculumSupplements.FirstOrDefault(y => y.DisciplineId == disciplineId)?.QuantityPractices, ConductedLectures = (int?)null, ConductedPractices = (int?)null }) .Union( _compilingScheduleRepository - .ReadCompilingSchedules() - .Where(x => x.DateDay >= startDate && x.DateDay <= endDate && x.DisciplineId == disciplineId) - .GroupBy(x => new { x.DateDay, x.GroupStudentsId }) - .Select(g => new { Date = g.Key.DateDay, Discipline = disciplineId, g.Key.GroupStudentsId, CountLectures = (int?)null, + .ReadCompilingSchedules(dateForm: startDate, dateTo: endDate, disciplineId: disciplineId) + .GroupBy(x => new { x.DateDay, x.NameDiscipline, x.NameGroup}) + .Select(g => new { Date = g.Key.DateDay, Discipline = g.Key.NameDiscipline ?? string.Empty, g.Key.NameGroup, CountLectures = (int?)null, CountPractices = (int?)null, ConductedLectures = CalculateConductedLectures(g) == 0 ? (int?)null : CalculateConductedLectures(g), ConductedPractices = CalculateConductedPractices(g) == 0 ? (int?)null : CalculateConductedPractices(g)})) .OrderBy(x => x.Date); @@ -69,12 +68,12 @@ internal class TableReport new List() { item } .Union( data - .Select(x => new string[] { x.Date.ToString("dd.MM.yyyy"), x.Discipline.ToString(), x.GroupStudentsId.ToString(), - x.CountLectures?.ToString() ?? string.Empty, x.CountPractices?.ToString() ?? string.Empty, - x.ConductedLectures?.ToString() ?? string.Empty, x.ConductedPractices?.ToString() ?? string.Empty })) + .Select(x => new string[] { x.Date.ToString("dd.MM.yyyy"), x.Discipline, x.NameGroup, + x.CountLectures?.ToString("N0") ?? string.Empty, x.CountPractices?.ToString("N0") ?? string.Empty, + x.ConductedLectures?.ToString("N0") ?? string.Empty, x.ConductedPractices?.ToString("N0") ?? string.Empty })) .Union( - [["Всего", "", "", data.Sum(x => x.CountLectures ?? 0).ToString(), data.Sum(x => x.CountPractices ?? 0).ToString(), - data.Sum(x => x.ConductedLectures ?? 0).ToString(), data.Sum(x => x.ConductedPractices ?? 0).ToString()]]) + [["Всего", "", "", data.Sum(x => x.CountLectures ?? 0).ToString("N0"), data.Sum(x => x.CountPractices ?? 0).ToString("N0"), + data.Sum(x => x.ConductedLectures ?? 0).ToString("N0"), data.Sum(x => x.ConductedPractices ?? 0).ToString("N0")]]) .ToList(); } diff --git a/ProjectSchedule/ProjectSchedule/Repositories/ICurriculumSupplementRepository.cs b/ProjectSchedule/ProjectSchedule/Repositories/ICurriculumSupplementRepository.cs index d2f2f1a..5f3932c 100644 --- a/ProjectSchedule/ProjectSchedule/Repositories/ICurriculumSupplementRepository.cs +++ b/ProjectSchedule/ProjectSchedule/Repositories/ICurriculumSupplementRepository.cs @@ -4,7 +4,7 @@ namespace ProjectSchedule.Repositories; public interface ICurriculumSupplementRepository { - IEnumerable ReadCurriculumSupplements(DateTime? dateForm = null, DateTime? dateTo = null, + IEnumerable ReadCurriculumSupplements(DateTime? dateForm = null, int? disciplineId = null, int? groupStudentsId = null); void CreateCurriculumSupplement(CurriculumSupplement curriculumSupplement); diff --git a/ProjectSchedule/ProjectSchedule/Repositories/Implementations/CompilingScheduleRepository.cs b/ProjectSchedule/ProjectSchedule/Repositories/Implementations/CompilingScheduleRepository.cs index 2c539a5..132b5c7 100644 --- a/ProjectSchedule/ProjectSchedule/Repositories/Implementations/CompilingScheduleRepository.cs +++ b/ProjectSchedule/ProjectSchedule/Repositories/Implementations/CompilingScheduleRepository.cs @@ -45,9 +45,48 @@ TypeWeek, NumberDay, NumberPair, TypeActivity) _logger.LogInformation("Получение всех объектов"); try { + var builder = new QueryBuilder(); + if (dateForm.HasValue) + { + builder.AddCondition("cs.DateDay >= @dateForm"); + } + if (dateTo.HasValue) + { + builder.AddCondition("cs.DateDay <= @dateTo"); + } + if (educatorId.HasValue) + { + builder.AddCondition("cs.EducatorId = @educatorId"); + } + if (disciplineId.HasValue) + { + builder.AddCondition("cs.DisciplineId = @disciplineId"); + } + if (groupStudentsId.HasValue) + { + builder.AddCondition("cs.GroupStudentsId = @groupStudentsId"); + } + if (audienceId.HasValue) + { + builder.AddCondition("cs.AudienceId = @audienceId"); + } + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = "SELECT * FROM CompilingSchedules"; - var compilingSchedules = connection.Query(querySelect); + var querySelect = $@" + SELECT + cs.*, + CONCAT(e.Surname, ' ', e.Name, ' ', e.Patronymic) AS EducatorName, + d.NameDiscipline AS NameDiscipline, + CONCAT(gs.AbbreviationGroup, '-', gs.GroupNumber) AS NameGroup, + a.NumberAudience AS NumberAudience + FROM CompilingSchedules cs + LEFT JOIN Educators e ON e.Id = cs.EducatorId + LEFT JOIN Disciplines d ON d.Id = cs.DisciplineId + LEFT JOIN GroupsStudents gs ON gs.Id = cs.GroupStudentsId + LEFT JOIN Audiences a ON a.Id = cs.AudienceId + {builder.Build()}"; + var compilingSchedules = connection.Query(querySelect, + new {dateForm, dateTo, educatorId, disciplineId, groupStudentsId, audienceId }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(compilingSchedules)); return compilingSchedules; } diff --git a/ProjectSchedule/ProjectSchedule/Repositories/Implementations/CurriculumSupplementRepository.cs b/ProjectSchedule/ProjectSchedule/Repositories/Implementations/CurriculumSupplementRepository.cs index 5aaa3b0..87fa3f4 100644 --- a/ProjectSchedule/ProjectSchedule/Repositories/Implementations/CurriculumSupplementRepository.cs +++ b/ProjectSchedule/ProjectSchedule/Repositories/Implementations/CurriculumSupplementRepository.cs @@ -69,22 +69,62 @@ public class CurriculumSupplementRepository : ICurriculumSupplementRepository } } - public IEnumerable ReadCurriculumSupplements(DateTime? dateForm = null, DateTime? dateTo = null, - int? disciplineId = null, int? groupStudentsId = null) + public IEnumerable ReadCurriculumSupplements(DateTime? dateForm = null, int? disciplineId = null, + int? groupStudentsId = null) { _logger.LogInformation("Получение всех объектов"); try { + var builder = new QueryBuilder(); + if (dateForm.HasValue) + { + builder.AddCondition("cs.DateAdoptionPlan <= @dateForm"); + } + if (groupStudentsId.HasValue) + { + builder.AddCondition("cs.GroupStudentsId = @groupStudentsId"); + } + if (disciplineId.HasValue) + { + builder.AddCondition("dcs.DisciplineId = @disciplineId"); + } + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @" - SELECT cs.*, dcs.DisciplineId, dcs.QuantityLectures, dcs.QuantityPractices FROM CurriculumSupplements cs - INNER JOIN DisciplineCurriculumSupplements dcs ON dcs.CurriculumSupplementId = cs.Id"; - var curriculumSupplements = connection.Query(querySelect); + var querySelect = $@" + SELECT + cs.*, + CONCAT(gs.AbbreviationGroup, '-', gs.GroupNumber) AS NameGroup, + dcs.DisciplineId, + dcs.QuantityLectures, + dcs.QuantityPractices, + d.NameDiscipline AS NameDiscipline + FROM CurriculumSupplements cs + LEFT JOIN GroupsStudents gs ON gs.Id = cs.GroupStudentsId + INNER JOIN DisciplineCurriculumSupplements dcs ON dcs.CurriculumSupplementId = cs.Id + LEFT JOIN Disciplines d ON d.Id = dcs.DisciplineId + {builder.Build()}"; + var supplementDict = new Dictionary>(); + + var curriculumSupplements = connection.Query(querySelect, + (supplement, curriculumSupplements) => + { + if (!supplementDict.TryGetValue(supplement.Id, out var dcs)) + { + dcs = []; + supplementDict.Add(supplement.Id, dcs); + } + + dcs.Add(curriculumSupplements); + return supplement; + }, splitOn: "DisciplineId", param: new { dateForm, disciplineId, groupStudentsId }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(curriculumSupplements)); - return curriculumSupplements.GroupBy(x => x.Id, y => y, - (key, value) => CurriculumSupplement.CreateOpeartion(value.First(), - value.Select(z => DisciplineCurriculumSupplement.CreateElement(0, z.DisciplineId, z.QuantityLectures, z.QuantityPractices)))).ToList(); + return supplementDict.Select(x => + { + var cs = curriculumSupplements.First(y => y.Id == x.Key); + cs.SetDisciplineCurriculumSupplements(x.Value); + return cs; + }).ToArray(); } catch (Exception ex) { diff --git a/ProjectSchedule/ProjectSchedule/Repositories/Implementations/QueryBuilder.cs b/ProjectSchedule/ProjectSchedule/Repositories/Implementations/QueryBuilder.cs new file mode 100644 index 0000000..a55d712 --- /dev/null +++ b/ProjectSchedule/ProjectSchedule/Repositories/Implementations/QueryBuilder.cs @@ -0,0 +1,35 @@ +using System.Text; + +namespace ProjectSchedule.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 -- 2.25.1