Ejemplo n.º 1
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Calories != null)
         {
             hashCode = hashCode * 59 + Calories.GetHashCode();
         }
         if (DailyValues != null)
         {
             hashCode = hashCode * 59 + DailyValues.GetHashCode();
         }
         if (Fat != null)
         {
             hashCode = hashCode * 59 + Fat.GetHashCode();
         }
         if (Carbs != null)
         {
             hashCode = hashCode * 59 + Carbs.GetHashCode();
         }
         if (Vitamins != null)
         {
             hashCode = hashCode * 59 + Vitamins.GetHashCode();
         }
         return(hashCode);
     }
 }
Ejemplo n.º 2
0
    public void makeCarbMeals()
    {
        dictionaryCarbs = new Dictionary <int, List <Carbs> >();
        UserConnect.ConnectionString = connString;
        cmd = UserConnect.CreateCommand();

        try
        {
            string query = "SELECT TOP " + sqlLimit + " name, protein, fat, Carbohydrates, calories from Ingredients where (name like '%potato%'" +
                           "OR name like '%pasta%' OR name like '%rice%' or name like '%macaroni%' or name like '%noodles%' or name like '%spaghetti%') and name NOT LIKE '%snack%'" +
                           "ORDER BY NEWID();";

            cmd.CommandText = query;

            UserConnect.Open();
            reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    Carbs carbs = new Carbs();

                    carbs.name          = reader["name"].ToString();
                    carbs.protein       = (int)reader["protein"];
                    carbs.fat           = Convert.ToDouble(reader["fat"]);
                    carbs.carbohydrates = Convert.ToDouble(reader["carbohydrates"]);
                    carbs.calories      = (int)reader["calories"];
                    carbs.servingSize   = 100;


                    double factor = calcCarb / carbs.calories;
                    carbs.protein       = (int)(carbs.protein * factor);
                    carbs.fat           = carbs.fat * factor;
                    carbs.carbohydrates = carbs.carbohydrates * factor;
                    carbs.calories      = (int)(carbs.calories * factor);
                    carbs.servingSize   = (int)(carbs.servingSize * factor);
                    carbList.Add(carbs);
                }
            }
            for (int i = 0; i < 7; i++)
            {
                List <Carbs> carbMeal = new List <Carbs>();
                for (int j = 0; j < meals; j++)
                {
                    Random rdm = new Random();

                    int num = rdm.Next(0, carbList.Count - 1);
                    carbMeal.Add(carbList[num]);
                    carbList.RemoveAt(num);
                }
                dictionaryCarbs.Add(i, carbMeal);
            }
        }
        finally
        {
            cmd.Dispose();
            UserConnect.Close();
        }
    }
Ejemplo n.º 3
0
 public override string ToString()
 {
     return
         ($"\nProteins  {Proteins.ToString("0.##")} g = {(Proteins * 4).ToString("0.##")} Kcal" +
          $"\nFat       {Fat.ToString("0.##")} g = {(Fat * 9).ToString("0.##")} Kcal" +
          $"\nCarbs     {Carbs.ToString("0.##")} g = {(Carbs * 4).ToString("0.##")} Kcal" +
          $"\nTotalgram {TotalGrams.ToString("0.##")} g = {Kcal.ToString("0.##")} Kcal");
 }
Ejemplo n.º 4
0
        public string ToInsert()
        {
            var kcal    = Kcal.ToString().Replace(',', '.');
            var protein = Protein.ToString().Replace(',', '.');
            var fat     = Fat.ToString().Replace(',', '.');
            var carbs   = Carbs.ToString().Replace(',', '.');

            return($"('{ID}', '{Name}', '{kcal}', '{protein}', '{fat}', '{carbs}', '{Type}')");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns true if RecipeObjectNutrients instances are equal
        /// </summary>
        /// <param name="other">Instance of RecipeObjectNutrients to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(RecipeObjectNutrients other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Calories == other.Calories ||
                     Calories != null &&
                     Calories.SequenceEqual(other.Calories)
                     ) &&
                 (
                     DailyValues == other.DailyValues ||
                     DailyValues != null &&
                     DailyValues.SequenceEqual(other.DailyValues)
                 ) &&
                 (
                     Fat == other.Fat ||
                     Fat != null &&
                     Fat.SequenceEqual(other.Fat)
                 ) &&
                 (
                     Carbs == other.Carbs ||
                     Carbs != null &&
                     Carbs.SequenceEqual(other.Carbs)
                 ) &&
                 (
                     Vitamins == other.Vitamins ||
                     Vitamins != null &&
                     Vitamins.SequenceEqual(other.Vitamins)
                 ));
        }
