예제 #1
0
        public ManagerViewFood(Food food)
        {
            InitializeComponent();

            var context = new MSSQLContext();

            FoodImage.Source = WorkWithImage.ConvertArrayByteToImage(food.Image);
            NameFood.Text    = food.Name;
            Category.Text    = context.Categories.Find(food.CategoryId).Name;
            Price.Text       = food.CurrentPrice.ToString();
            InMenu.IsChecked = food.InMenu;
            Description.Text = food.Description;
            this.food        = food;

            var structures = context.Structures.Where(s => s.FoodId == food.Id).ToList();

            foreach (var currentStructure in structures)
            {
                if (structures.IndexOf(currentStructure) == structures.Count)
                {
                    Ingredients.Text += context.Ingredients.First(i => i.Id == currentStructure.IngredientId).Name + ".";
                }
                else
                {
                    Ingredients.Text += context.Ingredients.First(i => i.Id == currentStructure.IngredientId).Name + " ,";
                }
            }

            context.Database.Connection.Close();
        }
예제 #2
0
        public UserViewFood(Food currentFood, List <FoodInBasket> basket, Button basketButton)
        {
            InitializeComponent();

            Price.Text            = currentFood.CurrentPrice.ToString();
            FoodDescription.Text  = currentFood.Description;
            AddToBasket.IsEnabled = Validation.CanUserBuy(basket, currentFood);
            foodImage.Source      = WorkWithImage.ConvertArrayByteToImage(currentFood.Image);

            using (var context = new MSSQLContext())
            {
                var structures = context.Structures.Where(s => s.FoodId == currentFood.Id)
                                 .Include(s => s.Ingredient)
                                 .ToList();

                foreach (var currentStructure in structures)
                {
                    if (structures.IndexOf(currentStructure) == structures.Count)
                    {
                        FoodStruct.Text += context.Ingredients.First(i => i.Id == currentStructure.IngredientId).Name +
                                           $" {currentStructure.Quantity} {currentStructure.Ingredient.Unit}.";
                    }
                    else
                    {
                        FoodStruct.Text += context.Ingredients.First(i => i.Id == currentStructure.IngredientId).Name +
                                           $" {currentStructure.Quantity} {currentStructure.Ingredient.Unit},";
                    }
                }
            }

            this.basket       = basket;
            this.currentFood  = currentFood;
            this.basketButton = basketButton;
        }
예제 #3
0
        private void LoadFood()
        {
            using (MSSQLContext context = new MSSQLContext())
            {
                foreach (var item in context.Structures.Where(s => s.FoodId == food.Id).ToList())
                {
                    model.Add(new IngredientsModel()
                    {
                        CookingStep    = item.CookingStep,
                        Unit           = item.Ingredient.Unit,
                        Weight         = item.Quantity,
                        IngredientName = item.Ingredient.Name
                    });
                }

                Table.ItemsSource  = model;
                AddFood.IsEnabled  = false;
                AddFood.Visibility = Visibility.Hidden;
                Name.Text          = food.Name;
                Category.Text      = context.Categories.Find(food.CategoryId).Name;
                Image.Source       = WorkWithImage.ConvertArrayByteToImage(food.Image);
            }
        }
예제 #4
0
        private void UpdateDb()
        {
            using (var context = new MSSQLContext())
            {
                food       = context.Foods.Find(food.Id);
                food.Name  = Name.Text;
                food.Image = WorkWithImage.ConverImageToArrayByte(Image.Source);

                var category = context.Categories.First(c => c.Name.ToLower() == Category.Text.ToLower());

                if (category == null)
                {
                    var newCategory = new Category()
                    {
                        Name = Category.Text
                    };

                    context.Categories.Add(newCategory);
                    context.SaveChanges();

                    food.CategoryId = newCategory.Id;
                }
                else
                {
                    food.CategoryId = category.Id;
                }

                var structures = context.Structures.Where(s => s.FoodId == food.Id).ToList();

                var listName = new List <string>();
                var newModel = new List <IngredientsModel>();

                foreach (var item in model)
                {
                    if (!listName.Contains(item.IngredientName))
                    {
                        var usefullList = model.Where(m => m.IngredientName.ToLower() == item.IngredientName.ToLower()).ToList();

                        string  CookingStep = "";
                        decimal Weight      = 0;

                        foreach (var elem in usefullList)
                        {
                            CookingStep += elem.CookingStep.TrimEnd(new char[] { ';' }) + ";";
                            Weight      += elem.Weight;
                        }


                        newModel.Add(new IngredientsModel()
                        {
                            IngredientName = item.IngredientName,
                            CookingStep    = CookingStep,
                            Weight         = Weight,
                            Unit           = item.Unit
                        });
                    }
                }

                foreach (var item in newModel)
                {
                    var ingredient = context.Ingredients.FirstOrDefault(i => i.Name == item.IngredientName);

                    if (ingredient == null)
                    {
                        ingredient = new Ingredient()
                        {
                            Count = 0, Name = item.IngredientName, Price = 0, Unit = item.Unit
                        };

                        context.Ingredients.Add(ingredient);
                        context.SaveChanges();

                        var structure = new Structure()
                        {
                            IngredientId = ingredient.Id, FoodId = food.Id, Quantity = item.Weight, CookingStep = item.CookingStep
                        };

                        context.Structures.Add(structure);
                        context.SaveChanges();
                    }
                    else
                    {
                        var structure = context.Structures.FirstOrDefault(s => s.FoodId == food.Id && s.IngredientId == ingredient.Id);

                        if (structure == null)
                        {
                            structure = new Structure()
                            {
                                IngredientId = ingredient.Id, FoodId = food.Id, Quantity = item.Weight, CookingStep = item.CookingStep
                            };

                            context.Structures.Add(structure);
                            context.SaveChanges();
                        }
                        else
                        {
                            structure.CookingStep = item.CookingStep;
                            structure.Quantity    = item.Weight;
                            structures.Remove(structures.First(s => s.FoodId == food.Id && s.IngredientId == ingredient.Id));

                            context.SaveChanges();
                        }
                    }
                }

                isDataDirty = false;

                context.Structures.RemoveRange(structures);
                context.SaveChanges();
            }

            Close();
        }
예제 #5
0
 private void ChangeImage_Click(object sender, RoutedEventArgs e)
 {
     Image.Source = WorkWithImage.LoadImageFromPc();
 }
예제 #6
0
        private void LoadFood(int category = 0, string name = "")
        {
            bool checkIngredients;

            Menu.Items.Clear();

            using (var context = new MSSQLContext())
            {
                foreach (var food in listFood)
                {
                    checkIngredients = true;

                    var structures = context.Structures.Where(s => s.FoodId == food.Id).ToList();

                    foreach (var currentStructure in structures)
                    {
                        bool exist = false;

                        foreach (var ingredient in listIngredients)
                        {
                            exist = ingredient.Id == currentStructure.IngredientId;

                            if (exist)
                            {
                                break;
                            }
                        }

                        if (!exist)
                        {
                            checkIngredients = false;
                            break;
                        }
                    }

                    if (!checkIngredients)
                    {
                        continue;
                    }
                    if (food.CategoryId != category && category != 0)
                    {
                        continue;
                    }
                    if (!food.Name.StartsWith(name) && name != "")
                    {
                        continue;
                    }

                    var stackpanel = new StackPanel()
                    {
                        Orientation = Orientation.Horizontal
                    };

                    Label label = new Label()
                    {
                        Content           = food.Name,
                        Foreground        = Brushes.White,
                        FontWeight        = FontWeights.DemiBold,
                        FontSize          = 16,
                        VerticalAlignment = VerticalAlignment.Center
                    };

                    Image img = new Image()
                    {
                        Source = WorkWithImage.ConvertArrayByteToImage(food.Image),
                    };

                    var button = new Button()
                    {
                        Name                = "Name" + food.Id.ToString(),
                        IsEnabled           = true,
                        Foreground          = Brushes.White,
                        VerticalAlignment   = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Right,
                        Margin              = new Thickness(5),
                        Content             = $"{food.Name}",
                    };

                    stackpanel.Children.Add(img);
                    stackpanel.Children.Add(label);
                    stackpanel.Children.Add(button);

                    button.Click += EventForFood;

                    Menu.Items.Add(stackpanel);
                }
            }
        }