2024-03-26 19:45:16 +04:00
|
|
|
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
|
|
|
|
using ConfectioneryContracts.SearchModels;
|
|
|
|
|
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 FormSupply : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
private readonly IPastryLogic _logicPastry;
|
|
|
|
|
|
|
|
|
|
private readonly IShopLogic _logicShop;
|
|
|
|
|
public FormSupply(ILogger<FormSupply> logger, IPastryLogic logicPastry, IShopLogic logicShop)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logicPastry = logicPastry;
|
|
|
|
|
_logicShop = logicShop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormSupply_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-03-26 19:58:34 +04:00
|
|
|
|
_logger.LogInformation("Pastries loading");
|
2024-03-26 19:45:16 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _logicPastry.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
comboBoxPastry.DisplayMember = "PastryName";
|
|
|
|
|
comboBoxPastry.ValueMember = "Id";
|
|
|
|
|
comboBoxPastry.DataSource = list;
|
|
|
|
|
comboBoxPastry.SelectedItem = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2024-03-26 19:58:34 +04:00
|
|
|
|
_logger.LogError(ex, "Pastries loading error");
|
2024-03-26 19:45:16 +04:00
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Shops loading");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _logicShop.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
comboBoxShop.DisplayMember = "ShopName";
|
|
|
|
|
comboBoxShop.ValueMember = "Id";
|
|
|
|
|
comboBoxShop.DataSource = list;
|
|
|
|
|
comboBoxShop.SelectedItem = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Shops loading error");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (comboBoxShop.SelectedValue == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (comboBoxPastry.SelectedValue == null)
|
|
|
|
|
{
|
2024-04-01 13:01:23 +04:00
|
|
|
|
MessageBox.Show("Выберите выпечку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2024-03-26 19:45:16 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Shop replenishment");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var pastry = _logicPastry.ReadElement(new PastrySearchModel
|
|
|
|
|
{ Id = Convert.ToInt32(comboBoxPastry.SelectedValue) });
|
|
|
|
|
if (pastry == null)
|
|
|
|
|
{
|
2024-04-01 13:01:23 +04:00
|
|
|
|
throw new Exception("Выпечка не найдена.");
|
2024-03-26 19:45:16 +04:00
|
|
|
|
}
|
|
|
|
|
var operationResult = _logicShop.Supply(new ShopSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = Convert.ToInt32(comboBoxShop.SelectedValue)
|
|
|
|
|
},
|
|
|
|
|
pastry,
|
|
|
|
|
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, "Shop replenishment error");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|