2024-04-23 22:54:54 +04:00
|
|
|
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
|
|
|
|
using ConfectioneryContracts.BindingModels;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
2024-04-23 22:23:21 +04:00
|
|
|
|
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
|
|
|
|
|
{
|
2024-04-23 22:54:54 +04:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
private readonly IPastryLogic _logicPastry;
|
|
|
|
|
|
|
|
|
|
private readonly IShopLogic _logicShop;
|
|
|
|
|
public FormPastrySale(ILogger<FormSupply> logger, IPastryLogic logicPastry, IShopLogic logicShop)
|
2024-04-23 22:23:21 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-04-23 22:54:54 +04:00
|
|
|
|
_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();
|
2024-04-23 22:23:21 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|