ISEbd-22_Rozhkov.I.E._Simple/GasStation/Forms/FormSellings.cs

55 lines
1.7 KiB
C#

using GasStation.Repositories;
using Unity;
namespace GasStation.Forms
{
public partial class FormSellings : Form
{
private readonly IUnityContainer _container;
private readonly ISellingRepository _sellingRepository;
public FormSellings(IUnityContainer container, ISellingRepository sellingRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_sellingRepository = sellingRepository ??
throw new ArgumentNullException(nameof(sellingRepository));
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormSelling>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList()
{
dataGridViewData.DataSource = _sellingRepository.ReadSelling();
dataGridViewData.Columns["ID"].Visible = false;
dataGridViewData.Columns["SellingDateTime"].DefaultCellStyle.Format = "dd MMMM yyyy";
}
private void FormSellings_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}