88 lines
3.1 KiB
C#
88 lines
3.1 KiB
C#
|
using SoftwareInstallationContracts.BusinessLogicsContracts;
|
|||
|
using SoftwareInstallationContracts.BindingModels;
|
|||
|
using Microsoft.Extensions.Logging;
|
|||
|
|
|||
|
namespace SoftwareInstallationView
|
|||
|
{
|
|||
|
public partial class FormPackageSale : Form
|
|||
|
{
|
|||
|
private readonly ILogger _logger;
|
|||
|
|
|||
|
private readonly IPackageLogic _logicPackage;
|
|||
|
|
|||
|
private readonly IShopLogic _logicShop;
|
|||
|
|
|||
|
public FormPackageSale(ILogger<FormMakeShipment> logger, IPackageLogic logicPackage, IShopLogic logicShop)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_logger = logger;
|
|||
|
_logicPackage = logicPackage;
|
|||
|
_logicShop = logicShop;
|
|||
|
}
|
|||
|
|
|||
|
private void FormPackageSale_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
_logger.LogInformation("Ice creams loading");
|
|||
|
try
|
|||
|
{
|
|||
|
var list = _logicPackage.ReadList(null);
|
|||
|
if (list != null)
|
|||
|
{
|
|||
|
comboBoxPackage.DisplayMember = "PackageName";
|
|||
|
comboBoxPackage.ValueMember = "Id";
|
|||
|
comboBoxPackage.DataSource = list;
|
|||
|
comboBoxPackage.SelectedItem = null;
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ice creams loading error");
|
|||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonSale_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (comboBoxPackage.SelectedValue == null)
|
|||
|
{
|
|||
|
MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
return;
|
|||
|
}
|
|||
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
|||
|
{
|
|||
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
return;
|
|||
|
}
|
|||
|
_logger.LogInformation("Ice cream sale");
|
|||
|
try
|
|||
|
{
|
|||
|
var operationResult = _logicShop.MakeSale(
|
|||
|
new PackageBindingModel
|
|||
|
{
|
|||
|
Id = Convert.ToInt32(comboBoxPackage.SelectedValue)
|
|||
|
},
|
|||
|
Convert.ToInt32(textBoxCount.Text)
|
|||
|
);
|
|||
|
if (!operationResult)
|
|||
|
{
|
|||
|
throw new Exception("Ошибка при продаже.");
|
|||
|
}
|
|||
|
MessageBox.Show("Продажа прошла успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|||
|
DialogResult = DialogResult.OK;
|
|||
|
Close();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Ice cream sale error");
|
|||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
DialogResult = DialogResult.Cancel;
|
|||
|
Close();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|