ISEbd-21_Koscheev.M.S.Softw.../SoftwareInstallation/SoftwareInstallationView/FormSellPackage.cs
2023-03-18 01:08:33 +04:00

55 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using SoftwareInstallationContracts.BusinessLogicsContracts;
namespace SoftwareInstallationView
{
public partial class FormSellPackage : Form
{
private readonly IShopLogic _shopLogic;
private readonly IPackageLogic _packageLogic;
public FormSellPackage(IPackageLogic logic, IShopLogic shopLogic)
{
InitializeComponent();
_packageLogic = logic;
_shopLogic = shopLogic;
var list = logic.ReadList(null);
if (list != null)
{
comboBoxPackage.DisplayMember = "PackageName";
comboBoxPackage.ValueMember = "Id";
comboBoxPackage.DataSource = list;
comboBoxPackage.SelectedItem = null;
}
}
private void ButtonSell_Click(object sender, EventArgs e)
{
if (comboBoxPackage.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (numericUpDownCount.Value <= 0)
{
MessageBox.Show("Количество должно быть больше нуля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var count = (int)numericUpDownCount.Value;
var package = _packageLogic.ReadElement(new() { Id = (int)comboBoxPackage.SelectedValue });
if (package == null || !_shopLogic.SellPackages(package, count))
{
MessageBox.Show("Не удалось продать изделия. Информацию смотрите в логах", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}