From d308417e6ad00d77c21b12175755ad2194c09e12 Mon Sep 17 00:00:00 2001 From: Maxim Date: Mon, 16 Dec 2024 23:03:26 +0400 Subject: [PATCH 1/2] pre ready lab4 --- ProjectGSM/Entities/Advocate.cs | 37 +++++++++------ ProjectGSM/Entities/Case.cs | 46 +++++++++++++------ ProjectGSM/Entities/CaseAdvocate.cs | 19 ++++++-- ProjectGSM/Entities/Client.cs | 29 ++++++++---- ProjectGSM/Entities/Court.cs | 17 ++++--- ProjectGSM/Entities/StatusHistory.cs | 18 +++++--- ProjectGSM/FormAdvocateApp.cs | 1 - ProjectGSM/Forms/FormAdvocates.cs | 8 +++- ProjectGSM/Forms/FormCases.Designer.cs | 44 +++++++++--------- ProjectGSM/Forms/FormCases.cs | 13 ++++-- ProjectGSM/Forms/FormClients.Designer.cs | 42 ++++++++--------- ProjectGSM/Forms/FormClients.cs | 12 +++-- ProjectGSM/Forms/FormCourts.Designer.cs | 42 ++++++++--------- ProjectGSM/Forms/FormCourts.cs | 13 ++++-- .../Forms/FormStatusesHistory.Designer.cs | 42 ++++++++--------- ProjectGSM/Forms/FormStatusesHistory.cs | 34 ++++++++------ ProjectGSM/Query/QueryBuilder.cs | 34 ++++++++++++++ .../Repositories/IStatusHistoryRepository.cs | 2 +- .../CaseAdvocatesRepository.cs | 5 +- .../Implementations/CaseRepository.cs | 16 +++++-- .../StatusHistoryRepository.cs | 46 +++++++++++++------ 21 files changed, 330 insertions(+), 190 deletions(-) create mode 100644 ProjectGSM/Query/QueryBuilder.cs diff --git a/ProjectGSM/Entities/Advocate.cs b/ProjectGSM/Entities/Advocate.cs index 5cdaf8b..ba02b2d 100644 --- a/ProjectGSM/Entities/Advocate.cs +++ b/ProjectGSM/Entities/Advocate.cs @@ -5,18 +5,29 @@ 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; + [Browsable(false)] public int Id { get; private set; } + + [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 }; } -} +} \ No newline at end of file diff --git a/ProjectGSM/Entities/Case.cs b/ProjectGSM/Entities/Case.cs index 9bec39e..5c97c9d 100644 --- a/ProjectGSM/Entities/Case.cs +++ b/ProjectGSM/Entities/Case.cs @@ -1,21 +1,39 @@ -using System.Text.Json.Serialization; +using System.ComponentModel; +using System.Text.Json.Serialization; using ProjectGSM.Entities.Enums; 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 Advocates { get; set; } + [Browsable(false)] public int Id { get; private 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 List Advocates { get; set; } = new(); + + [DisplayName("Адвокаты")] + public string AdvocatesNames => string.Join(", ", Advocates.Select(x => $"{x.AdvocateName} ({x.Post})")); + // Конструктор для создания сущности public static Case CreateEntity( int id, @@ -27,7 +45,7 @@ public class Case int courtId, int clientId, string description - ) + ) { return new Case { @@ -43,4 +61,4 @@ public class Case CreatedAt = DateTime.UtcNow }; } -} +} \ No newline at end of file diff --git a/ProjectGSM/Entities/CaseAdvocate.cs b/ProjectGSM/Entities/CaseAdvocate.cs index 59b80a0..1df5ff9 100644 --- a/ProjectGSM/Entities/CaseAdvocate.cs +++ b/ProjectGSM/Entities/CaseAdvocate.cs @@ -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; + [Browsable(false)] public int CaseId { get; private set; } + + [Browsable(false)] public int AdvocateId { get; private set; } + + [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) diff --git a/ProjectGSM/Entities/Client.cs b/ProjectGSM/Entities/Client.cs index 4af304b..f3380c6 100644 --- a/ProjectGSM/Entities/Client.cs +++ b/ProjectGSM/Entities/Client.cs @@ -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; + [Browsable(false)] public int Id { get; private set; } + + [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 }; } -} +} \ No newline at end of file diff --git a/ProjectGSM/Entities/Court.cs b/ProjectGSM/Entities/Court.cs index 8e3dc35..29f585e 100644 --- a/ProjectGSM/Entities/Court.cs +++ b/ProjectGSM/Entities/Court.cs @@ -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; + [Browsable(false)] public int Id { get; private set; } + + [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 }; } -} +} \ No newline at end of file diff --git a/ProjectGSM/Entities/StatusHistory.cs b/ProjectGSM/Entities/StatusHistory.cs index 55f386b..e84cd6e 100644 --- a/ProjectGSM/Entities/StatusHistory.cs +++ b/ProjectGSM/Entities/StatusHistory.cs @@ -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; + [Browsable(false)] public int CaseId { get; private set; } + + [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 }; } -} +} \ No newline at end of file diff --git a/ProjectGSM/FormAdvocateApp.cs b/ProjectGSM/FormAdvocateApp.cs index d21717e..71ed6de 100644 --- a/ProjectGSM/FormAdvocateApp.cs +++ b/ProjectGSM/FormAdvocateApp.cs @@ -1,5 +1,4 @@ using ProjectGSM.Forms; -using System.ComponentModel; using Unity; namespace ProjectGSM diff --git a/ProjectGSM/Forms/FormAdvocates.cs b/ProjectGSM/Forms/FormAdvocates.cs index 9d04851..8631fbd 100644 --- a/ProjectGSM/Forms/FormAdvocates.cs +++ b/ProjectGSM/Forms/FormAdvocates.cs @@ -102,8 +102,12 @@ namespace ProjectGSM.Forms } - private void LoadList() => dataGridViewAdvocats.DataSource = -_advocateRepository.ReadAdvocates(); + private void LoadList() { + dataGridViewAdvocats.DataSource = + _advocateRepository.ReadAdvocates(); + dataGridViewAdvocats.Columns["CreatedAt"].DefaultCellStyle.Format = + "dd.MM.yyyy"; + } private bool TryGetIdentifierFromSelectedRow(out int id) { diff --git a/ProjectGSM/Forms/FormCases.Designer.cs b/ProjectGSM/Forms/FormCases.Designer.cs index d8b1b63..bf38da9 100644 --- a/ProjectGSM/Forms/FormCases.Designer.cs +++ b/ProjectGSM/Forms/FormCases.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/ProjectGSM/Forms/FormCases.cs b/ProjectGSM/Forms/FormCases.cs index bf998cb..04f9654 100644 --- a/ProjectGSM/Forms/FormCases.cs +++ b/ProjectGSM/Forms/FormCases.cs @@ -81,20 +81,25 @@ namespace ProjectGSM.Forms } - private void LoadList() => dataGridView1.DataSource = -_caseRepository.ReadCases(); + private void LoadList() + { + dataGridView.DataSource = + _caseRepository.ReadCases(); + 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; } diff --git a/ProjectGSM/Forms/FormClients.Designer.cs b/ProjectGSM/Forms/FormClients.Designer.cs index 446c517..a645985 100644 --- a/ProjectGSM/Forms/FormClients.Designer.cs +++ b/ProjectGSM/Forms/FormClients.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/ProjectGSM/Forms/FormClients.cs b/ProjectGSM/Forms/FormClients.cs index eab944f..3eb8123 100644 --- a/ProjectGSM/Forms/FormClients.cs +++ b/ProjectGSM/Forms/FormClients.cs @@ -102,20 +102,24 @@ namespace ProjectGSM.Forms } - private void LoadList() => dataGridView1.DataSource = -_clientRepository.ReadClients(); + private void LoadList() { + dataGridView.DataSource = + _clientRepository.ReadClients(); + 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; } diff --git a/ProjectGSM/Forms/FormCourts.Designer.cs b/ProjectGSM/Forms/FormCourts.Designer.cs index 5c140b8..1ca6273 100644 --- a/ProjectGSM/Forms/FormCourts.Designer.cs +++ b/ProjectGSM/Forms/FormCourts.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/ProjectGSM/Forms/FormCourts.cs b/ProjectGSM/Forms/FormCourts.cs index 3f9c21c..d594c2f 100644 --- a/ProjectGSM/Forms/FormCourts.cs +++ b/ProjectGSM/Forms/FormCourts.cs @@ -102,20 +102,25 @@ namespace ProjectGSM.Forms } - private void LoadList() => dataGridView1.DataSource = -_courtRepository.ReadCourts(); + private void LoadList() + { + dataGridView.DataSource = + _courtRepository.ReadCourts(); + 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; } diff --git a/ProjectGSM/Forms/FormStatusesHistory.Designer.cs b/ProjectGSM/Forms/FormStatusesHistory.Designer.cs index f0443a3..2afe8fe 100644 --- a/ProjectGSM/Forms/FormStatusesHistory.Designer.cs +++ b/ProjectGSM/Forms/FormStatusesHistory.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/ProjectGSM/Forms/FormStatusesHistory.cs b/ProjectGSM/Forms/FormStatusesHistory.cs index f2cb80f..0622a16 100644 --- a/ProjectGSM/Forms/FormStatusesHistory.cs +++ b/ProjectGSM/Forms/FormStatusesHistory.cs @@ -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,31 @@ 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["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; } - } -} +} \ No newline at end of file diff --git a/ProjectGSM/Query/QueryBuilder.cs b/ProjectGSM/Query/QueryBuilder.cs new file mode 100644 index 0000000..518d898 --- /dev/null +++ b/ProjectGSM/Query/QueryBuilder.cs @@ -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}"; + } +} \ No newline at end of file diff --git a/ProjectGSM/Repositories/IStatusHistoryRepository.cs b/ProjectGSM/Repositories/IStatusHistoryRepository.cs index da00b97..5d7d406 100644 --- a/ProjectGSM/Repositories/IStatusHistoryRepository.cs +++ b/ProjectGSM/Repositories/IStatusHistoryRepository.cs @@ -5,7 +5,7 @@ namespace ProjectGSM.Repositories; public interface IStatusHistoryRepository { IEnumerable 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); } \ No newline at end of file diff --git a/ProjectGSM/Repositories/Implementations/CaseAdvocatesRepository.cs b/ProjectGSM/Repositories/Implementations/CaseAdvocatesRepository.cs index 8c64473..408b99e 100644 --- a/ProjectGSM/Repositories/Implementations/CaseAdvocatesRepository.cs +++ b/ProjectGSM/Repositories/Implementations/CaseAdvocatesRepository.cs @@ -27,7 +27,10 @@ public class CaseAdvocatesRepository : ICaseAdvocateRepository { 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"; var caseAdvocates = connection.Query(querySelect); _logger.LogDebug("Полученные объекты: {json}", diff --git a/ProjectGSM/Repositories/Implementations/CaseRepository.cs b/ProjectGSM/Repositories/Implementations/CaseRepository.cs index 757ae74..bc6ac48 100644 --- a/ProjectGSM/Repositories/Implementations/CaseRepository.cs +++ b/ProjectGSM/Repositories/Implementations/CaseRepository.cs @@ -26,8 +26,12 @@ public class CaseRepository : ICaseRepository { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var querySelect = "SELECT * FROM cases"; + var querySelect = + "SELECT cases.*, courts.name as CourtName, clients.name as ClientName " + + "FROM cases LEFT JOIN courts on courts.Id = cases.courtid " + + "LEFT JOIN clients on clients.Id = cases.clientid"; var cases = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", JsonSerializer.Serialize(cases)); return cases; @@ -70,7 +74,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 +85,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) diff --git a/ProjectGSM/Repositories/Implementations/StatusHistoryRepository.cs b/ProjectGSM/Repositories/Implementations/StatusHistoryRepository.cs index c5fb035..303f6c4 100644 --- a/ProjectGSM/Repositories/Implementations/StatusHistoryRepository.cs +++ b/ProjectGSM/Repositories/Implementations/StatusHistoryRepository.cs @@ -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 _logger; + public StatusHistoryRepository(IConnectionString connectionString, ILogger logger) { _connectionString = connectionString; _logger = logger; } + public IEnumerable 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(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(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) -- 2.25.1 From 219abbc68082264f9b0b36cbd5f674a2d201538e Mon Sep 17 00:00:00 2001 From: Maxim Date: Tue, 17 Dec 2024 01:21:56 +0400 Subject: [PATCH 2/2] lab4 ready --- ProjectGSM/Documents/ChartReport.cs | 28 +++++------ ProjectGSM/Documents/TableReport.cs | 5 +- ProjectGSM/Entities/Advocate.cs | 2 +- ProjectGSM/Entities/Case.cs | 12 ++++- ProjectGSM/Entities/CaseAdvocate.cs | 4 +- ProjectGSM/Entities/Client.cs | 2 +- ProjectGSM/Entities/Court.cs | 2 +- ProjectGSM/Entities/StatusHistory.cs | 2 +- ProjectGSM/Forms/FormAdvocates.cs | 1 + ProjectGSM/Forms/FormCase.cs | 2 +- ProjectGSM/Forms/FormCases.cs | 1 + ProjectGSM/Forms/FormClients.cs | 1 + ProjectGSM/Forms/FormCourts.cs | 1 + ProjectGSM/Forms/FormStatusesCasesReport.cs | 1 + ProjectGSM/Forms/FormStatusesHistory.cs | 1 + ProjectGSM/Repositories/ICaseRepository.cs | 2 +- .../CaseAdvocatesRepository.cs | 11 ++++- .../Implementations/CaseRepository.cs | 49 +++++++++++++++---- .../StatusHistoryRepository.cs | 2 +- 19 files changed, 90 insertions(+), 39 deletions(-) diff --git a/ProjectGSM/Documents/ChartReport.cs b/ProjectGSM/Documents/ChartReport.cs index 394ad4e..95a2c2c 100644 --- a/ProjectGSM/Documents/ChartReport.cs +++ b/ProjectGSM/Documents/ChartReport.cs @@ -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) { diff --git a/ProjectGSM/Documents/TableReport.cs b/ProjectGSM/Documents/TableReport.cs index e55c5f6..74a64f1 100644 --- a/ProjectGSM/Documents/TableReport.cs +++ b/ProjectGSM/Documents/TableReport.cs @@ -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( [ diff --git a/ProjectGSM/Entities/Advocate.cs b/ProjectGSM/Entities/Advocate.cs index ba02b2d..bfa8611 100644 --- a/ProjectGSM/Entities/Advocate.cs +++ b/ProjectGSM/Entities/Advocate.cs @@ -5,7 +5,7 @@ namespace ProjectGSM.Entities; public class Advocate { - [Browsable(false)] public int Id { get; private set; } + public int Id { get; private set; } [DisplayName("Имя")] public string Name { get; private set; } = string.Empty; diff --git a/ProjectGSM/Entities/Case.cs b/ProjectGSM/Entities/Case.cs index 5c97c9d..9d06729 100644 --- a/ProjectGSM/Entities/Case.cs +++ b/ProjectGSM/Entities/Case.cs @@ -6,7 +6,7 @@ namespace ProjectGSM.Entities; public class Case { - [Browsable(false)] public int Id { get; private set; } + public int Id { get; private set; } [DisplayName("Тип обращения")] public TypeAppeal TypeAppeal { get; private set; } @@ -29,11 +29,19 @@ public class Case [DisplayName("Дата создания")] public DateTime CreatedAt { get; private set; } = DateTime.UtcNow; - [JsonIgnore] [Browsable(false)] public List Advocates { get; set; } = new(); + [JsonIgnore] [Browsable(false)] public IEnumerable Advocates { get; private set; } = []; [DisplayName("Адвокаты")] public string AdvocatesNames => string.Join(", ", Advocates.Select(x => $"{x.AdvocateName} ({x.Post})")); + public void SetAdvocates(IEnumerable advocates) + { + if (advocates != null && advocates.Any()) + { + Advocates = advocates; + } + } + // Конструктор для создания сущности public static Case CreateEntity( int id, diff --git a/ProjectGSM/Entities/CaseAdvocate.cs b/ProjectGSM/Entities/CaseAdvocate.cs index 1df5ff9..1a47841 100644 --- a/ProjectGSM/Entities/CaseAdvocate.cs +++ b/ProjectGSM/Entities/CaseAdvocate.cs @@ -4,9 +4,9 @@ namespace ProjectGSM.Entities; public class CaseAdvocate { - [Browsable(false)] public int CaseId { get; private set; } + public int CaseId { get; private set; } - [Browsable(false)] public int AdvocateId { get; private set; } + public int AdvocateId { get; private set; } [DisplayName("Дело")] public string CaseDescription { get; private set; } = string.Empty; diff --git a/ProjectGSM/Entities/Client.cs b/ProjectGSM/Entities/Client.cs index f3380c6..c35a614 100644 --- a/ProjectGSM/Entities/Client.cs +++ b/ProjectGSM/Entities/Client.cs @@ -4,7 +4,7 @@ namespace ProjectGSM.Entities; public class Client { - [Browsable(false)] public int Id { get; private set; } + public int Id { get; private set; } [DisplayName("Имя")] public string Name { get; private set; } = string.Empty; diff --git a/ProjectGSM/Entities/Court.cs b/ProjectGSM/Entities/Court.cs index 29f585e..6748f85 100644 --- a/ProjectGSM/Entities/Court.cs +++ b/ProjectGSM/Entities/Court.cs @@ -4,7 +4,7 @@ namespace ProjectGSM.Entities; public class Court { - [Browsable(false)] public int Id { get; private set; } + public int Id { get; private set; } [DisplayName("Название")] public string Name { get; private set; } = string.Empty; diff --git a/ProjectGSM/Entities/StatusHistory.cs b/ProjectGSM/Entities/StatusHistory.cs index e84cd6e..1753d74 100644 --- a/ProjectGSM/Entities/StatusHistory.cs +++ b/ProjectGSM/Entities/StatusHistory.cs @@ -5,7 +5,7 @@ namespace ProjectGSM.Entities; public class StatusHistory { - [Browsable(false)] public int CaseId { get; private set; } + public int CaseId { get; private set; } [DisplayName("Дело")] public string CaseDescription { get; private set; } = string.Empty; diff --git a/ProjectGSM/Forms/FormAdvocates.cs b/ProjectGSM/Forms/FormAdvocates.cs index 8631fbd..65e0e89 100644 --- a/ProjectGSM/Forms/FormAdvocates.cs +++ b/ProjectGSM/Forms/FormAdvocates.cs @@ -105,6 +105,7 @@ namespace ProjectGSM.Forms private void LoadList() { dataGridViewAdvocats.DataSource = _advocateRepository.ReadAdvocates(); + dataGridViewAdvocats.Columns["Id"].Visible = false; dataGridViewAdvocats.Columns["CreatedAt"].DefaultCellStyle.Format = "dd.MM.yyyy"; } diff --git a/ProjectGSM/Forms/FormCase.cs b/ProjectGSM/Forms/FormCase.cs index 924f6db..ae7ff4e 100644 --- a/ProjectGSM/Forms/FormCase.cs +++ b/ProjectGSM/Forms/FormCase.cs @@ -43,7 +43,7 @@ namespace ProjectGSM.Forms } Case caseE = CreateCase(0); - caseE.Advocates = CreateListCaseAdvocateFromDataGrid(); + caseE.SetAdvocates(CreateListCaseAdvocateFromDataGrid()); _caseRepository.CreateCase(caseE); Close(); } diff --git a/ProjectGSM/Forms/FormCases.cs b/ProjectGSM/Forms/FormCases.cs index 04f9654..1ca7a8a 100644 --- a/ProjectGSM/Forms/FormCases.cs +++ b/ProjectGSM/Forms/FormCases.cs @@ -85,6 +85,7 @@ namespace ProjectGSM.Forms { dataGridView.DataSource = _caseRepository.ReadCases(); + dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["CreatedAt"].DefaultCellStyle.Format = "dd.MM.yyyy"; } diff --git a/ProjectGSM/Forms/FormClients.cs b/ProjectGSM/Forms/FormClients.cs index 3eb8123..83379dd 100644 --- a/ProjectGSM/Forms/FormClients.cs +++ b/ProjectGSM/Forms/FormClients.cs @@ -105,6 +105,7 @@ namespace ProjectGSM.Forms private void LoadList() { dataGridView.DataSource = _clientRepository.ReadClients(); + dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["CreatedAt"].DefaultCellStyle.Format = "dd.MM.yyyy"; } diff --git a/ProjectGSM/Forms/FormCourts.cs b/ProjectGSM/Forms/FormCourts.cs index d594c2f..92a2a98 100644 --- a/ProjectGSM/Forms/FormCourts.cs +++ b/ProjectGSM/Forms/FormCourts.cs @@ -106,6 +106,7 @@ namespace ProjectGSM.Forms { dataGridView.DataSource = _courtRepository.ReadCourts(); + dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["CreatedAt"].DefaultCellStyle.Format = "dd.MM.yyyy"; } diff --git a/ProjectGSM/Forms/FormStatusesCasesReport.cs b/ProjectGSM/Forms/FormStatusesCasesReport.cs index 83d228a..aabe5dd 100644 --- a/ProjectGSM/Forms/FormStatusesCasesReport.cs +++ b/ProjectGSM/Forms/FormStatusesCasesReport.cs @@ -20,6 +20,7 @@ namespace ProjectGSM.Forms public FormStatusesCasesReport(IUnityContainer container) { InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); } diff --git a/ProjectGSM/Forms/FormStatusesHistory.cs b/ProjectGSM/Forms/FormStatusesHistory.cs index 0622a16..ecbd532 100644 --- a/ProjectGSM/Forms/FormStatusesHistory.cs +++ b/ProjectGSM/Forms/FormStatusesHistory.cs @@ -50,6 +50,7 @@ namespace ProjectGSM.Forms { dataGridView.DataSource = _statusHistoryRepository.ReadStatusHistories(); + dataGridView.Columns["CaseId"].Visible = false; dataGridView.Columns["CreatedAt"].DefaultCellStyle.Format = "dd.MM.yyyy"; } diff --git a/ProjectGSM/Repositories/ICaseRepository.cs b/ProjectGSM/Repositories/ICaseRepository.cs index ff0f6cf..7db8947 100644 --- a/ProjectGSM/Repositories/ICaseRepository.cs +++ b/ProjectGSM/Repositories/ICaseRepository.cs @@ -4,7 +4,7 @@ namespace ProjectGSM.Repositories; public interface ICaseRepository { - IEnumerable ReadCases(); + IEnumerable ReadCases(DateTime? dateTo = null); Case ReadCaseById(int id); void CreateCase(Case caseEntity); void DeleteCase(int id); diff --git a/ProjectGSM/Repositories/Implementations/CaseAdvocatesRepository.cs b/ProjectGSM/Repositories/Implementations/CaseAdvocatesRepository.cs index 408b99e..d71cc69 100644 --- a/ProjectGSM/Repositories/Implementations/CaseAdvocatesRepository.cs +++ b/ProjectGSM/Repositories/Implementations/CaseAdvocatesRepository.cs @@ -4,6 +4,7 @@ using Dapper; using Microsoft.Extensions.Logging; using Npgsql; using ProjectGSM.Entities; +using ProjectGSM.Query; namespace ProjectGSM.Repositories.Implementations; @@ -25,14 +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 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"; + $"LEFT JOIN advocates as a ON a.id = ca.advocateid {builder.Build()}"; var caseAdvocates = - connection.Query(querySelect); + connection.Query(querySelect, param: new { dateTo }); _logger.LogDebug("Полученные объекты: {json}", JsonSerializer.Serialize(caseAdvocates)); return caseAdvocates; diff --git a/ProjectGSM/Repositories/Implementations/CaseRepository.cs b/ProjectGSM/Repositories/Implementations/CaseRepository.cs index bc6ac48..e3fa022 100644 --- a/ProjectGSM/Repositories/Implementations/CaseRepository.cs +++ b/ProjectGSM/Repositories/Implementations/CaseRepository.cs @@ -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,22 +21,51 @@ public class CaseRepository : ICaseRepository _logger = logger; } - public IEnumerable ReadCases() + public IEnumerable 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 cases.*, courts.name as CourtName, clients.name as ClientName " + - "FROM cases LEFT JOIN courts on courts.Id = cases.courtid " + - "LEFT JOIN clients on clients.Id = cases.clientid"; - var cases = connection.Query(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>(); + ; + var cases = connection.Query(querySelect, + (caseEntity, caseAdvocate) => + { + if (!casesDict.TryGetValue(caseEntity.Id, out var ca)) + { + ca = new List(); + 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) { diff --git a/ProjectGSM/Repositories/Implementations/StatusHistoryRepository.cs b/ProjectGSM/Repositories/Implementations/StatusHistoryRepository.cs index 303f6c4..f4f324a 100644 --- a/ProjectGSM/Repositories/Implementations/StatusHistoryRepository.cs +++ b/ProjectGSM/Repositories/Implementations/StatusHistoryRepository.cs @@ -43,7 +43,7 @@ public class StatusHistoryRepository : IStatusHistoryRepository 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()}"; + @$"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(querySelect, new { dateForm, dateTo, caseId }); _logger.LogDebug("Полученные объекты: {json}", -- 2.25.1