PIBD14-Boyko-M.S.-GSM-Autot.../ProjectGSM/Forms/FormStatusesHistory.cs

73 lines
2.3 KiB
C#
Raw Permalink Normal View History

2024-11-05 03:59:13 +04:00
using ProjectGSM.Repositories;
using Unity;
namespace ProjectGSM.Forms
{
public partial class FormStatusesHistory : Form
{
private readonly IUnityContainer _container;
private readonly IStatusHistoryRepository _statusHistoryRepository;
2024-12-16 23:03:26 +04:00
2024-11-05 03:59:13 +04:00
public FormStatusesHistory(IUnityContainer container, IStatusHistoryRepository statusHistoryRepository)
{
InitializeComponent();
_container = container ??
2024-12-16 23:03:26 +04:00
throw new ArgumentNullException(nameof(container));
2024-11-05 03:59:13 +04:00
_statusHistoryRepository = statusHistoryRepository ??
2024-12-16 23:03:26 +04:00
throw new
ArgumentNullException(nameof(statusHistoryRepository));
2024-11-05 03:59:13 +04:00
}
2024-12-16 23:03:26 +04:00
2024-11-05 03:59:13 +04:00
private void addButton_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormStatusHistory>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении",
2024-12-16 23:03:26 +04:00
MessageBoxButtons.OK, MessageBoxIcon.Error);
2024-11-05 03:59:13 +04:00
}
}
private void FormClients_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке",
2024-12-16 23:03:26 +04:00
MessageBoxButtons.OK, MessageBoxIcon.Error);
2024-11-05 03:59:13 +04:00
}
}
2024-12-16 23:03:26 +04:00
private void LoadList()
{
dataGridView.DataSource =
_statusHistoryRepository.ReadStatusHistories();
2024-12-17 01:21:56 +04:00
dataGridView.Columns["CaseId"].Visible = false;
2024-12-16 23:03:26 +04:00
dataGridView.Columns["CreatedAt"].DefaultCellStyle.Format =
"dd.MM.yyyy";
}
2024-11-05 03:59:13 +04:00
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
2024-12-16 23:03:26 +04:00
if (dataGridView.SelectedRows.Count < 1)
2024-11-05 03:59:13 +04:00
{
MessageBox.Show("Нет выбранной записи", "Ошибка",
2024-12-16 23:03:26 +04:00
MessageBoxButtons.OK, MessageBoxIcon.Error);
2024-11-05 03:59:13 +04:00
return false;
}
2024-12-16 23:03:26 +04:00
2024-11-05 03:59:13 +04:00
id =
2024-12-16 23:03:26 +04:00
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
2024-11-05 03:59:13 +04:00
return true;
}
}
2024-12-16 23:03:26 +04:00
}