125 lines
4.5 KiB
C#
125 lines
4.5 KiB
C#
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)
|
|
{
|
|
_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);
|
|
}
|
|
_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)
|
|
{
|
|
MessageBox.Show("Выберите выпечку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
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)
|
|
{
|
|
throw new Exception("Выпечка не найдена.");
|
|
}
|
|
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();
|
|
}
|
|
}
|
|
}
|