2024-12-03 13:25:56 +04:00
|
|
|
|
using Publication.Repositories;
|
|
|
|
|
using Publication.Repositories.Implementations;
|
|
|
|
|
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 Publication.Forms;
|
|
|
|
|
|
|
|
|
|
public partial class FormPublishingHouses : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly IUnityContainer container;
|
|
|
|
|
private readonly IPublisingHouseRepository publisingHouseRepository;
|
|
|
|
|
public FormPublishingHouses(IUnityContainer _container, IPublisingHouseRepository _publisingHouseRepository)
|
|
|
|
|
{
|
|
|
|
|
container = _container ?? throw new ArgumentNullException(nameof(_container));
|
|
|
|
|
publisingHouseRepository = _publisingHouseRepository ?? throw new ArgumentNullException(nameof(_publisingHouseRepository));
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonAdd_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
container.Resolve<FormPublishingHouse>().ShowDialog();
|
|
|
|
|
LoadList();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonEdit_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var form = container.Resolve<FormPublishingHouse>();
|
|
|
|
|
form.Id = findId;
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
LoadList();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonDelete_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!TryGetIdentifierFromSelectedRow(out var findId))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
publisingHouseRepository.DeletePublishingHouse(findId);
|
|
|
|
|
LoadList();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormPublishingHouses_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
LoadList();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка при загрузке",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-20 08:53:10 +04:00
|
|
|
|
private void LoadList()
|
|
|
|
|
{
|
|
|
|
|
dataGridView1.DataSource = publisingHouseRepository.ReadPublishingHouses();
|
|
|
|
|
dataGridView1.Columns["Id"].Visible = false;
|
|
|
|
|
}
|
2024-12-03 13:25:56 +04:00
|
|
|
|
}
|