コード例 #1
0
 public RecipeDetails()
 {
     InitializeComponent();
     CurrentFrame    = 0;
     AddButton.Speed = 4.0f;
     selectedItem    = null;
 }
コード例 #2
0
 public void RemoveIngredientItem(IngredientItem item)
 {
     if (ingredientBag.Contains(item))
     {
         ingredientBag.Remove(item);
     }
 }
コード例 #3
0
        // Add ingredient item
        public static async void UpdateRecipeAdd(RecipeItems selectedRecipe, IngredientItem newIngredient)
        {
            try
            {
                var SingleRecipeObject =
                    (await firebase
                     .Child(Application.Current.Properties["Id"].ToString())
                     .Child("Recipes")
                     .OnceAsync <RecipeItems>()).Where(a => a.Object.RecipeName == selectedRecipe.RecipeName).Where(a => a.Object.IngredientsList.Count == selectedRecipe.IngredientsList.Count).FirstOrDefault();;


                await firebase
                .Child(Application.Current.Properties["Id"].ToString())
                .Child("Recipes")
                .Child(SingleRecipeObject.Key)
                .Child("IngredientsList")
                .Child(SingleRecipeObject.Object.IngredientsList.Count.ToString())
                .PutAsync(new IngredientItem(newIngredient));

                //update nutrition facts here
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Error:{e}");
            }
        }
コード例 #4
0
 public IActionResult SaveItemsIngr(ItemIngredientViewModel i)
 {
     if (i.IsChoosed == true)
     {
         var k = _context.ingredientItems.Where(l => l.ItemId == i.ItemId).Where(f => f.IngredientId == i.IngredientId).FirstOrDefault();
         if (k == null)
         {
             var n = new IngredientItem();
             n.IngredientId = i.IngredientId;
             n.ItemId       = i.ItemId;
             n.Quantity     = i.Quantity;
             _context.Add(n);
             _context.SaveChanges();
         }
         else
         {
             if (k.Quantity != i.Quantity)
             {
                 k.Quantity = i.Quantity;
                 _context.Update(k);
                 _context.SaveChanges();
             }
         }
     }
     else
     {
         var k = _context.ingredientItems.Where(l => l.ItemId == i.ItemId).Where(f => f.IngredientId == i.IngredientId).FirstOrDefault();
         if (k != null)
         {
             _context.Remove(k);
             _context.SaveChanges();
         }
     }
     return(Ok(i));
 }
コード例 #5
0
        public override GameItem Clone()
        {
            IngredientItem clone = new IngredientItem();

            SetBasicCloneItem(clone);

            return(clone);
        }
コード例 #6
0
 public void RewardsZone3()
 {
     RewardCommon   = SelectedLocationItem.CommonLocation_3 [Random.Range(0, SelectedLocationItem.CommonLocation_3.Count)];
     RewardUncommon = SelectedLocationItem.UncommonLocation_3 [Random.Range(0, SelectedLocationItem.UncommonLocation_3.Count)];
     RewardRare     = SelectedLocationItem.RareLocation_3 [Random.Range(0, SelectedLocationItem.RareLocation_3.Count)];
     //Instantiate(ObtainedRewards);
     Gathering();
     CurrentTravelTime = SelectedLocationItem.TravelTimeLoc1;
 }
