Пример #1
0
        public ProgramManager(string UserFileSave, string UserFridgeFileSave, string RecipieDatabase, string FoodItemsDatabase, string RecipeSaveFile, string StatisticsSavePath, string ShoppingListSave)
        {
            UserFile = UserFileSave;

            UserFridgeFile = UserFridgeFileSave;

            RecipeSaverSaveFile  = RecipeSaveFile;
            StatisticsSaveFile   = StatisticsSavePath;
            ShoppingListSaveFile = ShoppingListSave;

            User = new UserTemplate(this);
            User = GetUser();
            User.CurrentManager = this;

            UserShoppingList      = new ShoppingList();
            UserShoppingList      = GetShoppingList();
            User.UserShoppingList = UserShoppingList;

            InitFridge(User);

            FoodItemsFile = FoodItemsDatabase;
            RecipiesFile  = RecipieDatabase;

            FoodManag = new FoodManager(FoodItemsFile);

            UserRecipeSaves = new RecipeSaver(RecipeSaverSaveFile);

            UserRecipeSaves = GetRecipeSaver();
            UserRecipeSaves.SaveLocation = RecipeSaverSaveFile;
            UserRecipeSaves.SaveRecipeSaver();

            StatManager = new StatisticsManager(StatisticsSaveFile)
            {
                SaveLocation = StatisticsSaveFile
            };
            StatManager.SaveStatistics();

            RecipieManag = new RecipeManager(RecipiesFile, this);
        }
Пример #2
0
        //Gets the amount needed to be removed based on what unit is being used and the density of the given food being modified. Returns a float.
        public static float GetAmountToRemove(string FoodName, float FoodAmount, string Unit, FoodManager foodManager)
        {
            float Mass        = 0;
            float FoodDensity = 0;
            float VolumeToUse = 0;

            if (Unit != "ml" && Unit != "Count")
            {
                if (foodManager.Foods.ContainsKey(FoodName))
                {
                    FoodDensity = foodManager.Foods[FoodName].FoodDensity;
                }

                if (StandardUnits.ContainsKey(Unit))
                {
                    VolumeToUse = StandardUnits[Unit];
                }

                Mass = FoodAmount * (VolumeToUse * FoodDensity);
            }

            if (Unit == "ml")
            {
                Mass = FoodAmount * StandardUnits[Unit];
            }

            if (Unit == "Count")
            {
                Mass = FoodAmount;
            }

            if (Unit == "g")
            {
                Mass = FoodAmount;
            }
            return(Mass);
        }
