public static void AdjustItemWeights(Ingredient sender, double newWeight,  ObservableCollection<Ingredient> items )
        {
            double oldWeight = sender.GetExactWeight();
            double weightAdjustRatio = newWeight / oldWeight;
            

            for (int i = 0; i < items.Count; i++)
            {
                Ingredient ingredient = items[i];
                double updatedWeight = ingredient.GetExactWeight() * weightAdjustRatio;
                ingredient.AdjustWeight(updatedWeight);
                
            }
            
        }
Beispiel #2
0
        public static void SetChildWeightsFromPercentage(Ingredient parentIngredient)
        {
            var children = parentIngredient.Ingredients;

            if (children == null || children.Count == 0)
            {
                return;
            }
            double totalWeight = parentIngredient.GetExactWeight();

            foreach (var child in children)
            {
                child.AdjustWeight(child.GetExactPercent() * totalWeight);
            }
        }
Beispiel #3
0
        public static void AdjustItemWeights(Ingredient sender, double newWeight, ObservableCollection <Ingredient> items)
        {
            double oldWeight         = sender.GetExactWeight();
            double weightAdjustRatio = newWeight / oldWeight;


            for (int i = 0; i < items.Count; i++)
            {
                if (items[i] == sender)
                {
                    continue;
                }
                Ingredient ingredient    = items[i];
                double     updatedWeight = ingredient.GetExactWeight() * weightAdjustRatio;
                ingredient.AdjustWeight(updatedWeight);
            }
            sender.AdjustWeight(newWeight);
        }
Beispiel #4
0
        public static void AdjustItemWeights(object senderObj, double newWeight, List <Ingredient> items)
        {
            Ingredient sender            = senderObj as Ingredient;
            double     oldWeight         = sender.GetExactWeight();
            double     weightAdjustRatio = newWeight / oldWeight;


            for (int i = 0; i < items.Count; i++)
            {
                Ingredient ingredient = items[i];
                if (ingredient == sender)
                {
                    continue;
                }
                //if (i == items.Count - 1)
                //{
                //    ingredient.Weight = weightRemaining;
                //    break;
                //}
                double updatedWeight = ingredient.GetExactWeight() * weightAdjustRatio;

                ingredient.AdjustWeight(updatedWeight);
            }
        }
        public static void SetChildWeightsFromPercentage( Ingredient parentIngredient)
        {
            var children = parentIngredient.Ingredients;
            if (children == null) return;
            double totalWeight = parentIngredient.GetExactWeight();

            foreach (var child in children) child.AdjustWeight(child.GetExactPercent() * totalWeight);

        }