Exemplo n.º 1
0
 public static void AdjustInventoryByItem(int itemId, double itemPortionSize,
                                          bool increase)
 {
     if (itemId > 0)
     {
         foreach (ItemIngredient itemIngredientIngredient in
                  ItemIngredient.GetAll(itemId))
         {
             AdjustInventoryByIngredient(
                 itemIngredientIngredient.IngredientId,
                 increase,
                 itemIngredientIngredient.Amount * itemPortionSize,
                 itemIngredientIngredient.MeasurementUnit);
         }
     }
 }
        private void InitializeFields()
        {
            listBox.SelectedItem = null;
            listBoxItemIngredients.SelectedItem = null;
            listBox.Items.Clear();
            listBoxItemIngredients.Items.Clear();

            List <Ingredient> ingredients = new List <Ingredient>(_cachedIngredients);

            if (ActiveItem != null)
            {
                foreach (ItemIngredient itemIngredient in ItemIngredient.GetAll(ActiveItem.Id))
                {
                    bool           added, changed, removed;
                    ItemIngredient current = GetItemIngredient(itemIngredient.Id,
                                                               out added, out changed, out removed);
                    if (!removed)
                    {
                        Ingredient ingredient = Ingredient.Find(ingredients, itemIngredient.IngredientId);
                        AddIngredientSetToListBox(
                            (changed ? current : itemIngredient), ingredient);
                        ingredients.Remove(ingredient);
                    }
                }
            }

            // Note: Added ones have an ItemId of zero so GetAll (above) will not find them
            foreach (ItemIngredient itemIngredient in _itemIngredientsAdded)
            {
                Ingredient ingredient = Ingredient.Find(ingredients, itemIngredient.IngredientId);
                AddIngredientSetToListBox(itemIngredient, ingredient);
                ingredients.Remove(ingredient);
            }

            foreach (Ingredient ingredient in ingredients)
            {
                listBox.Items.Add(new FormattedListBoxItem(ingredient.Id,
                                                           ingredient.FullName, true));
            }

            SetButtonsEnabled();
        }