コード例 #1
0
        public Usuario Select(int Id)
        {
            var OUsuario = new Usuario();

            try
            {
                var        SQL        = "select ID, LOGIN, SENHA, IDPESSOA from USUARIO where ID = @ID";
                IDbCommand comandoSQL = conexao.CreateCommand();
                comandoSQL.CommandText = SQL;
                comandoSQL.CommandType = CommandType.Text;
                HelperDB.AddParameter(comandoSQL, "@ID", Id);
                conexao.Open();

                IDataReader reader = comandoSQL.ExecuteReader();

                reader.Read();

                OUsuario.Id       = Int32.Parse(reader[0].ToString());
                OUsuario.Login    = reader[1].ToString();
                OUsuario.Senha    = reader[2].ToString();
                OUsuario.IdPessoa = Int32.Parse(reader[3].ToString());
                reader.Close();
            }
            finally
            {
                conexao.Close();
            }
            return(OUsuario);
        }
コード例 #2
0
        public bool ValidarUsuario(Usuario usuario)
        {
            bool result = false;

            try
            {
                var        SQL        = "select count(1) RESULT from USUARIO where LOGIN = @LOGIN and SENHA = @SENHA";
                IDbCommand comandoSQL = conexao.CreateCommand();
                comandoSQL.CommandText = SQL;
                comandoSQL.CommandType = CommandType.Text;
                HelperDB.AddParameter(comandoSQL, "@LOGIN", usuario.Login);
                HelperDB.AddParameter(comandoSQL, "@SENHA", usuario.Senha);
                conexao.Open();

                IDataReader reader = comandoSQL.ExecuteReader();

                reader.Read();
                result = Int32.Parse(reader[0].ToString()) > 0;

                reader.Close();
            }
            finally
            {
                conexao.Close();
            }
            return(result);
        }
コード例 #3
0
        public Pessoa Select(int Id)
        {
            var OPessoa = new Pessoa();

            try
            {
                var        SQL        = "select ID, NOME, CPF_CNPJ, TIPOPESSOA, DATANASCIMENTO from PESSOA where ID = @ID";
                IDbCommand comandoSQL = conexao.CreateCommand();
                comandoSQL.CommandText = SQL;
                comandoSQL.CommandType = CommandType.Text;
                HelperDB.AddParameter(comandoSQL, "@ID", Id);
                conexao.Open();

                IDataReader reader = comandoSQL.ExecuteReader();

                reader.Read();

                OPessoa.Id       = Int32.Parse(reader[0].ToString());
                OPessoa.Nome     = reader[1].ToString();
                OPessoa.Cpf_Cnpj = reader[2].ToString();

                if (reader.IsDBNull(3))
                {
                    OPessoa.TipoPessoa = 'F';
                }
                else
                {
                    OPessoa.TipoPessoa = char.Parse(reader[3].ToString());
                }

                if (reader.IsDBNull(4))
                {
                    OPessoa.DataNascimento = HelperDB.MinValue();
                }
                else
                {
                    OPessoa.DataNascimento = DateTime.Parse(reader[4].ToString());
                }

                reader.Close();
            }
            finally
            {
                conexao.Close();
            }
            return(OPessoa);
        }
コード例 #4
0
 public void Delete(Pessoa pessoa)
 {
     try
     {
         var        SQL        = "delete from PESSOA where ID = @ID";
         IDbCommand comandoSQL = conexao.CreateCommand();
         comandoSQL.CommandText = SQL;
         HelperDB.AddParameter(comandoSQL, "@ID", pessoa.Id);
         comandoSQL.CommandType = CommandType.Text;
         conexao.Open();
         comandoSQL.ExecuteNonQuery();
     }
     finally
     {
         conexao.Close();
     }
 }
コード例 #5
0
 public void Delete(Usuario usuario)
 {
     try
     {
         var        SQL        = "delete from USUARIO where ID = @ID";
         IDbCommand comandoSQL = conexao.CreateCommand();
         comandoSQL.CommandText = SQL;
         HelperDB.AddParameter(comandoSQL, "@ID", usuario.Id);
         comandoSQL.CommandType = CommandType.Text;
         conexao.Open();
         comandoSQL.ExecuteNonQuery();
     }
     finally
     {
         conexao.Close();
     }
 }
