diff --git a/ProjectTimeTable/ProjectTimeTable/Entites/Auditorium.cs b/ProjectTimeTable/ProjectTimeTable/Entites/Auditorium.cs index 5f9e28d..622bcd7 100644 --- a/ProjectTimeTable/ProjectTimeTable/Entites/Auditorium.cs +++ b/ProjectTimeTable/ProjectTimeTable/Entites/Auditorium.cs @@ -1,6 +1,7 @@ using ProjectTimeTable.Entites.Enums; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,10 +11,11 @@ namespace ProjectTimeTable.Entites; public class Auditorium { public int Id { get; private set; } + [DisplayName("Название аудитории")] public string Name { get; private set; } = string.Empty; - + [DisplayName("Тип аудитории")] public ClassType ClassType { get; private set; } - + [DisplayName("Размер аудитории")] public int Size { get; private set; } public static Auditorium CreateEntity(int id, string name, ClassType classType, int size) diff --git a/ProjectTimeTable/ProjectTimeTable/Entites/Discipline.cs b/ProjectTimeTable/ProjectTimeTable/Entites/Discipline.cs index 32c31a3..2063df9 100644 --- a/ProjectTimeTable/ProjectTimeTable/Entites/Discipline.cs +++ b/ProjectTimeTable/ProjectTimeTable/Entites/Discipline.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,6 +10,8 @@ namespace ProjectTimeTable.Entites; public class Discipline { public int ID { get; private set; } + + [DisplayName("Наименование дисцпилины")] public string Name { get; private set; } = string.Empty; public static Discipline CreateEntity(int id, string name) { diff --git a/ProjectTimeTable/ProjectTimeTable/Entites/DisciplinePlan.cs b/ProjectTimeTable/ProjectTimeTable/Entites/DisciplinePlan.cs index 152b75e..0f6a903 100644 --- a/ProjectTimeTable/ProjectTimeTable/Entites/DisciplinePlan.cs +++ b/ProjectTimeTable/ProjectTimeTable/Entites/DisciplinePlan.cs @@ -10,6 +10,7 @@ public class DisciplinePlan { public int PlanId { 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 Course { get; private set; } @@ -23,9 +24,4 @@ public class DisciplinePlan Course = course }; } - - - - - } diff --git a/ProjectTimeTable/ProjectTimeTable/Entites/Group.cs b/ProjectTimeTable/ProjectTimeTable/Entites/Group.cs index 32b4901..d750dff 100644 --- a/ProjectTimeTable/ProjectTimeTable/Entites/Group.cs +++ b/ProjectTimeTable/ProjectTimeTable/Entites/Group.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,11 +10,18 @@ namespace ProjectTimeTable.Entites; public class Group { public int Id { get; private set; } + [DisplayName("Название группы")] public string Name { get; private set; } = string.Empty; + [DisplayName("Курс")] public int Course { get; private set; } + [DisplayName("Количество людей")] public int CountPeople { get; private set; } + [Browsable(false)] 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) { return new diff --git a/ProjectTimeTable/ProjectTimeTable/Entites/GroupTimetable.cs b/ProjectTimeTable/ProjectTimeTable/Entites/GroupTimetable.cs index ec33cb9..f1cea9d 100644 --- a/ProjectTimeTable/ProjectTimeTable/Entites/GroupTimetable.cs +++ b/ProjectTimeTable/ProjectTimeTable/Entites/GroupTimetable.cs @@ -7,13 +7,15 @@ using System.Threading.Tasks; namespace ProjectTimeTable.Entites; public class GroupTimetable { - public int GroupId { get; private set; } - public int TimeTableId { get; private set; } public int DisciplineID { get; private set; } + public string DisciplineName { get; private set; } = string.Empty; public int ClassID { get; private set; } + public string ClassName { get; private set; } = string.Empty; public int GroupID { get; private set; } + public string GroupName { get; private set; } = string.Empty; 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) { @@ -21,7 +23,7 @@ public class GroupTimetable { DisciplineID = idDiscipline, ClassID = idClass, - GroupId = idGroup, + GroupID = idGroup, TeacherID = idTeacher, TimeTableId = idTimeTable }; diff --git a/ProjectTimeTable/ProjectTimeTable/Entites/Plan.cs b/ProjectTimeTable/ProjectTimeTable/Entites/Plan.cs index d3d9974..4022ca7 100644 --- a/ProjectTimeTable/ProjectTimeTable/Entites/Plan.cs +++ b/ProjectTimeTable/ProjectTimeTable/Entites/Plan.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,8 +9,16 @@ namespace ProjectTimeTable.Entites; public class Plan { - public int Id { get; private set; } + public int Id { get; private set; } + [DisplayName("Название плана")] 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 { get; @@ -25,4 +34,11 @@ public class Plan DisciplinePlan = disciplinePlan }; } + public void SetDisciplinePlan(IEnumerable disciplinePlans) + { + if (disciplinePlans != null && disciplinePlans.Any()) + { + DisciplinePlan = disciplinePlans; + } + } } diff --git a/ProjectTimeTable/ProjectTimeTable/Entites/Teacher.cs b/ProjectTimeTable/ProjectTimeTable/Entites/Teacher.cs index 32052e0..b588e05 100644 --- a/ProjectTimeTable/ProjectTimeTable/Entites/Teacher.cs +++ b/ProjectTimeTable/ProjectTimeTable/Entites/Teacher.cs @@ -1,6 +1,7 @@ using ProjectTimeTable.Entites.Enums; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,11 +11,15 @@ namespace ProjectTimeTable.Entites; public class Teacher { public int Id { get; private set; } + [DisplayName("Фамилия")] public string FirstName { get; private set; } = string.Empty; + [DisplayName("Имя")] public string SecondName { get; private set; } = string.Empty; + [DisplayName("Отчество")] public string LastName { get; private set; } = string.Empty; + public string FullName => $"{FirstName} {SecondName} {LastName}"; + [DisplayName("Ученая степень")] public TeacherPost TeacherPost { get; private set; } - public static Teacher CreateEntity(int id, string firstname, string secondname, string lastname, TeacherPost teacherPost) { @@ -23,6 +28,7 @@ public class Teacher FirstName = firstname ?? string.Empty, SecondName = secondname ?? string.Empty, LastName = lastname ?? string.Empty, - TeacherPost = teacherPost }; + TeacherPost = teacherPost + }; } } diff --git a/ProjectTimeTable/ProjectTimeTable/Entites/TimeTable.cs b/ProjectTimeTable/ProjectTimeTable/Entites/TimeTable.cs index f6f9c5e..0b6b20f 100644 --- a/ProjectTimeTable/ProjectTimeTable/Entites/TimeTable.cs +++ b/ProjectTimeTable/ProjectTimeTable/Entites/TimeTable.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,16 +10,25 @@ namespace ProjectTimeTable.Entites; public class TimeTable { public int Id { get; private set; } + [DisplayName("Количество пар")] public int NumberLesson { get; private set; } + [DisplayName("День")] public int Day { get; private set; } + [DisplayName("Неделя")] public int Week { get; private set; } + [Browsable(false)] + public string DisciplineName { get; set; } =string.Empty; + [Browsable(false)] public IEnumerable GroupTimetable { get; 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) { @@ -31,4 +41,11 @@ public class TimeTable GroupTimetable = groupTimetable }; } + public void SetTimeTableGroup(IEnumerable grouptts) + { + if (grouptts != null && grouptts.Any()) + { + GroupTimetable = grouptts; + } + } } diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormAuditoriums.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormAuditoriums.cs index f5dd710..3214fc0 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormAuditoriums.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormAuditoriums.cs @@ -35,8 +35,11 @@ namespace ProjectTimeTable.Forms 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) { id = 0; @@ -90,7 +93,6 @@ namespace ProjectTimeTable.Forms MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ButtonUpg_Click(object sender, EventArgs e) { if (!TryGetIdentifierFromSelectedRow(out var findId)) diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormDiscipline.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormDiscipline.cs index 40964c2..c550c9a 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormDiscipline.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormDiscipline.cs @@ -75,7 +75,6 @@ namespace ProjectTimeTable.Forms MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ButtonCancel_Click(object sender, EventArgs e) => Close(); private Discipline CreateDiscipline(int id) => Discipline.CreateEntity(id, textBoxName.Text); diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormDisciplines.Designer.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormDisciplines.Designer.cs index 4046fe6..f107f1e 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormDisciplines.Designer.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormDisciplines.Designer.cs @@ -110,7 +110,7 @@ Controls.Add(panel1); Name = "FormDisciplines"; StartPosition = FormStartPosition.CenterParent; - Text = "FormDisciplines"; + Text = "Дисциплины"; Load += FormDisciplines_Load; panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormDisciplines.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormDisciplines.cs index 92dc3be..9fc57a6 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormDisciplines.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormDisciplines.cs @@ -22,7 +22,6 @@ namespace ProjectTimeTable.Forms _container = container ?? throw new ArgumentNullException(nameof(container)); _disciplineRepository = disciplineRepository ?? throw new ArgumentNullException(nameof(disciplineRepository)); } - private void FormDisciplines_Load(object sender, EventArgs e) { try @@ -35,7 +34,11 @@ namespace ProjectTimeTable.Forms 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) { @@ -51,7 +54,6 @@ namespace ProjectTimeTable.Forms Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); return true; } - private void ButtonAdd_Click(object sender, EventArgs e) { try diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormGroup.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormGroup.cs index e6cd465..e3af63b 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormGroup.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormGroup.cs @@ -51,10 +51,7 @@ namespace ProjectTimeTable.Forms comboBoxPlan.DataSource = planRepository.ReadPlan(); comboBoxPlan.DisplayMember = "Name"; comboBoxPlan.ValueMember = "Id"; - - } - private void ButtonSave_Click(object sender, EventArgs e) { try @@ -86,7 +83,6 @@ namespace ProjectTimeTable.Forms private Group CreateGroup(int id) => Group.CreateEntity(id, TextBoxName.Text, Convert.ToInt32(numericUpDownCourse.Value), Convert.ToInt32(numericUpDownCount.Value), (int)comboBoxPlan.SelectedValue!); - private void ButtonCancel_Click(object sender, EventArgs e) => Close(); } } diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormGroups.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormGroups.cs index edd58c7..b958cd1 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormGroups.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormGroups.cs @@ -35,7 +35,11 @@ namespace ProjectTimeTable.Forms 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) { diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormPlan.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormPlan.cs index f71f8cd..63ade65 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormPlan.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormPlan.cs @@ -89,7 +89,5 @@ namespace ProjectTimeTable.Forms return list; } - - } } diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormPlanReport.Designer.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormPlanReport.Designer.cs index 4c32895..1214680 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormPlanReport.Designer.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormPlanReport.Designer.cs @@ -146,6 +146,7 @@ Controls.Add(textBoxFilePath); Controls.Add(label1); Name = "FormPlanReport"; + StartPosition = FormStartPosition.CenterParent; Text = "FormPlanReport"; ((System.ComponentModel.ISupportInitialize)numericUpDown).EndInit(); ResumeLayout(false); diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormPlanReport.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormPlanReport.cs index 61a8a23..f8c5a77 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormPlanReport.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormPlanReport.cs @@ -30,9 +30,6 @@ namespace ProjectTimeTable.Forms comboBoxgroup.ValueMember = "Id"; } - - - private void ButtonSelectFilePath_Click(object sender, EventArgs e) { var sfd = new SaveFileDialog() diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormPlans.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormPlans.cs index 79e39bc..7b4b80c 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormPlans.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormPlans.cs @@ -22,7 +22,6 @@ namespace ProjectTimeTable.Forms _container = container ?? throw new ArgumentNullException(nameof(container)); _planRepository = planRepository ?? throw new ArgumentNullException(nameof(planRepository)); } - private void FormPlans_Load(object sender, EventArgs e) { try @@ -35,7 +34,11 @@ namespace ProjectTimeTable.Forms 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) { diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormTeacher.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormTeacher.cs index 20f6373..b2e225b 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormTeacher.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormTeacher.cs @@ -18,7 +18,6 @@ namespace ProjectTimeTable.Forms private readonly ITeacherRepositories _teacherRepository; private int? _teacherId; - public int Id { set @@ -51,7 +50,6 @@ namespace ProjectTimeTable.Forms comboBoxPost.DataSource =Enum.GetValues(typeof(TeacherPost)); } - private void ButtonSave_Click(object sender, EventArgs e) { try @@ -82,10 +80,7 @@ namespace ProjectTimeTable.Forms } } - private void ButtonCancel_Click(object sender, EventArgs e) => Close(); - - private Teacher CreateTeacher(int id) => Teacher.CreateEntity(id, textBoxFirstName.Text, textBoxSecondName.Text, textBoxLastName.Text, (TeacherPost)comboBoxPost.SelectedItem!); } diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormTeachers.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormTeachers.cs index 6ae5a62..15d9bb3 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormTeachers.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormTeachers.cs @@ -23,9 +23,7 @@ namespace ProjectTimeTable.Forms throw new ArgumentNullException(nameof(container)); _teacherRepository = teacherRepository ?? throw new ArgumentNullException(nameof(teacherRepository)); - } - private void ButtonAdd_Click(object sender, EventArgs e) { try @@ -64,7 +62,6 @@ namespace ProjectTimeTable.Forms MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); } - } private void ButtonUpd_Click(object sender, EventArgs e) { @@ -85,9 +82,7 @@ namespace ProjectTimeTable.Forms MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); } - } - private void FormTeachers_Load(object sender, EventArgs e) { try @@ -99,11 +94,13 @@ namespace ProjectTimeTable.Forms MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); } - } - - private void LoadList() => dataGridView.DataSource =_teacherRepository.ReadTeacher(); - + private void LoadList() + { + dataGridView.DataSource = _teacherRepository.ReadTeacher(); + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["FullName"].Visible = false; + } private bool TryGetIdentifierFromSelectedRow(out int id) { id = 0; diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormTimeTable.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormTimeTable.cs index c392c27..b2d26eb 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormTimeTable.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormTimeTable.cs @@ -36,7 +36,7 @@ namespace ProjectTimeTable.Forms ColumnGroup.ValueMember = "Id"; ColumnTeacher.DataSource = teacherRepository.ReadTeacher(); - ColumnTeacher.DisplayMember = "FirstName"; + ColumnTeacher.DisplayMember = "FullName"; ColumnTeacher.ValueMember = "Id"; } @@ -49,8 +49,6 @@ namespace ProjectTimeTable.Forms { throw new Exception("Имеются незаполненные поля"); } - - dataGridViewTimeTable.RowCount--; _timeTableRepository.CreateTimeTable(TimeTable.CreateOperation(0, Convert.ToInt32(numericUpDownCountLesson.Value), Convert.ToInt32(numericUpDownDay.Value), Convert.ToInt32(numericUpDownWeek.Value), CreateListGroupTimeTableFromDataGrid())); @@ -66,8 +64,6 @@ namespace ProjectTimeTable.Forms private void ButtonCancel_Click(object sender, EventArgs e) => Close(); - - private List CreateListGroupTimeTableFromDataGrid() { var list = new List(); @@ -79,14 +75,10 @@ namespace ProjectTimeTable.Forms continue; } - list.Add(GroupTimetable.CreateElement(Convert.ToInt32(comboBoxDiscipline.SelectedIndex), Convert.ToInt32(comboBoxAuditorium.SelectedIndex), - Convert.ToInt32(comboBoxGroup.SelectedIndex), Convert.ToInt32(comboBoxTeacher.SelectedIndex), 0)); + list.Add(GroupTimetable.CreateElement(0,Convert.ToInt32(row.Cells["ColumnDiscipline"].Value), Convert.ToInt32(row.Cells["ColumnAuditorium"].Value), + Convert.ToInt32(row.Cells["ColumnGroup"].Value), Convert.ToInt32(row.Cells["ColumnTeacher"].Value))); } - return list; } - - - } } diff --git a/ProjectTimeTable/ProjectTimeTable/Forms/FormTimeTables.cs b/ProjectTimeTable/ProjectTimeTable/Forms/FormTimeTables.cs index 766806e..bed7f2e 100644 --- a/ProjectTimeTable/ProjectTimeTable/Forms/FormTimeTables.cs +++ b/ProjectTimeTable/ProjectTimeTable/Forms/FormTimeTables.cs @@ -36,7 +36,11 @@ namespace ProjectTimeTable.Forms 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) { @@ -79,7 +83,6 @@ namespace ProjectTimeTable.Forms { return; } - try { _timeTableRepository.DeleteTimeTable(findId); @@ -91,7 +94,5 @@ namespace ProjectTimeTable.Forms MessageBoxButtons.OK, MessageBoxIcon.Error); } } - - } } diff --git a/ProjectTimeTable/ProjectTimeTable/Reports/ChartReport.cs b/ProjectTimeTable/ProjectTimeTable/Reports/ChartReport.cs index d84d394..096715c 100644 --- a/ProjectTimeTable/ProjectTimeTable/Reports/ChartReport.cs +++ b/ProjectTimeTable/ProjectTimeTable/Reports/ChartReport.cs @@ -12,15 +12,19 @@ namespace ProjectTimeTable.Reports; internal class ChartReport { private readonly ITimeTableRepositories _timetableRepository; + private readonly IDisciplineRepositories _disciplineRepository; private readonly ILogger _logger; public ChartReport(ITimeTableRepositories timetableRepository, - ILogger logger) + ILogger logger, IDisciplineRepositories disciplineRepository) { _timetableRepository = timetableRepository ?? throw new ArgumentNullException(nameof(timetableRepository)); + _disciplineRepository = disciplineRepository ?? + throw new + ArgumentNullException(nameof(timetableRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } @@ -42,17 +46,22 @@ internal class ChartReport return false; } } - private List<(string Caption, double Value)> GetData(int week) { - return _timetableRepository - .ReadTimeTable() - .Where(x => x.Week == week) - .GroupBy(x => x.Day, (key, group) => new { - Id = key, - Count = group.Sum(x => x.NumberLesson) + var data = _timetableRepository + .ReadTimeTable(week); + foreach (var row in data) + { + row.DisciplineName = row.GroupTime.Split('|').First(); + } + 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(); + return result; } } diff --git a/ProjectTimeTable/ProjectTimeTable/Reports/DocReport.cs b/ProjectTimeTable/ProjectTimeTable/Reports/DocReport.cs index 1b1dd85..cd24a72 100644 --- a/ProjectTimeTable/ProjectTimeTable/Reports/DocReport.cs +++ b/ProjectTimeTable/ProjectTimeTable/Reports/DocReport.cs @@ -8,7 +8,6 @@ using System.Text; using System.Threading.Tasks; namespace ProjectTimeTable.Reports; - internal class DocReport { private readonly IGroupRepositories _groupRepository; @@ -70,7 +69,6 @@ includeTeacher, bool includeAuditorium, bool includeDiscipline) return false; } } - private List GetGroup() { return [ diff --git a/ProjectTimeTable/ProjectTimeTable/Reports/PdfBuilder.cs b/ProjectTimeTable/ProjectTimeTable/Reports/PdfBuilder.cs index b8e236f..61f513c 100644 --- a/ProjectTimeTable/ProjectTimeTable/Reports/PdfBuilder.cs +++ b/ProjectTimeTable/ProjectTimeTable/Reports/PdfBuilder.cs @@ -9,7 +9,6 @@ internal class PdfBuilder { private readonly string _filePath; private readonly Document _document; - public PdfBuilder(string filePath) { if (string.IsNullOrWhiteSpace(filePath)) diff --git a/ProjectTimeTable/ProjectTimeTable/Reports/TableReport.cs b/ProjectTimeTable/ProjectTimeTable/Reports/TableReport.cs index 6897136..401f98b 100644 --- a/ProjectTimeTable/ProjectTimeTable/Reports/TableReport.cs +++ b/ProjectTimeTable/ProjectTimeTable/Reports/TableReport.cs @@ -35,7 +35,7 @@ internal class TableReport { new ExcelBuilder(filePath) .AddHeader("Сводка по количеству дисциплин на курсе", 0, 3) - .AddParagraph("по плану", 0) + .AddParagraph($"По неделе {week}", 0) .AddTable([10, 10, 15, 10], GetData(week, discilineId, groupId)) .Build(); diff --git a/ProjectTimeTable/ProjectTimeTable/Reports/WordBuilder.cs b/ProjectTimeTable/ProjectTimeTable/Reports/WordBuilder.cs index d958724..a928622 100644 --- a/ProjectTimeTable/ProjectTimeTable/Reports/WordBuilder.cs +++ b/ProjectTimeTable/ProjectTimeTable/Reports/WordBuilder.cs @@ -32,8 +32,6 @@ public class WordBuilder _body = _document.AppendChild(new Body()); } - - public WordBuilder AddHeader(string header) { var paragraph = _body.AppendChild(new Paragraph()); diff --git a/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/AuditoriumRepositories.cs b/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/AuditoriumRepositories.cs index e35af5c..2620599 100644 --- a/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/AuditoriumRepositories.cs +++ b/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/AuditoriumRepositories.cs @@ -54,7 +54,6 @@ public class AuditoriumRepositories : IAuditoriumRepositories throw; } } - public IEnumerable ReadAuditorium() { _logger.LogInformation("Получение всех объектов"); @@ -73,7 +72,6 @@ public class AuditoriumRepositories : IAuditoriumRepositories throw; } } - public Auditorium ReadAuditoriumById(int id) { _logger.LogInformation("Получение объекта по идентификатору"); @@ -96,8 +94,6 @@ public class AuditoriumRepositories : IAuditoriumRepositories throw; } } - - public void UpdateAuditorium(Auditorium classs) { _logger.LogInformation("Редактирование объекта"); diff --git a/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/GroupRepositories.cs b/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/GroupRepositories.cs index b14e9b9..e6af148 100644 --- a/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/GroupRepositories.cs +++ b/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/GroupRepositories.cs @@ -63,7 +63,11 @@ public class GroupRepositories : IGroupRepositories try { 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(querySelect); _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(group)); diff --git a/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/PlanRepositories.cs b/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/PlanRepositories.cs index 9948bc4..e69b262 100644 --- a/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/PlanRepositories.cs +++ b/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/PlanRepositories.cs @@ -9,6 +9,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Unity; +using DocumentFormat.OpenXml.Drawing.Charts; +using static System.Runtime.InteropServices.JavaScript.JSType; +using System.Numerics; namespace ProjectTimeTable.Repositories.Implementation; @@ -55,17 +58,48 @@ public class PlanRepositories : IPlanRepositories throw; } } - public IEnumerable ReadPlan(int? groupId = null, int? disciplineId = null) { _logger.LogInformation("Получение всех объектов"); try { + var builder = new QueryBuilder(); + if (disciplineId.HasValue) + { + builder.AddCondition("dp.DisciplineID = @disciplineId"); + } + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = @"SELECT * FROM Plan"; - var plan = connection.Query(querySelect); - _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(plan)); - return plan; + var querySelect = $@" + SELECT p.*, d.Name AS DisciplineName, dp.CountLesson AS CountLesson, dp.Course as Course + 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>(); + + var plans = + connection.Query(querySelect, (plan, disciplineplans) => + { + if (!planDict.TryGetValue(plan.Id, out var frr)) + { + frr = []; + planDict.Add(plan.Id, frr); + } + frr.Add(disciplineplans); + 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) { @@ -73,7 +107,6 @@ public class PlanRepositories : IPlanRepositories throw; } } - public Plan ReadPlanById(int id) { _logger.LogInformation("Получение объекта по идентификатору"); @@ -81,7 +114,7 @@ public class PlanRepositories : IPlanRepositories try { 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(querySelect, new { id diff --git a/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/QueryBuilder.cs b/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/QueryBuilder.cs new file mode 100644 index 0000000..0bd0674 --- /dev/null +++ b/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/QueryBuilder.cs @@ -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}"; + } +} diff --git a/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/TimeTableRepositories.cs b/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/TimeTableRepositories.cs index d952105..b45a505 100644 --- a/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/TimeTableRepositories.cs +++ b/ProjectTimeTable/ProjectTimeTable/Repositories/Implementation/TimeTableRepositories.cs @@ -34,15 +34,18 @@ public class TimeTableRepositories : ITimeTableRepositories var queryInsert = @"INSERT INTO TimeTable (NumberLesson, Day, Week) VALUES (@NumberLesson, @Day, @Week); SELECT MAX(Id) FROM TimeTable"; - var PlanID = connection.QueryFirst(queryInsert, timeTable, transaction); - var querySubInsert = @"INSERT INTO GroupTimetable (GroupId, timeTableId, DisciplineID, ClassID, GroupID, TeacherID) - VALUES (@GroupId, @timeTableId, @DisciplineID, @ClassID, @GroupID, @TeacherID)"; + var TimeTableID = connection.QueryFirst(queryInsert, timeTable, transaction); + var querySubInsert = @"INSERT INTO GroupTimetable (timeTableId, DisciplineID, AuditoriumID, GroupID, TeacherID) + VALUES (@timeTableId, @DisciplineID, @AuditoriumID, @GroupID, @TeacherID)"; foreach (var elem in timeTable.GroupTimetable) { connection.Execute(querySubInsert, new { - elem.GroupId, - elem.TimeTableId, + TimeTableID, + elem.DisciplineID, + AuditoriumID = elem.ClassID, + elem.GroupID, + elem.TeacherID }, transaction); } transaction.Commit(); @@ -78,11 +81,43 @@ public class TimeTableRepositories : ITimeTableRepositories try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = "SELECT * FROM timetable"; - var timetable = connection.Query(querySelect); - _logger.LogDebug("Полученные объекты: {json}", - JsonConvert.SerializeObject(timetable)); - return timetable; + + var builder = new QueryBuilder(); + if (week.HasValue) + { + 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>(); + + var timetables = + connection.Query(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) {