private void button2_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult m = MessageBox.Show("Удалить?", "", MessageBoxButton.OKCancel);

            if (m == MessageBoxResult.OK)
            {
                Schedule s = null;
                if (listBox1.SelectedIndex >= 0)
                {
                    s = l[listBox1.SelectedIndex];
                }
                else if (listBox3.SelectedIndex >= 0)
                {
                    s = l[listBox2.SelectedIndex];
                }
                else if (listBox3.SelectedIndex >= 0)
                {
                    s = l[listBox3.SelectedIndex];
                }
                using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
                {
                    if (s != null)
                    {
                        var s1 = from Schedule in Db.Schedules
                                 where Schedule.ScheduleID == s.ScheduleID
                                 select Schedule;
                        Db.Schedules.DeleteOnSubmit(s1.FirstOrDefault());
                        Db.SubmitChanges();
                    }
                }
                init();
            }
        }
예제 #2
0
        private void button4_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult m = MessageBox.Show("Удалить?", "", MessageBoxButton.OKCancel);

            if (m == MessageBoxResult.OK)
            {
                Diet s = null;
                if (ListboxDiet.SelectedIndex >= 0)
                {
                    s = l[ListboxDiet.SelectedIndex];
                }

                using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
                {
                    if (s != null)
                    {
                        var s1 = from Diet in Db.Diets
                                 where Diet.DietID == s.DietID
                                 select Diet;
                        Db.Diets.DeleteOnSubmit(s1.FirstOrDefault());
                        Db.SubmitChanges();
                    }
                }
                init();
            }
        }
예제 #3
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
            {
                Product p = new Product(name.Text, listBox1.SelectedIndex, Convert.ToDouble(protein.Text), Convert.ToDouble(fat.Text),
                                        Convert.ToDouble(carbohydrates.Text), Convert.ToInt32(calories.Text), Convert.ToInt32(cost.Text), Convert.ToDouble(acidity.Text), listBox2.SelectedIndex);

                NavigationService.Navigate(new Uri("/ProductList.xaml", UriKind.Relative));
                Db.Products.InsertOnSubmit(p);
                Db.SubmitChanges();
            }
        }
        public void init()
        {
            using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
            {
                IQueryable <Dish> DishesQuery = from Dish in Db.Dishes select Dish;
                l = DishesQuery.ToList();
                var           list  = DishesQuery.Select(s => new { s.Name }).ToList();
                List <String> names = new List <string>();
                foreach (var s in list)
                {
                    String ss = s.ToString().Replace("{ Name = ", "");
                    ss = ss.Replace("}", "");
                    names.Add(ss);
                }

                List <String> portions = new List <String>();

                List <Dish> dishesList = DishesQuery.ToList();
                foreach (Dish dish in dishesList)
                {
                    if (dish.Measure == 0)
                    {
                        portions.Add(dish.Portion + " г.");
                    }
                    else
                    {
                        portions.Add(dish.Portion + " мл.");
                    }
                }

                List <int> calories = new List <int>();

                foreach (Dish dish in dishesList)
                {
                    int calory             = 0;
                    List <DishProduct> dps = dish.DishProducts.ToList();
                    foreach (DishProduct dp in dps)
                    {
                        Product p = dp.Product;
                        calory += p.Calories * dp.Quantity;
                    }
                    if (dish.Portion != 0)
                    {
                        calory /= dish.Portion;
                    }
                    calories.Add(calory);
                }

                listBox1.ItemsSource = names;
                listBox2.ItemsSource = portions;
                listBox3.ItemsSource = calories;
            }
        }
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
     {
         DishProduct dp = new DishProduct()
         {
             DId = AddDish.d.DishID, Product = l[SelectedIndex], Quantity = Convert.ToInt32(textBox1.Text)
         };
         AddDish.d.DishProducts.Add(dp);
         NavigationService.Navigate(new Uri("/AddDish.xaml", UriKind.Relative));
     }
 }
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult m = MessageBox.Show("Удалить?", "", MessageBoxButton.OKCancel);

            if (m == MessageBoxResult.OK)
            {
                Dish s = null;

                if (listBox2.SelectedIndex >= 0)
                {
                    s = l[listBox2.SelectedIndex];
                }
                else if (listBox3.SelectedIndex >= 0)
                {
                    s = l[listBox3.SelectedIndex];
                }
                else if (listBox1.SelectedIndex >= 0)
                {
                    s = l[listBox1.SelectedIndex];
                }
                using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
                {
                    if (s != null)
                    {
                        var s3 = from DishProduct in Db.DishProducts
                                 where DishProduct.DId == s.DishID
                                 select DishProduct;

                        List <DishProduct> dp = s3.ToList();
                        Db.DishProducts.DeleteAllOnSubmit(dp);
                        Db.SubmitChanges();

                        var s4 = from Ration in Db.Rations
                                 where Ration.Dish.DishID == s.DishID
                                 select Ration;

                        List <Ration> rp = s4.ToList();
                        Db.Rations.DeleteAllOnSubmit(rp);
                        Db.SubmitChanges();

                        var s1 = from Dish in Db.Dishes
                                 where Dish.DishID == s.DishID
                                 select Dish;
                        Db.Dishes.DeleteOnSubmit(s1.FirstOrDefault());
                        Db.SubmitChanges();
                    }
                }
                init();
            }
        }
