Esempio n. 1
0
        //When saved, data needs to be send to the database.
        public override void saveButtonClicked(object sender, EventArgs args)
        {
            if (nutrFacts != null)
            {
                var nutrQuantifier = nutrFacts.getQuantifier();
                var nutrQuantity   = nutrFacts.Quantity;
                //save info to database here
                if (selectedResult != null && nutrQuantity != null && !nutrQuantity.Equals("0") && nutrQuantifier != null && date != null)
                {
                    var db = DataAccessor.getDataAccessor();

                    //Increment the times this item has been selected so it will get priority in the future
                    db.incrementTimesSearched(selectedResult.food_no);

                    FoodHistoryItem item = new FoodHistoryItem();
                    //need to add date, quantity, quantifiers, and food_no to this item
                    item.food_no    = selectedResult.food_no;
                    item.Date       = date.ToString();
                    item.Quantity   = Convert.ToDouble(nutrQuantity);
                    item.Quantifier = nutrQuantifier;


                    //Add to our database
                    db.addFoodHistory(item);
                }
            }
        }
Esempio n. 2
0
        //pull up the saved customized values, or auto-populate recommended values
        public void setValues()
        {
            var db = DataAccessor.getDataAccessor();

            //if it is custom
            if (db.getSettingsItem("custom_dri").Equals("true"))
            {
                //macronutrients
                foreach (var macronutrient in this.macronutrients)
                {
                    this.FindByName <Entry>(macronutrient).Text = db.getDRIValue(macronutrient);
                }

                //vitamins
                foreach (var vitamin in this.vitamins)
                {
                    this.FindByName <Entry>(vitamin).Text = db.getDRIValue(vitamin);
                }

                //minerals
                foreach (var mineral in this.minerals)
                {
                    this.FindByName <Entry>(mineral).Text = db.getDRIValue(mineral);
                }
            }
            //recommended values, customized is false
            else
            {
                setValuesHelper();
            }
        }
Esempio n. 3
0
        private string calculateCalories()
        {
            var db = DataAccessor.getDataAccessor();

            //Calculating Calories using Mifflin-St. Jeor equation
            String ageString    = db.getSettingsItem("age");
            var    age          = int.Parse(ageString);
            String genderString = db.getSettingsItem("gender");

            gender = int.Parse(genderString); //male == 1, female == 0
            String weightString        = db.getSettingsItem("weight");
            var    weight_kg           = double.Parse(weightString) * 0.453592;
            String feet                = db.getSettingsItem("feet");
            String inches              = db.getSettingsItem("inches");
            var    height_cm           = (double.Parse(feet) * 12 + double.Parse(inches)) * 2.54;
            String activityLevelString = db.getSettingsItem("activity_level");
            var    activityLevel       = double.Parse(activityLevelString);
            var    calories            = 0;

            if (gender == 1)
            {
                calories = (int)((10 * weight_kg + 6.25 * height_cm - 5 * age + 5) * activityLevel);
            }
            else
            {
                calories = (int)((10 * weight_kg + 6.25 * height_cm - 5 * age - 161) * activityLevel);
            }
            return(calories.ToString());
        }
Esempio n. 4
0
        //gets the multiplier to convert to grams
        public static double getMultiplier(string quantifier, int food_no)
        {
            var    quantityIndex = -1;
            double multiplier    = 1.0;

            for (int i = 0; i < standardUnits.Length; i++)
            {
                if (quantifier.Equals(standardUnits[i]))
                {
                    quantityIndex = i;
                    break;
                }
            }
            if (quantityIndex >= 0)
            {
                multiplier = standardWeights[quantityIndex];
            }
            else
            {
                //custom units code here
                var db           = DataAccessor.getDataAccessor();
                var convertItems = db.getCustomQuantifiers(food_no);
                foreach (var item in convertItems)
                {
                    if (item.name.Equals(quantifier))
                    {
                        multiplier = item.gramsMultiplier;
                        break;
                    }
                }
            }
            return(multiplier);
        }
Esempio n. 5
0
        //update search results.
        public void searchForMatches(object sender, TextChangedEventArgs e)
        {
            var searchItem    = e.NewTextValue;
            var db            = DataAccessor.getDataAccessor();
            var searchResults = db.searchName(searchItem);

            searchList.ItemsSource = searchResults;
        }
Esempio n. 6
0
        /// <summary>
        /// Where you can add nutrients to the list of progress bars shown
        /// </summary>
        private void initializeItems()
        {
            var db = DataAccessor.getDataAccessor();
            //DRI not currently being used in Visualizing

            //retreiving the thresholds from the database
            var sugarThresh    = db.getDRIThresholds("dri_sugar");
            var omega63Thresh  = db.getDRIThresholds("dri_omega6/3 ratio");
            var caloriesThresh = db.getDRIThresholds("dri_calories");
            var netCarbsThresh = db.getDRIThresholds("dri_netCarbs");
            var fiberThresh    = db.getDRIThresholds("dri_dietaryFiber");
            var zincThresh     = db.getDRIThresholds("dri_zinc");
            var totCarbsThresh = db.getDRIThresholds("dri_totalCarbs");

            //quantity = 0, dri value = 1, low threshold = 2, high threshold = 3

            double[] QDRI12 = { 0, Convert.ToDouble(db.getDRIValue("dri_sugar")), Convert.ToDouble(sugarThresh[0].lowThresh), Convert.ToDouble(sugarThresh[0].highThresh) };
            double[] QDRI15 = { 0, Convert.ToDouble(db.getDRIValue("dri_omega6/3 ratio")), Convert.ToDouble(omega63Thresh[0].lowThresh), Convert.ToDouble(omega63Thresh[0].highThresh) };
            double[] QDRI14 = { 0, Convert.ToDouble(db.getDRIValue("dri_calories")), Convert.ToDouble(caloriesThresh[0].lowThresh), Convert.ToDouble(caloriesThresh[0].highThresh) };
            double[] QDRI2  = { 0, Convert.ToDouble(db.getDRIValue("dri_netCarbs")), Convert.ToDouble(netCarbsThresh[0].lowThresh), Convert.ToDouble(netCarbsThresh[0].highThresh) };
            double[] QDRI13 = { 0, Convert.ToDouble(db.getDRIValue("dri_dietaryFiber")), Convert.ToDouble(fiberThresh[0].lowThresh), Convert.ToDouble(fiberThresh[0].highThresh) };
            double[] QDRI9  = { 0, Convert.ToDouble(db.getDRIValue("dri_zinc")), Convert.ToDouble(zincThresh[0].lowThresh), Convert.ToDouble(zincThresh[0].highThresh) };
            double[] QDRI16 = { 0, Convert.ToDouble(db.getDRIValue("dri_totalCarbs")), Convert.ToDouble(totCarbsThresh[0].lowThresh), Convert.ToDouble(totCarbsThresh[0].highThresh) };

            //double[] QDRI1 = { 0, Convert.ToDouble(db.getDRIValue("dri_protein"))};
            //double[] QDRI3 = { 0, Convert.ToDouble(db.getDRIValue("dri_calcium")) };
            //double[] QDRI4 = { 0, Convert.ToDouble(db.getDRIValue("dri_iron")) };
            //double[] QDRI5 = { 0, Convert.ToDouble(db.getDRIValue("dri_magnesium")) };
            //double[] QDRI6 = { 0, Convert.ToDouble(db.getDRIValue("dri_phosphorus")) };
            //double[] QDRI7 = { 0, Convert.ToDouble(db.getDRIValue("dri_potassium")) };
            //double[] QDRI8 = { 0, Convert.ToDouble(db.getDRIValue("dri_sodium")) };
            //double[] QDRI10 = { 0, Convert.ToDouble(db.getDRIValue("dri_copper")) };
            //double[] QDRI11 = { 0, Convert.ToDouble(db.getDRIValue("dri_manganese")) };

            /////////////////////////////////////////////////////////////////////
            //creating the items to be displayed in the progress bars
            items.Add("Total Sugars(g)", QDRI12);
            items.Add("Omega6/3 Ratio", QDRI15);
            items.Add("Calories", QDRI14);
            items.Add("Carbohydrates(g)", QDRI16);
            //items.Add("Net Carbohydrates(g)",QDRI2);
            items.Add("Total Dietary Fiber(g)", QDRI13);
            items.Add("Zinc(mg)", QDRI9);


            //items.Add("Protein(g)", QDRI1);
            //items.Add("Iron(mg)", QDRI4);
            //items.Add("Calcium(mg)", QDRI3);
            //items.Add("Magnesium(mg)", QDRI5);
            //items.Add("Phosphorus(mg)", QDRI6);
            //items.Add("Potassium(mg)", QDRI7);
            //items.Add("Sodium(mg)", QDRI8);
            //items.Add("Copper(mg)", QDRI10);
            //items.Add("Magnanese(mg)", QDRI11);
        }
Esempio n. 7
0
        //reset values to the recommended DRI values pre-populated by the page
        public async void reset(object sender, EventArgs e)
        {
            var selection = await DisplayAlert("Reset?", "Are you sure you want to reset your dietary intake to the recommended values?", "Yes", "No");

            if (selection == true)
            {
                //set as not customized
                var db = DataAccessor.getDataAccessor();
                db.saveSettingsItem("custom_dri", "false");
                //populate fields
                setValues();
            }
        }
Esempio n. 8
0
        //allow the user to change the recommended DRI values
        public async void customize(object sender, EventArgs e)
        {
            var selection = await DisplayAlert("Customize?", "Are you sure you want to customize your recommended dietary intake?", "Yes", "No");

            if (selection == true)
            {
                var db = DataAccessor.getDataAccessor();
                //set as customized
                db.saveSettingsItem("custom_dri", "true");
                //save all of the custom values
                saveInfo();
            }
        }
Esempio n. 9
0
        //Save the user input data into the database
        private async void onSaveClicked(object sender, EventArgs e)
        {
            //check if inputs are valid
            if (recipeName.Text == null || recipeName.Text == "")
            {
                await DisplayAlert("Please input RECIPE NAME", "", "OK");
            }
            else if (quantity.Text == null || quantity.Text == "" || quantity.Text == "0")
            {
                await DisplayAlert("Please input QUANTITY", "example: 1.5 or 3", "OK");
            }
            else if (quantifier.Text == null || quantifier.Text == "")
            {
                await DisplayAlert("Please input QUANTIFIER NAME", "", "OK");
            }
            else if (recipeList.Count == 0)
            {
                await DisplayAlert("Please add an INGREDIENT", "", "OK");
            }
            else //perform save
            {
                //access database
                var    db            = DataAccessor.getDataAccessor();
                var    nutrientList  = db.getNutrientsFromHistoryList(recipeList);
                double totalQuantity = 0;

                double servingQuantity = Convert.ToDouble(quantity.Text);

                foreach (var item in recipeList)
                {
                    totalQuantity += UnitConverter.getMultiplier(item.Quantifier, item.food_no) * item.Quantity;
                }
                foreach (var item in nutrientList)
                {
                    item.quantity /= (totalQuantity);
                    item.quantity *= 100;//database is in 100g standard.
                }
                var servingMultiplier = (totalQuantity / servingQuantity) / 100;
                db.createFoodItem(nutrientList, recipeName.Text, servingMultiplier, quantifier.Text.ToString());

                //clear variables
                recipeList.Clear();
                recipeName.Text            = "";
                ingredientList.ItemsSource = "";
                quantity.Text   = "";
                quantifier.Text = "";

                await DisplayAlert("Recipe Saved", "", "OK");
            }
        }
Esempio n. 10
0
 private async void saveButtonClicked(object sender, EventArgs args)
 {
     // Upon clicking save button, add photo to the data base as a reminder and add it as a display item on mydaypage
     if (saveImage != null)
     {
         var db        = DataAccessor.getDataAccessor();
         var remainder = new MyDayRemainderItem();
         remainder.Date           = this.date;
         remainder.RemainderImage = saveImage;
         db.insertRemainder(remainder);
     }
     // Refresh the page
     MessagingCenter.Send(new MyDayFoodItem(), "RefreshMyDay");
     await Navigation.PopAsync();
 }
Esempio n. 11
0
        //for code reuse
        public void setValuesHelper()
        {
            var db = DataAccessor.getDataAccessor();

            calculateSaveNum();

            var calories = calculateCalories();
            var sugar    = calculateSugar(calories);

            //macronutrients
            this.FindByName <Entry>("dri_calories").Text     = calories;
            this.FindByName <Entry>("dri_totalCarbs").Text   = totalCarbs[saveNum];
            this.FindByName <Entry>("dri_sugar").Text        = sugar;
            this.FindByName <Entry>("dri_dietaryFiber").Text = dietaryFiber[saveNum];
            this.FindByName <Entry>("dri_netCarbs").Text     = netCarbs[saveNum];
            this.FindByName <Entry>("dri_protein").Text      = protein[saveNum];

            //vitamins
            this.FindByName <Entry>("dri_vitaminA").Text        = vitaminA[saveNum];
            this.FindByName <Entry>("dri_vitaminC").Text        = vitaminC[saveNum];
            this.FindByName <Entry>("dri_vitaminD").Text        = vitaminD[saveNum];
            this.FindByName <Entry>("dri_vitaminE").Text        = vitaminE[saveNum];
            this.FindByName <Entry>("dri_vitaminK").Text        = vitaminK[saveNum];
            this.FindByName <Entry>("dri_thiamin").Text         = thiamin[saveNum];
            this.FindByName <Entry>("dri_riboflavin").Text      = riboflavin[saveNum];
            this.FindByName <Entry>("dri_niacin").Text          = niacin[saveNum];
            this.FindByName <Entry>("dri_vitaminB6").Text       = vitaminB6[saveNum];
            this.FindByName <Entry>("dri_folate").Text          = folate[saveNum];
            this.FindByName <Entry>("dri_vitaminB12").Text      = vitaminB12[saveNum];
            this.FindByName <Entry>("dri_pantothenicAcid").Text = pantothenicAcid[saveNum];

            //minerals
            this.FindByName <Entry>("dri_calcium").Text    = calcium[saveNum];
            this.FindByName <Entry>("dri_iron").Text       = iron[saveNum];
            this.FindByName <Entry>("dri_magnesium").Text  = magnesium[saveNum];
            this.FindByName <Entry>("dri_phosphorus").Text = phosphorus[saveNum];
            this.FindByName <Entry>("dri_potassium").Text  = potassium[saveNum];
            this.FindByName <Entry>("dri_sodium").Text     = sodium[saveNum];
            this.FindByName <Entry>("dri_zinc").Text       = zinc[saveNum];
            this.FindByName <Entry>("dri_copper").Text     = copper[saveNum];
            this.FindByName <Entry>("dri_manganese").Text  = manganese[saveNum];
            this.FindByName <Entry>("dri_selenium").Text   = selenium[saveNum];

            //save for the nutrient graphs
            saveInfo();
        }
Esempio n. 12
0
        //Set the profile picture, default to logo if one does not exist.
        void UpdateMyDayPicture()
        {
            var db       = DataAccessor.getDataAccessor();
            var oldItems = db.getRemainders("ProfileImage");
            MyDayRemainderItem myDayRemainderItem = null;

            if (oldItems.Count > 0)
            {
                myDayRemainderItem = oldItems.First <MyDayRemainderItem>();
            }
            if (myDayRemainderItem != null)
            {
                pic.Source = myDayRemainderItem.RemainderImage.Source;
            }
            else
            {
                pic.Source = "ic_logo_24dp.png";
            }
        }
Esempio n. 13
0
        //Get all the nutrients associated with the current selection of days.
        private List <Nutrient> getNutrients()
        {
            var db       = DataAccessor.getDataAccessor();
            var baseList = new List <FoodHistoryItem>();

            for (int i = 0; i < daysToLoad; i++)
            {
                baseList.AddRange(db.getFoodHistoryList(date.AddDays(-i).ToString()));
            }
            var nutrientList = db.getNutrientsFromHistoryList(baseList);

            foreach (var item in nutrientList)
            {
                if (item.name != "Omega6/3 Ratio")
                {
                    item.quantity /= daysToLoad;
                }
            }
            return(nutrientList);
        }
Esempio n. 14
0
        public void updateUnitPickerWithCustomOptions()
        {
            //reset entire picker
            UnitsPicker.Items.Clear();

            //to reset duplicate units appearing
            setBaseUnitPickerChoices();

            if (selectedResult != null)
            {
                var db = DataAccessor.getDataAccessor();
                db.addCustomQuantifiers(selectedResult);
                foreach (var converter in selectedResult.convertions)
                {
                    if (converter.name != null && !UnitsPicker.Items.Contains(converter.name) && converter.name != "")
                    {
                        UnitsPicker.Items.Insert(0, converter.name);
                    }
                }
            }
        }
Esempio n. 15
0
        public AddItemPage()
        {
            InitializeComponent();


            searchbar = new Entry
            {
                Placeholder = "Search item",
            };

            //Get search results for every key entry into the search bar and display them
            searchbar.TextChanged += (sender, e) =>
            {
                String searchItem    = e.NewTextValue;;
                var    db            = DataAccessor.getDataAccessor();
                var    searchResults = db.searchName(searchItem);
                searchList.ItemsSource = searchResults;
            };


            mainStack.Children.Insert(0, searchbar);
        }
Esempio n. 16
0
        public void saveInfo()
        {
            Debug.WriteLine("saved");
            var db = DataAccessor.getDataAccessor();

            //macronutrients
            foreach (var macroNutrient in this.macronutrients)
            {
                db.saveDRIValue(macroNutrient, this.FindByName <Entry>(macroNutrient).Text);
            }

            //vitamins
            foreach (var vitamin in this.vitamins)
            {
                db.saveDRIValue(vitamin, this.FindByName <Entry>(vitamin).Text);
            }

            //minerals
            foreach (var mineral in this.minerals)
            {
                db.saveDRIValue(mineral, this.FindByName <Entry>(mineral).Text);
            }
        }
