66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
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;
|
|
using System.Xml.Linq;
|
|
using ProjectAirline.Repositories;
|
|
using Unity;
|
|
|
|
namespace ProjectAirline.Forms
|
|
{
|
|
public partial class FormTickets : Form
|
|
{
|
|
private readonly IUnityContainer _container;
|
|
private readonly ITicketRepository _ticketRepository;
|
|
public FormTickets(IUnityContainer container, ITicketRepository ticketRepository)
|
|
{
|
|
InitializeComponent();
|
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
|
_ticketRepository = ticketRepository ?? throw new ArgumentNullException(nameof(ticketRepository));
|
|
}
|
|
private void FormTickets_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
LoadList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_container.Resolve<FormTicket>().ShowDialog();
|
|
LoadList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
|
|
private void LoadList() => dataGridView.DataSource = _ticketRepository.ReadTickets();
|
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
|
{
|
|
id = 0;
|
|
if (dataGridView.SelectedRows.Count < 1)
|
|
{
|
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return false;
|
|
}
|
|
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
return true;
|
|
}
|
|
}
|
|
}
|