Esempio n. 1
0
        private void button_logout_Click(object sender, EventArgs e)
        {
            this.Hide();
            Menu_after_admin_login f1 = new Menu_after_admin_login();

            f1.ShowDialog();
            this.Close();
        }
        private void password_txt_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == Convert.ToChar(Keys.Return))
            {
                try
                {
                    string myConnection = "Server= (local)\\SQLEXPRESS; Database= Connection;User ID=sa;Password=p@ssword13";


                    SqlConnection myConn = new SqlConnection(myConnection);

                    SqlCommand    SelectCommand = new SqlCommand("Select *from login where Username COLLATE Latin1_General_CS_AS ='" + this.username_txt.Text + "'and Pass COLLATE Latin1_General_CS_AS='" + this.password_txt.Text + "';", myConn);
                    SqlDataReader myReader;
                    myConn.Open();
                    myReader = SelectCommand.ExecuteReader();
                    int count = 0;
                    while (myReader.Read())
                    {
                        count = count + 1;
                    }
                    if (count == 1)
                    {
                        MessageBox.Show("Username and Password are correct");
                        this.Hide();
                        Menu_after_admin_login f2 = new Menu_after_admin_login();
                        f2.ShowDialog();
                        this.Close();
                    }

                    else
                    {
                        MessageBox.Show("Username and password are not correct");
                    }
                    myConn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }