diff --git a/StudentProgress/StudentProgress/Forms/FormGrade.cs b/StudentProgress/StudentProgress/Forms/FormGrade.cs index 6feea54..4b749ab 100644 --- a/StudentProgress/StudentProgress/Forms/FormGrade.cs +++ b/StudentProgress/StudentProgress/Forms/FormGrade.cs @@ -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 CreateListFeedFeedReplenishmentsFromDataGrid() + public List CreateListStudentGradesFromDataGrid() { var list = new List(); 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; }