コード例 #6
0
        public void Insert(Usuario usuario)
        {
            try
            {
                var SQL = "insert into USUARIO (LOGIN, SENHA, IDPESSOA) values (@LOGIN, @SENHA, @IDPESSOA)";

                IDbCommand comandoSQL = conexao.CreateCommand();
                comandoSQL.CommandText = SQL;
                HelperDB.AddParameter(comandoSQL, "@LOGIN", usuario.Login);
                HelperDB.AddParameter(comandoSQL, "@SENHA", usuario.Senha);
                HelperDB.AddParameter(comandoSQL, "@IDPESSOA", usuario.IdPessoa);
                comandoSQL.CommandType = CommandType.Text;
                conexao.Open();
                comandoSQL.ExecuteNonQuery();
            }
            finally
            {
                conexao.Close();
            }
        }
コード例 #7
0
        public void Update(Usuario usuario)
        {
            try
            {
                var SQL = "update USUARIO set LOGIN = @LOGIN, SENHA = @SENHA, IDPESSOA = @IDPESSOA where ID = @ID";

                IDbCommand comandoSQL = conexao.CreateCommand();
                comandoSQL.CommandText = SQL;
                HelperDB.AddParameter(comandoSQL, "@LOGIN", usuario.Login);
                HelperDB.AddParameter(comandoSQL, "@SENHA", usuario.Senha);
                HelperDB.AddParameter(comandoSQL, "@IDPESSOA", usuario.IdPessoa);

                comandoSQL.CommandType = CommandType.Text;
                conexao.Open();
                comandoSQL.ExecuteNonQuery();
            }
            finally
            {
                conexao.Close();
            }
        }
コード例 #8
0
        public void Insert(Pessoa pessoa)
        {
            try
            {
                var SQL = "insert into PESSOA (NOME, CPF_CNPJ, TIPOPESSOA, DATANASCIMENTO)" +
                          " values (@NOME, @CPF_CNPJ, @TIPOPESSOA, @DATANASCIMENTO)";

                IDbCommand comandoSQL = conexao.CreateCommand();
                comandoSQL.CommandText = SQL;
                HelperDB.AddParameter(comandoSQL, "@NOME", pessoa.Nome);
                HelperDB.AddParameter(comandoSQL, "@CPF_CNPJ", pessoa.Cpf_Cnpj);
                HelperDB.AddParameter(comandoSQL, "@TIPOPESSOA", pessoa.TipoPessoa);
                HelperDB.AddParameter(comandoSQL, "@DATANASCIMENTO", pessoa.DataNascimento);
                comandoSQL.CommandType = CommandType.Text;
                conexao.Open();
                comandoSQL.ExecuteNonQuery();
            }
            finally
            {
                conexao.Close();
            }
        }
コード例 #9
0
        public void Update(Pessoa pessoa)
        {
            try
            {
                var SQL = "update PESSOA set NOME = @NOME, CPF_CNPJ = @CPF_CNPJ" +
                          " ,TIPOPESSOA = @TIPOPESSOA, DATANASCIMENTO = @DATANASCIMENTO where ID = @ID";

                IDbCommand comandoSQL = conexao.CreateCommand();
                comandoSQL.CommandText = SQL;
                HelperDB.AddParameter(comandoSQL, "@NOME", pessoa.Nome);
                HelperDB.AddParameter(comandoSQL, "@CPF_CNPJ", pessoa.Cpf_Cnpj);
                HelperDB.AddParameter(comandoSQL, "@TIPOPESSOA", pessoa.TipoPessoa);
                HelperDB.AddParameter(comandoSQL, "@ID", pessoa.Id);
                HelperDB.AddParameter(comandoSQL, "@DATANASCIMENTO", pessoa.DataNascimento);
                comandoSQL.CommandType = CommandType.Text;
                conexao.Open();
                comandoSQL.ExecuteNonQuery();
            }
            finally
            {
                conexao.Close();
            }
        }