Пол лабы
This commit is contained in:
parent
05981fa4b4
commit
3f76f7590e
@ -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;
|
||||||
@ -8,19 +9,26 @@ namespace StudentProgressRecord.Entity
|
|||||||
{
|
{
|
||||||
public class Marks
|
public class Marks
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public long StatementId { get; set; }
|
public long StatementId { get; set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public long StudentId { get; set; }
|
public long StudentId { get; set; }
|
||||||
|
|
||||||
public int Mark { 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
|
return new Marks
|
||||||
{
|
{
|
||||||
StatementId = statementId,
|
StatementId = statementId,
|
||||||
StudentId = studentId,
|
StudentId = studentId,
|
||||||
Mark = mark
|
Mark = mark,
|
||||||
|
StudentName = studentName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -11,14 +12,27 @@ namespace StudentProgressRecord.Entity
|
|||||||
{
|
{
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public long SubjectId { get; set; }
|
public long SubjectId { get; set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public long TeacherId { get; set; }
|
public long TeacherId { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Дата")]
|
||||||
public DateTime Date { get; set; }
|
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; } = [];
|
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,
|
public static Statement CreateOperation(long id, long subjectId, long teacherId,
|
||||||
DateTime timeStamp, IEnumerable<Marks> marks)
|
DateTime timeStamp, IEnumerable<Marks> marks)
|
||||||
{
|
{
|
||||||
@ -39,6 +53,8 @@ namespace StudentProgressRecord.Entity
|
|||||||
Id = statement.Id,
|
Id = statement.Id,
|
||||||
SubjectId = statement.SubjectId,
|
SubjectId = statement.SubjectId,
|
||||||
TeacherId = statement.TeacherId,
|
TeacherId = statement.TeacherId,
|
||||||
|
SubjectName = statement.SubjectName,
|
||||||
|
TeacherName = statement.TeacherName,
|
||||||
Date = statement.Date,
|
Date = statement.Date,
|
||||||
Marks = marks
|
Marks = marks
|
||||||
};
|
};
|
||||||
|
@ -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;
|
||||||
@ -11,10 +12,14 @@ namespace StudentProgressRecord.Entity
|
|||||||
|
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Имя")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Семейное положение")]
|
||||||
public bool FamilyPos { get; set; }
|
public bool FamilyPos { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[DisplayName("Общажитие")]
|
||||||
public bool Domitory { get; set; }
|
public bool Domitory { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using StudentProgressRecord.Entity.Enums;
|
using StudentProgressRecord.Entity.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;
|
||||||
@ -12,10 +13,18 @@ namespace StudentProgressRecord.Entity
|
|||||||
|
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
public long StudentId { get; set; }
|
public long StudentId { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Студент")]
|
||||||
|
public string StudentName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Тип операции")]
|
||||||
public Operations Operation { get; set; }
|
public Operations Operation { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[DisplayName("Дата")]
|
||||||
public DateTime Date { get; set; }
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
public static StudentTransition CreateOperation(long id, long studentId, Operations operation, DateTime time)
|
public static StudentTransition CreateOperation(long id, long studentId, Operations operation, DateTime time)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using StudentProgressRecord.Entity.Enums;
|
using StudentProgressRecord.Entity.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,8 +12,12 @@ namespace StudentProgressRecord.Entity
|
|||||||
{
|
{
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[DisplayName("Название")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[DisplayName("Направление")]
|
||||||
public Direction direction { get; set; }
|
public Direction direction { get; set; }
|
||||||
|
|
||||||
public static Subject CreateEntity(long id, string name, Direction direction)
|
public static Subject CreateEntity(long id, string name, Direction direction)
|
||||||
|
@ -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;
|
||||||
@ -10,6 +11,8 @@ namespace StudentProgressRecord.Entity
|
|||||||
{
|
{
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[DisplayName("Имя")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public static Teacher CreateEntity(long id, string name)
|
public static Teacher CreateEntity(long id, string name)
|
||||||
|
@ -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;
|
||||||
@ -12,12 +13,18 @@ namespace StudentProgressRecord.Entity
|
|||||||
|
|
||||||
public long SubjectId { get; set; }
|
public long SubjectId { get; set; }
|
||||||
|
|
||||||
|
public string SubjectName { get; set; }
|
||||||
|
|
||||||
public long TeacherId { get; set; }
|
public long TeacherId { get; set; }
|
||||||
|
|
||||||
|
public string TeacherName { get; set; }
|
||||||
|
|
||||||
public DateTime Date { get; set; }
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
public long StudentId { get; set; }
|
public long StudentId { get; set; }
|
||||||
|
|
||||||
public int Mark { get; set; }
|
public int Mark { get; set; }
|
||||||
|
|
||||||
|
public string StudentName { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,7 @@ namespace StudentProgressRecord.Forms.FormViewEntities
|
|||||||
private void LoadList()
|
private void LoadList()
|
||||||
{
|
{
|
||||||
dataGridView.DataSource = _statementRepository.ReadStatements();
|
dataGridView.DataSource = _statementRepository.ReadStatements();
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryGetIdFromSelectesRow(out int id)
|
private bool TryGetIdFromSelectesRow(out int id)
|
||||||
|
@ -57,18 +57,7 @@ namespace StudentProgressRecord.Forms.FormViewEntities
|
|||||||
private void LoadList()
|
private void LoadList()
|
||||||
{
|
{
|
||||||
dataGridView.DataSource = _studentTransitionRepository.ReadStudentTransitions();
|
dataGridView.DataSource = _studentTransitionRepository.ReadStudentTransitions();
|
||||||
}
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,7 @@ namespace StudentProgressRecord.Forms.FormViewEntities
|
|||||||
private void LoadList()
|
private void LoadList()
|
||||||
{
|
{
|
||||||
dataGridView.DataSource = _studentRepository.ReadStudents();
|
dataGridView.DataSource = _studentRepository.ReadStudents();
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryGetIdFromSelectesRow(out int id)
|
private bool TryGetIdFromSelectesRow(out int id)
|
||||||
|
@ -96,6 +96,7 @@ namespace StudentProgressRecord.Forms.FormViewEntities
|
|||||||
private void LoadList()
|
private void LoadList()
|
||||||
{
|
{
|
||||||
dataGridView.DataSource = _subjectRepository.ReadSubjects();
|
dataGridView.DataSource = _subjectRepository.ReadSubjects();
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryGetIdFromSelectesRow(out int id)
|
private bool TryGetIdFromSelectesRow(out int id)
|
||||||
|
@ -98,6 +98,7 @@ namespace StudentProgressRecord.Forms.FormViewEntities
|
|||||||
private void LoadList()
|
private void LoadList()
|
||||||
{
|
{
|
||||||
dataGridView.DataSource = _teacherRepository.ReadTeachers();
|
dataGridView.DataSource = _teacherRepository.ReadTeachers();
|
||||||
|
dataGridView.Columns["Id"].Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryGetIdFromSelectesRow(out int id)
|
private bool TryGetIdFromSelectesRow(out int id)
|
||||||
|
34
StudentProgressRecord/RepositoryImp/QueryBuilder.cs
Normal file
34
StudentProgressRecord/RepositoryImp/QueryBuilder.cs
Normal 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}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -88,18 +88,22 @@ namespace StudentProgressRecord.RepositoryImp
|
|||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.GetConnectionString());
|
using var connection = new NpgsqlConnection(_connectionString.GetConnectionString());
|
||||||
var querySelect =
|
var querySelect =
|
||||||
@"SELECT st.*, m.StudentId, m.Mark FROM Statement st
|
@"SELECT
|
||||||
JOIN Marks m ON m.statementid = st.id";
|
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);
|
var objs = connection.Query<TempStatement>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
JsonConvert.SerializeObject(objs));
|
JsonConvert.SerializeObject(objs));
|
||||||
|
|
||||||
return objs.GroupBy(x => x.Id, y => y,
|
return objs.GroupBy(x => x.Id, y => y,
|
||||||
(key, value) =>
|
(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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -85,7 +85,8 @@ namespace StudentProgressRecord.RepositoryImp
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.GetConnectionString());
|
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);
|
var objs = connection.Query<StudentTransition>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
JsonConvert.SerializeObject(objs));
|
JsonConvert.SerializeObject(objs));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user