예제 #7
0
        public Profile()
        {
            InitializeComponent();
            using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
            {
                IQueryable <Person> PersonQuery = from Person in Db.Persons where Person.Name != "" select Person;
                Person p = PersonQuery.FirstOrDefault();
                age.Text    = p.Age + "";
                name.Text   = p.Name;
                height.Text = p.Height + "";
                weight.Text = p.Weight + "";
                fat.Text    = p.PercentFat + "";
                bioage.Text = p.BioAge + "";
                if (p.Sex == "M")
                {
                    M.IsChecked = true;
                    F.IsChecked = false;
                }
                else
                {
                    F.IsChecked = true;
                    M.IsChecked = false;
                }

                IQueryable <IdealParameter> IpQuery = from IdealParameter in Db.IdealParameters
                                                      where IdealParameter.Height_min <= p.Height
                                                      where IdealParameter.Height_max >= p.Height
                                                      where IdealParameter.ConstitutionId == p.ConstitutionId
                                                      select IdealParameter;
                IdealParameter ip = IpQuery.FirstOrDefault();

                double idealW = Math.Round(((ip.Weight_max + ip.Weight_min) / 2), 1);
                ideal.Text = idealW + "";

                if (p.Weight > ip.Weight_min)
                {
                    info.Text = "Вам стоит сбросить вес на " + (p.Weight - ip.Weight_max) + "кг";
                }
                else if (p.Weight < ip.Weight_max)
                {
                    info.Text = "Вам стоит набрать вес на " + (ip.Weight_min - p.Weight) + "кг";
                }
                else
                {
                    info.Text = "Ваш вес в норме";
                }
            }
        }
예제 #8
0
        public void init()
        {
            using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
            {
                IQueryable <Diet> q = from Diet in Db.Diets select Diet;
                l = q.ToList();

                var           list  = q.Select(s => new { s.Name }).ToList();
                List <String> names = new List <string>();
                foreach (var s in list)
                {
                    String ss = s.ToString().Replace("{ Name = ", "");
                    ss = ss.Replace("}", "");
                    names.Add(ss);
                }
                ListboxDiet.ItemsSource = names;
            }
        }
 public AddProductToDish()
 {
     InitializeComponent();
     using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
     {
         IQueryable <Product> ProductQuery = from Product in Db.Products select Product;
         l = ProductQuery.ToList();
         var           list = ProductQuery.Select(s => new { s.Name }).ToList();
         List <String> ll   = new List <string>();
         foreach (var s in list)
         {
             String ss = s.ToString().Replace("{ Name = ", "");
             ss = ss.Replace("}", "");
             ll.Add(ss);
         }
         listBox4.ItemsSource = ll;
     }
 }
예제 #10
0
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
            {
                Dish d1 = new Dish(name1, d.Type, portion1, d.Measure);
                Db.Dishes.InsertOnSubmit(d1);
                Db.SubmitChanges();
                foreach (DishProduct dpr in d.DishProducts)
                {
                    dpr.DId = d1.DishID;
                    Db.DishProducts.InsertOnSubmit(dpr);
                    d1.DishProducts.Add(dpr);
                    Db.SubmitChanges();
                }

                NavigationService.Navigate(new Uri("/InfoPage.xaml", UriKind.Relative));
            }
        }
        public void init()
        {
            using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
            {
                IQueryable <Person> PersonQuery = from Person in Db.Persons where Person.Name != "" select Person;
                Person p = PersonQuery.FirstOrDefault();

                //фильтрация
                IQueryable <Product> ProductQuery = from Product in Db.Products where Product.IDType <= 3 - p.Preference select Product;
                l = ProductQuery.ToList();

                var           list  = ProductQuery.Select(s => new { s.Name }).ToList();
                List <String> names = new List <string>();
                foreach (var s in list)
                {
                    String ss = s.ToString().Replace("{ Name = ", "");
                    ss = ss.Replace("}", "");
                    names.Add(ss);
                }
                listBox1.ItemsSource = names;

                var list1 = ProductQuery.Select(s => new { s.Protein }).ToList();
                names = new List <string>();
                foreach (var s in list1)
                {
                    String ss = s.ToString().Replace("{ Protein = ", "");
                    ss = ss.Replace("}", "");
                    names.Add(ss);
                }
                listBox2.ItemsSource = names;

                var list2 = ProductQuery.Select(s => new { s.Fat }).ToList();
                names = new List <string>();
                foreach (var s in list2)
                {
                    String ss = s.ToString().Replace("{ Fat = ", "");
                    ss = ss.Replace("}", "");
                    names.Add(ss);
                }
                listBox3.ItemsSource = names;

                var list3 = ProductQuery.Select(s => new { s.Carbohydrates }).ToList();
                names = new List <string>();
                foreach (var s in list3)
                {
                    String ss = s.ToString().Replace("{ Carbohydrates = ", "");
                    ss = ss.Replace("}", "");
                    names.Add(ss);
                }
                listBox4.ItemsSource = names;

                var list4 = ProductQuery.Select(s => new { s.Calories }).ToList();
                names = new List <string>();
                foreach (var s in list4)
                {
                    String ss = s.ToString().Replace("{ Calories = ", "");
                    ss = ss.Replace("}", "");
                    names.Add(ss);
                }
                listBox5.ItemsSource = names;

                var list5 = ProductQuery.Select(s => new { s.Acidity }).ToList();
                names = new List <string>();
                foreach (var s in list5)
                {
                    String ss = s.ToString().Replace("{ Acidity = ", "");
                    ss = ss.Replace("}", "");
                    names.Add(ss);
                }
                listBox6.ItemsSource = names;
            }
        }
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            Product          s = null;
            MessageBoxResult m = MessageBox.Show("Удалить?", "", MessageBoxButton.OKCancel);

            if (m == MessageBoxResult.OK)
            {
                if (listBox1.SelectedIndex >= 0)
                {
                    s = l[listBox1.SelectedIndex];
                }
                else if (listBox3.SelectedIndex >= 0)
                {
                    s = l[listBox2.SelectedIndex];
                }
                else if (listBox3.SelectedIndex >= 0)
                {
                    s = l[listBox3.SelectedIndex];
                }
                else if (listBox4.SelectedIndex >= 0)
                {
                    s = l[listBox4.SelectedIndex];
                }
                else if (listBox5.SelectedIndex >= 0)
                {
                    s = l[listBox5.SelectedIndex];
                }
                else if (listBox6.SelectedIndex >= 0)
                {
                    s = l[listBox6.SelectedIndex];
                }
                using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
                {
                    if (s != null)
                    {
                        var s2 = from DietProduct in Db.DietProducts
                                 where DietProduct.PId == s.ProductID
                                 select DietProduct;

                        List <DietProduct> lp = s2.ToList();
                        Db.DietProducts.DeleteAllOnSubmit(lp);
                        Db.SubmitChanges();

                        var s3 = from DishProduct in Db.DishProducts
                                 where DishProduct.PId == s.ProductID
                                 select DishProduct;

                        List <DishProduct> dp = s3.ToList();
                        Db.DishProducts.DeleteAllOnSubmit(dp);
                        Db.SubmitChanges();

                        var s1 = from Product in Db.Products
                                 where Product.ProductID == s.ProductID
                                 select Product;
                        Db.Products.DeleteOnSubmit(s1.FirstOrDefault());
                        Db.SubmitChanges();
                    }
                }
                init();
            }
        }
