private void Btn_Editar_p_Click(object sender, RoutedEventArgs e)
        {
            List <Venta_dto> listado_pro = new List <Venta_dto>();

            if (txt_id_pro.Text == "")
            {
                MessageBox.Show("Debe seleccionar un producto");
            }
            else
            {
                bool    editar   = false;
                int     id       = int.Parse(txt_id_pro.Text.ToString());
                int     cantidad = int.Parse(txt_Cant_producto.Text.ToString());
                decimal total    = 0;
                decimal subT     = 0;
                decimal IVA      = 0;
                //   Producto_Negocio Prod_Neg = new Producto_Negocio();

                if (Application.Current.Properties["ListadoVenta"] != null)
                {
                    // trae lo que esta en la variable de sesion
                    var jsonValueToGet = JsonConvert.DeserializeObject(Application.Current.Properties["ListadoVenta"].ToString());

                    // lo convierte en un array
                    JArray jsonPreservar = JArray.Parse(jsonValueToGet.ToString());

                    //lo recorre para añadir al listado que luego se mostrará en la grilla
                    foreach (JObject item in jsonPreservar.Children <JObject>())
                    {
                        // estos datos vienen de la grilla, creamosla entidad para añadir al listado

                        Venta_dto entidad = new Venta_dto();
                        entidad.ID = int.Parse(item["ID"].ToString());
                        // entidad.SKU = item["SKU"].ToString();
                        entidad.Descripción = item["Descripción"].ToString();

                        if (id == int.Parse(item["ID"].ToString()) && item["T"].ToString() == "P")
                        {
                            entidad.Cantidad = cantidad;
                            entidad.Total    = (cantidad * decimal.Parse(item["Precio"].ToString())).ToString("n2");
                            editar           = true;
                        }
                        else
                        {
                            entidad.Cantidad = int.Parse(item["Cantidad"].ToString());
                            entidad.Total    = decimal.Parse(item["Total"].ToString()).ToString("n2");
                        }
                        entidad.T      = item["T"].ToString();
                        entidad.Precio = decimal.Parse(item["Precio"].ToString()).ToString("n2");

                        if (cmb_Documento_Vta.Text == "Factura")
                        {
                            subT  = ((total + decimal.Parse(entidad.Total)) * 81) / 100;
                            IVA   = ((total + decimal.Parse(entidad.Total)) * 19) / 100;
                            total = total + decimal.Parse(entidad.Total);
                        }
                        else
                        {
                            subT  = ((total + decimal.Parse(entidad.Total)) * 81) / 100;
                            IVA   = ((total + decimal.Parse(entidad.Total)) * 19) / 100;
                            total = total + decimal.Parse(entidad.Total);
                        }

                        //  total = total + decimal.Parse(entidad.Total);
                        listado_pro.Add(entidad);
                    }
                }

                var jsonValueToSave = JsonConvert.SerializeObject(listado_pro);
                Application.Current.Properties["ListadoVenta"] = jsonValueToSave;
                txt_Sub.Text   = subT.ToString("n2");
                txt_iva.Text   = IVA.ToString("n2");
                txt_total.Text = total.ToString("n2");
                Dt_G_list_pedido.ItemsSource = listado_pro;

                if (editar == true)
                {
                    MessageBox.Show("Cantidad Actualizada");
                    limpiar();
                }
                else
                {
                    MessageBox.Show("El Producto a actualizar no existe!");
                    limpiar();
                }
            }
        }
        private void Btn_Eliminar_p_Click(object sender, RoutedEventArgs e)
        {
            List <Venta_dto> list_prod = new List <Venta_dto>();

            if (txt_descr_producto.Text == "")
            {
                MessageBox.Show("Debe seleccionar un producto");
                limpiar();
            }
            else
            {
                bool    eliminado     = false;
                string  id_prod       = txt_id_pro.Text.ToString();
                int     cantidad_prod = int.Parse(txt_Cant_producto.Text);
                decimal total         = 0;
                decimal subT          = 0;
                decimal IVA           = 0;

                // Aqui trae lo previamente guardado en la grilla, si la variable se session esta nula no entra
                if (Application.Current.Properties["ListadoVenta"] != null)
                {
                    // trae lo que esta en la variable de sesion
                    var jsonValueToGet = JsonConvert.DeserializeObject(Application.Current.Properties["ListadoVenta"].ToString());

                    // lo convierte en un array
                    JArray jsonPreservar = JArray.Parse(jsonValueToGet.ToString());

                    //lo recorre para añadir al listado que luego se mostrará en la grilla
                    foreach (JObject item in jsonPreservar.Children <JObject>())
                    {
                        Venta_dto entidad = new Venta_dto();
                        entidad.ID          = int.Parse(item["ID"].ToString());
                        entidad.Descripción = item["Descripción"].ToString();
                        entidad.Cantidad    = int.Parse(item["Cantidad"].ToString());
                        entidad.Total       = decimal.Parse(item["Total"].ToString()).ToString("n2");
                        entidad.Precio      = decimal.Parse(item["Precio"].ToString()).ToString("n2");
                        entidad.T           = item["T"].ToString();
                        if (cmb_Documento_Vta.Text == "Factura")
                        {
                            subT  = ((total + decimal.Parse(entidad.Total)) * 81) / 100;
                            IVA   = ((total + decimal.Parse(entidad.Total)) * 19) / 100;
                            total = total + decimal.Parse(entidad.Total);
                        }
                        else
                        {
                            subT  = ((total + decimal.Parse(entidad.Total)) * 81) / 100;
                            IVA   = ((total + decimal.Parse(entidad.Total)) * 19) / 100;
                            total = total + decimal.Parse(entidad.Total);
                        }

                        if (id_prod == item["ID"].ToString() && item["T"].ToString() == "P")
                        {
                            eliminado = true;
                            total     = total - decimal.Parse(entidad.Total);
                        }
                        else
                        {
                            list_prod.Add(entidad);
                        }
                    }
                    var jsonValueToSave = JsonConvert.SerializeObject(list_prod);
                    Application.Current.Properties["ListadoVenta"] = jsonValueToSave;

                    txt_Sub.Text   = subT.ToString("n2");
                    txt_iva.Text   = IVA.ToString("n2");
                    txt_total.Text = total.ToString("n2");

                    if (eliminado == true)
                    {
                        MessageBox.Show("Producto eliminado");
                    }
                    else
                    {
                        MessageBox.Show("El producto no existe!");
                    }
                    Dt_G_list_pedido.ItemsSource = list_prod;
                }
                limpiar();
            }
        }
        /////////////////////////////////////////////////
        /////////////////////PRODUCTO////////////////////
        ////////////////////////////////////////////////////
        private void Btn_Agregar_p_Click(object sender, RoutedEventArgs e)
        {
            decimal          total      = 0;
            Producto_Negocio Prod_Neg   = new Producto_Negocio();
            List <Venta_dto> list_venta = new List <Venta_dto>();

            if (cmb_Documento_Vta.Text == "")
            {
                MessageBox.Show("Favor de seleccionar tipo de documento");
                limpiar();
            }
            else
            {
                if (txt_Cant_producto.Text == "" || txt_descr_producto.Text == "")
                {
                    if (txt_Cant_producto.Text == "" && txt_descr_producto.Text == "")
                    {
                        MessageBox.Show("Debe seleccionar un producto y su cantidad");
                    }
                    else
                    {
                        if (txt_descr_producto.Text == "")
                        {
                            MessageBox.Show("Debe seleccionar un producto");
                        }
                        if (txt_Cant_producto.Text == "")
                        {
                            MessageBox.Show("Debe ingresar cantidad");
                        }
                    }
                }
                else
                {
                    bool    existe        = false;
                    string  id_prod       = txt_id_pro.Text.ToString();
                    int     cantidad_prod = int.Parse(txt_Cant_producto.Text);
                    string  txt_tipo      = "P";
                    decimal subT          = 0;
                    decimal IVA           = 0;


                    // Aqui trae lo previamente guardado en la grilla, si la variable se session esta nula no entra
                    if (Application.Current.Properties["ListadoVenta"] != null)
                    {
                        // trae lo que esta en la variable de sesion
                        var jsonValueToGet = JsonConvert.DeserializeObject(Application.Current.Properties["ListadoVenta"].ToString());

                        // lo convierte en un array
                        JArray jsonPreservar = JArray.Parse(jsonValueToGet.ToString());

                        //lo recorre para añadir al listado que luego se mostrará en la grilla
                        foreach (JObject item in jsonPreservar.Children <JObject>())
                        {
                            // estos datos vienen de la grilla, creamosla entidad para añadir al listado

                            Venta_dto entidad = new Venta_dto();
                            entidad.ID = int.Parse(item["ID"].ToString());
                            //entidad.SKU = item["SKU"].ToString();
                            entidad.Descripción = item["Descripción"].ToString();
                            entidad.Cantidad    = int.Parse(item["Cantidad"].ToString());
                            entidad.T           = item["T"].ToString();


                            entidad.Total  = decimal.Parse(item["Total"].ToString()).ToString("n2");
                            entidad.Precio = decimal.Parse(item["Precio"].ToString()).ToString("n2");

                            if (cmb_Documento_Vta.Text == "Factura")
                            {
                                subT  = ((total + decimal.Parse(entidad.Total)) * 81) / 100;
                                IVA   = ((total + decimal.Parse(entidad.Total)) * 19) / 100;
                                total = total + decimal.Parse(entidad.Total);
                            }
                            else
                            {
                                subT  = ((total + decimal.Parse(entidad.Total)) * 81) / 100;
                                IVA   = ((total + decimal.Parse(entidad.Total)) * 19) / 100;
                                total = total + decimal.Parse(entidad.Total);
                            }

                            list_venta.Add(entidad);
                            if (id_prod == item["ID"].ToString() && item["T"].ToString() == "P")
                            {
                                existe = true;
                            }
                        }
                    }

                    if (existe)
                    {
                        MessageBox.Show(" El Producto : " + txt_descr_producto.Text + " ya existe en el listado");
                    }
                    else
                    {
                        DataTable respuesta = Prod_Neg.Buscar_Prod_id(id_prod);
                        foreach (DataRow item in respuesta.Rows)
                        {
                            Venta_dto entidad = new Venta_dto();
                            entidad.ID = int.Parse(item["id_producto"].ToString());
                            // entidad.SKU = item["sku_prod"].ToString();
                            entidad.Descripción = item["descr_producto"].ToString();
                            entidad.Cantidad    = cantidad_prod;


                            entidad.Precio = decimal.Parse(item["precio_prod"].ToString()).ToString("n2");
                            entidad.Total  = (decimal.Parse(item["precio_prod"].ToString()) * cantidad_prod).ToString("n2");


                            entidad.T = txt_tipo;
                            if (cmb_Documento_Vta.Text == "Factura")
                            {
                                subT  = ((total + decimal.Parse(entidad.Total)) * 81) / 100;
                                IVA   = ((total + decimal.Parse(entidad.Total)) * 19) / 100;
                                total = total + decimal.Parse(entidad.Total);
                            }
                            else
                            {
                                subT  = ((total + decimal.Parse(entidad.Total)) * 81) / 100;
                                IVA   = ((total + decimal.Parse(entidad.Total)) * 19) / 100;
                                total = total + decimal.Parse(entidad.Total);
                            }

                            list_venta.Add(entidad);
                        }
                    }

                    // actualiza variable de sesion con los datos actuales de la grilla
                    var jsonValueToSave = JsonConvert.SerializeObject(list_venta);
                    Application.Current.Properties["ListadoVenta"] = jsonValueToSave;

                    txt_Sub.Text   = subT.ToString("n2");
                    txt_iva.Text   = IVA.ToString("n2");
                    txt_total.Text = total.ToString("n2");
                    Dt_G_list_pedido.ItemsSource = list_venta;
                    limpiar();
                }
            }
        }