ISEbd-21_Kotova_M_D_LabWork_4 #4

Closed
MariaKotova wants to merge 2 commits from LabWork_4 into LabWork_3
32 changed files with 248 additions and 100 deletions

View File

@@ -1,6 +1,7 @@
using ProjectTimeTable.Entites.Enums; using ProjectTimeTable.Entites.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;
@@ -10,10 +11,11 @@ namespace ProjectTimeTable.Entites;
public class Auditorium public class Auditorium
{ {
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 ClassType ClassType { get; private set; } public ClassType ClassType { get; private set; }
[DisplayName("Размер аудитории")]
public int Size { get; private set; } public int Size { get; private set; }
public static Auditorium CreateEntity(int id, string name, ClassType classType, int size) public static Auditorium CreateEntity(int id, string name, ClassType classType, int size)

View File

@@ -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,6 +10,8 @@ namespace ProjectTimeTable.Entites;
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;
public static Discipline CreateEntity(int id, string name) public static Discipline CreateEntity(int id, string name)
{ {

View File

@@ -10,6 +10,7 @@ public class DisciplinePlan
{ {
public int PlanId { get; private set; } public int PlanId { get; private set; }
public int DisciplineId { get; private set; } public int DisciplineId { get; private set; }
public string DisciplineName { get; private set; } = string.Empty;
public int CountLesson { get; private set; } public int CountLesson { get; private set; }
public int Course { get; private set; } public int Course { get; private set; }
@@ -23,9 +24,4 @@ public class DisciplinePlan
Course = course Course = course
}; };
} }
} }

View File

