51 lines
1.8 KiB
C#
Raw Normal View History

2024-11-15 18:27:06 +04:00
using GasStation.Repositories;
using GasStation.Entities;
namespace GasStation.Forms
{
public partial class FormSupply : Form
{
private readonly ISupplyRepository _supplyRepository;
public FormSupply(ISupplyRepository supplyRepository, ISupplierRepository supplierRepository, IProductRepository productRepository)
{
InitializeComponent();
_supplyRepository = supplyRepository ??
throw new ArgumentNullException(nameof(supplyRepository));
comboBoxSupplier.DataSource = supplierRepository.ReadSupplier();
comboBoxSupplier.DisplayMember = "SupplierName";
comboBoxSupplier.ValueMember = "ID";
2024-12-02 14:38:24 +04:00
comboBoxProduct.DataSource = productRepository.ReadProduct();
comboBoxProduct.DisplayMember = "FullName";
2024-12-02 14:38:24 +04:00
comboBoxProduct.ValueMember = "ID";
2024-11-15 18:27:06 +04:00
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
2024-12-02 14:38:24 +04:00
if (comboBoxProduct.SelectedIndex < 0 ||
2024-11-15 18:27:06 +04:00
comboBoxSupplier.SelectedIndex < 0)
{
throw new Exception("Имеются незаполненые поля");
}
2024-12-02 14:38:24 +04:00
_supplyRepository.CreateSupply(Supply.CreateSupply(0, (int)comboBoxSupplier.SelectedValue!,
(int)comboBoxProduct.SelectedValue!, Convert.ToInt32(numericUpDownCount.Value)));
2024-11-15 18:27:06 +04:00
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
}
}