lab 1ready

This commit is contained in:
Maxim 2024-11-18 23:50:05 +04:00
parent ac3290f085
commit 5c229cb2ff
11 changed files with 46 additions and 117 deletions

View File

@ -1,4 +1,5 @@
using ProjectGSM.Entities.Enums; using System.Text.Json.Serialization;
using ProjectGSM.Entities.Enums;
namespace ProjectGSM.Entities; namespace ProjectGSM.Entities;
@ -14,7 +15,7 @@ public class Case
public int ClientId { get; private set; } public int ClientId { get; private set; }
public string Description { get; private set; } = string.Empty; public string Description { get; private set; } = string.Empty;
public DateTime CreatedAt { get; private set; } = DateTime.UtcNow; public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
[JsonIgnore]public List<CaseAdvocate> Advocates { get; set; }
// Конструктор для создания сущности // Конструктор для создания сущности
public static Case CreateEntity( public static Case CreateEntity(
int id, int id,

View File

@ -25,6 +25,8 @@ namespace ProjectGSM.Forms
throw new throw new
InvalidDataException(nameof(advocate)); InvalidDataException(nameof(advocate));
} }
_advocateId = value;
foreach (LicenseType elem in Enum.GetValues(typeof(LicenseType))) foreach (LicenseType elem in Enum.GetValues(typeof(LicenseType)))
{ {
if ((elem & advocate.LicenseType) != 0) if ((elem & advocate.LicenseType) != 0)
@ -84,7 +86,7 @@ namespace ProjectGSM.Forms
} }
else else
{ {
_advocateRepository.UpdateAdvocate(CreateAdvocate(0)); _advocateRepository.CreateAdvocate(CreateAdvocate(0));
} }
Close(); Close();
} }

View File

