Пример #1
0
        public IEnumerable <Lancamento> BuscarTodos(int id)
        {
            List <Lancamento> lista = new List <Lancamento>();

            try
            {
                using (SqlConnection conexao = new SqlConnection(_connectionString))
                    using (SqlCommand cmd = new SqlCommand("usp_LancamentoBuscarTodos", conexao)
                    {
                        CommandType = CommandType.StoredProcedure
                    })
                    {
                        cmd.Parameters.AddWithValue("@IdUsuario", id);

                        conexao.Open();

                        using (SqlDataReader reader = cmd.ExecuteReader())
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    lista.Add(new Lancamento()
                                    {
                                        Id          = reader.GetInt32(reader.GetOrdinal("Idlancamento")),
                                        IdCategoria = MetodoExtensao.BuscarValor <int>(reader, "IdCategoria"),
                                        IdUsuario   = reader.GetInt32(reader.GetOrdinal("IdUsuario")),
                                        Descricao   = reader.GetString(reader.GetOrdinal("Descricao")),
                                        Tipo        = reader.GetString(reader.GetOrdinal("Tipo")),
                                        Valor       = reader.GetDecimal(reader.GetOrdinal("Valor")),
                                        Data        = reader.GetDateTime(reader.GetOrdinal("Data")),
                                        Status      = reader.GetString(reader.GetOrdinal("Status"))
                                    });
                                }
                            }
                    }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return(lista);
        }
Пример #2
0
        public Usuario Logar(LoginDTO login)
        {
            try
            {
                using (SqlConnection conexao = new SqlConnection(_connectionString))
                    using (SqlCommand cmd = new SqlCommand("usp_UsuarioLogar", conexao))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@Login", login.Login);
                        cmd.Parameters.AddWithValue("@Senha", login.Senha);

                        conexao.Open();

                        using (SqlDataReader reader = cmd.ExecuteReader())
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    return(new Usuario()
                                    {
                                        Id = reader.GetInt32(reader.GetOrdinal("IdUsuario")),
                                        Nome = reader.GetString(reader.GetOrdinal("Nome")),
                                        Login = reader.GetString(reader.GetOrdinal("Login")),
                                        Senha = reader.GetString(reader.GetOrdinal("Senha")),
                                        DataCriacao = reader.GetDateTime(reader.GetOrdinal("DataCriacao")),
                                        DataAlteracao = MetodoExtensao.BuscarValor <DateTime>(reader, "DataAlteracao"),
                                        Status = reader.GetString(reader.GetOrdinal("Status"))
                                    });
                                }
                            }
                    }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return(null);
        }
Пример #3
0
        public List <GraficoDonutDTO> GraficoDonut(int IdUsuario)
        {
            List <GraficoDonutDTO> lista = new List <GraficoDonutDTO>();

            try
            {
                using (SqlConnection conexao = new SqlConnection(_connectionString))
                    using (SqlCommand cmd = new SqlCommand("usp_LancamentoGraficoDonuts", conexao)
                    {
                        CommandType = CommandType.StoredProcedure
                    })
                    {
                        cmd.Parameters.AddWithValue("@IdUsuario", IdUsuario);

                        conexao.Open();

                        using (SqlDataReader reader = cmd.ExecuteReader())
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    lista.Add(new GraficoDonutDTO()
                                    {
                                        CategoriaId        = reader.GetInt32(reader.GetOrdinal("Id")),
                                        CategoriaDescricao = reader.GetString(reader.GetOrdinal("Descricao")),
                                        Total = MetodoExtensao.BuscarValor <decimal>(reader, "Total")
                                    });
                                }
                            }
                    }
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return(lista);
        }