コード例 #7
0
        public IEnumerable <RecipeItem> GetLunchRecipies(RecipeForecastRequest request)
        {
            List <RecipeItem>     reqRecipes     = request.recipes;
            List <IngredientItem> reqIngredients = request.ingredients;

            List <RecipeItem> toprecipes = new List <RecipeItem>();
            List <RecipeItem> botrecipes = new List <RecipeItem>();
            DateTime          todaysDate = DateTime.Today;

            foreach (var item in reqRecipes)
            {
                bool can_use_recipe = true;
                bool top_recipe     = true;
                foreach (var rec_ingr in item.ingredients)
                {
                    if (can_use_recipe == true)
                    {
                        if (!reqIngredients.Any(z => z.title == rec_ingr))
                        {
                            can_use_recipe = false;
                        }
                        else
                        {
                            IngredientItem selected_ingredient = reqIngredients.Find(x => x.title == rec_ingr);
                            if (selected_ingredient.useBy < todaysDate)
                            {
                                can_use_recipe = false;
                            }
                            else
                            {
                                if (top_recipe == true)
                                {
                                    if (selected_ingredient.bestBefore < todaysDate)
                                    {
                                        top_recipe = false;
                                    }
                                }
                            }
                        }
                    }
                }
                if (can_use_recipe == true)
                {
                    if (top_recipe == true)
                    {
                        toprecipes.Add(item);
                    }
                    else
                    {
                        botrecipes.Add(item);
                    }
                }
            }
            return(toprecipes.Concat(botrecipes));
        }
コード例 #8
0
        private void SetEditFrame(IngredientItem item)
        {
            // Set stored values
            QuantityEntry.Text = item.Quantity.ToString();
            UnitEntry.Text     = item.Unit.ToString();
            WeightEntry.Text   = item.Weight.ToString();
            NameEntry.Text     = item.Name.ToString();
            CaloriesEntry.Text = item.Calories.ToString();

            NewItemEntry.IsVisible = true;
        }
コード例 #9
0
        //public Cauldron()// : base("Cauldron") { }

        #region Inherited

        public override string GenerateJson(bool topLevel)
        {
            var b = new StringBuilder(base.GenerateJson(false));

            if (BrewTime > 0)
            {
                b.AppendFormat("BrewTime:{0},", BrewTime);
            }

            var items = new string[4];

            var s = IngredientItem.GenerateJson(false);

            if (!string.IsNullOrWhiteSpace(s))
            {
                items[0] = s;
            }

            for (var i = 0; i < 3; i++)
            {
                s = Items[i].GenerateJson(false);
                if (!string.IsNullOrWhiteSpace(s))
                {
                    items[i + 1] = s;
                }
            }

            if (items.All(string.IsNullOrWhiteSpace))
            {
                return(b.ToString());
            }

            b.Append("Items:[");
            for (var i = 0; i < 4; i++)
            {
                s = items[i];
                if (string.IsNullOrWhiteSpace(s))
                {
                    continue;
                }
                if (s.EndsWith(","))
                {
                    s = s.Remove(s.Length - 1, 1);
                }
                b.AppendFormat("{0}:{{{1}}},", i, s);
            }
            b.Remove(b.Length - 1, 1);
            b.Append("]");

            return(b.ToString());
        }
コード例 #10
0
ファイル: Plate.cs プロジェクト: tiagosomda/roachcoach
    void OnTriggerEnter(Collider col)
    {
        IngredientItem item = col.GetComponent <IngredientItem>();

        if (item == null)
        {
            return;
        }
        else
        {
            items.Push(item);
            Debug.Log("Added IngredientItem");
        }
    }
コード例 #11
0
        public void FillGrid()
        {
            _list.ListView.Clear();

            string[] contents = File.ReadAllLines(FilePath);

            foreach (string line in contents)
            {
                string[] temp = line.Split('-'); //temp should always have only two strings contained after this point, the ID and the Name

                IngredientItem G = new IngredientItem(new Ingredient(Convert.ToInt32(temp[0]), temp[1], ""), 0.0f, Measurements.Serving);
                _list.Add(G);
            }
        }
コード例 #12
0
 private void EditButton_OnClick(object sender, EventArgs e)
 {
     // Save
     if (CurrentFrame == 44)
     {
         SaveEdit();
     }
     else
     {
         singleItem = selectedItem;
         SetEditFrame(singleItem);
         EditButton.PlayFrameSegment(0, 44);
         CurrentFrame = 44;
     }
 }