Esempio n. 17
0
        //Display the food items associated with today, and back in time to the number of selected days.
        void OnItemsClicked()
        {
            Image pic2 = new Image();

            if (Application.Current.Properties.ContainsKey("Profile Pic"))
            {
                pic2       = Application.Current.Properties["Profile Pic"] as Image;
                pic.Source = pic2.Source;
            }

            listView.BeginRefresh();
            listView.ItemsSource = null;
            var db = DataAccessor.getDataAccessor();

            ViewItemList.Clear();
            var remainderList = new List <MyDayRemainderItem>();

            for (int i = 0; i < daysToLoad; i++)
            {
                remainderList = db.getRemainders(date.AddDays(-i).ToString());
                foreach (var item in remainderList)
                {
                    ViewItemList.Add(item);
                }
            }
            for (int i = 0; i < daysToLoad; i++)
            {
                var baseList = db.getFoodHistory(date.AddDays(-i).ToString());

                foreach (var item in baseList)
                {
                    ViewItemList.Add(item);
                }
            }
            listView.ItemsSource = ViewItemList;
            listView.EndRefresh();
        }
Esempio n. 18
0
        //get all of the DRI information, put it into List to be passed
        public void getDRI()
        {
            var db = DataAccessor.getDataAccessor();

            dris.Add(Convert.ToDouble(db.getDRIValue("dri_protein")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_totalCarbs")));
            //dris.Add(0); // sugar

            dris.Add(Convert.ToDouble(db.getDRIValue("dri_dietaryFiber")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_calcium")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_iron")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_magnesium")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_phosphorus")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_potassium")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_sodium")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_zinc")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_copper")));

            dris.Add(Convert.ToDouble(db.getDRIValue("dri_manganese")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_selenium")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_vitaminA")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_vitaminC")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_thiamin")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_riboflavin")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_niacin")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_pantothenicAcid")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_vitaminB6")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_folate")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_vitaminB12")));
            dris.Add(0);     //omega 6 total
            dris.Add(0);     //omega 3 total
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_netCarbs")));
            dris.Add(0);     //total sugars
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_vitaminE")));
            dris.Add(Convert.ToDouble(db.getDRIValue("dri_vitaminK")));
            dris.Add(0);     //omega 3/6 ratio
        }
