2024-11-19 14:49:58 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using ProjectLibrary.Entites;
|
|
|
|
|
using ProjectLibrary.Entities;
|
2024-11-19 19:46:02 +04:00
|
|
|
|
using ProjectLibrary.Repositories;
|
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-19 19:46:02 +04:00
|
|
|
|
public int ID
|
2024-11-19 14:49:58 +04:00
|
|
|
|
{
|
2024-11-19 19:46:02 +04:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var ticketExtension = _ticketExtensionsRepository.GetTicketExtensionById(value);
|
|
|
|
|
|
|
|
|
|
if (ticketExtension == null)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException($"Ticket extension with ID {value} not found.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
txtReaderID.Text = ticketExtension.ReaderID.ToString();
|
|
|
|
|
dtpLastUpdateDate.Value = ticketExtension.LastUpdateDate;
|
|
|
|
|
dtpNextUpdateDate.Value = ticketExtension.NextUpdateDate;
|
|
|
|
|
|
|
|
|
|
_extensionId = value;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "[ Error : wrong data ]", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-19 14:49:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-19 19:46:02 +04:00
|
|
|
|
public FTicket_Extension(ITicketExtensionsRepository ticketExtensionsRepository)
|
2024-11-19 14:49:58 +04:00
|
|
|
|
{
|
2024-11-19 19:46:02 +04:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
_ticketExtensionsRepository = ticketExtensionsRepository ?? throw new ArgumentNullException(nameof(ticketExtensionsRepository));
|
2024-11-19 14:49:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-19 19:46:02 +04:00
|
|
|
|
private void SaveBtn_Click(object sender, EventArgs e)
|
2024-11-19 14:49:58 +04:00
|
|
|
|
{
|
2024-11-19 19:46:02 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(txtReaderID.Text))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("[ Error : blank spaces were left, not enough information ]");
|
|
|
|
|
}
|
2024-11-19 14:49:58 +04:00
|
|
|
|
|
2024-11-19 19:46:02 +04:00
|
|
|
|
var ticketExtension = CreateTicketExtension();
|
2024-11-19 14:49:58 +04:00
|
|
|
|
|
2024-11-19 19:46:02 +04:00
|
|
|
|
if (_extensionId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
_ticketExtensionsRepository.UpdateTicketExtension(ticketExtension);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_ticketExtensionsRepository.AddTicketExtension(ticketExtension);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MessageBox.Show("Данные успешно сохранены!", "[ Success ]", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "[ Error : while saving ]", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DiscardBtn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
2024-11-19 14:49:58 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-19 19:46:02 +04:00
|
|
|
|
private TicketExtensions CreateTicketExtension()
|
2024-11-19 14:49:58 +04:00
|
|
|
|
{
|
2024-11-19 19:46:02 +04:00
|
|
|
|
return TicketExtensions.CreateEntity(
|
|
|
|
|
int.Parse(txtReaderID.Text),
|
|
|
|
|
dtpLastUpdateDate.Value,
|
|
|
|
|
dtpNextUpdateDate.Value
|
|
|
|
|
);
|
2024-11-19 14:49:58 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|