2024-11-05 03:59:13 +04:00
|
|
|
|
using ProjectGSM.Entities;
|
2024-11-09 03:06:08 +04:00
|
|
|
|
using ProjectGSM.Entities.Enums;
|
2024-11-05 03:59:13 +04:00
|
|
|
|
using ProjectGSM.Repositories;
|
2024-11-09 03:06:08 +04:00
|
|
|
|
using ProjectGSM.Repositories.Implementations;
|
2024-11-05 03:59:13 +04:00
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public partial class FormCase : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly ICaseRepository _caseRepository;
|
|
|
|
|
|
2024-11-09 03:06:08 +04:00
|
|
|
|
private readonly ICaseAdvocateRepository _caseAdvocateRepository;
|
|
|
|
|
|
2024-11-05 03:59:13 +04:00
|
|
|
|
private int? _caseId;
|
|
|
|
|
|
|
|
|
|
public int Id
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var caseE =
|
|
|
|
|
_caseRepository.ReadCaseById(value);
|
|
|
|
|
if (caseE == null)
|
|
|
|
|
{
|
|
|
|
|
throw new
|
|
|
|
|
InvalidDataException(nameof(caseE));
|
|
|
|
|
}
|
2024-11-09 03:06:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typeApellBox.SelectedItem = caseE.TypeAppeal;
|
2024-11-05 03:59:13 +04:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-11-09 03:06:08 +04:00
|
|
|
|
public FormCase(ICaseRepository caseRepository, ICaseAdvocateRepository caseAdvocateRepository,IClientRepository clientRepository, ICourtRepository courtRepository, IAdvocateRepository advocateRepository)
|
2024-11-05 03:59:13 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_caseRepository = caseRepository ??
|
|
|
|
|
throw new
|
|
|
|
|
ArgumentNullException(nameof(caseRepository));
|
2024-11-09 03:06:08 +04:00
|
|
|
|
_caseAdvocateRepository = caseAdvocateRepository ?? throw new ArgumentNullException(nameof(caseAdvocateRepository));
|
|
|
|
|
|
|
|
|
|
typeApellBox.DataSource = Enum.GetValues(typeof(TypeAppeal));
|
2024-11-05 03:59:13 +04:00
|
|
|
|
|
2024-11-09 03:06:08 +04:00
|
|
|
|
ColumnAdvocate.DataSource = advocateRepository.ReadAdvocates();
|
|
|
|
|
ColumnAdvocate.DisplayMember = "Name";
|
|
|
|
|
ColumnAdvocate.ValueMember = "Id";
|
2024-11-05 03:59:13 +04:00
|
|
|
|
|
|
|
|
|
clientBox.DataSource = clientRepository.ReadClients();
|
|
|
|
|
clientBox.DisplayMember = "Name";
|
|
|
|
|
clientBox.ValueMember = "Id";
|
|
|
|
|
|
|
|
|
|
courtBox.DataSource = courtRepository.ReadCourts();
|
|
|
|
|
courtBox.DisplayMember = "Name";
|
|
|
|
|
courtBox.ValueMember = "Id";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
2024-11-09 03:06:08 +04:00
|
|
|
|
{if(dataGridView1.RowCount < 1 || typeApellBox.SelectedIndex < 0 || clientBox.SelectedIndex < 0 || courtBox.SelectedIndex < 0
|
2024-11-05 03:59:13 +04:00
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Имеются незаполненные поля");
|
|
|
|
|
}
|
|
|
|
|
if (_caseId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
_caseRepository.UpdateCase(CreateCase(_caseId.Value));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_caseRepository.UpdateCase(CreateCase(0));
|
|
|
|
|
}
|
2024-11-09 03:06:08 +04:00
|
|
|
|
foreach (CaseAdvocate row in CreateListCaseAdvocateFromDataGrid())
|
|
|
|
|
{
|
|
|
|
|
_caseAdvocateRepository.CreateCaseAdvocate(CaseAdvocate.CreateEntity(row.CaseId, row.AdvocateId, row.Post));
|
|
|
|
|
}
|
2024-11-05 03:59:13 +04:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cancelButton_Click(object sender, EventArgs e) => Close();
|
|
|
|
|
|
2024-11-09 03:06:08 +04:00
|
|
|
|
|
|
|
|
|
private List<CaseAdvocate> CreateListCaseAdvocateFromDataGrid()
|
|
|
|
|
{
|
|
|
|
|
var list = new List<CaseAdvocate>();
|
|
|
|
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
|
|
|
|
{
|
|
|
|
|
if (row.Cells["ColumnAdvocates"].Value == null ||
|
|
|
|
|
row.Cells["ColumnPost"].Value == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
list.Add(CaseAdvocate.CreateEntity(0,
|
|
|
|
|
Convert.ToInt32(row.Cells["ColumnAdvocates"].Value),
|
|
|
|
|
row.Cells["ColumnPost"].Value.ToString()??string.Empty));
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-11-05 03:59:13 +04:00
|
|
|
|
private Case CreateCase(int id) => Case.CreateEntity(id,
|
2024-11-09 03:06:08 +04:00
|
|
|
|
(TypeAppeal)typeApellBox.SelectedItem!,
|
2024-11-05 03:59:13 +04:00
|
|
|
|
paymentCheckBox.Checked,
|
|
|
|
|
priceNumeric.Value,
|
|
|
|
|
winPriceNumeric.Value,
|
|
|
|
|
verdictCheckBox.Checked,
|
|
|
|
|
courtBox.SelectedIndex,
|
|
|
|
|
clientBox.SelectedIndex,
|
|
|
|
|
textBox1.Text);
|
|
|
|
|
}
|
|
|
|
|
}
|