Esempio n. 1
0
    protected void btnAgregar_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
        {
            return;
        }
        try
        {
            DetalleCompraInsumosEntidad detalle = new DetalleCompraInsumosEntidad();
            cboProveedor.Enabled = false;
            btnGuardar.Enabled   = true;
            detalle.idProveedor  = cboInsumos.SelectedIndex;
            //detalle.fechaHora = horaActual;
            detalle.codInsumo   = cboInsumos.SelectedIndex;
            detalle.descripcion = cboInsumos.SelectedItem.ToString();
            float precio;
            if (float.TryParse(txtPrecio.Text, out precio))

            {
                detalle.precioUnitario = precio;
            }

            detalle.cantidad = int.Parse(txtCantidad.Text);

            agregarEnLista(detalle);
        }
        catch (Exception ex)
        {
            txtResultado.Visible = true;
            txtResultado.Text    = "Ha ocurrido el siguiente error: " + ex.Message;
        }
    }
Esempio n. 2
0
    protected void agregarEnLista(DetalleCompraInsumosEntidad detalle)
    {
        if (listaD.Count > 0)
        {
            bool bandera = false;
            foreach (DetalleCompraInsumosEntidad det in listaD)
            {
                if (det.codInsumo == detalle.codInsumo)
                {
                    det.cantidad = det.cantidad + detalle.cantidad;
                    bandera      = true;
                }
            }

            if (bandera == false)
            {
                listaD.Add(detalle);
            }
        }
        else
        {
            listaD.Add(detalle);
        }


        cargarGrilla();
        calcularTotal();
    }