예제 #13
0
        public void init()
        {
            using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
            {
                x = true;
                InitializeComponent();

                if (dayIdx == 0)
                {
                    day.Text = "Понедельник";
                }
                if (dayIdx == 1)
                {
                    day.Text = "Вторник";
                }
                if (dayIdx == 2)
                {
                    day.Text = "Среда";
                }
                if (dayIdx == 3)
                {
                    day.Text = "Четверг";
                }
                if (dayIdx == 4)
                {
                    day.Text = "Пятница";
                }
                if (dayIdx == 5)
                {
                    day.Text = "Суббота";
                }
                if (dayIdx == 6)
                {
                    day.Text = "Воскресенье";
                }

                IQueryable <Ration> RationQuery = from Ration in Db.Rations where Ration.DayWeek == dayIdx select Ration;
                r = RationQuery.ToList();

                var           list1 = RationQuery.Select(s => new { s.Time }).ToList();
                List <String> times = new List <string>();
                foreach (var s in list1)
                {
                    String ss = s.ToString().Replace("{ Time = ", "");
                    ss = ss.Replace("}", "");
                    times.Add(ss);
                }
                listBox1.ItemsSource = times;

                var           list2 = RationQuery.Select(s => new { s.Dish.Name }).ToList();
                List <String> names = new List <string>();
                foreach (var s in list2)
                {
                    String ss = s.ToString().Replace("{ Name = ", "");
                    ss = ss.Replace("}", "");
                    names.Add(ss);
                }
                listBox2.ItemsSource = names;

                var           list3         = RationQuery.Select(s => new { s.WeightDish, s.Dish }).ToList();
                List <String> portions      = new List <string>();
                List <String> calories      = new List <string>();
                int           totalCalories = 0;
                foreach (var s in list3)
                {
                    String ss = s.WeightDish.ToString().Replace("{ WeightDish = ", "");
                    ss = ss.Replace("}", "");
                    portions.Add(ss);
                    int calory             = 0;
                    List <DishProduct> dps = s.Dish.DishProducts.ToList();
                    foreach (DishProduct dp in dps)
                    {
                        Product p = dp.Product;
                        calory += p.Calories * dp.Quantity;
                    }
                    calory /= s.WeightDish;
                    calories.Add(calory + "");
                    totalCalories += calory;
                }
                listBox3.ItemsSource = portions;
                listBox4.ItemsSource = calories;
                total.Text           = totalCalories + "";

                IQueryable <Person> PersonQuery = from Person in Db.Persons where Person.Name != "" select Person;
                Person person         = PersonQuery.FirstOrDefault();
                double targetCalories = 0;
                if (person.Sex == "M")
                {
                    if (person.Age < 17)
                    {
                        targetCalories = 16.6 * person.Weight + 119 + 572;
                    }
                    else if (person.Age < 30)
                    {
                        targetCalories = 15.4 * person.Weight - 0.27 * person.Height + 717;
                    }
                    else if (person.Age < 60)
                    {
                        targetCalories = 11.3 * person.Weight + 0.16 * person.Height + 901;
                    }
                    else
                    {
                        targetCalories = 8.8 * person.Weight + 11.28 * person.Height - 1071;
                    }
                }
                else
                {
                    if (person.Age < 17)
                    {
                        targetCalories = 7.4 * person.Weight + 4.82 * person.Height + 217;
                    }
                    else if (person.Age < 30)
                    {
                        targetCalories = 13.3 * person.Weight + 3.34 * person.Height + 35;
                    }
                    else if (person.Age < 60)
                    {
                        targetCalories = 8.7 * person.Weight - 0.25 * person.Height + 865;
                    }
                    else
                    {
                        targetCalories = 9.2 * person.Weight + 6.37 * person.Height - 302;
                    }
                }
                textBlock4.Text = Math.Round(targetCalories, 1) + "";
                if (targetCalories * 1.1 < totalCalories)
                {
                    textBlock5.Text = "Употребляйте меньше калорий";
                }
                if (targetCalories > totalCalories * 1.1)
                {
                    textBlock5.Text = "Употребляйте больше калорий";
                }
            }
        }
