2 лаба готова
This commit is contained in:
parent
b35480e955
commit
0f718e3c87
@ -76,7 +76,7 @@ namespace ProjectPolyclinic.Forms
|
||||
var list = new List<Medicines_Visiting>();
|
||||
foreach (DataGridViewRow row in dataGridViewMedicines.Rows)
|
||||
{
|
||||
if (row.Cells["ColumnFeed"].Value == null ||
|
||||
if (row.Cells["ColumnMedicines"].Value == null ||
|
||||
row.Cells["ColumnCount"].Value == null)
|
||||
{
|
||||
continue;
|
||||
|
@ -1,4 +1,8 @@
|
||||
using ProjectPolyclinic.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectPolyclinic.Entities;
|
||||
using ProjectPolyclinic.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -8,27 +12,108 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectPolyclinic.Repositories.Implementations
|
||||
{
|
||||
internal class DoctorRepository:IDoctorRepository
|
||||
public class DoctorRepository:IDoctorRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<DoctorRepository> _logger;
|
||||
public DoctorRepository(IConnectionString connectionString, ILogger<DoctorRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateDoctor(Doctor doctor)
|
||||
{
|
||||
|
||||
}
|
||||
public void DeleteDoctor(int id)
|
||||
{
|
||||
|
||||
}
|
||||
public Doctor ReadDoctorById(int id)
|
||||
{
|
||||
return Doctor.CreateEntity(0, string.Empty, string.Empty, Specialization.None);
|
||||
}
|
||||
public IEnumerable<Doctor> ReadDoctors()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(doctor));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"INSERT INTO Doctors (First_Name, Last_Name, Specialization)
|
||||
VALUES (@First_Name, @Last_Name, @Specialization)";
|
||||
connection.Execute(queryInsert, doctor);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void UpdateDoctor(Doctor doctor)
|
||||
{
|
||||
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(doctor));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"UPDATE Doctors SET
|
||||
First_Name = @First_Name,
|
||||
Last_Name = @Last_Name,
|
||||
Specialization= @Specialization
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryUpdate, doctor);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void DeleteDoctor(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"DELETE FROM Doctors WHERE ID=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public Doctor ReadDoctorById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM Doctors WHERE Id=@id";
|
||||
var doctor = connection.QueryFirst<Doctor>(querySelect, new
|
||||
{
|
||||
id
|
||||
});
|
||||
_logger.LogDebug("Найденный объект: {json}",
|
||||
JsonConvert.SerializeObject(doctor));
|
||||
return doctor;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public IEnumerable<Doctor> ReadDoctors()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Doctors";
|
||||
var doctors = connection.Query<Doctor>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(doctors));
|
||||
return doctors;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,120 @@
|
||||
using ProjectPolyclinic.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectPolyclinic.Entities;
|
||||
using ProjectPolyclinic.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectPolyclinic.Repositories.Implementations
|
||||
{
|
||||
internal class MedicationRepository:IMedicationRepository
|
||||
public class MedicationRepository:IMedicationRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<MedicationRepository> _logger;
|
||||
public MedicationRepository(IConnectionString connectionString, ILogger<MedicationRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
public void CreateMedication(Medication medication)
|
||||
{
|
||||
|
||||
}
|
||||
public void DeleteMedication(int id)
|
||||
{
|
||||
|
||||
}
|
||||
public Medication ReadMedicationById(int id)
|
||||
{
|
||||
return Medication.CreateEntity(0, MedicinesType.None, string.Empty, string.Empty);
|
||||
}
|
||||
public IEnumerable<Medication> ReadMedication()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(medication));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"INSERT INTO Medicines (MedicinesType, Dosing, Description)
|
||||
VALUES (@MedicinesType, @Dosing, @Description)";
|
||||
connection.Execute(queryInsert, medication);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void UpdateMedication(Medication medication)
|
||||
{
|
||||
|
||||
_logger.LogInformation("Редактирование объекта");
|
||||
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(medication));
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryUpdate = @"UPDATE Medicines SET
|
||||
MedicinesType = @MedicinesType,
|
||||
Dosing = @Dosing,
|
||||
Description= @Description
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryUpdate, medication);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void DeleteMedication(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"DELETE FROM Medicines WHERE ID=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public Medication ReadMedicationById(int id)
|
||||
{
|
||||
_logger.LogInformation("Получение объекта по идентификатору");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM Medicines WHERE Id=@id";
|
||||
var medication = connection.QueryFirst<Medication>(querySelect, new
|
||||
{
|
||||
id
|
||||
});
|
||||
_logger.LogDebug("Найденный объект: {json}",
|
||||
JsonConvert.SerializeObject(medication));
|
||||
return medication;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public IEnumerable<Medication> ReadMedication()
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Medicines";
|
||||
var medicines = connection.Query<Medication>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(medicines));
|
||||
return medicines;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,9 @@
|
||||
using ProjectPolyclinic.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectPolyclinic.Entities;
|
||||
using Serilog.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -7,15 +12,56 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectPolyclinic.Repositories.Implementations
|
||||
{
|
||||
internal class ProfessionalDevelopmentRepository:IProfessionalDevelopmentRepository
|
||||
public class ProfessionalDevelopmentRepository:IProfessionalDevelopmentRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<ProfessionalDevelopmentRepository> _logger;
|
||||
public ProfessionalDevelopmentRepository(IConnectionString connectionString,ILogger<ProfessionalDevelopmentRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateProfessionalDevelopment(ProfessionalDevelopment professionalDevelopment)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}",
|
||||
JsonConvert.SerializeObject(professionalDevelopment));
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryInsert = @"
|
||||
INSERT INTO ProfessionalDevelopments (DoctorId, ProfessionalDevelopmentTime)
|
||||
VALUES (@DoctorId, @ProfessionalDevelopmentTime)";
|
||||
connection.Execute(queryInsert, professionalDevelopment);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ProfessionalDevelopment> ReadProfessionalDevelopment(DateTime? dateForm = null, DateTime? dateTo = null, int? doctorId = null, int? Id = null)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM ProfessionalDevelopments";
|
||||
var professionalDevelopments =
|
||||
connection.Query<ProfessionalDevelopment>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(professionalDevelopments));
|
||||
return professionalDevelopments;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,9 @@
|
||||
using ProjectPolyclinic.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectPolyclinic.Entities;
|
||||
using Serilog.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -7,19 +12,94 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectPolyclinic.Repositories.Implementations
|
||||
{
|
||||
internal class VisitingRepository:IVisitingRepository
|
||||
public class VisitingRepository:IVisitingRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<VisitingRepository> _logger;
|
||||
|
||||
public VisitingRepository(IConnectionString connectionString,ILogger<VisitingRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void CreateVisiting(Visiting visiting)
|
||||
{
|
||||
_logger.LogInformation("Добавление объекта");
|
||||
_logger.LogDebug("Объект: {json}",
|
||||
JsonConvert.SerializeObject(visiting));
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO Visitings (DoctorId, PatientId,DiagnosisName,VisitingTime)
|
||||
VALUES (@DoctorId, @PatientId, @DiagnosisName,@VisitingTime );
|
||||
SELECT MAX(Id) FROM Visitings";
|
||||
var visitingId = connection.QueryFirst<int>(queryInsert, visiting, transaction);
|
||||
var querySubInsert = @"
|
||||
INSERT INTO Medicines_Visiting (MedicinesId, VisitingId, Count)
|
||||
VALUES (@MedicinesId,@VisitingId, @Count)";
|
||||
foreach (var elem in visiting.Medicines)
|
||||
{
|
||||
connection.Execute(querySubInsert, new
|
||||
{
|
||||
visitingId,
|
||||
elem.MedicinesId,
|
||||
elem.Count
|
||||
}, transaction);
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void DeleteVisiting(int id)
|
||||
{
|
||||
_logger.LogInformation("Удаление объекта");
|
||||
_logger.LogDebug("Объект: {id}", id);
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var queryDelete = @"
|
||||
DELETE FROM Visitings
|
||||
WHERE Id=@id";
|
||||
connection.Execute(queryDelete, new { id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Visiting> ReadVisiting(DateTime? dateForm = null, DateTime? dateTo = null, int? patientId = null, int? doctorId = null,int ? visitingId = null)
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT * FROM Visitings";
|
||||
var visitings =
|
||||
connection.Query<Visiting>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(visitings));
|
||||
return visitings;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user