Exemplo n.º 1
0
        private void entrar_Click(object sender, EventArgs e)
        {
            try
            {
                //
                //POR ISTO A RESOLVER PRIMEIRO ---- IMPORTANTE
                //
                db.Open();
                if (userTextBox.Text == "Nome de Utilizador")
                {
                    MessageBox.Show("Escreva o seu Username !", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                if (passTextBox.Text == "Palavra-passe")
                {
                    MessageBox.Show("Escreva o seu username !", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                //confirmar se esta campros em grande
                if (!string.IsNullOrEmpty(userInserido) && !string.IsNullOrEmpty(passInserida))
                {
                    MessageBox.Show("Campos em branco !", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    this.Hide();
                    PaginaPrincipal Loja = new PaginaPrincipal();
                    Loja.Show();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"\nErro: {ex.Message}");
            }
            finally
            {
                if (db.State == System.Data.ConnectionState.Open)
                {
                    db.Close();
                    Console.WriteLine("Ligação à BD fechada entrada.");
                }
            }
        }
Exemplo n.º 2
0
        //codigo para confirmar se o utilizador escreve o seu username, pass e
        //por fim confirmas se existe a conta de utilizador
        private void Entrar_Click(object sender, EventArgs e)
        {
            MySqlCommand inserirDados = new MySqlCommand();

            inserirDados.Connection = Utils.db;


            try
            {
                Utils.db.Open();
                if (userTextBox.Text == "Nome de Utilizador" || string.IsNullOrEmpty(userTextBox.Text))
                {
                    MessageBox.Show("Escreva o seu Username !", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (passTextBox.Text == "Palavra-passe" || string.IsNullOrEmpty(passTextBox.Text))
                {
                    MessageBox.Show("Escreva a sua pass!", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (!Utils.ExisteUsername(Convert.ToString(userInserido), Convert.ToString(passInserida), inserirDados))
                {
                    infoOk("Erro!", "Credenciais incorretas");
                }
                else
                {
                    Utils.readInfoUser(Convert.ToString(passinfo), Convert.ToString(emailinfo), Convert.ToString(sexoinfo), Convert.ToInt32(telemovelinfo));
                    this.Hide();
                    PaginaPrincipal Loja = new PaginaPrincipal();
                    Loja.Show();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"\nErro: {ex.Message}");
            }
            finally
            {
                if (Utils.db.State == System.Data.ConnectionState.Open)
                {
                    Utils.db.Close();
                    Console.WriteLine("Ligação à BD fechada entrada.");
                }
            }
        }
Exemplo n.º 3
0
        //codigo para registar o novo utilizador
        private void adicionar_Click(object sender, EventArgs e)
        {
            MySqlCommand inserirDados = new MySqlCommand();

            inserirDados.Connection = db;

            try
            {
                db.Open();

                Console.WriteLine("Sexo -> " + sexoInserido);

                if (!string.IsNullOrEmpty(userInserido) && !string.IsNullOrEmpty(passInserida) &&
                    !string.IsNullOrEmpty(emailInserido) && !string.IsNullOrEmpty(telemovelInserido) &&
                    !string.IsNullOrEmpty(sexoInserido))
                {
                    if (existeUsername(Convert.ToString(userInserido), Convert.ToString(passInserida), inserirDados))
                    {
                        infoOk("Erro", "Username já existe");
                    }

                    else
                    {
                        inserirDados.CommandText = "insert into users (username, pass, email, sexo, telemovel) values (@user, @pass, @email, @sexo, @telemovel)";

                        inserirDados.Parameters.Add("@user", MySqlDbType.String).Value     = Convert.ToString(userInserido);
                        inserirDados.Parameters.Add("@pass", MySqlDbType.String).Value     = Convert.ToString(passInserida);
                        inserirDados.Parameters.Add("@email", MySqlDbType.String).Value    = Convert.ToString(emailInserido);
                        inserirDados.Parameters.Add("@sexo", MySqlDbType.String).Value     = Convert.ToString(sexoInserido);
                        inserirDados.Parameters.Add("@telemovel", MySqlDbType.Int32).Value = Convert.ToInt32(telemovelInserido);

                        int linhasCriadas = inserirDados.ExecuteNonQuery();

                        if (linhasCriadas > 0)
                        {
                            infoOk("Sucesso", "Foi inserido um novo user com o nome " + userInserido);
                        }

                        Console.WriteLine("Inserido o user: "******"Erro", "Faltam inserir dados no formulário.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"\nErro: {ex.Message}");
            }
            finally
            {
                if (db.State == System.Data.ConnectionState.Open)
                {
                    db.Close();
                    Console.WriteLine("Ligação à BD fechada registo.");
                }
            }
        }