93 lines
3.3 KiB
C#
Raw Normal View History

2023-03-06 17:15:03 +04:00
using Microsoft.Extensions.Logging;
2023-04-18 15:02:12 +04:00
using SecuritySystemView;
2023-03-06 17:15:03 +04:00
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
2023-05-16 01:43:26 +04:00
using SecuritySystemContracts.DI;
2023-03-06 17:15:03 +04:00
namespace SecuritySystemView
{
2023-04-23 10:08:28 +04:00
public partial class FormSecures : Form
2023-03-06 17:15:03 +04:00
{
private readonly ILogger _logger;
2023-03-07 12:47:29 +04:00
private readonly ISecureLogic _logic;
2023-04-23 10:08:28 +04:00
public FormSecures(ILogger<FormSecures> logger, ISecureLogic logic)
2023-03-06 17:15:03 +04:00
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
2023-04-23 10:08:28 +04:00
private void FormSecures_Load(object sender, EventArgs e)
2023-03-06 17:15:03 +04:00
{
LoadData();
}
private void LoadData()
{
try
{
2023-05-16 01:43:26 +04:00
dataGridView.FillandConfigGrid(_logic.ReadList(null));
_logger.LogInformation("Загрузка изделий");
2023-03-06 17:15:03 +04:00
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки изделий");
2023-05-16 01:43:26 +04:00
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
2023-03-06 17:15:03 +04:00
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
2023-05-16 01:43:26 +04:00
var form = DependencyManager.Instance.Resolve <FormSecure>();
2023-03-06 17:15:03 +04:00
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
2023-05-16 01:43:26 +04:00
var form = DependencyManager.Instance.Resolve <FormSecure>();
2023-03-06 17:15:03 +04:00
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
2023-05-16 01:43:26 +04:00
if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
2023-03-06 17:15:03 +04:00
{
2023-05-16 01:43:26 +04:00
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
2023-03-06 17:15:03 +04:00
_logger.LogInformation("Удаление изделия");
try
{
2023-05-16 01:43:26 +04:00
if (!_logic.Delete(new SecureBindingModel
{
Id = id
}))
2023-03-06 17:15:03 +04:00
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
2023-05-16 01:43:26 +04:00
_logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
2023-03-06 17:15:03 +04:00
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}