public override void EvaluateQuantityForLot(ComplexProductionDetail detail, double availableQuantity, double qttyToUse)
        {
            ComplexRecipe cr = detail.SourceRecipe;

            detail.SourceRecipe = null;
            detail.QuantityEvaluate(qttyToUse, this);
            detail.SourceRecipe = cr;
        }
        protected override void EvaluateQuantityForEmptyLot(ComplexProductionDetail detail, double qttyToUse)
        {
            ComplexRecipe cr = detail.SourceRecipe;

            detail.SourceRecipe = null;
            detail.QuantityEvaluate(qttyToUse, this);
            detail.SourceRecipe = cr;
        }
        public static ComplexRecipe GetById(long id)
        {
            ComplexRecipe ret = BusinessDomain.DataAccessProvider.GetComplexRecipeById <ComplexRecipe> (id);

            if (ret != null)
            {
                ret.RecalculatePrices();
                ret.IsDirty = false;
            }
            return(ret);
        }
        /// <summary>
        /// Removes all material and production details which use the specified recipe.
        /// </summary>
        /// <param name="recipe">The recipe that marks the details to remove.</param>
        public void RemoveRecipe(ComplexRecipe recipe)
        {
            for (int i = DetailsMat.Count - 1; i >= 0; i--)
            {
                if (DetailsMat [i].SourceRecipe.Id == recipe.Id)
                {
                    DetailsMat.RemoveAt(i);
                }
            }

            for (int i = DetailsProd.Count - 1; i >= 0; i--)
            {
                if (DetailsProd [i].SourceRecipe.Id == recipe.Id)
                {
                    DetailsProd.RemoveAt(i);
                }
            }
        }
        public bool AddRecipe(ComplexRecipe recipe, PriceGroup pGroup, long finalProductId = -1)
        {
            int materialsRow = DetailsMat.Count;

            for (int i = DetailsMat.Count - 1; i >= 0; i--)
            {
                if (!string.IsNullOrWhiteSpace(DetailsMat [i].ItemName))
                {
                    break;
                }

                materialsRow = i;
            }

            int productsRow = DetailsProd.Count;

            for (int i = DetailsProd.Count - 1; i >= 0; i--)
            {
                if (!string.IsNullOrWhiteSpace(DetailsProd [i].ItemName))
                {
                    break;
                }

                productsRow = i;
            }

            ComplexProductionDetail prodDetail = new ComplexProductionDetail();

            if (recipe.DetailsMat.Any(detail => !prodDetail.CheckItemCanEvaluate(Item.Cache.GetById(detail.ItemId))))
            {
                return(false);
            }

            if (recipe.DetailsProd.Any(detail => !prodDetail.CheckItemCanEvaluate(Item.Cache.GetById(detail.ItemId))))
            {
                return(false);
            }

            if (DetailsMat.Count <= materialsRow)
            {
                AddNewDetail();
            }

            foreach (ComplexRecipeDetail detail in recipe.DetailsMat)
            {
                if (DetailsMat.Count <= materialsRow)
                {
                    AddNewDetail();
                }

                prodDetail = DetailsMat [materialsRow];
                prodDetail.ItemEvaluate(Item.Cache.GetById(detail.ItemId), pGroup, true);
                prodDetail.Quantity     = detail.Quantity;
                prodDetail.SourceRecipe = recipe;
                if (finalProductId >= 0)
                {
                    prodDetail.FinalProductId = finalProductId;
                }

                materialsRow++;
            }

            foreach (ComplexRecipeDetail detail in recipe.DetailsProd)
            {
                if (DetailsProd.Count <= productsRow)
                {
                    AddNewAdditionalDetail();
                }

                prodDetail = DetailsProd [productsRow];
                prodDetail.ItemEvaluate(Item.Cache.GetById(detail.ItemId), pGroup, true);
                prodDetail.Quantity     = detail.Quantity;
                prodDetail.SourceRecipe = recipe;
                if (finalProductId >= 0)
                {
                    prodDetail.FinalProductId = finalProductId;
                }

                productsRow++;
            }

            RecalculatePrices();
            return(true);
        }