Exemplo n.º 1
0
        private void del_btn_Click(object sender, EventArgs e)
        {
            ClassMenu        cm     = (ClassMenu)data_menu_list.SelectedItem;
            List <ClassMenu> cmlist = DBConnection.Entities.ClassMenus.ToList();

            if (cm == null)
            {
                MessageBox.Show("Выберите меню для удаления!");
            }
            else
            {
                if (cm.Class.Num < 5)
                {
                    foreach (var item in cmlist)
                    {
                        if (item.Class.Num < 5)
                        {
                            DBConnection.Entities.ClassMenus.Remove(item);
                            DBConnection.Entities.SaveChanges();
                        }
                    }
                }

                if (cm.Class.Num < 10 && cm.Class.Num > 4)
                {
                    foreach (var item in cmlist)
                    {
                        if (item.Class.Num < 10 && item.Class.Num > 4)
                        {
                            DBConnection.Entities.ClassMenus.Remove(item);
                            DBConnection.Entities.SaveChanges();
                        }
                    }
                }

                if (cm.Class.Num > 9)
                {
                    foreach (var item in cmlist)
                    {
                        if (item.Class.Num > 9)
                        {
                            DBConnection.Entities.ClassMenus.Remove(item);
                            DBConnection.Entities.SaveChanges();
                        }
                    }
                }

                MessageBox.Show("Меню удалено!");
                this.Fill();
            }
        }
