Exemple #1
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            if (textBoxUsername.Text == "" || textBoxPassword.Text == "")
            {
                MessageBox.Show("Please provide Username and Password");
                return;
            }

            try
            {
                SqlConnection con = new SqlConnection(cs);
                SqlCommand    cmd = new SqlCommand("Select * from Users where Username=@username and Password=@password", con);
                cmd.Parameters.AddWithValue("@username", textBoxUsername.Text);
                cmd.Parameters.AddWithValue("@password", textBoxPassword.Text);
                con.Open();
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataSet        ds    = new DataSet();
                adapt.Fill(ds);
                con.Close();
                int count = ds.Tables[0].Rows.Count;
                if (count == 1)
                {
                    MessageBox.Show("Login Successful!");
                    this.Hide();
                    OrderList orderList = new OrderList();
                    orderList.Show();
                }
                else
                {
                    MessageBox.Show("Login Failed!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private void btnBack_Click(object sender, EventArgs e)
 {
     this.Hide();
     orderListForm.Show();
 }