public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            if (obj == null)
            {
                return(false);
            }

            if (obj.GetType() != this.GetType())
            {
                return(false);
            }

            VendaPorPeriodoDTO other = (VendaPorPeriodoDTO)obj;

            return(object.Equals(other.Ano, this.Ano) &&
                   object.Equals(other.Mes, this.Mes) &&
                   object.Equals(other.ValorVendido, this.ValorVendido));
        }
        public ReportsDTO GetReports()
        {
            const string commandText = "EXEC GetReports";

            using (SqlConnection dbConnection = new SqlConnection(connectionString))
            {
                dbConnection.Open();

                using (SqlCommand dbCommand = dbConnection.CreateCommand())
                {
                    dbCommand.CommandText = commandText;

                    using (SqlDataReader reader = dbCommand.ExecuteReader())
                    {
                        var nullableIntConverter     = new NullableIntConverterFromObject();
                        var nullableDecimalConverter = new NullableDecimalConverterFromObject();

                        ReportsDTO reportsDTO = new ReportsDTO();

                        var vendaPorPeriodoList = new List <VendaPorPeriodoDTO>();
                        while (reader.Read())
                        {
                            var vendaPorPeriodo = new VendaPorPeriodoDTO();

                            vendaPorPeriodo.Ano          = nullableIntConverter.Converter(reader[CAMPO_ANO]);
                            vendaPorPeriodo.Mes          = nullableIntConverter.Converter(reader[CAMPO_MES]);
                            vendaPorPeriodo.ValorVendido = nullableDecimalConverter.Converter(reader[CAMPO_VALOR_VENDIDO]);

                            vendaPorPeriodoList.Add(vendaPorPeriodo);
                        }

                        reader.NextResult();

                        var vendaPorCategoriaList = new List <VendaPorCategoriaDTO>();
                        while (reader.Read())
                        {
                            var vendaPorCategoria = new VendaPorCategoriaDTO();

                            vendaPorCategoria.Categoria    = Convert.ToString(reader[CAMPO_CATEGORIA]);
                            vendaPorCategoria.ValorVendido = nullableDecimalConverter.Converter(reader[CAMPO_VALOR_VENDIDO]);

                            vendaPorCategoriaList.Add(vendaPorCategoria);
                        }

                        reader.NextResult();

                        var vendaPorProdutoList = new List <VendaPorProdutoDTO>();
                        while (reader.Read())
                        {
                            var vendaPorProduto = new VendaPorProdutoDTO();

                            vendaPorProduto.CodigoProduto = nullableIntConverter.Converter(reader[CAMPO_CODIGO_PRODUTO]);
                            vendaPorProduto.Quantidade    = nullableIntConverter.Converter(reader[CAMPO_QUANTIDADE]);

                            vendaPorProdutoList.Add(vendaPorProduto);
                        }

                        var reports = new ReportsDTO
                        {
                            VendasPorPeriodo   = vendaPorPeriodoList,
                            VendasPorCategoria = vendaPorCategoriaList,
                            VendasPorProduto   = vendaPorProdutoList
                        };

                        return(reports);
                    }
                }
            }
        }