示例#1
0
        public AddItemUpdate(MyDayFoodItem item)
        {
            myDayItem = item;

            //get food item from database
            var             db = DataAccessor.getDataAccessor();
            FoodHistoryItem foodHistoryItem = db.getFoodHistoryItem(item.id);

            //store food info in NumoNameSearch var
            var search = new NumoNameSearch();

            this.search    = search;
            search.food_no = foodHistoryItem.food_no;
            search.name    = foodHistoryItem.DisplayName;

            //create new instance to display food info
            nutrFacts = new NutrFacts(this, search);

            //update the values being displayed
            nutrFacts.DescriptView   = foodHistoryItem.DisplayName;
            nutrFacts.Quantity       = foodHistoryItem.Quantity.ToString();
            nutrFacts.UnitPickerText = foodHistoryItem.Quantifier;
            nutrFacts.selectedResult = search;
            nutrFacts.updateUnitPickerWithCustomOptions();
        }
示例#2
0
        public async void ItemTapped(object sender, ItemTappedEventArgs e)
        {
            if (e.Item == null)
            {
                return; //ItemSelected is called on deselection, which results in SelectedItem being set to null
            }
            else if (e.Item.GetType() == typeof(MyDayFoodItem))
            {
                MyDayFoodItem foodItem = (MyDayFoodItem)e.Item;
                String        action   = await DisplayActionSheet("Do you want to modify " + foodItem.DisplayName + "?",
                                                                  "Cancel", "", "Edit", "Delete");

                if (action.Equals("Edit"))
                {
                    foodItem.OnEditEvent.Execute(null);
                }
                else if (action.Equals("Delete"))
                {
                    foodItem.OnDeleteEvent.Execute(null);

                    // Since the db is committing to fast, the undo button isn't working, so no need to update it's text
                    // undoButton.Text = "Undo";
                }
            }
        }
示例#3
0
        async public override void saveButtonClicked(object sender, EventArgs e)
        {
            var nutrQuantifier = nutrFacts.getQuantifier();
            var nutrQuantity   = nutrFacts.Quantity;

            if (search != null && nutrQuantity != null && !nutrQuantity.Equals("0") && nutrQuantifier != null)
            {
                var db = DataAccessor.getDataAccessor();

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

                item.History_Id = myDayItem.id;

                //Add to our database
                bool success = db.updateFoodHistory(item, saveMemento: false);
                if (success)
                {
                    await DisplayAlert("Update successful", "", "OK");
                }
                else
                {
                    await DisplayAlert("Update unsuccessful", "", "OK");
                }
            }
            MyDayFoodItem.sendRefresh();
        }
        //refresh everytime we return from the addItemPage
        protected override void OnAppearing()
        {
            base.OnAppearing();
            ingredientList.BeginRefresh();
            ingredientList.ItemsSource = null;

            List <MyDayFoodItem> foodItems = new List <MyDayFoodItem>();

            foreach (var item in recipeList)
            {
                var foodItem = new MyDayFoodItem();
                foodItem.DisplayName = item.DisplayName;
                foodItem.quantity    = "(" + item.Quantity + ")" + " " + item.Quantifier;
                foodItems.Add(foodItem);
            }
            ingredientList.ItemsSource = foodItems;
            ingredientList.EndRefresh();
        }
示例#5
0
        //retrieves the foodhistory associated to a certain date and prepares it for display as a MyDayFoodItem
        public List <MyDayFoodItem> getFoodHistory(String date)
        {
            var historyList = dbConn.Query <FoodHistoryItem>(String.Format("SELECT History_Id, Date as Date, Food_Id as food_no, Quantity as Quantity, Quantifier as Quantifier FROM FoodHistory WHERE Date LIKE '%{0}%'", date));
            var resultList  = new List <MyDayFoodItem>();

            foreach (var result in historyList)
            {
                if (result.food_no > 0)
                {
                    var newItem = new MyDayFoodItem();
                    newItem.id          = result.History_Id;
                    newItem.DisplayName = getNameFromID(result.food_no);
                    newItem.Quantity    = "(" + result.Quantity.ToString() + ") " + result.Quantifier;
                    resultList.Add(newItem);
                }
            }
            return(resultList);
        }
示例#6
0
        public void SaveButtonClicked(object sender, EventArgs e)
        {
            var nutrQuantifier = nutrFacts.getQuantifier();
            var nutrQuantity   = nutrFacts.Quantity;

            if (search != null && nutrQuantity != null && !nutrQuantity.Equals("0") && nutrQuantifier != null)
            {
                var db = DataAccessor.getDataAccessor();

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


                //Add to our database
                db.updateFoodHistory(item, myDayItem.id);
            }
            MyDayFoodItem.sendRefresh();
        }
示例#7
0
 //Update a food item's information
 async void UpdateMyDayFoodItem(MyDayFoodItem item)
 {
     AddItemUpdate update = new AddItemUpdate(item);
     await Navigation.PushAsync(update.nutrFacts);
 }