lab 1ready
This commit is contained in:
parent
ac3290f085
commit
5c229cb2ff
@ -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<CaseAdvocate> Advocates { get; set; }
|
||||
// Конструктор для создания сущности
|
||||
public static Case CreateEntity(
|
||||
int id,
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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<CaseAdvocate>();
|
||||
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;
|
||||
|
30
ProjectGSM/Forms/FormCases.Designer.cs
generated
30
ProjectGSM/Forms/FormCases.Designer.cs
generated
@ -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 = "Дела";
|
||||
|
@ -23,6 +23,7 @@ namespace ProjectGSM.Forms
|
||||
{
|
||||
set
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var client =
|
||||
@ -32,16 +33,18 @@ namespace ProjectGSM.Forms
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,8 @@ namespace ProjectGSM.Forms
|
||||
throw new
|
||||
InvalidDataException(nameof(court));
|
||||
}
|
||||
|
||||
_courtId = value;
|
||||
nameTextBox.Text = court.Name;
|
||||
adressBox.Text = court.Address;
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ namespace ProjectGSM
|
||||
private static IUnityContainer CreateContainer()
|
||||
{
|
||||
var container = new UnityContainer();
|
||||
container.RegisterType<IAdvocateRepository, AdvocateRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<ICaseAdvocateRepository, CaseAdvocateRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<ICaseRepository, CaseRepository>(new TransientLifetimeManager());
|
||||
container.RegisterType<IClientRepository, ClientRepository>(new TransientLifetimeManager());
|
||||
|
@ -49,7 +49,18 @@
|
||||
</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.Microsoft.Logging" Version="5.11.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -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);
|
||||
}
|
@ -7,6 +7,5 @@ public interface ICaseRepository
|
||||
IEnumerable<Case> ReadCases();
|
||||
Case ReadCaseById(int id);
|
||||
void CreateCase(Case caseEntity);
|
||||
void UpdateCase(Case caseEntity);
|
||||
void DeleteCase(int id);
|
||||
}
|
@ -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) { }
|
||||
}
|
Loading…
Reference in New Issue
Block a user