Пример #3
0
        public void AddToShoppingList(List <string> FoodItemsToChange, List <float> AmountsToChange, List <string> Units, FoodManager foodManager, ProgramManager programManager)
        {
            if (FoodItemsToChange != null)
            {
                for (int i = 0; i < FoodItemsToChange.Count; i++)
                {
                    float AmountToRemove = UnitConverter.GetAmountToRemove(FoodItemsToChange[i], AmountsToChange[i], Units[i], foodManager);

                    if (USUsersFoods.ContainsKey(FoodItemsToChange[i]))
                    {
                        foreach (KeyValuePair <string, FoodDef> element in USUsersFoods)
                        {
                            if (element.Value.USName == FoodItemsToChange[i] && element.Value.Amount - AmountToRemove < 0)
                            {
                                if (!programManager.UserShoppingList.USFoodsToBuy.Contains(FoodItemsToChange[i]))
                                {
                                    programManager.UserShoppingList.AddToShoppingList(element.Value.USName, element.Value.BGName);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!programManager.UserShoppingList.USFoodsToBuy.Contains(FoodItemsToChange[i]))
                        {
                            programManager.UserShoppingList.AddToShoppingList(FoodItemsToChange[i], foodManager.Foods[FoodItemsToChange[i]].BGName);
                        }
                    }
                }
                programManager.SaveShoppingList();
            }
            // Only if requirements are met does the function return true.
        }
Пример #4
0
        /// <summary>
        /// After using a certian product changes the Amount left, or if the AmountToChange is 0 removes the Item
        /// </summary>
        /// <param name="FoodItemToChange"></param>
        /// <param name="AmountToChange"></param>
        public void ModifyFoodItemAmount(List <string> FoodItemsToChange, List <float> AmountsToChange, List <string> Units, FoodManager foodManager, ProgramManager programManager)
        {
            for (int i = 0; i < FoodItemsToChange.Count; i++)
            {
                float AmountToRemove = UnitConverter.GetAmountToRemove(FoodItemsToChange[i], AmountsToChange[i], Units[i], foodManager);

                foreach (KeyValuePair <string, FoodDef> element in USUsersFoods)
                {
                    if (element.Value.USName.ToLower() == FoodItemsToChange[i].ToLower() && element.Value.Amount - AmountToRemove >= 0)
                    {
                        element.Value.Amount -= AmountToRemove;
                    }
                }
            }

            for (int i = 0; i < USUsersFoods.Count; i++)
            {
                if (USUsersFoods.ElementAt(i).Value.Amount == 0)
                {
                    if (!programManager.UserShoppingList.USFoodsToBuy.Contains(FoodItemsToChange[i]))
                    {
                        programManager.UserShoppingList.AddToShoppingList(USUsersFoods.ElementAt(i).Value.USName, USUsersFoods.ElementAt(i).Value.BGName);
                    }
                    USUsersFoods.Remove(USUsersFoods.ElementAt(i).Key);
                }
            }
            SaveFridge();
            programManager.SaveShoppingList();
        }
Пример #5
0
        /// <summary>
        /// Takes a string array, loops through the array checknig if the fridge dictionary contains such a key.
        /// If it doesn't contain even one item it breaks the loop and returns false.
        /// </summary>
        /// <param name="foods"></param>
        /// <returns></returns>
        public bool FridgeConatains(List <string> FoodItemsToChange, List <float> AmountsToChange, List <string> Units, FoodManager foodManager, ProgramManager programManager)
        {
            if (FoodItemsToChange != null)
            {
                for (int i = 0; i < FoodItemsToChange.Count; i++)
                {
                    float AmountToRemove = UnitConverter.GetAmountToRemove(FoodItemsToChange[i], AmountsToChange[i], Units[i], foodManager);

                    if (USUsersFoods.ContainsKey(FoodItemsToChange[i]))
                    {
                        foreach (KeyValuePair <string, FoodDef> element in USUsersFoods)
                        {
                            if (element.Value.USName == FoodItemsToChange[i] && element.Value.Amount - AmountToRemove < 0)
                            {
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            // Only if requirements are met does the function return true.
            return(true);
        }
Пример #6
0
        /// <summary>
        /// After using a certian product changes the Amount left, or if the AmountToChange is 0 removes the Item
        /// </summary>
        /// <param name="FoodItemToChange"></param>
        /// <param name="AmountToChange"></param>
        public void ModifyFoodItemAmount(List <string> FoodItemsToChange, List <float> AmountsToChange, List <string> Units, FoodManager foodManager)
        {
            for (int i = 0; i < FoodItemsToChange.Count; i++)
            {
                float AmountToRemove = UnitConverter.GetAmountToRemove(FoodItemsToChange[i], AmountsToChange[i], Units[i], foodManager);

                foreach (KeyValuePair <string, FoodDef> element in USUsersFoods)
                {
                    if (element.Value.USName.ToLower() == FoodItemsToChange[i].ToLower() && element.Value.Amount - AmountToRemove >= 0)
                    {
                        element.Value.Amount -= AmountToRemove;
                    }
                }
            }

            for (int i = 0; i < USUsersFoods.Count; i++)
            {
                if (USUsersFoods.ElementAt(i).Value.Amount == 0)
                {
                    USUsersFoods.Remove(USUsersFoods.ElementAt(i).Key);
                }
            }

            SaveFridge();
        }