From ab2fb2021475b88c2d588ca4096a4a369f8fabcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B7=D0=B0=D0=BC=D0=B0=D1=82=20=D0=98=D1=88=D1=82?= =?UTF-8?q?=D1=83=D0=B3=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Tue, 24 Dec 2024 21:45:53 +0400 Subject: [PATCH] =?UTF-8?q?=D1=87=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D1=82?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectSchedule/Entities/Audience.cs | 7 +++ .../ProjectSchedule/Entities/Discipline.cs | 3 + .../DisciplineStudingPlanSupplement.cs | 1 + .../ProjectSchedule/Entities/Group.cs | 9 +++ .../ProjectSchedule/Entities/Schedule.cs | 31 ++++++++++ .../Entities/StudingPlanSupplement.cs | 27 +++++---- .../ProjectSchedule/Entities/Teacher.cs | 8 +++ .../TempDisciplineStudingPlanSupplement.cs | 20 ------- .../ProjectSchedule/Forms/FormAudiences.cs | 6 +- .../Forms/FormDisciplineReport.cs | 2 +- .../ProjectSchedule/Forms/FormDisciplines.cs | 6 +- .../ProjectSchedule/Forms/FormGroups.cs | 7 ++- .../ProjectSchedule/Forms/FormSchedule.cs | 6 +- .../ProjectSchedule/Forms/FormSchedules.cs | 7 ++- .../Forms/FormStudingPlanSupplements.cs | 6 +- .../ProjectSchedule/Forms/FormTeachers.cs | 7 ++- .../ProjectSchedule/Reports/ChartReport.cs | 9 ++- .../ProjectSchedule/Reports/TableReport.cs | 28 +++++---- .../IStudingPlanSupplementRepository.cs | 2 +- .../Implementations/QueryBuilder.cs | 35 +++++++++++ .../Implementations/ScheduleRepository.cs | 42 +++++++++++++- .../StudingPlanSupplementRepository.cs | 58 ++++++++++++++++--- 22 files changed, 255 insertions(+), 72 deletions(-) delete mode 100644 ProjectSchedule/ProjectSchedule/Entities/TempDisciplineStudingPlanSupplement.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 2449cb0..92fc587 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/Audience.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/Audience.cs @@ -4,14 +4,21 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.ComponentModel; namespace ProjectSchedule.Entities; public class Audience { public int Id { get; private set; } + + [DisplayName("Номер аудитории")] public string Number { get; private set; } = string.Empty; + + [DisplayName("Количество мест")] public int SeatsCount { get; private set; } + + [DisplayName("Тип аудитории")] public TypeAudience TypeAudience { get; private set; } public static Audience CreateEntity(int id, string number, TypeAudience typeAudience, int seatsCount) diff --git a/ProjectSchedule/ProjectSchedule/Entities/Discipline.cs b/ProjectSchedule/ProjectSchedule/Entities/Discipline.cs index 4992dc1..4601642 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/Discipline.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/Discipline.cs @@ -3,12 +3,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.ComponentModel; namespace ProjectSchedule.Entities; public class Discipline { public int Id { get; private set; } + + [DisplayName("Название дисциплины")] public string Name { get; private set; } = string.Empty; public static Discipline CreateEntity(int id, string name) diff --git a/ProjectSchedule/ProjectSchedule/Entities/DisciplineStudingPlanSupplement.cs b/ProjectSchedule/ProjectSchedule/Entities/DisciplineStudingPlanSupplement.cs index 6f1b06d..7aceb51 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/DisciplineStudingPlanSupplement.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/DisciplineStudingPlanSupplement.cs @@ -10,6 +10,7 @@ public class DisciplineStudingPlanSupplement { public int Id { get; private set; } public int DisciplineId { get; private set; } + public string NameDiscipline { get; private set; } = string.Empty; public int LecturesCount { get; private set; } public int PracticesCount { get; private set; } diff --git a/ProjectSchedule/ProjectSchedule/Entities/Group.cs b/ProjectSchedule/ProjectSchedule/Entities/Group.cs index 4c7903a..232d3e5 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/Group.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/Group.cs @@ -3,14 +3,23 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.ComponentModel; namespace ProjectSchedule.Entities; public class Group { public int Id { get; private set; } + + [DisplayName("Название группы")] public string Name { get; private set; } = string.Empty; + + [DisplayName("Номер группы")] public string GroupNumber { get; private set; } = string.Empty; + + public string NameGroup => $"{Name}-{GroupNumber}"; + + [DisplayName("Количество студентов")] public int StudentsCount { get; private set; } public static Group CreateEntity(int id, string name, string groupNumber, int studentsCount) diff --git a/ProjectSchedule/ProjectSchedule/Entities/Schedule.cs b/ProjectSchedule/ProjectSchedule/Entities/Schedule.cs index dc1c35f..e3967fd 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/Schedule.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/Schedule.cs @@ -4,20 +4,51 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.ComponentModel; namespace ProjectSchedule.Entities; public class Schedule { public int Id { get; private set; } + + [Browsable(false)] public int TeacherId { get; private set; } + + [Browsable(false)] public int DisciplineId { get; private set; } + + [Browsable(false)] public int GroupId { get; private set; } + + [Browsable(false)] public int AudienceId { get; private set; } + + [DisplayName("Преподаватель")] + public string TeacherName { 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 int NumberDay { get; private set; } + + [DisplayName("Номер пары")] public int NumberPair { get; private set; } + + [DisplayName("Номер недели")] public TypeWeek TypeWeek { get; private set; } + + [DisplayName("Тип пары")] public TypePair TypePair { get; private set; } public static Schedule CreateOperation(int id, int teacherId, int disciplineId, int groupId, int audienceId, diff --git a/ProjectSchedule/ProjectSchedule/Entities/StudingPlanSupplement.cs b/ProjectSchedule/ProjectSchedule/Entities/StudingPlanSupplement.cs index 174a094..27f4ff4 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/StudingPlanSupplement.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/StudingPlanSupplement.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.ComponentModel; namespace ProjectSchedule.Entities; @@ -10,14 +11,26 @@ public class StudingPlanSupplement { public int Id { get; private set; } + [Browsable(false)] public int GroupId { get; private set; } + [DisplayName("Группа студентов")] + public string NameGroup { get; private set; } = string.Empty; + + [DisplayName("Название учебного плана")] public string NameStudingPlan { get; private set; } = string.Empty; + [DisplayName("Семестр")] public string Semester { get; private set; } = string.Empty; + [DisplayName("Дата принятия плана")] public DateTime DateApprovePlan { get; private set; } + [DisplayName("Дисциплины")] + public string Discipline => DisciplineStudingPlanSupplements != null ? + string.Join(", ", DisciplineStudingPlanSupplements.Select(x => $"{x.NameDiscipline} {x.LecturesCount} {x.PracticesCount}")) : string.Empty; + + [Browsable(false)] public IEnumerable DisciplineStudingPlanSupplements { get; private set; } = []; public static StudingPlanSupplement CreateOperation(int id, int groupId, string nameStudingPlan, @@ -34,17 +47,11 @@ public class StudingPlanSupplement }; } - public static StudingPlanSupplement CreateOperation(TempDisciplineStudingPlanSupplement tempDisciplineStudingPlanSupplement, - IEnumerable disciplineStudingPlanSupplements) + public void SetDisciplineStudingPlanSupplements(IEnumerable disciplineStudingPlanSupplements) { - return new StudingPlanSupplement + if (disciplineStudingPlanSupplements != null && disciplineStudingPlanSupplements.Any()) { - Id = tempDisciplineStudingPlanSupplement.Id, - GroupId = tempDisciplineStudingPlanSupplement.GroupId, - NameStudingPlan = tempDisciplineStudingPlanSupplement.NameStudingPlan, - Semester = tempDisciplineStudingPlanSupplement.Semester, - DateApprovePlan = tempDisciplineStudingPlanSupplement.DateApprovePlan, - DisciplineStudingPlanSupplements = disciplineStudingPlanSupplements - }; + DisciplineStudingPlanSupplements = disciplineStudingPlanSupplements; + } } } \ No newline at end of file diff --git a/ProjectSchedule/ProjectSchedule/Entities/Teacher.cs b/ProjectSchedule/ProjectSchedule/Entities/Teacher.cs index 598dc0d..b7226e2 100644 --- a/ProjectSchedule/ProjectSchedule/Entities/Teacher.cs +++ b/ProjectSchedule/ProjectSchedule/Entities/Teacher.cs @@ -3,16 +3,24 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.ComponentModel; namespace ProjectSchedule.Entities; public class Teacher { 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 Teacher CreateEntity(int id, string surname, string name, string patronymic) { return new Teacher diff --git a/ProjectSchedule/ProjectSchedule/Entities/TempDisciplineStudingPlanSupplement.cs b/ProjectSchedule/ProjectSchedule/Entities/TempDisciplineStudingPlanSupplement.cs deleted file mode 100644 index 1f128d9..0000000 --- a/ProjectSchedule/ProjectSchedule/Entities/TempDisciplineStudingPlanSupplement.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace ProjectSchedule.Entities; - -public class TempDisciplineStudingPlanSupplement -{ - public int Id { get; private set; } - - public int GroupId { get; private set; } - - public string NameStudingPlan { get; private set; } = string.Empty; - - public string Semester { get; private set; } = string.Empty; - - public DateTime DateApprovePlan { get; private set; } - - public int DisciplineId { get; private set; } - - public int LecturesCount { get; private set; } - - public int PracticesCount { 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/FormDisciplineReport.cs b/ProjectSchedule/ProjectSchedule/Forms/FormDisciplineReport.cs index 3c214c4..b9d71de 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormDisciplineReport.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormDisciplineReport.cs @@ -15,7 +15,7 @@ namespace ProjectSchedule.Forms throw new ArgumentNullException(nameof(container)); comboBoxDiscipline.DataSource = disciplineRepository.ReadDisciplines(); - comboBoxDiscipline.DisplayMember = "NameDiscipline"; + comboBoxDiscipline.DisplayMember = "Name"; comboBoxDiscipline.ValueMember = "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/FormGroups.cs b/ProjectSchedule/ProjectSchedule/Forms/FormGroups.cs index dcb7a1a..0fefd59 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormGroups.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormGroups.cs @@ -86,7 +86,12 @@ namespace ProjectSchedule.Forms } } - private void LoadList() => dataGridViewData.DataSource = _groupRepository.ReadGroups(); + private void LoadList() + { + dataGridViewData.DataSource = _groupRepository.ReadGroups(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["NameGroup"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectSchedule/ProjectSchedule/Forms/FormSchedule.cs b/ProjectSchedule/ProjectSchedule/Forms/FormSchedule.cs index dedb4a2..d4438ae 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormSchedule.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormSchedule.cs @@ -17,11 +17,11 @@ namespace ProjectSchedule.Forms throw new ArgumentNullException(nameof(scheduleRepository)); comboBoxTeacher.DataSource = teacherRepository.ReadTeachers(); - comboBoxTeacher.DisplayMember = "Surname"; + comboBoxTeacher.DisplayMember = "FullName"; comboBoxTeacher.ValueMember = "Id"; comboBoxDiscipline.DataSource = disciplineRepository.ReadDisciplines(); - comboBoxDiscipline.DisplayMember = "NameDiscipline"; + comboBoxDiscipline.DisplayMember = "Name"; comboBoxDiscipline.ValueMember = "Id"; comboBoxGroup.DataSource = groupRepository.ReadGroups(); @@ -29,7 +29,7 @@ namespace ProjectSchedule.Forms comboBoxGroup.ValueMember = "Id"; comboBoxAudience.DataSource = audienceRepository.ReadAudiences(); - comboBoxAudience.DisplayMember = "NumberAudience"; + comboBoxAudience.DisplayMember = "Number"; comboBoxAudience.ValueMember = "Id"; comboBoxTypeWeek.DataSource = Enum.GetValues(typeof(TypeWeek)); diff --git a/ProjectSchedule/ProjectSchedule/Forms/FormSchedules.cs b/ProjectSchedule/ProjectSchedule/Forms/FormSchedules.cs index 0b6dcbc..fc314cb 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormSchedules.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormSchedules.cs @@ -43,6 +43,11 @@ namespace ProjectSchedule.Forms } } - private void LoadList() => dataGridViewData.DataSource = _scheduleRepository.ReadSchedules(); + private void LoadList() + { + dataGridViewData.DataSource = _scheduleRepository.ReadSchedules(); + 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/FormStudingPlanSupplements.cs b/ProjectSchedule/ProjectSchedule/Forms/FormStudingPlanSupplements.cs index bad41e7..9ca81d8 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormStudingPlanSupplements.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormStudingPlanSupplements.cs @@ -67,8 +67,12 @@ namespace ProjectSchedule.Forms } } - private void LoadList() => + private void LoadList() + { dataGridViewData.DataSource = _studingPlanSupplementRepository.ReadStudingPlanSupplements(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["DateApprovePlan"].DefaultCellStyle.Format = "dd MMMM yyyy"; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectSchedule/ProjectSchedule/Forms/FormTeachers.cs b/ProjectSchedule/ProjectSchedule/Forms/FormTeachers.cs index c6c0749..7764134 100644 --- a/ProjectSchedule/ProjectSchedule/Forms/FormTeachers.cs +++ b/ProjectSchedule/ProjectSchedule/Forms/FormTeachers.cs @@ -86,7 +86,12 @@ namespace ProjectSchedule.Forms } } - private void LoadList() => dataGridViewData.DataSource = _teacherRepository.ReadTeachers(); + private void LoadList() + { + dataGridViewData.DataSource = _teacherRepository.ReadTeachers(); + dataGridViewData.Columns["Id"].Visible = false; + dataGridViewData.Columns["FullName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectSchedule/ProjectSchedule/Reports/ChartReport.cs b/ProjectSchedule/ProjectSchedule/Reports/ChartReport.cs index 249774f..3ef5f9b 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 _scheduleRepository - .ReadSchedules() - .Where(x => x.DateDay.Date == dateTime.Date) - .GroupBy(x => x.GroupId, (key, group) => new { Id = key, Count = group.Count() }) - .Select(x => (x.Id.ToString(), (double)x.Count)) + .ReadSchedules(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 c851b63..ac58003 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([10, 10, 10, 10, 10, 10, 10], GetData(disciplineId, startDate, endDate)) .Build(); @@ -49,12 +49,11 @@ internal class TableReport private List GetData(int disciplineId, DateTime startDate, DateTime endDate) { var data = _studingPlanSupplementRepository - .ReadStudingPlanSupplements() - .Where(x => x.DateApprovePlan <= startDate && x.DisciplineStudingPlanSupplements.Any(y => y.DisciplineId == disciplineId)) + .ReadStudingPlanSupplements(dateForm: startDate, disciplineId: disciplineId) .Select(x => new { Date = x.DateApprovePlan, - Discipline = disciplineId, - x.GroupId, + Discipline = x.DisciplineStudingPlanSupplements.FirstOrDefault(y => y.DisciplineId == disciplineId)?.NameDiscipline ?? string.Empty, + x.NameGroup, CountLectures = x.DisciplineStudingPlanSupplements.FirstOrDefault(y => y.DisciplineId == disciplineId)?.LecturesCount, CountPractices = x.DisciplineStudingPlanSupplements.FirstOrDefault(y => y.DisciplineId == disciplineId)?.PracticesCount, PastLectures = (int?)null, @@ -62,13 +61,12 @@ internal class TableReport }) .Union( _scheduleRepository - .ReadSchedules() - .Where(x => x.DateDay >= startDate && x.DateDay <= endDate && x.DisciplineId == disciplineId) - .GroupBy(x => new { x.DateDay, x.GroupId }) + .ReadSchedules(dateForm: startDate, dateTo: endDate, disciplineId: disciplineId) + .GroupBy(x => new { x.DateDay, x.NameDiscipline, x.NameGroup }) .Select(g => new { Date = g.Key.DateDay, - Discipline = disciplineId, - g.Key.GroupId, + Discipline = g.Key.NameDiscipline ?? string.Empty, + g.Key.NameGroup, CountLectures = (int?)null, CountPractices = (int?)null, PastLectures = g.Count(s => s.TypePair == TypePair.Lecture) == 0 ? (int?)null : g.Count(s => s.TypePair == TypePair.Lecture), @@ -80,12 +78,12 @@ internal class TableReport new List() { item } .Union( data - .Select(x => new string[] { x.Date.ToString("dd.MM.yyyy"), x.Discipline.ToString(), x.GroupId.ToString(), - x.CountLectures?.ToString() ?? string.Empty, x.CountPractices?.ToString() ?? string.Empty, - x.PastLectures?.ToString() ?? string.Empty, x.PastPractices?.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.PastLectures?.ToString("N0") ?? string.Empty, x.PastPractices?.ToString("N0") ?? string.Empty })) .Union( - [["Всего", "", "", data.Sum(x => x.CountLectures ?? 0).ToString(), data.Sum(x => x.CountPractices ?? 0).ToString(), - data.Sum(x => x.PastLectures ?? 0).ToString(), data.Sum(x => x.PastPractices ?? 0).ToString()]]) + [["Всего", "", "", data.Sum(x => x.CountLectures ?? 0).ToString("N0"), data.Sum(x => x.CountPractices ?? 0).ToString("N0"), + data.Sum(x => x.PastLectures ?? 0).ToString("N0"), data.Sum(x => x.PastPractices ?? 0).ToString("N0")]]) .ToList(); } } \ No newline at end of file diff --git a/ProjectSchedule/ProjectSchedule/Repositories/IStudingPlanSupplementRepository.cs b/ProjectSchedule/ProjectSchedule/Repositories/IStudingPlanSupplementRepository.cs index 634c319..0891823 100644 --- a/ProjectSchedule/ProjectSchedule/Repositories/IStudingPlanSupplementRepository.cs +++ b/ProjectSchedule/ProjectSchedule/Repositories/IStudingPlanSupplementRepository.cs @@ -9,7 +9,7 @@ namespace ProjectSchedule.Repositories; public interface IStudingPlanSupplementRepository { - IEnumerable ReadStudingPlanSupplements(DateTime? dateForm = null, DateTime? dateTo = null, + IEnumerable ReadStudingPlanSupplements(DateTime? dateForm = null, int? disciplineId = null, int? groupStudentsId = null); void CreateStudingPlanSupplement(StudingPlanSupplement studingPlanSupplement); void DeleteStudingPlanSupplement(int id); 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 diff --git a/ProjectSchedule/ProjectSchedule/Repositories/Implementations/ScheduleRepository.cs b/ProjectSchedule/ProjectSchedule/Repositories/Implementations/ScheduleRepository.cs index cc3ce1e..32ce46d 100644 --- a/ProjectSchedule/ProjectSchedule/Repositories/Implementations/ScheduleRepository.cs +++ b/ProjectSchedule/ProjectSchedule/Repositories/Implementations/ScheduleRepository.cs @@ -45,9 +45,47 @@ TypeWeek, NumberDay, NumberPair, TypePair) _logger.LogInformation("Получение всех объектов"); try { + var builder = new QueryBuilder(); + if (dateForm.HasValue) + { + builder.AddCondition("s.DateDay >= @dateForm"); + } + if (dateTo.HasValue) + { + builder.AddCondition("s.DateDay <= @dateTo"); + } + if (teacherId.HasValue) + { + builder.AddCondition("s.TeacherId = @teacherId"); + } + if (disciplineId.HasValue) + { + builder.AddCondition("s.DisciplineId = @disciplineId"); + } + if (groupStudentsId.HasValue) + { + builder.AddCondition("s.GroupStudentsId = @groupStudentsId"); + } + if (audienceId.HasValue) + { + builder.AddCondition("s.AudienceId = @audienceId"); + } using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = "SELECT * FROM Schedule"; - var schedules = connection.Query(querySelect); + var querySelect = $@" + SELECT + s.*, + CONCAT(e.Surname, ' ', e.Name, ' ', e.Patronymic) AS TeacherName, + d.Name AS NameDiscipline, + CONCAT(g.Name, '-', g.GroupNumber) AS NameGroup, + a.Number AS NumberAudience + FROM Schedule s + LEFT JOIN Teacher e ON e.Id = s.TeacherId + LEFT JOIN Discipline d ON d.Id = s.DisciplineId + LEFT JOIN Groups g ON g.Id = s.GroupId + LEFT JOIN Audience a ON a.Id = s.AudienceId + {builder.Build()}"; + var schedules = connection.Query(querySelect, + new { dateForm, dateTo, teacherId, disciplineId, groupStudentsId, audienceId }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(schedules)); return schedules; } diff --git a/ProjectSchedule/ProjectSchedule/Repositories/Implementations/StudingPlanSupplementRepository.cs b/ProjectSchedule/ProjectSchedule/Repositories/Implementations/StudingPlanSupplementRepository.cs index 61f32eb..322c39f 100644 --- a/ProjectSchedule/ProjectSchedule/Repositories/Implementations/StudingPlanSupplementRepository.cs +++ b/ProjectSchedule/ProjectSchedule/Repositories/Implementations/StudingPlanSupplementRepository.cs @@ -69,22 +69,62 @@ public class StudingPlanSupplementRepository : IStudingPlanSupplementRepository } } - public IEnumerable ReadStudingPlanSupplements(DateTime? dateForm = null, DateTime? dateTo = null, - int? disciplineId = null, int? groupStudentsId = null) + public IEnumerable ReadStudingPlanSupplements(DateTime? dateForm = null, int? disciplineId = null, + int? groupStudentsId = null) { _logger.LogInformation("Получение всех объектов"); try { + var builder = new QueryBuilder(); + if (dateForm.HasValue) + { + builder.AddCondition("sps.DateApprovePlan <= @dateForm"); + } + if (groupStudentsId.HasValue) + { + builder.AddCondition("sps.GroupId = @groupStudentsId"); + } + if (disciplineId.HasValue) + { + builder.AddCondition("dsps.DisciplineId = @disciplineId"); + } + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @" - SELECT sps.*, dsps.DisciplineId, dsps.LecturesCount, dsps.PracticesCount FROM StudingPlanSupplement sps - INNER JOIN Discipline_StudingPlanSupplement dsps ON dsps.StudingPlanSupplementId = sps.Id"; - var studingPlanSupplements = connection.Query(querySelect); + var querySelect = $@" + SELECT + sps.*, + CONCAT(g.Name, '-', g.GroupNumber) AS NameGroup, + dsps.DisciplineId, + dsps.LecturesCount, + dsps.PracticesCount, + d.Name AS NameDiscipline + FROM StudingPlanSupplement sps + LEFT JOIN Groups g ON g.Id = sps.GroupId + INNER JOIN Discipline_StudingPlanSupplement dsps ON dsps.StudingPlanSupplementId = sps.Id + LEFT JOIN Discipline d ON d.Id = dsps.DisciplineId + {builder.Build()}"; + var supplementDict = new Dictionary>(); + + var studingPlanSupplements = connection.Query(querySelect, + (supplement, studingPlanSupplements) => + { + if (!supplementDict.TryGetValue(supplement.Id, out var dsps)) + { + dsps = []; + supplementDict.Add(supplement.Id, dsps); + } + + dsps.Add(studingPlanSupplements); + return supplement; + }, splitOn: "DisciplineId", param: new { dateForm, disciplineId, groupStudentsId }); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(studingPlanSupplements)); - return studingPlanSupplements.GroupBy(x => x.Id, y => y, - (key, value) => StudingPlanSupplement.CreateOperation(value.First(), - value.Select(z => DisciplineStudingPlanSupplement.CreateElement(0, z.DisciplineId, z.LecturesCount, z.PracticesCount)))).ToList(); + return supplementDict.Select(x => + { + var cs = studingPlanSupplements.First(y => y.Id == x.Key); + cs.SetDisciplineStudingPlanSupplements(x.Value); + return cs; + }).ToArray(); } catch (Exception ex) { -- 2.25.1