@ -1,16 +1,6 @@
using ProjectGSM.Entities; using ProjectGSM.Entities;
using ProjectGSM.Entities.Enums; using ProjectGSM.Entities.Enums;
using ProjectGSM.Repositories; 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 namespace ProjectGSM.Forms
{ {
@ -19,50 +9,13 @@ namespace ProjectGSM.Forms
{ {
private readonly ICaseRepository _caseRepository; private readonly ICaseRepository _caseRepository;
private readonly ICaseAdvocateRepository _caseAdvocateRepository;
private int? _caseId; public FormCase(ICaseRepository caseRepository,IClientRepository clientRepository, ICourtRepository courtRepository, IAdvocateRepository advocateRepository)
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)
{ {
InitializeComponent(); InitializeComponent();
_caseRepository = caseRepository ?? _caseRepository = caseRepository ??
throw new throw new
ArgumentNullException(nameof(caseRepository)); ArgumentNullException(nameof(caseRepository));
_caseAdvocateRepository = caseAdvocateRepository ?? throw new ArgumentNullException(nameof(caseAdvocateRepository));
typeApellBox.DataSource = Enum.GetValues(typeof(TypeAppeal)); typeApellBox.DataSource = Enum.GetValues(typeof(TypeAppeal));
@ -88,18 +41,10 @@ namespace ProjectGSM.Forms
{ {
throw new Exception("Имеются незаполненные поля"); throw new Exception("Имеются незаполненные поля");
} }
if (_caseId.HasValue)
{ Case caseE = CreateCase(0);
_caseRepository.UpdateCase(CreateCase(_caseId.Value)); caseE.Advocates = CreateListCaseAdvocateFromDataGrid();
} _caseRepository.CreateCase(caseE);
else
{
_caseRepository.UpdateCase(CreateCase(0));
}
foreach (CaseAdvocate row in CreateListCaseAdvocateFromDataGrid())
{
_caseAdvocateRepository.CreateCaseAdvocate(CaseAdvocate.CreateEntity(row.CaseId, row.AdvocateId, row.Post));
}
Close(); Close();
} }
catch (Exception ex) catch (Exception ex)
@ -118,13 +63,13 @@ namespace ProjectGSM.Forms
var list = new List<CaseAdvocate>(); var list = new List<CaseAdvocate>();
foreach (DataGridViewRow row in dataGridView1.Rows) foreach (DataGridViewRow row in dataGridView1.Rows)
{ {
if (row.Cells["ColumnAdvocates"].Value == null || if (row.Cells["ColumnAdvocate"].Value == null ||
row.Cells["ColumnPost"].Value == null) row.Cells["ColumnPost"].Value == null)
{ {
continue; continue;
} }
list.Add(CaseAdvocate.CreateEntity(0, list.Add(CaseAdvocate.CreateEntity(0,
Convert.ToInt32(row.Cells["ColumnAdvocates"].Value), Convert.ToInt32(row.Cells["ColumnAdvocate"].Value),
row.Cells["ColumnPost"].Value.ToString()??string.Empty)); row.Cells["ColumnPost"].Value.ToString()??string.Empty));
} }
return list; return list;

View File

@ -41,33 +41,29 @@
panel1.Controls.Add(deleteButton); panel1.Controls.Add(deleteButton);
panel1.Controls.Add(addButton); panel1.Controls.Add(addButton);
panel1.Dock = DockStyle.Right; panel1.Dock = DockStyle.Right;
panel1.Location = new Point(863, 0); panel1.Location = new Point(604, 0);
panel1.Margin = new Padding(4, 5, 4, 5);
panel1.Name = "panel1"; panel1.Name = "panel1";
panel1.Size = new Size(203, 750); panel1.Size = new Size(142, 450);
panel1.TabIndex = 0; panel1.TabIndex = 0;
// //
// deleteButton // deleteButton
// //
deleteButton.BackgroundImage = Properties.Resources.circle_x_svgrepo_com; deleteButton.BackgroundImage = Properties.Resources.circle_x_svgrepo_com;
deleteButton.BackgroundImageLayout = ImageLayout.Zoom; deleteButton.BackgroundImageLayout = ImageLayout.Stretch;
deleteButton.Location = new Point(47, 400); deleteButton.Location = new Point(33, 137);
deleteButton.Margin = new Padding(4, 5, 4, 5); deleteButton.Margin = new Padding(2, 2, 2, 2);
deleteButton.Name = "deleteButton"; deleteButton.Name = "deleteButton";
deleteButton.Size = new Size(107, 125); deleteButton.Size = new Size(75, 72);
deleteButton.TabIndex = 2; deleteButton.TabIndex = 0;
deleteButton.Text = " ";
deleteButton.UseVisualStyleBackColor = true;
deleteButton.Click += deleteButton_Click; deleteButton.Click += deleteButton_Click;
// //
// addButton // addButton
// //
addButton.BackgroundImage = Properties.Resources.circle_plus_svgrepo_com; addButton.BackgroundImage = Properties.Resources.circle_plus_svgrepo_com;
addButton.BackgroundImageLayout = ImageLayout.Zoom; addButton.BackgroundImageLayout = ImageLayout.Zoom;
addButton.Location = new Point(47, 63); addButton.Location = new Point(33, 38);
addButton.Margin = new Padding(4, 5, 4, 5);
addButton.Name = "addButton"; addButton.Name = "addButton";
addButton.Size = new Size(107, 125); addButton.Size = new Size(75, 75);
addButton.TabIndex = 0; addButton.TabIndex = 0;
addButton.Text = " "; addButton.Text = " ";
addButton.UseVisualStyleBackColor = true; addButton.UseVisualStyleBackColor = true;
@ -84,24 +80,22 @@
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView1.Dock = DockStyle.Fill; dataGridView1.Dock = DockStyle.Fill;
dataGridView1.Location = new Point(0, 0); dataGridView1.Location = new Point(0, 0);
dataGridView1.Margin = new Padding(4, 5, 4, 5);
dataGridView1.MultiSelect = false; dataGridView1.MultiSelect = false;
dataGridView1.Name = "dataGridView1"; dataGridView1.Name = "dataGridView1";
dataGridView1.ReadOnly = true; dataGridView1.ReadOnly = true;
dataGridView1.RowHeadersVisible = false; dataGridView1.RowHeadersVisible = false;
dataGridView1.RowHeadersWidth = 62; dataGridView1.RowHeadersWidth = 62;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView1.Size = new Size(863, 750); dataGridView1.Size = new Size(604, 450);
dataGridView1.TabIndex = 1; dataGridView1.TabIndex = 1;
// //
// FormCases // FormCases
// //
AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1066, 750); ClientSize = new Size(746, 450);
Controls.Add(dataGridView1); Controls.Add(dataGridView1);
Controls.Add(panel1); Controls.Add(panel1);
Margin = new Padding(4, 5, 4, 5);
Name = "FormCases"; Name = "FormCases";
StartPosition = FormStartPosition.CenterScreen; StartPosition = FormStartPosition.CenterScreen;
Text = "Дела"; Text = "Дела";

View File

@ -23,25 +23,28 @@ namespace ProjectGSM.Forms
{ {
set set
{ {
try try
{ {
var client = var client =
_clientRepository.ReadClientById(value); _clientRepository.ReadClientById(value);
if (client == null) if (client == null)
{ {
throw new throw new
InvalidDataException(nameof(client)); InvalidDataException(nameof(client));
} }
_clientId = value;
nameTextBox.Text = client.Name; nameTextBox.Text = client.Name;
emailTextBox.Text = client.Email; emailTextBox.Text = client.Email;
sexCheckBox.Checked = client.Sex; 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; phoneText.Text = client.PhoneNumber;
adressBox.Text = client.Address; adressBox.Text = client.Address;
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, $"Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
} }
@ -70,13 +73,13 @@ ArgumentNullException(nameof(clientRepository));
} }
else else
{ {
_clientRepository.UpdateClient(CreateClient(0)); _clientRepository.CreateClient(CreateClient(0));
} }
Close(); Close();
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBox.Show(ex.Message, $"Ошибка при сохранении {_clientId}",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);
} }

View File

@ -23,6 +23,8 @@ namespace ProjectGSM.Forms
throw new throw new
InvalidDataException(nameof(court)); InvalidDataException(nameof(court));
} }
_courtId = value;
nameTextBox.Text = court.Name; nameTextBox.Text = court.Name;
adressBox.Text = court.Address; adressBox.Text = court.Address;
} }

