2024-05-06 20:26:16 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using StudentEnrollmentContracts.BindingModels;
|
|
|
|
|
using StudentEnrollmentContracts.BusinessLogicContracts;
|
|
|
|
|
|
|
|
|
|
namespace StudentEnrollmentView
|
|
|
|
|
{
|
|
|
|
|
public partial class FormCourses : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly ICourseLogic _logic;
|
|
|
|
|
public FormCourses(ILogger<FormCourses> logger, ICourseLogic logic)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
|
|
|
|
}
|
|
|
|
|
private void FormCourses_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _logic.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
dataGridView.DataSource = list;
|
2024-05-08 09:52:33 +04:00
|
|
|
|
dataGridView.Columns["course_id"].Visible = false;
|
|
|
|
|
dataGridView.Columns["facultyid"].Visible = false;
|
2024-05-06 20:26:16 +04:00
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Загрузка направлений");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки направлений");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormCourse));
|
|
|
|
|
if (service is FormCourse form)
|
|
|
|
|
{
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormCourse));
|
|
|
|
|
if (service is FormCourse form)
|
|
|
|
|
{
|
|
|
|
|
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonDel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
if (MessageBox.Show("Удалить запись?", "Вопрос",
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
2024-05-08 09:52:33 +04:00
|
|
|
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["course_id"].Value);
|
2024-05-06 20:26:16 +04:00
|
|
|
|
_logger.LogInformation("Удаление направления");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!_logic.Delete(new CourseBindingModel
|
|
|
|
|
{
|
2024-05-07 23:34:50 +04:00
|
|
|
|
course_id = id
|
2024-05-06 20:26:16 +04:00
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
|
|
|
|
}
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления направления");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonRef_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|