private void bk_Click(object sender, EventArgs e)
 {
     if (gar == 2)
     {
         dept d = new dept();
         d.Show();
         this.Hide();
     }
     else if (gar == 4)
     {
         select d = new select();
         d.Show();
         this.Hide();
     }
 }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (!(usertxt.Text == string.Empty))
                {
                    if (!(passtxt.Text == string.Empty))
                    {
                        String str = "Server=.;Database=store1;Trusted_Connection=True;";

                        String query = "select * from login where uname = '" + usertxt.Text + "'and pass = '******'";

                        SqlConnection con = new SqlConnection(str);

                        SqlCommand cmd = new SqlCommand(query, con);

                        SqlDataReader dbr;

                        con.Open();

                        dbr = cmd.ExecuteReader();

                        int count = 0;

                        while (dbr.Read())
                        {
                            count = count + 1;
                        }

                        if (count == 1)
                        {
                            login obj = new login();

                            select dmain = new select();
                            dmain.Show(); //after login Redirect to second window
                            this.Hide();  //after login hide the  Login window
                        }

                        else if (count > 1)
                        {
                            MessageBox.Show("Duplicate username and password", "login page");
                        }

                        else
                        {
                            MessageBox.Show(" username and password incorrect", "login page");
                        }
                    }

                    else
                    {
                        MessageBox.Show(" password empty", "login page");
                    }
                }
                else
                {
                    MessageBox.Show(" username empty", "login page");
                }

                // con.Close();
            }

            catch (Exception es)
            {
                MessageBox.Show(es.Message);
            }
        }