2024-05-06 20:26:16 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using StudentEnrollmentContracts.BindingModels;
|
|
|
|
|
using StudentEnrollmentContracts.BusinessLogicContracts;
|
|
|
|
|
|
|
|
|
|
namespace StudentEnrollmentView
|
|
|
|
|
{
|
|
|
|
|
public partial class FormCourse : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IFacultyLogic _logicF;
|
|
|
|
|
private readonly ICourseLogic _logicC;
|
|
|
|
|
private int? _id;
|
|
|
|
|
public int Id { set { _id = value; } }
|
|
|
|
|
public FormCourse(ILogger<FormCourse> logger, IFacultyLogic logicF, ICourseLogic logicC)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logicF = logicF;
|
|
|
|
|
_logicC = logicC;
|
|
|
|
|
}
|
|
|
|
|
private void FormCourse_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Загрузка факультетов для направления");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var _list = _logicF.ReadList(null);
|
|
|
|
|
if (_list != null)
|
|
|
|
|
{
|
|
|
|
|
comboBoxFaculty.DisplayMember = "FacultyName";
|
|
|
|
|
comboBoxFaculty.ValueMember = "Id";
|
|
|
|
|
comboBoxFaculty.DataSource = _list;
|
|
|
|
|
comboBoxFaculty.SelectedItem = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки факультетов для направления");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(textBoxName.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Заполните поле название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (comboBoxFaculty.SelectedValue == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите факультет", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Создание направления");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var operationResult = _logicC.Create(new CourseBindingModel
|
|
|
|
|
{
|
2024-05-07 23:34:50 +04:00
|
|
|
|
course_id = _id ?? 0,
|
|
|
|
|
name = textBoxName.Text,
|
|
|
|
|
facultyid = Convert.ToInt32(comboBoxFaculty.SelectedValue)
|
2024-05-06 20:26:16 +04:00
|
|
|
|
});
|
|
|
|
|
if (!operationResult)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Ошибка при создании направления. Дополнительная информация в логах.");
|
|
|
|
|
}
|
|
|
|
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка создания направления");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|