Ejemplo n.º 1
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "Aluno")
            {
                this.Hide();
                Aluno newform = new Aluno();
                newform.Show();
            }

            else if (textBox1.Text == "Professor")
            {
                this.Hide();
                Professor newform = new Professor();
                newform.Show();
            }

            else if (textBox1.Text == "Administrador")
            {
                this.Hide();
                Admin newform = new Admin();
                newform.Show();
            }
            else if (textBox1.Text == "EE")
            {
                this.Hide();
                EE newform = new EE();
                newform.Show();
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string           conexao    = "Server=localhost;Database=Scholendar;Uid=root";
            var              connection = new MySqlConnection(conexao);
            MySqlDataAdapter adapter    = new MySqlDataAdapter();

            if (textBoxPassNova1.Text == "" || textBoxPassNova2.Text == "" || textBoxPassVelha.Text == "")
            {
                MessageBox.Show("Preencha todas as palavra-passe.");
            }
            else
            {
                if (textBoxPassNova1.Text == textBoxPassNova2.Text)
                {
                    pictureBox5.Visible = false;
                    if (textBoxUtilizador.Text == "1") // Aluno
                    {
                        connection.Open();
                        string          ID_Aluno   = textBoxID_Utilizador.Text;
                        string          query2     = "select * from Aluno where ID_Aluno = '" + ID_Aluno + "' ";
                        MySqlCommand    MyCommand2 = new MySqlCommand(query2, connection);
                        MySqlDataReader MyReader2;
                        MyReader2 = MyCommand2.ExecuteReader();
                        while (MyReader2.Read())
                        {
                            textBoxVerPassVelha.Text = MyReader2["pass"].ToString();
                        }
                        connection.Close();

                        if (textBoxPassVelha.Text == textBoxVerPassVelha.Text)
                        {
                            pictureBox4.Visible = false;

                            try
                            {
                                connection.Open();
                                string sql = "Update Aluno set pass = '******' where ID_Aluno = '" + ID_Aluno + "';";
                                adapter.InsertCommand = new MySqlCommand(sql, connection);
                                adapter.InsertCommand.ExecuteNonQuery();
                                connection.Close();


                                connection.Open();
                                string sql1 = "Update Aluno set var = '0' where ID_Aluno = '" + ID_Aluno + "';";
                                adapter.InsertCommand = new MySqlCommand(sql1, connection);
                                adapter.InsertCommand.ExecuteNonQuery();

                                connection.Close();

                                this.Close();
                                Aluno newform = new Aluno();
                                newform.Show();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.ToString());
                            }
                            finally
                            {
                                connection.Close();
                            }
                        }
                        else
                        {
                            pictureBox4.Visible = true;
                        }
                    }

                    else if (textBoxUtilizador.Text == "2") // Admin
                    {
                        connection.Open();
                        string          ID_Admin   = textBoxID_Utilizador.Text;
                        string          query2     = "select * from Admin where ID_Admin = '" + ID_Admin + "' ";
                        MySqlCommand    MyCommand2 = new MySqlCommand(query2, connection);
                        MySqlDataReader MyReader2;
                        MyReader2 = MyCommand2.ExecuteReader();
                        while (MyReader2.Read())
                        {
                            textBoxVerPassVelha.Text = MyReader2["pass"].ToString();
                        }
                        connection.Close();

                        if (textBoxPassVelha.Text == textBoxVerPassVelha.Text)
                        {
                            pictureBox4.Visible = false;

                            try
                            {
                                connection.Open();
                                string sql = "Update Admin set pass = '******' where ID_Admin = '" + ID_Admin + "';";
                                adapter.InsertCommand = new MySqlCommand(sql, connection);
                                adapter.InsertCommand.ExecuteNonQuery();
                                connection.Close();


                                connection.Open();
                                string sql1 = "Update Admin set var = '0' where ID_Admin = '" + ID_Admin + "';";
                                adapter.InsertCommand = new MySqlCommand(sql1, connection);
                                adapter.InsertCommand.ExecuteNonQuery();

                                connection.Close();

                                this.Close();
                                Admin newform = new Admin();
                                newform.Show();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.ToString());
                            }
                            finally
                            {
                                connection.Close();
                            }
                        }
                        else
                        {
                            pictureBox4.Visible = true;
                        }
                    }

                    else if (textBoxUtilizador.Text == "3") // Professor
                    {
                        connection.Open();
                        string          ID_Professor = textBoxID_Utilizador.Text;
                        string          query2       = "select * from Professor where ID_Professor = '" + ID_Professor + "' ";
                        MySqlCommand    MyCommand2   = new MySqlCommand(query2, connection);
                        MySqlDataReader MyReader2;
                        MyReader2 = MyCommand2.ExecuteReader();
                        while (MyReader2.Read())
                        {
                            textBoxVerPassVelha.Text = MyReader2["pass"].ToString();
                        }
                        connection.Close();

                        if (textBoxPassVelha.Text == textBoxVerPassVelha.Text)
                        {
                            pictureBox4.Visible = false;

                            try
                            {
                                connection.Open();
                                string sql = "Update Professor set pass = '******' where ID_Professor = '" + ID_Professor + "';";
                                adapter.InsertCommand = new MySqlCommand(sql, connection);
                                adapter.InsertCommand.ExecuteNonQuery();
                                connection.Close();


                                connection.Open();
                                string sql1 = "Update Professor set var = '0' where ID_Professor = '" + ID_Professor + "';";
                                adapter.InsertCommand = new MySqlCommand(sql1, connection);
                                adapter.InsertCommand.ExecuteNonQuery();

                                connection.Close();

                                this.Close();
                                Professor newform = new Professor();
                                newform.Show();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.ToString());
                            }
                            finally
                            {
                                connection.Close();
                            }
                        }
                        else
                        {
                            pictureBox4.Visible = true;
                        }
                    }
                    else if (textBoxUtilizador.Text == "4") // EE
                    {
                        connection.Open();
                        string          ID_EE      = textBoxID_Utilizador.Text;
                        string          query2     = "select * from EE where ID_EE = '" + ID_EE + "' ";
                        MySqlCommand    MyCommand2 = new MySqlCommand(query2, connection);
                        MySqlDataReader MyReader2;
                        MyReader2 = MyCommand2.ExecuteReader();
                        while (MyReader2.Read())
                        {
                            textBoxVerPassVelha.Text = MyReader2["pass"].ToString();
                        }
                        connection.Close();

                        if (textBoxPassVelha.Text == textBoxVerPassVelha.Text)
                        {
                            pictureBox4.Visible = false;

                            try
                            {
                                connection.Open();
                                string sql = "Update EE set pass = '******' where ID_EE = '" + ID_EE + "';";
                                adapter.InsertCommand = new MySqlCommand(sql, connection);
                                adapter.InsertCommand.ExecuteNonQuery();
                                connection.Close();


                                connection.Open();
                                string sql1 = "Update EE set var = '0' where ID_EE = '" + ID_EE + "';";
                                adapter.InsertCommand = new MySqlCommand(sql1, connection);
                                adapter.InsertCommand.ExecuteNonQuery();

                                connection.Close();

                                this.Close();
                                EE newform = new EE();
                                newform.Show();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.ToString());
                            }
                            finally
                            {
                                connection.Close();
                            }
                        }
                        else
                        {
                            pictureBox4.Visible = true;
                        }
                    }
                    else
                    {
                        pictureBox5.Visible = true;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            string conexao    = "Server=localhost;Database=Scholendar;Uid=root";
            var    connection = new MySqlConnection(conexao);
            //var command = connection.CreateCommand();
            MySqlCommand query = new MySqlCommand("select count(*) from Admin where Utilizador = '" + textBoxUtilizador.Text + "' and Pass = '******'", connection);

            connection.Open();
            DataTable        dataTable = new DataTable();
            MySqlDataAdapter da        = new MySqlDataAdapter(query);
            MySqlDataAdapter adapter   = new MySqlDataAdapter();

            da.Fill(dataTable);

            connection.Close();


            //QUERY'S
            MySqlCommand queryAl   = new MySqlCommand("select * from Aluno where Utilizador = '" + textBoxUtilizador.Text + "' and Pass = '******'", connection);
            MySqlCommand queryAd   = new MySqlCommand("select * from Admin where Utilizador = '" + textBoxUtilizador.Text + "' and Pass = '******'", connection);
            MySqlCommand queryProf = new MySqlCommand("select * from Professor where Utilizador = '" + textBoxUtilizador.Text + "' and Pass = '******'", connection);
            MySqlCommand queryEE   = new MySqlCommand("select * from EE where Utilizador = '" + textBoxUtilizador.Text + "' and Pass = '******'", connection);

            connection.Open();

            //DATATABLES
            DataTable dataTable1 = new DataTable();
            DataTable dataTable2 = new DataTable();
            DataTable dataTable3 = new DataTable();
            DataTable dataTable4 = new DataTable();


            //ADAPATERS
            MySqlDataAdapter daAl   = new MySqlDataAdapter(queryAl);
            MySqlDataAdapter daAd   = new MySqlDataAdapter(queryAd);
            MySqlDataAdapter daProf = new MySqlDataAdapter(queryProf);
            MySqlDataAdapter daEE   = new MySqlDataAdapter(queryEE);


            daAl.Fill(dataTable1);
            daAd.Fill(dataTable2);
            daProf.Fill(dataTable3);
            daEE.Fill(dataTable4);


            connection.Close();


            foreach (DataRow list in dataTable1.Rows) // Aluno
            {
                if (Convert.ToInt32(list.ItemArray[0]) > 0)
                {
                    textBoxVar.Text = "1";
                }
                else
                {
                }
            }

            foreach (DataRow list2 in dataTable2.Rows) // Admin
            {
                if (Convert.ToInt32(list2.ItemArray[0]) > 0)
                {
                    textBoxVar.Text = "2";
                }
                else
                {
                }
            }

            foreach (DataRow list3 in dataTable3.Rows) //Professor
            {
                if (Convert.ToInt32(list3.ItemArray[0]) > 0)
                {
                    textBoxVar.Text = "3";
                }
                else
                {
                }
            }


            foreach (DataRow list4 in dataTable4.Rows) //EE
            {
                if (Convert.ToInt32(list4.ItemArray[0]) > 0)
                {
                    textBoxVar.Text = "4";
                }
                else
                {
                }
            }

            string Utilizador = textBoxUtilizador.Text;

            if (textBoxVar.Text == "1") // Aluno
            {
                connection.Open();

                string          queryAlHex = "select * from Aluno where Utilizador = '" + Utilizador + "' ";
                MySqlCommand    MyCommand  = new MySqlCommand(queryAlHex, connection);
                MySqlDataReader MyReader;
                MyReader = MyCommand.ExecuteReader();
                while (MyReader.Read())
                {
                    textBoxID_Aluno.Text = MyReader["ID_Aluno"].ToString();
                }
                connection.Close();

                connection.Open();
                string          query1     = "select * from Aluno where ID_aluno = '" + textBoxID_Aluno.Text + "' ;";
                MySqlCommand    MyCommand1 = new MySqlCommand(query1, connection);
                MySqlDataReader MyReader1;
                MyReader1 = MyCommand1.ExecuteReader();
                while (MyReader1.Read())
                {
                    textBoxVarPass.Text = MyReader1["var"].ToString();
                }
                connection.Close();

                try
                {
                    string ID_Aluno = textBoxID_Aluno.Text;
                    connection.Open();

                    string sql = "Update VAR set var = ('" + ID_Aluno + "') where ID_Var = 1;";
                    adapter.InsertCommand = new MySqlCommand(sql, connection);
                    adapter.InsertCommand.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    connection.Close();
                }

                connection.Open();
                string sql1 = "Update VAR set var = '1' where ID_Var = 2;";
                adapter.InsertCommand = new MySqlCommand(sql1, connection);
                adapter.InsertCommand.ExecuteNonQuery();
                connection.Close();

                if (textBoxVarPass.Text == "1")
                {
                    this.Hide();
                    MudarPass newform = new MudarPass();
                    newform.Show();
                }
                else if (textBoxVarPass.Text == "0")
                {
                    this.Hide();
                    Aluno Form = new Aluno();
                    Form.Show();
                }
            }
            else if (textBoxVar.Text == "2") // Admin
            {
                connection.Open();

                string          queryAlHex = "select * from Admin where Utilizador = '" + Utilizador + "' ";
                MySqlCommand    MyCommand  = new MySqlCommand(queryAlHex, connection);
                MySqlDataReader MyReader;
                MyReader = MyCommand.ExecuteReader();
                while (MyReader.Read())
                {
                    textBoxID_Admin.Text = MyReader["ID_Admin"].ToString();
                }
                connection.Close();

                connection.Open();
                string          query1     = "select * from Admin where ID_Admin = '" + textBoxID_Admin.Text + "' ;";
                MySqlCommand    MyCommand1 = new MySqlCommand(query1, connection);
                MySqlDataReader MyReader1;
                MyReader1 = MyCommand1.ExecuteReader();
                while (MyReader1.Read())
                {
                    textBoxVarPass.Text = MyReader1["var"].ToString();
                }
                connection.Close();

                try
                {
                    string ID_Admin = textBoxID_Admin.Text;
                    connection.Open();

                    string sql = "Update VAR set var = ('" + ID_Admin + "') where ID_Var = 1;";
                    adapter.InsertCommand = new MySqlCommand(sql, connection);
                    adapter.InsertCommand.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    connection.Close();
                }
                connection.Open();
                string sql1 = "Update VAR set var = '2' where ID_Var = 2;";
                adapter.InsertCommand = new MySqlCommand(sql1, connection);
                adapter.InsertCommand.ExecuteNonQuery();
                connection.Close();
                if (textBoxVarPass.Text == "1")
                {
                    this.Hide();
                    MudarPass newform = new MudarPass();
                    newform.Show();
                }
                else if (textBoxVarPass.Text == "0")
                {
                    this.Hide();
                    Admin Form = new Admin();
                    Form.Show();
                }
            }
            else if (textBoxVar.Text == "3") // Professor
            {
                connection.Open();

                string          queryAlHex = "select * from Professor where Utilizador = '" + Utilizador + "' ";
                MySqlCommand    MyCommand  = new MySqlCommand(queryAlHex, connection);
                MySqlDataReader MyReader;
                MyReader = MyCommand.ExecuteReader();
                while (MyReader.Read())
                {
                    textBoxIDProf.Text = MyReader["ID_Professor"].ToString();
                }
                connection.Close();

                connection.Open();
                string          query1     = "select * from Professor where ID_Professor = '" + textBoxIDProf.Text + "' ;";
                MySqlCommand    MyCommand1 = new MySqlCommand(query1, connection);
                MySqlDataReader MyReader1;
                MyReader1 = MyCommand1.ExecuteReader();
                while (MyReader1.Read())
                {
                    textBoxVarPass.Text = MyReader1["var"].ToString();
                }
                connection.Close();

                try
                {
                    string ID_Prof = textBoxIDProf.Text;
                    connection.Open();

                    string sql = "Update VAR set var = ('" + ID_Prof + "') where ID_Var = 1;";
                    adapter.InsertCommand = new MySqlCommand(sql, connection);
                    adapter.InsertCommand.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    connection.Close();
                }
                connection.Open();
                string sql1 = "Update VAR set var = '3' where ID_Var = 2;";
                adapter.InsertCommand = new MySqlCommand(sql1, connection);
                adapter.InsertCommand.ExecuteNonQuery();
                connection.Close();
                if (textBoxVarPass.Text == "1")
                {
                    this.Hide();
                    MudarPass newform = new MudarPass();
                    newform.Show();
                }
                else if (textBoxVarPass.Text == "0")
                {
                    this.Hide();
                    Professor Form = new Professor();
                    Form.Show();
                }
            }

            if (textBoxVar.Text == "4") // EE
            {
                connection.Open();

                string          ID_EE      = textBoxID_EE.Text;
                string          queryAlHex = "select * from EE where Utilizador = '" + Utilizador + "' ";
                MySqlCommand    MyCommand  = new MySqlCommand(queryAlHex, connection);
                MySqlDataReader MyReader;
                MyReader = MyCommand.ExecuteReader();
                while (MyReader.Read())
                {
                    textBoxID_EE.Text = MyReader["ID_EE"].ToString();
                }
                connection.Close();

                connection.Open();
                string          query1     = "select * from EE where ID_EE = '" + ID_EE + "' ;";
                MySqlCommand    MyCommand1 = new MySqlCommand(query1, connection);
                MySqlDataReader MyReader1;
                MyReader1 = MyCommand1.ExecuteReader();
                while (MyReader1.Read())
                {
                    textBoxVarPass.Text = MyReader1["var"].ToString();
                }
                connection.Close();

                try
                {
                    connection.Open();

                    string sql = "Update VAR set var = ('" + ID_EE + "') where ID_Var = 1;";
                    adapter.InsertCommand = new MySqlCommand(sql, connection);
                    adapter.InsertCommand.ExecuteNonQuery();

                    connection.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    connection.Close();
                }
                connection.Open();

                string sql1 = "Update VAR set var = '4' where ID_Var = 2;";
                adapter.InsertCommand = new MySqlCommand(sql1, connection);
                adapter.InsertCommand.ExecuteNonQuery();
                connection.Close();

                if (textBoxVarPass.Text == "1")
                {
                    this.Hide();
                    MudarPass newform = new MudarPass();
                    newform.Show();
                }
                else if (textBoxVarPass.Text == "0")
                {
                    this.Hide();
                    EE Form = new EE();
                    Form.Show();
                }
            }
            else if (textBoxPass.Text == "" || textBoxUtilizador.Text == "")
            {
                MessageBox.Show("Insira o utilizador e a Password");
            }
            else if (textBoxVar.Text == "")
            {
                MessageBox.Show("Utilizador Incorreto");
            }
        }