示例#1
0
 private void Login_btn_Click(object sender, RoutedEventArgs e)
 {
     //if its login page validate the username and password
     if (signup_btn1.Content.Equals("Login"))
     {
         string UserNam  = Properties.Settings.Default.UserName;
         string Password = Properties.Settings.Default.Password;
         string u_name   = UserName.Text;
         string password = pass.Password;
         //show the phonebook page if valid details
         if (UserNam.Equals(u_name) && Password.Equals(password))
         {
             PhoneBook pb = new PhoneBook();
             pb.Show();
             this.Hide();
         }
         else
         {
             //throw error if invalid details
             MessageBox.Show("Please Enter valid username and password", "Wrong Password", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     //if its signup page set the setting of app to save the details of signup information
     else
     {
         string u_name   = UserName.Text;
         string password = pass.Password;
         //if the passwords match save the details
         if (password.Equals(rpass.Password))
         {
             Properties.Settings.Default.UserName = u_name;
             Properties.Settings.Default.Password = password;
             Properties.Settings.Default.Save();
             this.Hide();
             MainWindow mw = new MainWindow();
             mw.Show();
         }
         else
         {
             //if password do not match in two fields throw error
             MessageBox.Show("Password MisMatch ", "Password Error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }