Ejemplo n.º 1
0
 private void Add_admin(object sender, RoutedEventArgs e)
 {
     if (AddLogin.Text.Length > 0)
     {
         db = new KursachEntities();
         db.Admins.Load();;
         foreach (Admin i in db.Admins)
         {
             if (AddLogin.Text == i.Login)
             {
                 MessageBox.Show("This login is busy, pls pressed another login");
             }
         }
         if (AddPassword.Password.Length > 0)
         {
             Admin admin = new Admin {
                 Login = AddLogin.Text, Password = AddPassword.Password
             };
             db.Admins.Add(admin);
             db.SaveChanges();
         }
         else
         {
             MessageBox.Show("You dont pressed password");
         }
     }
     else
     {
         MessageBox.Show("You dont pressed login");
     }
 }
 public InfoAboutUser()
 {
     InitializeComponent();
     db = new KursachEntities();
     db.UsersToTopics.Load();
     UserInfoDg.ItemsSource = db.UsersToTopics.Local.ToBindingList();
 }
Ejemplo n.º 3
0
 public BanUser()
 {
     InitializeComponent();
     db = new KursachEntities();
     db.Users.Load();
     UserBanDg.ItemsSource = db.Users.Local.ToBindingList();
 }
Ejemplo n.º 4
0
 public Legs(string str)
 {
     _str = str;
     InitializeComponent();
     db = new KursachEntities();
     db.Topics.Load();
     LegsDg.ItemsSource = db.Topics.Local.ToBindingList().Where(x => x.Topic1 == "Legs");
 }
Ejemplo n.º 5
0
 public Legs()
 {
     InitializeComponent();
     db = new KursachEntities();
     db.Topics.Load();
     LegsDg.ItemsSource = db.Topics.Local.ToBindingList().Where(x => x.Topic1 == "Legs");
     Delete.Visibility  = Visibility.Hidden;
     Refresh.Visibility = Visibility.Hidden;
 }
Ejemplo n.º 6
0
        public void Add_Click(object sender, RoutedEventArgs e)
        {
            db = new KursachEntities();
            Topic topic = new Topic {
                Topic1 = Topic.Text, Level = Convert.ToInt32(Levels.Text), Image = FilePath, Content = new TextRange(Content1.Document.ContentStart, Content1.Document.ContentEnd).Text
            };

            db.Topics.Add(topic);
            db.SaveChanges();
        }
Ejemplo n.º 7
0
 public Legs(int _id)
 {
     a = _id;
     InitializeComponent();
     db = new KursachEntities();
     db.Topics.Load();
     LegsDg.ItemsSource = db.Topics.Local.ToBindingList().Where(x => x.Topic1 == "Legs");
     Levels.IsReadOnly  = true;
     Content.IsReadOnly = true;
     Photo.IsReadOnly   = true;
     Delete.Visibility  = Visibility.Hidden;
     Refresh.Visibility = Visibility.Hidden;
 }
 private void Auth_Click(object sender, RoutedEventArgs e)
 {
     if (AuthLogin.Text.Length > 0)            // проверяем введён ли логин
     {
         if (AuthPassword.Password.Length > 0) // проверяем введён ли пароль
         {
             KursachEntities kursachEntities = new KursachEntities();
             kursachEntities.Users.Load();
             kursachEntities.Admins.Load();
             BindingList <User>  ts     = kursachEntities.Users.Local.ToBindingList();
             BindingList <Admin> admins = kursachEntities.Admins.Local.ToBindingList();
             int a = 0;
             foreach (var i in admins)
             {
                 if (i.Login == AuthLogin.Text && i.Password == AuthPassword.Password)
                 {
                     MainWindow mainWindow = new MainWindow(i.Login);
                     mainWindow.Show();
                     this.Close();
                     a++;
                     break;
                 }
             }
             foreach (var i in ts)
             {
                 string vs = GetHash(AuthPassword.Password);
                 if (i.Login == AuthLogin.Text && i.Password == vs)
                 {
                     MainWindow mainWindow = new MainWindow(i.Id);
                     mainWindow.Show();
                     this.Close();
                     a++;
                     break;
                 }
             }
             if (a == 0)
             {
                 MessageBox.Show("Пользователь не найден");
             }
         }
         else
         {
             MessageBox.Show("Введите пароль");  // выводим ошибку
         }
     }
     else
     {
         MessageBox.Show("Введите логин");  // выводим ошибку
     }
 }
