From 22202cc63d4351a2ca2a8443b7f88fcf1afe89c6 Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Tue, 9 Apr 2024 13:06:42 +0400 Subject: [PATCH] Last cummit --- SchoolSchedule/SchoolSchedule/LessonForm.cs | 13 +++ .../SchoolSchedule/MainForm.Designer.cs | 94 +++++++++++++++---- SchoolSchedule/SchoolSchedule/MainForm.cs | 56 +++++++++-- SchoolSchedule/SchoolSchedule/MainForm.resx | 15 +++ .../Implements/StudentStorage.cs | 2 +- 5 files changed, 156 insertions(+), 24 deletions(-) diff --git a/SchoolSchedule/SchoolSchedule/LessonForm.cs b/SchoolSchedule/SchoolSchedule/LessonForm.cs index f473bf3..9fc4d2e 100644 --- a/SchoolSchedule/SchoolSchedule/LessonForm.cs +++ b/SchoolSchedule/SchoolSchedule/LessonForm.cs @@ -1,6 +1,8 @@ using Microsoft.EntityFrameworkCore.Diagnostics; +using SchoolScheduleContracts.BindingModels; using SchoolScheduleContracts.BusinessLogicsContracts; using SchoolScheduleContracts.SearchModels; +using SchoolScheduleDataModels.Enums; using SchoolScheduleDataModels.Models; using System; using System.Collections.Generic; @@ -32,6 +34,17 @@ namespace SchoolSchedule dataGridView1.Rows.Clear(); foreach (var student in students) { + + if (!student.Attendance.ContainsKey(Lesson.Id)) { + student.Attendance.Add(Lesson.Id, (Lesson, StudentStatus.УП, null)); + _logic.Update(new StudentBindingModel + { + Id = student.Id, + GradeId = student.GradeId, + FullName = student.FullName, + Attendance = student.Attendance + }); + } dataGridView1.Rows.Add(new object[] { student.FullName, student.Attendance[Lesson.Id].Item2, student.Attendance[Lesson.Id].Item3, student.Id }); } } diff --git a/SchoolSchedule/SchoolSchedule/MainForm.Designer.cs b/SchoolSchedule/SchoolSchedule/MainForm.Designer.cs index fb66abe..5d20787 100644 --- a/SchoolSchedule/SchoolSchedule/MainForm.Designer.cs +++ b/SchoolSchedule/SchoolSchedule/MainForm.Designer.cs @@ -37,6 +37,12 @@ занятияToolStripMenuItem = new ToolStripMenuItem(); предметыToolStripMenuItem = new ToolStripMenuItem(); учителяToolStripMenuItem = new ToolStripMenuItem(); + классыToolStripMenuItem = new ToolStripMenuItem(); + SubjectName = new DataGridViewTextBoxColumn(); + Homework = new DataGridViewTextBoxColumn(); + Mark = new DataGridViewTextBoxColumn(); + Status = new DataGridViewTextBoxColumn(); + Date = new DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -44,83 +50,133 @@ // comboBox1 // comboBox1.FormattingEnabled = true; - comboBox1.Location = new Point(12, 32); + comboBox1.Location = new Point(14, 43); + comboBox1.Margin = new Padding(3, 4, 3, 4); comboBox1.Name = "comboBox1"; - comboBox1.Size = new Size(241, 23); + comboBox1.Size = new Size(275, 28); comboBox1.TabIndex = 0; - comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged; // // dataGridView1 // dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView1.Location = new Point(12, 61); + dataGridView1.Columns.AddRange(new DataGridViewColumn[] { SubjectName, Homework, Mark, Status, Date }); + dataGridView1.Location = new Point(14, 81); + dataGridView1.Margin = new Padding(3, 4, 3, 4); dataGridView1.Name = "dataGridView1"; - dataGridView1.Size = new Size(776, 377); + dataGridView1.RowHeadersWidth = 51; + dataGridView1.Size = new Size(887, 503); dataGridView1.TabIndex = 1; // // RefreshButton // - RefreshButton.Location = new Point(259, 32); + RefreshButton.Location = new Point(296, 43); + RefreshButton.Margin = new Padding(3, 4, 3, 4); RefreshButton.Name = "RefreshButton"; - RefreshButton.Size = new Size(75, 23); + RefreshButton.Size = new Size(86, 31); RefreshButton.TabIndex = 3; RefreshButton.Text = "Обновить"; RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; // // menuStrip1 // + menuStrip1.ImageScalingSize = new Size(20, 20); menuStrip1.Items.AddRange(new ToolStripItem[] { менюToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(800, 24); + menuStrip1.Padding = new Padding(7, 3, 0, 3); + menuStrip1.Size = new Size(914, 30); menuStrip1.TabIndex = 4; menuStrip1.Text = "menuStrip1"; // // менюToolStripMenuItem // - менюToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ученикиToolStripMenuItem, занятияToolStripMenuItem, предметыToolStripMenuItem, учителяToolStripMenuItem }); + менюToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ученикиToolStripMenuItem, занятияToolStripMenuItem, предметыToolStripMenuItem, учителяToolStripMenuItem, классыToolStripMenuItem }); менюToolStripMenuItem.Name = "менюToolStripMenuItem"; - менюToolStripMenuItem.Size = new Size(51, 20); + менюToolStripMenuItem.Size = new Size(63, 24); менюToolStripMenuItem.Text = "меню"; // // ученикиToolStripMenuItem // ученикиToolStripMenuItem.Name = "ученикиToolStripMenuItem"; - ученикиToolStripMenuItem.Size = new Size(180, 22); + ученикиToolStripMenuItem.Size = new Size(162, 26); ученикиToolStripMenuItem.Text = "ученики"; ученикиToolStripMenuItem.Click += ученикиToolStripMenuItem_Click; // // занятияToolStripMenuItem // занятияToolStripMenuItem.Name = "занятияToolStripMenuItem"; - занятияToolStripMenuItem.Size = new Size(180, 22); + занятияToolStripMenuItem.Size = new Size(162, 26); занятияToolStripMenuItem.Text = "занятия"; занятияToolStripMenuItem.Click += занятияToolStripMenuItem_Click; // // предметыToolStripMenuItem // предметыToolStripMenuItem.Name = "предметыToolStripMenuItem"; - предметыToolStripMenuItem.Size = new Size(180, 22); + предметыToolStripMenuItem.Size = new Size(162, 26); предметыToolStripMenuItem.Text = "предметы"; предметыToolStripMenuItem.Click += предметыToolStripMenuItem_Click; // // учителяToolStripMenuItem // учителяToolStripMenuItem.Name = "учителяToolStripMenuItem"; - учителяToolStripMenuItem.Size = new Size(180, 22); + учителяToolStripMenuItem.Size = new Size(162, 26); учителяToolStripMenuItem.Text = "учителя"; учителяToolStripMenuItem.Click += учителяToolStripMenuItem_Click; // + // классыToolStripMenuItem + // + классыToolStripMenuItem.Name = "классыToolStripMenuItem"; + классыToolStripMenuItem.Size = new Size(162, 26); + классыToolStripMenuItem.Text = "классы"; + классыToolStripMenuItem.Click += классыToolStripMenuItem_Click; + // + // SubjectName + // + SubjectName.HeaderText = "Имя предмета"; + SubjectName.MinimumWidth = 6; + SubjectName.Name = "SubjectName"; + SubjectName.Width = 200; + // + // Homework + // + Homework.HeaderText = "ДЗ"; + Homework.MinimumWidth = 6; + Homework.Name = "Homework"; + Homework.Width = 200; + // + // Mark + // + Mark.HeaderText = "Оценка"; + Mark.MinimumWidth = 6; + Mark.Name = "Mark"; + Mark.Width = 125; + // + // Status + // + Status.HeaderText = "Статус"; + Status.MinimumWidth = 6; + Status.Name = "Status"; + Status.Width = 125; + // + // Date + // + Date.HeaderText = "Дата"; + Date.MinimumWidth = 6; + Date.Name = "Date"; + Date.Width = 125; + // // MainForm // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(914, 600); Controls.Add(RefreshButton); Controls.Add(dataGridView1); Controls.Add(comboBox1); Controls.Add(menuStrip1); MainMenuStrip = menuStrip1; + Margin = new Padding(3, 4, 3, 4); Name = "MainForm"; Text = "MainForm"; Load += MainForm_Load; @@ -142,5 +198,11 @@ private ToolStripMenuItem занятияToolStripMenuItem; private ToolStripMenuItem предметыToolStripMenuItem; private ToolStripMenuItem учителяToolStripMenuItem; + private ToolStripMenuItem классыToolStripMenuItem; + private DataGridViewTextBoxColumn SubjectName; + private DataGridViewTextBoxColumn Homework; + private DataGridViewTextBoxColumn Mark; + private DataGridViewTextBoxColumn Status; + private DataGridViewTextBoxColumn Date; } } \ No newline at end of file diff --git a/SchoolSchedule/SchoolSchedule/MainForm.cs b/SchoolSchedule/SchoolSchedule/MainForm.cs index e7a6c90..5b4f7f9 100644 --- a/SchoolSchedule/SchoolSchedule/MainForm.cs +++ b/SchoolSchedule/SchoolSchedule/MainForm.cs @@ -1,4 +1,6 @@ using SchoolScheduleContracts.BusinessLogicsContracts; +using SchoolScheduleContracts.SearchModels; +using SchoolScheduleDataBaseImplement.Models; using System; using System.Collections.Generic; using System.ComponentModel; @@ -14,20 +16,43 @@ namespace SchoolSchedule public partial class MainForm : Form { IStudentLogic _logic; - public MainForm(IStudentLogic logic) + ITeacherLogic _logicT; + ISubjectLogic _logicS; + ILessonLogic _logicL; + private int? _id; + public int Id { set { _id = value; } } + public MainForm(IStudentLogic logic, ITeacherLogic logicT, ISubjectLogic logicS, ILessonLogic logicL) { InitializeComponent(); _logic = logic; - } - private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) - { - dataGridView1.DataSource = null; - dataGridView1.Rows.Clear(); + _logicT = logicT; + _logicS = logicS; + _logicL = logicL; } private void MainForm_Load(object sender, EventArgs e) { - + var list = _logic.ReadList(null); + if (list != null) + { + comboBox1.DisplayMember = "FullName"; + comboBox1.ValueMember = "Id"; + comboBox1.DataSource = list; + comboBox1.SelectedItem = null; + } + } + void LoadData() + { + if (_id.HasValue) + { + var student = _logic.ReadElement(new StudentSearchModel { Id = _id }); + foreach (var lesson in student.Attendance) + { + var subject = _logicS.ReadElement(new SubjectSearchModel { Id = lesson.Value.Item1.SubjectId }); + var lessont = _logicL.ReadElement(new LessonSearchModel { Id = lesson.Key }); + dataGridView1.Rows.Add(new object[] { subject.SubjectName, lessont.Homework, lesson.Value.Item3, lesson.Value.Item2, lessont.Date }); + } + } } private void ученикиToolStripMenuItem_Click(object sender, EventArgs e) @@ -65,5 +90,22 @@ namespace SchoolSchedule form.ShowDialog(); } } + + private void классыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(GradesForm)); + if (service is GradesForm form) + { + form.ShowDialog(); + } + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + dataGridView1.DataSource = null; + dataGridView1.Rows.Clear(); + Id = (int)comboBox1.SelectedValue; + LoadData(); + } } } diff --git a/SchoolSchedule/SchoolSchedule/MainForm.resx b/SchoolSchedule/SchoolSchedule/MainForm.resx index a0623c8..0708e9f 100644 --- a/SchoolSchedule/SchoolSchedule/MainForm.resx +++ b/SchoolSchedule/SchoolSchedule/MainForm.resx @@ -117,6 +117,21 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + + + True + + + True + 17, 17 diff --git a/SchoolSchedule/SchoolScheduleDataBaseImplement/Implements/StudentStorage.cs b/SchoolSchedule/SchoolScheduleDataBaseImplement/Implements/StudentStorage.cs index 658ccfb..074a6cc 100644 --- a/SchoolSchedule/SchoolScheduleDataBaseImplement/Implements/StudentStorage.cs +++ b/SchoolSchedule/SchoolScheduleDataBaseImplement/Implements/StudentStorage.cs @@ -39,7 +39,7 @@ namespace SchoolScheduleDataBaseImplement.Implements return null; } using var context = new SchoolScheduleDataBase(); - return context.Students.Include(x => x.Lessons).Include(x => x.Grade) + return context.Students.Include(x => x.Lessons).ThenInclude(x => x.Lesson).ThenInclude(x => x.Subject).Include(x => x.Grade) .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel;