Пол лабы

This commit is contained in:
funa4i 2024-12-02 20:25:45 +04:00
parent 05981fa4b4
commit 3f76f7590e
15 changed files with 104 additions and 19 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -8,19 +9,26 @@ namespace StudentProgressRecord.Entity
{
public class Marks
{
public long StatementId { get; set; }
[Browsable(false)]
public long StudentId { get; set; }
public int Mark { get; set; }
public static Marks CreateElement(long statementId, long studentId, int mark)
public string StudentName { get; set; } = string.Empty;
public static Marks CreateElement(long statementId, long studentId, int mark, string studentName="")
{
return new Marks
{
StatementId = statementId,
StudentId = studentId,
Mark = mark
Mark = mark,
StudentName = studentName
};
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
@ -11,14 +12,27 @@ namespace StudentProgressRecord.Entity
{
public long Id { get; set; }
[Browsable(false)]
public long SubjectId { get; set; }
[Browsable(false)]
public long TeacherId { get; set; }
[DisplayName("Дата")]
public DateTime Date { get; set; }
[DisplayName("Название предмета")]
public string SubjectName { get; set; } = string.Empty;
[DisplayName("Преподователь")]
public string TeacherName { get; set; } = string.Empty;
[Browsable(false)]
public IEnumerable<Marks> Marks { get; set; } = [];
[DisplayName("Оценки")]
public string Mark => Marks != null ? string.Join(", ", Marks.Select(x => $"{x.StudentName} {x.Mark}")) : string.Empty;
public static Statement CreateOperation(long id, long subjectId, long teacherId,
DateTime timeStamp, IEnumerable<Marks> marks)
{
@ -39,6 +53,8 @@ namespace StudentProgressRecord.Entity
Id = statement.Id,
SubjectId = statement.SubjectId,
TeacherId = statement.TeacherId,
SubjectName = statement.SubjectName,
TeacherName = statement.TeacherName,
Date = statement.Date,
Marks = marks
};

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -11,10 +12,14 @@ namespace StudentProgressRecord.Entity
public long Id { get; set; }
[DisplayName("Имя")]
public string Name { get; set; }
[DisplayName("Семейное положение")]
public bool FamilyPos { get; set; }
[DisplayName("Общажитие")]
public bool Domitory { get; set; }

View File

@ -1,6 +1,7 @@
using StudentProgressRecord.Entity.Enums;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -12,10 +13,18 @@ namespace StudentProgressRecord.Entity
public long Id { get; set; }
[Browsable(false)]
public long StudentId { get; set; }
[DisplayName("Студент")]
public string StudentName { get; set; } = string.Empty;
[DisplayName("Тип операции")]
public Operations Operation { get; set; }
[DisplayName("Дата")]
public DateTime Date { get; set; }
public static StudentTransition CreateOperation(long id, long studentId, Operations operation, DateTime time)

View File

@ -1,6 +1,7 @@
using StudentProgressRecord.Entity.Enums;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -11,8 +12,12 @@ namespace StudentProgressRecord.Entity
{
public long Id { get; set; }
[DisplayName("Название")]
public string Name { get; set; }
[DisplayName("Направление")]
public Direction direction { get; set; }
public static Subject CreateEntity(long id, string name, Direction direction)

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -10,6 +11,8 @@ namespace StudentProgressRecord.Entity
{
public long Id { get; set; }
[DisplayName("Имя")]
public string Name { get; set; }
public static Teacher CreateEntity(long id, string name)

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -12,12 +13,18 @@ namespace StudentProgressRecord.Entity
public long SubjectId { get; set; }
public string SubjectName { get; set; }
public long TeacherId { get; set; }
public string TeacherName { get; set; }
public DateTime Date { get; set; }
public long StudentId { get; set; }
public int Mark { get; set; }
public string StudentName { get; set; }
}
}

View File

@ -78,6 +78,7 @@ namespace StudentProgressRecord.Forms.FormViewEntities
private void LoadList()
{
dataGridView.DataSource = _statementRepository.ReadStatements();
dataGridView.Columns["Id"].Visible = false;
}
private bool TryGetIdFromSelectesRow(out int id)

View File

@ -57,18 +57,7 @@ namespace StudentProgressRecord.Forms.FormViewEntities
private void LoadList()
{
dataGridView.DataSource = _studentTransitionRepository.ReadStudentTransitions();
}
private bool TryGetIdFromSelectesRow(out int id)
{
id = 0;
if (dataGridView.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
return true;
dataGridView.Columns["Id"].Visible = false;
}
}
}

View File

@ -98,6 +98,7 @@ namespace StudentProgressRecord.Forms.FormViewEntities
private void LoadList()
{
dataGridView.DataSource = _studentRepository.ReadStudents();
dataGridView.Columns["Id"].Visible = false;
}
private bool TryGetIdFromSelectesRow(out int id)

View File

@ -96,6 +96,7 @@ namespace StudentProgressRecord.Forms.FormViewEntities
private void LoadList()
{
dataGridView.DataSource = _subjectRepository.ReadSubjects();
dataGridView.Columns["Id"].Visible = false;
}
private bool TryGetIdFromSelectesRow(out int id)

View File

@ -98,6 +98,7 @@ namespace StudentProgressRecord.Forms.FormViewEntities
private void LoadList()
{
dataGridView.DataSource = _teacherRepository.ReadTeachers();
dataGridView.Columns["Id"].Visible = false;
}
private bool TryGetIdFromSelectesRow(out int id)

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentProgressRecord.RepositoryImp
{
public 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

@ -88,18 +88,22 @@ namespace StudentProgressRecord.RepositoryImp
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new NpgsqlConnection(_connectionString.GetConnectionString());
var querySelect =
@"SELECT st.*, m.StudentId, m.Mark FROM Statement st
JOIN Marks m ON m.statementid = st.id";
@"SELECT
st.*, s.Name as SubjectName, t.Name as TeacherName, m.Mark, Student.Name as StudentName FROM Statement st
JOIN Subject s ON s.id = st.SubjectId
JOIN Teacher t ON t.id = st.TeacherId
JOIN Marks m ON m.statementId = st.id
LEFT JOIN Student on Student.id = m.studentId
";
var objs = connection.Query<TempStatement>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(objs));
return objs.GroupBy(x => x.Id, y => y,
(key, value) =>
Statement.CreateOperation(value.First(), value.Select(z => Marks.CreateElement(0, z.StudentId, z.Mark)))).ToList();
Statement.CreateOperation(value.First(), value.Select(z => Marks.CreateElement(0, z.StudentId, z.Mark, z.StudentName)))).ToList();
}
catch (Exception ex)
{

View File

@ -85,7 +85,8 @@ namespace StudentProgressRecord.RepositoryImp
try
{
using var connection = new NpgsqlConnection(_connectionString.GetConnectionString());
var querySelect = "SELECT * FROM StudentTransition";
var querySelect = @"SELECT st.*, s.Name as StudentName FROM StudentTransition st
JOIN Student s ON s.id = st.StudentId";
var objs = connection.Query<StudentTransition>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(objs));