88 lines
2.2 KiB
C#
Raw Normal View History

2024-05-24 01:56:34 +04:00
using SushiBarBusinessLogic;
using SushiBarContracts.ViewModels;
namespace SushiBarView.Forms
{
public partial class FormDishIngredient : Form
{
private readonly List<IngredientViewModel>? _list;
public int Id
{
get
{
return Convert.ToInt32(ComboBox.SelectedValue);
}
set
{
ComboBox.SelectedValue = value;
}
}
public IngredientViewModel? IngredientModel
{
get
{
if (_list == null)
{
return null;
}
foreach (var Elem in _list)
{
if (Elem.Id == Id)
{
return Elem;
}
}
return null;
}
}
public int Count
{
get { return Convert.ToInt32(CountTextBox.Text); }
set { CountTextBox.Text = value.ToString(); }
}
public FormDishIngredient(IngredientLogic Logic)
{
InitializeComponent();
_list = Logic.ReadList(null);
if (_list != null)
{
ComboBox.DisplayMember = "IngredientName";
ComboBox.ValueMember = "Id";
ComboBox.DataSource = _list;
ComboBox.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(CountTextBox.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (ComboBox.SelectedValue == null)
{
MessageBox.Show("Выберите ингредиент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}