예제 #14
0
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            using (MyDataContext context = new MyDataContext(strConnectionString))
            {
                if (name.Text != "" && age.Text != "" && height.Text != "" && weight.Text != "" &&
                    waist.Text != "" && hip.Text != "" && wrist.Text != "")
                {
                    p.Name               = name.Text;
                    p.Age                = Convert.ToInt32(age.Text);
                    p.Height             = Convert.ToInt32(height.Text);
                    p.Weight             = Convert.ToInt32(weight.Text);
                    p.Sex                = gender;
                    p.WaistCircumference = Convert.ToInt32(waist.Text);
                    p.HipCircumference   = Convert.ToInt32(hip.Text);
                    p.WristCircumference = Convert.ToInt32(wrist.Text);
                    p.Ration             = "";

                    //STUB!

                    /*p.Name = "Аня";
                     * p.Age = 21;
                     * p.Height = 174;
                     * p.Weight = 63;
                     * p.Sex = "F";
                     * p.WaistCircumference = 62;
                     * p.HipCircumference = 88;
                     * p.WristCircumference = 16;
                     * p.Preference = 0;*/

                    //constitution
                    if (p.WristCircumference > 18.5)
                    {
                        p.ConstitutionId = 2;
                    }
                    else if (p.WristCircumference < 16)
                    {
                        p.ConstitutionId = 0;
                    }
                    else
                    {
                        p.ConstitutionId = 1;
                    }

                    //fat percentage
                    p.PercentFat = Math.Round(((p.Weight * 1.0) / (p.Height * p.Height) * 10000), 1);

                    //bioage
                    double rl  = 0;
                    double kss = 0;
                    if (gender == "M")
                    {
                        rl  = p.Age - 21;
                        kss = (p.WaistCircumference * p.Weight) / (p.HipCircumference * p.Height * p.Height * (17.2 + 0.31 * rl + 0.0012 * rl * rl));
                    }
                    else
                    {
                        rl  = p.Age - 18;
                        kss = (p.WaistCircumference * p.Weight) / (p.HipCircumference * p.Height * p.Height * (14.7 + 0.26 * rl + 0.001 * rl * rl));
                    } double bioage = 0;
                    if (gender == "M")
                    {
                        bioage = kss * (p.Age - 18) + 18;
                    }
                    else
                    {
                        bioage = kss * (p.Age - 21) + 21;
                    }
                    p.BioAge = (int)Math.Round(bioage);

                    if (d != null)
                    {
                        IQueryable <Diet> q = from Diet in context.Diets where d.DietID == Diet.DietID select Diet;
                        d = q.FirstOrDefault();
                    }
                    if (d == null)
                    {
                        IQueryable <Diet> q = from Diet in context.Diets select Diet;
                        d = q.FirstOrDefault();
                    }
                    p.Diet = d;

                    //insert
                    context.Persons.InsertOnSubmit(p);
                    context.SubmitChanges();

                    NavigationService.Navigate(new Uri("/InfoPage.xaml", UriKind.Relative));
                }
            }
        }
예제 #15
0
        public AddDish()
        {
            InitializeComponent();
            if (a)
            {
                d = new Dish()
                {
                    Name = "", Portion = 0
                };
                d.DishProducts = new System.Data.Linq.EntitySet <DishProduct>();
                a        = false;
                name1    = "";
                portion1 = 0;
            }
            else
            {
                name.Text     = name1;
                textBox1.Text = portion1 + "";
                using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
                {
                    var           list1 = d.DishProducts.ToList();
                    var           list2 = d.DishProducts.Select(s => new { s.Quantity, s.Product.MeasureID }).ToList();
                    List <String> ll    = new List <string>();
                    foreach (var s in list2)
                    {
                        String ss = "";
                        if (s.MeasureID == 0)
                        {
                            ss = s.Quantity + " г.";
                        }
                        if (s.MeasureID == 1)
                        {
                            ss = s.Quantity + " шт.";
                        }
                        if (s.MeasureID == 2)
                        {
                            ss = s.Quantity + " мл.";
                        }
                        ll.Add(ss);
                    }
                    var           list3 = d.DishProducts.Select(s => new { s.Product.Name }).ToList();
                    List <String> list4 = new List <string>();
                    foreach (var s in list3)
                    {
                        String ss = s.ToString().Replace("{ Name = ", "");
                        ss = ss.Replace("}", "");
                        list4.Add(ss);
                    }
                    d.DishProducts.ToList();
                    lb2.ItemsSource = ll;
                    lb1.ItemsSource = list4;

                    int calory             = 0;
                    List <DishProduct> dps = d.DishProducts.ToList();
                    foreach (DishProduct dp in dps)
                    {
                        Product p = dp.Product;
                        calory += p.Calories * dp.Quantity;
                    }
                    if (d.Portion != 0)
                    {
                        calory /= d.Portion;
                    }
                    textBlock3.Text = calory + "";
                }
            }
        }
