public async void Cancel()
        {
            var respuesta = await Mensajes.ShowMessageAsync("Esta seguro de eliminar la factura", "Eliminar",
                                                            MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings
            {
                AffirmativeButtonText = "Si",
                NegativeButtonText    = "No",
                AnimateShow           = true,
                AnimateHide           = false
            });

            if (respuesta == MessageDialogResult.Affirmative)
            {
                try
                {
                    foreach (GenerarVenta row in GenerarVentas.ToList())
                    {
                        this.GenerarVentas.Remove(row);
                    }
                    this.Total = "0";
                    this.Nit   = "";
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show(e.Message);
                }

                await Mensajes.ShowMessageAsync("Exito", "Factura eliminada Correctamente");
            }

            else
            {
                await Mensajes.ShowMessageAsync("Eliminar", "No se elimino ningun registro");
            }
        }
        public void Add()
        {
            GenerarVenta nuevo         = new GenerarVenta();
            decimal      totalTemporal = 0;

            if (this.SelectProducto != null && !this.CantidadProducto.Equals(""))
            {
                if (Convert.ToInt16(this.CantidadProducto) <= Convert.ToInt16(this.Existencia))
                {
                    try
                    {
                        if (Convert.ToInt16(this.CantidadProducto) <= 11)
                        {
                            nuevo.PrecioUnitario = Convert.ToDecimal(this.PrecioUnitario);
                        }
                        else if (Convert.ToInt16(this.CantidadProducto) <= 15)
                        {
                            nuevo.PrecioUnitario = Convert.ToDecimal(this.PrecioPorDocena);
                        }
                        else if (Convert.ToInt16(this.CantidadProducto) > 15)
                        {
                            nuevo.PrecioUnitario = Convert.ToDecimal(this.PrecioPorMayor);
                        }
                        nuevo.CodigoProducto = this.SelectProducto.CodigoProducto;
                        nuevo.Descripcion    = this.SelectProducto.Descripcion;
                        nuevo.Cantidad       = Convert.ToInt16(this.CantidadProducto);
                        nuevo.Total          = (Convert.ToInt16(this.CantidadProducto) * nuevo.PrecioUnitario);
                        this.GenerarVentas.Add(nuevo);

                        foreach (GenerarVenta row in GenerarVentas.ToList())
                        {
                            totalTemporal = totalTemporal + Convert.ToDecimal(row.Total);
                        }
                        this.Total = totalTemporal.ToString();
                    }
                    catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.ToString()); }
                }
            }
            else
            {
                Mensajes.ShowMessageAsync("Error", "Debe seleccionar alguna fila e ingresar una cantidad");
            }

            this.CantidadProducto = "";
        }
        public async void Delete()
        {
            decimal totalTemporal = 0;

            if (this.SelectGenerarVenta != null)
            {
                var respuesta = await Mensajes.ShowMessageAsync("Esta seguro de eliminar el registro", "Eliminar",
                                                                MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings
                {
                    AffirmativeButtonText = "Si",
                    NegativeButtonText    = "No",
                    AnimateShow           = true,
                    AnimateHide           = false
                });

                if (respuesta == MessageDialogResult.Affirmative)
                {
                    try
                    {
                        this.GenerarVentas.Remove(this.SelectGenerarVenta);
                        foreach (GenerarVenta row in GenerarVentas.ToList())
                        {
                            totalTemporal = totalTemporal + Convert.ToDecimal(row.Total);
                        }
                        this.Total = totalTemporal.ToString();
                    }
                    catch (Exception e)
                    {
                        System.Windows.MessageBox.Show(e.Message);
                    }

                    await Mensajes.ShowMessageAsync("Exito", "Registro eliminado Correctamente");
                }

                else
                {
                    await Mensajes.ShowMessageAsync("Eliminar", "No se elimino ningun registro");
                }
            }
            else
            {
                await Mensajes.ShowMessageAsync("Eliminar", "Debe seleccionar un registro");
            }
        }
        public async void Save()
        {
            bool isEmpty = GenerarVentas.Any();

            if (isEmpty && !Mensajes.Nit.Text.ToString().Equals(""))
            {
                try
                {
                    var resultado = await Mensajes.ShowMessageAsync("Agregando", "Desea generar una nueva factura",
                                                                    MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings
                    {
                        AffirmativeButtonText = "Si",
                        NegativeButtonText    = "No",
                        AnimateShow           = true,
                        AnimateHide           = false
                    });

                    if (resultado == MessageDialogResult.Affirmative)
                    {
                        Factura ultimoRegistro = factura.Save(Mensajes.Nit.Text.ToString(), DateTime.Today, Convert.ToDecimal(this.Total));
                        foreach (GenerarVenta row in GenerarVentas.ToList())
                        {
                            detalleFactura.Save(ultimoRegistro.Numerofactura, row.CodigoProducto, row.Cantidad, row.PrecioUnitario, 0);
                            this.GenerarVentas.Remove(row);
                            productoUpdate.updateExistencia(row.CodigoProducto, row.Cantidad);
                        }
                        foreach (Producto row in Productos.ToList())
                        {
                            this.Productos.Remove(row);
                        }


                        //CollectionViewSource.GetDefaultView(this.Productos).Refresh();

                        ProductoModel actualizado = new ProductoModel();
                        this.Total           = "0";
                        this.Nit             = "";
                        this.PrecioPorDocena = "";
                        this.PrecioPorMayor  = "";
                        this.PrecioUnitario  = "";
                        this.Cantidad        = "";
                        this.Existencia      = "";
                        await Mensajes.ShowMessageAsync("Exito", "Factura Ingresada correctamente");

                        foreach (Producto row in actualizado.ShowList2())
                        {
                            this.Productos.Add(row);
                        }
                    }
                    else
                    {
                        await Mensajes.ShowMessageAsync("Error", "No se ingreso ninguna factura");
                    }
                }
                catch (Exception e)
                {
                    await Mensajes.ShowMessageAsync("Error", e.Message);
                }
            }
            else
            {
                await Mensajes.ShowMessageAsync("Error", "Debe de haber registros para facturar y elegir un cliente");
            }
        }