ПИбд-23. Иштуганов А.М. Четвертая лабораторная #4

Open
Azamat wants to merge 1 commits from LabWork_4 into LabWork_3
22 changed files with 255 additions and 72 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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; }

View File

@ -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)

View File

@ -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,

View File

@ -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<DisciplineStudingPlanSupplement> 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<DisciplineStudingPlanSupplement> disciplineStudingPlanSupplements)
public void SetDisciplineStudingPlanSupplements(IEnumerable<DisciplineStudingPlanSupplement> 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;
}
}
}

View File

@ -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

View File

@ -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; }
}

View File

@ -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)
{

View File

@ -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";
}

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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));

View File

@ -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";
}
}
}

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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();
}
}

View File

@ -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<string[]> 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<string[]>() { 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();
}
}

View File

@ -9,7 +9,7 @@ namespace ProjectSchedule.Repositories;
public interface IStudingPlanSupplementRepository
{
IEnumerable<StudingPlanSupplement> ReadStudingPlanSupplements(DateTime? dateForm = null, DateTime? dateTo = null,
IEnumerable<StudingPlanSupplement> ReadStudingPlanSupplements(DateTime? dateForm = null,
int? disciplineId = null, int? groupStudentsId = null);
void CreateStudingPlanSupplement(StudingPlanSupplement studingPlanSupplement);
void DeleteStudingPlanSupplement(int id);

View File

@ -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}";
}
}

View File

@ -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<Schedule>(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<Schedule>(querySelect,
new { dateForm, dateTo, teacherId, disciplineId, groupStudentsId, audienceId });
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(schedules));
return schedules;
}

View File

@ -69,22 +69,62 @@ public class StudingPlanSupplementRepository : IStudingPlanSupplementRepository
}
}
public IEnumerable<StudingPlanSupplement> ReadStudingPlanSupplements(DateTime? dateForm = null, DateTime? dateTo = null,
int? disciplineId = null, int? groupStudentsId = null)
public IEnumerable<StudingPlanSupplement> 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<TempDisciplineStudingPlanSupplement>(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<int, List<DisciplineStudingPlanSupplement>>();
var studingPlanSupplements = connection.Query<StudingPlanSupplement, DisciplineStudingPlanSupplement, StudingPlanSupplement>(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)
{