Ejemplo n.º 6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Table[]  tableList = new Table[] { tbMonday, tbTuesday, tbWednesday, tbThursday, tbFriday, tbSaturday, tbSunday };
        string[] days      = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
        mp = new MealPlanner(Convert.ToInt32(Session["sUserId"]));

        Dictionary <int, List <Protein> > prDict = mp.getProteins();
        Dictionary <int, List <Carbs> >   cbDict = mp.getCarbs();
        Dictionary <int, List <Fats> >    fDict  = mp.getFats();
        Dictionary <int, List <Snacks> >  skDict = mp.getSnacks();
        Dictionary <int, List <Vegs> >    vDict  = mp.getVegs();

        for (int t = 0; t < tableList.Length; t++)
        {
            TableRow dRow = new TableRow();
            tableList[t].Rows.Add(dRow);
            TableCell dCell = new TableCell();
            dCell.Text       = days[t];
            dCell.Font.Bold  = true;
            dCell.ColumnSpan = 6;
            dCell.ForeColor  = System.Drawing.Color.White;
            dCell.BackColor  = System.Drawing.ColorTranslator.FromHtml("#33b5e5");
            dRow.Cells.Add(dCell);

            for (int m = 0; m < mp.getMeals(); m++)
            {
                TableRow tRow = new TableRow();
                tableList[t].Rows.Add(tRow);
                TableCell tCell = new TableCell();
                tCell.Text       = "Meal" + (m + 1).ToString();
                tCell.Font.Bold  = true;
                tCell.ColumnSpan = 6;
                tCell.ForeColor  = System.Drawing.Color.White;
                tCell.BackColor  = System.Drawing.ColorTranslator.FromHtml("#0d47a1");
                tRow.Cells.Add(tCell);

                TableRow tRow2 = new TableRow();
                tableList[t].Rows.Add(tRow2);
                TableCell hCell = new TableCell();
                hCell.Text = "Name";
                TableCell hCell1 = new TableCell();
                hCell1.Text = "Total Calories";
                TableCell hCell2 = new TableCell();
                hCell2.Text = "Protein(g)";
                TableCell hCell3 = new TableCell();
                hCell3.Text = "Carbs(g)";
                TableCell hCell4 = new TableCell();
                hCell4.Text = "Fats(g)";
                TableCell hCell5 = new TableCell();
                hCell5.Text      = "Serving Size(g)";
                hCell.Font.Bold  = true;
                hCell1.Font.Bold = true;
                hCell2.Font.Bold = true;
                hCell3.Font.Bold = true;
                hCell4.Font.Bold = true;
                hCell5.Font.Bold = true;
                tRow2.Cells.Add(hCell);
                tRow2.Cells.Add(hCell1);
                tRow2.Cells.Add(hCell2);
                tRow2.Cells.Add(hCell3);
                tRow2.Cells.Add(hCell4);
                tRow2.Cells.Add(hCell5);

                TableRow tRow3 = new TableRow();
                tableList[t].Rows.Add(tRow3);
                TableCell pCell  = new TableCell();
                TableCell pCell1 = new TableCell();
                TableCell pCell2 = new TableCell();
                TableCell pCell3 = new TableCell();
                TableCell pCell4 = new TableCell();
                TableCell pCell5 = new TableCell();
                Protein   p      = prDict[t].ElementAt(m);
                pCell.Text  = p.name.ToString();
                pCell1.Text = p.calories.ToString();
                pCell2.Text = p.protein.ToString();
                pCell3.Text = Math.Round(p.carbohydrates, 2).ToString();
                pCell4.Text = Math.Round(p.fat, 2).ToString();
                pCell5.Text = Math.Round(p.servingSize, 2).ToString();
                tRow3.Cells.Add(pCell);
                tRow3.Cells.Add(pCell1);
                tRow3.Cells.Add(pCell2);
                tRow3.Cells.Add(pCell3);
                tRow3.Cells.Add(pCell4);
                tRow3.Cells.Add(pCell5);

                TableRow tRow4 = new TableRow();
                tableList[t].Rows.Add(tRow4);
                TableCell cCell  = new TableCell();
                TableCell cCell1 = new TableCell();
                TableCell cCell2 = new TableCell();
                TableCell cCell3 = new TableCell();
                TableCell cCell4 = new TableCell();
                TableCell cCell5 = new TableCell();
                Carbs     c      = cbDict[t].ElementAt(m);
                cCell.Text  = c.name.ToString();
                cCell1.Text = c.calories.ToString();
                cCell2.Text = c.protein.ToString();
                cCell3.Text = Math.Round(c.carbohydrates, 2).ToString();
                cCell4.Text = Math.Round(c.fat, 2).ToString();
                cCell5.Text = Math.Round(c.servingSize, 2).ToString();
                tRow4.Cells.Add(cCell);
                tRow4.Cells.Add(cCell1);
                tRow4.Cells.Add(cCell2);
                tRow4.Cells.Add(cCell3);
                tRow4.Cells.Add(cCell4);
                tRow4.Cells.Add(cCell5);

                TableRow tRow5 = new TableRow();
                tableList[t].Rows.Add(tRow5);
                TableCell fCell  = new TableCell();
                TableCell fCell1 = new TableCell();
                TableCell fCell2 = new TableCell();
                TableCell fCell3 = new TableCell();
                TableCell fCell4 = new TableCell();
                TableCell fCell5 = new TableCell();
                Fats      f      = fDict[t].ElementAt(m);
                fCell.Text  = f.name.ToString();
                fCell1.Text = f.calories.ToString();
                fCell2.Text = f.protein.ToString();
                fCell3.Text = Math.Round(f.carbohydrates, 2).ToString();
                fCell4.Text = Math.Round(f.fat, 2).ToString();
                fCell5.Text = Math.Round(f.servingSize, 2).ToString();
                tRow5.Cells.Add(fCell);
                tRow5.Cells.Add(fCell1);
                tRow5.Cells.Add(fCell2);
                tRow5.Cells.Add(fCell3);
                tRow5.Cells.Add(fCell4);
                tRow5.Cells.Add(fCell5);

                if (m == 2 || m == 4)
                {
                    int      mm    = m - 2;
                    TableRow tRow6 = new TableRow();
                    tableList[t].Rows.Add(tRow6);
                    TableCell sCell  = new TableCell();
                    TableCell sCell1 = new TableCell();
                    TableCell sCell2 = new TableCell();
                    TableCell sCell3 = new TableCell();
                    TableCell sCell4 = new TableCell();
                    TableCell sCell5 = new TableCell();
                    Snacks    s      = skDict[t].ElementAt(mm);
                    sCell.Text  = s.name.ToString();
                    sCell1.Text = s.calories.ToString();
                    sCell2.Text = s.protein.ToString();
                    sCell3.Text = Math.Round(s.carbohydrates, 2).ToString();
                    sCell4.Text = Math.Round(s.fat, 2).ToString();
                    sCell5.Text = Math.Round(s.servingSize, 2).ToString();
                    tRow6.Cells.Add(sCell);
                    tRow6.Cells.Add(sCell1);
                    tRow6.Cells.Add(sCell2);
                    tRow6.Cells.Add(sCell3);
                    tRow6.Cells.Add(sCell4);
                    tRow6.Cells.Add(sCell5);
                }

                TableRow tRow7 = new TableRow();
                tableList[t].Rows.Add(tRow7);
                TableCell vCell  = new TableCell();
                TableCell vCell1 = new TableCell();
                TableCell vCell2 = new TableCell();
                TableCell vCell3 = new TableCell();
                TableCell vCell4 = new TableCell();
                TableCell vCell5 = new TableCell();
                Vegs      v      = vDict[t].ElementAt(m);
                vCell.Text  = v.name.ToString();
                vCell1.Text = v.calories.ToString();
                vCell2.Text = "<b>Fiber(g):</b>  " + Math.Round(v.fiber, 2).ToString();
                vCell5.Text = Math.Round(v.servingSize, 2).ToString();

                vCell2.ColumnSpan      = 3;
                vCell2.HorizontalAlign = HorizontalAlign.Center;
                tRow7.Cells.Add(vCell);
                tRow7.Cells.Add(vCell1);
                tRow7.Cells.Add(vCell2);
                tRow7.Cells.Add(vCell5);
            }
        }
    }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            // credit: http://stackoverflow.com/a/263416/677735
            unchecked // Overflow is fine, just wrap
            {
                var hash = 41;
                // Suitable nullity checks etc, of course :)

                if (Id != null)
                {
                    hash = hash * 59 + Id.GetHashCode();
                }

                if (EventType != null)
                {
                    hash = hash * 59 + EventType.GetHashCode();
                }

                if (CreatedAt != null)
                {
                    hash = hash * 59 + CreatedAt.GetHashCode();
                }

                if (Glucose != null)
                {
                    hash = hash * 59 + Glucose.GetHashCode();
                }

                if (GlucoseType != null)
                {
                    hash = hash * 59 + GlucoseType.GetHashCode();
                }

                if (Carbs != null)
                {
                    hash = hash * 59 + Carbs.GetHashCode();
                }

                if (Insulin != null)
                {
                    hash = hash * 59 + Insulin.GetHashCode();
                }

                if (Units != null)
                {
                    hash = hash * 59 + Units.GetHashCode();
                }

                if (Notes != null)
                {
                    hash = hash * 59 + Notes.GetHashCode();
                }

                if (EnteredBy != null)
                {
                    hash = hash * 59 + EnteredBy.GetHashCode();
                }

                return(hash);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns true if Treatment instances are equal
        /// </summary>
        /// <param name="other">Instance of Treatment to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Treatment other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                     ) &&
                 (
                     EventType == other.EventType ||
                     EventType != null &&
                     EventType.Equals(other.EventType)
                 ) &&
                 (
                     CreatedAt == other.CreatedAt ||
                     CreatedAt != null &&
                     CreatedAt.Equals(other.CreatedAt)
                 ) &&
                 (
                     Glucose == other.Glucose ||
                     Glucose != null &&
                     Glucose.Equals(other.Glucose)
                 ) &&
                 (
                     GlucoseType == other.GlucoseType ||
                     GlucoseType != null &&
                     GlucoseType.Equals(other.GlucoseType)
                 ) &&
                 (
                     Carbs == other.Carbs ||
                     Carbs != null &&
                     Carbs.Equals(other.Carbs)
                 ) &&
                 (
                     Insulin == other.Insulin ||
                     Insulin != null &&
                     Insulin.Equals(other.Insulin)
                 ) &&
                 (
                     Units == other.Units ||
                     Units != null &&
                     Units.Equals(other.Units)
                 ) &&
                 (
                     Notes == other.Notes ||
                     Notes != null &&
                     Notes.Equals(other.Notes)
                 ) &&
                 (
                     EnteredBy == other.EnteredBy ||
                     EnteredBy != null &&
                     EnteredBy.Equals(other.EnteredBy)
                 ));
        }