Leave Blank DataTable

0

Good afternoon everyone, I have the following method through which, by means of a Add button , I am adding various items to DataTable , which are visualize in a DataGridView in list form, the detail that I have is this: when I click the New Button , the form is cleaned, I start to fill the various controls that I need to load the again > DataGrid but when clicking the Add button , only the necessary operations are carried out to calculate the total etc, leaving inside the DataTable the information of the articles that I entered previously, so which I need to validate, if you press the New Button leave me blank the DataTable as if the process were the initial, attached code used.

#region LlenarGrid

if (dtGridArticulos.Columns.Contains("Articulo") && dtGridArticulos.Columns.Contains("Cantidad") && dtGridArticulos.Columns.Contains("PrecioUnitario") && dtGridArticulos.Columns.Contains("SubtotalArticulo") && dtGridArticulos.Columns.Contains("Detalle"))
{
    DataRow drArticulosSeleccionados = dtGridArticulos.NewRow();
    if (articulo != "" && cliente != "" && cantidad != 0 && preciounitario != 0 && descripcion != "")
    {
        foreach (DataRow drGridArticulos in dtGridArticulos.Rows)
        {
            drArticulosSeleccionados["Articulo"] = articulo;
            drArticulosSeleccionados["Cantidad"] = cantidad;
            drArticulosSeleccionados["PrecioUnitario"] = Convert.ToDouble(preciounitario);
            drArticulosSeleccionados["Detalle"] = Convert.ToString(descripcion);
            if (cantidad>0 && preciounitario>0)
            {
                subtotal = cantidad * preciounitario;
                if (subtotal>0)
                {
                    drArticulosSeleccionados["SubtotalArticulo"] = Convert.ToDouble(subtotal);
                }
                else
                {
                    txtIngCantidad.Text = "0";
                    txtIngPU.Text = "0.00";
                    drArticulosSeleccionados["SubtotalArticulo"] = Convert.ToDouble("0.00");
                }
            }
            else
            {
                if (cantidad==0)
                {
                    objValidaciones.MostrarAviso("La cantidad de artículos debe ser mayor que 0", true, lblAviso1);
                }
                if (preciounitario == 0)
                {
                    objValidaciones.MostrarAviso("El precio unitario de cada artículo debe ser mayor que 0", true, lblAviso1);
                }
            }
            dtGridArticulos.Rows.Add(drArticulosSeleccionados);
            subtotal1 += subtotal;
            if (subtotal1>0)
            {
                txtIngSubtot.Text = string.Format("{0:n2}", (Math.Truncate(subtotal1 * 100) / 100));
            }
            else
            {
                txtIngSubtot.Text = "0.00";
            }
            subtotalfinal = subtotal1 * IVA;
            if (subtotalfinal > 0)
            {
                txtIvaIngOrden.Text = string.Format("{0:n2}", (Math.Truncate(subtotalfinal * 100) / 100));
                totalfinal = subtotal1 + subtotalfinal;
                txtIngTotal.Text = string.Format("{0:n2}", (Math.Truncate(totalfinal * 100) / 100));
            }
            else
            {
                txtIngTotal.Text = "0.0";
            }
        }                        
    }
}
else
{
    dtGridArticulos.Columns.Add("Articulo");
    dtGridArticulos.Columns.Add("Cantidad");
    dtGridArticulos.Columns.Add("PrecioUnitario");
    dtGridArticulos.Columns.Add("SubtotalArticulo");
    dtGridArticulos.Columns.Add("Detalle");
    DataRow drArticulosSeleccionados = dtGridArticulos.NewRow();
    if (articulo != "" && cliente != "" && cantidad != 0 && preciounitario != 0 && descripcion != "")
    {
        drArticulosSeleccionados["Articulo"] = articulo;
        drArticulosSeleccionados["Cantidad"] = cantidad;
        drArticulosSeleccionados["PrecioUnitario"] = Convert.ToDouble(preciounitario);
        drArticulosSeleccionados["Detalle"] = Convert.ToString(descripcion);
        if (cantidad > 0 && preciounitario > 0)
        {
            subtotal = cantidad * preciounitario;
            if (subtotal > 0)
            {
                drArticulosSeleccionados["SubtotalArticulo"] = Convert.ToDouble(subtotal);
            }
            else
            {
                drArticulosSeleccionados["SubtotalArticulo"] = Convert.ToDouble("0.00");
            }
        }
        else
        {
            if (cantidad == 0)
            {
                objValidaciones.MostrarAviso("La cantidad de artículos debe ser mayor que 0", true, lblAviso1);
            }
            if (preciounitario == 0)
            {
                objValidaciones.MostrarAviso("El precio unitario de cada artículo debe ser mayor que 0", true, lblAviso1);
            }
        }
        dtGridArticulos.Rows.Add(drArticulosSeleccionados);
        subtotal1 += subtotal;
        if (subtotal1 > 0)
        {
            txtIngSubtot.Text = string.Format("{0:n2}", (Math.Truncate(subtotal1 * 100) / 100));
        }
        else
        {
            txtIngSubtot.Text = "0.00";
        }
        subtotalfinal = subtotal1 * IVA;
        if (subtotalfinal > 0)
        {
            totalfinal = subtotal1 + subtotalfinal;
            txtIvaIngOrden.Text = string.Format("{0:n2}", (Math.Truncate(subtotalfinal * 100) / 100));
            txtIngTotal.Text = string.Format("{0:n2}", (Math.Truncate(totalfinal * 100) / 100));
        }
        else
        {
            txtIngTotal.Text = "0.00";
        }
    }
}
#endregion
    
asked by Alberto Arenas 06.12.2017 в 19:38
source

0 answers