95 lines
3.3 KiB
C#
95 lines
3.3 KiB
C#
using ConfectioneryContracts.BusinessLogicsContracts;
|
|
using ConfectioneryContracts.BindingModels;
|
|
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 ConfectioneryView
|
|
{
|
|
public partial class FormPastrySale : Form
|
|
{
|
|
private readonly ILogger _logger;
|
|
|
|
private readonly IPastryLogic _logicPastry;
|
|
|
|
private readonly IShopLogic _logicShop;
|
|
public FormPastrySale(ILogger<FormSupply> logger, IPastryLogic logicPastry, IShopLogic logicShop)
|
|
{
|
|
InitializeComponent();
|
|
_logger = logger;
|
|
_logicPastry = logicPastry;
|
|
_logicShop = logicShop;
|
|
}
|
|
private void FormPastrySale_Load(object sender, EventArgs e)
|
|
{
|
|
_logger.LogInformation("Pastries loading");
|
|
try
|
|
{
|
|
var list = _logicPastry.ReadList(null);
|
|
if (list != null)
|
|
{
|
|
comboBoxPastry.DisplayMember = "PastryName";
|
|
comboBoxPastry.ValueMember = "Id";
|
|
comboBoxPastry.DataSource = list;
|
|
comboBoxPastry.SelectedItem = null;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Pastries loading error");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void ButtonSale_Click(object sender, EventArgs e)
|
|
{
|
|
if (comboBoxPastry.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите выпечку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
|
{
|
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
_logger.LogInformation("Pastry sale");
|
|
try
|
|
{
|
|
var operationResult = _logicShop.Sale(
|
|
new PastryBindingModel
|
|
{
|
|
Id = Convert.ToInt32(comboBoxPastry.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, "Pastry sale error");
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
}
|
|
}
|