ISEbd_21_Kuklew_M.I._Softwa.../SoftwareInstallation/FormSellSoftwareInstallation.cs

88 lines
3.3 KiB
C#
Raw Normal View History

2024-05-12 14:45:39 +04:00
using Microsoft.Extensions.Logging;
using SoftwareInstallationContracts.BusinessLogicsContracts;
using SoftwareInstallationContracts.SearchModels;
using SoftwareInstallationContracts.StoragesContracts;
using SoftwareInstallationContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SoftwareInstallationView
{
public partial class FormSellPackage : Form
{
private readonly ILogger _logger;
private readonly IPackageLogic _logicP;
private readonly IShopLogic _logicS;
private List<PackageViewModel> _pizzaList = new List<PackageViewModel>();
public FormSellPackage(ILogger<FormSellPackage> logger, IPackageLogic logicP, IShopLogic logicS)
{
InitializeComponent();
_logger = logger;
_logicP = logicP;
_logicS = logicS;
}
private void FormSellingPackage_Load(object sender, EventArgs e)
{
_pizzaList = _logicP.ReadList(null);
if (_pizzaList != null)
{
comboBoxPackage.DisplayMember = "PackageName";
comboBoxPackage.ValueMember = "Id";
comboBoxPackage.DataSource = _pizzaList;
comboBoxPackage.SelectedItem = null;
_logger.LogInformation("Загрузка пиццы для продажи");
}
}
private void ButtonSell_Click(object sender, EventArgs e)
{
if (comboBoxPackage.SelectedValue == null)
{
MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание покупки");
try
{
bool resout = _logicS.Sale(new SupplySearchModel
{
PackageId = Convert.ToInt32(comboBoxPackage.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text)
});
if (resout)
{
_logger.LogInformation("Проверка пройдена, продажа проведена");
MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
else
{
_logger.LogInformation("Проверка не пройдена");
MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания покупки");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}