예제 #1
0
 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     if (!int.TryParse(NavigationContext.QueryString["id"], out entryId))
         throw new ArgumentNullException("no food id was passed");
     else
         selectedEntry = DailyBurnService.NutritionLog.foodEntries[entryId];
 }
예제 #2
0
        public static void ModifyFoodEntry (food_log_entry ModifiedEntry, RestCallback Callback)
        {
            //Modify is not implemented so we will do a delete and an add
            //Store off the actual callback and IDfor later
            modifiedCallback = Callback;
            oldId = ModifiedEntry.id;

            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("food_log_entry[food_id]", ModifiedEntry.food_id.ToString());
            parameters.Add("food_log_entry[servings_eaten]", ModifiedEntry.servings_eaten.ToString());
            parameters.Add("food_log_entry[logged_on]", ModifiedEntry.created_at.ToString("yyyy-MM-dd"));

            if (ModifiedEntry.meal_name_id != 0)
                parameters.Add("food_log_entry[meal_name_id]", ModifiedEntry.meal_name_id.ToString());

            HelperMethods.CallDailyBurnApiPost(DailyBurnSettings.FoodLogEntriesAPI,
                                          modifiedFoodLogAddCallback,
                                          parameters);
            //we invalidated the model so cause a get
            DailyBurnService.NutritionLog = null;

        }
예제 #3
0
        private TextBlock createAndAddTextBlock(food_log_entry food, string textValue, Thickness margin, int column, int columnSpan, TextAlignment textAlignment, bool isHeaderRow)
        {

            TextBlock tb = new TextBlock();
            tb.Text = textValue;
            tb.TextWrapping = TextWrapping.Wrap;
            tb.Margin = margin;
            tb.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
            tb.TextAlignment = textAlignment;
            tb.Width = Double.NaN;
            tb.FontSize = 16;
            tb.Tag = food;

            tb.MouseLeftButtonDown += new MouseButtonEventHandler(tb_MouseLeftButtonDown);

            if (mealGrid.RowDefinitions.Count % 2 == 0 && !isHeaderRow)
            {
                Border b = new Border();
                b.Background = new SolidColorBrush(Color.FromArgb(95, 35, 35, 40));
                b.Child = tb;
                mealGrid.Children.Add(b);
                Grid.SetRow(b, mealGrid.RowDefinitions.Count - 1);
                Grid.SetRowSpan(b, 1);
                Grid.SetColumn(b, column);
                Grid.SetColumnSpan(b, columnSpan);
            }
            else
            {
                mealGrid.Children.Add(tb);
                Grid.SetRow(tb, mealGrid.RowDefinitions.Count - 1);
                Grid.SetRowSpan(tb, 1);
                Grid.SetColumn(tb, column);
                Grid.SetColumnSpan(tb, columnSpan);

            }
            return tb;
        }
예제 #4
0
        private void addFoodItemRow(food_log_entry MealItem)
        {
            Thickness margin = new Thickness(2,2,2, 0);
            addRowToMealGrid();

            string foodUrl = MealItem.food_picture_url;

            addFoodImage(foodUrl, margin);
            
            createAndAddTextBlock(MealItem, MealItem.food_name + Environment.NewLine + dbwp7Resources.ServingsLabel + MealItem.servings_eaten.ToString(), 
                                  margin, 1, 1, TextAlignment.Left, false);
            createAndAddTextBlock(MealItem, MealItem.calories_eaten.ToString(), margin, 2, 1, TextAlignment.Right, false);
            createAndAddTextBlock(MealItem, MealItem.total_fat_eaten.ToString(), margin, 3, 1, TextAlignment.Right, false);
            createAndAddTextBlock(MealItem, MealItem.total_carbs_eaten.ToString(), margin, 4, 1, TextAlignment.Right, false);
            createAndAddTextBlock(MealItem, MealItem.protein_eaten.ToString(), margin, 5, 1, TextAlignment.Right, false);

        }
예제 #5
0
 private void AddFoodItemRow(food_log_entry MealItem)
 {
     Dispatcher.BeginInvoke(() =>
         {
             addFoodItemRow(MealItem);
         });
 }
예제 #6
0
 private void updateDailyTotals(food_log_entry current)
 {
     totalCaloriesDay += current.calories_eaten;
     totalCarbsDay += current.total_carbs_eaten;
     totalFatDay += current.total_fat_eaten;
     totalProtDay += current.protein_eaten;
 }
예제 #7
0
        private void parseFoodLogEntries(Hammock.RestResponse response)
        {
            /* JSON is horked have to use XML
            DataContractJsonSerializer jSon = new DataContractJsonSerializer(typeof(food_log_entry[]));
            food_log_entry[] foodEntries = jSon.ReadObject(response.ContentStream) as food_log_entry[];*/

            XmlReader rdr = XmlReader.Create(response.ContentStream);
            while (!rdr.EOF)
            {
                if (rdr.ReadToFollowing("food-log-entry"))
                {
                    food_log_entry current = new food_log_entry();
                    rdr.ReadToFollowing("calories-eaten");
                    current.calories_eaten = rdr.ReadElementContentAsFloat();
                    rdr.ReadToFollowing("created-at");
                    current.created_at = rdr.ReadElementContentAsDateTime();
                    rdr.ReadToFollowing("food-id");
                    current.food_id = rdr.ReadElementContentAsInt();
                    rdr.ReadToFollowing("id");
                    current.id = rdr.ReadElementContentAsInt();
                    rdr.ReadToFollowing("logged-on");
                    current.logged_on = rdr.ReadElementContentAsDateTime();
                    rdr.ReadToFollowing("meal-name-id");
                    if (!rdr.MoveToAttribute("nil"))
                        current.meal_name_id = rdr.ReadElementContentAsInt();
                    else
                        current.meal_name_id = 0;
                    rdr.ReadToFollowing("servings-eaten");
                    current.servings_eaten = rdr.ReadElementContentAsFloat();
                    rdr.ReadToFollowing("user-id");
                    current.user_id = rdr.ReadElementContentAsInt();
                    rdr.ReadToFollowing("total-fat-eaten");
                    current.total_fat_eaten = rdr.ReadElementContentAsFloat();
                    rdr.ReadToFollowing("total-carbs-eaten");
                    current.total_carbs_eaten = rdr.ReadElementContentAsFloat();
                    rdr.ReadToFollowing("protein-eaten");
                    current.protein_eaten = rdr.ReadElementContentAsFloat();
                    rdr.ReadToFollowing("food-name");
                    current.food_name = rdr.ReadElementContentAsString();
                    rdr.ReadToFollowing("food-picture-url");
                    current.food_picture_url = rdr.ReadElementContentAsString();

                    updateDailyTotals(current);
                    foodEntries.Add(current.id, current);
                    
                    if (mealEntries.ContainsKey(current.meal_name_id))
                        mealEntries[current.meal_name_id].Add(current);
                    else
                    {
                        List<food_log_entry> list = new List<food_log_entry>();
                        list.Add(current);
                        mealEntries.Add(current.meal_name_id,list);
                    }

                }
            }
        }