almost done, except customerexecutorreview...
This commit is contained in:
parent
1da0a7d90c
commit
4a12f3b1e4
@ -16,11 +16,11 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|||||||
|
|
||||||
comboBoxContractCustomerId.DataSource = customerRepository.ReadCustomers();
|
comboBoxContractCustomerId.DataSource = customerRepository.ReadCustomers();
|
||||||
comboBoxContractCustomerId.DisplayMember = "Name";
|
comboBoxContractCustomerId.DisplayMember = "Name";
|
||||||
comboBoxContractCustomerId.DisplayMember = "Id";
|
comboBoxContractCustomerId.ValueMember = "Id";
|
||||||
|
|
||||||
comboBoxContractExecutorId.DataSource = executorRepository.ReadExecutors();
|
comboBoxContractExecutorId.DataSource = executorRepository.ReadExecutors();
|
||||||
comboBoxContractExecutorId.DisplayMember = "Name";
|
comboBoxContractExecutorId.DisplayMember = "Name";
|
||||||
comboBoxContractExecutorId.DisplayMember = "Id";
|
comboBoxContractExecutorId.ValueMember = "Id";
|
||||||
|
|
||||||
foreach (var elem in Enum.GetValues(typeof(ContractCategory)))
|
foreach (var elem in Enum.GetValues(typeof(ContractCategory)))
|
||||||
{
|
{
|
||||||
@ -71,10 +71,9 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|||||||
|
|
||||||
foreach (DataGridViewRow row in dataGridViewServices.Rows)
|
foreach (DataGridViewRow row in dataGridViewServices.Rows)
|
||||||
if (!row.IsNewRow)
|
if (!row.IsNewRow)
|
||||||
list.Add(Service.CreateEntity(0, Convert.ToString(row.Cells["Description"].Value)!, 0));
|
list.Add(Service.CreateEntity(0, Convert.ToString(row.Cells["ColumnServiceDescription"].Value)!, 0));
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,15 +11,16 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|||||||
ICustomerRepository customerRepository, IExecutorRepository executorRepository)
|
ICustomerRepository customerRepository, IExecutorRepository executorRepository)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_customerExecutorReviewRepository = customerExecutorReviewRepository ?? throw new ArgumentNullException(nameof(customerExecutorReviewRepository));
|
_customerExecutorReviewRepository = customerExecutorReviewRepository ??
|
||||||
|
throw new ArgumentNullException(nameof(customerExecutorReviewRepository));
|
||||||
|
|
||||||
comboBoxCustomerExecutorReviewCustomerId.DataSource = customerRepository.ReadCustomers();
|
comboBoxCustomerExecutorReviewCustomerId.DataSource = customerRepository.ReadCustomers();
|
||||||
comboBoxCustomerExecutorReviewCustomerId.DisplayMember = "Name";
|
comboBoxCustomerExecutorReviewCustomerId.DisplayMember = "Name";
|
||||||
comboBoxCustomerExecutorReviewCustomerId.DisplayMember = "Id";
|
comboBoxCustomerExecutorReviewCustomerId.ValueMember = "Id";
|
||||||
|
|
||||||
comboBoxCustomerExecutorReviewExecutorId.DataSource = executorRepository.ReadExecutors();
|
comboBoxCustomerExecutorReviewExecutorId.DataSource = executorRepository.ReadExecutors();
|
||||||
comboBoxCustomerExecutorReviewExecutorId.DisplayMember = "Name";
|
comboBoxCustomerExecutorReviewExecutorId.DisplayMember = "Name";
|
||||||
comboBoxCustomerExecutorReviewCustomerId.DisplayMember = "Id";
|
comboBoxCustomerExecutorReviewCustomerId.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonSave_Click(object sender, EventArgs e)
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
@ -33,9 +34,7 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
|
|
||||||
_customerExecutorReviewRepository.CreateCustomerExecutorReview(CustomerExecutorReview.CreateElement(
|
_customerExecutorReviewRepository.CreateCustomerExecutorReview(CreateCustomerExecutorReview(0));
|
||||||
0, (int)comboBoxCustomerExecutorReviewCustomerId.SelectedValue!, (int)comboBoxCustomerExecutorReviewExecutorId.SelectedValue!,
|
|
||||||
richTextBoxCustomerExecutorReviewReview.Text, Convert.ToInt32(numericUpDownCustomerExecutorReviewGrade.Value)));
|
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
@ -46,5 +45,14 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
|
private CustomerExecutorReview CreateCustomerExecutorReview(int id)
|
||||||
|
{
|
||||||
|
return CustomerExecutorReview.CreateElement(
|
||||||
|
id, (int)comboBoxCustomerExecutorReviewCustomerId.SelectedValue!,
|
||||||
|
(int)comboBoxCustomerExecutorReviewExecutorId.SelectedValue!,
|
||||||
|
richTextBoxCustomerExecutorReviewReview.Text,
|
||||||
|
Convert.ToInt32(numericUpDownCustomerExecutorReviewGrade.Value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,12 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
using System.Data.SqlClient;
|
|
||||||
|
|
||||||
namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories.Implementations;
|
namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories.Implementations;
|
||||||
|
|
||||||
public class ContractRepository : IContractRepository
|
public class ContractRepository : IContractRepository
|
||||||
{
|
{
|
||||||
private readonly IConnectionString _connectionString;
|
private readonly IConnectionString _connectionString;
|
||||||
|
|
||||||
private readonly ILogger<ContractRepository> _logger;
|
private readonly ILogger<ContractRepository> _logger;
|
||||||
|
|
||||||
public ContractRepository(IConnectionString connectionString, ILogger<ContractRepository> logger)
|
public ContractRepository(IConnectionString connectionString, ILogger<ContractRepository> logger)
|
||||||
@ -27,10 +25,24 @@ public class ContractRepository : IContractRepository
|
|||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
|
||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO Contracts (CustomerId, ExecutorId, Category, ConclusionDate, Deadline, PaymentAmount)
|
INSERT INTO Contracts (CustomerId, ExecutorId, Category,
|
||||||
VALUES (@CustomerId, @ExecutorId, @Category, @ConclusionDate, @Deadline, @PaymentAmount)";
|
ConclusionDate, Deadline, PaymentAmount)
|
||||||
connection.Execute(queryInsert, contract);
|
VALUES (@CustomerId, @ExecutorId, @Category,
|
||||||
|
@ConclusionDate, @Deadline, @PaymentAmount);
|
||||||
|
SELECT MAX(Id) FROM Contracts;
|
||||||
|
";
|
||||||
|
var contractId = connection.QueryFirst<int>(queryInsert, contract, transaction);
|
||||||
|
|
||||||
|
var querySubInsert = @"
|
||||||
|
INSERT INTO Services (Description, ContractId)
|
||||||
|
VALUES (@Description, @ContractId);
|
||||||
|
";
|
||||||
|
foreach (var elem in contract.Services)
|
||||||
|
connection.Execute(querySubInsert, new { elem.Description, contractId }, transaction);
|
||||||
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -41,16 +53,16 @@ public class ContractRepository : IContractRepository
|
|||||||
|
|
||||||
public void DeleteContract(int id)
|
public void DeleteContract(int id)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Добавление объекта");
|
_logger.LogInformation("Удаление объекта");
|
||||||
_logger.LogDebug("Объект: {id}", id);
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
connection.Open();
|
|
||||||
var queryDelete = @"
|
var queryDelete = @"
|
||||||
DELETE FROM Contracts
|
DELETE FROM Contracts
|
||||||
WHERE Id = @id";
|
WHERE Id = @id
|
||||||
|
";
|
||||||
connection.Execute(queryDelete, new { id });
|
connection.Execute(queryDelete, new { id });
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -67,7 +79,6 @@ public class ContractRepository : IContractRepository
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
connection.Open();
|
|
||||||
var querySelect = @"SELECT * FROM Contracts";
|
var querySelect = @"SELECT * FROM Contracts";
|
||||||
var contracts = connection.Query<Entities.Contract>(querySelect);
|
var contracts = connection.Query<Entities.Contract>(querySelect);
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
using PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
using PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
||||||
|
|
||||||
namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories.Implementations;
|
namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories.Implementations;
|
||||||
@ -8,17 +11,73 @@ public class CustomerExecutorReviewRepository : ICustomerExecutorReviewRepositor
|
|||||||
private readonly IConnectionString _connectionString;
|
private readonly IConnectionString _connectionString;
|
||||||
private readonly ILogger<CustomerExecutorReviewRepository> _logger;
|
private readonly ILogger<CustomerExecutorReviewRepository> _logger;
|
||||||
|
|
||||||
|
public CustomerExecutorReviewRepository(IConnectionString connectionString, ILogger<CustomerExecutorReviewRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateCustomerExecutorReview(CustomerExecutorReview customerContractReview)
|
public void CreateCustomerExecutorReview(CustomerExecutorReview customerContractReview)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(customerContractReview));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO CustomerExecutorReviews (CustomerId, ExecutorId, Review, Grade)
|
||||||
|
VALUES (@CustomerId, @ExecutorId, @Review, @Grade);
|
||||||
|
";
|
||||||
|
connection.Execute(queryInsert, customerContractReview);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomerExecutorReview ReadCustomerExecutorReviewById(int id)
|
public CustomerExecutorReview ReadCustomerExecutorReviewById(int id)
|
||||||
{
|
{
|
||||||
return CustomerExecutorReview.CreateElement(0, 0, 0, string.Empty, 0);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM CustomerExecutorReviews WHERE Id = @Id;
|
||||||
|
";
|
||||||
|
var customerEexcutorReview = connection.QueryFirst<CustomerExecutorReview>(querySelect, new { id });
|
||||||
|
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(customerEexcutorReview));
|
||||||
|
return customerEexcutorReview;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<CustomerExecutorReview> ReadCustomerExecutorReviews(int? customerId = null, int? executorId = null)
|
public IEnumerable<CustomerExecutorReview> ReadCustomerExecutorReviews(int? customerId = null, int? executorId = null)
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM CustomerExecutorReviews;
|
||||||
|
";
|
||||||
|
var customerExecutorReviews = connection.Query<CustomerExecutorReview>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(customerExecutorReviews));
|
||||||
|
return customerExecutorReviews;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
using PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
using PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
||||||
|
|
||||||
namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories.Implementations;
|
namespace PIbd_23_Gutorov_I.A._IT_Company.Repositories.Implementations;
|
||||||
@ -8,25 +11,115 @@ public class ExecutorRepository : IExecutorRepository
|
|||||||
private readonly IConnectionString _connectionString;
|
private readonly IConnectionString _connectionString;
|
||||||
private readonly ILogger<ExecutorRepository> _logger;
|
private readonly ILogger<ExecutorRepository> _logger;
|
||||||
|
|
||||||
|
public ExecutorRepository(IConnectionString connectionString, ILogger<ExecutorRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void CreateExecutor(Executor executor)
|
public void CreateExecutor(Executor executor)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(executor));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO Executors (Name, Post)
|
||||||
|
VALUES (@Name, @Post);
|
||||||
|
";
|
||||||
|
connection.Execute(queryInsert, executor);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteExecutor(int id)
|
public void DeleteExecutor(int id)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM Executors WHERE Id = @Id;
|
||||||
|
";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Executor ReadExecutorById(int id)
|
public Executor ReadExecutorById(int id)
|
||||||
{
|
{
|
||||||
return Executor.CreateEntity(0, string.Empty, Entities.Enums.ExecutorPost.None);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM Executors WHERE Id = @Id;
|
||||||
|
";
|
||||||
|
var executor = connection.QueryFirst<Executor>(querySelect, new { id });
|
||||||
|
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(executor));
|
||||||
|
return executor;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Executor> ReadExecutors()
|
public IEnumerable<Executor> ReadExecutors()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM Executors;
|
||||||
|
";
|
||||||
|
var executors = connection.Query<Executor>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(executors));
|
||||||
|
return executors;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateExecutor(Executor executor)
|
public void UpdateExecutor(Executor executor)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(executor));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE Executors
|
||||||
|
SET Name = @Name, Post = @Post
|
||||||
|
WHERE Id = @Id;
|
||||||
|
";
|
||||||
|
connection.Execute(queryUpdate, executor);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user