Пибд-21 Абакаров А.А Лабораторная работа 4 #5
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,8 +10,8 @@ namespace ProjectRepairWork.Entities;
|
||||
public class BuildingMaterials
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Название материала")]
|
||||
public string MaterialsType { get; private set; } = string.Empty;
|
||||
|
||||
public static BuildingMaterials CreatEntity(int id, string materialType)
|
||||
{
|
||||
return new BuildingMaterials
|
||||
|
@ -1,6 +1,7 @@
|
||||
using ProjectRepairWork.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -10,7 +11,10 @@ namespace ProjectRepairWork.Entities;
|
||||
public class Contractors
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DisplayName("Название компании")]
|
||||
public string CompanyName { get; private set; } = string.Empty;
|
||||
[DisplayName("Контакты")]
|
||||
public string Contacts { get; private set; } = string.Empty;
|
||||
public static Contractors CreatEntity(int id, string companyName, string contants)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -8,6 +9,7 @@ namespace ProjectRepairWork.Entities;
|
||||
public class Cost
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Цена")]
|
||||
public int Price { get; private set; }
|
||||
public static Cost CreatEntity(int id, int price)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,17 +10,22 @@ namespace ProjectRepairWork.Entities;
|
||||
public class MaterialProcurement
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Browsable(false)]
|
||||
public int MaterialsId { get; private set; }
|
||||
[DisplayName("Материалы")]
|
||||
public string MaterailName { get; private set; } = string.Empty;
|
||||
[DisplayName("Дата закупки")]
|
||||
public DateTime ProcurmentDate { get; private set; }
|
||||
[DisplayName("Сумма закупки")]
|
||||
public int MaterialsPrice { get; private set; }
|
||||
|
||||
public static MaterialProcurement CreatOpertions(int id, int materialsId, int materialsPrice)
|
||||
public static MaterialProcurement CreatOpertions(int id, DateTime procurmentDate, int materialsId, int materialsPrice)
|
||||
{
|
||||
return new MaterialProcurement
|
||||
{
|
||||
Id = id,
|
||||
MaterialsId = materialsId,
|
||||
ProcurmentDate = DateTime.Now,
|
||||
ProcurmentDate = procurmentDate,
|
||||
MaterialsPrice = materialsPrice,
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using ProjectRepairWork.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,11 +10,17 @@ namespace ProjectRepairWork.Entities;
|
||||
public class Premises
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Клиент")]
|
||||
public string ClientName { get; private set; } = string.Empty;
|
||||
[DisplayName("Адрес")]
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
[DisplayName("Площадь")]
|
||||
public int Area { get; private set; }
|
||||
[DisplayName("Тип помещения")]
|
||||
public PremisesType PremisesType { get; private set; }
|
||||
[DisplayName("Дата начала")]
|
||||
public DateTime DateStart { get; private set; }
|
||||
[DisplayName("Дата конца")]
|
||||
public DateTime DateEnd { get; private set; }
|
||||
public static Premises CreatEntity(int id, string clientName, string address, int area, DateTime dateStart, DateTime dateEnd, PremisesType premisesType)
|
||||
{
|
||||
|
@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using ProjectRepairWork.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,12 +11,26 @@ namespace ProjectRepairWork.Entities;
|
||||
public class Repair
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Browsable(false)]
|
||||
public int ContractorsId { get; private set; }
|
||||
[Browsable(false)]
|
||||
public int PremisesId { get; private set; }
|
||||
[DisplayName("Подрядчик")]
|
||||
public string CompanyName { get; private set; } = string.Empty;
|
||||
[Browsable(false)]
|
||||
public int PremisesType { get; private set; }
|
||||
[DisplayName("Помещение")]
|
||||
public string PremisesName => $"{(PremisesType)PremisesType}";
|
||||
|
||||
[DisplayName("Дата ремонта")]
|
||||
public DateTime DateRepair { get; private set; }
|
||||
public IEnumerable<RepairRepair> RepairRepair { get; private set; } = [];
|
||||
public string RepairRepair => RepairRepairList != null ?
|
||||
string.Join(" ,", RepairRepairList.Select(x => $"{x.WorkName} {x.Count}"))
|
||||
: string.Empty;
|
||||
|
||||
[Browsable(false)]
|
||||
public List<RepairRepair> RepairRepairList { get; private set; } = new List<RepairRepair>();
|
||||
|
||||
|
||||
|
||||
public static Repair CreatOpertions(int id, int contractorsId, DateTime dateRepair, int premisesId, IEnumerable<RepairRepair> repairRepair)
|
||||
@ -25,9 +41,16 @@ public class Repair
|
||||
ContractorsId = contractorsId,
|
||||
PremisesId = premisesId,
|
||||
DateRepair = dateRepair,
|
||||
RepairRepair = repairRepair,
|
||||
RepairRepairList = repairRepair.ToList(),
|
||||
|
||||
};
|
||||
}
|
||||
public void SetRepairRepairList(IEnumerable<RepairRepair> repairRepair)
|
||||
{
|
||||
if (repairRepair != null && repairRepair.Any())
|
||||
{
|
||||
RepairRepairList = repairRepair.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -10,6 +11,9 @@ public class RepairRepair
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int WorkId { get; private set; }
|
||||
[DisplayName("Работы")]
|
||||
public string WorkName { get; private set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
|
||||
|
||||
|
@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectRepairWork.Entities;
|
||||
|
||||
public class TempRepairRepair
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int ContractorsId { get; private set; }
|
||||
public int PremisesId { get; private set; }
|
||||
public DateTime DateRepair { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using ProjectRepairWork.Entities.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -10,7 +11,9 @@ namespace ProjectRepairWork.Entities;
|
||||
public class Works
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DisplayName("Вид работ")]
|
||||
public string WorkName { get; private set; } = string.Empty;
|
||||
[DisplayName("Название материалов")]
|
||||
public MaterialsName MaterialsName { get; private set; }
|
||||
public static Works CreatEntity(int id, string workName, MaterialsName materialsName)
|
||||
{
|
||||
|
2
ProjectRepairWork/FormRepairWork.Designer.cs
generated
2
ProjectRepairWork/FormRepairWork.Designer.cs
generated
@ -132,7 +132,7 @@
|
||||
directoryReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.W;
|
||||
directoryReportToolStripMenuItem.Size = new Size(346, 26);
|
||||
directoryReportToolStripMenuItem.Text = "Документ со справочником ";
|
||||
directoryReportToolStripMenuItem.Click += directoryReportToolStripMenuItem_Click;
|
||||
directoryReportToolStripMenuItem.Click += DirectoryReportToolStripMenuItem_Click;
|
||||
//
|
||||
// ContractorReportToolStripMenuItem
|
||||
//
|
||||
|
@ -73,7 +73,7 @@ namespace ProjectRepairWork
|
||||
}
|
||||
}
|
||||
|
||||
private void directoryReportToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
private void DirectoryReportToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -80,7 +80,11 @@ namespace ProjectRepairWork.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _buildingMaterialsRepository.ReadBuildingMaterials();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _buildingMaterialsRepository.ReadBuildingMaterials();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -91,7 +91,11 @@ namespace ProjectRepairWork.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _contractorsRepository.ReadContractors();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _contractorsRepository.ReadContractors();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -79,7 +79,10 @@ namespace ProjectRepairWork.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _costRepository.ReadCost();
|
||||
private void LoadList() {
|
||||
dataGridView.DataSource = _costRepository.ReadCost();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -57,6 +57,7 @@
|
||||
// numericUpDownMaterialRrocurement
|
||||
//
|
||||
numericUpDownMaterialRrocurement.Location = new Point(153, 161);
|
||||
numericUpDownMaterialRrocurement.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
|
||||
numericUpDownMaterialRrocurement.Name = "numericUpDownMaterialRrocurement";
|
||||
numericUpDownMaterialRrocurement.Size = new Size(150, 27);
|
||||
numericUpDownMaterialRrocurement.TabIndex = 2;
|
||||
|
@ -38,7 +38,7 @@ public partial class FormMaterialProcurement : Form
|
||||
throw new Exception("Имеются незаполненные поля");
|
||||
}
|
||||
|
||||
_materialProcurementRepository.CreateMaterialProcurement(MaterialProcurement.CreatOpertions(0,
|
||||
_materialProcurementRepository.CreateMaterialProcurement(MaterialProcurement.CreatOpertions(0,dateTimePickerMaterialRrocurement.Value,
|
||||
(int)comboBoxMaterialRrocurement.SelectedValue!, (int)numericUpDownMaterialRrocurement.Value!));
|
||||
|
||||
Close();
|
||||
|
@ -25,7 +25,12 @@ namespace ProjectRepairWork.Forms
|
||||
}
|
||||
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _materialProcurementRepository.ReadMaterialProcurement();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _materialProcurementRepository.ReadMaterialProcurement();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -12,7 +12,6 @@ namespace ProjectRepairWork.Forms
|
||||
|
||||
public FormMaterialsReport(IUnityContainer container)
|
||||
{
|
||||
InitializeComponent();
|
||||
InitializeComponent();
|
||||
_container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
}
|
||||
|
@ -80,7 +80,10 @@ namespace ProjectRepairWork.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _premisesRepository.ReadPremises();
|
||||
private void LoadList() {
|
||||
dataGridView.DataSource = _premisesRepository.ReadPremises();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -34,7 +34,13 @@ namespace ProjectRepairWork.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _repairRepository.ReadRepair();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource = _repairRepository.ReadRepair();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["RepairRepair"].Visible = false;
|
||||
dataGridView.Columns["DateRepair"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||
}
|
||||
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
@ -92,7 +92,10 @@ namespace ProjectRepairWork.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView.DataSource = _worksRepository.ReadWorks();
|
||||
private void LoadList() {
|
||||
dataGridView.DataSource = _worksRepository.ReadWorks();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
}
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
|
@ -28,7 +28,7 @@ public class ChartReport
|
||||
{
|
||||
new PdfBuilder(filePath)
|
||||
.AddHeader("Поступление материалов")
|
||||
.AddPieChart("Виды материала", GetData(dateTime))
|
||||
.AddPieChart($"Виды материалов на {dateTime: dd MMMM yyyy}", GetData(dateTime))
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ using ProjectRepairWork.Entities;
|
||||
|
||||
namespace ProjectRepairWork.Reports;
|
||||
|
||||
internal class TableReport
|
||||
public class TableReport
|
||||
{
|
||||
private readonly IRepairRepository _repairRepository;
|
||||
private readonly IWorksRepository _worksRepository;
|
||||
@ -32,7 +32,7 @@ internal class TableReport
|
||||
var data = GetData(contractorsId, startDate, endDate);
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader("Сводка по подрядчикам", 0, 3)
|
||||
.AddParagraph("за период", 0)
|
||||
.AddParagraph($"за период, c {startDate: dd.MM.yyyy} по {endDate: dd.MM.yyyy} ", 0)
|
||||
.AddTable(new int[] { 10, 15, 15 }, data)
|
||||
.Build();
|
||||
return true;
|
||||
@ -81,7 +81,7 @@ internal class TableReport
|
||||
.Union(
|
||||
groupedData
|
||||
.Select(x => new string[] {
|
||||
x.WorksName.ToString(), x.Date.ToString(), x.Quantity.ToString()
|
||||
x.WorksName.ToString(), x.Date.ToString() ?? string.Empty, x.Quantity.ToString()?? string.Empty
|
||||
}))
|
||||
.Union(
|
||||
new List<string[]>() { new string[] { "Всего", "", totalQuantity.ToString() } })
|
||||
|
@ -9,7 +9,8 @@ namespace ProjectRepairWork.Repositories;
|
||||
|
||||
public interface IMaterialProcurementRepository
|
||||
{
|
||||
IEnumerable<MaterialProcurement> ReadMaterialProcurement();
|
||||
IEnumerable<MaterialProcurement> ReadMaterialProcurement(DateTime? dateForm = null,
|
||||
DateTime? dateTo = null, int? materialsId = null);
|
||||
MaterialProcurement ReadMaterialProcurementById(int id);
|
||||
void CreateMaterialProcurement(MaterialProcurement materialProcurement);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace ProjectRepairWork.Repositories;
|
||||
|
||||
public interface IRepairRepository
|
||||
{
|
||||
IEnumerable<Repair> ReadRepair(int? contractorsId = null, int? costId = null, int? worksId = null, int? premisesId = null);
|
||||
IEnumerable<Repair> ReadRepair(DateTime? dateForm = null, DateTime? dateTo = null, int? contractorsId = null, int? costId = null, int? worksId = null, int? premisesId = null);
|
||||
IEnumerable<RepairRepair> ReadRepairRepair();
|
||||
void CraeteRepair(Repair repair);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ProjectRepairWork.Repositories.Implementation;
|
||||
|
||||
@ -65,15 +66,38 @@ public class MaterialProcurementRepository : IMaterialProcurementRepository
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public IEnumerable<MaterialProcurement> ReadMaterialProcurement()
|
||||
public IEnumerable<MaterialProcurement> ReadMaterialProcurement(DateTime? dateForm = null,
|
||||
DateTime? dateTo = null, int? materialsId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (dateForm.HasValue)
|
||||
{
|
||||
builder.AddCondition("mp.ProcurmentDate >= @dateForm");
|
||||
}
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("mp.ProcurmentDate <= @dateTo");
|
||||
}
|
||||
if (materialsId.HasValue)
|
||||
{
|
||||
builder.AddCondition("mp.MaterialsId = @materialsId");
|
||||
}
|
||||
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM MaterialProcurement";
|
||||
var materialProcurement = connection.Query<MaterialProcurement>(querySelect);
|
||||
var querySelect = $@"
|
||||
SELECT
|
||||
mp.*,
|
||||
bm.MaterialsType as MaterailName
|
||||
|
||||
FROM MaterialProcurement mp
|
||||
LEFT JOIN BuildingMaterials bm on bm.Id = mp.MaterialsId
|
||||
{builder.Build()}";
|
||||
|
||||
var materialProcurement = connection.Query<MaterialProcurement>(querySelect, new { dateForm, dateTo, materialsId });
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(materialProcurement));
|
||||
return materialProcurement;
|
||||
|
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectRepairWork.Repositories.Implementation;
|
||||
|
||||
public 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}";
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace ProjectRepairWork.Repositories.Implementation;
|
||||
|
||||
@ -34,18 +35,18 @@ public class RepairRepository : IRepairRepository
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"
|
||||
INSERT INTO Repair (ContractorsId, PremisesId, DateRepair)
|
||||
VALUES (@ContractorsId, @PremisesId, @DateRepair);
|
||||
SELECT MAX(Id) FROM Repair";
|
||||
VALUES (@ContractorsId, @PremisesId, @DateRepair)
|
||||
RETURNING Id;";
|
||||
var repairId =
|
||||
connection.QueryFirst<int>(queryInsert, repair, transaction);
|
||||
var querySubInsert = @"
|
||||
INSERT INTO RepairRepair (RepairId, WorkId, Count)
|
||||
VALUES (@RepairId, @WorkId, @Count)";
|
||||
foreach (var elem in repair.RepairRepair)
|
||||
foreach (var elem in repair.RepairRepairList)
|
||||
{
|
||||
connection.Execute(querySubInsert, new
|
||||
{
|
||||
repairId,
|
||||
RepairId = repairId,
|
||||
elem.WorkId,
|
||||
elem.Count
|
||||
}, transaction);
|
||||
@ -59,14 +60,52 @@ public class RepairRepository : IRepairRepository
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Repair> ReadRepair(int? contractorsId = null, int? costId = null, int? worksId = null, int? premisesId = null)
|
||||
public IEnumerable<Repair> ReadRepair(DateTime? dateForm = null, DateTime? dateTo = null, int? contractorsId = null, int? costId = null, int? worksId = null, int? premisesId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (dateForm.HasValue)
|
||||
{
|
||||
builder.AddCondition("r.DateRepair >= @dateForm");
|
||||
}
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("r.DateRepair <= @dateTo");
|
||||
}
|
||||
if (contractorsId.HasValue)
|
||||
{
|
||||
builder.AddCondition("r.ContractorsId = @contractorsId");
|
||||
}
|
||||
if (costId.HasValue)
|
||||
{
|
||||
builder.AddCondition("r.Cost = @costId");
|
||||
}
|
||||
if (worksId.HasValue)
|
||||
{
|
||||
builder.AddCondition("r.WorkId = @worksId");
|
||||
}
|
||||
if (premisesId.HasValue)
|
||||
{
|
||||
builder.AddCondition("r.PremisesId = @premisesId");
|
||||
}
|
||||
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM Repair";
|
||||
var repair = connection.Query<Repair>(querySelect);
|
||||
var querySelect = $@"
|
||||
SELECT
|
||||
r.*,
|
||||
c.CompanyName as CompanyName,
|
||||
p.PremisesType as PremisesType
|
||||
|
||||
FROM Repair r
|
||||
LEFT JOIN Contractors c on c.Id = r.ContractorsId
|
||||
LEFT JOIN RepairRepair rr on rr.Id = r.Id
|
||||
|
||||
LEFT JOIN Premises p on p.Id = r.PremisesId
|
||||
{builder.Build()}";
|
||||
var repair = connection.Query<Repair>(querySelect, new { dateForm, dateTo });
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(repair));
|
||||
return repair;
|
||||
|
Loading…
Reference in New Issue
Block a user