123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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
- {
- /// <summary>
- /// Логика взаимодействия для MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- private B0Entities _entities;
- public List<Ingredient> 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<DishCompound> list = new List<DishCompound>();
- 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();
- }
- }
- }
|