Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0)
            {
                bool isSuccess = login("admin");
                Console.WriteLine(isSuccess);
                if (isSuccess == true)
                {
                    FormAdmin admin = new FormAdmin();
                    this.Hide();
                    admin.whoLogin(txtUsername.Text);
                    admin.Show();
                }
                else
                {
                    MessageBox.Show("Faild! Username or Password wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }


            else if (comboBox1.SelectedIndex == 1)
            {
                bool isSuccess = login("doctor");
                if (isSuccess == true)
                {
                    FormDoctor doctor = new FormDoctor();
                    this.Hide();
                    doctor.whoLogin(txtUsername.Text);
                    doctor.Show();
                }
                else
                {
                    MessageBox.Show("Faild! Username or Password wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            else if (comboBox1.SelectedIndex == 2)
            {
                bool isSuccess = login("pharmasist");
                if (isSuccess == true)
                {
                    FormPharmasist pharmasist = new FormPharmasist();
                    this.Hide();
                    pharmasist.whoLogin(txtUsername.Text);
                    pharmasist.Show();
                }
                else
                {
                    MessageBox.Show("Faild! Username or Password wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            else if (comboBox1.SelectedIndex == 3)
            {
                bool isSuccess = login("students");
                if (isSuccess == true)
                {
                    FormStudent student = new FormStudent();
                    student.parsingValue(txtUsername.Text);
                    this.Hide();
                    student.Show();
                }
                else
                {
                    MessageBox.Show("Faild! Username or Password wrong", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string query = "";

            if (comboBox1.SelectedIndex == 0)
            {
                FormAdmin admin = new FormAdmin();

                MySqlConnection conn = new MySqlConnection(constring);
                DataTable       dt1  = new DataTable();
                try
                {
                    string           sql     = "SELECT * FROM admin WHERE first_name='" + textBox1.Text + "' AND password='******' LIMIT 1  ";
                    MySqlCommand     cmd     = new MySqlCommand(sql, conn);
                    MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                    conn.Open();
                    adapter.Fill(dt1);
                    if (dt1.Rows.Count == 1)
                    {
                        admin.Show();
                        this.Hide();
                    }
                    else
                    {
                        label5.Text = "Invalid Username/Password";
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    conn.Close();
                }
            }
            else if (comboBox1.SelectedIndex == 1)
            {
                FormDoctor      doctor = new FormDoctor();
                MySqlConnection conn   = new MySqlConnection(constring);
                DataTable       dt1    = new DataTable();
                try
                {
                    string           sql     = "SELECT * FROM doctor WHERE first_name='" + textBox1.Text + "' AND password='******' LIMIT 1  ";
                    MySqlCommand     cmd     = new MySqlCommand(sql, conn);
                    MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                    conn.Open();
                    adapter.Fill(dt1);
                    if (dt1.Rows.Count == 1)
                    {
                        doctor.Show();
                        this.Hide();
                    }
                    else
                    {
                        label5.Text = "Invalid Username/Password";
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    conn.Close();
                }
            }
            else if (comboBox1.SelectedIndex == 2)
            {
                FormPharmasist  pharmasist = new FormPharmasist();
                MySqlConnection conn       = new MySqlConnection(constring);
                DataTable       dt1        = new DataTable();
                try
                {
                    string           sql     = "SELECT * FROM pharmasist WHERE first_name='" + textBox1.Text + "' AND password='******' LIMIT 1  ";
                    MySqlCommand     cmd     = new MySqlCommand(sql, conn);
                    MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                    conn.Open();
                    adapter.Fill(dt1);
                    if (dt1.Rows.Count == 1)
                    {
                        pharmasist.Show();
                        this.Hide();
                    }
                    else
                    {
                        label5.Text = "Invalid Username/Password";
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    conn.Close();
                }
            }



            //student select
            else if (comboBox1.SelectedIndex == 3)
            {
                MySqlConnection con = new MySqlConnection(constring);

                string       selectSql = "SELECT * FROM students WHERE first_name='" + textBox1.Text + "' AND password='******' LIMIT 1  ";
                MySqlCommand com       = new MySqlCommand(selectSql, con);


                try
                {
                    con.Open();

                    using (MySqlDataReader read = com.ExecuteReader())
                    {
                        while (read.Read())
                        {
                            label5.Text = (read["id"].ToString());
                        }
                    }
                }
                finally
                {
                    con.Close();
                }



                query = "SELECT * FROM students WHERE first_name='" + textBox1.Text + "' AND password='******' LIMIT 1  ";


                MySqlConnection conn = new MySqlConnection(constring);
                DataTable       dt1  = new DataTable();
                try
                {
                    string           sql     = "SELECT * FROM students WHERE first_name='" + textBox1.Text + "' AND password='******' LIMIT 1  ";
                    MySqlCommand     cmd     = new MySqlCommand(sql, conn);
                    MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                    conn.Open();
                    adapter.Fill(dt1);
                    if (dt1.Rows.Count == 1)
                    {
                        FormStudent student = new FormStudent(label5.Text);
                        student.Show();
                        this.Hide();
                    }
                    else
                    {
                        label5.Text = "Invalid Username/Password";
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    conn.Close();
                }
            }
        }