@@ -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,11 +10,18 @@ namespace ProjectTimeTable.Entites;
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 int Course { get; private set; } public int Course { get; private set; }
[DisplayName("Количество людей")]
public int CountPeople { get; private set; } public int CountPeople { get; private set; }
[Browsable(false)]
public int PlanID { get; private set; } public int PlanID { get; private set; }
[DisplayName("План")]
public string PlanName { get; private set; } = string.Empty;
public static Group CreateEntity(int id, string name, int course, int countPeople, int planId) public static Group CreateEntity(int id, string name, int course, int countPeople, int planId)
{ {
return new return new

View File

@@ -7,13 +7,15 @@ using System.Threading.Tasks;
namespace ProjectTimeTable.Entites; namespace ProjectTimeTable.Entites;
public class GroupTimetable public class GroupTimetable
{ {
public int GroupId { get; private set; }
public int TimeTableId { get; private set; } public int TimeTableId { get; private set; }
public int DisciplineID { get; private set; } public int DisciplineID { get; private set; }
public string DisciplineName { get; private set; } = string.Empty;
public int ClassID { get; private set; } public int ClassID { get; private set; }
public string ClassName { get; private set; } = string.Empty;
public int GroupID { get; private set; } public int GroupID { get; private set; }
public string GroupName { get; private set; } = string.Empty;
public int TeacherID { get; private set; } public int TeacherID { get; private set; }
public string TeacherName { get; private set; } = string.Empty;
public static GroupTimetable CreateElement(int idTimeTable, int idDiscipline, int idClass, int idGroup, int idTeacher) public static GroupTimetable CreateElement(int idTimeTable, int idDiscipline, int idClass, int idGroup, int idTeacher)
{ {
@@ -21,7 +23,7 @@ public class GroupTimetable
{ {
DisciplineID = idDiscipline, DisciplineID = idDiscipline,
ClassID = idClass, ClassID = idClass,
GroupId = idGroup, GroupID = idGroup,
TeacherID = idTeacher, TeacherID = idTeacher,
TimeTableId = idTimeTable TimeTableId = idTimeTable
}; };

View File

@@ -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,7 +10,15 @@ namespace ProjectTimeTable.Entites;
public class Plan public class Plan
{ {
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 DisciplineName => DisciplinePlan != null ?
string.Join(", ", DisciplinePlan.Select(x => $"{x.DisciplineName} {x.CountLesson} {x.Course}")) :
string.Empty;
[Browsable(false)]
public IEnumerable<DisciplinePlan> DisciplinePlan public IEnumerable<DisciplinePlan> DisciplinePlan
{ {
get; get;
@@ -25,4 +34,11 @@ public class Plan
DisciplinePlan = disciplinePlan DisciplinePlan = disciplinePlan
}; };
} }
public void SetDisciplinePlan(IEnumerable<DisciplinePlan> disciplinePlans)
{
if (disciplinePlans != null && disciplinePlans.Any())
{
DisciplinePlan = disciplinePlans;
}
}
} }

View File

@@ -1,6 +1,7 @@
using ProjectTimeTable.Entites.Enums; using ProjectTimeTable.Entites.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;
@@ -10,12 +11,16 @@ namespace ProjectTimeTable.Entites;
public class Teacher public class Teacher
{ {
public int Id { get; private set; } public int Id { get; private set; }
[DisplayName("Фамилия")]
public string FirstName { get; private set; } = string.Empty; public string FirstName { get; private set; } = string.Empty;
[DisplayName("Имя")]
public string SecondName { get; private set; } = string.Empty; public string SecondName { get; private set; } = string.Empty;
[DisplayName("Отчество")]
public string LastName { get; private set; } = string.Empty; public string LastName { get; private set; } = string.Empty;
public string FullName => $"{FirstName} {SecondName} {LastName}";
[DisplayName("Ученая степень")]
public TeacherPost TeacherPost { get; private set; } public TeacherPost TeacherPost { get; private set; }
public static Teacher CreateEntity(int id, string firstname, string secondname, string lastname, TeacherPost teacherPost) public static Teacher CreateEntity(int id, string firstname, string secondname, string lastname, TeacherPost teacherPost)
{ {
return new Teacher return new Teacher
@@ -23,6 +28,7 @@ public class Teacher
FirstName = firstname ?? string.Empty, FirstName = firstname ?? string.Empty,
SecondName = secondname ?? string.Empty, SecondName = secondname ?? string.Empty,
LastName = lastname ?? string.Empty, LastName = lastname ?? string.Empty,
TeacherPost = teacherPost }; TeacherPost = teacherPost
};
} }
} }

View File

@@ -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,16 +10,25 @@ namespace ProjectTimeTable.Entites;
public class TimeTable public class TimeTable
{ {
public int Id { get; private set; } public int Id { get; private set; }
[DisplayName("Количество пар")]
public int NumberLesson { get; private set; } public int NumberLesson { get; private set; }
[DisplayName("День")]
public int Day { get; private set; } public int Day { get; private set; }
[DisplayName("Неделя")]
public int Week { get; private set; } public int Week { get; private set; }
[Browsable(false)]
public string DisciplineName { get; set; } =string.Empty;
[Browsable(false)]
public IEnumerable<GroupTimetable> GroupTimetable public IEnumerable<GroupTimetable> GroupTimetable
{ {
get; get;
private set; private set;
} = []; } = [];
[DisplayName("Расписание")]
public string GroupTime => GroupTimetable != null ?
string.Join(", ", GroupTimetable.Select(x => $"{x.DisciplineName}|{x.ClassName} {x.GroupName} {x.TeacherName}")) :
string.Empty;
public static TimeTable CreateOperation(int id, int numberLesson, int day, int week, IEnumerable<GroupTimetable> groupTimetable) public static TimeTable CreateOperation(int id, int numberLesson, int day, int week, IEnumerable<GroupTimetable> groupTimetable)
{ {
@@ -31,4 +41,11 @@ public class TimeTable
GroupTimetable = groupTimetable GroupTimetable = groupTimetable
}; };
} }
public void SetTimeTableGroup(IEnumerable<GroupTimetable> grouptts)
{
if (grouptts != null && grouptts.Any())
{
GroupTimetable = grouptts;
}
}
} }

View File

