private void AllItems_DragDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent("dragStapleFormat"))
     {
         var    ingredientData = (SelectedIngredientsCollection)this.FindResource("SelectedIngredientsCollectionData");
         var    stapleElement  = e.Data.GetData("dragStapleFormat") as StapleItem;
         string stapleName     = stapleElement.Staple;
         var    staple         = new SelectedIngredient(stapleName, "");
         ingredientData.Add(staple);
     }
 }
Exemple #2
0
        public override bool Equals(object obj)
        {
            // Check for null values and compare run-time types.
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            SelectedIngredient otherIngredient = (SelectedIngredient)obj;

            if (otherIngredient.DateToUse == _dateToUse && otherIngredient._ingredient == _ingredient)
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// The drop event for adding a meal to the Daily List
        /// </summary>
        private void List_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("dragMealFormat"))
            {
                // sender is itemsControl
                // Update the table data
                int          updateIndex  = DecideDropTarget(e, (ItemsControl)sender);
                var          xElement     = e.Data.GetData("dragMealFormat") as XmlElement;
                var          colData      = (SelectedMealCollection)this.FindResource("SelectedMealCollectionData");
                SelectedMeal mealToUpdate = colData[updateIndex];

                mealToUpdate.addMeal(xElement.GetAttribute("name"));

                if (mealToUpdate.Ingredients == null)
                {
                    mealToUpdate.Ingredients = new List <string>();
                }

                foreach (XmlNode ingredientNode in xElement.SelectNodes("Ingredients/Ingredient"))
                {
                    mealToUpdate.Ingredients.Add(ingredientNode.InnerText);
                }

                // Update the selected ingredient view
                var ingredientData = (SelectedIngredientsCollection)this.FindResource("SelectedIngredientsCollectionData");
                if (mealToUpdate.Ingredients != null)
                {
                    foreach (string ingredient in mealToUpdate.Ingredients)
                    {
                        var selectedIngredient = new SelectedIngredient(ingredient, mealToUpdate.DateTime.ToString("yyyy-MM-dd"));
                        if (!ingredientData.Contains(selectedIngredient))
                        {
                            ingredientData.Add(selectedIngredient);
                        }
                    }
                }
            }

            _index = -1;
        }
Exemple #4
0
        public async Task <DateTime> LoadLatest(string endPoint, SelectedMealCollection mealData, SelectedIngredientsCollection ingredientsData)
        {
            DateTime startDate = DateTime.MinValue;

            try
            {
                string data = await ServerGet(endPoint);

                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(data);
                var meals = xmlDoc.SelectNodes("//ArrayOfSelectedMeal/SelectedMeal");

                mealData.Clear();
                foreach (XmlNode xmlNode in meals)
                {
                    // <ArrayOfSelectedMeal>
                    // Now populate meals and staples
                    string date         = xmlNode.SelectSingleNode("DateTime").InnerText;
                    var    ingredients  = xmlNode.SelectNodes("Ingredients/string");
                    var    mealsForDate = xmlNode.SelectNodes("Meals/string");
                    var    selectedMeal = new SelectedMeal();

                    // Datetime conversion
                    DateTime mealDate;
                    if (DateTime.TryParse(date, out mealDate))
                    {
                        selectedMeal.DateTime = mealDate;
                        if (startDate == DateTime.MinValue || mealDate < startDate)
                        {
                            startDate = mealDate;
                        }
                    }

                    foreach (XmlNode mealNode in mealsForDate)
                    {
                        selectedMeal.addMeal(mealNode.InnerText);
                    }

                    foreach (XmlNode ingredientNode in ingredients)
                    {
                        selectedMeal.Ingredients.Add(ingredientNode.InnerText);
                    }

                    mealData.Add(selectedMeal);
                }

                //<ArrayOfSelectedIngredient>
                var selectedIngredients = xmlDoc.SelectNodes("//ArrayOfSelectedIngredient/SelectedIngredient");

                ingredientsData.Clear();
                foreach (XmlNode xmlNode in selectedIngredients)
                {
                    string ingredient = xmlNode.SelectSingleNode("Ingredient").InnerText;
                    string date       = xmlNode.SelectSingleNode("DateToUse").InnerText;

                    var selectedIngredient = new SelectedIngredient();
                    selectedIngredient.Ingredient = ingredient;
                    selectedIngredient.DateToUse  = date;
                    ingredientsData.Add(selectedIngredient);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to load data from server: " + ex.Message, "Failed Load", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(startDate);
        }