вкаепнр
This commit is contained in:
parent
2e1ae14c4e
commit
9a6c7c6f9d
@ -11,21 +11,16 @@ namespace Academic_Performance.Entities
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int StudentId { get; private set; }
|
||||
/// public int TeachersId { get; private set; }
|
||||
/// <summary>
|
||||
///public int SubjectId { get; private set; }
|
||||
/// </summary>
|
||||
|
||||
public string Value { get; private set; } = string.Empty;
|
||||
public static Mark CreateElement(int id,
|
||||
int studentId,///int teacherId, int subjectId,
|
||||
int studentId,
|
||||
string value)
|
||||
{
|
||||
return new Mark
|
||||
{
|
||||
Id = id,
|
||||
StudentId = studentId,
|
||||
/// TeachersId = teacherId,
|
||||
/// SubjectId = subjectId,
|
||||
Value = value
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Academic_Performance.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -10,9 +11,21 @@ namespace Academic_Performance.Entities
|
||||
public class Order
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
|
||||
|
||||
[Browsable(false)]
|
||||
public int StudentId { get; private set; }
|
||||
[DisplayName("Фио Студента")]
|
||||
public string StudentName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Информация")]
|
||||
public string Information { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Баллы")]
|
||||
public TypeS? TypeS { get; private set; }
|
||||
|
||||
[DisplayName("Дата")]
|
||||
public DateTime Date { get; private set; }
|
||||
public static Order CreateEntity(int id, int studentId, string information,TypeS types)
|
||||
{
|
||||
|
@ -1,6 +1,8 @@
|
||||
using Academic_Performance.Entities.Enums;
|
||||
using DocumentFormat.OpenXml.Bibliography;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -9,13 +11,29 @@ using System.Threading.Tasks;
|
||||
namespace Academic_Performance.Entities
|
||||
{
|
||||
public class Statement
|
||||
{ public int Id { get; private set; }
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int SubjectId { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int TeacherId{ get; private set; }
|
||||
|
||||
[DisplayName("Фио Преподавателя")]
|
||||
public string TeacherName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Предмет")]
|
||||
public string SubjectName{ get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата")]
|
||||
public DateTime Date { get; private set; }
|
||||
public IEnumerable<Mark> Mark{ get; private set; } = [];
|
||||
public static Statement CreateOperation(int id, int subjectId, int teacherId, IEnumerable<Mark> mark)
|
||||
[DisplayName("Оценка")]
|
||||
public string Mark => Marks != null ? string.Join(", ", Marks.Select(x => $"{x.Value}")) : string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public IEnumerable<Mark> Marks{ get; private set; } = [];
|
||||
public static Statement CreateOperation(int id, int subjectId, int teacherId, IEnumerable<Mark> marks)
|
||||
{
|
||||
return new Statement
|
||||
{
|
||||
@ -23,23 +41,25 @@ namespace Academic_Performance.Entities
|
||||
SubjectId = subjectId,
|
||||
TeacherId = teacherId,
|
||||
Date = DateTime.Now,
|
||||
Mark = mark
|
||||
Marks = marks
|
||||
};
|
||||
}
|
||||
|
||||
public static Statement CreateOperation(TempMarks tempmarks, IEnumerable<Mark> mark)
|
||||
|
||||
}
|
||||
public void SetMarks(IEnumerable<Mark> marks)
|
||||
{
|
||||
return new Statement
|
||||
if (marks != null && marks.Any())
|
||||
{
|
||||
Id = tempmarks.Id,
|
||||
SubjectId = tempmarks.SubjectId,
|
||||
TeacherId = tempmarks.TeacherId,
|
||||
Date = tempmarks.Date,
|
||||
Mark = mark
|
||||
};
|
||||
Marks = marks;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Academic_Performance.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -10,9 +11,14 @@ namespace Academic_Performance.Entities
|
||||
public class Student
|
||||
{
|
||||
public int Id{ get; private set; }
|
||||
[DisplayName("Группа")]
|
||||
public Groupp Groupp { get; private set; }
|
||||
[DisplayName("Фио")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
[DisplayName("Поток")]
|
||||
public string Flow { get; private set; } = string.Empty;
|
||||
[DisplayName("Общая Справка")]
|
||||
public string Name_Student => $"{Name} {Groupp}";
|
||||
public static Student CreateEntity(int id, string name,string flow, Groupp groupp)
|
||||
{
|
||||
return new Student
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Microsoft.VisualBasic.Devices;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,6 +10,7 @@ namespace Academic_Performance.Entities;
|
||||
public class Subject
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Предмет")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public static Subject CreateEntity(int id, string name)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -8,6 +9,7 @@ namespace Academic_Performance.Entities;
|
||||
|
||||
public class Teacher
|
||||
{ public int Id { get; private set; }
|
||||
[DisplayName("ФИО Преподаватель")]
|
||||
public string Name{ get; private set; } = string.Empty;
|
||||
public static Teacher CreateEntity(int id, string name)
|
||||
{
|
||||
|
@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Academic_Performance.Entities;
|
||||
|
||||
public class TempMarks
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int StudentId { get; private set; }
|
||||
public int TeacherId { get; private set; }
|
||||
public int SubjectId { get; private set; }
|
||||
public DateTime Date { get; private set; }
|
||||
public string Value { get; private set; } = string.Empty;
|
||||
}
|
@ -72,8 +72,12 @@ namespace Academic_Performance.Forms
|
||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() =>
|
||||
dataGridView.DataSource = _statementRepository.ReadStatement();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _statementRepository.ReadStatement();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["Date"].DefaultCellStyle.Format = "dd.MM.yyyy";
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -92,7 +92,11 @@ namespace Academic_Performance.Forms
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridView.DataSource = _orderRepository.ReadOrder();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _orderRepository.ReadOrder();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -36,7 +36,11 @@ namespace Academic_Performance.Forms
|
||||
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridView1.DataSource = _studentRepository.ReadStudent();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView1.DataSource = _studentRepository.ReadStudent();
|
||||
dataGridView1.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
@ -106,7 +106,11 @@ namespace Academic_Performance.Forms
|
||||
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView1.DataSource = _subjectRepository.ReadSubject();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView1.DataSource = _subjectRepository.ReadSubject();
|
||||
dataGridView1.Columns["Id"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -51,7 +51,11 @@ namespace Academic_Performance.Forms
|
||||
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void LoadList() => dataGridView1.DataSource = _teacherRepository.ReadTeachers();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView1.DataSource = _teacherRepository.ReadTeachers();
|
||||
dataGridView1.Columns["Id"].Visible = false;
|
||||
}
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
||||
|
@ -54,7 +54,7 @@ public class TableReport
|
||||
|
||||
var marks = _statementRepository.ReadStatement()
|
||||
.Where(g => g.Date >= startDate && g.Date <= endDate)
|
||||
.SelectMany(g => g.Mark.Where(m => m.StudentId == studentId).Select(m => new
|
||||
.SelectMany(g => g.Marks.Where(m => m.StudentId == studentId).Select(m => new
|
||||
{
|
||||
Date = g.Date,
|
||||
Subject = subjects.TryGetValue(g.SubjectId, out var subject) ? subject : "Неизвестный предмет",
|
||||
|
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
namespace Academic_Performance.Repositories
|
||||
{
|
||||
public interface IOrderRepository
|
||||
{ IEnumerable<Order> ReadOrder(DateTime? dateForm = null, DateTime? dateTo = null);
|
||||
{ IEnumerable<Order> ReadOrder(DateTime? dateForm = null, DateTime? dateTo = null, int? studentId = null);
|
||||
Order GetOrderById(int id);
|
||||
void AddOrder(Order order);
|
||||
void UpdateOrder(Order order);
|
||||
|
@ -9,7 +9,7 @@ namespace Academic_Performance.Repositories
|
||||
{
|
||||
public interface IStatementRepository
|
||||
{
|
||||
IEnumerable<Statement> ReadStatement(DateTime? dateFrom = null, DateTime? dateTo = null);
|
||||
IEnumerable<Statement> ReadStatement(DateTime? dateFrom = null, DateTime? dateTo = null, int? teacherId = null, int? subjectId = null);
|
||||
void CreateStatement(Statement statement);
|
||||
void DeleteStatement(int id);
|
||||
}
|
||||
|
@ -104,23 +104,42 @@ namespace Academic_Performance.Repositories.Implementations
|
||||
throw;
|
||||
}
|
||||
}
|
||||
IEnumerable<Order> IOrderRepository.ReadOrder(DateTime? dateForm = null, DateTime? dateTo = null)
|
||||
IEnumerable<Order> IOrderRepository.ReadOrder(DateTime? dateForm = null, DateTime? dateTo = null, int? studentId = null)
|
||||
{
|
||||
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (dateForm.HasValue)
|
||||
{
|
||||
builder.AddCondition("rt.Date >= @dateFrom");
|
||||
}
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("rt.Date <= @dateTo");
|
||||
}
|
||||
if (studentId.HasValue)
|
||||
{
|
||||
builder.AddCondition("rt.StudentId = @studentId");
|
||||
}
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Orderrr";
|
||||
var order = connection.Query<Order>(querySelect);
|
||||
var querySelect = @"SELECT rt.*, tr.Name as StudentName
|
||||
FROM Orderrr rt
|
||||
INNER JOIN Studentt tr ON rt.studentId = tr.id";
|
||||
var routes = connection.Query<Order>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(order));
|
||||
return order;
|
||||
JsonConvert.SerializeObject(routes));
|
||||
return routes;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Academic_Performance.Repositories.Implementations;
|
||||
|
||||
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}";
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ namespace Academic_Performance.Repositories.Implementations
|
||||
var statementId = connection.QueryFirst<int>(queryInsert, statement, transaction);
|
||||
var querySubInsert = @"INSERT INTO Markkk(Value,StudentId)
|
||||
VALUES (@Value,@StudentId)";
|
||||
foreach (var elem in statement.Mark)
|
||||
foreach (var elem in statement.Marks)
|
||||
{
|
||||
connection.Execute(querySubInsert, new
|
||||
{
|
||||
@ -92,20 +92,62 @@ namespace Academic_Performance.Repositories.Implementations
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Statement> ReadStatement(DateTime? dateFrom = null, DateTime? dateTo = null)
|
||||
public IEnumerable<Statement> ReadStatement(DateTime? dateFrom = null, DateTime? dateTo = null, int? teacherId = null, int? subjectId = null)
|
||||
{
|
||||
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (dateFrom.HasValue)
|
||||
{
|
||||
builder.AddCondition("con.Date >= @dateForm");
|
||||
}
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("con.Date <= @dateTo");
|
||||
}
|
||||
if (teacherId.HasValue)
|
||||
{
|
||||
builder.AddCondition("con.TeacherId = @teacherId");
|
||||
}
|
||||
if (subjectId.HasValue)
|
||||
{
|
||||
builder.AddCondition("con.SubjectId = @subjectId");
|
||||
}
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT inv.*, ipr.StudentId, ipr.Value FROM Statement11 inv
|
||||
INNER JOIN Markkk ipr ON ipr.Id = inv.Id";
|
||||
var statement = connection.Query<TempMarks>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(statement));
|
||||
return statement.GroupBy(x => x.Id, y => y,
|
||||
(key, value) => Statement.CreateOperation(value.First(),
|
||||
value.Select(z => Mark.CreateElement(0, z.StudentId, z.Value)))).ToList();
|
||||
|
||||
var querySelect = @$"SELECT con.*, cl.Name as TeacherName, s.Name as SubjectName,
|
||||
ct.StudentId, ct.Value
|
||||
FROM Statement11 con
|
||||
INNER JOIN Markkk ct ON ct.Id = con.Id
|
||||
INNER JOIN Teacher cl ON con.teacherId = cl.Id
|
||||
INNER JOIN Subject s ON con.SubjectId = s.Id
|
||||
|
||||
{builder.Build()}";
|
||||
|
||||
var contractDict = new Dictionary<int, List<Mark>>();
|
||||
|
||||
var contracts = connection.Query<Statement, Mark, Statement>(querySelect,
|
||||
(statement, mark) =>
|
||||
{
|
||||
if (!contractDict.TryGetValue(statement.Id, out var tr))
|
||||
{
|
||||
tr = [];
|
||||
contractDict.Add(statement.Id, tr);
|
||||
}
|
||||
|
||||
|
||||
tr.Add(mark);
|
||||
return statement;
|
||||
}, splitOn: "StudentId", param: new { dateFrom, dateTo, teacherId,subjectId });
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
||||
|
||||
return contractDict.Select(x =>
|
||||
{
|
||||
var tr = contracts.First(y => y.Id == x.Key);
|
||||
tr.SetMarks(x.Value);
|
||||
return tr;
|
||||
}).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -114,20 +156,9 @@ namespace Academic_Performance.Repositories.Implementations
|
||||
}
|
||||
|
||||
|
||||
/// _logger.LogInformation("Получение всех объектов");
|
||||
/// try
|
||||
/// {
|
||||
/// using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
//// var statements = connection.Query<Statement>(querySelect);
|
||||
//// _logger.LogDebug("Полученные объекты: {json}",
|
||||
/// JsonConvert.SerializeObject(statements));
|
||||
/// return statements;
|
||||
/// }
|
||||
/// catch (Exception ex)
|
||||
/// {
|
||||
/// _logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
/// throw;
|
||||
/// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user