2024-02-29 23:33:00 +04:00
|
|
|
|
using ConfectioneryContracts.BindingModels;
|
|
|
|
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
|
|
|
|
using ConfectioneryContracts.ViewModels;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
2024-02-28 22:55:32 +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 FormCreateSupply : Form
|
|
|
|
|
{
|
2024-02-29 23:33:00 +04:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IPastryLogic _logicP;
|
|
|
|
|
private readonly IShopLogic _logicS;
|
|
|
|
|
private List<ShopViewModel> _shopList = new List<ShopViewModel>();
|
|
|
|
|
private List<PastryViewModel> _pastryList = new List<PastryViewModel>();
|
|
|
|
|
|
|
|
|
|
public FormCreateSupply(ILogger<FormCreateSupply> logger, IPastryLogic logicP, IShopLogic logicS)
|
2024-02-28 22:55:32 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-02-29 23:33:00 +04:00
|
|
|
|
_logger = logger;
|
|
|
|
|
_logicP = logicP;
|
|
|
|
|
_logicS = logicS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormCreateSupply_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_shopList = _logicS.ReadList(null);
|
|
|
|
|
_pastryList = _logicP.ReadList(null);
|
|
|
|
|
if (_shopList != null)
|
|
|
|
|
{
|
|
|
|
|
comboBoxShop.DisplayMember = "ShopName";
|
|
|
|
|
comboBoxShop.ValueMember = "Id";
|
|
|
|
|
comboBoxShop.DataSource = _shopList;
|
|
|
|
|
comboBoxShop.SelectedItem = null;
|
|
|
|
|
_logger.LogInformation("Загрузка магазинов для поставок");
|
|
|
|
|
}
|
|
|
|
|
if (_pastryList != null)
|
|
|
|
|
{
|
|
|
|
|
comboBoxPastry.DisplayMember = "PastryName";
|
|
|
|
|
comboBoxPastry.ValueMember = "Id";
|
|
|
|
|
comboBoxPastry.DataSource = _pastryList;
|
|
|
|
|
comboBoxPastry.SelectedItem = null;
|
|
|
|
|
_logger.LogInformation("Загрузка кондитерского изделия для поставок");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonSave_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (comboBoxShop.SelectedValue == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (comboBoxPastry.SelectedValue == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Создание поставки");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var operationResult = _logicS.MakeSupply(new SupplyBindingModel
|
|
|
|
|
{
|
|
|
|
|
ShopId = Convert.ToInt32(comboBoxShop.SelectedValue),
|
|
|
|
|
PastryId = Convert.ToInt32(comboBoxPastry.SelectedValue),
|
|
|
|
|
Count = 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, "Ошибка создания поставки");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
Close();
|
2024-02-28 22:55:32 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|