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)