Ejemplo n.º 1
0
        //
        protected void ReadData()
        {
            try {
                string comando = "SELECT Codigo, NomeCompleto, Login, Anotacoes FROM Usuarios ORDER BY Codigo";
                AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction();
                db.ConnectionString = conexao;


                DataTable dt = new DataTable();
                dt = (DataTable)db.Query(comando);

                //copia os dados de dt para datasource do gridview
                Usuarios.DataSource = dt;
                Usuarios.DataBind();
                dt.Dispose();

                Codigo.Text       = "";
                NomeCompleto.Text = "";
                Login.Text        = "";
                Senha.Text        = "";
                Anotacoes.Text    = "";
            }
            catch (Exception ex) {
                Mensagem.Text = $"Houve uma falha inesperada no registro dos dados: {ex.Message} ";

                RecoverExceptions re = new RecoverExceptions();
                re.SaveException(ex);
            }
        }
Ejemplo n.º 2
0
        //verifica se o login ja existe antes de cadastrar
        protected bool EsteLoginExiste(string nomeLogin)
        {
            string comando = "SELECT * FROM Usuarios WHERE Login='******';";

            // 3. CONECTAR AO BANCO DE DADOS ED ENVIAR O COMANDO SQL
            AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction();
            db.ConnectionString = conexao;
            // DataTable é o repositório na MP para os dados vindos do SELECT
            System.Data.DataTable tb = (System.Data.DataTable)db.Query(comando);

            if (tb.Rows.Count == 1)
            {
                if (tb.Rows[0]["Codigo"].ToString() == Codigo.Text)
                {
                    // este código de usuário é o mesmo que esta sendo editado.
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
    // SALVA OS DADOS NA TABELA USUÁRIOS
    protected void Salvar_Click(object sender, EventArgs e)
    {
        if (Nome.Text.Trim() == "")
        {
            MsgErro.Text = "Digite o nome";
        }
        if (Senha.Text.Trim() == "")
        {
            MsgErro.Text = "Digite o senha";
        }
        else
        {
            string sql = "";

            if (UsuarioId.Value != "")
            {
                // UPDATE
                sql = "UPDATE Usuarios SET Nome='" + Nome.Text + "',Email='" + Email.Text + "',Senha='" + Senha.Text + "',DateTimeUpdate=Now() WHERE UsuarioID=" + UsuarioId.Value;
            }
            else
            {
                sql = "INSERT INTO Usuarios(Nome,Email,Senha,DateTimeInsert,DateTimeUpdate,Status) VALUES('" + Nome.Text + "','" + Email.Text + "','" + Senha.Text + "',Now(),Now(),1);";
            }
            dbase = new Conexao().GetConnection();
            dbase.Query(sql);
        }
        LimparCampos();
    }
Ejemplo n.º 4
0
    protected void Salvar_Click(object sender, EventArgs e)
    {
        // validação de entradas
        if (Nome.Text.Trim() == "")
        {
            // exibe a mensagem de erro
        }
        else
        {
            if (user_id.Value != "")
            {
                sql = "UPDATE USUARIOS SET Nome='" + Nome.Text + "',Email='" + Email.Text + "',Senha='" + Senha.Text + "'Date_Time_Update=Now() WHERE user_id=" + user_id.Value + ";";
            }
            else
            {
                string sql = "INSERT INTO Usuarios(Nome,Email,Senha,Date_Time_Insert, Data_Time_Update, Status, user_id)VALUES('" + Nome.Text + "','" + Email.Text + "','" + Senha.Text + "','" + DateTime.UtcNow.ToString() + "','" + DateTime.UtcNow.ToString() + "',1," + Session["usuario_id"].ToString() + ");";
            }


            // grava registro
            string sql = "INSERT INTO Usuarios(Nome,Email,Senha,Date_Time_Insert, Data_Time_Update, Status, user_id)VALUES('" + Nome.Text + "','" + Email.Text + "','" + Senha.Text + "','" + DateTime.UtcNow.ToString() + "','" + DateTime.UtcNow.ToString() + "',1," + Session["usuario_id"].ToString() + ");";

            db = new ConexaoDataBase().GetConnection();
            db.Query(sql);
        }
    }
Ejemplo n.º 5
0
        protected void Salvar_Click(object sender, EventArgs e)
        {
            try {
                if (NomeCompleto.Text.Trim() == "")
                {
                    Mensagem.Text = "O nome deve ser digitado";
                }
                else if (Login.Text.Trim() == "")
                {
                    Mensagem.Text = "O nome de login ser digitado";
                }
                else if (EsteLoginExiste(Login.Text.Trim()))
                {
                    Mensagem.Text = "Este nome de login já existe, tente outro.";
                }

                else if (Senha.Text.Trim() == "")
                {
                    Mensagem.Text = "A senha deve ser digitada";
                }


                else
                {
                    string comando = "";
                    if (Codigo.Text == "")
                    {
                        comando = $"INSERT INTO Usuarios(NomeCompleto, Login, Senha, Anotacoes)" +
                                  $" Values('{NomeCompleto.Text}', '{Login.Text}', '{Senha.Text}', '{Anotacoes.Text}');";
                    }
                    else
                    {
                        comando = $"UPDATE Usuarios SET NomeCompleto='{NomeCompleto.Text}', Login='******', Senha='{Senha.Text}', Anotacoes='{Anotacoes.Text}' WHERE CODIGO={Codigo.Text}";
                    }



                    //3.Conectar ao banco e enviar o comando sql
                    AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction();
                    db.ConnectionString = conexao;
                    db.Query(comando);



                    ReadData();
                }
            }
            catch (Exception ex) {
                Mensagem.Text = $"Houve uma falha inesperada no registro dos dados: {ex.Message} ";

                RecoverExceptions re = new RecoverExceptions();
                re.SaveException(ex);
            }
        }
Ejemplo n.º 6
0
    protected void LoadUsuarios()
    {
        string sql = "SELECT user_id,Nome,Email FROM USUARIOS WHERE Status=1 ORDER BY Nome";

        db = new ConexaoDataBase().GetConnection();
        DataTable tb = (DataTable)db.Query(sql);

        // Carrega os dados da consulta no gridview
        ListaUsuarios.DataSouce = tb;
        ListaUsuarios.DataBind();
    }
Ejemplo n.º 7
0
 protected void Excluir_Click(object sender, EventArgs e)
 {
     if (UsuarioId.Value == null)
     {
         MsgErro.Text = "Usuario Não encontrado";
     }
     else
     {
         string sql = "UPDATE Usuarios set Status = -1 where  UsuarioID = " + UsuarioId.Value;
         dbase = new Conexao().GetConnection();
         dbase.Query(sql);
         LimparCampos();
     }
 }
Ejemplo n.º 8
0
    // EXIBE TODOS OS USUÁRIO NO GRID
    protected void LoadGrid()
    {
        string sql = "SELECT UsuarioId,Nome,Email FROM Usuarios WHERE Status=1 ORDER BY Nome;";

        dbase = new Conexao().GetConnection();

        DataTable tb = (DataTable)dbase.Query(sql);

        if (tb.Rows.Count > 0)
        {
            Usuarios.DataSource = tb;
            Usuarios.DataBind();
        }
    }
Ejemplo n.º 9
0
        //BUSCAR
        protected void Buscar_Click(object sender, EventArgs e)
        {
            string comando = $"SELECT Codigo, NomeCompleto, Login FROM Usuarios WHERE NomeCompleto + Login LIKE '%{BuscarUsuario.Text}%';";

            AppDatabase.OleDBTransaction db = new AppDatabase.OleDBTransaction();
            db.ConnectionString = conexao;

            DataTable dt = new DataTable();

            dt = (DataTable)db.Query(comando);

            Usuarios.DataSource = dt;
            Usuarios.DataBind();
            dt.Dispose();
        }
    protected void Gravar_Click(object sender, EventArgs e)
    {
        string comando = "UPDATE Cadastro SET Nome='" + Nome.Text + "',Email='" + Email.Text + "',Telefone='" + Telefone.Text + "',Resumo='" + Resumo.Text + "' WHERE Registro=" + Registro.Text;

        AppDatabase.OleDBTransaction ole = new AppDatabase.OleDBTransaction();
        // define a conexão com o database
        ole.ConnectionString = conexao;
        if ((int)ole.Query(comando) == 1)
        {
            Limpar();
            CarregarNomes();
            Entrada.Visible = false;
        }
        else
        {
            msg.Text = "Falha na atualização dos dados!";
        }
    }
Ejemplo n.º 11
0
    protected void Enviar_Click(object sender, EventArgs e)
    {
        if (Nome.Text.Trim() == "")
        {
            msg.Text = "O nome deve ser digitado!";
        }
        else if (Email.Text.Trim() == "")
        {
            msg.Text = "O nome deve ser digitado!";
        }
        else
        {
            try
            {
                // coneção PostGreSQL
                //User ID = root; Password = myPassword; Host = localhost; Port = 5432; Database = myDataBase; Pooling = true; Min Pool Size = 0; Max Pool Size = 100; Connection Lifetime = 0;

                string conexao = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/app_data/BancoDados.accdb") + ";Persist Security Info = False; ";

                string comando = "INSERT INTO Cadastro(Nome,Email,Telefone,Resumo) VALUES('" + Nome.Text + "','" + Email.Text + "','" + Telefone.Text + "','" + Resumo.Text + "');";

                // cria uma instancia da classe para transação no banco de dados access
                // o pacote AppDataBase foi importado para a pasta bin
                AppDatabase.OleDBTransaction ole = new AppDatabase.OleDBTransaction();

                // define a conexão com o database
                ole.ConnectionString = conexao;

                if ((int)ole.Query(comando) == 1)
                {
                    Entrada.Visible       = false;
                    MensagemFinal.Visible = true;
                }
            }
            catch (Exception ex)
            {
                msg.Text = ex.Message;
            }
        }
    }
    protected void Buscar_Click(object sender, EventArgs e)
    {
        Entrada.Visible = true;

        string comando = "SELECT * FROM Cadastro WHERE Registro=" + Registros.SelectedValue;

        AppDatabase.OleDBTransaction ole = new AppDatabase.OleDBTransaction();
        // define a conexão com o database
        ole.ConnectionString = conexao;
        DataTable tb = (DataTable)ole.Query(comando);

        if (tb.Rows.Count == 1)
        {
            Registro.Text = tb.Rows[0]["Registro"].ToString();
            Nome.Text     = tb.Rows[0]["Nome"].ToString();
            Email.Text    = tb.Rows[0]["Email"].ToString();
            Telefone.Text = tb.Rows[0]["Telefone"].ToString();
            Resumo.Text   = tb.Rows[0]["Resumo"].ToString();

            Gravar.Enabled  = true;
            Excluir.Enabled = true;
        }
    }
Ejemplo n.º 13
0
    protected void ListaUsuarios_SelectedIndexChanged(object sender, EventArgs e)
    {
        user_id.Value = ListaUsuarios.SelectedRow.Cells[1].Text;

        string sql = "SELECT * FROM Usuarios where user_id=" + user_id.Value + " AND Status=1;";

        db = new ConexaoDataBase().GetConnection();
        DataTable tb = (DataTable).db.Query(sql);

        // verifica se o registro foi encotrado na tabela
        if (tb.Rows.Count == 1)
        {
            Nome.Text  = tb.Rows[0]["Nome"].ToString();
            Email.Text = tb.Rows[0]["Email"].ToString();
            Senha.Text = tb.Rows[0]["Senha"].ToString();
            //habilita o botao excluir
            Excluir.Enable = True
        }
        else
        {
            Msg.Text = "Usuarios não encontrado";
        }
    }
Ejemplo n.º 14
0
    protected void Usuarios_SelectedIndexChanged(object sender, EventArgs e)
    {
        // Obtem o UsuarioId do item selecionado no gridview
        UsuarioId.Value = Usuarios.SelectedRow.Cells[1].Text;
        string sql = "SELECT * FROM Usuarios WHERE UsuarioId=" + UsuarioId.Value + " AND Status=1;";

        dbase = new Conexao().GetConnection();
        DataTable tb = (DataTable)dbase.Query(sql);

        // verifica se o registro foi encontrado na tabela
        if (tb.Rows.Count == 1)
        {
            Nome.Text  = tb.Rows[0]["Nome"].ToString();
            Email.Text = tb.Rows[0]["Email"].ToString();
            Senha.Text = tb.Rows[0]["Senha"].ToString();

            // habilita o botão excluir
            Excluir.Enabled = true;
        }
        else
        {
            MsgErro.Text = "Usuario Não encontrado";
        }
    }
Ejemplo n.º 15
0
 /// <summary>
 /// Retorna uma instancia da classe OleDbTransaction conectada ao banco de dados
 /// </summary>
 /// <returns></returns>
 public AppDatabase.OleDBTransaction GetConnection()
 {
     db = new AppDatabase.OleDBTransaction();
     db.ConnectionString = conexao;
     return(db);
 }