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(); }
//Clear all fields to make it obvious the button press had an impact. public virtual 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); updateUndoButton(); } } }
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(); }
//Adds the foodHistory entry to the database public void addFoodHistory(FoodHistoryItem item, bool saveMemento = true) { if (saveMemento) { createMemento(); } dbConn.Execute(String.Format("INSERT INTO FoodHistory (Date, Food_Id, Quantity, Quantifier) VALUES ('{0}', {1}, {2}, '{3}')", item.Date, item.food_no, item.Quantity, item.Quantifier)); }
//Append created item to the recipeList. public override void saveButtonClicked(object sender, EventArgs args) { var result = new FoodHistoryItem(); result.food_no = selectedResult.food_no; //nutrFacts is from parenting class result.Quantity = Convert.ToDouble(nutrFacts.Quantity); result.Quantifier = nutrFacts.getQuantifier(); recipeList.Add(result); Navigation.RemovePage(this); base.OnBackButtonPressed(); }
//Update an entry in the foodhistory table. public bool updateFoodHistory(FoodHistoryItem item, bool saveMemento = true) { // Create memento just in case user wants to undo update if (saveMemento) { createMemento(); } int rowsModified = dbConn.Execute(String.Format("UPDATE FoodHistory SET Quantity = {0}, Quantifier = '{1}', Food_Id = {2} WHERE History_id = {3}", item.Quantity, item.Quantifier, item.food_no, item.History_Id)); if (rowsModified > 0) { return(true); } else { return(false); } }
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(); }
//Update an entry in the foodhistory table. public void updateFoodHistory(FoodHistoryItem item, int id) { dbConn.Execute(String.Format("UPDATE FoodHistory SET Quantity = {0}, Quantifier = '{1}', Food_Id = {2} WHERE History_id = {3}", item.Quantity, item.Quantifier, item.food_no, id)); }
//Adds the foodHistory entry to the database public void addFoodHistory(FoodHistoryItem item) { dbConn.Execute(String.Format("INSERT INTO FoodHistory (Date, Food_Id, Quantity, Quantifier) VALUES ('{0}', {1}, {2}, '{3}')", item.Date, item.food_no, item.Quantity, item.Quantifier)); }