PIbd-22_Chernyshev_G.J._30_.../GarmentFactory/FormSellTextile.cs

88 lines
2.6 KiB
C#

using GarmentFactoryContracts.BusinessLogicsContracts;
using GarmentFactoryContracts.SearchModels;
using GarmentFactoryContracts.ViewModels;
using Microsoft.Extensions.Logging;
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 GarmentFactoryView
{
public partial class FormSellTextile : Form
{
private readonly ILogger _logger;
private readonly ITextileLogic _logicT;
private readonly IShopLogic _logicS;
private List<TextileViewModel> _TextileList = new List<TextileViewModel>();
public FormSellTextile(ILogger<FormSellTextile> logger, ITextileLogic logicT, IShopLogic logicS)
{
InitializeComponent();
_logger = logger;
_logicT = logicT;
_logicS = logicS;
}
private void FormSellingTextile_Load(object sender, EventArgs e)
{
_TextileList = _logicT.ReadList(null);
if (_TextileList != null)
{
comboBoxTextile.DisplayMember = "TextileName";
comboBoxTextile.ValueMember = "Id";
comboBoxTextile.DataSource = _TextileList;
comboBoxTextile.SelectedItem = null;
_logger.LogInformation("Загрузка пиццы для продажи");
}
}
private void ButtonSell_Click(object sender, EventArgs e)
{
if (comboBoxTextile.SelectedValue == null)
{
MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание покупки");
try
{
bool resout = _logicS.Sell(new SupplySearchModel
{
TextileId = Convert.ToInt32(comboBoxTextile.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();
}
}
}