public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            IngredientAmount amount = (IngredientAmount)value;

            if (amount.Ingredient == null)
            {
                return(FormatPieces(0));
            }

            switch (amount.Ingredient.Unit)
            {
            case IngredientUnit.Pieces:
                return(FormatPieces(amount.Amount));

            case IngredientUnit.Volume:
                return(FormatVolume(amount.Amount));

            case IngredientUnit.Weight:
                return(FormatWeight(amount.Amount));

            default:
                return(amount.Amount.ToString(CultureInfo.InvariantCulture));
            }
        }
Ejemplo n.º 2
0
 public override void Execute(object parameter)
 {
     //var values = (object[])parameter;
     // Because of namespace we have to use "Model" prefix.
     Model.Recipe           recipe = (Model.Recipe)parameter;
     Model.IngredientAmount ia     = new IngredientAmount();
     recipe.Ingredients.Add(ia);
 }
        private void IngredientRemove_OnClick(object sender, RoutedEventArgs e)
        {
            Button           button = (Button)sender;
            IngredientAmount amount = (IngredientAmount)button.DataContext;

            selectedRecipe.Ingredients.Remove(amount);
            listIngredientPerRecipeList.Items.Refresh();
            UpdateNutrition();
        }
Ejemplo n.º 4
0
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            Button           button = (Button)sender;
            IngredientAmount amount = (IngredientAmount)button.DataContext;

            ingredientAmount.Remove(amount);
            listIngredientPerRecipeList.Items.Refresh();
            btnIngredientAdd.IsEnabled = false;
        }
Ejemplo n.º 5
0
        public override void Execute(object parameter)
        {
            var values = (object[])parameter;
            IngredientAmount amount       = (IngredientAmount)values[0];
            string           addAmountStr = Convert.ToString(values[1]);
            decimal          addAmount    = decimal.Parse(addAmountStr, CultureInfo.InvariantCulture);

            amount.Ingredient.InStoreAmount += addAmount;
            _viewModel.UpdateRequiredIngredients();
        }
Ejemplo n.º 6
0
        private static IngredientAmount GetAmount(ObservableCollection <IngredientAmount> collection, Ingredient ingredient)
        {
            // Find ingredient
            IngredientAmount ingr = collection.FirstOrDefault(i => i.Ingredient.Id == ingredient.Id);

            if (ingr == null)
            {
                // Add ingredient
                ingr = new IngredientAmount(ingredient);
                collection.Add(ingr);
            }

            return(ingr);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Database.SetInitializer(new DropCreateDatabaseAlways <OneToOneContext>());

            using (var context = new OneToOneContext())
            {
                var ingredientAmount = new IngredientAmount
                {
                    Amount   = 10,
                    AmountId = 20,
                    Name     = "the first one"
                };

                context.IngredientAmounts.Add(ingredientAmount);
                context.SaveChanges();
            }
        }
Ejemplo n.º 8
0
 public void UpdateRequiredIngredients()
 {
     RequiredAmounts.Clear();
     foreach (IngredientAmount amount in _totalRequiredAmounts)
     {
         if (amount.Amount > amount.Ingredient.InStoreAmount)
         {
             IngredientAmount updatedAmount = GetAmount(RequiredAmounts, amount.Ingredient);
             updatedAmount.Amount = amount.Amount - amount.Ingredient.InStoreAmount;
         }
         else
         {
             IngredientAmount deleteAmount = RequiredAmounts.FirstOrDefault(
                 i => i.Ingredient.Id == amount.Ingredient.Id);
             if (deleteAmount != null)
             {
                 RequiredAmounts.Remove(deleteAmount);
             }
         }
     }
 }