예제 #16
0
        public void init()
        {
            using (MyDataContext Db = new MyDataContext(MainPage.strConnectionString))
            {
                x = true;
                InitializeComponent();

                if (dayIdx == 0)
                {
                    day.Text = "Понедельник";
                }
                if (dayIdx == 1)
                {
                    day.Text = "Вторник";
                }
                if (dayIdx == 2)
                {
                    day.Text = "Среда";
                }
                if (dayIdx == 3)
                {
                    day.Text = "Четверг";
                }
                if (dayIdx == 4)
                {
                    day.Text = "Пятница";
                }
                if (dayIdx == 5)
                {
                    day.Text = "Суббота";
                }
                if (dayIdx == 6)
                {
                    day.Text = "Воскресенье";
                }

                IQueryable <Person> q = from Person in Db.Persons where Person.Name != "" select Person;
                Person person         = q.FirstOrDefault();

                IQueryable <Schedule> ScheduleQuery = from Schedule in Db.Schedules where Schedule.DayWeek == dayIdx select Schedule;
                l = ScheduleQuery.ToList();
                var           list     = ScheduleQuery.Select(s => new { s.Time, s.Action, s.Duration }).ToList();
                List <String> times    = new List <string>();
                List <String> actions  = new List <string>();
                List <String> calories = new List <String>();
                foreach (var s in list)
                {
                    String ss = s.Time.ToString().Replace("{ Time = ", "");
                    ss = ss.Replace("}", "");
                    times.Add(ss);
                    ss = s.Action.Name.Replace("{ Action = ", "");
                    ss = ss.Replace("}", "");
                    actions.Add(ss);
                    double d = Math.Round((s.Action.Energy * person.Weight * s.Duration) / 60, 1);
                    calories.Add(d + "");
                }
                listBox1.ItemsSource = times;
                listBox2.ItemsSource = actions;
                listBox3.ItemsSource = calories;
            }
        }