Ejemplo n.º 9
0
 private void Subscribe_Click(object sender, RoutedEventArgs e)
 {
     if (a > 0)
     {
         using (KursachEntities db = new KursachEntities())
         {
             UsersToTopic user1 = new UsersToTopic {
                 UserId = a, TopicNumber = ((Topic)LegsDg.SelectedItem).NumberOfTopic
             };
             db.UsersToTopics.Add(user1);
             db.SaveChanges();
         }
     }
 }
Ejemplo n.º 10
0
        public MyWorkouts(int _id)
        {
            db = new KursachEntities();
            InitializeComponent();
            a = _id;
            db.UsersToTopics.Load();
            db.Topics.Load();
            BindingList <UsersToTopic> usersTos = db.UsersToTopics.Local.ToBindingList();
            BindingList <Topic>        topics   = new BindingList <Topic>();

            foreach (var i in db.UsersToTopics.Where(x => x.UserId == a))
            {
                topics.Add(db.Topics.Where(y => y.NumberOfTopic == i.TopicNumber).First());
            }
            MyWorkoutsDG.ItemsSource = topics;
        }
Ejemplo n.º 11
0
 private void Reg_Click(object sender, RoutedEventArgs e)
 {
     if (RegLogin.Text.Length > 0)                    // проверяем логин
     {
         if (RegPassword.Password.Length > 0)         // проверяем пароль
         {
             if (RegCopyPassword.Password.Length > 0) // проверяем второй пароль
             {
                 if (RegPassword.Password == RegCopyPassword.Password)
                 {
                     using (KursachEntities db = new KursachEntities())
                     {
                         string vs    = GetHash(RegPassword.Password);
                         User   user1 = new User {
                             Login = RegLogin.Text, Password = vs
                         };
                         db.Users.Add(user1);
                         db.SaveChanges();
                         MainWindow mainWindow = new MainWindow(user1.Id);
                         mainWindow.Show();
                         this.Close();
                     }
                 }
                 else
                 {
                     MessageBox.Show("Пароли не совподают");
                 }
             }
             else
             {
                 MessageBox.Show("Повторите пароль");
             }
         }
         else
         {
             MessageBox.Show("Укажите пароль");
         }
     }
     else
     {
         MessageBox.Show("Укажите логин");
     }
 }
Ejemplo n.º 12
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            db = new KursachEntities();
            db.Topics.Load();
            db.UsersToTopics.Load();
            Topic topic       = LegsDg.SelectedItem as Topic;
            int   numbers     = 0;
            var   userToTopic = db.Topics;

            foreach (Topic i in userToTopic.Where(x => x.NumberOfTopic == ((Topic)LegsDg.SelectedItem).NumberOfTopic))
            {
                numbers = (int)i.NumberOfTopic;
            }
            int number = db.Database.ExecuteSqlCommand($"Delete from UsersToTopic Where TopicNumber={numbers}");

            if (topic != null)
            {
                int b = db.Database.ExecuteSqlCommand($"Delete from Topic Where NumberOfTopic={numbers}");
            }
        }
Ejemplo n.º 13
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            db = new KursachEntities();
            db.Users.Load();
            db.UsersToTopics.Load();
            User user        = UserBanDg.SelectedItem as User;
            var  userToTopic = db.Users;
            int  id          = 0;

            foreach (User i in userToTopic.Where(x => x.Id == ((User)UserBanDg.SelectedItem).Id))
            {
                id = (int)i.Id;
            }
            int number = db.Database.ExecuteSqlCommand($"Delete from UsersToTopic Where UserId={id}");

            if (user != null)
            {
                int b = db.Database.ExecuteSqlCommand($"Delete from Users Where Id={id}");
            }
            db.Users.Load();
            UserBanDg.ItemsSource = db.Users.Local.ToBindingList();
        }
