Пример #1
0
        private static Boolean userlogin(string username, string password, Boolean whilestate)
        {
            if (username == "")
            {
                MessageBox.Show("Mohon isi username anda");
            }
            else if (password == "")
            {
                MessageBox.Show("Mohon isi password anda");
            }
            else
            {
                string        connstring = cmethod.GetConnString();
                SqlConnection conn       = new SqlConnection(connstring);

                string query = "SELECT * FROM Userdata ";
                try
                {
                    conn.Open();
                    SqlCommand    cmd = new SqlCommand(query, conn);
                    SqlDataReader dr  = cmd.ExecuteReader();

                    while (dr.Read())
                    {
                        if (username == dr["Username"].ToString() && password == dr["Password"].ToString())
                        {
                            if (dr["Level_Access"].ToString() == "1")
                            {
                                HomepageAdmin homeadmin = new HomepageAdmin(username);

                                whilestate = true;

                                homeadmin.Show();
                                break;
                            }
                            else if (dr["Level_Access"].ToString() == "2")
                            {
                                Homepage homeuser = new Homepage(username);

                                whilestate = true;

                                homeuser.Show();
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    conn.Close();
                }
            }
            return(whilestate);
        }
Пример #2
0
        private void txbusername_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (txbusername.Text == "")
                {
                    MessageBox.Show("Mohon isi username anda");
                }
                else if (txbpassword.Text == "")
                {
                    MessageBox.Show("Mohon isi password anda");
                }
                else
                {
                    string        connstring = @"Data Source=MICHELLE;Initial Catalog=ProjectMfy;Integrated Security=True";
                    SqlConnection conn       = new SqlConnection(connstring);

                    string query = "SELECT * FROM Userdata ";
                    try
                    {
                        conn.Open();
                        SqlCommand    cmd = new SqlCommand(query, conn);
                        SqlDataReader dr  = cmd.ExecuteReader();

                        while (dr.Read())
                        {
                            if (txbusername.Text == dr["Username"].ToString() && txbpassword.Text == dr["Password"].ToString())
                            {
                                if (dr["Level_Access"].ToString() == "1")
                                {
                                    HomepageAdmin homeadmin = new HomepageAdmin(txbusername.Text);
                                    this.Hide();
                                    homeadmin.Show();
                                    break;
                                }
                                else if (dr["Level_Access"].ToString() == "2")
                                {
                                    Homepage homeuser = new Homepage(txbusername.Text);
                                    this.Hide();
                                    homeuser.Show();
                                    break;
                                }
                            }
                            else if (txbusername.Text != dr["Username"].ToString())
                            {
                                MessageBox.Show("Username atau Password yang anda masukkan salah");
                                txbusername.Clear();
                                txbpassword.Clear();
                                break;
                            }
                            else if (txbpassword.Text != dr["Password"].ToString())
                            {
                                MessageBox.Show("Username atau Password yang anda masukkan salah");
                                txbusername.Clear();
                                txbpassword.Clear();
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
        }