69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
|
using ProjectGSM.Repositories;
|
|||
|
using Unity;
|
|||
|
|
|||
|
namespace ProjectGSM.Forms
|
|||
|
{
|
|||
|
public partial class FormStatusesHistory : Form
|
|||
|
{
|
|||
|
private readonly IUnityContainer _container;
|
|||
|
|
|||
|
private readonly IStatusHistoryRepository _statusHistoryRepository;
|
|||
|
public FormStatusesHistory(IUnityContainer container, IStatusHistoryRepository statusHistoryRepository)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_container = container ??
|
|||
|
throw new ArgumentNullException(nameof(container));
|
|||
|
_statusHistoryRepository = statusHistoryRepository ??
|
|||
|
throw new
|
|||
|
ArgumentNullException(nameof(statusHistoryRepository));
|
|||
|
|
|||
|
}
|
|||
|
private void addButton_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_container.Resolve<FormStatusHistory>().ShowDialog();
|
|||
|
LoadList();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message, "Ошибка при добавлении",
|
|||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void FormClients_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
LoadList();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message, "Ошибка при загрузке",
|
|||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void LoadList() => dataGridView1.DataSource =
|
|||
|
_statusHistoryRepository.ReadStatusHistories();
|
|||
|
|
|||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
|||
|
{
|
|||
|
id = 0;
|
|||
|
if (dataGridView1.SelectedRows.Count < 1)
|
|||
|
{
|
|||
|
MessageBox.Show("Нет выбранной записи", "Ошибка",
|
|||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
return false;
|
|||
|
}
|
|||
|
id =
|
|||
|
Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|