View File

@ -23,7 +23,6 @@ namespace ProjectGSM
private static IUnityContainer CreateContainer() private static IUnityContainer CreateContainer()
{ {
var container = new UnityContainer(); var container = new UnityContainer();
container.RegisterType<IAdvocateRepository, AdvocateRepository>(new TransientLifetimeManager());
container.RegisterType<ICaseAdvocateRepository, CaseAdvocateRepository>(new TransientLifetimeManager()); container.RegisterType<ICaseAdvocateRepository, CaseAdvocateRepository>(new TransientLifetimeManager());
container.RegisterType<ICaseRepository, CaseRepository>(new TransientLifetimeManager()); container.RegisterType<ICaseRepository, CaseRepository>(new TransientLifetimeManager());
container.RegisterType<IClientRepository, ClientRepository>(new TransientLifetimeManager()); container.RegisterType<IClientRepository, ClientRepository>(new TransientLifetimeManager());

View File

@ -49,7 +49,18 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Npgsql" Version="9.0.0" />
<PackageReference Include="Serilog" Version="4.2.0-dev-02328" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.1-dev-10410" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
<PackageReference Include="Unity" Version="5.11.10" /> <PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,11 +0,0 @@
using ProjectGSM.Entities;
namespace ProjectGSM.Repositories;
public interface ICaseAdvocateRepository
{
IEnumerable<CaseAdvocate> ReadCaseAdvocates(DateTime? dateForm = null, DateTime? dateTo = null, int? caseId = null,
int? advocateId = null);
void CreateCaseAdvocate(CaseAdvocate caseAdvocate);
void DeleteCaseAdvocate(int caseId, int advocateId);
}

View File

@ -7,6 +7,5 @@ public interface ICaseRepository
IEnumerable<Case> ReadCases(); IEnumerable<Case> ReadCases();
Case ReadCaseById(int id); Case ReadCaseById(int id);
void CreateCase(Case caseEntity); void CreateCase(Case caseEntity);
void UpdateCase(Case caseEntity);
void DeleteCase(int id); void DeleteCase(int id);
} }

View File

@ -1,16 +0,0 @@
using ProjectGSM.Entities;
namespace ProjectGSM.Repositories.Implementations;
public class CaseAdvocateRepository : ICaseAdvocateRepository
{
public IEnumerable<CaseAdvocate> 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) { }
}