private void AddMealSummary(int mealNo, DataRow row, decimal Carbs, decimal Sugar, decimal Fat, decimal FatSat, decimal FatMono, decimal FatPoly, decimal FatTrans, decimal Protein, decimal Alcohol, decimal Weight, Meal Meal)
 {
     ucMealSummary mealSummary = new ucMealSummary();
     mealSummary.MealName = row["Name"].ToString();
     mealSummary.Energy = Meal.Energy;
     mealSummary.Carbs = Carbs;
     mealSummary.Sugar = Sugar;
     mealSummary.Fat = Fat;
     mealSummary.FatMono = FatMono;
     mealSummary.FatPoly = FatPoly;
     mealSummary.FatSat = FatSat;
     mealSummary.FatTrans = FatTrans;
     mealSummary.Protein = Protein;
     mealSummary.Alcohol = Alcohol;
     mealSummary.Weight = Weight;
     mealSummary.Top = 2 + (mealNo * 160);
     mealSummary.Left = 2;
     mealSummary.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
     this.Controls.Add(mealSummary);
 }
        private void fill()
        {
            int mealNo = 0;
            foreach (DataRow row in tblMeals.Rows)
            {
                decimal Carbs = 0;
                decimal Sugar = 0;
                decimal Fat = 0;
                decimal FatSat = 0;
                decimal FatMono = 0;
                decimal FatPoly = 0;
                decimal FatTrans = 0;
                decimal Protein = 0;
                decimal Alcohol = 0;
                decimal Weight = 0;

                int MealId = (int)row["id"];
                Meal Meal = new Meal(MealId);
                if (Meal.Energy > 0)
                {
                    int n = 0;
                    foreach (Global.Food Food in Meal.Foods)
                    {
                        Carbs += Meal.Foods[n].Carbs;
                        Sugar += Meal.Foods[n].Sugar;
                        Fat += Meal.Foods[n].Fat;
                        FatSat += Meal.Foods[n].FatSat;
                        FatMono += Meal.Foods[n].FatMono;
                        FatPoly += Meal.Foods[n].FatPoly;
                        FatTrans += Meal.Foods[n].FatTrans;
                        Protein += Meal.Foods[n].Protein;
                        Alcohol += Meal.Foods[n].Alcohol;
                        Weight += Meal.Foods[n].Count * Meal.Foods[n].unitWeight;
                        n += 1;
                    }
                    AddMealSummary(mealNo, row, Carbs, Sugar, Fat, FatSat, FatMono, FatPoly, FatTrans, Protein, Alcohol, Weight, Meal);
                    mealNo += 1;
                }
            }
        }
Пример #3
0
        private void getMeals()
        {
            int mealNo = 0;
            decimal Carbs = 0;
            decimal Sugar = 0;
            decimal Fat = 0;
            decimal FatSat = 0;
            decimal FatMono = 0;
            decimal FatPoly = 0;
            decimal FatTrans = 0;
            decimal Protein = 0;
            decimal Alcohol = 0;
            decimal Weight = 0;
            decimal totalEnergy = 0;

            dgvDiary.Rows.Clear();
            string sqlString = "SELECT " +
                "tblMeals.id, " +
                "tblMeals.id_mealtype, " +
                "tblMeals.date, " +
                "tblMeals.time, " +
                "tblMealTypes.SortOrder, " +
                "tblMealTypes.Name " +
                "FROM tblMeals " +
                "LEFT OUTER JOIN tblMealTypes on tblMeals.id_mealType = tblMealTypes.id " +
                "WHERE date = @date AND tblMeals.idUser = @idUser" +
                " ORDER BY tblMealTypes.SortOrder, time";
            SqlDataAdapter a = new SqlDataAdapter(sqlString, Global.conn1);
            a.SelectCommand.Parameters.AddWithValue("@date", dtpDate.Value.Date);
            a.SelectCommand.Parameters.AddWithValue("@idUser", Global.idUser);
            _tblMeals=new DataTable();
            a.Fill(_tblMeals);

            foreach (DataRow row in _tblMeals.Rows )
            {
                decimal MealCarbs = 0;
                decimal MealFat = 0;
                decimal MealProtein = 0;
                decimal MealAlcohol = 0;
                int MealId = (int)row["id"];
                Meal Meal = new Meal(MealId);
                if (Meal.Foods.Length > 0)
                {
                    int HeaderRowNo = dgvDiary.Rows.Add();
                    dgvDiary.Rows[HeaderRowNo].DefaultCellStyle = FoodDiaryHeadingStyle();
                    dgvDiary.Rows[HeaderRowNo].Cells[1].Value = MealId;
                    dgvDiary.Rows[HeaderRowNo].Cells[3].Value = row["Name"].ToString();
                    dgvDiary.Rows[HeaderRowNo].Cells[4].Value = Meal.Energy.ToString("# ###.##") + " kCal";
                    totalEnergy += Meal.Energy;
                    int RowNo;
                    foreach (Global.Food Food in Meal.Foods)
                    {
                        RowNo = dgvDiary.Rows.Add();
                        dgvDiary.Rows[RowNo].Cells[0].Value = Food.idDiary;
                        dgvDiary.Rows[RowNo].Cells[1].Value = MealId;
                        dgvDiary.Rows[RowNo].Cells[2].Value = Food.idFood;
                        dgvDiary.Rows[RowNo].Cells[3].Value = Food.DisplayName;
                        dgvDiary.Rows[RowNo].Cells[4].Value = Food.Energy.ToString("# ###.##") + " kCal";

                        Carbs += Food.Carbs;
                        MealCarbs += Food.Carbs;
                        Sugar += Food.Sugar;
                        Fat += Food.Fat;
                        MealFat += Food.Fat;
                        FatSat += Food.FatSat;
                        FatMono += Food.FatMono;
                        FatPoly += Food.FatPoly;
                        FatTrans += Food.FatTrans;
                        Protein += Food.Protein;
                        MealProtein += Food.Protein;
                        Alcohol += Food.Alcohol;
                        MealAlcohol += Food.Alcohol;
                        Weight += Food.Count * Food.unitWeight;
                    }
                }
            }
            setDiaryGrid();
            AddDaySummary(mealNo, Carbs, Sugar, Fat, FatSat, FatMono, FatPoly, FatTrans, Protein, Alcohol, Weight, totalEnergy);
        }