Exemple #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            MySqlConnection cn;

            cn = new MySqlConnection(connectionString);
            try
            {
                cn.Open();
            }
            catch (Exception)
            {
                MessageBox.Show("Can not open connection ! ");
            }

            try
            {
                LoginForm login = new LoginForm();
                MainForm  main  = new MainForm();
                username = txtUser.Text;
                password = txtPass.Text;

                cm.Connection = cn;

                string query = "select User_Username, User_Password, Teacher_FirstName, Teacher_Position from user, teacher where user.User_ID = teacher.User_ID and User_Username = '******' and User_Password = '******'";
                cm = new MySqlCommand(query, cn);
                MySqlDataReader reader = cm.ExecuteReader();
                if (reader.Read())
                {
                    txtFirstName.Text = reader.GetString(reader.GetOrdinal("Teacher_FirstName"));
                    txtPosition.Text  = reader.GetString(reader.GetOrdinal("Teacher_Position"));
                }

                if (reader.HasRows)
                {
                    MainForm admin = new MainForm();
                    admin.Show();
                    this.Hide();
                    if (txtPosition.Text == "Admin")
                    {
                    }
                    else if (txtPosition.Text == "Teacher")
                    {
                        TeacherMainForm teacher = new TeacherMainForm();
                        teacher.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("Invalid Username or Password", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        reader.Close();
                    }
                }


                else
                {
                    MessageBox.Show("Invalid Username or Password", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemple #2
0
        private void AdminMainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            LoginForm login = new LoginForm();

            login.Show();
        }