Limit query in index but not in combo

1

Good afternoon,

In the company's ERP we have a query in the Index that is limited to 80 records. The problem is that in create we have combos that bring more than 150 records and also limiting to 80 records.

How can I do to just leave in index without having to create another method?

private StringBuilder LimitarRetornoLinhas()
    {
        var sql = new StringBuilder();
        sql.Append("SELECT * FROM (" + Environment.NewLine);
        sql.Append(_sql.ToString());
        sql.Append(" ) WHERE ROWNUM <= 80 ");
        return sql;
    }

-

public List<Fabricante> Selecionar()

    {
        var fabricantes = new List<Fabricante>();

        _sql.Append(" ORDER BY FAB_NOME ");

        StringBuilder sql = LimitarRetornoLinhas();
        Conexao conexao = new Conexao();
        DataTable dt = new DataTable();
        conexao.AbrirConexao();

        dt = conexao.ObterDataTable(sql.ToString());

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                fabricantes.Add(Mapear(dt.Rows[i]));
            }
        }

        return fabricantes;
    }
    
asked by anonymous 05.10.2018 / 18:02

2 answers

1

Change to receive the desired number of records as a parameter:

private StringBuilder LimitarRetornoLinhas(int quantidadeRegistros = 80)
{
    StringBuilder sql = new StringBuilder();

    sql.Append("SELECT * FROM (" + Environment.NewLine);
    sql.Append(_sql.ToString());
    sql.Append(string.Format(" ) WHERE ROWNUM <= {0} ", quantidadeRegistros));

    return sql;
}

Now just call your method by passing the desired number of records:

StringBuilder query = LimitarRetornoLinhas(150);
    
05.10.2018 / 18:15
0
private StringBuilder LimitarRetornoLinhas(bool carregarTodos)
    {
        var sql = new StringBuilder();
        if (carregarTodos == false)
        {
            sql.Append("SELECT * FROM (" + Environment.NewLine);
            sql.Append(_sql.ToString());
            sql.Append($" ) WHERE ROWNUM <= 80"); 
        }
        else
        {
            sql.Append(_sql.ToString());
        }

        return sql;
    }

-

public List<Fabricante> Selecionar(bool carregarTodos)
    {
        var fabricantes = new List<Fabricante>();

        _sql.Append(" ORDER BY FAB_NOME ");

        StringBuilder sql = LimitarRetornoLinhas(carregarTodos);
        Conexao conexao = new Conexao();
        DataTable dt = new DataTable();
        conexao.AbrirConexao();

        dt = conexao.ObterDataTable(sql.ToString());

        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                fabricantes.Add(Mapear(dt.Rows[i]));
            }
        }

        return fabricantes;
    }
    
05.10.2018 / 18:32