@@ -35,8 +35,11 @@ namespace ProjectTimeTable.Forms
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void LoadList() => dataGridView.DataSource = _auditoriumRepository.ReadAuditorium(); private void LoadList()
{
dataGridView.DataSource = _auditoriumRepository.ReadAuditorium();
dataGridView.Columns["Id"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)
{ {
id = 0; id = 0;
@@ -90,7 +93,6 @@ namespace ProjectTimeTable.Forms
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void ButtonUpg_Click(object sender, EventArgs e) private void ButtonUpg_Click(object sender, EventArgs e)
{ {
if (!TryGetIdentifierFromSelectedRow(out var findId)) if (!TryGetIdentifierFromSelectedRow(out var findId))

View File

@@ -75,7 +75,6 @@ namespace ProjectTimeTable.Forms
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void ButtonCancel_Click(object sender, EventArgs e) => Close(); private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Discipline CreateDiscipline(int id) => Discipline.CreateEntity(id, textBoxName.Text); private Discipline CreateDiscipline(int id) => Discipline.CreateEntity(id, textBoxName.Text);

View File

@@ -110,7 +110,7 @@
Controls.Add(panel1); Controls.Add(panel1);
Name = "FormDisciplines"; Name = "FormDisciplines";
StartPosition = FormStartPosition.CenterParent; StartPosition = FormStartPosition.CenterParent;
Text = "FormDisciplines"; Text = "Дисциплины";
Load += FormDisciplines_Load; Load += FormDisciplines_Load;
panel1.ResumeLayout(false); panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();

View File

@@ -22,7 +22,6 @@ namespace ProjectTimeTable.Forms
_container = container ?? throw new ArgumentNullException(nameof(container)); _container = container ?? throw new ArgumentNullException(nameof(container));
_disciplineRepository = disciplineRepository ?? throw new ArgumentNullException(nameof(disciplineRepository)); _disciplineRepository = disciplineRepository ?? throw new ArgumentNullException(nameof(disciplineRepository));
} }
private void FormDisciplines_Load(object sender, EventArgs e) private void FormDisciplines_Load(object sender, EventArgs e)
{ {
try try
@@ -35,7 +34,11 @@ namespace ProjectTimeTable.Forms
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void LoadList() => dataGridView.DataSource = _disciplineRepository.ReadDiscipline(); private void LoadList()
{
dataGridView.DataSource = _disciplineRepository.ReadDiscipline();
dataGridView.Columns["Id"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)
{ {
@@ -51,7 +54,6 @@ namespace ProjectTimeTable.Forms
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
return true; return true;
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
try try

View File

@@ -51,10 +51,7 @@ namespace ProjectTimeTable.Forms
comboBoxPlan.DataSource = planRepository.ReadPlan(); comboBoxPlan.DataSource = planRepository.ReadPlan();
comboBoxPlan.DisplayMember = "Name"; comboBoxPlan.DisplayMember = "Name";
comboBoxPlan.ValueMember = "Id"; comboBoxPlan.ValueMember = "Id";
} }
private void ButtonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
{ {
try try
@@ -86,7 +83,6 @@ namespace ProjectTimeTable.Forms
private Group CreateGroup(int id) => Group.CreateEntity(id, TextBoxName.Text, private Group CreateGroup(int id) => Group.CreateEntity(id, TextBoxName.Text,
Convert.ToInt32(numericUpDownCourse.Value), Convert.ToInt32(numericUpDownCount.Value), (int)comboBoxPlan.SelectedValue!); Convert.ToInt32(numericUpDownCourse.Value), Convert.ToInt32(numericUpDownCount.Value), (int)comboBoxPlan.SelectedValue!);
private void ButtonCancel_Click(object sender, EventArgs e) => Close(); private void ButtonCancel_Click(object sender, EventArgs e) => Close();
} }
} }

View File

@@ -35,7 +35,11 @@ namespace ProjectTimeTable.Forms
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void LoadList() => dataGridView.DataSource = _groupRepository.ReadGroup(); private void LoadList()
{
dataGridView.DataSource = _groupRepository.ReadGroup();
dataGridView.Columns["Id"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)
{ {

View File

@@ -89,7 +89,5 @@ namespace ProjectTimeTable.Forms
return list; return list;
} }
} }
} }

View File

@@ -146,6 +146,7 @@
Controls.Add(textBoxFilePath); Controls.Add(textBoxFilePath);
Controls.Add(label1); Controls.Add(label1);
Name = "FormPlanReport"; Name = "FormPlanReport";
StartPosition = FormStartPosition.CenterParent;
Text = "FormPlanReport"; Text = "FormPlanReport";
((System.ComponentModel.ISupportInitialize)numericUpDown).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDown).EndInit();
ResumeLayout(false); ResumeLayout(false);

View File

@@ -30,9 +30,6 @@ namespace ProjectTimeTable.Forms
comboBoxgroup.ValueMember = "Id"; comboBoxgroup.ValueMember = "Id";
} }
private void ButtonSelectFilePath_Click(object sender, EventArgs e) private void ButtonSelectFilePath_Click(object sender, EventArgs e)
{ {
var sfd = new SaveFileDialog() var sfd = new SaveFileDialog()

View File

@@ -22,7 +22,6 @@ namespace ProjectTimeTable.Forms
_container = container ?? throw new ArgumentNullException(nameof(container)); _container = container ?? throw new ArgumentNullException(nameof(container));
_planRepository = planRepository ?? throw new ArgumentNullException(nameof(planRepository)); _planRepository = planRepository ?? throw new ArgumentNullException(nameof(planRepository));
} }
private void FormPlans_Load(object sender, EventArgs e) private void FormPlans_Load(object sender, EventArgs e)
{ {
try try
@@ -35,7 +34,11 @@ namespace ProjectTimeTable.Forms
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void LoadList() => dataGridView.DataSource = _planRepository.ReadPlan(); private void LoadList()
{
dataGridView.DataSource = _planRepository.ReadPlan();
dataGridView.Columns["Id"].Visible = false;
}
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {

View File

@@ -18,7 +18,6 @@ namespace ProjectTimeTable.Forms
private readonly ITeacherRepositories _teacherRepository; private readonly ITeacherRepositories _teacherRepository;
private int? _teacherId; private int? _teacherId;
public int Id public int Id
{ {
set set
@@ -51,7 +50,6 @@ namespace ProjectTimeTable.Forms
comboBoxPost.DataSource =Enum.GetValues(typeof(TeacherPost)); comboBoxPost.DataSource =Enum.GetValues(typeof(TeacherPost));
} }
private void ButtonSave_Click(object sender, EventArgs e) private void ButtonSave_Click(object sender, EventArgs e)
{ {
try try
@@ -82,10 +80,7 @@ namespace ProjectTimeTable.Forms
} }
} }
private void ButtonCancel_Click(object sender, EventArgs e) => Close(); private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Teacher CreateTeacher(int id) => Teacher.CreateEntity(id, textBoxFirstName.Text, textBoxSecondName.Text, private Teacher CreateTeacher(int id) => Teacher.CreateEntity(id, textBoxFirstName.Text, textBoxSecondName.Text,
textBoxLastName.Text, (TeacherPost)comboBoxPost.SelectedItem!); textBoxLastName.Text, (TeacherPost)comboBoxPost.SelectedItem!);
} }

View File

