From 5c229cb2ffde582c6436087473755f2a5da9be59 Mon Sep 17 00:00:00 2001 From: Maxim Date: Mon, 18 Nov 2024 23:50:05 +0400 Subject: [PATCH] lab 1ready --- ProjectGSM/Entities/Case.cs | 5 +- ProjectGSM/Forms/FormAdvocate.cs | 4 +- ProjectGSM/Forms/FormCase.cs | 69 ++----------------- ProjectGSM/Forms/FormCases.Designer.cs | 30 ++++---- ProjectGSM/Forms/FormClient.cs | 13 ++-- ProjectGSM/Forms/FormCourt.cs | 2 + ProjectGSM/Program.cs | 1 - ProjectGSM/ProjectGSM.csproj | 11 +++ .../Repositories/ICaseAdvocateRepository.cs | 11 --- ProjectGSM/Repositories/ICaseRepository.cs | 1 - .../Implementations/CaseAdvocateRepository.cs | 16 ----- 11 files changed, 46 insertions(+), 117 deletions(-) delete mode 100644 ProjectGSM/Repositories/ICaseAdvocateRepository.cs delete mode 100644 ProjectGSM/Repositories/Implementations/CaseAdvocateRepository.cs diff --git a/ProjectGSM/Entities/Case.cs b/ProjectGSM/Entities/Case.cs index 1d74e39..9bec39e 100644 --- a/ProjectGSM/Entities/Case.cs +++ b/ProjectGSM/Entities/Case.cs @@ -1,4 +1,5 @@ -using ProjectGSM.Entities.Enums; +using System.Text.Json.Serialization; +using ProjectGSM.Entities.Enums; namespace ProjectGSM.Entities; @@ -14,7 +15,7 @@ public class Case 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; } // Конструктор для создания сущности public static Case CreateEntity( int id, diff --git a/ProjectGSM/Forms/FormAdvocate.cs b/ProjectGSM/Forms/FormAdvocate.cs index ec9a06e..c9bba6c 100644 --- a/ProjectGSM/Forms/FormAdvocate.cs +++ b/ProjectGSM/Forms/FormAdvocate.cs @@ -25,6 +25,8 @@ namespace ProjectGSM.Forms throw new InvalidDataException(nameof(advocate)); } + + _advocateId = value; foreach (LicenseType elem in Enum.GetValues(typeof(LicenseType))) { if ((elem & advocate.LicenseType) != 0) @@ -84,7 +86,7 @@ namespace ProjectGSM.Forms } else { - _advocateRepository.UpdateAdvocate(CreateAdvocate(0)); + _advocateRepository.CreateAdvocate(CreateAdvocate(0)); } Close(); } diff --git a/ProjectGSM/Forms/FormCase.cs b/ProjectGSM/Forms/FormCase.cs index 29c8afa..47d1424 100644 --- a/ProjectGSM/Forms/FormCase.cs +++ b/ProjectGSM/Forms/FormCase.cs @@ -1,16 +1,6 @@ using ProjectGSM.Entities; using ProjectGSM.Entities.Enums; using ProjectGSM.Repositories; -using ProjectGSM.Repositories.Implementations; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace ProjectGSM.Forms { @@ -19,50 +9,13 @@ namespace ProjectGSM.Forms { private readonly ICaseRepository _caseRepository; - private readonly ICaseAdvocateRepository _caseAdvocateRepository; - private int? _caseId; - - public int Id - { - set - { - try - { - var caseE = - _caseRepository.ReadCaseById(value); - if (caseE == null) - { - throw new - InvalidDataException(nameof(caseE)); - } - - - typeApellBox.SelectedItem = caseE.TypeAppeal; - clientBox.SelectedIndex = caseE.ClientId; - courtBox.SelectedIndex = caseE.CourtId; - paymentCheckBox.Checked = caseE.Payment; - priceNumeric.Value = caseE.Price; - winPriceNumeric.Value = caseE.VictoryPrice; - verdictCheckBox.Checked= caseE.Verdict; - textBox1.Text = caseE.Description; - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - - - public FormCase(ICaseRepository caseRepository, ICaseAdvocateRepository caseAdvocateRepository,IClientRepository clientRepository, ICourtRepository courtRepository, IAdvocateRepository advocateRepository) + public FormCase(ICaseRepository caseRepository,IClientRepository clientRepository, ICourtRepository courtRepository, IAdvocateRepository advocateRepository) { InitializeComponent(); _caseRepository = caseRepository ?? throw new ArgumentNullException(nameof(caseRepository)); - _caseAdvocateRepository = caseAdvocateRepository ?? throw new ArgumentNullException(nameof(caseAdvocateRepository)); typeApellBox.DataSource = Enum.GetValues(typeof(TypeAppeal)); @@ -88,18 +41,10 @@ namespace ProjectGSM.Forms { throw new Exception("Имеются незаполненные поля"); } - if (_caseId.HasValue) - { - _caseRepository.UpdateCase(CreateCase(_caseId.Value)); - } - else - { - _caseRepository.UpdateCase(CreateCase(0)); - } - foreach (CaseAdvocate row in CreateListCaseAdvocateFromDataGrid()) - { - _caseAdvocateRepository.CreateCaseAdvocate(CaseAdvocate.CreateEntity(row.CaseId, row.AdvocateId, row.Post)); - } + + Case caseE = CreateCase(0); + caseE.Advocates = CreateListCaseAdvocateFromDataGrid(); + _caseRepository.CreateCase(caseE); Close(); } catch (Exception ex) @@ -118,13 +63,13 @@ namespace ProjectGSM.Forms var list = new List(); foreach (DataGridViewRow row in dataGridView1.Rows) { - if (row.Cells["ColumnAdvocates"].Value == null || + if (row.Cells["ColumnAdvocate"].Value == null || row.Cells["ColumnPost"].Value == null) { continue; } list.Add(CaseAdvocate.CreateEntity(0, - Convert.ToInt32(row.Cells["ColumnAdvocates"].Value), + Convert.ToInt32(row.Cells["ColumnAdvocate"].Value), row.Cells["ColumnPost"].Value.ToString()??string.Empty)); } return list; diff --git a/ProjectGSM/Forms/FormCases.Designer.cs b/ProjectGSM/Forms/FormCases.Designer.cs index fdbea7f..d8b1b63 100644 --- a/ProjectGSM/Forms/FormCases.Designer.cs +++ b/ProjectGSM/Forms/FormCases.Designer.cs @@ -41,33 +41,29 @@ panel1.Controls.Add(deleteButton); panel1.Controls.Add(addButton); panel1.Dock = DockStyle.Right; - panel1.Location = new Point(863, 0); - panel1.Margin = new Padding(4, 5, 4, 5); + panel1.Location = new Point(604, 0); panel1.Name = "panel1"; - panel1.Size = new Size(203, 750); + panel1.Size = new Size(142, 450); panel1.TabIndex = 0; // // deleteButton // deleteButton.BackgroundImage = Properties.Resources.circle_x_svgrepo_com; - deleteButton.BackgroundImageLayout = ImageLayout.Zoom; - deleteButton.Location = new Point(47, 400); - deleteButton.Margin = new Padding(4, 5, 4, 5); + deleteButton.BackgroundImageLayout = ImageLayout.Stretch; + deleteButton.Location = new Point(33, 137); + deleteButton.Margin = new Padding(2, 2, 2, 2); deleteButton.Name = "deleteButton"; - deleteButton.Size = new Size(107, 125); - deleteButton.TabIndex = 2; - deleteButton.Text = " "; - deleteButton.UseVisualStyleBackColor = true; + deleteButton.Size = new Size(75, 72); + deleteButton.TabIndex = 0; deleteButton.Click += deleteButton_Click; // // addButton // addButton.BackgroundImage = Properties.Resources.circle_plus_svgrepo_com; addButton.BackgroundImageLayout = ImageLayout.Zoom; - addButton.Location = new Point(47, 63); - addButton.Margin = new Padding(4, 5, 4, 5); + addButton.Location = new Point(33, 38); addButton.Name = "addButton"; - addButton.Size = new Size(107, 125); + addButton.Size = new Size(75, 75); addButton.TabIndex = 0; addButton.Text = " "; addButton.UseVisualStyleBackColor = true; @@ -84,24 +80,22 @@ dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView1.Dock = DockStyle.Fill; dataGridView1.Location = new Point(0, 0); - dataGridView1.Margin = new Padding(4, 5, 4, 5); dataGridView1.MultiSelect = false; dataGridView1.Name = "dataGridView1"; dataGridView1.ReadOnly = true; dataGridView1.RowHeadersVisible = false; dataGridView1.RowHeadersWidth = 62; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView1.Size = new Size(863, 750); + dataGridView1.Size = new Size(604, 450); dataGridView1.TabIndex = 1; // // FormCases // - AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1066, 750); + ClientSize = new Size(746, 450); Controls.Add(dataGridView1); Controls.Add(panel1); - Margin = new Padding(4, 5, 4, 5); Name = "FormCases"; StartPosition = FormStartPosition.CenterScreen; Text = "Дела"; diff --git a/ProjectGSM/Forms/FormClient.cs b/ProjectGSM/Forms/FormClient.cs index 8971889..a8000a7 100644 --- a/ProjectGSM/Forms/FormClient.cs +++ b/ProjectGSM/Forms/FormClient.cs @@ -23,25 +23,28 @@ namespace ProjectGSM.Forms { set { + try { var client = - _clientRepository.ReadClientById(value); + _clientRepository.ReadClientById(value); if (client == null) { throw new InvalidDataException(nameof(client)); } + + _clientId = value; nameTextBox.Text = client.Name; emailTextBox.Text = client.Email; sexCheckBox.Checked = client.Sex; - dateTimePicker.Value = new DateTime(client.DateOfBirth.Year, client.DateOfBirth.Month, client.DateOfBirth.Day); + dateTimePicker.Value = client.DateOfBirth; phoneText.Text = client.PhoneNumber; adressBox.Text = client.Address; } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, $"Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } @@ -70,13 +73,13 @@ ArgumentNullException(nameof(clientRepository)); } else { - _clientRepository.UpdateClient(CreateClient(0)); + _clientRepository.CreateClient(CreateClient(0)); } Close(); } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBox.Show(ex.Message, $"Ошибка при сохранении {_clientId}", MessageBoxButtons.OK, MessageBoxIcon.Error); } diff --git a/ProjectGSM/Forms/FormCourt.cs b/ProjectGSM/Forms/FormCourt.cs index cc6ef76..152b277 100644 --- a/ProjectGSM/Forms/FormCourt.cs +++ b/ProjectGSM/Forms/FormCourt.cs @@ -23,6 +23,8 @@ namespace ProjectGSM.Forms throw new InvalidDataException(nameof(court)); } + + _courtId = value; nameTextBox.Text = court.Name; adressBox.Text = court.Address; } diff --git a/ProjectGSM/Program.cs b/ProjectGSM/Program.cs index d5e65dd..35a4988 100644 --- a/ProjectGSM/Program.cs +++ b/ProjectGSM/Program.cs @@ -23,7 +23,6 @@ namespace ProjectGSM private static IUnityContainer CreateContainer() { var container = new UnityContainer(); - container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); container.RegisterType(new TransientLifetimeManager()); diff --git a/ProjectGSM/ProjectGSM.csproj b/ProjectGSM/ProjectGSM.csproj index 282209d..461f231 100644 --- a/ProjectGSM/ProjectGSM.csproj +++ b/ProjectGSM/ProjectGSM.csproj @@ -49,7 +49,18 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ProjectGSM/Repositories/ICaseAdvocateRepository.cs b/ProjectGSM/Repositories/ICaseAdvocateRepository.cs deleted file mode 100644 index cf35edb..0000000 --- a/ProjectGSM/Repositories/ICaseAdvocateRepository.cs +++ /dev/null @@ -1,11 +0,0 @@ -using ProjectGSM.Entities; - -namespace ProjectGSM.Repositories; - -public interface ICaseAdvocateRepository -{ - IEnumerable ReadCaseAdvocates(DateTime? dateForm = null, DateTime? dateTo = null, int? caseId = null, - int? advocateId = null); - void CreateCaseAdvocate(CaseAdvocate caseAdvocate); - void DeleteCaseAdvocate(int caseId, int advocateId); -} \ No newline at end of file diff --git a/ProjectGSM/Repositories/ICaseRepository.cs b/ProjectGSM/Repositories/ICaseRepository.cs index 8f3d8ab..ff0f6cf 100644 --- a/ProjectGSM/Repositories/ICaseRepository.cs +++ b/ProjectGSM/Repositories/ICaseRepository.cs @@ -7,6 +7,5 @@ public interface ICaseRepository IEnumerable ReadCases(); Case ReadCaseById(int id); void CreateCase(Case caseEntity); - void UpdateCase(Case caseEntity); void DeleteCase(int id); } \ No newline at end of file diff --git a/ProjectGSM/Repositories/Implementations/CaseAdvocateRepository.cs b/ProjectGSM/Repositories/Implementations/CaseAdvocateRepository.cs deleted file mode 100644 index 488549a..0000000 --- a/ProjectGSM/Repositories/Implementations/CaseAdvocateRepository.cs +++ /dev/null @@ -1,16 +0,0 @@ -using ProjectGSM.Entities; - -namespace ProjectGSM.Repositories.Implementations; - -public class CaseAdvocateRepository : ICaseAdvocateRepository -{ - public IEnumerable ReadCaseAdvocates(DateTime? dateForm = null, DateTime? dateTo = null, - int? caseId = null, int? advocateId = null) - { - return []; - } - - public void CreateCaseAdvocate(CaseAdvocate caseAdvocate) { } - - public void DeleteCaseAdvocate(int caseId, int advocateId) { } -} \ No newline at end of file