Ejemplo n.º 14
0
        private void IsDone_Click(object sender, RoutedEventArgs e)
        {
            var result = MessageBox.Show("Вы закончили тренировку?", "Qustion", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                UsersToTopic usersToTopic = new UsersToTopic {
                    UserId = a, TopicNumber = ((Topic)MyWorkoutsDG.SelectedItem).NumberOfTopic
                };
                if (usersToTopic != null)
                {
                    var maxLevel = db.Topics;
                    int maxlevel = 0;
                    foreach (Topic i in maxLevel.Where(y => y.Topic1 == ((Topic)MyWorkoutsDG.SelectedItem).Topic1 && y.Level > ((Topic)MyWorkoutsDG.SelectedItem).Level))
                    {
                        if (maxlevel < i.Level)
                        {
                            maxlevel = (int)i.Level;
                        }
                    }
                    if (maxlevel > ((Topic)MyWorkoutsDG.SelectedItem).Level)
                    {
                        var result2 = MessageBox.Show("Не хотели бы приступить к следующему уровну?", "Qustion", MessageBoxButton.YesNo, MessageBoxImage.Question);
                        if (result2 == MessageBoxResult.Yes)
                        {
                            int topicasd     = 0;
                            var _topicNumber = db.Topics;
                            int d            = 0;
                            foreach (Topic i in _topicNumber.Where(y => y.Topic1 == ((Topic)MyWorkoutsDG.SelectedItem).Topic1 && y.Level > ((Topic)MyWorkoutsDG.SelectedItem).Level))
                            {
                                if (d == 0)
                                {
                                    d++;
                                    topicasd = i.NumberOfTopic;
                                }
                                else if (d > 0)
                                {
                                    break;
                                }
                            }
                            db.UsersToTopics.Remove(db.UsersToTopics.Where(x => x.UserId == a && x.TopicNumber == ((Topic)MyWorkoutsDG.SelectedItem).NumberOfTopic).First());
                            db.SaveChanges();
                            BindingList <Topic> topics7 = new BindingList <Topic>();
                            foreach (var i in db.UsersToTopics.Where(x => x.UserId == a))
                            {
                                topics7.Add(db.Topics.Where(y => y.NumberOfTopic == i.TopicNumber).First());
                            }
                            MyWorkoutsDG.ItemsSource = topics7;
                            UsersToTopic user1 = new UsersToTopic {
                                UserId = a, TopicNumber = topicasd
                            };
                            db.UsersToTopics.Add(user1);
                            db.SaveChanges();
                            BindingList <Topic> topics1 = new BindingList <Topic>();

                            foreach (var i in db.UsersToTopics.Where(x => x.UserId == a))
                            {
                                topics1.Add(db.Topics.Where(y => y.NumberOfTopic == i.TopicNumber).First());
                            }
                            MyWorkoutsDG.ItemsSource = topics1;
                        }
                        else
                        {
                            var result4 = MessageBox.Show("Хотите остаться на данном уровне?", "Qustion", MessageBoxButton.YesNo, MessageBoxImage.Question);
                            if (result4 == MessageBoxResult.No)
                            {
                                BindingList <Topic> topics1 = new BindingList <Topic>();
                                foreach (var i in db.UsersToTopics.Where(x => x.UserId == a))
                                {
                                    topics1.Add(db.Topics.Where(y => y.NumberOfTopic == i.TopicNumber).First());
                                }
                                MyWorkoutsDG.ItemsSource = topics1;
                                db = new KursachEntities();
                                var minLevel = db.Topics;
                                int minlevel = 123123;
                                foreach (Topic i in minLevel.Where(y => y.Topic1 == ((Topic)MyWorkoutsDG.SelectedItem).Topic1 && y.Level < ((Topic)MyWorkoutsDG.SelectedItem).Level))
                                {
                                    if (minlevel > i.Level)
                                    {
                                        minlevel = (int)i.Level;
                                    }
                                }
                                if (minlevel < ((Topic)MyWorkoutsDG.SelectedItem).Level)
                                {
                                    var result5 = MessageBox.Show("Хотите перейти на предыдущий уровень?", "Qustion", MessageBoxButton.YesNo, MessageBoxImage.Question);
                                    if (result5 == MessageBoxResult.Yes)
                                    {
                                        int topicasd     = 0;
                                        var _topicNumber = db.Topics;
                                        int d            = 0;
                                        foreach (Topic i in _topicNumber.Where(y => y.Topic1 == ((Topic)MyWorkoutsDG.SelectedItem).Topic1 && y.Level < ((Topic)MyWorkoutsDG.SelectedItem).Level))
                                        {
                                            if (d == 0)
                                            {
                                                d++;
                                                topicasd = i.NumberOfTopic;
                                            }
                                            else if (d > 0)
                                            {
                                                break;
                                            }
                                        }
                                        db.UsersToTopics.Remove(db.UsersToTopics.Where(x => x.UserId == a && x.TopicNumber == ((Topic)MyWorkoutsDG.SelectedItem).NumberOfTopic).First());
                                        db.SaveChanges();
                                        UsersToTopic user1 = new UsersToTopic {
                                            UserId = a, TopicNumber = topicasd
                                        };
                                        db.UsersToTopics.Add(user1);
                                        db.SaveChanges();
                                        BindingList <Topic> topics6 = new BindingList <Topic>();
                                        foreach (var i in db.UsersToTopics.Where(x => x.UserId == a))
                                        {
                                            topics6.Add(db.Topics.Where(y => y.NumberOfTopic == i.TopicNumber).First());
                                        }
                                        MyWorkoutsDG.ItemsSource = topics6;
                                    }
                                    else
                                    {
                                        db.UsersToTopics.Remove(db.UsersToTopics.Where(x => x.UserId == a && x.TopicNumber == ((Topic)MyWorkoutsDG.SelectedItem).NumberOfTopic).First());
                                        db.SaveChanges();
                                        BindingList <Topic> topics6 = new BindingList <Topic>();
                                        foreach (var i in db.UsersToTopics.Where(x => x.UserId == a))
                                        {
                                            topics1.Add(db.Topics.Where(y => y.NumberOfTopic == i.TopicNumber).First());
                                        }
                                        MyWorkoutsDG.ItemsSource = topics6;
                                    }
                                }
                                else
                                {
                                    var result8 = MessageBox.Show("Простите ниже этого уровня нету, повторяем?", "Qustion", MessageBoxButton.YesNo, MessageBoxImage.Question);
                                    if (result8 == MessageBoxResult.No)
                                    {
                                        db.UsersToTopics.Remove(db.UsersToTopics.Where(x => x.UserId == a && x.TopicNumber == ((Topic)MyWorkoutsDG.SelectedItem).NumberOfTopic).First());
                                        db.SaveChanges();
                                        BindingList <Topic> topics6 = new BindingList <Topic>();
                                        foreach (var i in db.UsersToTopics.Where(x => x.UserId == a))
                                        {
                                            topics1.Add(db.Topics.Where(y => y.NumberOfTopic == i.TopicNumber).First());
                                        }
                                        MyWorkoutsDG.ItemsSource = topics6;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        var result2 = MessageBox.Show("Не хочешь повторить что сделал?", "Qustion", MessageBoxButton.YesNo, MessageBoxImage.Question);
                        if (result2 == MessageBoxResult.Yes)
                        {
                            BindingList <Topic> topics1 = new BindingList <Topic>();
                            foreach (var i in db.UsersToTopics.Where(x => x.UserId == a))
                            {
                                topics1.Add(db.Topics.Where(y => y.NumberOfTopic == i.TopicNumber).First());
                            }
                            MyWorkoutsDG.ItemsSource = topics1;
                        }
                        else
                        {
                            db.UsersToTopics.Remove(db.UsersToTopics.Where(x => x.UserId == a && x.TopicNumber == ((Topic)MyWorkoutsDG.SelectedItem).NumberOfTopic).First());
                            db.SaveChanges();
                            BindingList <Topic> topics4 = new BindingList <Topic>();
                            foreach (var i in db.UsersToTopics.Where(x => x.UserId == a))
                            {
                                topics4.Add(db.Topics.Where(y => y.NumberOfTopic == i.TopicNumber).First());
                            }
                            MyWorkoutsDG.ItemsSource = topics4;
                        }
                    }
                }
                BindingList <Topic> topics = new BindingList <Topic>();
                foreach (var i in db.UsersToTopics.Where(x => x.UserId == a))
                {
                    topics.Add(db.Topics.Where(y => y.NumberOfTopic == i.TopicNumber).First());
                }
                MyWorkoutsDG.ItemsSource = topics;
            }
            else
            {
                var result3 = MessageBox.Show("Хотите отменить тренировку?", "Qustion", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result3 == MessageBoxResult.Yes)
                {
                    db.UsersToTopics.Remove(db.UsersToTopics.Where(x => x.UserId == a && x.TopicNumber == ((Topic)MyWorkoutsDG.SelectedItem).NumberOfTopic).First());
                    db.SaveChanges();
                    BindingList <Topic> topics = new BindingList <Topic>();
                    foreach (var i in db.UsersToTopics.Where(x => x.UserId == a))
                    {
                        topics.Add(db.Topics.Where(y => y.NumberOfTopic == i.TopicNumber).First());
                    }
                    MyWorkoutsDG.ItemsSource = topics;
                }
                else
                {
                    var minLevel = db.Topics;
                    int minlevel = 123123;
                    foreach (Topic i in minLevel.Where(y => y.Topic1 == ((Topic)MyWorkoutsDG.SelectedItem).Topic1 && y.Level < ((Topic)MyWorkoutsDG.SelectedItem).Level))
                    {
                        if (minlevel > i.Level)
                        {
                            minlevel = (int)i.Level;
                        }
                    }
                    if (minlevel < ((Topic)MyWorkoutsDG.SelectedItem).Level)
                    {
                        var result9 = MessageBox.Show("Хотите вернуться на предыдущий уровень?", "Qustion", MessageBoxButton.YesNo, MessageBoxImage.Question);
                        if (result9 == MessageBoxResult.Yes)
                        {
                            int topicasd     = 0;
                            var _topicNumber = db.Topics;
                            int d            = 0;
                            foreach (Topic i in _topicNumber.Where(y => y.Topic1 == ((Topic)MyWorkoutsDG.SelectedItem).Topic1 && y.Level < ((Topic)MyWorkoutsDG.SelectedItem).Level))
                            {
                                if (d == 0)
                                {
                                    d++;
                                    topicasd = i.NumberOfTopic;
                                }
                                else if (d > 0)
                                {
                                    break;
                                }
                            }
                            db.UsersToTopics.Remove(db.UsersToTopics.Where(x => x.UserId == a && x.TopicNumber == ((Topic)MyWorkoutsDG.SelectedItem).NumberOfTopic).First());
                            db.SaveChanges();
                            UsersToTopic user1 = new UsersToTopic {
                                UserId = a, TopicNumber = topicasd
                            };
                            db.UsersToTopics.Add(user1);
                            db.SaveChanges();
                            BindingList <Topic> topics10 = new BindingList <Topic>();
                            foreach (var i in db.UsersToTopics.Where(x => x.UserId == a))
                            {
                                topics10.Add(db.Topics.Where(y => y.NumberOfTopic == i.TopicNumber).First());
                            }
                            MyWorkoutsDG.ItemsSource = topics10;
                        }
                    }
                    else
                    {
                        db.UsersToTopics.Remove(db.UsersToTopics.Where(x => x.UserId == a && x.TopicNumber == ((Topic)MyWorkoutsDG.SelectedItem).NumberOfTopic).First());
                        db.SaveChanges();
                        BindingList <Topic> topics10 = new BindingList <Topic>();
                        foreach (var i in db.UsersToTopics.Where(x => x.UserId == a))
                        {
                            topics10.Add(db.Topics.Where(y => y.NumberOfTopic == i.TopicNumber).First());
                        }
                        MyWorkoutsDG.ItemsSource = topics10;
                    }
                }
            }
        }