@@ -23,9 +23,7 @@ namespace ProjectTimeTable.Forms
throw new ArgumentNullException(nameof(container)); throw new ArgumentNullException(nameof(container));
_teacherRepository = teacherRepository ?? _teacherRepository = teacherRepository ??
throw new ArgumentNullException(nameof(teacherRepository)); throw new ArgumentNullException(nameof(teacherRepository));
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
try try
@@ -64,7 +62,6 @@ namespace ProjectTimeTable.Forms
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBox.Show(ex.Message, "Ошибка при удалении",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void ButtonUpd_Click(object sender, EventArgs e) private void ButtonUpd_Click(object sender, EventArgs e)
{ {
@@ -85,9 +82,7 @@ namespace ProjectTimeTable.Forms
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBox.Show(ex.Message, "Ошибка при изменении",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void FormTeachers_Load(object sender, EventArgs e) private void FormTeachers_Load(object sender, EventArgs e)
{ {
try try
@@ -99,11 +94,13 @@ namespace ProjectTimeTable.Forms
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBox.Show(ex.Message, "Ошибка при загрузке",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void LoadList()
private void LoadList() => dataGridView.DataSource =_teacherRepository.ReadTeacher(); {
dataGridView.DataSource = _teacherRepository.ReadTeacher();
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["FullName"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)
{ {
id = 0; id = 0;

View File

@@ -36,7 +36,7 @@ namespace ProjectTimeTable.Forms
ColumnGroup.ValueMember = "Id"; ColumnGroup.ValueMember = "Id";
ColumnTeacher.DataSource = teacherRepository.ReadTeacher(); ColumnTeacher.DataSource = teacherRepository.ReadTeacher();
ColumnTeacher.DisplayMember = "FirstName"; ColumnTeacher.DisplayMember = "FullName";
ColumnTeacher.ValueMember = "Id"; ColumnTeacher.ValueMember = "Id";
} }
@@ -49,8 +49,6 @@ namespace ProjectTimeTable.Forms
{ {
throw new Exception("Имеются незаполненные поля"); throw new Exception("Имеются незаполненные поля");
} }
dataGridViewTimeTable.RowCount--;
_timeTableRepository.CreateTimeTable(TimeTable.CreateOperation(0, Convert.ToInt32(numericUpDownCountLesson.Value), _timeTableRepository.CreateTimeTable(TimeTable.CreateOperation(0, Convert.ToInt32(numericUpDownCountLesson.Value),
Convert.ToInt32(numericUpDownDay.Value), Convert.ToInt32(numericUpDownWeek.Value), Convert.ToInt32(numericUpDownDay.Value), Convert.ToInt32(numericUpDownWeek.Value),
CreateListGroupTimeTableFromDataGrid())); CreateListGroupTimeTableFromDataGrid()));
@@ -66,8 +64,6 @@ namespace ProjectTimeTable.Forms
private void ButtonCancel_Click(object sender, EventArgs e) => private void ButtonCancel_Click(object sender, EventArgs e) =>
Close(); Close();
private List<GroupTimetable> CreateListGroupTimeTableFromDataGrid() private List<GroupTimetable> CreateListGroupTimeTableFromDataGrid()
{ {
var list = new List<GroupTimetable>(); var list = new List<GroupTimetable>();
@@ -79,14 +75,10 @@ namespace ProjectTimeTable.Forms
continue; continue;
} }
list.Add(GroupTimetable.CreateElement(Convert.ToInt32(comboBoxDiscipline.SelectedIndex), Convert.ToInt32(comboBoxAuditorium.SelectedIndex), list.Add(GroupTimetable.CreateElement(0,Convert.ToInt32(row.Cells["ColumnDiscipline"].Value), Convert.ToInt32(row.Cells["ColumnAuditorium"].Value),
Convert.ToInt32(comboBoxGroup.SelectedIndex), Convert.ToInt32(comboBoxTeacher.SelectedIndex), 0)); Convert.ToInt32(row.Cells["ColumnGroup"].Value), Convert.ToInt32(row.Cells["ColumnTeacher"].Value)));
} }
return list; return list;
} }
} }
} }

View File

@@ -36,7 +36,11 @@ namespace ProjectTimeTable.Forms
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void LoadList() => dataGridView.DataSource = _timeTableRepository.ReadTimeTable(); private void LoadList()
{
dataGridView.DataSource = _timeTableRepository.ReadTimeTable();
dataGridView.Columns["Id"].Visible = false;
}
private bool TryGetIdentifierFromSelectedRow(out int id) private bool TryGetIdentifierFromSelectedRow(out int id)
{ {
@@ -79,7 +83,6 @@ namespace ProjectTimeTable.Forms
{ {
return; return;
} }
try try
{ {
_timeTableRepository.DeleteTimeTable(findId); _timeTableRepository.DeleteTimeTable(findId);
@@ -91,7 +94,5 @@ namespace ProjectTimeTable.Forms
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
} }
} }

