115 lines
4.4 KiB
C#
115 lines
4.4 KiB
C#
using Microsoft.Extensions.Logging;
|
||
using SushiBarContracts.BindingModel;
|
||
using SushiBarContracts.BusinessLogicsContracts;
|
||
using SushiBarContracts.SearchModel;
|
||
|
||
namespace SushiBarView.Shops
|
||
{
|
||
public partial class FormAddSushiInShop : Form
|
||
{
|
||
private readonly ILogger _logger;
|
||
private readonly IShopLogic _shopLogic;
|
||
private readonly ISushiLogic _sushiLogic;
|
||
|
||
public FormAddSushiInShop(ILogger<FormAddSushiInShop> logger, IShopLogic shopLogic, ISushiLogic sushiLogic)
|
||
{
|
||
InitializeComponent();
|
||
_logger = logger;
|
||
_shopLogic = shopLogic;
|
||
_sushiLogic = sushiLogic;
|
||
}
|
||
|
||
private void buttonSave_Click(object sender, EventArgs e)
|
||
{
|
||
if (comboBoxShop.SelectedValue == null)
|
||
{
|
||
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
if (comboBoxSushi.SelectedValue == null)
|
||
{
|
||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||
{
|
||
MessageBox.Show("Введите количество изделий", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
_logger.LogInformation("Добавление изделия в магазин");
|
||
|
||
try
|
||
{
|
||
var operationResult = _shopLogic.AddSushiInShop(
|
||
new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue), ShopName = comboBoxShop.Text },
|
||
new SushiBindingModel { Id = Convert.ToInt32(comboBoxSushi.SelectedValue), SushiName = comboBoxSushi.Text },
|
||
Convert.ToInt32(textBoxCount.Text)
|
||
);
|
||
|
||
if (!operationResult)
|
||
{
|
||
MessageBox.Show("Не получилось почему-то добавить суши", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
|
||
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 FormAddSushiInShop_Load(object sender, EventArgs e)
|
||
{
|
||
_logger.LogInformation("Загрузка магазинов");
|
||
try
|
||
{
|
||
var listShops = _shopLogic.ReadList(null);
|
||
if (listShops != null)
|
||
{
|
||
comboBoxShop.DisplayMember = "ShopName";
|
||
comboBoxShop.ValueMember = "Id";
|
||
comboBoxShop.DataSource = listShops;
|
||
comboBoxShop.SelectedItem = null;
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка загрузки списка магазинов");
|
||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
|
||
_logger.LogInformation("Загрузка суши");
|
||
try
|
||
{
|
||
var list = _sushiLogic.ReadList(null);
|
||
if (list != null)
|
||
{
|
||
comboBoxSushi.DisplayMember = "SushiName";
|
||
comboBoxSushi.ValueMember = "Id";
|
||
comboBoxSushi.DataSource = list;
|
||
comboBoxSushi.SelectedItem = null;
|
||
}
|
||
|
||
}
|
||
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();
|
||
}
|
||
}
|
||
}
|