Ejemplo n.º 1
0
        private void LoadValues()
        {
            if (dgvFood.SelectedRows.Count == 0)
            {
                return;
            }

            string value = dgvFood.SelectedRows[0].Cells[0].Value.ToString();
            Foods  lf    = fds.LoadActive(value);

            if (lf.Index == -1)
            {
                return;
            }
            //we have a value
            //load it to current
            fs = fds.LoadActive(value);
            //update the labels
            if (fs.Measure == null && fs.Weight == 0)
            {
                vServing.Text = "No Measure or weight supplied";
            }
            else if (fs.Measure == null)
            {
                vServing.Text = "No Measure supplied - weight: " + fs.Weight + "g";
            }
            else
            {
                vServing.Text = "Measure: " + fs.Measure + " - weight: " + fs.Weight + "g";
            }
            vCarbohydrates.Text = "Carb: " + fs.Carb.ToString();
            vFibers.Text        = "Fiber: " + fs.Fiber.ToString();
            vFats.Text          = "Fat: " + fs.Fat.ToString();
        }
Ejemplo n.º 2
0
 private void FoodSearch_Completed()
 {
     fs                   = fds.Current;
     bs.DataSource        = fds.GetNames("").ConvertAll(x => new { Value = x });
     tFood.Enabled        = true;
     dgvFood.Enabled      = true;
     RefreshFoods.Enabled = fds.RefreshFoods;
 }
Ejemplo n.º 3
0
        private async void ProcessAll(string json)
        {
            fr      = Deserialize <FoodRoot>(json);
            fd      = fr.report.foods;
            Current = LoadActive(0);

            //Validate Refresh
            HttpClient hpClient = new HttpClient();
            string     results  = await hpClient.GetStringAsync(totals).ConfigureAwait(false);

            int    tstart = results.IndexOf("\"total\": ") + 8;
            int    tend   = results.IndexOf(",", tstart);
            string stotal = results.Substring(tstart, tend - tstart);
            int    total  = int.Parse(stotal);

            RefreshFoods = (total == fr.report.total);
        }
Ejemplo n.º 4
0
        public Foods LoadActive(int index)
        {
            Foods food = new Foods();

            food.Index = -1;
            if (index < 0 || index > fd.Count)
            {
                return(food);
            }
            food.Index   = index;
            food.Name    = fd[index].name;
            food.Measure = fd[index].measure;
            food.Weight  = fd[index].weight;
            food.Carb    = fd[index].nutrients[0].value;
            food.Fiber   = fd[index].nutrients[1].value;
            food.Fat     = fd[index].nutrients[2].value;
            return(food);
        }
Ejemplo n.º 5
0
        private void ProcessAll(string[] json)
        {
            Status("Processed string 1 of " + (json.Length) + ".");
            fr = Deserialize <FoodRoot>(json[0]);

            for (int j = 1; j < json.Length; j++)
            {
                Status("Processed string " + j + " of " + (json.Length - 1) + ".");
                FoodRoot tr = Deserialize <FoodRoot>(json[j]);
                fr.report.foods.AddRange(tr.report.foods);
            }

            fd      = fr.report.foods;
            Current = LoadActive(0);
            Status("Enter filter");
            Completed();
            WriteFile();
        }