2024-11-05 03:59:13 +04:00
|
|
|
|
using ProjectGSM.Repositories;
|
|
|
|
|
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 Unity;
|
|
|
|
|
|
|
|
|
|
namespace ProjectGSM.Forms
|
|
|
|
|
{
|
|
|
|
|
public partial class FormAdvocates : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly IUnityContainer _container;
|
|
|
|
|
|
|
|
|
|
private readonly IAdvocateRepository _advocateRepository;
|
|
|
|
|
public FormAdvocates(IUnityContainer container, IAdvocateRepository advocateRepository)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_container = container ??
|
|
|
|
|
throw new ArgumentNullException(nameof(container));
|
|
|
|
|
_advocateRepository = advocateRepository ??
|
|
|
|
|
throw new
|
|
|
|
|
ArgumentNullException(nameof(advocateRepository));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void deleteButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show("Удалить запись?", "Удаление",
|
|
|
|
|
MessageBoxButtons.YesNo) != DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_advocateRepository.DeleteAdvocate(findId);
|
|
|
|
|
LoadList();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при удалении",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void editButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var form = _container.Resolve<FormAdvocate>();
|
|
|
|
|
form.Id = findId;
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
LoadList();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при изменении",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_container.Resolve<FormAdvocate>().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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-16 23:03:26 +04:00
|
|
|
|
private void LoadList() {
|
|
|
|
|
dataGridViewAdvocats.DataSource =
|
|
|
|
|
_advocateRepository.ReadAdvocates();
|
|
|
|
|
dataGridViewAdvocats.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 21:44:10 +04:00
|
|
|
|
if (dataGridViewAdvocats.SelectedRows.Count < 1)
|
2024-11-05 03:59:13 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Нет выбранной записи", "Ошибка",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
id =
|
2024-12-16 21:44:10 +04:00
|
|
|
|
Convert.ToInt32(dataGridViewAdvocats.SelectedRows[0].Cells["Id"].Value);
|
2024-11-05 03:59:13 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|