Ejemplo n.º 1
0
        private void btnhome_Click(object sender, EventArgs e)
        {
            Form10 anotherform = new Form10(userid);

            anotherform.previousForm = this;
            anotherform.Show();
            this.Close();
        }
Ejemplo n.º 2
0
        private void btnlogin_Click(object sender, EventArgs e)
        {
            string usr   = txtuser.Text;
            string psw   = txtpass.Text;
            string query = "SELECT * FROM users WHERE username='******'AND password='******';";

            conn.Open();
            MySqlCommand     comm = new MySqlCommand(query, conn);
            MySqlDataAdapter adp  = new MySqlDataAdapter(comm);

            conn.Close();
            DataTable dt = new DataTable();

            adp.Fill(dt);

            if (dt.Rows.Count == 1)
            {
                string fn     = dt.Rows[0][1].ToString();
                string ln     = dt.Rows[0][2].ToString();
                string utype  = dt.Rows[0][8].ToString();
                int    userid = int.Parse(dt.Rows[0][0].ToString());
                Class1.currentid = int.Parse(dt.Rows[0][0].ToString());

                MessageBox.Show("Welcome " + ln + ", " + fn + "!", "",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                if (utype == "Admin")
                {
                    Form2 anotherform = new Form2();
                    anotherform.previousForm = this;
                    anotherform.types        = dt.Rows[0][1].ToString();
                    anotherform.typesfn      = dt.Rows[0][3].ToString();
                    anotherform.Show();
                    this.Hide();
                }
                if (utype == "Student")
                {
                    Form10 form = new Form10(userid);
                    form.previousForm = this;
                    form.Show();
                    form.fn = dt.Rows[0][1].ToString();
                    form.ln = dt.Rows[0][3].ToString();
                    this.Hide();
                }
            }
            else
            {
                if (usr == "")
                {
                    MessageBox.Show("Username is empty.");
                }
                else if (psw == "")
                {
                    MessageBox.Show("Password is empty.");
                }
                else if (psw == "" && usr == "")
                {
                    MessageBox.Show("Enter your credentials.");
                }
                else
                {
                    MessageBox.Show("Records not found.");
                }
                txtuser.Clear();
                txtpass.Clear();
            }
        }