public void Execute(object parameter)
 {
     this.execute(parameter);
     using (BD_KURSACH_Entities db = new BD_KURSACH_Entities())
     {
         try
         {
             Random value  = new Random();
             int    number = value.Next(0, 100);
             var    groups = db.Group.ToList();
             Found : foreach (var g in groups)
             {
                 if (g.Number_Group == number)
                 {
                     number = value.Next(0, 100000);
                     goto Found;
                 }
             }
             Trainer trainer = WorkTrainerWindowViewModel.trainer;
             Group   group   = new Group();
             group.Number_Group = number;
             group.Id_Trainer   = trainer.id;
             db.Group.Add(group);
             db.SaveChanges();
             MessageBox.Show("группа создана, но в ней никто не участвует добавьте клиентов");
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Beispiel #2
0
 public void Execute(object parameter)
 {
     this.execute(parameter);
     using (BD_KURSACH_Entities db = new BD_KURSACH_Entities())
     {
         try
         {
             Client  client  = new Client();
             var     clients = db.Client.ToList();
             TextBox text    = (TextBox)parameter;
             foreach (var c in clients)
             {
                 if (c.id.ToString() == text.Text)
                 {
                     client = c;
                 }
             }
             Trainer trainer = WorkTrainerWindowViewModel.trainer;
             client.Number_Group    = trainer.Number_Group;
             db.Entry(client).State = EntityState.Modified;
             db.SaveChanges();
             MessageBox.Show($"клиент добавлен в группу под номером {client.Number_Group}");
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
        public void Execute(object parameter)
        {
            this.execute(parameter);
            using (BD_KURSACH_Entities db = new BD_KURSACH_Entities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        Random  value    = new Random();
                        Trainer trainer1 = (Trainer)parameter;
                        int     rand     = value.Next(0, 100000);
                        var     trainers = db.Trainer.ToList();
Found:
                        foreach (var c in trainers)
                        {
                            if (c.id == rand)
                            {
                                rand = value.Next(0, 100000);
                                goto Found;
                            }
                        }
                        foreach (var c in trainers)
                        {
                            if (c.Login == trainer1.Login)
                            {
                                throw new Exception("Такой логин уже используется");
                            }
                        }
                        if (trainer1.DataTrainer.BarbellSquat < trainer1.DataTrainer.Weight * 1.4 && trainer1.DataTrainer.Deadlift < trainer1.DataTrainer.Weight * 1.8 &&
                            trainer1.DataTrainer.BenchPress < trainer1.DataTrainer.Weight * 1.2 && trainer1.DataTrainer.Pullups < 10)
                        {
                            throw new Exception("Вы слабоваты для тренера");
                        }
                        trainer1.id = rand;
                        db.DataTrainer.Add(trainer1.DataTrainer);
                        db.Trainer.Add(trainer1);
                        db.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("значения введены неверно, перепроверьте пожалуйсто");
                        transaction.Rollback();
                    }
                }
            }
        }
        public void Execute(object parameter)
        {
            this.execute(parameter);
            using (BD_KURSACH_Entities db = new BD_KURSACH_Entities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        Random value   = new Random();
                        Client client1 = (Client)parameter;
                        int    rand    = value.Next(0, 100000);
                        var    clients = db.Client.ToList();
Found:
                        foreach (var c in clients)
                        {
                            if (c.id == rand)
                            {
                                rand = value.Next(0, 100000);
                                goto Found;
                            }
                        }
                        foreach (var c in clients)
                        {
                            if (c.Login == client1.Login)
                            {
                                throw new Exception("Такой логин уже используется");
                            }
                        }
                        client1.id = rand;
                        List <ExercisesForClient> lol = GenerateExercises(parameter);
                        db.Client.Add(client1);
                        db.DataClient.Add(client1.DataClient);
                        db.ExercisesForClient.AddRange(lol);
                        db.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        transaction.Rollback();
                    }
                }
            }
        }
        public void Execute(object parameter)
        {
            using (BD_KURSACH_Entities db = new BD_KURSACH_Entities())
            {
                try
                {
                    int     num     = 0;
                    var     clients = db.Client.ToList();
                    TextBox text    = (TextBox)parameter;
                    var     exer    = db.ExercisesForClient.Where(i => i.Id_client.ToString() == text.Text).ToList();

                    exer.ElementAt(num).First_Day  = WindowOfViews.EditUser.FirstDayFirstExercise.Text;
                    exer.ElementAt(num).Second_Day = WindowOfViews.EditUser.SecondDayFirstExercise.Text;
                    exer.ElementAt(num).Third_Day  = WindowOfViews.EditUser.ThirdDayFirstExercise.Text;
                    num++;
                    exer.ElementAt(num).First_Day  = WindowOfViews.EditUser.FirstDaySecondExercise.Text;
                    exer.ElementAt(num).Second_Day = WindowOfViews.EditUser.SecondDaySecondExercise.Text;
                    exer.ElementAt(num).Third_Day  = WindowOfViews.EditUser.ThirdDaySecondExercise.Text;
                    num++;
                    exer.ElementAt(num).First_Day  = WindowOfViews.EditUser.FirstDayThirdExercise.Text;
                    exer.ElementAt(num).Second_Day = WindowOfViews.EditUser.SecondDayThirdExercise.Text;
                    exer.ElementAt(num).Third_Day  = WindowOfViews.EditUser.ThirdDayThirdExercise.Text;
                    num++;
                    exer.ElementAt(num).First_Day  = WindowOfViews.EditUser.FirstDayFourthExercise.Text;
                    exer.ElementAt(num).Second_Day = WindowOfViews.EditUser.SecondDayFourthExercise.Text;
                    exer.ElementAt(num).Third_Day  = WindowOfViews.EditUser.ThirdDayFourthExercise.Text;
                    num++;
                    exer.ElementAt(num).First_Day  = WindowOfViews.EditUser.FirstDayFifthExercise.Text;
                    exer.ElementAt(num).Second_Day = WindowOfViews.EditUser.SecondDayFifthExercise.Text;
                    exer.ElementAt(num).Third_Day  = WindowOfViews.EditUser.ThirdDayFifthExercise.Text;
                    num++;
                    exer.ElementAt(num).First_Day  = WindowOfViews.EditUser.FirstDaySixthExercise.Text;
                    exer.ElementAt(num).Second_Day = WindowOfViews.EditUser.SecondDaySixthExercise.Text;
                    exer.ElementAt(num).Third_Day  = WindowOfViews.EditUser.ThirdDaySixthExercise.Text;
                    db.SaveChanges();
                    MessageBox.Show("изменения прошли успешно");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #6
0
 public void Execute(object parameter)
 {
     using (BD_KURSACH_Entities db = new BD_KURSACH_Entities())
     {
         try
         {
             Messages messages = new Messages();
             Random   value    = new Random();
             messages.id_Message    = value.Next(0, 10000000);
             messages.Who_sender    = WorkTrainerWindowViewModel.trainer.id;
             messages.Who_recipient = int.Parse(WindowOfViews.ChatTrainer.comboBox.Text);
             messages.messages1     = WindowOfViews.ChatTrainer.messageText.Text;
             messages.Date          = DateTime.Now;
             db.Messages.Add(messages);
             db.SaveChanges();
             ChatTrainerViewModel.lol.ChoiseClient = messages.Who_recipient.ToString();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
 public void Execute(object parameter)
 {
     using (BD_KURSACH_Entities db = new BD_KURSACH_Entities())
     {
         try
         {
             WorkUserWindowViewModel.client.FirstName                  = WindowOfViews.EditDataUser.FirstName.Text;
             WorkUserWindowViewModel.client.SecondName                 = WindowOfViews.EditDataUser.SecondName.Text;
             WorkUserWindowViewModel.client.Login                      = WindowOfViews.EditDataUser.Login.Text;
             WorkUserWindowViewModel.client.Password                   = WindowOfViews.EditDataUser.Password.Text;
             WorkUserWindowViewModel.client.DataClient.Weight          = int.Parse(WindowOfViews.EditDataUser.Weight.Text);
             WorkUserWindowViewModel.client.DataClient.Height          = int.Parse(WindowOfViews.EditDataUser.Height.Text);
             WorkUserWindowViewModel.client.DataClient.Bodytype        = WindowOfViews.EditDataUser.BodyType.Text;
             db.Entry(WorkUserWindowViewModel.client).State            = EntityState.Modified;
             db.Entry(WorkUserWindowViewModel.client.DataClient).State = EntityState.Modified;
             db.SaveChanges();
             MessageBox.Show("изменения прошли успешно");
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Beispiel #8
0
        private static double GetProgress()
        {
            double progress11 = 1;
            double progress12 = 1;
            double progress13 = 1;
            double progress21 = 1;
            double progress22 = 1;
            double progress23 = 1;
            int    crossexer  = 0;
            double progress   = 0;

            using (BD_KURSACH_Entities db = new BD_KURSACH_Entities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    var exer = db.ResultExercises.Where(i => i.Id_Client == WorkUserWindowViewModel.client.id).ToList();
                    if (exer.Count() != 0)
                    {
                        try
                        {
                            var sortedexer = from u in exer
                                             orderby u.Date descending
                                             select u;
                            if (sortedexer.FirstOrDefault().First_Day_Quantity != "" && sortedexer.FirstOrDefault().Second_Day_Quantity != "" && sortedexer.FirstOrDefault().Third_Day_Quantity != "")
                            {
                                crossexer = 6;
                            }
                            if (sortedexer.FirstOrDefault().First_Day_Quantity == "" || sortedexer.FirstOrDefault().Second_Day_Quantity == "" || sortedexer.FirstOrDefault().Third_Day_Quantity == "")
                            {
                                crossexer = 12;
                            }

                            if (sortedexer.FirstOrDefault().First_Day_Quantity != "" && sortedexer.FirstOrDefault().Second_Day_Quantity == "" && sortedexer.FirstOrDefault().Third_Day_Quantity == "")
                            {
                                crossexer += 6;
                            }
                            if (sortedexer.FirstOrDefault().First_Day_Quantity == "" && sortedexer.FirstOrDefault().Second_Day_Quantity != "" && sortedexer.FirstOrDefault().Third_Day_Quantity == "")
                            {
                                crossexer += 6;
                            }
                            if (sortedexer.FirstOrDefault().First_Day_Quantity == "" && sortedexer.FirstOrDefault().Second_Day_Quantity == "" && sortedexer.FirstOrDefault().Third_Day_Quantity != "")
                            {
                                crossexer += 6;
                            }

                            for (int i = 0; i < crossexer; i++)
                            {
                                if (sortedexer.ElementAt(i).First_Day_Quantity != "")
                                {
                                    if (sortedexer.ElementAt(i).First_Day_Weight != "" && sortedexer.ElementAt(i).First_Day_Quantity != "")
                                    {
                                        progress11 = int.Parse(sortedexer.ElementAt(i).First_Day_Weight);
                                        progress11 = progress11 * int.Parse(sortedexer.ElementAt(i).First_Day_Quantity) * 0.8;
                                    }
                                    if (sortedexer.ElementAt(i).First_Day_Weight == "" && sortedexer.ElementAt(i).First_Day_Quantity != "")
                                    {
                                        progress11 = int.Parse(sortedexer.ElementAt(i).First_Day_Quantity) * 10;
                                    }
                                }
                                if (sortedexer.ElementAt(i).Second_Day_Quantity != "")
                                {
                                    if (sortedexer.ElementAt(i).Second_Day_Weight != "" && sortedexer.ElementAt(i).Second_Day_Quantity != "")
                                    {
                                        progress12 = int.Parse(sortedexer.ElementAt(i).Second_Day_Weight);
                                        progress12 = progress12 * int.Parse(sortedexer.ElementAt(i).Second_Day_Quantity) * 0.8;
                                    }
                                    if (sortedexer.ElementAt(i).Second_Day_Weight == "" && sortedexer.ElementAt(i).Second_Day_Quantity != "")
                                    {
                                        progress12 = int.Parse(sortedexer.ElementAt(i).Second_Day_Quantity) * 10;
                                    }
                                }
                                if (sortedexer.ElementAt(i).Third_Day_Quantity != "")
                                {
                                    if (sortedexer.ElementAt(i).Third_Day_Weight != "" && sortedexer.ElementAt(i).Third_Day_Quantity != "")
                                    {
                                        progress13 = int.Parse(sortedexer.ElementAt(i).Third_Day_Weight);
                                        progress13 = progress13 * int.Parse(sortedexer.ElementAt(i).Third_Day_Quantity) * 0.8;
                                    }
                                    if (sortedexer.ElementAt(i).Third_Day_Weight == "" && sortedexer.ElementAt(i).Third_Day_Quantity != "")
                                    {
                                        progress13 = int.Parse(sortedexer.ElementAt(i).Third_Day_Quantity) * 10;
                                    }
                                }
                            }
                            //--------------------------------------------------------------------------------------------------------------------
                            for (int k = sortedexer.Count() - crossexer; k < sortedexer.Count(); k++)
                            {
                                if (sortedexer.ElementAt(k).First_Day_Quantity != "")
                                {
                                    if (sortedexer.ElementAt(k).First_Day_Weight != "" && sortedexer.ElementAt(k).First_Day_Quantity != "")
                                    {
                                        progress21 = int.Parse(sortedexer.ElementAt(k).First_Day_Weight);
                                        progress21 = progress21 * int.Parse(sortedexer.ElementAt(k).First_Day_Quantity) * 0.8;
                                    }
                                    if (sortedexer.ElementAt(k).First_Day_Weight == "" && sortedexer.ElementAt(k).First_Day_Quantity != "")
                                    {
                                        progress21 = int.Parse(sortedexer.ElementAt(k).First_Day_Quantity) * 10;
                                    }
                                }
                                if (sortedexer.ElementAt(k).Second_Day_Quantity != "")
                                {
                                    if (sortedexer.ElementAt(k).Second_Day_Weight != "" && sortedexer.ElementAt(k).Second_Day_Quantity != "")
                                    {
                                        progress22 = int.Parse(sortedexer.ElementAt(k).Second_Day_Weight);
                                        progress22 = progress22 * int.Parse(sortedexer.ElementAt(k).Second_Day_Quantity) * 0.8;
                                    }
                                    if (sortedexer.ElementAt(k).Second_Day_Weight == "" && sortedexer.ElementAt(k).Second_Day_Quantity != "")
                                    {
                                        progress22 = int.Parse(sortedexer.ElementAt(k).Second_Day_Quantity) * 10;
                                    }
                                }
                                if (sortedexer.ElementAt(k).Third_Day_Quantity != "")
                                {
                                    if (sortedexer.ElementAt(k).Third_Day_Weight != "" && sortedexer.ElementAt(k).Third_Day_Quantity != "")
                                    {
                                        progress23 = int.Parse(sortedexer.ElementAt(k).Third_Day_Weight);
                                        progress23 = progress23 * int.Parse(sortedexer.ElementAt(k).Third_Day_Quantity) * 0.8;
                                    }
                                    if (sortedexer.ElementAt(k).Third_Day_Weight == "" && sortedexer.ElementAt(k).Third_Day_Quantity != "")
                                    {
                                        progress23 = int.Parse(sortedexer.ElementAt(k).Third_Day_Quantity) * 10;
                                    }
                                }
                            }

                            if (progress21 != 1 && progress22 != 1 && progress23 != 1)
                            {
                                progress = (progress21 + progress22 + progress23) / (progress11 + progress12 + progress13);
                            }
                            if (progress21 == 1)
                            {
                                progress = (double)client.DataClient.Progress * (progress21 / progress11);
                            }
                            if (progress22 == 1)
                            {
                                progress = (double)client.DataClient.Progress * (progress22 / progress12);
                            }
                            if (progress23 == 1)
                            {
                                progress = (double)client.DataClient.Progress * (progress23 / progress13);
                            }
                            client.DataClient.Progress        = Math.Round(progress, 2);
                            db.Entry(client.DataClient).State = EntityState.Modified;
                            db.SaveChanges();
                            transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                            transaction.Rollback();
                        }
                    }
                }
            }
            return(Math.Round(progress, 2));
        }
 public void Execute(object parameter)
 {
     using (BD_KURSACH_Entities db = new BD_KURSACH_Entities())
     {
         try
         {
             List <ResultExercises> listresult = new List <ResultExercises>();
             var    exer = db.ExercisesForClient.Where(i => i.Id_client == WorkUserWindowViewModel.client.id).ToList();
             int    num;
             Random value = new Random();
             for (num = 0; num < exer.Count; num++)
             {
                 listresult.Add(new ResultExercises());
                 listresult.ElementAt(num).First_Day  = exer.ElementAt(num).First_Day;
                 listresult.ElementAt(num).Second_Day = exer.ElementAt(num).Second_Day;
                 listresult.ElementAt(num).Third_Day  = exer.ElementAt(num).Third_Day;
                 listresult.ElementAt(num).number     = value.Next(0, 1000000);
                 listresult.ElementAt(num).Id_Client  = exer.ElementAt(num).Id_client;
                 listresult.ElementAt(num).Date       = DateTime.Now;
             }
             num = 0;
             listresult.ElementAt(num).First_Day_Weight    = WindowOfViews.AddResult.FirstDay1_Copy.Text;
             listresult.ElementAt(num).First_Day_Quantity  = WindowOfViews.AddResult.FirstDay1.Text;
             listresult.ElementAt(num).Second_Day_Weight   = WindowOfViews.AddResult.SecondDay1_Copy.Text;
             listresult.ElementAt(num).Second_Day_Quantity = WindowOfViews.AddResult.SecondDay1.Text;
             listresult.ElementAt(num).Third_Day_Weight    = WindowOfViews.AddResult.ThirdDay1_Copy.Text;
             listresult.ElementAt(num).Third_Day_Quantity  = WindowOfViews.AddResult.ThirdDay1.Text;
             num++;
             listresult.ElementAt(num).First_Day_Weight    = WindowOfViews.AddResult.FirstDay2_Copy.Text;
             listresult.ElementAt(num).First_Day_Quantity  = WindowOfViews.AddResult.FirstDay2.Text;
             listresult.ElementAt(num).Second_Day_Weight   = WindowOfViews.AddResult.SecondDay2_Copy.Text;
             listresult.ElementAt(num).Second_Day_Quantity = WindowOfViews.AddResult.SecondDay2.Text;
             listresult.ElementAt(num).Third_Day_Weight    = WindowOfViews.AddResult.ThirdDay2.Text;
             listresult.ElementAt(num).Third_Day_Quantity  = WindowOfViews.AddResult.ThirdDay2.Text;
             num++;
             listresult.ElementAt(num).First_Day_Weight    = WindowOfViews.AddResult.FirstDay3_Copy.Text;
             listresult.ElementAt(num).First_Day_Quantity  = WindowOfViews.AddResult.FirstDay3.Text;
             listresult.ElementAt(num).Second_Day_Weight   = WindowOfViews.AddResult.SecondDay3_Copy.Text;
             listresult.ElementAt(num).Second_Day_Quantity = WindowOfViews.AddResult.SecondDay3.Text;
             listresult.ElementAt(num).Third_Day_Weight    = WindowOfViews.AddResult.ThirdDay3_Copy.Text;
             listresult.ElementAt(num).Third_Day_Quantity  = WindowOfViews.AddResult.ThirdDay3.Text;
             num++;
             listresult.ElementAt(num).First_Day_Weight    = WindowOfViews.AddResult.FirstDay4_Copy.Text;
             listresult.ElementAt(num).First_Day_Quantity  = WindowOfViews.AddResult.FirstDay4.Text;
             listresult.ElementAt(num).Second_Day_Weight   = WindowOfViews.AddResult.SecondDay4_Copy.Text;
             listresult.ElementAt(num).Second_Day_Quantity = WindowOfViews.AddResult.SecondDay4.Text;
             listresult.ElementAt(num).Third_Day_Weight    = WindowOfViews.AddResult.ThirdDay4_Copy.Text;
             listresult.ElementAt(num).Third_Day_Quantity  = WindowOfViews.AddResult.ThirdDay4.Text;
             num++;
             listresult.ElementAt(num).First_Day_Weight    = WindowOfViews.AddResult.FirstDay5_Copy.Text;
             listresult.ElementAt(num).First_Day_Quantity  = WindowOfViews.AddResult.FirstDay5.Text;
             listresult.ElementAt(num).Second_Day_Weight   = WindowOfViews.AddResult.SecondDay5_Copy.Text;
             listresult.ElementAt(num).Second_Day_Quantity = WindowOfViews.AddResult.SecondDay5.Text;
             listresult.ElementAt(num).Third_Day_Weight    = WindowOfViews.AddResult.ThirdDay5_Copy.Text;
             listresult.ElementAt(num).Third_Day_Quantity  = WindowOfViews.AddResult.ThirdDay5.Text;
             num++;
             listresult.ElementAt(num).First_Day_Weight    = WindowOfViews.AddResult.FirstDay6_Copy.Text;
             listresult.ElementAt(num).First_Day_Quantity  = WindowOfViews.AddResult.FirstDay6.Text;
             listresult.ElementAt(num).Second_Day_Weight   = WindowOfViews.AddResult.SecondDay6_Copy.Text;
             listresult.ElementAt(num).Second_Day_Quantity = WindowOfViews.AddResult.SecondDay6.Text;
             listresult.ElementAt(num).Third_Day_Weight    = WindowOfViews.AddResult.ThirdDay6_Copy.Text;
             listresult.ElementAt(num).Third_Day_Quantity  = (WindowOfViews.AddResult.ThirdDay6.Text);
             num++;
             bool fics = false;
             int  k;
             for (int i = 0; i < exer.Count; i++)
             {
                 if (listresult.ElementAt(i).First_Day_Weight != "" && !int.TryParse(listresult.ElementAt(i).First_Day_Weight, out k))
                 {
                     fics = true;
                 }
                 if (listresult.ElementAt(i).First_Day_Quantity != "" && !int.TryParse(listresult.ElementAt(i).First_Day_Quantity, out k))
                 {
                     fics = true;
                 }
                 if (listresult.ElementAt(i).Second_Day_Weight != "" && !int.TryParse(listresult.ElementAt(i).Second_Day_Weight, out k))
                 {
                     fics = true;
                 }
                 if (listresult.ElementAt(i).Second_Day_Quantity != "" && !int.TryParse(listresult.ElementAt(i).Second_Day_Quantity, out k))
                 {
                     fics = true;
                 }
                 if (listresult.ElementAt(i).Third_Day_Weight != "" && !int.TryParse(listresult.ElementAt(i).Third_Day_Weight, out k))
                 {
                     fics = true;
                 }
                 if (listresult.ElementAt(i).Third_Day_Quantity != "" && !int.TryParse(listresult.ElementAt(i).Third_Day_Quantity, out k))
                 {
                     fics = true;
                 }
             }
             if (fics == true)
             {
                 throw new Exception("неверно введено значение");
             }
             if (fics == false)
             {
                 db.ResultExercises.AddRange(listresult);
                 db.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }