2024-11-20 19:31:06 +04:00
|
|
|
|
using ProjectLibrary.Entites;
|
|
|
|
|
using ProjectLibrary.Repositores;
|
2024-11-19 14:49:58 +04:00
|
|
|
|
|
|
|
|
|
namespace ProjectLibrary.Forms
|
|
|
|
|
{
|
|
|
|
|
public partial class FTicket_Extension : Form
|
|
|
|
|
{
|
2024-11-19 19:46:02 +04:00
|
|
|
|
private readonly ITicketExtensionsRepository _ticketExtensionsRepository;
|
|
|
|
|
private int? _extensionId;
|
2024-11-19 14:49:58 +04:00
|
|
|
|
|
2024-11-20 19:31:06 +04:00
|
|
|
|
public int Id
|
2024-11-19 14:49:58 +04:00
|
|
|
|
{
|
2024-11-19 19:46:02 +04:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-11-20 19:31:06 +04:00
|
|
|
|
var ticket = _ticketExtensionsRepository.ReadTicketExtensionById(value);
|
|
|
|
|
if (ticket == null)
|
2024-11-19 19:46:02 +04:00
|
|
|
|
{
|
2024-11-20 19:31:06 +04:00
|
|
|
|
throw new InvalidOperationException("Заказ не найден.");
|
2024-11-19 19:46:02 +04:00
|
|
|
|
}
|
2024-11-20 19:31:06 +04:00
|
|
|
|
comboBoxId.SelectedItem = ticket.ReaderID;
|
|
|
|
|
dtpLastUpdateDate.Text = ticket.LastUpdateDate.ToString();
|
|
|
|
|
dtpNextUpdateDate.Text = ticket.NextUpdateDate.ToString();
|
2024-11-19 19:46:02 +04:00
|
|
|
|
_extensionId = value;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-11-20 19:31:06 +04:00
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при загрузке данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2024-11-19 19:46:02 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-19 14:49:58 +04:00
|
|
|
|
}
|
2024-11-20 19:31:06 +04:00
|
|
|
|
public FTicket_Extension(ITicketExtensionsRepository ticketRepository)
|
2024-11-19 14:49:58 +04:00
|
|
|
|
{
|
2024-11-19 19:46:02 +04:00
|
|
|
|
InitializeComponent();
|
2024-11-20 19:31:06 +04:00
|
|
|
|
_ticketExtensionsRepository = ticketRepository ?? throw new ArgumentNullException(nameof(ticketRepository));
|
2024-11-19 14:49:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-20 19:31:06 +04:00
|
|
|
|
private void btnSave_Click(object sender, EventArgs e)
|
2024-11-19 14:49:58 +04:00
|
|
|
|
{
|
2024-11-19 19:46:02 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
2024-11-20 19:31:06 +04:00
|
|
|
|
if (string.IsNullOrWhiteSpace(dtpLastUpdateDate.Text) || string.IsNullOrWhiteSpace(dtpNextUpdateDate.Text) || comboBoxId.SelectedItem == null)
|
2024-11-19 19:46:02 +04:00
|
|
|
|
{
|
2024-11-20 19:31:06 +04:00
|
|
|
|
throw new Exception("Не все поля заполнены.");
|
2024-11-19 19:46:02 +04:00
|
|
|
|
}
|
2024-11-19 14:49:58 +04:00
|
|
|
|
|
2024-11-20 19:31:06 +04:00
|
|
|
|
var ticket = TicketExtensions.CreateEntity(
|
|
|
|
|
_extensionId ?? 0,
|
|
|
|
|
DateTime.Parse(dtpLastUpdateDate.Text),
|
|
|
|
|
DateTime.Parse(dtpNextUpdateDate.Text)
|
|
|
|
|
);
|
2024-11-19 14:49:58 +04:00
|
|
|
|
|
2024-11-19 19:46:02 +04:00
|
|
|
|
if (_extensionId.HasValue)
|
|
|
|
|
{
|
2024-11-20 19:31:06 +04:00
|
|
|
|
_ticketExtensionsRepository.UpdateTicketExtension(ticket);
|
2024-11-19 19:46:02 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-11-20 19:31:06 +04:00
|
|
|
|
_ticketExtensionsRepository.CreateTicketExtension(ticket);
|
2024-11-19 19:46:02 +04:00
|
|
|
|
}
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-11-20 19:31:06 +04:00
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при сохранении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2024-11-19 19:46:02 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-20 19:31:06 +04:00
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
2024-11-19 14:49:58 +04:00
|
|
|
|
{
|
2024-11-20 19:31:06 +04:00
|
|
|
|
this.Close();
|
2024-11-19 14:49:58 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|