88 lines
3.2 KiB
C#
88 lines
3.2 KiB
C#
using PrecastConcretePlantContracts.BusinessLogicsContracts;
|
|
using PrecastConcretePlantContracts.BindingModels;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace PrecastConcretePlantView
|
|
{
|
|
public partial class FormReinforcedSale : Form
|
|
{
|
|
private readonly ILogger _logger;
|
|
|
|
private readonly IReinforcedLogic _logicReinforced;
|
|
|
|
private readonly IShopLogic _logicShop;
|
|
|
|
public FormReinforcedSale(ILogger<FormShopReplenishment> logger, IReinforcedLogic logicReinforced, IShopLogic logicShop)
|
|
{
|
|
InitializeComponent();
|
|
_logger = logger;
|
|
_logicReinforced = logicReinforced;
|
|
_logicShop = logicShop;
|
|
}
|
|
|
|
private void FormReinforcedSale_Load(object sender, EventArgs e)
|
|
{
|
|
_logger.LogInformation("Reinforceds loading");
|
|
try
|
|
{
|
|
var list = _logicReinforced.ReadList(null);
|
|
if (list != null)
|
|
{
|
|
comboBoxReinforced.DisplayMember = "ReinforcedName";
|
|
comboBoxReinforced.ValueMember = "Id";
|
|
comboBoxReinforced.DataSource = list;
|
|
comboBoxReinforced.SelectedItem = null;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Reinforceds loading error");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void ButtonSale_Click(object sender, EventArgs e)
|
|
{
|
|
if (comboBoxReinforced.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
|
{
|
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
_logger.LogInformation("Reinforced sale");
|
|
try
|
|
{
|
|
var operationResult = _logicShop.MakeSale(
|
|
new ReinforcedBindingModel
|
|
{
|
|
Id = Convert.ToInt32(comboBoxReinforced.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, "Reinforced sale error");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
}
|
|
}
|