Ejemplo n.º 1
0
        public async void Save()
        {
            bool isEmpty = GenerarCompras.Any();

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

                    if (resultado == MessageDialogResult.Affirmative)
                    {
                        Compra ultimoRegistro = compra.Save(Convert.ToInt16(this.NumeroDocumento), Convert.ToInt16(Mensajes.Nit.Text.ToString()), DateTime.Today, Convert.ToDecimal(this.Total));
                        foreach (DetalleCompra row in GenerarCompras.ToList())
                        {
                            detalleCompra.Save(ultimoRegistro.IdCompra, row.CodigoProducto, row.Cantidad, row.Precio, row.SubTotal);
                            this.GenerarCompras.Remove(row);
                            productoUpdate.updateIncrementoExistencia(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.NumeroDocumento = "";
                        this.Existencia      = "";
                        await Mensajes.ShowMessageAsync("Exito", "Compra Ingresada correctamente");

                        foreach (Producto row in actualizado.ShowList2())
                        {
                            this.Productos.Add(row);
                        }
                    }
                    else
                    {
                        await Mensajes.ShowMessageAsync("Error", "No se ingreso ninguna compra");
                    }
                }
                catch (Exception e)
                {
                    await Mensajes.ShowMessageAsync("Numero Documento debe ser de tipo numero entero", e.Message);
                }
            }
            else
            {
                await Mensajes.ShowMessageAsync("Error", "Debe de haber registros para la compra y elegir un proveedor");
            }
        }