Лабораторная работа №4
This commit is contained in:
parent
708e4683a7
commit
1532635fd0
@ -1,13 +1,19 @@
|
||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||
|
||||
public class Client
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Имя")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Юридическая форма")]
|
||||
public string LegalForm { get; private set; } = string.Empty;
|
||||
|
||||
public string FullName => $"{LegalForm} {Name}";
|
||||
|
||||
public static Client CreateEntity(int id, string name, string legalForm)
|
||||
{
|
||||
return new Client
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ISEbd_22_Vasin_E.D._It_Company.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||
|
||||
@ -6,20 +7,36 @@ public class Contract
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
[DisplayName("Заказчик")]
|
||||
public string ClientName { get; private set; } = string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public int ContractorId { get; private set; }
|
||||
|
||||
[DisplayName("Исполнитель")]
|
||||
public string ContractorName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Стоимость")]
|
||||
public int Amount { get; private set; }
|
||||
|
||||
[DisplayName("Дата заключения")]
|
||||
public DateTime StartDate { get; private set; }
|
||||
|
||||
[DisplayName("Дата Завершения")]
|
||||
public DateTime Deadline { get; private set; }
|
||||
|
||||
[DisplayName("Тип контракта")]
|
||||
public ContractType ContractType { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public IEnumerable<ServiceContract> ServiceContracts { get; private set; } = [];
|
||||
|
||||
[DisplayName("Услуги")]
|
||||
public string Service => ServiceContracts != null ? string.Join(", ", ServiceContracts.Select(x => $"{x.ServiceName}")) : string.Empty;
|
||||
|
||||
public static Contract CreateEntity(int id, int clientId, int contractorId, int amount,
|
||||
DateTime deadline, ContractType contractType, IEnumerable<ServiceContract> serviceContracts)
|
||||
{
|
||||
@ -36,18 +53,11 @@ public class Contract
|
||||
};
|
||||
}
|
||||
|
||||
public static Contract CreateEntity(TempServiceContract tempServiceContract, IEnumerable<ServiceContract> serviceContracts)
|
||||
public void SetServiceContracts(IEnumerable<ServiceContract> serviceContracts)
|
||||
{
|
||||
return new Contract
|
||||
if (serviceContracts != null && serviceContracts.Any())
|
||||
{
|
||||
Id = tempServiceContract.Id,
|
||||
ClientId = tempServiceContract.ClientId,
|
||||
ContractorId = tempServiceContract.ContractorId,
|
||||
Amount = tempServiceContract.Amount,
|
||||
StartDate = DateTime.Now,
|
||||
Deadline = tempServiceContract.Deadline,
|
||||
ContractType = tempServiceContract.ContractType,
|
||||
ServiceContracts = serviceContracts
|
||||
};
|
||||
ServiceContracts = serviceContracts;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,19 @@
|
||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||
|
||||
public class Contractor
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Имя")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Фамилия")]
|
||||
public string Surname { get; private set; } = string.Empty;
|
||||
|
||||
public string FullName => $"{Name} {Surname}";
|
||||
|
||||
public static Contractor CreateEntity(int id, string name, string surname)
|
||||
{
|
||||
return new Contractor
|
||||
|
@ -1,13 +1,23 @@
|
||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||
|
||||
public class ContractorVacation
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int ContractorId { get; private set; }
|
||||
|
||||
[DisplayName("Исполнитель")]
|
||||
public string ContractorName { get; private set; } = string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public int VacationId { get; private set; }
|
||||
|
||||
[DisplayName("Даты отпуска")]
|
||||
public string VacationDates { get; private set; } = string.Empty;
|
||||
|
||||
public static ContractorVacation CreateElement(int id, int contractorId, int vacationId)
|
||||
{
|
||||
return new ContractorVacation
|
||||
|
@ -1,9 +1,12 @@
|
||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||
|
||||
public class Service
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Название")]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
public static Service CreateEntity(int id, string name)
|
||||
|
@ -1,11 +1,17 @@
|
||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||
|
||||
public class ServiceContract
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int ServiceId { get; private set; }
|
||||
|
||||
[DisplayName("Название услуги")]
|
||||
public string ServiceName { get; private set; } = string.Empty;
|
||||
|
||||
public static ServiceContract CreateElement(int id, int serviceId)
|
||||
{
|
||||
return new ServiceContract
|
||||
|
@ -1,4 +1,6 @@
|
||||
using ISEbd_22_Vasin_E.D._It_Company.Entities.Enums;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using ISEbd_22_Vasin_E.D._It_Company.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||
|
||||
@ -6,10 +8,15 @@ public class Vacation
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Дата начала")]
|
||||
public DateTime StartDate { get; private set; }
|
||||
|
||||
[DisplayName("Дата конца")]
|
||||
public DateTime EndDate { get; private set; }
|
||||
|
||||
public string DisplayDate => $"{StartDate:dd.MM.yyyy} - {EndDate:dd.MM.yyyy}";
|
||||
|
||||
[DisplayName("Тип отпуска")]
|
||||
public VacationType VacationType { get; private set; }
|
||||
|
||||
public static Vacation CreateEntity(int id, DateTime startDate, DateTime endDate, VacationType vacationType)
|
||||
|
@ -78,7 +78,12 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _clientRepository.ReadClients();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _clientRepository.ReadClients();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["FullName"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -15,11 +15,11 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
||||
_contractRepository = contractRepository ?? throw new ArgumentNullException(nameof(contractRepository));
|
||||
|
||||
comboBoxClient.DataSource = clientRepository.ReadClients();
|
||||
comboBoxClient.DisplayMember = "Name";
|
||||
comboBoxClient.DisplayMember = "FullName";
|
||||
comboBoxClient.ValueMember = "Id";
|
||||
|
||||
comboBoxContractor.DataSource = contractorRepository.ReadContractors();
|
||||
comboBoxContractor.DisplayMember = "Name";
|
||||
comboBoxContractor.DisplayMember = "FullName";
|
||||
comboBoxContractor.ValueMember = "Id";
|
||||
|
||||
ColumnServiceName.DataSource = serviceRepository.ReadServices();
|
||||
|
@ -14,7 +14,7 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
|
||||
comboBoxClientId.DataSource = clientRepository.ReadClients();
|
||||
comboBoxClientId.DisplayMember = "Name";
|
||||
comboBoxClientId.DisplayMember = "FullName";
|
||||
comboBoxClientId.ValueMember = "Id";
|
||||
}
|
||||
|
||||
|
@ -15,18 +15,10 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
||||
throw new ArgumentNullException(nameof(contractorVacationRepository));
|
||||
|
||||
comboBoxContractor.DataSource = contractorRepository.ReadContractors();
|
||||
comboBoxContractor.DisplayMember = "Name";
|
||||
comboBoxContractor.DisplayMember = "FullName";
|
||||
comboBoxContractor.ValueMember = "Id";
|
||||
|
||||
var vacations = vacationRepository.ReadVacations()
|
||||
.Select(v => new
|
||||
{
|
||||
Id = v.Id,
|
||||
DisplayDate =
|
||||
$"{v.StartDate.ToString("dd.MM.yyyy")} - {v.EndDate.ToString("dd.MM.yyyy")}"
|
||||
})
|
||||
.ToList();
|
||||
comboBoxVacation.DataSource = vacations;
|
||||
comboBoxVacation.DataSource = vacationRepository.ReadVacations();
|
||||
comboBoxVacation.DisplayMember = "DisplayDate";
|
||||
comboBoxVacation.ValueMember = "Id";
|
||||
}
|
||||
|
@ -61,7 +61,11 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _contractorVacationRepository.ReadContractorVacations();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _contractorVacationRepository.ReadContractorVacations();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -78,7 +78,12 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _contractorRepository.ReadContractors();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _contractorRepository.ReadContractors();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["FullName"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -41,6 +41,12 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _contractRepository.ReadContracts();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _contractRepository.ReadContracts();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["StartDate"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||
dataGridViewData.Columns["Deadline"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,11 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _serviceRepository.ReadServices();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _serviceRepository.ReadServices();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -78,7 +78,14 @@ namespace ISEbd_22_Vasin_E.D._It_Company.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewData.DataSource = _vacationRepository.ReadVacations();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridViewData.DataSource = _vacationRepository.ReadVacations();
|
||||
dataGridViewData.Columns["Id"].Visible = false;
|
||||
dataGridViewData.Columns["DisplayDate"].Visible = false;
|
||||
dataGridViewData.Columns["StartDate"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||
dataGridViewData.Columns["EndDate"].DefaultCellStyle.Format = "dd MMMM yyyy";
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -9,10 +9,6 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Forms\odjv2pa0.v01~" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.2.0" />
|
||||
|
@ -23,7 +23,7 @@ internal class ChartReport
|
||||
{
|
||||
new PdfBuilder(filePath)
|
||||
.AddHeader("Распределение услуг на исполнителя")
|
||||
.AddPieChart("Услуги", GetData(dateTime))
|
||||
.AddPieChart($"Услуги на {dateTime:dd MMMM yyyy}", GetData(dateTime))
|
||||
.Build();
|
||||
|
||||
return true;
|
||||
@ -38,8 +38,7 @@ internal class ChartReport
|
||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
{
|
||||
return _contractRepository
|
||||
.ReadContracts()
|
||||
.Where(x => x.StartDate.Date == dateTime.Date)
|
||||
.ReadContracts(deadlineFrom: dateTime, deadlineTo: dateTime.AddDays(1))
|
||||
.GroupBy(x => x.ContractorId, (key, group) => new
|
||||
{
|
||||
Id = key,
|
||||
|
@ -25,7 +25,7 @@ internal class TableReport
|
||||
{
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader("Сводка по заключениям контрактов", 0, 4)
|
||||
.AddParagraph("за период", 0)
|
||||
.AddParagraph($"за период с {startDate: dd.MM.yyyy} по {endDate: dd.MM.yyyy}", 0)
|
||||
.AddTable([10, 10, 15, 15], GetData(customerId, startDate, endDate))
|
||||
.Build();
|
||||
|
||||
@ -41,11 +41,8 @@ internal class TableReport
|
||||
private List<string[]> GetData(int clientId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var data = _contractRepository
|
||||
.ReadContracts()
|
||||
.Where(x => x.StartDate >= startDate
|
||||
&& x.StartDate <= endDate
|
||||
&& x.ClientId == clientId)
|
||||
.GroupBy(x => x.StartDate)
|
||||
.ReadContracts(clientId: clientId, startDateFrom: startDate, startDateTo: endDate)
|
||||
.GroupBy(x => x.ContractorId)
|
||||
.Select(x => new
|
||||
{
|
||||
x.First().ContractorId,
|
||||
@ -55,11 +52,8 @@ internal class TableReport
|
||||
})
|
||||
.Union(
|
||||
_contractRepository
|
||||
.ReadContracts()
|
||||
.Where(x => x.Deadline >= startDate
|
||||
&& x.Deadline <= endDate
|
||||
&& x.ClientId == clientId)
|
||||
.GroupBy(x => x.Deadline)
|
||||
.ReadContracts(clientId: clientId, deadlineFrom: startDate, deadlineTo: endDate)
|
||||
.GroupBy(x => x.ContractorId)
|
||||
.Select(x => new
|
||||
{
|
||||
x.First().ContractorId,
|
||||
@ -74,7 +68,7 @@ internal class TableReport
|
||||
return new List<string[]>() { item }
|
||||
.Union(data.Select(x => new string[] {
|
||||
x.ContractorId.ToString(),
|
||||
x.Date.ToString(),
|
||||
x.Date.ToString("dd.MM.yyyy"),
|
||||
x.CountIn?.ToString() ?? string.Empty,
|
||||
x.CountOut?.ToString() ?? string.Empty
|
||||
}))
|
||||
|
@ -65,17 +65,90 @@ VALUES (@ContractId, @ServiceId);
|
||||
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (clientId.HasValue)
|
||||
{
|
||||
builder.AddCondition("c.ClientId = @clientId");
|
||||
}
|
||||
if (contractorId.HasValue)
|
||||
{
|
||||
builder.AddCondition("c.ContractorId = @contractorId");
|
||||
}
|
||||
if (amountFrom.HasValue)
|
||||
{
|
||||
builder.AddCondition("c.Amount >= @amountFrom");
|
||||
}
|
||||
if (amountTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("c.Amount <= @amountTo");
|
||||
}
|
||||
if (startDateFrom.HasValue)
|
||||
{
|
||||
builder.AddCondition("c.StartDate >= @startDateFrom");
|
||||
}
|
||||
if (startDateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("c.StartDate <= @startDateTo");
|
||||
}
|
||||
if (deadlineFrom.HasValue)
|
||||
{
|
||||
builder.AddCondition("c.Deadline >= @deadlineFrom");
|
||||
}
|
||||
if (deadlineTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("c.Deadline <= @deadlineTo");
|
||||
}
|
||||
if (contractType.HasValue)
|
||||
{
|
||||
builder.AddCondition("c.ContractType = @contractType");
|
||||
}
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT c.*, sc.ServiceId
|
||||
var querySelect = @$"
|
||||
SELECT
|
||||
c.*,
|
||||
CONCAT(cl.LegalForm, ' ', cl.Name) as ClientName,
|
||||
CONCAT(co.Name, ' ', co.Surname) as ContractorName,
|
||||
sc.ServiceId,
|
||||
s.Name as ServiceName
|
||||
FROM Contracts c
|
||||
INNER JOIN ServiceContracts sc ON sc.ContractId = c.Id
|
||||
LEFT JOIN Services s ON sc.ServiceId = s.Id
|
||||
LEFT JOIN Clients cl ON c.ClientId = cl.Id
|
||||
LEFT JOIN Contractors co ON c.ContractorId = co.Id
|
||||
{builder.Build()};
|
||||
";
|
||||
var contracts = connection.Query<TempServiceContract>(querySelect);
|
||||
|
||||
var contractsDict = new Dictionary<int, List<ServiceContract>>();
|
||||
|
||||
var contracts = connection.Query<Contract, ServiceContract, Contract>(querySelect, (contract, serviceContract) =>
|
||||
{
|
||||
if (!contractsDict.TryGetValue(contract.Id, out var sc))
|
||||
{
|
||||
sc = [];
|
||||
contractsDict.Add(contract.Id, sc);
|
||||
}
|
||||
|
||||
sc.Add(serviceContract);
|
||||
return contract;
|
||||
}, splitOn: "ServiceId", param: new
|
||||
{
|
||||
clientId,
|
||||
contractorId,
|
||||
amountFrom,
|
||||
amountTo,
|
||||
deadlineFrom,
|
||||
deadlineTo,
|
||||
contractType
|
||||
});
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
||||
return contracts.GroupBy(x => x.Id, y => y, (key, value) =>
|
||||
Contract.CreateEntity(value.First(), value.Select(z =>
|
||||
ServiceContract.CreateElement(0, z.ServiceId)))).ToList();
|
||||
|
||||
return contractsDict.Select(x =>
|
||||
{
|
||||
var c = contracts.First(y => y.Id == x.Key);
|
||||
c.SetServiceContracts(x.Value);
|
||||
return c;
|
||||
}).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Dapper;
|
||||
using ISEbd_22_Vasin_E.D._It_Company.Entities;
|
||||
using ISEbd_22_Vasin_E.D._It_Company.Repositories.Implementations;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
@ -45,11 +46,28 @@ VALUES (@ContractorId, @VacationId);
|
||||
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (contractorId.HasValue)
|
||||
{
|
||||
builder.AddCondition("cv.ContractorId = @contractorId");
|
||||
}
|
||||
if (vacationId.HasValue)
|
||||
{
|
||||
builder.AddCondition("cv.VacationId = @vacationId");
|
||||
}
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"
|
||||
SELECT * FROM ContractorVacations;
|
||||
var querySelect = @$"
|
||||
SELECT
|
||||
cv.*,
|
||||
CONCAT(c.Name, ' ', c.Surname) as ContractorName,
|
||||
CONCAT(TO_CHAR(v.StartDate, 'DD.MM.YYYY'), ' - ', TO_CHAR(v.EndDate, 'DD.MM.YYYY')) as VacationDates
|
||||
FROM ContractorVacations cv
|
||||
LEFT JOIN Contractors c ON c.Id = cv.ContractorId
|
||||
LEFT JOIN Vacations v ON v.Id = cv.VacationId
|
||||
{builder.Build()};
|
||||
";
|
||||
var contractorVacations = connection.Query<ContractorVacation>(querySelect);
|
||||
var contractorVacations = connection.Query<ContractorVacation>(querySelect, new { contractorId, vacationId });
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contractorVacations));
|
||||
return contractorVacations;
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
using System.Text;
|
||||
|
||||
namespace ISEbd_22_Vasin_E.D._It_Company.Repositories.Implementations;
|
||||
|
||||
internal class QueryBuilder
|
||||
{
|
||||
private readonly StringBuilder _builder;
|
||||
|
||||
public QueryBuilder()
|
||||
{
|
||||
_builder = new();
|
||||
}
|
||||
|
||||
public QueryBuilder AddCondition(string condition)
|
||||
{
|
||||
if (_builder.Length > 0)
|
||||
{
|
||||
_builder.Append(" AND ");
|
||||
}
|
||||
|
||||
_builder.Append(condition);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public string Build()
|
||||
{
|
||||
if (_builder.Length == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return $"WHERE {_builder}";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user