119 lines
3.9 KiB
C#
119 lines
3.9 KiB
C#
|
using ProjectGSM.Entities;
|
|||
|
using ProjectGSM.Repositories;
|
|||
|
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;
|
|||
|
|
|||
|
private int? _caseId;
|
|||
|
|
|||
|
public int Id
|
|||
|
{
|
|||
|
set
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var caseE =
|
|||
|
_caseRepository.ReadCaseById(value);
|
|||
|
if (caseE == null)
|
|||
|
{
|
|||
|
throw new
|
|||
|
InvalidDataException(nameof(caseE));
|
|||
|
}
|
|||
|
typeApellBox.SelectedIndex = caseE.TypeAppealId;
|
|||
|
clientBox.SelectedIndex = caseE.ClientId;
|
|||
|
courtBox.SelectedIndex = caseE.CourtId;
|
|||
|
statusBox.SelectedIndex = caseE.StatusId;
|
|||
|
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, IClientRepository clientRepository, ICourtRepository courtRepository, IStatusRepository statusRepository)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_caseRepository = caseRepository ??
|
|||
|
throw new
|
|||
|
ArgumentNullException(nameof(caseRepository));
|
|||
|
|
|||
|
typeApellBox.DataSource = caseRepository.ReadCases();
|
|||
|
typeApellBox.DisplayMember = "Name";
|
|||
|
typeApellBox.ValueMember = "Id";
|
|||
|
|
|||
|
clientBox.DataSource = clientRepository.ReadClients();
|
|||
|
clientBox.DisplayMember = "Name";
|
|||
|
clientBox.ValueMember = "Id";
|
|||
|
|
|||
|
statusBox.DataSource = statusRepository.ReadStatuses();
|
|||
|
statusBox.DisplayMember = "Name";
|
|||
|
statusBox.ValueMember = "Id";
|
|||
|
|
|||
|
courtBox.DataSource = courtRepository.ReadCourts();
|
|||
|
courtBox.DisplayMember = "Name";
|
|||
|
courtBox.ValueMember = "Id";
|
|||
|
}
|
|||
|
|
|||
|
private void saveButton_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{if(typeApellBox.SelectedIndex < 0 || clientBox.SelectedIndex < 0 || statusBox.SelectedIndex < 0 || courtBox.SelectedIndex < 0
|
|||
|
|
|||
|
)
|
|||
|
{
|
|||
|
throw new Exception("Имеются незаполненные поля");
|
|||
|
}
|
|||
|
if (_caseId.HasValue)
|
|||
|
{
|
|||
|
_caseRepository.UpdateCase(CreateCase(_caseId.Value));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_caseRepository.UpdateCase(CreateCase(0));
|
|||
|
}
|
|||
|
Close();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
|||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void cancelButton_Click(object sender, EventArgs e) => Close();
|
|||
|
|
|||
|
private Case CreateCase(int id) => Case.CreateEntity(id,
|
|||
|
typeApellBox.SelectedIndex,
|
|||
|
paymentCheckBox.Checked,
|
|||
|
priceNumeric.Value,
|
|||
|
winPriceNumeric.Value,
|
|||
|
statusBox.SelectedIndex,
|
|||
|
verdictCheckBox.Checked,
|
|||
|
courtBox.SelectedIndex,
|
|||
|
clientBox.SelectedIndex,
|
|||
|
textBox1.Text);
|
|||
|
}
|
|||
|
}
|