лаба4
This commit is contained in:
parent
afbdd5205d
commit
c0fb5a6878
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,8 +10,8 @@ namespace ProjectRepairWork.Entities;
|
|||||||
public class BuildingMaterials
|
public class BuildingMaterials
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[DisplayName("Название материала")]
|
||||||
public string MaterialsType { get; private set; } = string.Empty;
|
public string MaterialsType { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public static BuildingMaterials CreatEntity(int id, string materialType)
|
public static BuildingMaterials CreatEntity(int id, string materialType)
|
||||||
{
|
{
|
||||||
return new BuildingMaterials
|
return new BuildingMaterials
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using ProjectRepairWork.Entities.Enums;
|
using ProjectRepairWork.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -10,7 +11,10 @@ namespace ProjectRepairWork.Entities;
|
|||||||
public class Contractors
|
public class Contractors
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[DisplayName("Название компании")]
|
||||||
public string CompanyName { get; private set; } = string.Empty;
|
public string CompanyName { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Контакты")]
|
||||||
public string Contacts { get; private set; } = string.Empty;
|
public string Contacts { get; private set; } = string.Empty;
|
||||||
public static Contractors CreatEntity(int id, string companyName, string contants)
|
public static Contractors CreatEntity(int id, string companyName, string contants)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -8,6 +9,7 @@ namespace ProjectRepairWork.Entities;
|
|||||||
public class Cost
|
public class Cost
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[DisplayName("Цена")]
|
||||||
public int Price { get; private set; }
|
public int Price { get; private set; }
|
||||||
public static Cost CreatEntity(int id, int price)
|
public static Cost CreatEntity(int id, int price)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,17 +10,20 @@ namespace ProjectRepairWork.Entities;
|
|||||||
public class MaterialProcurement
|
public class MaterialProcurement
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[Browsable(false)]
|
||||||
public int MaterialsId { get; private set; }
|
public int MaterialsId { get; private set; }
|
||||||
|
[DisplayName("Дата закупки")]
|
||||||
public DateTime ProcurmentDate { get; private set; }
|
public DateTime ProcurmentDate { get; private set; }
|
||||||
|
[DisplayName("Сумма закупки")]
|
||||||
public int MaterialsPrice { get; private set; }
|
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
|
return new MaterialProcurement
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
MaterialsId = materialsId,
|
MaterialsId = materialsId,
|
||||||
ProcurmentDate = DateTime.Now,
|
ProcurmentDate = procurmentDate,
|
||||||
MaterialsPrice = materialsPrice,
|
MaterialsPrice = materialsPrice,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using ProjectRepairWork.Entities.Enums;
|
using ProjectRepairWork.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,11 +10,17 @@ namespace ProjectRepairWork.Entities;
|
|||||||
public class Premises
|
public class Premises
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[DisplayName("Клиент")]
|
||||||
public string ClientName { get; private set; } = string.Empty;
|
public string ClientName { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Адрес")]
|
||||||
public string Address { get; private set; } = string.Empty;
|
public string Address { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Площадь")]
|
||||||
public int Area { get; private set; }
|
public int Area { get; private set; }
|
||||||
|
[DisplayName("Тип помещения")]
|
||||||
public PremisesType PremisesType { get; private set; }
|
public PremisesType PremisesType { get; private set; }
|
||||||
|
[DisplayName("Дата начала")]
|
||||||
public DateTime DateStart { get; private set; }
|
public DateTime DateStart { get; private set; }
|
||||||
|
[DisplayName("Дата конца")]
|
||||||
public DateTime DateEnd { get; private set; }
|
public DateTime DateEnd { get; private set; }
|
||||||
public static Premises CreatEntity(int id, string clientName, string address, int area, DateTime dateStart, DateTime dateEnd, PremisesType premisesType)
|
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.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,12 +11,26 @@ namespace ProjectRepairWork.Entities;
|
|||||||
public class Repair
|
public class Repair
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[Browsable(false)]
|
||||||
public int ContractorsId { get; private set; }
|
public int ContractorsId { get; private set; }
|
||||||
|
[Browsable(false)]
|
||||||
public int PremisesId { get; private set; }
|
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 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)
|
public static Repair CreatOpertions(int id, int contractorsId, DateTime dateRepair, int premisesId, IEnumerable<RepairRepair> repairRepair)
|
||||||
@ -25,9 +41,16 @@ public class Repair
|
|||||||
ContractorsId = contractorsId,
|
ContractorsId = contractorsId,
|
||||||
PremisesId = premisesId,
|
PremisesId = premisesId,
|
||||||
DateRepair = dateRepair,
|
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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -10,6 +11,9 @@ public class RepairRepair
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public int WorkId { get; private set; }
|
public int WorkId { get; private set; }
|
||||||
|
[DisplayName("Работы")]
|
||||||
|
public string WorkName { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Количество")]
|
||||||
public int Count { get; set; }
|
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 ProjectRepairWork.Entities.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -10,7 +11,9 @@ namespace ProjectRepairWork.Entities;
|
|||||||
public class Works
|
public class Works
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
[DisplayName("Вид работ")]
|
||||||
public string WorkName { get; private set; } = string.Empty;
|
public string WorkName { get; private set; } = string.Empty;
|
||||||
|
[DisplayName("Название материалов")]
|
||||||
public MaterialsName MaterialsName { get; private set; }
|
public MaterialsName MaterialsName { get; private set; }
|
||||||
public static Works CreatEntity(int id, string workName, MaterialsName materialsName)
|
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.ShortcutKeys = Keys.Control | Keys.W;
|
||||||
directoryReportToolStripMenuItem.Size = new Size(346, 26);
|
directoryReportToolStripMenuItem.Size = new Size(346, 26);
|
||||||
directoryReportToolStripMenuItem.Text = "Документ со справочником ";
|
directoryReportToolStripMenuItem.Text = "Документ со справочником ";
|
||||||
directoryReportToolStripMenuItem.Click += directoryReportToolStripMenuItem_Click;
|
directoryReportToolStripMenuItem.Click += DirectoryReportToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// ContractorReportToolStripMenuItem
|
// ContractorReportToolStripMenuItem
|
||||||
//
|
//
|
||||||
|
@ -73,7 +73,7 @@ namespace ProjectRepairWork
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void directoryReportToolStripMenuItem_Click(object sender, EventArgs e)
|
private void DirectoryReportToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
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)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
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)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
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)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -38,7 +38,7 @@ public partial class FormMaterialProcurement : Form
|
|||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
|
|
||||||
_materialProcurementRepository.CreateMaterialProcurement(MaterialProcurement.CreatOpertions(0,
|
_materialProcurementRepository.CreateMaterialProcurement(MaterialProcurement.CreatOpertions(0,dateTimePickerMaterialRrocurement.Value,
|
||||||
(int)comboBoxMaterialRrocurement.SelectedValue!, (int)numericUpDownMaterialRrocurement.Value!));
|
(int)comboBoxMaterialRrocurement.SelectedValue!, (int)numericUpDownMaterialRrocurement.Value!));
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
|
@ -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)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
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)
|
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)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -28,7 +28,7 @@ public class ChartReport
|
|||||||
{
|
{
|
||||||
new PdfBuilder(filePath)
|
new PdfBuilder(filePath)
|
||||||
.AddHeader("Поступление материалов")
|
.AddHeader("Поступление материалов")
|
||||||
.AddPieChart("Виды материала", GetData(dateTime))
|
.AddPieChart($"Виды материалов на {dateTime: dd MMMM yyyy}", GetData(dateTime))
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ using ProjectRepairWork.Entities;
|
|||||||
|
|
||||||
namespace ProjectRepairWork.Reports;
|
namespace ProjectRepairWork.Reports;
|
||||||
|
|
||||||
internal class TableReport
|
public class TableReport
|
||||||
{
|
{
|
||||||
private readonly IRepairRepository _repairRepository;
|
private readonly IRepairRepository _repairRepository;
|
||||||
private readonly IWorksRepository _worksRepository;
|
private readonly IWorksRepository _worksRepository;
|
||||||
@ -32,7 +32,7 @@ internal class TableReport
|
|||||||
var data = GetData(contractorsId, startDate, endDate);
|
var data = GetData(contractorsId, startDate, endDate);
|
||||||
new ExcelBuilder(filePath)
|
new ExcelBuilder(filePath)
|
||||||
.AddHeader("Сводка по подрядчикам", 0, 3)
|
.AddHeader("Сводка по подрядчикам", 0, 3)
|
||||||
.AddParagraph("за период", 0)
|
.AddParagraph($"за период, c {startDate: dd.MM.yyyy} по {endDate: dd.MM.yyyy} ", 0)
|
||||||
.AddTable(new int[] { 10, 15, 15 }, data)
|
.AddTable(new int[] { 10, 15, 15 }, data)
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
@ -81,7 +81,7 @@ internal class TableReport
|
|||||||
.Union(
|
.Union(
|
||||||
groupedData
|
groupedData
|
||||||
.Select(x => new string[] {
|
.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(
|
.Union(
|
||||||
new List<string[]>() { new string[] { "Всего", "", totalQuantity.ToString() } })
|
new List<string[]>() { new string[] { "Всего", "", totalQuantity.ToString() } })
|
||||||
|
@ -9,7 +9,8 @@ namespace ProjectRepairWork.Repositories;
|
|||||||
|
|
||||||
public interface IMaterialProcurementRepository
|
public interface IMaterialProcurementRepository
|
||||||
{
|
{
|
||||||
IEnumerable<MaterialProcurement> ReadMaterialProcurement();
|
IEnumerable<MaterialProcurement> ReadMaterialProcurement(DateTime? dateForm = null,
|
||||||
|
DateTime? dateTo = null, int? materialsId = null);
|
||||||
MaterialProcurement ReadMaterialProcurementById(int id);
|
MaterialProcurement ReadMaterialProcurementById(int id);
|
||||||
void CreateMaterialProcurement(MaterialProcurement materialProcurement);
|
void CreateMaterialProcurement(MaterialProcurement materialProcurement);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace ProjectRepairWork.Repositories;
|
|||||||
|
|
||||||
public interface IRepairRepository
|
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();
|
IEnumerable<RepairRepair> ReadRepairRepair();
|
||||||
void CraeteRepair(Repair repair);
|
void CraeteRepair(Repair repair);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ProjectRepairWork.Repositories.Implementation;
|
namespace ProjectRepairWork.Repositories.Implementation;
|
||||||
|
|
||||||
@ -65,15 +66,37 @@ public class MaterialProcurementRepository : IMaterialProcurementRepository
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public IEnumerable<MaterialProcurement> ReadMaterialProcurement()
|
public IEnumerable<MaterialProcurement> ReadMaterialProcurement(DateTime? dateForm = null,
|
||||||
|
DateTime? dateTo = null, int? materialsId = null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
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
|
using var connection = new
|
||||||
NpgsqlConnection(_connectionString.ConnectionString);
|
NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = "SELECT * FROM MaterialProcurement";
|
var querySelect = $@"
|
||||||
var materialProcurement = connection.Query<MaterialProcurement>(querySelect);
|
SELECT
|
||||||
|
mp.*,
|
||||||
|
bm.MaterialsType as MaterialsName
|
||||||
|
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}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
JsonConvert.SerializeObject(materialProcurement));
|
JsonConvert.SerializeObject(materialProcurement));
|
||||||
return 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.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
||||||
namespace ProjectRepairWork.Repositories.Implementation;
|
namespace ProjectRepairWork.Repositories.Implementation;
|
||||||
|
|
||||||
@ -34,18 +35,18 @@ public class RepairRepository : IRepairRepository
|
|||||||
using var transaction = connection.BeginTransaction();
|
using var transaction = connection.BeginTransaction();
|
||||||
var queryInsert = @"
|
var queryInsert = @"
|
||||||
INSERT INTO Repair (ContractorsId, PremisesId, DateRepair)
|
INSERT INTO Repair (ContractorsId, PremisesId, DateRepair)
|
||||||
VALUES (@ContractorsId, @PremisesId, @DateRepair);
|
VALUES (@ContractorsId, @PremisesId, @DateRepair)
|
||||||
SELECT MAX(Id) FROM Repair";
|
RETURNING Id;";
|
||||||
var repairId =
|
var repairId =
|
||||||
connection.QueryFirst<int>(queryInsert, repair, transaction);
|
connection.QueryFirst<int>(queryInsert, repair, transaction);
|
||||||
var querySubInsert = @"
|
var querySubInsert = @"
|
||||||
INSERT INTO RepairRepair (RepairId, WorkId, Count)
|
INSERT INTO RepairRepair (RepairId, WorkId, Count)
|
||||||
VALUES (@RepairId, @WorkId, @Count)";
|
VALUES (@RepairId, @WorkId, @Count)";
|
||||||
foreach (var elem in repair.RepairRepair)
|
foreach (var elem in repair.RepairRepairList)
|
||||||
{
|
{
|
||||||
connection.Execute(querySubInsert, new
|
connection.Execute(querySubInsert, new
|
||||||
{
|
{
|
||||||
repairId,
|
RepairId = repairId,
|
||||||
elem.WorkId,
|
elem.WorkId,
|
||||||
elem.Count
|
elem.Count
|
||||||
}, transaction);
|
}, 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("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
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);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = "SELECT * FROM Repair";
|
var querySelect = $@"
|
||||||
var repair = connection.Query<Repair>(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}",
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
JsonConvert.SerializeObject(repair));
|
JsonConvert.SerializeObject(repair));
|
||||||
return repair;
|
return repair;
|
||||||
|
Loading…
Reference in New Issue
Block a user