Pibd-24 Boyko_M.S. LabWork04 #4
@ -47,22 +47,20 @@ public class ChartReport
|
||||
{
|
||||
try
|
||||
{
|
||||
var advocateEarnings = _caseRepository
|
||||
.ReadCases()
|
||||
.Where(x => x.CreatedAt.Date <= dateTime.Date)
|
||||
.Join(_caseAdvocateRepository.ReadCaseAdvocates().Where(x => x.CreatedAt.Date <= dateTime.Date),
|
||||
caseItem => caseItem.Id,
|
||||
caseAdvocate => caseAdvocate.CaseId,
|
||||
(caseItem, caseAdvocate) => new { caseItem, caseAdvocate })
|
||||
.GroupBy(x => x.caseAdvocate.AdvocateId, (key, group) => new
|
||||
{
|
||||
AdvocateName = _advocateRepository.ReadAdvocateById(key)?.Name ?? "Unknown",
|
||||
Earnings = group.Sum(x => x.caseItem.Payment ? (x.caseItem.Verdict ? x.caseItem.VictoryPrice : x.caseItem.Price) : 0)
|
||||
})
|
||||
.Select(x => (x.AdvocateName, (double)x.Earnings))
|
||||
return _caseAdvocateRepository
|
||||
.ReadCaseAdvocates(dateTo: dateTime.Date.AddDays(1))
|
||||
.Join(_caseRepository.ReadCases(dateTime.Date.AddDays(1)),
|
||||
caseItem => caseItem.CaseId,
|
||||
caseCaseId => caseCaseId.Id,
|
||||
(caseItem, caseCase) => new
|
||||
{
|
||||
caseItem.AdvocateName, caseCase.Payment, caseCase.Verdict, caseCase.Price, caseCase.VictoryPrice
|
||||
})
|
||||
.GroupBy(x => x.AdvocateName)
|
||||
.Select(g => (g.Key,
|
||||
Sum: g.Sum(x =>
|
||||
x.Payment ? (x.Verdict ? (double)(x.Price + x.VictoryPrice) : (double)x.Price) : 0)))
|
||||
.ToList();
|
||||
|
||||
return advocateEarnings;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -33,7 +33,7 @@ internal class TableReport
|
||||
{
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader($"Сводка по делу \"{_caseRepository.ReadCaseById(caseId).Description}\"", 0, 4)
|
||||
.AddParagraph("за период", 0)
|
||||
.AddParagraph($"за период c {startDate:dd.MM.yyyy} по{endDate: dd.MM.yyyy}", 0)
|
||||
.AddTable([10, 10, 15], GetData(caseId, startDate,
|
||||
endDate))
|
||||
.Build();
|
||||
@ -50,6 +50,7 @@ internal class TableReport
|
||||
{
|
||||
var statusData = _statusHistoryRepository
|
||||
.ReadStatusHistories()
|
||||
// .ReadStatusHistories(startDate, endDate, caseId)
|
||||
.Where(x => x.CreatedAt >= startDate && x.CreatedAt <= endDate && x.CaseId == caseId)
|
||||
.GroupBy(x => (x.Status, x.CreatedAt.Date))
|
||||
.Select(x => new
|
||||
@ -65,7 +66,7 @@ internal class TableReport
|
||||
statusData
|
||||
.Select(x => new string[]
|
||||
{
|
||||
x.Status.ToString(), x.Date.ToString(), x.Count.ToString()
|
||||
x.Status.ToString(), x.Date.ToString("dd.MM.yyyy"), x.Count.ToString()
|
||||
}))
|
||||
.Union(
|
||||
[
|
||||
|
@ -6,17 +6,28 @@ namespace ProjectGSM.Entities;
|
||||
public class Advocate
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public bool Sex { get; private set; }
|
||||
public DateTime DateOfBirth { get; private set; }
|
||||
public int Experience { get; private set; }
|
||||
public int CompletedTasks { get; private set; }
|
||||
public int Rating { get; private set; }
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
public string PhoneNumber { get; private set; } = string.Empty;
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
public LicenseType LicenseType { get; private set; }
|
||||
public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
[DisplayName("Имя")] public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пол")] public bool Sex { get; private set; }
|
||||
|
||||
[DisplayName("Дата рождения")] public DateTime DateOfBirth { get; private set; }
|
||||
|
||||
[DisplayName("Опыт")] public int Experience { get; private set; }
|
||||
|
||||
[DisplayName("Выполненные задачи")] public int CompletedTasks { get; private set; }
|
||||
|
||||
[DisplayName("Рейтинг")] public int Rating { get; private set; }
|
||||
|
||||
[DisplayName("Электронная почта")] public string Email { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Номер телефона")] public string PhoneNumber { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Адрес")] public string Address { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Тип лицензии")] public LicenseType LicenseType { get; private set; }
|
||||
|
||||
[DisplayName("Дата создания")] public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
// Конструктор для создания сущности
|
||||
public static Advocate CreateEntity(
|
||||
@ -47,4 +58,4 @@ public class Advocate
|
||||
CreatedAt = DateTime.UtcNow
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json.Serialization;
|
||||
using ProjectGSM.Entities.Enums;
|
||||
|
||||
namespace ProjectGSM.Entities;
|
||||
@ -6,16 +7,41 @@ namespace ProjectGSM.Entities;
|
||||
public class Case
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public TypeAppeal TypeAppeal { get; private set; }
|
||||
public bool Payment { get; private set; } = false;
|
||||
public decimal Price { get; private set; }
|
||||
public decimal VictoryPrice { get; private set; }
|
||||
public bool Verdict { get; private set; } = false;
|
||||
public int CourtId { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
public string Description { get; private set; } = string.Empty;
|
||||
public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
||||
[JsonIgnore]public List<CaseAdvocate> Advocates { get; set; }
|
||||
|
||||
[DisplayName("Тип обращения")] public TypeAppeal TypeAppeal { get; private set; }
|
||||
|
||||
[DisplayName("Оплата")] public bool Payment { get; private set; } = false;
|
||||
|
||||
[DisplayName("Цена")] public decimal Price { get; private set; }
|
||||
|
||||
[DisplayName("Цена приговора")] public decimal VictoryPrice { get; private set; }
|
||||
|
||||
[DisplayName("Решение")] public bool Verdict { get; private set; } = false;
|
||||
|
||||
[Browsable(false)] public int CourtId { get; private set; }
|
||||
|
||||
[Browsable(false)] public int ClientId { get; private set; }
|
||||
|
||||
[DisplayName("Суд")] public string CourtName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Клиент")] public string ClientName { get; private set; } = string.Empty;
|
||||
[DisplayName("Описание")] public string Description { get; private set; } = string.Empty;
|
||||
[DisplayName("Дата создания")] public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
|
||||
[JsonIgnore] [Browsable(false)] public IEnumerable<CaseAdvocate> Advocates { get; private set; } = [];
|
||||
|
||||
[DisplayName("Адвокаты")]
|
||||
public string AdvocatesNames => string.Join(", ", Advocates.Select(x => $"{x.AdvocateName} ({x.Post})"));
|
||||
|
||||
public void SetAdvocates(IEnumerable<CaseAdvocate> advocates)
|
||||
{
|
||||
if (advocates != null && advocates.Any())
|
||||
{
|
||||
Advocates = advocates;
|
||||
}
|
||||
}
|
||||
|
||||
// Конструктор для создания сущности
|
||||
public static Case CreateEntity(
|
||||
int id,
|
||||
@ -27,7 +53,7 @@ public class Case
|
||||
int courtId,
|
||||
int clientId,
|
||||
string description
|
||||
)
|
||||
)
|
||||
{
|
||||
return new Case
|
||||
{
|
||||
@ -43,4 +69,4 @@ public class Case
|
||||
CreatedAt = DateTime.UtcNow
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,20 @@
|
||||
namespace ProjectGSM.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectGSM.Entities;
|
||||
|
||||
public class CaseAdvocate
|
||||
{
|
||||
public int CaseId { get; private set; }
|
||||
|
||||
public int AdvocateId { get; private set; }
|
||||
public string Post { get; private set; } = string.Empty;
|
||||
public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
[DisplayName("Дело")] public string CaseDescription { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Авокат")] public string AdvocateName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Должность")] public string Post { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата создания")] public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
// Конструктор для создания сущности
|
||||
public static CaseAdvocate CreateEntity(int caseId, int advocateId, string post)
|
||||
|
@ -1,15 +1,24 @@
|
||||
namespace ProjectGSM.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectGSM.Entities;
|
||||
|
||||
public class Client
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public bool Sex { get; private set; }
|
||||
public DateTime DateOfBirth { get; private set; }
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
public string PhoneNumber { get; private set; } = string.Empty;
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
[DisplayName("Имя")] public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пол")] public bool Sex { get; private set; }
|
||||
|
||||
[DisplayName("Дата рождения")] public DateTime DateOfBirth { get; private set; }
|
||||
|
||||
[DisplayName("Электронная почта")] public string Email { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Номер телефона")] public string PhoneNumber { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Адрес")] public string Address { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата создания")] public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
// Конструктор для создания сущности
|
||||
public static Client CreateEntity(
|
||||
@ -33,4 +42,4 @@ public class Client
|
||||
CreatedAt = DateTime.UtcNow
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,16 @@
|
||||
namespace ProjectGSM.Entities;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ProjectGSM.Entities;
|
||||
|
||||
public class Court
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
[DisplayName("Название")] public string Name { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Адрес")] public string Address { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата создания")] public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
// Конструктор для создания сущности
|
||||
public static Court CreateEntity(int id, string name, string address, DateTime? createdAt = null)
|
||||
@ -18,4 +23,4 @@ public class Court
|
||||
CreatedAt = createdAt ?? DateTime.UtcNow
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,19 @@
|
||||
using ProjectGSM.Entities.Enums;
|
||||
using System.ComponentModel;
|
||||
using ProjectGSM.Entities.Enums;
|
||||
|
||||
namespace ProjectGSM.Entities;
|
||||
|
||||
public class StatusHistory
|
||||
{
|
||||
public int CaseId { get; private set; }
|
||||
public Status Status { get; private set; }
|
||||
public decimal Price { get; private set; }
|
||||
public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
[DisplayName("Дело")] public string CaseDescription { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Статус")] public Status Status { get; private set; }
|
||||
|
||||
[DisplayName("Цена")] public decimal Price { get; private set; }
|
||||
|
||||
[DisplayName("Дата создания")] public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
// Конструктор для создания сущности
|
||||
public static StatusHistory CreateEntity(int caseId, Status status, decimal price, DateTime? dateTime = null)
|
||||
@ -20,4 +26,4 @@ public class StatusHistory
|
||||
CreatedAt = dateTime ?? DateTime.UtcNow
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using ProjectGSM.Forms;
|
||||
using System.ComponentModel;
|
||||
using Unity;
|
||||
|
||||
namespace ProjectGSM
|
||||
|
@ -102,8 +102,13 @@ namespace ProjectGSM.Forms
|
||||
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridViewAdvocats.DataSource =
|
||||
_advocateRepository.ReadAdvocates();
|
||||
private void LoadList() {
|
||||
dataGridViewAdvocats.DataSource =
|
||||
_advocateRepository.ReadAdvocates();
|
||||
dataGridViewAdvocats.Columns["Id"].Visible = false;
|
||||
dataGridViewAdvocats.Columns["CreatedAt"].DefaultCellStyle.Format =
|
||||
"dd.MM.yyyy";
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
|
@ -43,7 +43,7 @@ namespace ProjectGSM.Forms
|
||||
}
|
||||
|
||||
Case caseE = CreateCase(0);
|
||||
caseE.Advocates = CreateListCaseAdvocateFromDataGrid();
|
||||
caseE.SetAdvocates(CreateListCaseAdvocateFromDataGrid());
|
||||
_caseRepository.CreateCase(caseE);
|
||||
Close();
|
||||
}
|
||||
|
44
ProjectGSM/Forms/FormCases.Designer.cs
generated
44
ProjectGSM/Forms/FormCases.Designer.cs
generated
@ -31,9 +31,9 @@
|
||||
panel1 = new Panel();
|
||||
deleteButton = new Button();
|
||||
addButton = new Button();
|
||||
dataGridView1 = new DataGridView();
|
||||
dataGridView = new DataGridView();
|
||||
panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
@ -71,37 +71,37 @@
|
||||
//
|
||||
// dataGridView1
|
||||
//
|
||||
dataGridView1.AllowUserToAddRows = false;
|
||||
dataGridView1.AllowUserToDeleteRows = false;
|
||||
dataGridView1.AllowUserToResizeColumns = false;
|
||||
dataGridView1.AllowUserToResizeRows = false;
|
||||
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridView1.BackgroundColor = SystemColors.Info;
|
||||
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView1.Dock = DockStyle.Fill;
|
||||
dataGridView1.Location = new Point(0, 0);
|
||||
dataGridView1.MultiSelect = false;
|
||||
dataGridView1.Name = "dataGridView1";
|
||||
dataGridView1.ReadOnly = true;
|
||||
dataGridView1.RowHeadersVisible = false;
|
||||
dataGridView1.RowHeadersWidth = 62;
|
||||
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView1.Size = new Size(604, 450);
|
||||
dataGridView1.TabIndex = 1;
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
dataGridView.AllowUserToDeleteRows = false;
|
||||
dataGridView.AllowUserToResizeColumns = false;
|
||||
dataGridView.AllowUserToResizeRows = false;
|
||||
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridView.BackgroundColor = SystemColors.Info;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Dock = DockStyle.Fill;
|
||||
dataGridView.Location = new Point(0, 0);
|
||||
dataGridView.MultiSelect = false;
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.ReadOnly = true;
|
||||
dataGridView.RowHeadersVisible = false;
|
||||
dataGridView.RowHeadersWidth = 62;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(604, 450);
|
||||
dataGridView.TabIndex = 1;
|
||||
//
|
||||
// FormCases
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(746, 450);
|
||||
Controls.Add(dataGridView1);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(panel1);
|
||||
Name = "FormCases";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Дела";
|
||||
Load += FormClients_Load;
|
||||
panel1.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@ -110,6 +110,6 @@
|
||||
private Panel panel1;
|
||||
private Button deleteButton;
|
||||
private Button addButton;
|
||||
private DataGridView dataGridView1;
|
||||
private DataGridView dataGridView;
|
||||
}
|
||||
}
|
@ -81,20 +81,26 @@ namespace ProjectGSM.Forms
|
||||
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView1.DataSource =
|
||||
_caseRepository.ReadCases();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource =
|
||||
_caseRepository.ReadCases();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["CreatedAt"].DefaultCellStyle.Format =
|
||||
"dd.MM.yyyy";
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
if (dataGridView1.SelectedRows.Count < 1)
|
||||
if (dataGridView.SelectedRows.Count < 1)
|
||||
{
|
||||
MessageBox.Show("Нет выбранной записи", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
id =
|
||||
Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value);
|
||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
42
ProjectGSM/Forms/FormClients.Designer.cs
generated
42
ProjectGSM/Forms/FormClients.Designer.cs
generated
@ -32,9 +32,9 @@
|
||||
deleteButton = new Button();
|
||||
editButton = new Button();
|
||||
addButton = new Button();
|
||||
dataGridView1 = new DataGridView();
|
||||
dataGridView = new DataGridView();
|
||||
panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
@ -86,36 +86,36 @@
|
||||
//
|
||||
// dataGridView1
|
||||
//
|
||||
dataGridView1.AllowUserToAddRows = false;
|
||||
dataGridView1.AllowUserToDeleteRows = false;
|
||||
dataGridView1.AllowUserToResizeColumns = false;
|
||||
dataGridView1.AllowUserToResizeRows = false;
|
||||
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridView1.BackgroundColor = SystemColors.Info;
|
||||
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView1.Dock = DockStyle.Fill;
|
||||
dataGridView1.Location = new Point(0, 0);
|
||||
dataGridView1.MultiSelect = false;
|
||||
dataGridView1.Name = "dataGridView1";
|
||||
dataGridView1.ReadOnly = true;
|
||||
dataGridView1.RowHeadersVisible = false;
|
||||
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView1.Size = new Size(604, 450);
|
||||
dataGridView1.TabIndex = 1;
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
dataGridView.AllowUserToDeleteRows = false;
|
||||
dataGridView.AllowUserToResizeColumns = false;
|
||||
dataGridView.AllowUserToResizeRows = false;
|
||||
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridView.BackgroundColor = SystemColors.Info;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Dock = DockStyle.Fill;
|
||||
dataGridView.Location = new Point(0, 0);
|
||||
dataGridView.MultiSelect = false;
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.ReadOnly = true;
|
||||
dataGridView.RowHeadersVisible = false;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(604, 450);
|
||||
dataGridView.TabIndex = 1;
|
||||
//
|
||||
// FormClients
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(746, 450);
|
||||
Controls.Add(dataGridView1);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(panel1);
|
||||
Name = "FormClients";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Клиенты";
|
||||
Load += FormClients_Load;
|
||||
panel1.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@ -125,6 +125,6 @@
|
||||
private Button deleteButton;
|
||||
private Button editButton;
|
||||
private Button addButton;
|
||||
private DataGridView dataGridView1;
|
||||
private DataGridView dataGridView;
|
||||
}
|
||||
}
|
@ -102,20 +102,25 @@ namespace ProjectGSM.Forms
|
||||
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView1.DataSource =
|
||||
_clientRepository.ReadClients();
|
||||
private void LoadList() {
|
||||
dataGridView.DataSource =
|
||||
_clientRepository.ReadClients();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["CreatedAt"].DefaultCellStyle.Format =
|
||||
"dd.MM.yyyy";
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
if (dataGridView1.SelectedRows.Count < 1)
|
||||
if (dataGridView.SelectedRows.Count < 1)
|
||||
{
|
||||
MessageBox.Show("Нет выбранной записи", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
id =
|
||||
Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value);
|
||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
42
ProjectGSM/Forms/FormCourts.Designer.cs
generated
42
ProjectGSM/Forms/FormCourts.Designer.cs
generated
@ -32,9 +32,9 @@
|
||||
deleteButton = new Button();
|
||||
editButton = new Button();
|
||||
addButton = new Button();
|
||||
dataGridView1 = new DataGridView();
|
||||
dataGridView = new DataGridView();
|
||||
panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
@ -86,36 +86,36 @@
|
||||
//
|
||||
// dataGridView1
|
||||
//
|
||||
dataGridView1.AllowUserToAddRows = false;
|
||||
dataGridView1.AllowUserToDeleteRows = false;
|
||||
dataGridView1.AllowUserToResizeColumns = false;
|
||||
dataGridView1.AllowUserToResizeRows = false;
|
||||
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridView1.BackgroundColor = SystemColors.Info;
|
||||
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView1.Dock = DockStyle.Fill;
|
||||
dataGridView1.Location = new Point(0, 0);
|
||||
dataGridView1.MultiSelect = false;
|
||||
dataGridView1.Name = "dataGridView1";
|
||||
dataGridView1.ReadOnly = true;
|
||||
dataGridView1.RowHeadersVisible = false;
|
||||
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView1.Size = new Size(604, 450);
|
||||
dataGridView1.TabIndex = 1;
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
dataGridView.AllowUserToDeleteRows = false;
|
||||
dataGridView.AllowUserToResizeColumns = false;
|
||||
dataGridView.AllowUserToResizeRows = false;
|
||||
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridView.BackgroundColor = SystemColors.Info;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Dock = DockStyle.Fill;
|
||||
dataGridView.Location = new Point(0, 0);
|
||||
dataGridView.MultiSelect = false;
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.ReadOnly = true;
|
||||
dataGridView.RowHeadersVisible = false;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(604, 450);
|
||||
dataGridView.TabIndex = 1;
|
||||
//
|
||||
// FormCourts
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(746, 450);
|
||||
Controls.Add(dataGridView1);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(panel1);
|
||||
Name = "FormCourts";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Суды";
|
||||
Load += FormClients_Load;
|
||||
panel1.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@ -125,6 +125,6 @@
|
||||
private Button deleteButton;
|
||||
private Button editButton;
|
||||
private Button addButton;
|
||||
private DataGridView dataGridView1;
|
||||
private DataGridView dataGridView;
|
||||
}
|
||||
}
|
@ -102,20 +102,26 @@ namespace ProjectGSM.Forms
|
||||
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView1.DataSource =
|
||||
_courtRepository.ReadCourts();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource =
|
||||
_courtRepository.ReadCourts();
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["CreatedAt"].DefaultCellStyle.Format =
|
||||
"dd.MM.yyyy";
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
if (dataGridView1.SelectedRows.Count < 1)
|
||||
if (dataGridView.SelectedRows.Count < 1)
|
||||
{
|
||||
MessageBox.Show("Нет выбранной записи", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
id =
|
||||
Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value);
|
||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ namespace ProjectGSM.Forms
|
||||
public FormStatusesCasesReport(IUnityContainer container)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
}
|
||||
|
42
ProjectGSM/Forms/FormStatusesHistory.Designer.cs
generated
42
ProjectGSM/Forms/FormStatusesHistory.Designer.cs
generated
@ -30,9 +30,9 @@
|
||||
{
|
||||
panel1 = new Panel();
|
||||
addButton = new Button();
|
||||
dataGridView1 = new DataGridView();
|
||||
dataGridView = new DataGridView();
|
||||
panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
@ -58,36 +58,36 @@
|
||||
//
|
||||
// dataGridView1
|
||||
//
|
||||
dataGridView1.AllowUserToAddRows = false;
|
||||
dataGridView1.AllowUserToDeleteRows = false;
|
||||
dataGridView1.AllowUserToResizeColumns = false;
|
||||
dataGridView1.AllowUserToResizeRows = false;
|
||||
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridView1.BackgroundColor = SystemColors.Info;
|
||||
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView1.Dock = DockStyle.Fill;
|
||||
dataGridView1.Location = new Point(0, 0);
|
||||
dataGridView1.MultiSelect = false;
|
||||
dataGridView1.Name = "dataGridView1";
|
||||
dataGridView1.ReadOnly = true;
|
||||
dataGridView1.RowHeadersVisible = false;
|
||||
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView1.Size = new Size(604, 450);
|
||||
dataGridView1.TabIndex = 1;
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
dataGridView.AllowUserToDeleteRows = false;
|
||||
dataGridView.AllowUserToResizeColumns = false;
|
||||
dataGridView.AllowUserToResizeRows = false;
|
||||
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||
dataGridView.BackgroundColor = SystemColors.Info;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Dock = DockStyle.Fill;
|
||||
dataGridView.Location = new Point(0, 0);
|
||||
dataGridView.MultiSelect = false;
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.ReadOnly = true;
|
||||
dataGridView.RowHeadersVisible = false;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(604, 450);
|
||||
dataGridView.TabIndex = 1;
|
||||
//
|
||||
// FormStatusesHistory
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(746, 450);
|
||||
Controls.Add(dataGridView1);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(panel1);
|
||||
Name = "FormStatusesHistory";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Суды";
|
||||
Load += FormClients_Load;
|
||||
panel1.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@ -95,6 +95,6 @@
|
||||
|
||||
private Panel panel1;
|
||||
private Button addButton;
|
||||
private DataGridView dataGridView1;
|
||||
private DataGridView dataGridView;
|
||||
}
|
||||
}
|
@ -8,16 +8,17 @@ namespace ProjectGSM.Forms
|
||||
private readonly IUnityContainer _container;
|
||||
|
||||
private readonly IStatusHistoryRepository _statusHistoryRepository;
|
||||
|
||||
public FormStatusesHistory(IUnityContainer container, IStatusHistoryRepository statusHistoryRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_container = container ??
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
_statusHistoryRepository = statusHistoryRepository ??
|
||||
throw new
|
||||
ArgumentNullException(nameof(statusHistoryRepository));
|
||||
|
||||
throw new
|
||||
ArgumentNullException(nameof(statusHistoryRepository));
|
||||
}
|
||||
|
||||
private void addButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
@ -28,9 +29,8 @@ namespace ProjectGSM.Forms
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при добавлении",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void FormClients_Load(object sender, EventArgs e)
|
||||
@ -42,27 +42,32 @@ namespace ProjectGSM.Forms
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при загрузке",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void LoadList() => dataGridView1.DataSource =
|
||||
_statusHistoryRepository.ReadStatusHistories();
|
||||
private void LoadList()
|
||||
{
|
||||
dataGridView.DataSource =
|
||||
_statusHistoryRepository.ReadStatusHistories();
|
||||
dataGridView.Columns["CaseId"].Visible = false;
|
||||
dataGridView.Columns["CreatedAt"].DefaultCellStyle.Format =
|
||||
"dd.MM.yyyy";
|
||||
}
|
||||
|
||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||
{
|
||||
id = 0;
|
||||
if (dataGridView1.SelectedRows.Count < 1)
|
||||
if (dataGridView.SelectedRows.Count < 1)
|
||||
{
|
||||
MessageBox.Show("Нет выбранной записи", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
id =
|
||||
Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value);
|
||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
34
ProjectGSM/Query/QueryBuilder.cs
Normal file
34
ProjectGSM/Query/QueryBuilder.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System.Text;
|
||||
|
||||
namespace ProjectGSM.Query;
|
||||
|
||||
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}";
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ namespace ProjectGSM.Repositories;
|
||||
|
||||
public interface ICaseRepository
|
||||
{
|
||||
IEnumerable<Case> ReadCases();
|
||||
IEnumerable<Case> ReadCases(DateTime? dateTo = null);
|
||||
Case ReadCaseById(int id);
|
||||
void CreateCase(Case caseEntity);
|
||||
void DeleteCase(int id);
|
||||
|
@ -5,7 +5,7 @@ namespace ProjectGSM.Repositories;
|
||||
public interface IStatusHistoryRepository
|
||||
{
|
||||
IEnumerable<StatusHistory> ReadStatusHistories(DateTime? dateForm = null, DateTime? dateTo = null,
|
||||
int? caseId = null, int? statusId = null);
|
||||
int? caseId = null);
|
||||
void CreateStatusHistory(StatusHistory statusHistory);
|
||||
void DeleteStatusHistory(int statusId, int caseId);
|
||||
}
|
@ -4,6 +4,7 @@ using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Npgsql;
|
||||
using ProjectGSM.Entities;
|
||||
using ProjectGSM.Query;
|
||||
|
||||
namespace ProjectGSM.Repositories.Implementations;
|
||||
|
||||
@ -25,11 +26,20 @@ public class CaseAdvocatesRepository : ICaseAdvocateRepository
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("ca.CreatedAt <= @dateTo");
|
||||
}
|
||||
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM case_advocates";
|
||||
var querySelect =
|
||||
"SELECT ca.*, a.name as AdvocateName, cs.description as CaseDescription " +
|
||||
"FROM case_advocates as ca LEFT JOIN cases as cs ON cs.id = ca.caseid " +
|
||||
$"LEFT JOIN advocates as a ON a.id = ca.advocateid {builder.Build()}";
|
||||
var caseAdvocates =
|
||||
connection.Query<CaseAdvocate>(querySelect);
|
||||
connection.Query<CaseAdvocate>(querySelect, param: new { dateTo });
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonSerializer.Serialize(caseAdvocates));
|
||||
return caseAdvocates;
|
||||
|
@ -1,9 +1,11 @@
|
||||
using System.Data.SqlClient;
|
||||
using System.Text.Json;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Npgsql;
|
||||
using ProjectGSM.Entities;
|
||||
using ProjectGSM.Query;
|
||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||
|
||||
namespace ProjectGSM.Repositories.Implementations;
|
||||
|
||||
@ -19,18 +21,51 @@ public class CaseRepository : ICaseRepository
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IEnumerable<Case> ReadCases()
|
||||
public IEnumerable<Case> ReadCases(DateTime? dateTo = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
builder.AddCondition("cases.CreatedAt <= @dateTo");
|
||||
}
|
||||
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM cases";
|
||||
var cases = connection.Query<Case>(querySelect);
|
||||
|
||||
var querySelect =
|
||||
"SELECT cases.*, courts.name as CourtName, clients.name as ClientName, ca.caseid as CaseId, a.name as AdvocateName " +
|
||||
"FROM cases " +
|
||||
"LEFT JOIN courts on courts.Id = cases.courtid " +
|
||||
"LEFT JOIN clients on clients.Id = cases.clientid " +
|
||||
"INNER JOIN case_advocates ca ON ca.caseid = cases.Id LEFT JOIN advocates a on a.Id = ca.advocateid " +
|
||||
$"{builder.Build()}";
|
||||
// $"{builder.Build()}";
|
||||
|
||||
var casesDict = new Dictionary<int, List<CaseAdvocate>>();
|
||||
;
|
||||
var cases = connection.Query<Case, CaseAdvocate, Case>(querySelect,
|
||||
(caseEntity, caseAdvocate) =>
|
||||
{
|
||||
if (!casesDict.TryGetValue(caseEntity.Id, out var ca))
|
||||
{
|
||||
ca = new List<CaseAdvocate>();
|
||||
casesDict.Add(caseEntity.Id, ca);
|
||||
}
|
||||
|
||||
ca.Add(caseAdvocate);
|
||||
return caseEntity;
|
||||
}, splitOn: "CaseId", param: new { dateTo, });
|
||||
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonSerializer.Serialize(cases));
|
||||
return cases;
|
||||
JsonConvert.SerializeObject(cases));
|
||||
return casesDict.Select(x =>
|
||||
{
|
||||
var caseEntity = cases.First(y => y.Id == x.Key);
|
||||
caseEntity.SetAdvocates(x.Value);
|
||||
return caseEntity;
|
||||
}).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -70,7 +105,8 @@ public class CaseRepository : ICaseRepository
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
var queryInsert = @"INSERT INTO Cases (typeappeal, Payment, Price, victoryprice, Verdict, courtid, clientid, Description, createdat)
|
||||
var queryInsert =
|
||||
@"INSERT INTO Cases (typeappeal, Payment, Price, victoryprice, Verdict, courtid, clientid, Description, createdat)
|
||||
VALUES (@TypeAppeal, @Payment, @Price, @VictoryPrice, @Verdict, @CourtId, @ClientId, @Description, @CreatedAt);
|
||||
SELECT MAX(Id) FROM cases;";
|
||||
var caseId =
|
||||
@ -80,9 +116,12 @@ SELECT MAX(Id) FROM cases;";
|
||||
VALUES (@CaseId, @AdvocateId, @Post, @CreatedAt)";
|
||||
foreach (var elem in caseEntity.Advocates)
|
||||
{
|
||||
connection.Execute(querySubInsert, new {
|
||||
caseId, elem.AdvocateId, elem.Post, elem.CreatedAt }, transaction);
|
||||
connection.Execute(querySubInsert, new
|
||||
{
|
||||
caseId, elem.AdvocateId, elem.Post, elem.CreatedAt
|
||||
}, transaction);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -4,6 +4,7 @@ using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Npgsql;
|
||||
using ProjectGSM.Entities;
|
||||
using ProjectGSM.Query;
|
||||
|
||||
namespace ProjectGSM.Repositories.Implementations;
|
||||
|
||||
@ -11,34 +12,50 @@ public class StatusHistoryRepository : IStatusHistoryRepository
|
||||
{
|
||||
private readonly IConnectionString _connectionString;
|
||||
private readonly ILogger<StatusHistoryRepository> _logger;
|
||||
|
||||
public StatusHistoryRepository(IConnectionString connectionString,
|
||||
ILogger<StatusHistoryRepository> logger)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IEnumerable<StatusHistory> ReadStatusHistories(DateTime? dateForm = null, DateTime? dateTo = null,
|
||||
int? caseId = null, int? statusId = null)
|
||||
int? caseId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
var builder = new QueryBuilder();
|
||||
if (dateForm.HasValue)
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM status_histories";
|
||||
var statusHistories =
|
||||
connection.Query<StatusHistory>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonSerializer.Serialize(statusHistories));
|
||||
return statusHistories;
|
||||
builder.AddCondition("sh.CreatedAt >= @dateForm");
|
||||
}
|
||||
catch (Exception ex)
|
||||
if (dateTo.HasValue)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
builder.AddCondition("sh.CreatedAt <= @dateTo");
|
||||
}
|
||||
if (caseId.HasValue)
|
||||
{
|
||||
builder.AddCondition("sh.caseid = @caseId");
|
||||
}
|
||||
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect =
|
||||
@$"SELECT sh.*, c.description as CaseDescription FROM status_histories as sh LEFT JOIN cases as c ON c.id = sh.caseid {builder.Build()}";
|
||||
var statusHistories =
|
||||
connection.Query<StatusHistory>(querySelect, new { dateForm, dateTo, caseId });
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonSerializer.Serialize(statusHistories));
|
||||
return statusHistories;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateStatusHistory(StatusHistory statusHistory)
|
||||
{
|
||||
@ -59,7 +76,6 @@ public class StatusHistoryRepository : IStatusHistoryRepository
|
||||
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void DeleteStatusHistory(int statusId, int caseId)
|
||||
|
Loading…
Reference in New Issue
Block a user
Закомментированного кода быть не должно