From a8247cf8f78d635f112ae84e39b1d1ecc4d6a00c Mon Sep 17 00:00:00 2001 From: funa4i Date: Tue, 19 Nov 2024 16:02:24 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D0=B5=D1=87=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormsEntity/FormStatement.Designer.cs | 1 + .../Forms/FormsEntity/FormStatement.cs | 2 +- .../RepositoryImp/SubjectRepository.cs | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/StudentProgressRecord/Forms/FormsEntity/FormStatement.Designer.cs b/StudentProgressRecord/Forms/FormsEntity/FormStatement.Designer.cs index 305fd83..3cdd1f2 100644 --- a/StudentProgressRecord/Forms/FormsEntity/FormStatement.Designer.cs +++ b/StudentProgressRecord/Forms/FormsEntity/FormStatement.Designer.cs @@ -61,6 +61,7 @@ // // dateTimePicker // + dateTimePicker.Enabled = false; dateTimePicker.Location = new Point(13, 163); dateTimePicker.Name = "dateTimePicker"; dateTimePicker.Size = new Size(250, 27); diff --git a/StudentProgressRecord/Forms/FormsEntity/FormStatement.cs b/StudentProgressRecord/Forms/FormsEntity/FormStatement.cs index e52dd98..9ed164a 100644 --- a/StudentProgressRecord/Forms/FormsEntity/FormStatement.cs +++ b/StudentProgressRecord/Forms/FormsEntity/FormStatement.cs @@ -47,7 +47,7 @@ namespace StudentProgressRecord.Forms { try { - if (dataGridView.RowCount < 1 || comboBoxTeacher.SelectedIndex < 0 || comboBoxSubject.SelectedIndex < 0) + if (dataGridView.RowCount < 2 || comboBoxTeacher.SelectedIndex < 0 || comboBoxSubject.SelectedIndex < 0) { throw new Exception("Имеются незаполненые поля"); } diff --git a/StudentProgressRecord/RepositoryImp/SubjectRepository.cs b/StudentProgressRecord/RepositoryImp/SubjectRepository.cs index 399e127..b7487a9 100644 --- a/StudentProgressRecord/RepositoryImp/SubjectRepository.cs +++ b/StudentProgressRecord/RepositoryImp/SubjectRepository.cs @@ -61,7 +61,24 @@ namespace StudentProgressRecord.RepositoryImp public Subject ReadSubjectById(long id) { - return Subject.CreateEntity(0, string.Empty, Direction.None); + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var querySelect = @" + SELECT * FROM Subject + WHERE Id=@id"; + var obj = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", + JsonConvert.SerializeObject(obj)); + return obj; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } public IEnumerable ReadSubjects()