Exemplo n.º 1
0
        private void del_aft_dish_btn_Click(object sender, EventArgs e)
        {
            DishGram obj = (DishGram)aft_dish_list.SelectedItem;

            if (obj == null)
            {
                MessageBox.Show("Выберите блюдо для удаления!");
            }
            else
            {
                car      -= obj.d.Carbohydrates * (obj.gramm / 100);
                fat      -= obj.d.Fats * (obj.gramm / 100);
                prot     -= obj.d.Protein * (obj.gramm / 100);
                aft_norm -= obj.d.Calories * (obj.gramm / 100);
                sum      -= obj.d.Calories * (obj.gramm / 100);

                typed_carbohydrates_lbl.Text = car.ToString();
                typed_fats_lbl.Text          = fat.ToString();
                typed_proteins_lbl.Text      = prot.ToString();

                earn_day_kal_lbl.Text = sum.ToString();

                rec_aft_kal_lbl.Text = aft_norm.ToString();

                aft_dish_list.Items.RemoveAt(aft_dish_list.SelectedIndex);
            }
        }
Exemplo n.º 2
0
        private void choose_comp_menu_btn_Click(object sender, EventArgs e)
        {
            using (var f = new ChoiceMenuForm())
            {
                var res = f.ShowDialog();
                if (res == DialogResult.OK)
                {
                    break_dish_list.Items.Clear();
                    din_dish_list.Items.Clear();
                    aft_dish_list.Items.Clear();

                    if (f.classm == null)
                    {
                        this.Fill();
                    }
                    else
                    {
                        ClassMenu cm = f.classm;

                        List <ClassMenu> cl = DBConnection.Entities.ClassMenus.ToList();
                        List <Dish>      d  = DBConnection.Entities.Dishes.ToList();
                        menu_date.Value = cm.Date;


                        foreach (ClassMenu item in cl)
                        {
                            if (cm.ClassId == item.ClassId)
                            {
                                foreach (Dish val in d)
                                {
                                    if (val.DishId == item.IdDish)
                                    {
                                        DishGram dg = new DishGram();

                                        if (val.MealTime.ToLower() == "завтрак")
                                        {
                                            dg.d     = val;
                                            dg.gramm = item.Gramm;
                                            break_dish_list.Items.Add(dg);
                                            break_norm += val.Calories * Convert.ToDouble(item.Gramm / 100);
                                            car        += val.Carbohydrates * Convert.ToDouble(item.Gramm / 100);
                                            fat        += val.Fats * Convert.ToDouble(item.Gramm / 100);
                                            prot       += val.Protein * Convert.ToDouble(item.Gramm / 100);
                                        }

                                        else if (val.MealTime.ToLower() == "обед")
                                        {
                                            dg.d     = val;
                                            dg.gramm = item.Gramm;
                                            din_dish_list.Items.Add(dg);
                                            din_norm += val.Calories * Convert.ToDouble(item.Gramm / 100);
                                            car      += val.Carbohydrates * Convert.ToDouble(item.Gramm / 100);
                                            fat      += val.Fats * Convert.ToDouble(item.Gramm / 100);
                                            prot     += val.Protein * Convert.ToDouble(item.Gramm / 100);
                                        }

                                        else if (val.MealTime.ToLower() == "полдник")
                                        {
                                            dg.d     = val;
                                            dg.gramm = item.Gramm;
                                            aft_dish_list.Items.Add(dg);
                                            aft_norm += val.Calories * Convert.ToDouble(item.Gramm / 100);
                                            car      += val.Carbohydrates * Convert.ToDouble(item.Gramm / 100);
                                            fat      += val.Fats * Convert.ToDouble(item.Gramm / 100);
                                            prot     += val.Protein * Convert.ToDouble(item.Gramm / 100);
                                        }
                                    }
                                }
                            }
                        }

                        rec_aft_kal_lbl.Text         = aft_norm.ToString();
                        rec_break_kal_lbl.Text       = break_norm.ToString();
                        rec_din_kal_lbl.Text         = din_norm.ToString();
                        typed_carbohydrates_lbl.Text = car.ToString();
                        typed_fats_lbl.Text          = fat.ToString();
                        typed_proteins_lbl.Text      = prot.ToString();
                        earn_day_kal_lbl.Text        = Convert.ToString(sum = break_norm + aft_norm + din_norm);
                    }
                }
            }

            this.Fill();
        }
Exemplo n.º 3
0
        private void add_aft_dish_btn_Click(object sender, EventArgs e)
        {
            Dish obj = (Dish)all_dish_list.SelectedItem;

            if (obj == null)
            {
                MessageBox.Show("Выберите блюдо из списка!");
            }
            else if (obj.MealTime.ToLower() != "полдник")
            {
                MessageBox.Show("Это блюдо нельзя добавить в полдник!");
            }
            else
            {
                DishGram dishGram = new DishGram();
                using (var f = new GramForm(obj))
                {
                    f.Owner = this;
                    var res = f.ShowDialog();
                    if (res == DialogResult.OK)
                    {
                        double num = f.gram;
                        dishGram.d     = obj;
                        dishGram.gramm = num;
                        dg.Add(dishGram);

                        car      += obj.Carbohydrates * (num / 100);
                        fat      += obj.Fats * (num / 100);
                        prot     += obj.Protein * (num / 100);
                        aft_norm += obj.Calories * (num / 100);
                        sum      += obj.Calories * (num / 100);

                        if (Convert.ToDouble(aft_day_kal_lbl.Text) < aft_norm)
                        {
                            car        -= obj.Carbohydrates * (num / 100);
                            fat        -= obj.Fats * (num / 100);
                            prot       -= obj.Protein * (num / 100);
                            break_norm -= obj.Calories * (num / 100);
                            sum        -= obj.Calories * (num / 100);

                            MessageBox.Show("Вы превысили калорий!!!");
                        }

                        else if (Convert.ToDouble(norm_carbohydrates_lbl.Text) < car)
                        {
                            car        -= obj.Carbohydrates * (num / 100);
                            fat        -= obj.Fats * (num / 100);
                            prot       -= obj.Protein * (num / 100);
                            break_norm -= obj.Calories * (num / 100);
                            sum        -= obj.Calories * (num / 100);

                            MessageBox.Show("Вы превысили норму углеводов!!!");
                        }

                        else if (Convert.ToDouble(norm_fats_lbl.Text) < fat)
                        {
                            car        -= obj.Carbohydrates * (num / 100);
                            fat        -= obj.Fats * (num / 100);
                            prot       -= obj.Protein * (num / 100);
                            break_norm -= obj.Calories * (num / 100);
                            sum        -= obj.Calories * (num / 100);

                            MessageBox.Show("Вы превысили норму жиров!!!");
                        }

                        else if (Convert.ToDouble(norm_proteins_lbl.Text) < prot)
                        {
                            car        -= obj.Carbohydrates * (num / 100);
                            fat        -= obj.Fats * (num / 100);
                            prot       -= obj.Protein * (num / 100);
                            break_norm -= obj.Calories * (num / 100);
                            sum        -= obj.Calories * (num / 100);

                            MessageBox.Show("Вы превысили норму белков!!!");
                        }

                        else
                        {
                            typed_carbohydrates_lbl.Text = car.ToString();
                            typed_fats_lbl.Text          = fat.ToString();
                            typed_proteins_lbl.Text      = prot.ToString();

                            aft_dish_list.Items.Add(dishGram);

                            rec_aft_kal_lbl.Text = aft_norm.ToString();
                        }

                        earn_day_kal_lbl.Text = sum.ToString();
                    }
                }
            }
        }