116 lines
4.0 KiB
C#
116 lines
4.0 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using PizzeriaBusinessLogic.BusinessLogics;
|
|
using PizzeriaContracts.BindingModels;
|
|
using PizzeriaContracts.BusinessLogicsContracts;
|
|
using PizzeriaContracts.SearchModels;
|
|
using PizzeriaContracts.ViewModels;
|
|
using System;
|
|
using System.Collections;
|
|
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;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
namespace PizzeriaView
|
|
{
|
|
public partial class FormCreateSupply : Form
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IPizzaLogic _logicP;
|
|
private readonly IShopLogic _logicS;
|
|
private List<ShopViewModel> _shopList = new List<ShopViewModel>();
|
|
private List<PizzaViewModel> _pizzaList = new List<PizzaViewModel>();
|
|
|
|
public FormCreateSupply(ILogger<FormCreateSupply> logger, IPizzaLogic logicP, IShopLogic logicS)
|
|
{
|
|
InitializeComponent();
|
|
_logger = logger;
|
|
_logicP = logicP;
|
|
_logicS = logicS;
|
|
}
|
|
|
|
private void FormCreateSupply_Load(object sender, EventArgs e)
|
|
{
|
|
_shopList = _logicS.ReadList(null);
|
|
_pizzaList = _logicP.ReadList(null);
|
|
if (_shopList != null)
|
|
{
|
|
comboBoxShop.DisplayMember = "ShopName";
|
|
comboBoxShop.ValueMember = "Id";
|
|
comboBoxShop.DataSource = _shopList;
|
|
comboBoxShop.SelectedItem = null;
|
|
_logger.LogInformation("Загрузка магазинов для поставок");
|
|
}
|
|
if (_pizzaList != null)
|
|
{
|
|
comboBoxPizza.DisplayMember = "PizzaName";
|
|
comboBoxPizza.ValueMember = "Id";
|
|
comboBoxPizza.DataSource = _pizzaList;
|
|
comboBoxPizza.SelectedItem = null;
|
|
_logger.LogInformation("Загрузка пиццы для поставок");
|
|
}
|
|
}
|
|
|
|
private void ButtonSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
|
{
|
|
MessageBox.Show("Заполните поле Количество", "Ошибка",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (comboBoxPizza.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите пиццу", "Ошибка",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
if (comboBoxPizza.SelectedValue == null)
|
|
{
|
|
MessageBox.Show("Выберите магазин", "Ошибка",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
int count = Convert.ToInt32(textBoxCount.Text);
|
|
|
|
bool res = _logicS.MakeSupply(
|
|
new ShopSearchModel() { Id = Convert.ToInt32(comboBoxShop.SelectedValue) },
|
|
_logicP.ReadElement(new() { Id = Convert.ToInt32(comboBoxPizza.SelectedValue) }),
|
|
count
|
|
);
|
|
|
|
if (!res)
|
|
{
|
|
throw new Exception("Ошибка при пополнении. Дополнительная информация в логах");
|
|
}
|
|
|
|
MessageBox.Show("Пополнение прошло успешно");
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
|
|
}
|
|
catch (Exception err)
|
|
{
|
|
MessageBox.Show("Ошибка пополнения");
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
}
|
|
}
|