Esempio n. 19
0
        //save without loading the page, need for the visualizer
        /// <summary>
        /// Sugar and Calories Calculated
        /// dri values and threshold values saved here
        /// Can edit the threshold values per nutrient here.
        /// </summary>
        public void saveNoLoad()
        {
            var db = DataAccessor.getDataAccessor();

            calculateSaveNum();

            var calories = calculateCalories();
            var sugar    = calculateSugar(calories);

            //default threshold percentages of dri
            var lowDefault  = 0.25;
            var highDefault = 1.25;

            //macronutrients
            db.saveDRIValue("dri_omega6/3 ratio", "4"); 
 db.saveDRIThresholds("dri_omega6/3 ratio", "4", "10");

            db.saveDRIValue("dri_calories", calories.ToString());
            db.saveDRIThresholds("dri_calories",
                                 (Convert.ToDouble(calories) * lowDefault).ToString(),
                                 (Convert.ToDouble(calories) * highDefault).ToString());

            db.saveDRIValue("dri_totalCarbs", totalCarbs[saveNum]);
            db.saveDRIThresholds("dri_totalCarbs",
                                 (Convert.ToDouble(totalCarbs[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(totalCarbs[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_sugar", sugar.ToString());
            db.saveDRIThresholds("dri_sugar",
                                 (Convert.ToDouble(sugar) * lowDefault).ToString(),
                                 (Convert.ToDouble(sugar) * highDefault).ToString());

            db.saveDRIValue("dri_dietaryFiber", dietaryFiber[saveNum]);
            db.saveDRIThresholds("dri_dietaryFiber",
                                 (Convert.ToDouble(dietaryFiber[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(dietaryFiber[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_netCarbs", netCarbs[saveNum]);
            db.saveDRIThresholds("dri_netCarbs",
                                 (Convert.ToDouble(netCarbs[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(netCarbs[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_protein", protein[saveNum]);
            db.saveDRIThresholds("dri_protein",
                                 (Convert.ToDouble(protein[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(protein[saveNum]) * highDefault).ToString());
            //vitamins
            db.saveDRIValue("dri_vitaminA", vitaminA[saveNum]);
            db.saveDRIThresholds("dri_vitaminA",
                                 (Convert.ToDouble(vitaminA[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(vitaminA[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_vitaminC", vitaminC[saveNum]);
            db.saveDRIThresholds("dri_vitaminC",
                                 (Convert.ToDouble(vitaminC[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(vitaminC[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_vitaminD", vitaminD[saveNum]);
            db.saveDRIThresholds("dri_vitaminD",
                                 (Convert.ToDouble(vitaminD[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(vitaminD[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_vitaminE", vitaminE[saveNum]);
            db.saveDRIThresholds("dri_vitaminE",
                                 (Convert.ToDouble(vitaminE[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(vitaminE[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_vitaminK", vitaminK[saveNum]);
            db.saveDRIThresholds("dri_vitaminK",
                                 (Convert.ToDouble(vitaminK[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(vitaminK[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_thiamin", thiamin[saveNum]);
            db.saveDRIThresholds("dri_thiamin",
                                 (Convert.ToDouble(thiamin[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(thiamin[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_riboflavin", riboflavin[saveNum]);
            db.saveDRIThresholds("dri_riboflavin",
                                 (Convert.ToDouble(riboflavin[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(riboflavin[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_niacin", niacin[saveNum]);
            db.saveDRIThresholds("dri_niacin",
                                 (Convert.ToDouble(niacin[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(niacin[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_vitaminB6", vitaminB6[saveNum]);
            db.saveDRIThresholds("dri_vitaminB6",
                                 (Convert.ToDouble(vitaminB6[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(vitaminB6[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_folate", folate[saveNum]);
            db.saveDRIThresholds("dri_folate",
                                 (Convert.ToDouble(folate[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(folate[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_vitaminB12", vitaminB12[saveNum]);
            db.saveDRIThresholds("dri_vitaminB12",
                                 (Convert.ToDouble(vitaminB12[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(vitaminB12[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_pantothenicAcid", pantothenicAcid[saveNum]);
            db.saveDRIThresholds("dri_pantothenicAcid",
                                 (Convert.ToDouble(pantothenicAcid[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(pantothenicAcid[saveNum]) * highDefault).ToString());

            //minerals
            db.saveDRIValue("dri_calcium", calcium[saveNum]);
            db.saveDRIThresholds("dri_calcium",
                                 (Convert.ToDouble(calcium[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(calcium[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_iron", iron[saveNum]);
            db.saveDRIThresholds("dri_iron",
                                 (Convert.ToDouble(iron[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(iron[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_magnesium", magnesium[saveNum]);
            db.saveDRIThresholds("dri_magnesium",
                                 (Convert.ToDouble(magnesium[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(magnesium[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_phosphorus", phosphorus[saveNum]);
            db.saveDRIThresholds("dri_phosphorus",
                                 (Convert.ToDouble(phosphorus[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(phosphorus[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_potassium", potassium[saveNum]);
            db.saveDRIThresholds("dri_potassium",
                                 (Convert.ToDouble(potassium[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(potassium[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_sodium", sodium[saveNum]);
            db.saveDRIThresholds("dri_sodium",
                                 (Convert.ToDouble(sodium[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(sodium[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_zinc", zinc[saveNum]);
            db.saveDRIThresholds("dri_zinc",
                                 (Convert.ToDouble(zinc[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(zinc[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_copper", copper[saveNum]);
            db.saveDRIThresholds("dri_copper",
                                 (Convert.ToDouble(copper[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(copper[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_manganese", manganese[saveNum]);
            db.saveDRIThresholds("dri_manganese",
                                 (Convert.ToDouble(manganese[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(manganese[saveNum]) * highDefault).ToString());

            db.saveDRIValue("dri_selenium", selenium[saveNum]);
            db.saveDRIThresholds("dri_selenium",
                                 (Convert.ToDouble(selenium[saveNum]) * lowDefault).ToString(),
                                 (Convert.ToDouble(selenium[saveNum]) * highDefault).ToString());
        }
Esempio n. 20
0
        //calculate the index
        public void calculateSaveNum()
        {
            var db = DataAccessor.getDataAccessor();
            //4 values needed to calculate DRI
            String age = db.getSettingsItem("age");

            if (age != null && age != "")
            {
                ageNum = int.Parse(age);
            }

            String genderString = db.getSettingsItem("gender");

            gender = int.Parse(genderString);

            String pregnantString = db.getSettingsItem("pregnant");

            pregnant = int.Parse(pregnantString);

            String lactatingString = db.getSettingsItem("lactating");

            lactating = int.Parse(lactatingString);


            //calculations for infants
            if (ageNum < 1)
            {
                saveNum = 0;
            }

            //Calculations for Children
            else if (ageNum >= 1 && ageNum <= 3)
            {
                saveNum = 1;
            }
            //calculations for older children
            else if (ageNum >= 4 && ageNum <= 8)
            {
                saveNum = 2;
            }
            //calculations for adults
            else
            {
                //Males
                if (gender == 1)
                {
                    //9-13
                    if (ageNum >= 9 && ageNum <= 13)
                    {
                        saveNum = 3;
                    }
                    //14-18
                    else if (ageNum >= 14 && ageNum <= 18)
                    {
                        saveNum = 4;
                    }
                    //19-30
                    else if (ageNum >= 19 && ageNum <= 30)
                    {
                        saveNum = 5;
                    }
                    //31-50
                    else if (ageNum >= 31 && ageNum <= 50)
                    {
                        saveNum = 6;
                    }
                    //51-70
                    else if (ageNum >= 51 && ageNum <= 70)
                    {
                        saveNum = 7;
                    }
                    //70+
                    else if (ageNum > 70)
                    {
                        saveNum = 8;
                    }
                }
                //female
                else if (gender == 0)
                {
                    //not pregnant or lactating
                    if (pregnant == 0 && lactating == 0)
                    {
                        //9-13
                        if (ageNum >= 9 && ageNum <= 13)
                        {
                            saveNum = 9;
                        }
                        //14-18
                        else if (ageNum >= 14 && ageNum <= 18)
                        {
                            saveNum = 10;
                        }
                        //19-30
                        else if (ageNum >= 19 && ageNum <= 30)
                        {
                            saveNum = 11;
                        }

                        //31-50
                        else if (ageNum >= 31 && ageNum <= 50)
                        {
                            saveNum = 12;
                        }
                        //51-70
                        else if (ageNum >= 51 && ageNum <= 70)
                        {
                            saveNum = 13;
                        }
                        //70+
                        else if (ageNum > 70)
                        {
                            saveNum = 14;
                        }
                    }
                    //pregnant women
                    else if (pregnant == 1 && lactating == 0)
                    {
                        //14-18
                        if (ageNum >= 14 && ageNum <= 18)
                        {
                            saveNum = 15;
                        }
                        //19-30
                        else if (ageNum >= 19 && ageNum <= 30)
                        {
                            saveNum = 16;
                        }
                        //31-50
                        else if (ageNum >= 31 && ageNum <= 50)
                        {
                            saveNum = 17;
                        }
                    }
                    //lactating women
                    else if (pregnant == 0 && lactating == 1)
                    {
                        //14-18
                        if (ageNum >= 14 && ageNum <= 18)
                        {
                            saveNum = 18;
                        }
                        //19-30
                        else if (ageNum >= 19 && ageNum <= 30)
                        {
                            saveNum = 19;
                        }
                        //31-50
                        else if (ageNum >= 31 && ageNum <= 50)
                        {
                            saveNum = 20;
                        }
                    }
                }
            }
        }
Esempio n. 21
0
        public SettingsPage()
        {
            InitializeComponent();
            //not all of the settings are currently being used for calculations

            //load the saved settings
            var db = DataAccessor.getDataAccessor();

            //name
            this.FindByName <EntryCell>("settings_name").Text = db.getSettingsItem("name");

            //gender
            String gender = db.getSettingsItem("gender");

            //male
            if (gender.Equals("1"))
            {
                this.FindByName <Picker>("settings_gender").SelectedIndex = 1;
            }
            //female 0
            else
            {
                this.FindByName <Picker>("settings_gender").SelectedIndex = 0;
            }

            //activity level
            String activity_level = db.getSettingsItem("activity_level");

            //inactive = 0
            if (activity_level.Equals("1.2"))
            {
                this.FindByName <Picker>("settings_activity_level").SelectedIndex = 2;
            }
            //moderately active = 1
            else if (activity_level.Equals("1.3"))
            {
                this.FindByName <Picker>("settings_activity_level").SelectedIndex = 1;
            }
            //highly active = 2
            else
            {
                this.FindByName <Picker>("settings_activity_level").SelectedIndex = 0;
            }

            //age
            this.FindByName <EntryCell>("settings_age").Text = db.getSettingsItem("age");

            //weight
            this.FindByName <EntryCell>("settings_weight").Text = db.getSettingsItem("weight");

            //height
            this.FindByName <EntryCell>("settings_feet").Text   = db.getSettingsItem("feet");
            this.FindByName <EntryCell>("settings_inches").Text = db.getSettingsItem("inches");

            //Health Concerns
            //pregnant? 1 true 0 false
            String pregnant = db.getSettingsItem("pregnant");

            if (pregnant == "1")
            {
                this.FindByName <SwitchCell>("settings_pregnant").On = true;
            }
            else
            {
                this.FindByName <SwitchCell>("settings_pregnant").On = false;
            }

            //lactating? 1 true 0 false
            String lactating = db.getSettingsItem("lactating");

            if (lactating == "1")
            {
                this.FindByName <SwitchCell>("settings_lactating").On = true;
            }
            else
            {
                this.FindByName <SwitchCell>("settings_lactating").On = false;
            }

            //high blood pressure
            String blood_pressure = db.getSettingsItem("blood_pressure");

            if (blood_pressure == "1")
            {
                this.FindByName <SwitchCell>("settings_blood_pressure").On = true;
            }
            else
            {
                this.FindByName <SwitchCell>("settings_blood_pressure").On = false;
            }

            //type 2 diabetes
            String t2d = db.getSettingsItem("t2d");

            if (t2d == "1")
            {
                this.FindByName <SwitchCell>("settings_t2d").On = true;
            }
            else
            {
                this.FindByName <SwitchCell>("settings_t2d").On = false;
            }

            //gluten sensitvity
            String gluten_sensitivity = db.getSettingsItem("gluten_sensitivity");

            if (gluten_sensitivity == "1")
            {
                this.FindByName <SwitchCell>("settings_gluten_sensitivity").On = true;
            }
            else
            {
                this.FindByName <SwitchCell>("settings_gluten_sensitivity").On = false;
            }

            //cardiovascular disease
            String cvd = db.getSettingsItem("cvd");

            if (cvd == "1")
            {
                this.FindByName <SwitchCell>("settings_cvd").On = true;
            }
            else
            {
                this.FindByName <SwitchCell>("settings_cvd").On = false;
            }

            //liver disease
            String liver_disease = db.getSettingsItem("liver_disease");

            if (liver_disease == "1")
            {
                this.FindByName <SwitchCell>("settings_liver_disease").On = true;
            }
            else
            {
                this.FindByName <SwitchCell>("settings_liver_disease").On = false;
            }

            //liver disease
            String kidney_disease = db.getSettingsItem("kidney_disease");

            if (kidney_disease == "1")
            {
                this.FindByName <SwitchCell>("settings_kidney_disease").On = true;
            }
            else
            {
                this.FindByName <SwitchCell>("settings_kidney_disease").On = false;
            }

            //liver disease
            String sibo = db.getSettingsItem("sibo");

            if (sibo == "1")
            {
                this.FindByName <SwitchCell>("settings_sibo").On = true;
            }
            else
            {
                this.FindByName <SwitchCell>("settings_sibo").On = false;
            }

            //maximize macro balance
            String macro_balance = db.getSettingsItem("macro_balance");

            if (macro_balance == "1")
            {
                this.FindByName <SwitchCell>("settings_macro_balance").On = true;
            }
            else
            {
                this.FindByName <SwitchCell>("settings_macro_balance").On = false;
            }

            //maximize weight loss
            String weight_loss = db.getSettingsItem("weight_loss");

            if (weight_loss == "1")
            {
                this.FindByName <SwitchCell>("settings_weight_loss").On = true;
            }
            else
            {
                this.FindByName <SwitchCell>("settings_weight_loss").On = false;
            }

            //Reload photo here
            var oldItems = db.getRemainders("ProfileImage");
            MyDayRemainderItem myDayRemainderItem = null;

            if (oldItems.Count > 0)
            {
                myDayRemainderItem = oldItems.First <MyDayRemainderItem>();
            }
            if (myDayRemainderItem != null)
            {
                profilePic.Source = myDayRemainderItem.RemainderImage.Source;
            }
        }
Esempio n. 22
0
        //called when user clicks "save"
        public async void onSaveClicked(object sender, EventArgs e)
        {
            //error string
            String needed = "Please enter: ";

            //check to see if necessary fields have been input

            //didn't enter a name
            if (this.FindByName <EntryCell>("settings_name").Text == null)
            {
                needed += "\nName";
            }
            else
            {
                if (this.FindByName <EntryCell>("settings_name").Text.Equals(""))
                {
                    needed += "\nName";
                }
            }

            //didn't select a sex ;(
            if (this.FindByName <Picker>("settings_gender").SelectedIndex == -1)
            {
                needed += "\nSex";
            }

            //didn't select exercise level
            if (this.FindByName <Picker>("settings_activity_level").SelectedIndex == -1)
            {
                needed += "\nDaily Exercise Level";
            }

            //Error checking

            //0<age<100
            String age = this.FindByName <EntryCell>("settings_age").Text;

            //if they entered an age....
            if (age != "" && age != null)
            {
                int ageNum = int.Parse(age);
                //must be in a certain age range, else error
                if (ageNum < 0 || ageNum >= 100)
                {
                    needed += "\nAge >= 0 and <=99";
                }
            }
            //they didn't enter an age
            else
            {
                needed += "\nAge >= 0 and <=99";
            }

            //0<=feet<=10
            String feet = this.FindByName <EntryCell>("settings_feet").Text;

            //if they entered any feet
            if (feet != "" && feet != null)
            {
                int feetNum = int.Parse(feet);
                //must be in a certain range, else error
                if (feetNum < 0 || feetNum > 10)
                {
                    needed += "\nFeet >= 0 and <=10";
                }
            }
            //they didn't enter any feet
            else
            {
                needed += "\nFeet >= 0 and <=10";
            }

            //0<=inches<=11
            String inches = this.FindByName <EntryCell>("settings_inches").Text;

            //if they entered any inches
            if (inches != "" && inches != null)
            {
                int inchesNum = int.Parse(inches);
                //must be in a certain range, else error
                if (inchesNum < 0 || inchesNum > 11)
                {
                    needed += "\nInches >= 0 and <=11";
                }
            }
            //they didn't enter any inches
            else
            {
                needed += "\nInches >= 0 and <=11";
            }

            //non negative weight
            String weight = this.FindByName <EntryCell>("settings_weight").Text;

            //if they entered any inches
            if (weight != "" && weight != null)
            {
                int weightNum = int.Parse(weight);
                //must be in a certain range, else error
                if (weightNum < 0)
                {
                    needed += "\nWeight >= 0";
                }
            }
            //they didn't enter any weight
            else
            {
                needed += "\nWeight >= 0";
            }

            //using "Please enter: " string to check if there are no errors
            //if everything has been input, go back to the main page
            if (needed.Equals("Please enter: "))
            {
                var db = DataAccessor.getDataAccessor();

                //saving the user settings
                db.saveSettingsItem("name", this.FindByName <EntryCell>("settings_name").Text);
                db.saveSettingsItem("age", this.FindByName <EntryCell>("settings_age").Text);
                db.saveSettingsItem("weight", this.FindByName <EntryCell>("settings_weight").Text);
                db.saveSettingsItem("feet", this.FindByName <EntryCell>("settings_feet").Text);
                db.saveSettingsItem("inches", this.FindByName <EntryCell>("settings_inches").Text);

                //saving sex in the db by whichever value is selected
                if (this.FindByName <Picker>("settings_gender").SelectedIndex == 1)
                {
                    db.saveSettingsItem("gender", "1");
                }
                else
                {
                    db.saveSettingsItem("gender", "0");
                }

                //saving exercise level in the db by whichever value is selected
                if (this.FindByName <Picker>("settings_activity_level").SelectedIndex == 2)
                {
                    db.saveSettingsItem("activity_level", "1.2");
                }
                else if (this.FindByName <Picker>("settings_activity_level").SelectedIndex == 1)
                {
                    db.saveSettingsItem("activity_level", "1.3");
                }
                else
                {
                    db.saveSettingsItem("activity_level", "1.4");
                }

                //saving pregnant toggle in the db, by whichever pregnant value is selected
                if (this.FindByName <SwitchCell>("settings_pregnant").On == true)
                {
                    db.saveSettingsItem("pregnant", "1");
                }
                else
                {
                    db.saveSettingsItem("pregnant", "0");
                }

                if (this.FindByName <SwitchCell>("settings_lactating").On == true)
                {
                    db.saveSettingsItem("lactating", "1");
                }
                else
                {
                    db.saveSettingsItem("lactating", "0");
                }

                if (this.FindByName <SwitchCell>("settings_blood_pressure").On == true)
                {
                    db.saveSettingsItem("blood_pressure", "1");
                }
                else
                {
                    db.saveSettingsItem("blood_pressure", "0");
                }

                if (this.FindByName <SwitchCell>("settings_t2d").On == true)
                {
                    db.saveSettingsItem("t2d", "1");
                }
                else
                {
                    db.saveSettingsItem("t2d", "0");
                }

                if (this.FindByName <SwitchCell>("settings_gluten_sensitivity").On == true)
                {
                    db.saveSettingsItem("gluten_sensitivity", "1");
                }
                else
                {
                    db.saveSettingsItem("gluten_sensitivity", "0");
                }
                if (this.FindByName <SwitchCell>("settings_cvd").On == true)
                {
                    db.saveSettingsItem("cvd", "1");
                }
                else
                {
                    db.saveSettingsItem("cvd", "0");
                }
                if (this.FindByName <SwitchCell>("settings_liver_disease").On == true)
                {
                    db.saveSettingsItem("liver_disease", "1");
                }
                else
                {
                    db.saveSettingsItem("liver_disease", "0");
                }
                if (this.FindByName <SwitchCell>("settings_kidney_disease").On == true)
                {
                    db.saveSettingsItem("kidney_disease", "1");
                }
                else
                {
                    db.saveSettingsItem("kidney_disease", "0");
                }
                if (this.FindByName <SwitchCell>("settings_sibo").On == true)
                {
                    db.saveSettingsItem("sibo", "1");
                }
                else
                {
                    db.saveSettingsItem("sibo", "0");
                }
                if (this.FindByName <SwitchCell>("settings_macro_balance").On == true)
                {
                    db.saveSettingsItem("macro_balance", "1");
                }
                else
                {
                    db.saveSettingsItem("macro_balance", "0");
                }
                if (this.FindByName <SwitchCell>("settings_weight_loss").On == true)
                {
                    db.saveSettingsItem("weight_loss", "1");
                }
                else
                {
                    db.saveSettingsItem("weight_loss", "0");
                }


                //try and save profile photo
                if (MainImage.Source != null)
                {
                    var remainderItem = new MyDayRemainderItem();
                    remainderItem.Date                  = "ProfileImage";
                    remainderItem.RemainderImage        = new Image();
                    remainderItem.RemainderImage.Source = MainImage.Source;
                    var oldItems = db.getRemainders("ProfileImage");
                    MyDayRemainderItem oldItem = null;
                    if (oldItems.Count > 0)
                    {
                        oldItem = oldItems.First <MyDayRemainderItem>(i => i.Date == "ProfileImage");
                    }
                    if (oldItem != null)
                    {
                        db.deleteFoodHistoryItem(oldItem.id);
                    }
                    db.insertRemainder(remainderItem);
                }

                MessagingCenter.Send(new MyDayFoodItem(), "RefreshMyDay");
                try
                {
                    await Navigation.PopModalAsync();//only used the first run, will error every other time.

                    DRIPage driP = new DRIPage();
                    driP.saveNoLoad();
                }
                catch (Exception)
                {
                }

                //display settings were saved
                await DisplayAlert("Settings Saved", "", "OK");
            }
            //display the error message
            else
            {
                await DisplayAlert("Error", needed, "OK");
            }
        }
Esempio n. 23
0
        //Create food item from user data and save to database
        async void saveButtonClicked(object sender, EventArgs args)
        {
            //check if inputs are valid
            if (CreateItemName.Text == null || CreateItemName.Text == "")
            {
                await DisplayAlert("Please input NAME", "", "OK");
            }
            else if (quantity.Text == null || quantity.Text == "" || quantity.Text == "0")
            {
                await DisplayAlert("Please input QUANTITY", "example: 1.5 or 3", "OK");
            }
            else if (quantifier.Text == null || quantifier.Text == "")
            {
                await DisplayAlert("Please input SERVING", "", "OK");
            }
            else if (gramsAmount.Text == null || gramsAmount.Text == "")
            {
                await DisplayAlert("Please input GRAMS", "", "OK");
            }
            else //perform save
            {
                var db = DataAccessor.getDataAccessor();

                var nutrientList = new List <Nutrient>();
                //multiplier deals with getting food to the 100g rate by the time it's in the db.
                var multiplier = 1 / Convert.ToDouble(gramsAmount.Text);

                foreach (var item in nutrientSection)
                {
                    var entryCellItem = (EntryCell)item;
                    if (Convert.ToDouble(entryCellItem.Text) > 0)
                    {
                        var oldNutrient = nutrientList.FindLast(i => i.dbNo == mappings[Array.IndexOf(inputValues, entryCellItem.Label)]);
                        if (oldNutrient == null)
                        {
                            var nutrient = new Nutrient();
                            nutrient.dbNo     = mappings[Array.IndexOf(inputValues, entryCellItem.Label)];
                            nutrient.quantity = Convert.ToDouble(entryCellItem.Text) * multiplier;
                            nutrientList.Add(nutrient);
                        }
                        else
                        {
                            oldNutrient.quantity += Convert.ToDouble(entryCellItem.Text) * multiplier;
                        }
                    }
                }
                //check if there were any nutrients input
                if (nutrientList.Count == 0)
                {
                    await DisplayAlert("Please input NUTRIENTS", "", "OK");
                }
                else
                {
                    //servingMultiplier for the custom unit
                    var servingMultiplier = Convert.ToDouble(quantity.Text) / (multiplier);

                    //put into database
                    db.createFoodItem(nutrientList, CreateItemName.Text, servingMultiplier, quantifier.Text.ToString());

                    //wipe inputs
                    foreach (var item in nutrientSection)
                    {
                        var entryCellItem = (EntryCell)item;
                        entryCellItem.Text = "0";
                    }
                    quantity.Text       = "";
                    quantifier.Text     = "";
                    gramsAmount.Text    = "";
                    CreateItemName.Text = "";

                    //alert user it was saved
                    await DisplayAlert("Item Saved", "", "OK");
                }
            }
        }
Esempio n. 24
0
        private void displayNutrInfo()
        {
            //check if there is a quantity
            if (Quantity != "")
            {
                //remove old info
                nutTable.Clear();

                var db = DataAccessor.getDataAccessor();
                //get selected food with nutrient info
                var foodItem = db.getFoodItem(selectedResult.food_no, UnitConverter.getMultiplier(getQuantifier(), selectedResult.food_no) * Convert.ToDouble(Quantity));

                //remove extra omega values, only want totals
                foodItem.stripExtraOmegs();

                //add preliminary table titles
                var colTitle = new StackLayout()
                {
                    Orientation = StackOrientation.Horizontal
                };
                colTitle.Children.Add(new Label() //nutrients
                {
                    Text              = "Nutrient",
                    WidthRequest      = 150,
                    HorizontalOptions = LayoutOptions.StartAndExpand,
                    TextColor         = (Color)App.Current.Resources["BtnBkgColor"],
                    FontAttributes    = FontAttributes.Bold
                });
                colTitle.Children.Add(new Label()
                {
                    Text = "Amount",
                    //HorizontalOptions = LayoutOptions.StartAndExpand,
                    HorizontalOptions = LayoutOptions.EndAndExpand,

                    TextColor      = (Color)App.Current.Resources["BtnBkgColor"],
                    FontAttributes = FontAttributes.Bold
                });
                //////TODO show what these nutrient values are as percentages of the DRI
                //colTitle.Children.Add(new Label()
                //{
                //    Text = "DRI %",
                //    HorizontalOptions = LayoutOptions.End,
                //    TextColor = (Color)App.Current.Resources["BtnBkgColor"],
                //    FontAttributes = FontAttributes.Bold
                //});
                //add to table


                nutTable.Add(new ViewCell()
                {
                    View = colTitle
                });
                //////////////////


                //add each nutrient into table
                foreach (var item in foodItem.nutrients)
                {
                    //create a new stack to put in table
                    var layout = new StackLayout()
                    {
                        Orientation = StackOrientation.Horizontal
                    };
                    //stack contains nutrient name
                    layout.Children.Add(new Label()
                    {
                        Text = item.name,
                        HorizontalOptions = LayoutOptions.StartAndExpand,
                        WidthRequest      = 150,
                        Style             = App.Current.Resources["LabelStyle"] as Style
                    });
                    //stack contains nutrient quantity
                    layout.Children.Add(new Label()
                    {
                        Text = Convert.ToString(Math.Round(item.quantity, 4)),
                        HorizontalOptions = LayoutOptions.EndAndExpand,
                        Style             = App.Current.Resources["LabelStyle"] as Style
                    });

                    ///////////TODO add DRI %'s
                    //layout.Children.Add(new Label()
                    //{
                    //    Text = Convert.ToString(Math.Round(item.quantity, 4)),
                    //    HorizontalOptions = LayoutOptions.End,
                    //    Style = App.Current.Resources["LabelStyle"] as Style
                    //});

                    //add nutrient to xaml table
                    nutTable.Add(new ViewCell()
                    {
                        View = layout
                    });
                }
            }
        }