Exemple #1
0
        private void txtPassword_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    string query = "select User_Name from users where User_Name=@Name and Password=@Pass and (User_Type=0 or User_Type=1)";
                    conn.Open();
                    MySqlCommand comand = new MySqlCommand(query, conn);
                    comand.Parameters.AddWithValue("@Name", txtName.Text);
                    comand.Parameters.AddWithValue("@Pass", txtPassword.Text);
                    var result = comand.ExecuteScalar();
                    conn.Close();

                    if (result != null)
                    {
                        CarsMainForm f = new CarsMainForm();
                        f.Show();
                        this.Hide();
                    }
                    else
                    {
                        txtPassword.Focus();
                        MessageBox.Show("Enter correct password");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                string query = "select User_ID,User_Name from users where User_Name=@Name and Password=@Pass and (User_Type=0 or User_Type=1)";
                conn.Open();
                MySqlCommand comand = new MySqlCommand(query, conn);
                comand.Parameters.AddWithValue("@Name", txtName.Text);
                comand.Parameters.AddWithValue("@Pass", txtPassword.Text);
                MySqlDataReader result = comand.ExecuteReader();


                if (result != null)
                {
                    while (result.Read())
                    {
                        UserControl.userID   = (int)result[0];
                        UserControl.userName = result[1].ToString();

                        CarsMainForm f = new CarsMainForm();
                        f.Show();
                    }

                    this.Hide();
                }
                else
                {
                    MessageBox.Show("please try again");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            conn.Close();
        }