コード例 #13
0
        public static async void UpdateRecipeEdit(SingleRecipeData selectedRecipe, IngredientItem unEditedIngredient, IngredientItem editedIngredient)
        {
            try
            {
                var SingleRecipeObject =
                    (await firebase
                     .Child(Application.Current.Properties["Id"].ToString())
                     .Child("Recipes")
                     .OnceAsync <RecipeItems>()).Where(a => a.Object.RecipeName == selectedRecipe.RecipeTitle)
                    .Where(a => a.Object.IngredientsList.Count == selectedRecipe.Items.Count).FirstOrDefault();;

                int editIndex = -1;
                for (int i = 0; i < selectedRecipe.Items.Count; i++)
                {
                    if (selectedRecipe.Items.ElementAt(i) == unEditedIngredient)
                    {
                        editIndex = i;
                    }
                }

                // if index was not found(it should)
                if (editIndex == -1)
                {
                    Debug.WriteLine("UpdateRecipeEdit failed to match index of item to be edited");
                    return;
                }

                await firebase
                .Child(Application.Current.Properties["Id"].ToString())
                .Child("Recipes")
                .Child(SingleRecipeObject.Key)
                .Child("IngredientsList")
                .Child(editIndex.ToString())
                .PutAsync(new IngredientItem(editedIngredient));

                await firebase
                .Child(Application.Current.Properties["Id"].ToString())
                .Child("Recipes")
                .Child(SingleRecipeObject.Key)
                .Child("NutritionValues")
                .PutAsync(new NutritionFacts(selectedRecipe.NutritionValues));
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Error:{e}");
            }
        }
コード例 #14
0
 private void IngredientsList_ItemTapped(object sender, ItemTappedEventArgs e)
 {
     if (previousItem == IngredientsList.SelectedItem)
     {
         IngredientsList.SelectedItem = null;
         AddButton.IsVisible          = true;
         EditButtonFrame.IsVisible    = false;
     }
     else
     {
         previousItem = selectedItem;
         selectedItem = e.Item as IngredientItem;
         if (!EditButtonFrame.IsVisible)
         {
             AddButton.IsVisible       = false;
             EditButtonFrame.IsVisible = true;
         }
     }
 }
コード例 #15
0
        private async void AddButton_Clicked(object sender, EventArgs e)
        {
            string ConnectionString = SqlHelper.GetConnectionString();
            string query            = String.Format("SELECT IngredientID, LOWER(LongDesc) FROM INGREDIENT WHERE LOWER(LongDesc) LIKE '{0},%';", IngredientEntry.Text.ToLower());

            SqlConnection con  = new SqlConnection(ConnectionString);
            SqlCommand    comm = new SqlCommand(query, con);

            try
            {
                con.Open();
            }
            catch (Exception)
            {
                await DisplayAlert("Failed", "Could not connect", "OK");
            }

            try
            {
                SqlDataReader read = comm.ExecuteReader();

                //This section assumes that no Ingredients have duplicate CommonNames
                if (read.Read())
                {
                    string         temp     = read.GetString(1);
                    string[]       contents = temp.Split(',');
                    IngredientItem G        = new IngredientItem(new Ingredient(read.GetInt32(0), contents[0], ""), 0.0f, Measurements.Serving);
                    _list.Add(G);

                    File.AppendAllText(FilePath, String.Format("{0}-{1}\n", G.ID.ToString(), G.Name));
                }
                else
                {
                    await DisplayAlert("Error", "This Ingredient could not be found", "OK");
                }
            }
            catch (Exception)
            {
                await DisplayAlert("Error", "Exception thrown while reading from database", "OK");
            }
            con.Close();
        }
