73 lines
2.3 KiB
C#
73 lines
2.3 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()
|
|
{
|
|
dataGridView.DataSource =
|
|
_statusHistoryRepository.ReadStatusHistories();
|
|
dataGridView.Columns["CaseId"].Visible = false;
|
|
dataGridView.Columns["CreatedAt"].DefaultCellStyle.Format =
|
|
"dd.MM.yyyy";
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
} |