Ejemplo n.º 1
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";
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
                    }
                }
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
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());
        }
Ejemplo n.º 9
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;
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
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
                    });
                }
            }
        }
Ejemplo n.º 11
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");
                }
            }
        }
Ejemplo n.º 12
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");
            }
        }
Ejemplo n.º 13
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;
            }
        }