___ ___ erkimt Listview in Uneven c # ______ qstntxt ___

I am filling a listview from a select to the Oracle database. This is the code.

%pre%

What this result presents to me:

Now ... what I need is for it to look something like this: } }

It would be to group the orders with the same id.

The select to the database is a view that would be this:

%pre%     
______ azszpr220169 ___

Assuming that your query is ordered as you want, that is, the records are correct, what you should do would be something like this:

%pre%

What we are doing here is comparing the order with the previous one. If the order is different, we put all the data we want in the list .. If not, we leave those columns blank, and only fill the others.

This way you will achieve what you need. Notice that if the orders are different, I change the current order. And I start the first one in 0.

This is commonly known as control cuts.

    
___

1

I am filling a listview from a select to the Oracle database. This is the code.

                //comado que establece un adaptador entre la base de datos y el programa
#pragma warning disable CS0618 // El tipo o el miembro están obsoletos
            OracleDataAdapter adaptador = new OracleDataAdapter("select * from ENCABEZADO_PRODUCTOS", cnn);
#pragma warning restore CS0618 // El tipo o el miembro están obsoletos
            DataSet ds = new DataSet();
            DataTable tabla = new DataTable();

            adaptador.Fill(ds);//se llena el dataset
            tabla = ds.Tables[0];//se llena la tabla
            this.listView1.Items.Clear();//se limpa el list view
            ListViewItem item;
            for (int i = 0; i < tabla.Rows.Count; i++)
            {
                DataRow filas = tabla.Rows[i];
                item = listView1.Items.Add(filas["ID_ORDEN"].ToString());
                item.SubItems.Add(filas["PROVEEDOR"].ToString());
                item.SubItems.Add(filas["TIPO_TRANSACCION"].ToString());
                item.SubItems.Add(filas["TIPO_COMPRA"].ToString());
                item.SubItems.Add(filas["FECHA_EMISION"].ToString());
                item.SubItems.Add(filas["ESTADO"].ToString());
                item.SubItems.Add(filas["NUMERO_CUENTA"].ToString());
                item.SubItems.Add(filas["MONEDA"].ToString());
                item.SubItems.Add(filas["ID_PRODUCTO"].ToString());
                item.SubItems.Add(filas["ARTICULO"].ToString());
                item.SubItems.Add(filas["CATEGORIA"].ToString());
                item.SubItems.Add(filas["UNIDAD_MEDIDA"].ToString());
                item.SubItems.Add(filas["CANTIDAD_PEDIDA"].ToString());
                item.SubItems.Add(filas["CANTIDAD_RECIBIDA"].ToString());
                item.SubItems.Add(filas["BACKORDER"].ToString());
                item.SubItems.Add(filas["COSTO_UNITARIO"].ToString());
                item.SubItems.Add(filas["MONTO_TOTAL"].ToString());
            }
            cnn.Close();//se cierra la conexion

What this result presents to me:

Now ... what I need is for it to look something like this: } }

It would be to group the orders with the same id.

The select to the database is a view that would be this:

SELECT
    O.ID_ORDEN,
    O.FECHA_EMISION,
    O.TIPO_TRANSACCION,
    O.TIPO_COMPRA,
    P.NOMBRE NOMBRE_PERSONA,
    D.ID_DETALLE,
    D.CANTIDAD_PEDIDA,
    D.CANTIDAD_RECIBIDA,
    D.BACKORDER,
    D.MONTO_TOTAL, 
    PROD.NOMBRE NOMBRE_PRODUCTO
FROM
    ORDEN         O,
    DETALLE       D,
    PERSONA       P,
    PERSONA_X_ROL PROL,
    PRODUCTO      PROD 
WHERE
    O.ID_DETALLE         = D.ID_DETALLE        AND
    P.ID_PERSONA         = PROL.PERSONA_ROL    AND
    O.PROVEEDOR_ORDEN_ID = PROL.ID_PERSONA_ROL AND
    D.PRODUCTO_ID        = PROD.ID_PRODUCTO;
    
asked by java005 06.12.2018 в 19:20
source

1 answer

2

Assuming that your query is ordered as you want, that is, the records are correct, what you should do would be something like this:

int ID_ORDEN = 0;
for (int i = 0; i < tabla.Rows.Count; i++)
{
    DataRow filas = tabla.Rows[i];
    if (filas["ID_ORDEN"] != ID_ORDEN )
    {
        ID_ORDEN = filas["ID_ORDEN"];
        item = listView1.Items.Add(filas["ID_ORDEN"].ToString());
        item.SubItems.Add(filas["PROVEEDOR"].ToString());
        item.SubItems.Add(filas["TIPO_TRANSACCION"].ToString());
        item.SubItems.Add(filas["TIPO_COMPRA"].ToString());
        item.SubItems.Add(filas["FECHA_EMISION"].ToString());
    }
    else
    {
        item = listView1.Items.Add("");
        item.SubItems.Add("");
        item.SubItems.Add("");
        item.SubItems.Add("");
        item.SubItems.Add("");
    }
    item.SubItems.Add(filas["ESTADO"].ToString());
    item.SubItems.Add(filas["NUMERO_CUENTA"].ToString());
    ....
}

What we are doing here is comparing the order with the previous one. If the order is different, we put all the data we want in the list .. If not, we leave those columns blank, and only fill the others.

This way you will achieve what you need. Notice that if the orders are different, I change the current order. And I start the first one in 0.

This is commonly known as control cuts.

    
answered by 06.12.2018 / 20:40
source