Ejemplo n.º 9
0
        public void UpdatePizzaHouse(SettingEditDto dto)
        {
            UseDb(db =>
            {
                PizzaHouse entity = db.PizzaHouses.GetById(dto.PizzaHouseId);
                entity.Capacity   = dto.Capacity;
                dto.StartHour     = dto.StartHour % 24;
                dto.EndHour       = dto.EndHour % 24;
                entity.OpenTime   = TimeSpan.FromHours(dto.StartHour);
                entity.CloseTime  = TimeSpan.FromHours(dto.EndHour);
                db.PizzaHouses.Update(entity);

                var ams = db.IngredientAmounts.Query()
                          .Where(l => l.PizzaHouseId == dto.PizzaHouseId);

                foreach (var am in dto.IngState)
                {
                    var e = ams.FirstOrDefault(a => a.IngredientId == am.Id);
                    if (e == null)
                    {
                        e = new IngredientAmount
                        {
                            IngredientId = am.Id,
                            PizzaHouseId = dto.PizzaHouseId,
                            Quantity     = am.Quantity
                        };

                        db.IngredientAmounts.Create(e);
                    }
                    else
                    {
                        e.Quantity = am.Quantity;
                        db.IngredientAmounts.Update(e);
                    }
                }

                db.Save();
            });
        }
Ejemplo n.º 10
0
    void AddIngredient(Ingredient.IngredientType ingredientType)
    {
        messageText.DisplayMessage("", null);
        // You need to be working on a recipie
        if (currentRecipie == null)
        {
            Debug.Log("No current recipie!");
            return;
        }
        if (GetCurrentStep() == null)
        {
            Debug.Log("No current step!");
            return;
        }
        // Check if you added something WRONG!!!
        bool recipieContainsIngredient = false;

        foreach (IngredientAmount requiredIngredient in GetCurrentStep().requiredIngredients)
        {
            if (requiredIngredient.ingredient == ingredientType)
            {
                recipieContainsIngredient = true;
            }
        }
        if (!recipieContainsIngredient)
        {
            messageText.DisplayMessage("Wrong ingredient!", RandomFailString());
            RecipieFailed();
            return;
        }
        if (heat < GetCurrentStep().minHeat)
        {
            messageText.DisplayMessage("Not enough heat!", RandomFailString());
            RecipieFailed();
            return;
        }
        if (heat > GetCurrentStep().maxHeat)
        {
            messageText.DisplayMessage("Too much heat!", RandomFailString());
            RecipieFailed();
            return;
        }
        // Add ingredient to the dictionary
        bool addedAlready = false;

        foreach (IngredientAmount addedIngredient in addedIngredientsThisStep)
        {
            if (addedIngredient.ingredient == ingredientType)
            {
                addedIngredient.value = addedIngredient.value + 1;
            }
        }
        if (!addedAlready)
        {
            IngredientAmount newAmount = new IngredientAmount();
            newAmount.ingredient = ingredientType;
            newAmount.value      = 1;
            addedIngredientsThisStep.Add(newAmount);
        }
        CheckRecipieStatus();
        SetNewColor();
    }
        public override Job StartingJobForOn(Pawn pawn, Thing thing)
        {
            Job       job;
            bool      flag;
            BillGiver billGiver = thing as BillGiver;
            Pawn      pawn1     = thing as Pawn;

            if (pawn1 == null)
            {
                return(null);
            }

            Log.Error("1 - " + pawn.Name + " / " + thing.def.defName);

            if (billGiver == null)
            {
                return(null);
            }
            if (thing.def == this.def.billGiverDef)
            {
                flag = true;
            }
            else
            {
                flag = (!this.def.billGiversAllMechanoids || pawn1 == null ? false : pawn1.RaceProps.mechanoid);
            }
            if (!flag)
            {
                return(null);
            }
            if (!billGiver.ReadyToHaveBillDone())
            {
                return(null);
            }
            if (!billGiver.BillStack.AnyShouldDoNow())
            {
                return(null);
            }
            if (!pawn.CanReserve(thing, ReservationType.Use) || thing.IsBurning() || thing.IsForbidden(pawn.Faction))
            {
                return(null);
            }
            if (!pawn.CanReach(billGiver.BillInteractionCell, PathMode.OnSquare))
            {
                return(null);
            }
            IEnumerator <IntVec3> enumerator = billGiver.IngredientStackCells.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    IntVec3 current = enumerator.Current;
                    Thing   thing1  = Find.ThingGrid.ThingAt(current, EntityCategory.Item);
                    if (thing1 == null)
                    {
                        continue;
                    }
                    job = GenHaulAI.HaulAsideJobFor(pawn, thing1);
                    return(job);
                }
                goto Label0;
            }
            finally
            {
                if (enumerator == null)
                {
                }
                enumerator.Dispose();
            }
            return(job);

Label0:
            Bill bill = null;
            IEnumerator <Bill> enumerator1 = billGiver.BillStack.GetEnumerator();

            try
            {
                while (enumerator1.MoveNext())
                {
                    Bill current1 = enumerator1.Current;
                    if (current1.ShouldDoNow())
                    {
                        if (current1.recipe.PawnSatisfiesSkillRequirements(pawn))
                        {
                            this.chosenIngThings.Clear();
                            int num = 0;
                            List <IngredientAmount> .Enumerator enumerator2 = current1.recipe.ingredients.GetEnumerator();
                            try
                            {
                                while (enumerator2.MoveNext())
                                {
                                    IngredientAmount ingredientAmount = enumerator2.Current;
                                    int num1 = ingredientAmount.count;
                                    do
                                    {
                                        Predicate <Thing> predicate = (Thing t) => (t.IsForbidden(pawn.Faction) || !pawn.CanReserve(t, ReservationType.Total) || !current1.recipe.fixedIngredientFilter.Allows(t) || !current1.ingredientFilter.Allows(t) || !ingredientAmount.filter.Allows(t) || this.chosenIngThings.ContainsKey(t) ? false : (!current1.CheckIngredientsIfSociallyProper ? true : t.IsSociallyProper(pawn)));
                                        Thing             thing2    = GenClosest.ClosestThingReachable(thing.Position, WorkGiver_DoBill.ThingRequestFor(ingredientAmount.filter), PathMode.ClosestTouch, RegionTraverseParameters.For(pawn, true), current1.ingredientSearchRadius, predicate, null);
                                        if (thing2 != null)
                                        {
                                            int num2 = Mathf.Min(num1, thing2.stackCount);
                                            this.chosenIngThings.Add(thing2, num2);
                                            num1 = num1 - num2;
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }while (num1 > 0);
                                    if (num1 <= 0)
                                    {
                                        num++;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                            finally
                            {
                                ((IDisposable)(object)enumerator2).Dispose();
                            }
                            if (num != current1.recipe.ingredients.Count)
                            {
                                continue;
                            }
                            bill = current1;
                            break;
                        }
                    }
                }
            }
            finally
            {
                if (enumerator1 == null)
                {
                }
                enumerator1.Dispose();
            }
            if (bill == null)
            {
                return(null);
            }
            billGiver.BillStack.RemoveInvalidBills();
            bool flag1 = false;
            IEnumerator <Bill> enumerator3 = billGiver.BillStack.GetEnumerator();

            try
            {
                while (enumerator3.MoveNext())
                {
                    if (enumerator3.Current != bill)
                    {
                        continue;
                    }
                    flag1 = true;
                    break;
                }
            }
            finally
            {
                if (enumerator3 == null)
                {
                }
                enumerator3.Dispose();
            }
            if (!flag1)
            {
                return(null);
            }
            Job job1 = new Job(JobDefOf.DoBill, thing)
            {
                targetQueueB = new List <TargetPack>(this.chosenIngThings.Count),
                numToBring   = new List <int>(this.chosenIngThings.Count)
            };

            foreach (KeyValuePair <Thing, int> chosenIngThing in this.chosenIngThings)
            {
                job1.targetQueueB.Add(chosenIngThing.Key);
                job1.numToBring.Add(chosenIngThing.Value);
            }
            job1.reportString = bill.recipe.jobString;
            job1.haulMode     = HaulMode.ToCellNonStorage;
            job1.bill         = bill;
            return(job1);
        }