Лабораторная работа 2
This commit is contained in:
parent
eb83644996
commit
472f599a62
@ -1,7 +1,4 @@
|
|||||||
using System;
|
using StudentProgress.Entities;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using StudentProgress.Entities;
|
|
||||||
using StudentProgress.Entities.Enums;
|
using StudentProgress.Entities.Enums;
|
||||||
using StudentProgress.Repositories;
|
using StudentProgress.Repositories;
|
||||||
|
|
||||||
@ -18,23 +15,16 @@ namespace StudentProgress.Forms
|
|||||||
IProfessorsRepository professorsRepository, IStudentRepository studentRepository)
|
IProfessorsRepository professorsRepository, IStudentRepository studentRepository)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
_gradesRepository = gradesRepository ?? throw new ArgumentNullException(nameof(gradesRepository));
|
_gradesRepository = gradesRepository ?? throw new ArgumentNullException(nameof(gradesRepository));
|
||||||
_subjectsRepository = subjectsRepository ?? throw new ArgumentNullException(nameof(subjectsRepository));
|
_subjectsRepository = subjectsRepository ?? throw new ArgumentNullException(nameof(subjectsRepository));
|
||||||
_professorsRepository = professorsRepository ?? throw new ArgumentNullException(nameof(professorsRepository));
|
_professorsRepository = professorsRepository ?? throw new ArgumentNullException(nameof(professorsRepository));
|
||||||
_studentRepository = studentRepository ?? throw new ArgumentNullException(nameof(studentRepository));
|
_studentRepository = studentRepository ?? throw new ArgumentNullException(nameof(studentRepository));
|
||||||
|
|
||||||
LoadWorkTypes();
|
|
||||||
LoadSubjects();
|
LoadSubjects();
|
||||||
LoadProfessors();
|
LoadProfessors();
|
||||||
LoadStudents();
|
LoadStudents();
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadWorkTypes()
|
|
||||||
{
|
|
||||||
foreach (var elem in Enum.GetValues(typeof(TypeOfWork)))
|
|
||||||
{
|
|
||||||
checkedListBoxType.Items.Add(elem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadSubjects()
|
private void LoadSubjects()
|
||||||
@ -47,9 +37,9 @@ namespace StudentProgress.Forms
|
|||||||
|
|
||||||
private void LoadProfessors()
|
private void LoadProfessors()
|
||||||
{
|
{
|
||||||
var professors = _professorsRepository.ReadProfessorsName();
|
var professors = _professorsRepository.ReadProfessors();
|
||||||
comboBoxProfessor.DataSource = professors;
|
comboBoxProfessor.DataSource = professors;
|
||||||
comboBoxProfessor.DisplayMember = "FirstNameProfessor";
|
comboBoxProfessor.DisplayMember = "FirstName";
|
||||||
comboBoxProfessor.ValueMember = "Id";
|
comboBoxProfessor.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,11 +55,11 @@ namespace StudentProgress.Forms
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (comboBoxSubject.SelectedIndex < 0 || checkedListBoxType.CheckedItems.Count == 0)
|
if (comboBoxSubject.SelectedIndex < 0 || dataGridView1.RowCount < 1)
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
CreateGrade(0);
|
_gradesRepository.CreateGrade(CreateGrade(0));
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -80,43 +70,18 @@ namespace StudentProgress.Forms
|
|||||||
|
|
||||||
private void buttonCancel_Click(object sender, EventArgs e) => Close();
|
private void buttonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
private Grades CreateGrade(int id)
|
private Grades CreateGrade(int id) => Grades.CreateEntity(id, (int)comboBoxSubject.SelectedValue!, (int)comboBoxProfessor.SelectedValue!, dateTimePicker1.Value, CreateListStudentGradesFromDataGrid());
|
||||||
{
|
|
||||||
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 void FormGrade_Load(object sender, EventArgs e)
|
public List<StudentGrades> CreateListStudentGradesFromDataGrid()
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
var list = new List<StudentGrades>();
|
var list = new List<StudentGrades>();
|
||||||
foreach (DataGridViewRow row in dataGridView1.Rows)
|
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;
|
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;
|
return list;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user