Exemplo n.º 2
0
        private void Detail_btn_Click(object sender, EventArgs e)
        {
            ClassMenu obj = (ClassMenu)data_menu_list.SelectedItem;

            using (var f = new CompiledMenuForm(obj))
            {
                var res = f.ShowDialog();
                if (res == DialogResult.OK)
                {
                    this.classm       = obj;
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }

            this.Fill();
        }
Exemplo n.º 3
0
        public CompiledMenuForm(ClassMenu cm)
        {
            InitializeComponent();
            List <ClassMenu> cl = DBConnection.Entities.ClassMenus.ToList();
            List <Dish>      d  = DBConnection.Entities.Dishes.ToList();

            foreach (ClassMenu item in cl)
            {
                if (cm.ClassId == item.ClassId)
                {
                    foreach (Dish val in d)
                    {
                        if (val.DishId == item.IdDish)
                        {
                            if (val.MealTime.ToLower() == "завтрак")
                            {
                                break_dish_list.Items.Add(val);
                                break_sum += Convert.ToDouble(val.Calories) * Convert.ToDouble(item.Gramm / 100);
                            }

                            else if (val.MealTime.ToLower() == "обед")
                            {
                                din_dish_list.Items.Add(val);
                                din_sum += Convert.ToDouble(val.Calories) * Convert.ToDouble(item.Gramm / 100);
                            }

                            else if (val.MealTime.ToLower() == "полдник")
                            {
                                aft_dish_list.Items.Add(val);
                                aft_sum += Convert.ToDouble(val.Calories) * Convert.ToDouble(item.Gramm / 100);
                            }
                        }
                    }
                }
            }

            rec_aft_kal_lbl.Text   = aft_sum.ToString();
            rec_break_kal_lbl.Text = break_sum.ToString();
            rec_din_kal_lbl.Text   = din_sum.ToString();
        }
Exemplo n.º 4
0
        private void save_all_btn_Click(object sender, EventArgs e)
        {
            ClassMenu           cm  = new ClassMenu();
            List <Class>        cli = DBConnection.Entities.Classes.ToList();
            List <DishMealTime> dmt = new List <DishMealTime>();

            foreach (DishMealTime d in break_dish_list.Items)
            {
                dmt.Add(d);
            }
            foreach (DishMealTime d in din_dish_list.Items)
            {
                dmt.Add(d);
            }
            foreach (DishMealTime d in aft_dish_list.Items)
            {
                dmt.Add(d);
            }

            cm.Date = menu_date.Value;

            foreach (DishMealTime d in dmt)
            {
                cm.IdDishMenu = d.Id;

                if (first_call_tlstr.Checked || second_call_tlstr.Checked || third_call_tlstr.Checked || four_call_tlstr.Checked)
                {
                    foreach (Class c in cli)
                    {
                        if (c.Num == 1 || c.Num == 2 || c.Num == 3 || c.Num == 4)
                        {
                            cm.ClassId = c.ClassId;
                            cli.Remove(c);
                            break;
                        }
                    }
                }
                else if (fifth_call_tlstr.Checked || six_call_tlstr.Checked || seventh_call_tlstr.Checked || eighth_call_tlstr.Checked || ninth_call_tlstr.Checked)
                {
                    foreach (Class c in cli)
                    {
                        if (c.Num == 5 || c.Num == 6 || c.Num == 7 || c.Num == 8 || c.Num == 9)
                        {
                            cm.ClassId = c.ClassId;
                            cli.Remove(c);
                            break;
                        }
                    }
                }
                else if (tenth_call_tlstr.Checked || eleventh_call_tlstr.Checked)
                {
                    foreach (Class c in cli)
                    {
                        if (c.Num == 10 || c.Num == 11)
                        {
                            cm.ClassId = c.ClassId;
                            cli.Remove(c);
                            break;
                        }
                    }
                }

                DBConnection.Entities.ClassMenus.Add(cm);
                DBConnection.Entities.SaveChanges();
            }

            MessageBox.Show("Меню успешно сохранено!");
        }
Exemplo n.º 5
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.º 6
0
        private void save_all_btn_Click(object sender, EventArgs e)
        {
            ClassMenu       cm  = new ClassMenu();
            List <Class>    cli = DBConnection.Entities.Classes.ToList();
            List <DishGram> clm = new List <DishGram>();

            foreach (DishGram d in break_dish_list.Items)
            {
                clm.Add(d);
            }

            foreach (DishGram d in din_dish_list.Items)
            {
                clm.Add(d);
            }

            foreach (DishGram d in aft_dish_list.Items)
            {
                clm.Add(d);
            }

            cm.Date = menu_date.Value;

            foreach (Class c in cli)
            {
                if (first_call_tlstr.Checked)
                {
                    if (c.Num < 5)
                    {
                        cm.ClassId = c.ClassId;

                        foreach (var d in clm)
                        {
                            foreach (DishGram item in dg)
                            {
                                if (d.d.DishId == item.d.DishId)
                                {
                                    cm.Gramm  = item.gramm;
                                    cm.IdDish = d.d.DishId;
                                    break;
                                }
                            }

                            DBConnection.Entities.ClassMenus.Add(cm);
                            DBConnection.Entities.SaveChanges();
                        }
                    }
                }

                else if (second_call_tlstr.Checked)
                {
                    if (c.Num > 4 && c.Num < 10)
                    {
                        cm.ClassId = c.ClassId;

                        foreach (var d in clm)
                        {
                            foreach (DishGram item in dg)
                            {
                                if (d.d.DishId == item.d.DishId)
                                {
                                    cm.Gramm  = item.gramm;
                                    cm.IdDish = d.d.DishId;
                                    break;
                                }
                            }

                            DBConnection.Entities.ClassMenus.Add(cm);
                            DBConnection.Entities.SaveChanges();
                        }
                    }
                }

                else if (third_call_tlstr.Checked)
                {
                    if (c.Num > 9)
                    {
                        cm.ClassId = c.ClassId;

                        foreach (var d in clm)
                        {
                            foreach (DishGram item in dg)
                            {
                                if (d.d.DishId == item.d.DishId)
                                {
                                    cm.Gramm  = item.gramm;
                                    cm.IdDish = d.d.DishId;
                                    break;
                                }
                            }

                            DBConnection.Entities.ClassMenus.Add(cm);
                            DBConnection.Entities.SaveChanges();
                        }
                    }
                }
            }

            MessageBox.Show("Меню успешно сохранено!");
        }
Exemplo n.º 7
0
 private void Choose_btn_Click(object sender, EventArgs e)
 {
     this.classm       = (ClassMenu)data_menu_list.SelectedItem;
     this.DialogResult = DialogResult.OK;
     this.Close();
 }