コード例 #16
0
        private void Button_Clicked(object sender, EventArgs e)
        {
            // Add item
            if (CurrentFrame == 25)
            {
                NewItemEntry.IsVisible    = true;
                IngredientsList.IsEnabled = false;
                QuantityEntry.Focus();
                singleItem = new IngredientItem();
                AddButton.PlayFrameSegment(25, 45);
                CurrentFrame = 45;
                return;
            }

            // Cancel
            if (CurrentFrame == 45)
            {
                ResetNewItemFrame();
                AddButton.PlayFrameSegment(45, 125);
                AddButton.PlayFrameSegment(0, 25);
                CurrentFrame = 25;
            }
        }
コード例 #17
0
        async public void FillGrid()
        {
            string ConnectionString = SqlHelper.GetConnectionString();
            //Below querys assumes that UserIDs and PantryIDs are equivalent
            //Commented query below will be used when more columns are added to INGREDIENT
            //string query = String.Format("SELECT ING.IngredientID, ING.CommonName, ING.LongDesc, Quantity FROM PANTRY_INGREDIENTS AS PING JOIN INGREDIENT AS ING ON PING.IngredientID = ING.IngredientID WHERE PantryID = {0};", SqlHelper.UserID);
            string query = String.Format("SELECT IngredientID, CommonName, Quantity FROM PANTRY_INGREDIENTS WHERE PantryID={0};", SqlHelper.UserID);

            SqlConnection con  = new SqlConnection(ConnectionString);
            SqlCommand    comm = new SqlCommand(query, con);

            try
            {
                con.Open();
            }
            catch (Exception)
            {
                await DisplayAlert("Failed", "Could not connect", "OK");
            }

            try
            {
                SqlDataReader read = comm.ExecuteReader();

                while (read.Read())
                {
                    IngredientItem p = new IngredientItem(new Ingredient(read.GetInt32(0), read.GetString(1), ""), read.GetInt32(2), Measurements.Serving);
                    _list.Add(p);
                }
            }
            catch (Exception)
            {
                await DisplayAlert("Error", "Exception thrown while reading from database in FillGrid", "OK");
            }

            con.Close();
        }
コード例 #18
0
 private void SaveEdit()
 { //todo Edit in firebase
     thisRecipe = (BindingContext as SingleRecipeData);
     for (int i = 0; i < thisRecipe.Items.Count; i++)
     {
         if (selectedItem == thisRecipe.Items.ElementAt(i))
         {
             thisRecipe.Items.ElementAt(i).Equals(singleItem);
             thisNutrition.UpdateValues();
             FirebaseHelper.UpdateRecipeEdit(thisRecipe, selectedItem, singleItem);
             IngredientsList.SelectedItem = null;
             previousItem = null;
             selectedItem = null;
             EditButton.PlayFrameSegment(44, 63);
             EditButton.PlayFrameSegment(63, 2);
             ResetNewItemFrame();
             EditButtonFrame.IsVisible = false;
             AddButton.IsVisible       = true;
             AddButton.PlayFrameSegment(45, 125);
             AddButton.PlayFrameSegment(0, 25);
             CurrentFrame = 25;
         }
     }
 }
コード例 #19
0
 public void AddIngredient(IngredientItem item)
 {
     IngredientInventory.Add(item);
 }
コード例 #20
0
 public IActionResult ChooseIngr(IngredientItem i)
 {
     _context.Add(i);
     _context.SaveChanges();
     return(Ok(i));
 }