View File

@@ -12,14 +12,18 @@ namespace ProjectTimeTable.Reports;
internal class ChartReport internal class ChartReport
{ {
private readonly ITimeTableRepositories _timetableRepository; private readonly ITimeTableRepositories _timetableRepository;
private readonly IDisciplineRepositories _disciplineRepository;
private readonly ILogger<ChartReport> _logger; private readonly ILogger<ChartReport> _logger;
public ChartReport(ITimeTableRepositories timetableRepository, public ChartReport(ITimeTableRepositories timetableRepository,
ILogger<ChartReport> logger) ILogger<ChartReport> logger, IDisciplineRepositories disciplineRepository)
{ {
_timetableRepository = timetableRepository ?? _timetableRepository = timetableRepository ??
throw new throw new
ArgumentNullException(nameof(timetableRepository));
_disciplineRepository = disciplineRepository ??
throw new
ArgumentNullException(nameof(timetableRepository)); ArgumentNullException(nameof(timetableRepository));
_logger = logger ?? _logger = logger ??
throw new ArgumentNullException(nameof(logger)); throw new ArgumentNullException(nameof(logger));
@@ -42,17 +46,22 @@ internal class ChartReport
return false; return false;
} }
} }
private List<(string Caption, double Value)> GetData(int week) private List<(string Caption, double Value)> GetData(int week)
{ {
return _timetableRepository var data = _timetableRepository
.ReadTimeTable() .ReadTimeTable(week);
.Where(x => x.Week == week) foreach (var row in data)
.GroupBy(x => x.Day, (key, group) => new { {
Id = key, row.DisciplineName = row.GroupTime.Split('|').First();
Count = group.Sum(x => x.NumberLesson) }
var result = data
.GroupBy(x => x.DisciplineName, (key, group) => new
{
DisciplineName = key,
Count = group.Sum(y => y.NumberLesson)
}) })
.Select(x => (x.Id.ToString(), (double)x.Count)) .Select(x => (x.DisciplineName.ToString(), (double)x.Count))
.ToList(); .ToList();
return result;
} }
} }

View File

