using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ProjectD
{
///
/// Логика взаимодействия для MainWindow.xaml
///
public partial class MainWindow : Window
{
private B0Entities _entities;
public List Ingredients { get; set; }
public MainWindow()
{
InitializeComponent();
_entities = new B0Entities();
Ingredients = _entities.Ingredient.ToList();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
StackPanel stackPanel = new StackPanel();
stackPanel.Orientation = Orientation.Horizontal;
IngredientList.Children.Add(stackPanel);
ComboBox comboBox = new ComboBox();
TextBox textBox = new TextBox();
textBox.Width = 40;
comboBox.Width = 120;
comboBox.ItemsSource = Ingredients;
comboBox.DisplayMemberPath = "name";
stackPanel.Children.Add(comboBox);
stackPanel.Children.Add(textBox);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (textBoxDishName.Text.Length == 0)
{
textBoxDishName.Focus();
MessageBox.Show("Введите название блюда");
return;
}
Dish dish = new Dish()
{
name = textBoxDishName.Text,
};
var d = _entities.Dish.Add(dish);
_entities.SaveChanges();
List list = new List();
foreach (var ing in IngredientList.Children)
{
var st = ing as StackPanel;
if (st != null)
{
var cb = st.Children[0] as ComboBox;
var tb = st.Children[1] as TextBox;
var ingredient = cb.SelectedItem as Ingredient;
if (ingredient != null)
{
list.Add(new DishCompound()
{
dish = d.id,
ingredient = ingredient.id,
volume = float.Parse(tb.Text),
});
}
}
}
_entities.DishCompound.AddRange(list);
_entities.SaveChanges();
}
}
}