コード例 #21
0
        //This ugly function uses three queries. I'm sure they could maybe be made into less but I'm not sure at the moment.
        private async void AddButton_Clicked(object sender, EventArgs e)
        {
            string ConnectionString = SqlHelper.GetConnectionString();
            string query            = String.Format("SELECT IngredientID, LOWER(LongDesc) FROM INGREDIENT WHERE LOWER(LongDesc) LIKE '{0},%';", IngredientEntry.Text.ToLower());

            SqlConnection con  = new SqlConnection(ConnectionString);
            SqlCommand    comm = new SqlCommand(query, con);

            string ingrname      = "default";
            int    ingrid        = -1;
            int    count         = 1;
            bool   alreadyexists = false;

            try
            {
                con.Open();
            }
            catch (Exception)
            {
                await DisplayAlert("Failed", "Could not connect", "OK");

                return;
            }

            try
            {
                SqlDataReader read = comm.ExecuteReader();

                if (!read.Read())
                {
                    con.Close();
                    read.Close();
                    await DisplayAlert("Error", "The specified ingredient does not exist", "OK");

                    return;
                }
                else
                {
                    ingrid   = read.GetInt32(0);
                    ingrname = read.GetString(1);
                    //Long desc currently contains a bunch of garbage after the first comma
                    //This grabs the first word before the comma
                    string[] contents = ingrname.Split(',');
                    ingrname = contents[0];
                }
                read.Close();
            }
            catch (Exception)
            {
                await DisplayAlert("Error", "Exception thrown while reading from database", "OK");

                return;
            }
            //Below assumes that the PantryID and UserID are equal
            query = String.Format("SELECT Quantity FROM PANTRY_INGREDIENTS WHERE IngredientID={0} AND PantryID={1}", ingrid, SqlHelper.UserID);
            comm  = new SqlCommand(query, con);

            try
            {
                SqlDataReader read = comm.ExecuteReader();

                if (read.Read())
                {
                    alreadyexists = true;
                    count         = read.GetInt32(0) + 1;
                }
                else
                {
                    alreadyexists = false;
                    count         = 1;
                }
                read.Close();
            }
            catch (Exception)
            {
                await DisplayAlert("Error", "Exception thrown while reading from database", "OK");

                return;
            }

            //Below assumes that the PantryID and UserID are equal
            if (alreadyexists)
            {
                query = String.Format("UPDATE PANTRY_INGREDIENTS SET Quantity={0} WHERE PantryID={1} AND IngredientID={2};", count, SqlHelper.UserID, ingrid);
                IngredientItem p = _list.ListView.Single(x => x.ID == ingrid); //Finds the ingredient in the ListView that matches the user input

                //The quantity didn't update unless I removed it first
                int index = _list.ListView.IndexOf(p);
                _list.ListView.RemoveAt(index);
                p.Quantity += 1;
                _list.ListView.Insert(index, p);
            }
            else
            {
                query = String.Format("INSERT INTO PANTRY_INGREDIENTS VALUES({0}, {1}, '{2}', {3});", SqlHelper.UserID, ingrid, ingrname, 1);
                IngredientItem p = new IngredientItem(new Ingredient(ingrid, ingrname, ""), 1.0f, Measurements.Serving);

                _list.Add(p);
            }

            comm = new SqlCommand(query, con);

            comm.ExecuteNonQuery();
            con.Close();
        }