@@ -8,7 +8,6 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ProjectTimeTable.Reports; namespace ProjectTimeTable.Reports;
internal class DocReport internal class DocReport
{ {
private readonly IGroupRepositories _groupRepository; private readonly IGroupRepositories _groupRepository;
@@ -70,7 +69,6 @@ includeTeacher, bool includeAuditorium, bool includeDiscipline)
return false; return false;
} }
} }
private List<string[]> GetGroup() private List<string[]> GetGroup()
{ {
return [ return [

View File

@@ -9,7 +9,6 @@ internal class PdfBuilder
{ {
private readonly string _filePath; private readonly string _filePath;
private readonly Document _document; private readonly Document _document;
public PdfBuilder(string filePath) public PdfBuilder(string filePath)
{ {
if (string.IsNullOrWhiteSpace(filePath)) if (string.IsNullOrWhiteSpace(filePath))

View File

@@ -35,7 +35,7 @@ internal class TableReport
{ {
new ExcelBuilder(filePath) new ExcelBuilder(filePath)
.AddHeader("Сводка по количеству дисциплин на курсе", 0, 3) .AddHeader("Сводка по количеству дисциплин на курсе", 0, 3)
.AddParagraph("по плану", 0) .AddParagraph($"По неделе {week}", 0)
.AddTable([10, 10, 15, 10], GetData(week, discilineId, groupId)) .AddTable([10, 10, 15, 10], GetData(week, discilineId, groupId))
.Build(); .Build();

View File

@@ -32,8 +32,6 @@ public class WordBuilder
_body = _document.AppendChild(new Body()); _body = _document.AppendChild(new Body());
} }
public WordBuilder AddHeader(string header) public WordBuilder AddHeader(string header)
{ {
var paragraph = _body.AppendChild(new Paragraph()); var paragraph = _body.AppendChild(new Paragraph());

View File

@@ -54,7 +54,6 @@ public class AuditoriumRepositories : IAuditoriumRepositories
throw; throw;
} }
} }
public IEnumerable<Auditorium> ReadAuditorium() public IEnumerable<Auditorium> ReadAuditorium()
{ {
_logger.LogInformation("Получение всех объектов"); _logger.LogInformation("Получение всех объектов");
@@ -73,7 +72,6 @@ public class AuditoriumRepositories : IAuditoriumRepositories
throw; throw;
} }
} }
public Auditorium ReadAuditoriumById(int id) public Auditorium ReadAuditoriumById(int id)
{ {
_logger.LogInformation("Получение объекта по идентификатору"); _logger.LogInformation("Получение объекта по идентификатору");
@@ -96,8 +94,6 @@ public class AuditoriumRepositories : IAuditoriumRepositories
throw; throw;
} }
} }
public void UpdateAuditorium(Auditorium classs) public void UpdateAuditorium(Auditorium classs)
{ {
_logger.LogInformation("Редактирование объекта"); _logger.LogInformation("Редактирование объекта");

View File

@@ -63,7 +63,11 @@ public class GroupRepositories : IGroupRepositories
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Groupp"; var querySelect = @"
SELECT g.*, op.Name AS PlanName
FROM Groupp g
INNER JOIN Plan AS op ON op.ID = g.PlanID";
var group = connection.Query<Group>(querySelect); var group = connection.Query<Group>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", _logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(group)); JsonConvert.SerializeObject(group));

View File

@@ -9,6 +9,9 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Unity; using Unity;
using DocumentFormat.OpenXml.Drawing.Charts;
using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Numerics;
namespace ProjectTimeTable.Repositories.Implementation; namespace ProjectTimeTable.Repositories.Implementation;
@@ -55,17 +58,48 @@ public class PlanRepositories : IPlanRepositories
throw; throw;
} }
} }
public IEnumerable<Plan> ReadPlan(int? groupId = null, int? disciplineId = null) public IEnumerable<Plan> ReadPlan(int? groupId = null, int? disciplineId = null)
{ {
_logger.LogInformation("Получение всех объектов"); _logger.LogInformation("Получение всех объектов");
try try
{ {
var builder = new QueryBuilder();
if (disciplineId.HasValue)
{
builder.AddCondition("dp.DisciplineID = @disciplineId");
}
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM Plan"; var querySelect = $@"
var plan = connection.Query<Plan>(querySelect); SELECT p.*, d.Name AS DisciplineName, dp.CountLesson AS CountLesson, dp.Course as Course
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(plan)); FROM Plan p
INNER JOIN DisciplinePlan AS dp ON dp.PlanID = p.Id
INNER JOIN Discipline AS d ON d.ID = dp.DisciplineID
{builder.Build()}";
var planDict = new Dictionary<int, List<DisciplinePlan>>();
var plans =
connection.Query<Plan, DisciplinePlan, Plan>(querySelect, (plan, disciplineplans) =>
{
if (!planDict.TryGetValue(plan.Id, out var frr))
{
frr = [];
planDict.Add(plan.Id, frr);
}
frr.Add(disciplineplans);
return plan; return plan;
}, splitOn: "DisciplineName", param: new { disciplineId });
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(plans));
return planDict.Select(x =>
{
var fr = plans.First(y => y.Id == x.Key);
fr.SetDisciplinePlan(x.Value);
return fr;
}).ToArray();
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -73,7 +107,6 @@ public class PlanRepositories : IPlanRepositories
throw; throw;
} }
} }
public Plan ReadPlanById(int id) public Plan ReadPlanById(int id)
{ {
_logger.LogInformation("Получение объекта по идентификатору"); _logger.LogInformation("Получение объекта по идентификатору");
@@ -81,7 +114,7 @@ public class PlanRepositories : IPlanRepositories
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"SELECT * FROM teacher WHERE [Id]=@id"; var querySelect = @"SELECT * FROM plan WHERE [Id]=@id";
var plan = connection.QueryFirst<Plan>(querySelect, new var plan = connection.QueryFirst<Plan>(querySelect, new
{ {
id id

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectTimeTable.Repositories.Implementation;
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

@@ -34,15 +34,18 @@ public class TimeTableRepositories : ITimeTableRepositories
var queryInsert = @"INSERT INTO TimeTable (NumberLesson, Day, Week) var queryInsert = @"INSERT INTO TimeTable (NumberLesson, Day, Week)
VALUES (@NumberLesson, @Day, @Week); VALUES (@NumberLesson, @Day, @Week);
SELECT MAX(Id) FROM TimeTable"; SELECT MAX(Id) FROM TimeTable";
var PlanID = connection.QueryFirst<int>(queryInsert, timeTable, transaction); var TimeTableID = connection.QueryFirst<int>(queryInsert, timeTable, transaction);
var querySubInsert = @"INSERT INTO GroupTimetable (GroupId, timeTableId, DisciplineID, ClassID, GroupID, TeacherID) var querySubInsert = @"INSERT INTO GroupTimetable (timeTableId, DisciplineID, AuditoriumID, GroupID, TeacherID)
VALUES (@GroupId, @timeTableId, @DisciplineID, @ClassID, @GroupID, @TeacherID)"; VALUES (@timeTableId, @DisciplineID, @AuditoriumID, @GroupID, @TeacherID)";
foreach (var elem in timeTable.GroupTimetable) foreach (var elem in timeTable.GroupTimetable)
{ {
connection.Execute(querySubInsert, new connection.Execute(querySubInsert, new
{ {
elem.GroupId, TimeTableID,
elem.TimeTableId, elem.DisciplineID,
AuditoriumID = elem.ClassID,
elem.GroupID,
elem.TeacherID
}, transaction); }, transaction);
} }
transaction.Commit(); transaction.Commit();
@@ -78,11 +81,43 @@ public class TimeTableRepositories : ITimeTableRepositories
try try
{ {
using var connection = new NpgsqlConnection(_connectionString.ConnectionString); using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM timetable";
var timetable = connection.Query<TimeTable>(querySelect); var builder = new QueryBuilder();
_logger.LogDebug("Полученные объекты: {json}", if (week.HasValue)
JsonConvert.SerializeObject(timetable)); {
return timetable; builder.AddCondition("tt.Week = @Week");
}
var querySelect = $@"
SELECT tt.*, d.Name AS DisciplineName, a.Name AS ClassName, g.Name AS GroupName, t.FirstName AS TeacherName
FROM TimeTable tt
INNER JOIN GroupTimeTable AS gt ON gt.TimeTableId = tt.Id
INNER JOIN Discipline AS d ON d.ID = gt.DisciplineID
INNER JOIN Auditorium AS a ON a.ID = gt.AuditoriumID
INNER JOIN Groupp AS g ON g.ID = gt.GroupID
INNER JOIN Teacher AS t ON t.ID = gt.TeacherID {builder.Build()}";
var timetableDict = new Dictionary<int, List<GroupTimetable>>();
var timetables =
connection.Query<TimeTable, GroupTimetable, TimeTable>(querySelect, (timetables, grouptimetables) =>
{
if (!timetableDict.TryGetValue(timetables.Id, out var frr))
{
frr = [];
timetableDict.Add(timetables.Id, frr);
}
frr.Add(grouptimetables);
return timetables;
}, splitOn: "DisciplineName", param: new { week,day, groupId, classId, teacherId});
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(timetables));
return timetableDict.Select(x =>
{
var fr = timetables.First(y => y.Id == x.Key);
fr.SetTimeTableGroup(x.Value);
return fr;
}).ToArray();
} }
catch (Exception ex) catch (Exception ex)
{ {