private void UpdateTotals(string scope) { FoodData totals = new FoodData(); if (View.Model.MainWindow.UserData.PlannedDiet == null) { return; } foreach (DietPlanEntry entry in View.Model.MainWindow.UserData.PlannedDiet) { // Restrict results to the specified scope if (entry.Scope != scope) { continue; } FoodData data = USDA.GetFoodData(entry.FoodName); // Adjust the nutrient values to reflect the quantity and unit double quantity = Convert.ToDouble(entry.Quantity); string NDB_No = USDA.GetNDBNumber(entry.FoodName); double factor = USDA.GetNutrientConversionFactor(NDB_No, entry.Unit, quantity); data *= factor; // Add the adjusted data to the total totals += data; } // Apply rounding to the data if the option is set and update the data if (Settings.Default.Rounding == true) { totals = FoodData.Round(totals, Settings.Default.RoundingNumberOfFractionalDigits); } View.Model.MainWindow.FoodData = totals; }
public void Execute(object parameter) { if (View.Model.MainWindow.TotalsTabDataStatus.UpdateNeeded == false && View.Model.MainWindow.TotalsTabDataStatus.DataChanged == false) { return; } // Flag that helps this command fire at the proper time which is set to true initially and set to false as needed View.Model.MainWindow.TotalsTabDataStatus.IsShowingDataGridTotals = true; string _parameter = ((string)parameter).ToLower(); switch (_parameter) { // Passing one of the following strings causes appropriate data to be displayed in the Totals tab case "daily": View.Model.MainWindow.TotalsTabDescription = "Totals for the 'Daily' meal plan"; UpdateTotals("Daily"); break; case "mondays": View.Model.MainWindow.TotalsTabDescription = "Totals for the 'Mondays' meal plan"; UpdateTotals("Mondays"); break; case "tuesdays": View.Model.MainWindow.TotalsTabDescription = "Totals for the 'Tuesdays' meal plan"; UpdateTotals("Tuesdays"); break; case "wednesdays": View.Model.MainWindow.TotalsTabDescription = "Totals for the 'Wednesdays' meal plan"; UpdateTotals("Wednesdays"); break; case "thursdays": View.Model.MainWindow.TotalsTabDescription = "Totals for the 'Thursdays' meal plan"; UpdateTotals("Thursdays"); break; case "fridays": View.Model.MainWindow.TotalsTabDescription = "Totals for the 'Fridays' meal plan"; UpdateTotals("Fridays"); break; case "saturdays": View.Model.MainWindow.TotalsTabDescription = "Totals for the 'Saturdays' meal plan"; UpdateTotals("Saturdays"); break; case "sundays": View.Model.MainWindow.TotalsTabDescription = "Totals for the 'Sundays' meal plan"; UpdateTotals("Sundays"); break; case "weekends": View.Model.MainWindow.TotalsTabDescription = "Totals for the 'Weekends' meal plan"; UpdateTotals("Weekends"); break; case "weekdays": View.Model.MainWindow.TotalsTabDescription = "Totals for the 'Weekdays' meal plan"; UpdateTotals("Weekdays"); break; default: // Display details for an individual food item (the case when one of the above keywords is not passed in _parameter // Update the Totals tab description text View.Model.MainWindow.TotalsTabDescription = "Totals for: '" + _parameter + "' (100 gram portion)"; // Apply rounding to the data if the option is set and update the data FoodData d = USDA.GetFoodData(_parameter); if (Properties.Settings.Default.Rounding) { d = FoodData.Round(d, Settings.Default.RoundingNumberOfFractionalDigits); } View.Model.MainWindow.FoodData = d; View.Model.MainWindow.TotalsTabDataStatus.IsShowingDataGridTotals = false; break; } if (View.Model.MainWindow.TotalsTabDataStatus.DataChanged) { View.Model.MainWindow.UserData.Save(); } View.Model.MainWindow.TotalsTabDataStatus.DataChanged = false; View.Model.MainWindow.TotalsTabDataStatus.UpdateNeeded = false; }