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(); }
//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); // Update the undo button at the superclass level 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(); }
public bool getLastState() { bool success; if (savepoint != null) { DataAccessor db = DataAccessor.getDataAccessor(); success = db.rollback(this); return(success); } 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(); }
//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); }