コード例 #1
0
ファイル: AddItemUpdate.cs プロジェクト: Ncf4n1/NuMo
        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
        //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();
                }
            }
        }
コード例 #3
0
ファイル: AddItemUpdate.cs プロジェクト: NuMoOfficial/NuMo
        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();
        }
コード例 #4
0
        public bool getLastState()
        {
            bool success;

            if (savepoint != null)
            {
                DataAccessor db = DataAccessor.getDataAccessor();
                success = db.rollback(this);
                return(success);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
ファイル: AddItemUpdate.cs プロジェクト: Ncf4n1/NuMo
        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();
        }
コード例 #6
0
ファイル: UnitConverter.cs プロジェクト: NuMoOfficial/NuMo
        //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);
        }