Example #1
0
        public Cadastro listarUsu(int id)
        {
            try
            {
                conn = classeConexão.obterConexao();
                if (conn.State == ConnectionState.Open)
                {
                    try
                    {
                        SqlCommand cmd = new SqlCommand("select * from Usuario where idCarteira = @id", conn);
                        cmd.Parameters.AddWithValue("@id", id);
                        SqlDataReader reader1 = cmd.ExecuteReader();
                        Cadastro      a       = new Cadastro();


                        if (reader1.Read())
                        {
                            a.setId(id);

                            a.setId(int.Parse(reader1[0].ToString()));
                            a.setNome(reader1[1].ToString());
                            a.setEmail(reader1[2].ToString());
                            a.setSenha(reader1[5].ToString());
                            a.setData(DateTime.Parse(reader1[3].ToString()));
                            a.setCpf(reader1[4].ToString());
                            reader1.Close();
                            cmd.Dispose();
                            return(a);
                        }
                        else
                        {
                            reader1.Close();
                            cmd.Dispose();
                            return(null);
                        }
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Erro: " + error);

                        return(null);
                    }
                    finally
                    {
                        classeConexão.fecharConexao();
                    }
                }
                else
                {
                    MessageBox.Show(conn.State.ToString());
                    return(null);
                }
            }
            catch (Exception error)
            {
                MessageBox.Show("Erro: " + error);

                return(null);
            }
        }
Example #2
0
        private void btnEditar_Click(object sender, EventArgs e)
        {
            Cadastro a = new Cadastro();

            a.setId(int.Parse(txtId.Text));
            a.setNome(txtNome.Text);
            a.setEmail(txtEmail.Text);
            a.setCpf(txtCPF.Text);
            a.setSenha(txtSenha.Text);
            a.setData(DateTime.Parse(txtNasc.Text));

            consultaDao.atualizarUsu(a);

            listarTable();

            txtId.Clear();
            txtEmail.Clear();
            txtCPF.Clear();
            txtNome.Clear();
            txtSenha.Clear();
            txtNasc.Clear();
        }