Лабораторная работа 2

This commit is contained in:
Сафия Мухамадиева 2024-12-19 05:24:11 +04:00
parent eb83644996
commit 472f599a62

View File

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using StudentProgress.Entities;
using StudentProgress.Entities;
using StudentProgress.Entities.Enums;
using StudentProgress.Repositories;
@ -18,23 +15,16 @@ namespace StudentProgress.Forms
IProfessorsRepository professorsRepository, IStudentRepository studentRepository)
{
InitializeComponent();
_gradesRepository = gradesRepository ?? throw new ArgumentNullException(nameof(gradesRepository));
_subjectsRepository = subjectsRepository ?? throw new ArgumentNullException(nameof(subjectsRepository));
_professorsRepository = professorsRepository ?? throw new ArgumentNullException(nameof(professorsRepository));
_studentRepository = studentRepository ?? throw new ArgumentNullException(nameof(studentRepository));
LoadWorkTypes();
LoadSubjects();
LoadProfessors();
LoadStudents();
}
private void LoadWorkTypes()
{
foreach (var elem in Enum.GetValues(typeof(TypeOfWork)))
{
checkedListBoxType.Items.Add(elem);
}
}
private void LoadSubjects()
@ -47,9 +37,9 @@ namespace StudentProgress.Forms
private void LoadProfessors()
{
var professors = _professorsRepository.ReadProfessorsName();
var professors = _professorsRepository.ReadProfessors();
comboBoxProfessor.DataSource = professors;
comboBoxProfessor.DisplayMember = "FirstNameProfessor";
comboBoxProfessor.DisplayMember = "FirstName";
comboBoxProfessor.ValueMember = "Id";
}
@ -65,11 +55,11 @@ namespace StudentProgress.Forms
{
try
{
if (comboBoxSubject.SelectedIndex < 0 || checkedListBoxType.CheckedItems.Count == 0)
if (comboBoxSubject.SelectedIndex < 0 || dataGridView1.RowCount < 1)
{
throw new Exception("Имеются незаполненные поля");
}
CreateGrade(0);
_gradesRepository.CreateGrade(CreateGrade(0));
Close();
}
catch (Exception ex)
@ -80,43 +70,18 @@ namespace StudentProgress.Forms
private void buttonCancel_Click(object sender, EventArgs e) => Close();
private Grades CreateGrade(int id)
{
TypeOfWork typeOfWork = TypeOfWork.None;
foreach (var elem in checkedListBoxType.CheckedItems)
{
typeOfWork |= (TypeOfWork)elem;
}
return Grades.CreateEntity(id, (int)comboBoxSubject.SelectedValue, (int)comboBoxProfessor.SelectedValue, dateTimePicker1.Value);
}
private Grades CreateGrade(int id) => Grades.CreateEntity(id, (int)comboBoxSubject.SelectedValue!, (int)comboBoxProfessor.SelectedValue!, dateTimePicker1.Value, CreateListStudentGradesFromDataGrid());
private void FormGrade_Load(object sender, EventArgs e)
{
var columnGrade = new DataGridViewComboBoxColumn
{
Name = "ColumnGrade",
HeaderText = "Оценка",
DataSource = Enum.GetValues(typeof(Grade))
};
if (dataGridView1.Columns["ColumnGrade"] != null)
{
dataGridView1.Columns.Remove("ColumnGrade");
}
dataGridView1.Columns.Add(columnGrade);
}
private List<StudentGrades> CreateListFeedFeedReplenishmentsFromDataGrid()
public List<StudentGrades> CreateListStudentGradesFromDataGrid()
{
var list = new List<StudentGrades>();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells["ColumnStudent"].Value == null || row.Cells["ColumnGrade"].Value == null)
if (row.Cells["ColumnStudent"].Value == null || row.Cells["ColumnMark"].Value == null)
{
continue;
}
list.Add(StudentGrades.CreateEntity(0, Convert.ToInt32(row.Cells["ColumnStudent"].Value), (Grade)(row.Cells["ColumnGrade"].Value)));
list.Add(StudentGrades.CreateEntity(0, Convert.ToInt32(row.Cells["ColumnStudent"].Value), (Grade)Convert.ToInt32(row.Cells["ColumnMark"].Value)));
}
return list;
}