コード例 #22
0
        private async void RemoveButton_Clicked(object sender, EventArgs e)
        {
            string ConnectionString = SqlHelper.GetConnectionString();
            string query            = String.Format("SELECT IngredientID, LOWER(LongDesc) FROM INGREDIENT WHERE LOWER(LongDesc) LIKE '{0},%';", IngredientEntry.Text.ToLower());

            SqlConnection con  = new SqlConnection(ConnectionString);
            SqlCommand    comm = new SqlCommand(query, con);

            int ingrid = -1;
            int count  = 0;

            try
            {
                con.Open();
            }
            catch (Exception)
            {
                await DisplayAlert("Failed", "Could not connect", "OK");

                return;
            }

            try
            {
                SqlDataReader read = comm.ExecuteReader();

                if (!read.Read())
                {
                    con.Close();
                    read.Close();
                    await DisplayAlert("Error", "The specified ingredient does not exist", "OK");

                    return;
                }
                else
                {
                    ingrid = read.GetInt32(0);
                }
                read.Close();
            }
            catch (Exception)
            {
                await DisplayAlert("Error", "Exception thrown while reading from database", "OK");

                return;
            }

            query = String.Format("SELECT Quantity FROM PANTRY_INGREDIENTS WHERE IngredientID={0} AND PantryID={1}", ingrid, SqlHelper.UserID);
            comm  = new SqlCommand(query, con);

            try
            {
                SqlDataReader read = comm.ExecuteReader();

                if (read.Read())
                {
                    count = read.GetInt32(0);
                }
                else
                {
                    await DisplayAlert("Error", "That ingredient is not in your pantry", "OK");
                }
                read.Close();
            }
            catch (Exception)
            {
                await DisplayAlert("Error", "Exception thrown while reading from database", "OK");

                return;
            }

            if (count == 1)
            {
                query = String.Format("DELETE FROM PANTRY_INGREDIENTS WHERE IngredientID={0} AND PantryID={1}", ingrid, SqlHelper.UserID);
                IngredientItem p = _list.ListView.Single(x => x.ID == ingrid); //Finds the ingredient in the ListView that matches the user input
                _list.ListView.Remove(p);
            }
            else
            {
                query = String.Format("UPDATE PANTRY_INGREDIENTS SET Quantity={0} WHERE IngredientID={1} AND PantryID={2};", count - 1, ingrid, SqlHelper.UserID);

                IngredientItem p = _list.ListView.Single(x => x.ID == ingrid); //Finds the ingredient in the ListView that matches the user input

                //The quantity didn't update unless I removed it first
                int index = _list.ListView.IndexOf(p);
                _list.ListView.RemoveAt(index);
                p.Quantity -= 1;
                _list.ListView.Insert(index, p);
            }

            comm = new SqlCommand(query, con);
            comm.ExecuteNonQuery();

            con.Close();
        }
コード例 #23
0
 public void AddIngredientItem(IngredientItem item)
 {
     ingredientBag.Add(item);
 }
コード例 #24
0
        public void Serialize()
        {
            Dictionary <ItemID, GameItem> dictionary = new Dictionary <ItemID, GameItem>();

            Sword sword = new Sword
            {
                ItemId      = ItemID.OLD_SWORD,
                Name        = "OldSword",
                PrefabName  = "OldSword",
                AttackPower = 10,
                IconName    = "OldSword",
                Type        = ItemType.Sword
            };

            dictionary.Add(sword.ItemId, sword);

            Bow bow = new Bow
            {
                ItemId      = ItemID.OLD_BOW,
                Name        = "OldBow",
                PrefabName  = "OldBow",
                AttackPower = 10,
                IconName    = "OldBow",
                Type        = ItemType.Bow
            };

            dictionary.Add(bow.ItemId, bow);

            Potion potion = new Potion
            {
                ItemId     = ItemID.POTION,
                Name       = "Potion",
                PrefabName = "Potion",
                IconName   = "Potion",
                Type       = ItemType.Potion
            };

            dictionary.Add(potion.ItemId, potion);


            Arrow arrow = new Arrow
            {
                ItemId     = ItemID.ARROW,
                Name       = "Arrow",
                PrefabName = "Arrow",
                IconName   = "Arrow",
                Type       = ItemType.Arrow
            };

            dictionary.Add(arrow.ItemId, arrow);

            IngredientItem stone = new IngredientItem
            {
                ItemId     = ItemID.STONE,
                Name       = "Stone",
                PrefabName = "StonePrefab",
                IconName   = "StoneIcon",
                Type       = ItemType.Ingredient
            };

            dictionary.Add(stone.ItemId, stone);

            string json = JsonConvert.SerializeObject(dictionary);

            File.WriteAllText(ItemsFilePath, json);
        }
コード例 #25
0
 public IActionResult ChooseIng([FromBody] IngredientItem c)
 {
     _context.Add(c);
     _context.SaveChanges();
     return(Ok(c));
 }
コード例 #26
0
 public void AddToPlayerInventPortal(IngredientItem IngredientToAdd)
 {
     Invent.IngredientInventory.Add(IngredientToAdd);
     //instatiate progress bar and timer
 }