Exemplo n.º 1
0
        private void label13_Click(object sender, EventArgs e)
        {
            AdminHomePage adminhomepage = new AdminHomePage();

            this.Hide();
            adminhomepage.Closed += (s, args) => this.Close();
            adminhomepage.Show();
        }
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            Con.Close();
            String Username = txtUsername.Text;
            String Password = GetEncryptionMd5.MD5Process(txtPassword.Password.Trim());

            Cmd = new SqlCommand("Select * From tblUsers Where EmailId='" + Username + "' " +
                                 "or ContactNumber='" + Username + "' and Password='******' ", Con);
            Con.Open();
            SqlDataReader DR;

            DR = Cmd.ExecuteReader();

            if (DR.HasRows)
            {
                DR.Read();
                if ((Username == DR.GetValue(3).ToString() && Password == DR.GetValue(6).ToString()) ||
                    (Username == DR.GetValue(4).ToString() && Password == DR.GetValue(6).ToString())
                    )
                {
                    txtUsername.Text       = "Email Or Contact No.";
                    txtUsername.Foreground = Brushes.DarkGray;
                    txtPassword.Password   = "";
                    string Role = "A=Admin, L= Librarian";
                    Role = DR.GetValue(5).ToString().Trim();

                    if (Role == "A" || Role == "a" || Role == "L" || Role == "l")
                    {
                        //User Is Admin
                        AdminHomePage adminHomePage = new AdminHomePage(int.Parse(DR.GetValue(0).ToString()), DR.GetValue(3).ToString());
                        adminHomePage.Show();
                        this.Close();
                    }
                    else
                    {
                        return;
                    }
                    lblInvalid.Visibility = Visibility.Hidden;
                }
                else
                {
                    lblInvalid.Visibility = Visibility.Visible;
                    lblInvalid.Content    = "Invalid Password!";
                    txtPassword.Password  = "";
                }
            }
            else
            {
                //User Does Not Exists!
                lblInvalid.Content     = "User Does Not Exists!";
                lblInvalid.Visibility  = Visibility.Visible;
                txtUsername.Text       = "Email Or Contact No.";
                txtUsername.Foreground = Brushes.DarkGray;
                txtPassword.Password   = "";
            }
        }