예제 #17
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            using (MyDataContext Db = new MyDataContext(strConnectionString))
            {
                //  Db.DeleteDatabase();
                if (Db.DatabaseExists() == false)
                {
                    Db.CreateDatabase();
                    //inserting in ideal parameters table

                    List <IdealParameter> ii = new List <IdealParameter>();
                    ii.Add(new IdealParameter(152.5, 155, 47.8, 49.2, "F", 0));
                    ii.Add(new IdealParameter(155, 157, 49.2, 50.8, "F", 0));
                    ii.Add(new IdealParameter(157, 160, 50.8, 52.1, "F", 0));
                    ii.Add(new IdealParameter(160, 162, 52.1, 53.8, "F", 0));
                    ii.Add(new IdealParameter(162, 165, 53.8, 55.3, "F", 0));
                    ii.Add(new IdealParameter(165, 167, 55.3, 56.6, "F", 0));
                    ii.Add(new IdealParameter(167, 170, 56.6, 57.8, "F", 0));
                    ii.Add(new IdealParameter(170, 172, 57.8, 59, "F", 0));
                    ii.Add(new IdealParameter(172, 175, 59, 60.3, "F", 0));
                    ii.Add(new IdealParameter(175, 177, 60.3, 61.5, "F", 0));
                    ii.Add(new IdealParameter(177, 180, 61.5, 62.7, "F", 0));

                    ii.Add(new IdealParameter(152.5, 155, 54, 55.2, "F", 1));
                    ii.Add(new IdealParameter(155, 157, 55.2, 57, "F", 1));
                    ii.Add(new IdealParameter(157, 160, 57, 58.5, "F", 1));
                    ii.Add(new IdealParameter(160, 162, 58.5, 60.1, "F", 1));
                    ii.Add(new IdealParameter(162, 165, 60.1, 61.8, "F", 1));
                    ii.Add(new IdealParameter(165, 167, 61.8, 63, "F", 1));
                    ii.Add(new IdealParameter(167, 170, 63, 64, "F", 1));
                    ii.Add(new IdealParameter(170, 172, 64, 65.2, "F", 1));
                    ii.Add(new IdealParameter(172, 175, 65.2, 66.5, "F", 1));
                    ii.Add(new IdealParameter(175, 177, 61.5, 67.7, "F", 1));
                    ii.Add(new IdealParameter(177, 180, 62.7, 68.9, "F", 1));

                    ii.Add(new IdealParameter(152.5, 155, 59, 61.6, "F", 2));
                    ii.Add(new IdealParameter(155, 157, 61.6, 63.1, "F", 2));
                    ii.Add(new IdealParameter(157, 160, 63.1, 64.8, "F", 2));
                    ii.Add(new IdealParameter(160, 162, 64.8, 66.3, "F", 2));
                    ii.Add(new IdealParameter(162, 165, 66.3, 67.8, "F", 2));
                    ii.Add(new IdealParameter(165, 167, 67.8, 69, "F", 2));
                    ii.Add(new IdealParameter(167, 170, 69, 70, "F", 2));
                    ii.Add(new IdealParameter(170, 172, 70, 71.2, "F", 2));
                    ii.Add(new IdealParameter(172, 175, 71.2, 72.5, "F", 2));
                    ii.Add(new IdealParameter(175, 177, 72.5, 73.3, "F", 2));
                    ii.Add(new IdealParameter(177, 180, 73.3, 74.9, "F", 2));

                    ii.Add(new IdealParameter(155, 157.5, 49.3, 51.7, "M", 0));
                    ii.Add(new IdealParameter(157.5, 160, 51.7, 53.5, "M", 0));
                    ii.Add(new IdealParameter(160, 162.5, 53.5, 55.3, "M", 0));
                    ii.Add(new IdealParameter(162.5, 165, 55.3, 57.1, "M", 0));
                    ii.Add(new IdealParameter(165, 167.5, 57.1, 59.3, "M", 0));
                    ii.Add(new IdealParameter(167.5, 170, 59.3, 60.5, "M", 0));
                    ii.Add(new IdealParameter(170, 172, 60.5, 63.3, "M", 0));
                    ii.Add(new IdealParameter(172, 175, 63.3, 63.3, "M", 0));
                    ii.Add(new IdealParameter(175, 177.5, 63.3, 67.3, "M", 0));
                    ii.Add(new IdealParameter(177.5, 180, 67.3, 68.9, "M", 0));
                    ii.Add(new IdealParameter(180, 182.5, 68.9, 70.9, "M", 0));
                    ii.Add(new IdealParameter(182.5, 185, 70.9, 72.8, "M", 0));

                    ii.Add(new IdealParameter(155, 157.5, 56, 58, "M", 1));
                    ii.Add(new IdealParameter(157.5, 160, 58, 60, "M", 1));
                    ii.Add(new IdealParameter(160, 162.5, 60, 61.7, "M", 1));
                    ii.Add(new IdealParameter(162.5, 165, 61.7, 63.5, "M", 1));
                    ii.Add(new IdealParameter(165, 167.5, 63.5, 65.8, "M", 1));
                    ii.Add(new IdealParameter(167.5, 170, 65.8, 67.8, "M", 1));
                    ii.Add(new IdealParameter(170, 172, 67.8, 69.7, "M", 1));
                    ii.Add(new IdealParameter(172, 175, 69.7, 71.7, "M", 1));
                    ii.Add(new IdealParameter(175, 177.5, 71.7, 73.8, "M", 1));
                    ii.Add(new IdealParameter(177.5, 180, 73.8, 75.2, "M", 1));
                    ii.Add(new IdealParameter(180, 182.5, 75.2, 77.2, "M", 1));
                    ii.Add(new IdealParameter(182.5, 185, 77.2, 79.2, "M", 1));

                    ii.Add(new IdealParameter(155, 157.5, 62.2, 64, "M", 2));
                    ii.Add(new IdealParameter(157.5, 160, 64, 66, "M", 2));
                    ii.Add(new IdealParameter(160, 162.5, 66, 68, "M", 2));
                    ii.Add(new IdealParameter(162.5, 165, 68, 69.5, "M", 2));
                    ii.Add(new IdealParameter(165, 167.5, 69.5, 71.8, "M", 2));
                    ii.Add(new IdealParameter(167.5, 170, 71.8, 73.8, "M", 2));
                    ii.Add(new IdealParameter(170, 172, 73.8, 76.8, "M", 2));
                    ii.Add(new IdealParameter(172, 175, 76.8, 77.8, "M", 2));
                    ii.Add(new IdealParameter(175, 177.5, 77.8, 79.8, "M", 2));
                    ii.Add(new IdealParameter(177.5, 180, 79.8, 81.2, "M", 2));
                    ii.Add(new IdealParameter(180, 182.5, 81.2, 83.6, "M", 2));
                    ii.Add(new IdealParameter(182.5, 185, 83.6, 85.2, "M", 2));

                    Db.IdealParameters.InsertAllOnSubmit(ii);
                    Db.SubmitChanges();

                    List <Product> products = new List <Product>();
                    Product        p1       = new Product("Баклажаны", 0, 1.2, 0.1, 7.1, 24, 0, 15.1, 0);
                    products.Add(p1);
                    Product p2 = new Product("Морковь", 0, 1.3, 0.1, 9.3, 34, 0, 15.1, 0);
                    products.Add(p2);
                    Product p3 = new Product("Огурцы свежие", 0, 0.8, 0.1, 3.8, 14, 0, 13.5, 0);
                    products.Add(p3);
                    Product p4 = new Product("Салат", 0, 1.5, 0.2, 3.1, 17, 0, 14.2, 0);
                    products.Add(p4);
                    Product p5 = new Product("Шампиньоны", 0, 4.3, 1, 1, 27, 0, 3.5, 0);
                    products.Add(p5);
                    Product p6 = new Product("Творог нежирный", 2, 18, 0.6, 1.8, 88, 0, 1.7, 0);
                    products.Add(p6);
                    Product p7 = new Product("Свинина", 3, 14.3, 33, 0, 357, 0, 12.47, 0);
                    products.Add(p7);
                    Product p8 = new Product("Говядина", 3, 18.6, 16, 0, 218, 0, 38.61, 0);
                    products.Add(p8);
                    Product p9 = new Product("Филе куриное", 3, 23.6, 1.9, 0.4, 113, 0, 24.32, 0);
                    products.Add(p9);
                    Product p10 = new Product("Яйцо куриное", 1, 12.7, 11.5, 0.7, 157, 0, 11.16, 1);
                    products.Add(p10);
                    Product p11 = new Product("Масло оливковое", 1, 0, 99.8, 0, 898, 0, 6.1, 2);
                    products.Add(p10);

                    Db.Products.InsertAllOnSubmit(products);
                    Db.SubmitChanges();

                    Dish d1 = new Dish("Салат овощной", 0, 200, 0);
                    Db.Dishes.InsertOnSubmit(d1);
                    Db.SubmitChanges();
                    DishProduct dp = new DishProduct()
                    {
                        DId = d1.DishID, Product = p2, Quantity = 100
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d1.DishProducts.Add(dp);
                    dp = new DishProduct()
                    {
                        DId = d1.DishID, Product = p3, Quantity = 100
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d1.DishProducts.Add(dp);
                    dp = new DishProduct()
                    {
                        DId = d1.DishID, Product = p4, Quantity = 100
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d1.DishProducts.Add(dp);
                    dp = new DishProduct()
                    {
                        DId = d1.DishID, Product = p11, Quantity = 20
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d1.DishProducts.Add(dp);
                    Db.SubmitChanges();

                    Dish d2 = new Dish("Рагу овощное", 1, 200, 0);
                    Db.Dishes.InsertOnSubmit(d2);
                    Db.SubmitChanges();
                    dp = new DishProduct()
                    {
                        DId = d2.DishID, Product = p1, Quantity = 200
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d2.DishProducts.Add(dp);
                    dp = new DishProduct()
                    {
                        DId = d2.DishID, Product = p2, Quantity = 300
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d2.DishProducts.Add(dp);
                    dp = new DishProduct()
                    {
                        DId = d2.DishID, Product = p11, Quantity = 20
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d2.DishProducts.Add(dp);
                    Db.SubmitChanges();

                    Dish d3 = new Dish("Рагу мясное", 3, 200, 0);
                    Db.Dishes.InsertOnSubmit(d3);
                    Db.SubmitChanges();
                    dp = new DishProduct()
                    {
                        DId = d3.DishID, Product = p2, Quantity = 200
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d3.DishProducts.Add(dp);
                    dp = new DishProduct()
                    {
                        DId = d3.DishID, Product = p5, Quantity = 150
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d3.DishProducts.Add(dp);
                    dp = new DishProduct()
                    {
                        DId = d3.DishID, Product = p8, Quantity = 100
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d3.DishProducts.Add(dp);
                    dp = new DishProduct()
                    {
                        DId = d3.DishID, Product = p11, Quantity = 30
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d3.DishProducts.Add(dp);
                    Db.SubmitChanges();

                    Dish d4 = new Dish("Салат с курицей", 3, 150, 0);
                    Db.Dishes.InsertOnSubmit(d4);
                    Db.SubmitChanges();
                    dp = new DishProduct()
                    {
                        DId = d4.DishID, Product = p4, Quantity = 200
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d4.DishProducts.Add(dp);
                    dp = new DishProduct()
                    {
                        DId = d4.DishID, Product = p5, Quantity = 100
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d4.DishProducts.Add(dp);
                    dp = new DishProduct()
                    {
                        DId = d4.DishID, Product = p9, Quantity = 100
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d4.DishProducts.Add(dp);
                    dp = new DishProduct()
                    {
                        DId = d4.DishID, Product = p11, Quantity = 10
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d4.DishProducts.Add(dp);
                    Db.SubmitChanges();

                    Dish d5 = new Dish("Котлеты морковные", 1, 80, 0);
                    Db.Dishes.InsertOnSubmit(d5);
                    Db.SubmitChanges();
                    dp = new DishProduct()
                    {
                        DId = d5.DishID, Product = p2, Quantity = 300
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d5.DishProducts.Add(dp);
                    dp = new DishProduct()
                    {
                        DId = d5.DishID, Product = p10, Quantity = 20
                    };
                    Db.DishProducts.InsertOnSubmit(dp);
                    d5.DishProducts.Add(dp);
                    Db.SubmitChanges();

                    List <Ration> r = new List <Ration>();
                    r.Add(new Ration {
                        Time = "9:00", DayWeek = 0, WeightDish = 80, Dish = d5
                    });
                    r.Add(new Ration {
                        Time = "9:00", DayWeek = 0, WeightDish = 100, Dish = d1
                    });
                    r.Add(new Ration {
                        Time = "12:00", DayWeek = 0, WeightDish = 150, Dish = d3
                    });
                    r.Add(new Ration {
                        Time = "12:00", DayWeek = 0, WeightDish = 80, Dish = d5
                    });
                    r.Add(new Ration {
                        Time = "18:00", DayWeek = 0, WeightDish = 200, Dish = d4
                    });

                    r.Add(new Ration {
                        Time = "9:00", DayWeek = 1, WeightDish = 80, Dish = d5
                    });
                    r.Add(new Ration {
                        Time = "9:00", DayWeek = 1, WeightDish = 150, Dish = d2
                    });
                    r.Add(new Ration {
                        Time = "12:00", DayWeek = 1, WeightDish = 100, Dish = d4
                    });
                    r.Add(new Ration {
                        Time = "12:00", DayWeek = 1, WeightDish = 80, Dish = d5
                    });
                    r.Add(new Ration {
                        Time = "18:00", DayWeek = 1, WeightDish = 200, Dish = d1
                    });

                    r.Add(new Ration {
                        Time = "9:00", DayWeek = 2, WeightDish = 100, Dish = d1
                    });
                    r.Add(new Ration {
                        Time = "9:00", DayWeek = 2, WeightDish = 150, Dish = d3
                    });
                    r.Add(new Ration {
                        Time = "12:00", DayWeek = 2, WeightDish = 100, Dish = d4
                    });
                    r.Add(new Ration {
                        Time = "12:00", DayWeek = 2, WeightDish = 100, Dish = d2
                    });
                    r.Add(new Ration {
                        Time = "18:00", DayWeek = 2, WeightDish = 100, Dish = d1
                    });
                    r.Add(new Ration {
                        Time = "18:00", DayWeek = 2, WeightDish = 80, Dish = d5
                    });
                    Db.Rations.InsertAllOnSubmit(r);
                    Db.SubmitChanges();

                    List <DietApp_.Action> a  = new List <DietApp_.Action>();
                    DietApp_.Action        a1 = new DietApp_.Action {
                        Name = "Бег", Energy = 8.14
                    };
                    DietApp_.Action a2 = new DietApp_.Action {
                        Name = "Ходьба", Energy = 3.08
                    };
                    DietApp_.Action a3 = new DietApp_.Action {
                        Name = "Плавание", Energy = 8.8
                    };
                    DietApp_.Action a4 = new DietApp_.Action {
                        Name = "Теннис", Energy = 6.16
                    };
                    DietApp_.Action a5 = new DietApp_.Action {
                        Name = "Катание на коньках", Energy = 4.62
                    };
                    DietApp_.Action a6 = new DietApp_.Action {
                        Name = "Настольный теннис", Energy = 5.5
                    };
                    DietApp_.Action a7 = new DietApp_.Action {
                        Name = "Езда на велосипеде", Energy = 3.52
                    };
                    a.Add(a1);
                    a.Add(a2);
                    a.Add(a3);
                    a.Add(a4);
                    a.Add(a5);
                    a.Add(a6);
                    a.Add(a7);
                    Db.Actions.InsertAllOnSubmit(a);
                    Db.SubmitChanges();

                    Schedule s = new Schedule {
                        DayWeek = 0, Time = "10:00", Action = a2, Duration = 30
                    };
                    Db.Schedules.InsertOnSubmit(s);
                    Db.SubmitChanges();
                    s.Action = a2;
                    Db.SubmitChanges();

                    s = new Schedule {
                        DayWeek = 0, Time = "06:00", Action = a1, Duration = 25
                    };
                    Db.Schedules.InsertOnSubmit(s);
                    Db.SubmitChanges();
                    s.Action = a1;
                    Db.SubmitChanges();

                    s = new Schedule {
                        DayWeek = 1, Time = "06:00", Action = a1, Duration = 30
                    };
                    Db.Schedules.InsertOnSubmit(s);
                    Db.SubmitChanges();
                    s.Action = a1;
                    Db.SubmitChanges();

                    s = new Schedule {
                        DayWeek = 1, Time = "11:00", Action = a7, Duration = 60
                    };
                    Db.Schedules.InsertOnSubmit(s);
                    Db.SubmitChanges();
                    s.Action = a7;
                    Db.SubmitChanges();

                    s = new Schedule {
                        DayWeek = 2, Time = "19:00", Action = a3, Duration = 45
                    };
                    Db.Schedules.InsertOnSubmit(s);
                    Db.SubmitChanges();
                    s.Action = a3;
                    Db.SubmitChanges();

                    s = new Schedule {
                        DayWeek = 2, Time = "15:00", Action = a4, Duration = 30
                    };
                    Db.Schedules.InsertOnSubmit(s);
                    Db.SubmitChanges();
                    s.Action = a3;
                    Db.SubmitChanges();

                    List <Product> l = new List <Product>();

                    Diet diet1 = new Diet("Без диеты", 0);
                    d = diet1;
                    Db.Diets.InsertOnSubmit(diet1);
                    Db.SubmitChanges();

                    Diet diet2 = new Diet("Диета №1", 30);
                    Db.Diets.InsertOnSubmit(diet2);
                    Db.SubmitChanges();
                    DietProduct dpr = new DietProduct {
                        DId = diet2.DietID, Product = p1
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p2
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p3
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p4
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p5
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p6
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p9
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p10
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p11
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    diet2.DietProducts.Add(dpr);
                    Db.SubmitChanges();

                    diet2 = new Diet("Диета №2", 60);
                    Db.Diets.InsertOnSubmit(diet2);
                    Db.SubmitChanges();
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p1
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p2
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p3
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p4
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p5
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p6
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p7
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p9
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p11
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    diet2.DietProducts.Add(dpr);
                    Db.SubmitChanges();

                    diet2 = new Diet("Диета №3", 30);
                    Db.Diets.InsertOnSubmit(diet2);
                    Db.SubmitChanges();
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p1
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p2
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p3
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p4
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p5
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p6
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p7
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p8
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    dpr = new DietProduct {
                        DId = diet2.DietID, Product = p9
                    };
                    Db.DietProducts.InsertOnSubmit(dpr);
                    diet2.DietProducts.Add(dpr);
                    Db.SubmitChanges();

                    MessageBox.Show("База данных успешно создана.");
                }

                name.Text   = Name1;
                age.Text    = Age1;
                height.Text = Height1;
                weight.Text = Weight1;
                waist.Text  = WaistCircumference1;
                hip.Text    = HipCircumference1;
                wrist.Text  = WristCircumference1;
                if (gender == "M")
                {
                    radioButton1.IsChecked = true;
                    sex.IsChecked          = false;
                }
                else
                {
                    sex.IsChecked = true; radioButton1.IsChecked = false;
                }

                IQueryable <Person> PersonQuery = Db.Persons.Select(v => v);
                p = PersonQuery.FirstOrDefault();
                if (p == null)
                {
                    p = new Person();
                    IQueryable <Diet> q = from Diet in Db.Diets select Diet;
                    p.Diet = d;
                    d      = q.FirstOrDefault();
                    Db.Persons.InsertOnSubmit(p);
                    Db.SubmitChanges();
                    preference.Text = preference_;
                    p.Diet          = d;
                    diet.Text       = d.Name;
                }
            }
        }