Beispiel #1
0
 private void LogIn_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         mess.Text = string.Empty;
         if (InLogin.Text == string.Empty || InPass.Password == string.Empty)
         {
             mess.Text = "Введите логин и пароль.";
             return;
         }
         bool enter = false;
         if (InLogin.Text == NoDbName && InPass.Password == NoDbPass)
         {
             enter        = true;
             InLogin.Text = string.Empty;
         }
         else
         {
             using (DUser db = new DUser())
             {
                 foreach (Users item in db.Users)
                 {
                     if (item.name == InLogin.Text && item.pass == InPass.Password)
                     {
                         enter = true;
                     }
                 }
             }
         }
         if (enter)
         {
             path += InLogin.Text + "/";
             ftp.GetDirectory(ip, path, ref cont);
             UserName.Content           = InLogin.Text;
             InLogin.Text               = string.Empty;
             InPass.Password            = string.Empty;
             this.LogOut.Visibility     = Visibility.Visible;
             StartWindow.Visibility     = Visibility.Collapsed;
             UserName.Visibility        = Visibility.Visible;
             NavigationPanel.Visibility = Visibility.Visible;
             fileInfo.Visibility        = Visibility.Visible;
             ImageLeftCorner.Visibility = Visibility.Visible;
         }
         else
         {
             mess.Text = "Пользователь не найден";
         }
     }
     catch (Exception q)
     {
         InLogin.Text    = string.Empty;
         InPass.Password = string.Empty;
         MessageBox.Show(q.Message);
     }
 }
Beispiel #2
0
        private void ToRegister_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (Login.Text != String.Empty && Pass1.Password != String.Empty && Pass2.Password != String.Empty)
                {
                    if (Pass1.Password == Pass2.Password)
                    {
                        using (DUser db = new DUser())
                        {
                            var users = db.Users;
                            if (users.Count() > 0)
                            {
                                foreach (Users item in users)
                                {
                                    if (item.name == Login.Text)
                                    {
                                        MessageBox.Show("Пользователь с таким именем уже существует.", "Ошибка");
                                        return;
                                    }
                                }
                            }
                            db.Users.Add(new Users {
                                name = Login.Text, pass = Pass1.Password
                            });

                            db.SaveChanges();
                        }
                        ftp.CreateDir(ip, "", Login.Text);
                        MessageBox.Show("Добро пожаловать " + Login.Text);
                        Login.Text                    = string.Empty;
                        Pass1.Password                = string.Empty;
                        Pass2.Password                = string.Empty;
                        StartWindow.Visibility        = Visibility.Visible;
                        RegistrationWindow.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        mess.Text = "Пароли должны совпадать!";
                    }
                }
                else
                {
                    mess.Text = "Все поля должны быть заполнены!";
                }
            }
            catch (Exception q)
            {
                MessageBox.Show(q.Message);
            }
        }