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); }