52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
using GasStation.Entities;
|
|
using GasStation.Repositories;
|
|
using GasStation.Repositories.Implementations;
|
|
|
|
|
|
namespace GasStation.Forms
|
|
{
|
|
public partial class FormSelling : Form
|
|
{
|
|
private readonly ISellingRepository _sellingRepository;
|
|
|
|
public FormSelling(ISellingRepository sellingRepository, IGasmanRepository gasmanRepository, IProductRepository productRepository)
|
|
{
|
|
InitializeComponent();
|
|
_sellingRepository = sellingRepository ??
|
|
throw new ArgumentNullException(nameof(sellingRepository));
|
|
|
|
comboBoxGasman.DataSource = gasmanRepository.ReadGasman();
|
|
comboBoxGasman.DisplayMember = "GasmanName";
|
|
comboBoxGasman.ValueMember = "ID";
|
|
|
|
comboBoxProduct.DataSource = productRepository.ReadProduct();
|
|
comboBoxProduct.DisplayMember = "ProductName";
|
|
comboBoxProduct.ValueMember = "ID";
|
|
}
|
|
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (comboBoxGasman.SelectedIndex < 0 ||
|
|
comboBoxProduct.SelectedIndex < 0)
|
|
{
|
|
throw new Exception("Имеются незаполненые поля");
|
|
}
|
|
|
|
_sellingRepository.CreateSelling(Selling.CreateSelling(0, (int)comboBoxGasman.SelectedValue!,
|
|
(int)comboBoxProduct.SelectedValue!, Convert.ToInt32(numericUpDownCount.Value)));
|
|
|
|
Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
|
}
|
|
}
|