Лабораторная работа 4
This commit is contained in:
parent
197a2ab8da
commit
df766afebd
@ -1,12 +1,19 @@
|
|||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
using SessionResults_Kudyaeva.Entities.Enums;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Entities;
|
namespace SessionResults_Kudyaeva.Entities;
|
||||||
|
|
||||||
public class Discipline
|
public class Discipline
|
||||||
{
|
{
|
||||||
public int ID { get; private set; }
|
public int ID { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Название")]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Описание")]
|
||||||
public string Description { get; private set; } = string.Empty;
|
public string Description { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("На каких курсах")]
|
||||||
public Course Courses { get; private set; }
|
public Course Courses { get; private set; }
|
||||||
|
|
||||||
public static Discipline Create(int id, string name, string description, Course courses)
|
public static Discipline Create(int id, string name, string description, Course courses)
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
using SessionResults_Kudyaeva.Entities.Enums;
|
||||||
using System;
|
using System.ComponentModel;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Entities;
|
namespace SessionResults_Kudyaeva.Entities;
|
||||||
|
|
||||||
public class Group
|
public class Group
|
||||||
{
|
{
|
||||||
public int ID { get; private set; }
|
public int ID { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Название")]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Тип")]
|
||||||
public GroupType Type { get; private set; }
|
public GroupType Type { get; private set; }
|
||||||
|
|
||||||
public static Group Create(int id, string name, GroupType type)
|
public static Group Create(int id, string name, GroupType type)
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
using SessionResults_Kudyaeva.Entities.Enums;
|
||||||
using System;
|
using System.ComponentModel;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Entities;
|
namespace SessionResults_Kudyaeva.Entities;
|
||||||
|
|
||||||
@ -11,14 +7,46 @@ public class Retake
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int StudentId { get; private set; }
|
public int StudentId { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int TeacherId { get; private set; }
|
public int TeacherId { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int DisciplineId { get; private set; }
|
public int DisciplineId { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public string TeacherSurname { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public string TeacherName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public string TeacherMiddleName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public string StudentSurname { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public string StudentName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public string StudentMiddleName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Студент")]
|
||||||
|
public string StudentDisplayName => $"{StudentSurname} {StudentName[0]}. {StudentMiddleName[0]}.";
|
||||||
|
|
||||||
|
[DisplayName("Преподаватель")]
|
||||||
|
public string TeacherDisplayName => $"{TeacherSurname} {TeacherName[0]}. {TeacherMiddleName[0]}.";
|
||||||
|
|
||||||
|
[DisplayName("Предмет")]
|
||||||
|
public string DisciplineName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Оценка")]
|
||||||
public Mark Mark { get; private set; }
|
public Mark Mark { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Дата перезачета")]
|
||||||
public DateTime Date { get; private set; }
|
public DateTime Date { get; private set; }
|
||||||
|
|
||||||
public static Retake CreateOperation(int id, int studentId, int teacherId, int disciplineId, Mark mark, DateTime date)
|
public static Retake CreateOperation(int id, int studentId, int teacherId, int disciplineId, Mark mark, DateTime date)
|
||||||
|
@ -1,11 +1,41 @@
|
|||||||
namespace SessionResults_Kudyaeva.Entities;
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace SessionResults_Kudyaeva.Entities;
|
||||||
|
|
||||||
public class Statement
|
public class Statement
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int TeacherId { get; private set; }
|
public int TeacherId { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public int DisciplineId { get; private set; }
|
public int DisciplineId { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public string TeacherSurname { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public string TeacherName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public string TeacherMiddleName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Преподаватель")]
|
||||||
|
public string TeacherDisplayName => $"{TeacherSurname} {TeacherName[0]}. {TeacherMiddleName[0]}.";
|
||||||
|
|
||||||
|
[DisplayName("Предмет")]
|
||||||
|
public string DisciplineName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Дата")]
|
||||||
public DateTime Date { get; private set; }
|
public DateTime Date { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Оценки")]
|
||||||
|
public string Fuel => StatementStudents != null ?
|
||||||
|
string.Join(", ", StatementStudents.Select(x => $"{x.StudentDisplayName} {(int)x.Mark}")) :
|
||||||
|
string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public IEnumerable<StatementStudent> StatementStudents { get; private set; } = [];
|
public IEnumerable<StatementStudent> StatementStudents { get; private set; } = [];
|
||||||
|
|
||||||
public static Statement CreateOperation(int id, int teacherId, int disciplineId, DateTime date, IEnumerable<StatementStudent> statementStudents)
|
public static Statement CreateOperation(int id, int teacherId, int disciplineId, DateTime date, IEnumerable<StatementStudent> statementStudents)
|
||||||
@ -20,15 +50,11 @@ public class Statement
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Statement CreateOperation(TempStatementStudent tempStatementStudent, IEnumerable<StatementStudent> statementStudents)
|
public void SetStatementStudents(IEnumerable<StatementStudent> statementStudents)
|
||||||
{
|
{
|
||||||
return new Statement
|
if (statementStudents != null && statementStudents.Any())
|
||||||
{
|
{
|
||||||
Id = tempStatementStudent.Id,
|
StatementStudents = statementStudents;
|
||||||
TeacherId = tempStatementStudent.TeacherId,
|
}
|
||||||
DisciplineId = tempStatementStudent.DisciplineId,
|
|
||||||
Date = tempStatementStudent.Date,
|
|
||||||
StatementStudents = statementStudents
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
using SessionResults_Kudyaeva.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -11,6 +12,10 @@ public class StatementStudent
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public int StudentId { get; private set; }
|
public int StudentId { get; private set; }
|
||||||
|
public string StudentSurname { get; private set; } = string.Empty;
|
||||||
|
public string StudentName { get; private set; } = string.Empty;
|
||||||
|
public string StudentMiddleName { get; private set; } = string.Empty;
|
||||||
|
public string StudentDisplayName => $"{StudentSurname} {StudentName[0]}. {StudentMiddleName[0]}.";
|
||||||
public Mark Mark { get; private set; }
|
public Mark Mark { get; private set; }
|
||||||
|
|
||||||
public static StatementStudent CreateOperation(int id, int studentId, Mark mark)
|
public static StatementStudent CreateOperation(int id, int studentId, Mark mark)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
using SessionResults_Kudyaeva.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -11,10 +12,21 @@ namespace SessionResults_Kudyaeva.Entities;
|
|||||||
public class Student
|
public class Student
|
||||||
{
|
{
|
||||||
public int ID { get; private set; }
|
public int ID { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Фамилия")]
|
||||||
public string Surname { get; private set; } = string.Empty;
|
public string Surname { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Имя")]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Отчество")]
|
||||||
public string MiddleName { get; private set; } = string.Empty;
|
public string MiddleName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public int GroupID { get; private set; }
|
public int GroupID { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Группа")]
|
||||||
|
public string GroupName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public string DisplayName => $"{Surname} {Name[0]}. {MiddleName[0]}.";
|
public string DisplayName => $"{Surname} {Name[0]}. {MiddleName[0]}.";
|
||||||
|
|
||||||
public static Student Create(int id, string surname, string name, string middleName, int groupID)
|
public static Student Create(int id, string surname, string name, string middleName, int groupID)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,9 +10,16 @@ namespace SessionResults_Kudyaeva.Entities;
|
|||||||
public class Teacher
|
public class Teacher
|
||||||
{
|
{
|
||||||
public int ID { get; private set; }
|
public int ID { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Фамилия")]
|
||||||
public string Surname { get; private set; } = string.Empty;
|
public string Surname { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Имя")]
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Отчество")]
|
||||||
public string MiddleName { get; private set; } = string.Empty;
|
public string MiddleName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public string DisplayName => $"{Surname} {Name[0]}. {MiddleName[0]}.";
|
public string DisplayName => $"{Surname} {Name[0]}. {MiddleName[0]}.";
|
||||||
|
|
||||||
public static Teacher Create(int id, string surname, string name, string middleName)
|
public static Teacher Create(int id, string surname, string name, string middleName)
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
using SessionResults_Kudyaeva.Entities.Enums;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Entities;
|
|
||||||
|
|
||||||
public class TempStatementStudent
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
public int TeacherId { get; private set; }
|
|
||||||
public int DisciplineId { get; private set; }
|
|
||||||
public DateTime Date { get; private set; }
|
|
||||||
public int StudentId { get; private set; }
|
|
||||||
public Mark Mark { get; private set; }
|
|
||||||
}
|
|
@ -91,7 +91,11 @@ public partial class DisciplineListForm : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewDisciplines.DataSource = _disciplineRepository.GetAllDisciplines();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewDisciplines.DataSource = _disciplineRepository.GetAllDisciplines();
|
||||||
|
dataGridViewDisciplines.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -93,7 +93,11 @@ public partial class GroupsListForm : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewGroups.DataSource = _groupRepository.GetAllGroups();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewGroups.DataSource = _groupRepository.GetAllGroups();
|
||||||
|
dataGridViewGroups.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,11 @@ public partial class RetakeListForm : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _retakeRepository.GetAllRetakes();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _retakeRepository.GetAllRetakes();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private void RetakeListForm_Load(object sender, EventArgs e)
|
private void RetakeListForm_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -40,6 +40,9 @@ public partial class StatementListForm : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _statementRepository.GetAllStatements();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _statementRepository.GetAllStatements();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,13 @@ public partial class StudentsList : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewStudents.DataSource = _studentRepository.GetAllStudents();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewStudents.DataSource = _studentRepository.GetAllStudents();
|
||||||
|
dataGridViewStudents.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewStudents.Columns["DisplayName"].Visible = false;
|
||||||
|
//dataGridViewStudents.Columns["GroupId"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -90,7 +90,12 @@ public partial class TeachersList : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewTeachers.DataSource = _teacherRepository.GetAllTeachers();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewTeachers.DataSource = _teacherRepository.GetAllTeachers();
|
||||||
|
dataGridViewTeachers.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewTeachers.Columns["DisplayName"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@ internal class ChartReport
|
|||||||
{
|
{
|
||||||
new PdfBuilder(filePath)
|
new PdfBuilder(filePath)
|
||||||
.AddHeader("Выставленные оценки по предметам")
|
.AddHeader("Выставленные оценки по предметам")
|
||||||
.AddPieChart("Предметы", GetData(dateTime))
|
.AddPieChart($"Выставлено оценок за предметы на {dateTime:dd.MM.yyyy}", GetData(dateTime))
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -33,13 +33,12 @@ internal class ChartReport
|
|||||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||||
{
|
{
|
||||||
return _statementRepository
|
return _statementRepository
|
||||||
.GetAllStatements()
|
.GetAllStatements(dateFrom: dateTime.Date, dateTo:dateTime.Date.AddDays(1))
|
||||||
.Where(x => x.Date.Date == dateTime.Date)
|
.GroupBy(x => x.DisciplineName, (key, group) => new {
|
||||||
.GroupBy(x => x.DisciplineId, (key, group) => new {
|
DisciplineName = key,
|
||||||
Id = key,
|
|
||||||
Count = group.Sum(statement => statement.StatementStudents.Count())
|
Count = group.Sum(statement => statement.StatementStudents.Count())
|
||||||
})
|
})
|
||||||
.Select(x => (x.Id.ToString(), (double)x.Count))
|
.Select(x => (x.DisciplineName, (double)x.Count))
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ internal class TableReport
|
|||||||
{
|
{
|
||||||
new ExcelBuilder(filePath)
|
new ExcelBuilder(filePath)
|
||||||
.AddHeader("Сводка по оценкам студента", 0, 3)
|
.AddHeader("Сводка по оценкам студента", 0, 3)
|
||||||
.AddParagraph("за период", 0)
|
.AddParagraph($"за период {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0)
|
||||||
.AddTable([10, 15, 15, 15], GetData(studentId, startDate, endDate))
|
.AddTable([10, 15, 15, 15], GetData(studentId, startDate, endDate))
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
@ -39,8 +39,7 @@ internal class TableReport
|
|||||||
private List<string[]> GetData(int studentId, DateTime startDate, DateTime endDate)
|
private List<string[]> GetData(int studentId, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
var statements = _statementRepository
|
var statements = _statementRepository
|
||||||
.GetAllStatements()
|
.GetAllStatements(startDate, endDate, studentId)
|
||||||
.Where(x => x.Date >= startDate && x.Date <= endDate && x.StatementStudents.Any(y => y.StudentId == studentId))
|
|
||||||
.Select(x => new {
|
.Select(x => new {
|
||||||
Discipline = x.DisciplineId.ToString(),
|
Discipline = x.DisciplineId.ToString(),
|
||||||
x.Date,
|
x.Date,
|
||||||
@ -49,8 +48,7 @@ internal class TableReport
|
|||||||
});
|
});
|
||||||
|
|
||||||
var retakes = _retakeRepository
|
var retakes = _retakeRepository
|
||||||
.GetAllRetakes()
|
.GetAllRetakes(startDate, endDate, studentId)
|
||||||
.Where(x => x.Date >= startDate && x.Date <= endDate && x.StudentId == studentId)
|
|
||||||
.Select(x => new {
|
.Select(x => new {
|
||||||
Discipline = x.DisciplineId.ToString(),
|
Discipline = x.DisciplineId.ToString(),
|
||||||
x.Date,
|
x.Date,
|
||||||
|
@ -10,5 +10,6 @@ namespace SessionResults_Kudyaeva.Repositories;
|
|||||||
public interface IRetakeRepository
|
public interface IRetakeRepository
|
||||||
{
|
{
|
||||||
void CreateRetake(Retake retake);
|
void CreateRetake(Retake retake);
|
||||||
IEnumerable<Retake> GetAllRetakes();
|
IEnumerable<Retake> GetAllRetakes(DateTime? dateFrom = null, DateTime? dateTo = null,
|
||||||
|
int? studentId = null);
|
||||||
}
|
}
|
||||||
|
@ -10,5 +10,5 @@ namespace SessionResults_Kudyaeva.Repositories;
|
|||||||
public interface IStatementRepository
|
public interface IStatementRepository
|
||||||
{
|
{
|
||||||
void CreateStatement(Statement statement);
|
void CreateStatement(Statement statement);
|
||||||
IEnumerable<Statement> GetAllStatements();
|
IEnumerable<Statement> GetAllStatements(DateTime? dateFrom = null, DateTime? dateTo = null, int? studentId = null);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SessionResults_Kudyaeva.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}";
|
||||||
|
}
|
||||||
|
}
|
@ -37,14 +37,41 @@ public class RetakeRepository : IRetakeRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Retake> GetAllRetakes()
|
public IEnumerable<Retake> GetAllRetakes(DateTime? dateFrom = null, DateTime? dateTo = null,
|
||||||
|
int? studentId = null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("re.Date >= @dateFrom");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("re.Date <= @dateTo");
|
||||||
|
}
|
||||||
|
if (studentId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("re.StudentId = @studentId");
|
||||||
|
}
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = "SELECT * FROM Retake";
|
var querySelect = $@"SELECT
|
||||||
var retakes = connection.Query<Retake>(querySelect);
|
re.*,
|
||||||
|
tc.Surname as TeacherSurname,
|
||||||
|
tc.Name as TeacherName,
|
||||||
|
tc.MiddleName as TeacherMiddleName,
|
||||||
|
ds.Name as DisciplineName,
|
||||||
|
stud.Surname as StudentSurname,
|
||||||
|
stud.Name as StudentName,
|
||||||
|
stud.MiddleName as StudentMiddleName
|
||||||
|
FROM Retake re
|
||||||
|
LEFT JOIN Teacher tc on tc.Id = re.TeacherId
|
||||||
|
LEFT JOIN Discipline ds on ds.Id = re.DisciplineId
|
||||||
|
LEFT JOIN Student stud on stud.Id = re.StudentId
|
||||||
|
{builder.Build()}";
|
||||||
|
var retakes = connection.Query<Retake>(querySelect, new { dateFrom, dateTo, studentId });
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
JsonConvert.SerializeObject(retakes));
|
JsonConvert.SerializeObject(retakes));
|
||||||
return retakes;
|
return retakes;
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
|
using DocumentFormat.OpenXml.Spreadsheet;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
using SessionResults_Kudyaeva.Entities;
|
using SessionResults_Kudyaeva.Entities;
|
||||||
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
||||||
namespace SessionResults_Kudyaeva.Repositories.Implementations;
|
namespace SessionResults_Kudyaeva.Repositories.Implementations;
|
||||||
|
|
||||||
@ -54,18 +56,65 @@ public class StatementRepository : IStatementRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Statement> GetAllStatements()
|
public IEnumerable<Statement> GetAllStatements(DateTime? dateFrom = null, DateTime? dateTo = null,
|
||||||
|
int? studentId = null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("s.Date >= @dateFrom");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("s.Date <= @dateTo");
|
||||||
|
}
|
||||||
|
if (studentId.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("ss.StudentId = @studentId");
|
||||||
|
}
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"SELECT s.*, ss.StudentId, ss.Mark FROM Statement s
|
var querySelect = $@"SELECT
|
||||||
INNER JOIN StatementStudent ss on ss.StatementId = s.Id";
|
s.*,
|
||||||
var statements = connection.Query<TempStatementStudent>(querySelect);
|
tc.Surname as TeacherSurname,
|
||||||
|
tc.Name as TeacherName,
|
||||||
|
tc.MiddleName as TeacherMiddleName,
|
||||||
|
ds.Name as DisciplineName,
|
||||||
|
ss.StudentId,
|
||||||
|
ss.Mark,
|
||||||
|
stud.Surname as StudentSurname,
|
||||||
|
stud.Name as StudentName,
|
||||||
|
stud.MiddleName as StudentMiddleName
|
||||||
|
FROM Statement s
|
||||||
|
LEFT JOIN Teacher tc on tc.Id = s.TeacherId
|
||||||
|
LEFT JOIN Discipline ds on ds.Id = s.DisciplineId
|
||||||
|
INNER JOIN StatementStudent ss on ss.StatementId = s.Id
|
||||||
|
LEFT JOIN Student stud on stud.Id = ss.StudentId
|
||||||
|
{builder.Build()}";
|
||||||
|
var statementsDict = new Dictionary<int, List<StatementStudent>>();
|
||||||
|
|
||||||
|
var statements = connection.Query<Statement, StatementStudent, Statement>(querySelect,
|
||||||
|
(statement, statementStudent) =>
|
||||||
|
{
|
||||||
|
if (!statementsDict.TryGetValue(statement.Id, out var sts))
|
||||||
|
{
|
||||||
|
sts = [];
|
||||||
|
statementsDict.Add(statement.Id, sts);
|
||||||
|
}
|
||||||
|
|
||||||
|
sts.Add(statementStudent);
|
||||||
|
return statement;
|
||||||
|
}, splitOn: "StudentId", param: new { dateFrom, dateTo, studentId });
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
JsonConvert.SerializeObject(statements));
|
JsonConvert.SerializeObject(statements));
|
||||||
return statements.GroupBy(x => x.Id, y => y, (key, value) => Statement.CreateOperation(value.First(), value.Select(z => StatementStudent.CreateOperation(0, z.StudentId, z.Mark)))).ToList();
|
return statementsDict.Select(x =>
|
||||||
|
{
|
||||||
|
var s = statements.First(y => y.Id == x.Key);
|
||||||
|
s.SetStatementStudents(x.Value);
|
||||||
|
return s;
|
||||||
|
}).ToArray();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -62,7 +62,9 @@ public class StudentRepository : IStudentRepository
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = "SELECT * FROM Student";
|
var querySelect = @"SELECT st.*, gr.Name as GroupName
|
||||||
|
FROM Student st
|
||||||
|
LEFT JOIN ""Group"" gr on gr.id = st.GroupID";
|
||||||
var students = connection.Query<Student>(querySelect);
|
var students = connection.Query<Student>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
JsonConvert.SerializeObject(students));
|
JsonConvert.SerializeObject(students));
|
||||||
|
Loading…
Reference in New Issue
Block a user