Beispiel #1
0
        private void PrintBtn_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveDialog = new SaveFileDialog
            {
                Filter = "PDF file (*.pdf)|*.pdf"
            };

            if (saveDialog.ShowDialog() == true)
            {
                var s           = saveDialog.FileName;
                var fileCreated = DocumentsCreator.ProductsList(_productsOc, saveDialog.FileName);
                if (fileCreated)
                {
                    ParentView.Show_MessageView("El documento ha sido creado con éxito",
                                                //affirmative action
                                                delegate
                    {
                        ParentView.Show_ProductsView();
                    },
                                                "Aceptar",
                                                //negative action
                                                null,
                                                null,
                                                FontAwesome.WPF.FontAwesomeIcon.CheckCircle
                                                );
                }
                else
                {
                    ParentView.Show_MessageView("Hubo un problema al crear el documento\nComuniquese a soporte técnico",
                                                //affirmative action
                                                delegate
                    {
                        ParentView.Show_ProductsView();
                    },
                                                "Aceptar",
                                                //negative action
                                                null,
                                                null,
                                                FontAwesome.WPF.FontAwesomeIcon.ExclamationCircle
                                                );
                }
            }
        }
Beispiel #2
0
 private void DeleteBtn_Click(object sender, RoutedEventArgs e)
 {
     if (!(ProductsDgd.SelectedItem is Products product))
     {
         return;
     }
     try
     {
         using (var db = App.DbFactory.Open())
         {
             db.Delete(product);
         }
         ParentView.Show_MessageView("El producto se ha eliminado con éxito",
                                     //affirmative action
                                     delegate
         {
             ParentView.Show_ProductsView();
         },
                                     "Aceptar",
                                     //negative action
                                     null,
                                     null,
                                     FontAwesome.WPF.FontAwesomeIcon.CheckCircle
                                     );
     }
     catch (Exception)
     {
         ParentView.Show_MessageView("Hubo un problema al eliminar el producto\nComuniquese a soporte técnico",
                                     //affirmative action
                                     delegate
         {
             ParentView.Show_ProductsView();
         },
                                     "Aceptar",
                                     //negative action
                                     null,
                                     null,
                                     FontAwesome.WPF.FontAwesomeIcon.ExclamationCircle
                                     );
     }
 }
 private void CancelBtn_Click(object sender, RoutedEventArgs e)
 {
     ParentView.Show_ProductsView();
 }
        private void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            var name              = ProductTxt.Text;
            var categoryParsed    = Enum.TryParse(CategoryCmb.Text, out ProductCategory category);
            var priceParsed       = decimal.TryParse(PriceTxt.Text, out decimal price);
            var packageUnitParsed = Enum.TryParse(UnitCmb.Text, out PackageUnit packageUnit);
            var weightParsed      = decimal.TryParse(WeightTxt.Text, out decimal weight);
            var wasteParsed       = decimal.TryParse(WasteTxt.Text, out decimal waste);
            var yieldParsed       = decimal.TryParse(YieldTxt.Text, out decimal yield);

            if (name == "" || name == string.Empty)
            {
                WarningTbk.Text       = "Ingrese el nombre del producto";
                WarningTbk.Visibility = Visibility.Visible;
            }
            else if (!categoryParsed || CategoryCmb.Text == "-Seleccione una opción-")
            {
                WarningTbk.Text       = "Verifique que haya seleccionado una categoría";
                WarningTbk.Visibility = Visibility.Visible;
            }
            else if (!priceParsed)
            {
                WarningTbk.Text       = "Ingrese el precio del producto";
                WarningTbk.Visibility = Visibility.Visible;
            }
            else if (!packageUnitParsed || UnitCmb.Text == "-Seleccione una opción-")
            {
                WarningTbk.Text       = "Verifique que haya seleccionado una unidad de medida";
                WarningTbk.Visibility = Visibility.Visible;
            }
            else if (!weightParsed)
            {
                WarningTbk.Text       = "Ingrese el peso del producto";
                WarningTbk.Visibility = Visibility.Visible;
            }
            else if (!wasteParsed)
            {
                WarningTbk.Text       = "Ingrese el porcentaje de merma";
                WarningTbk.Visibility = Visibility.Visible;
            }
            else if (!yieldParsed)
            {
                WarningTbk.Text       = "Verifique que todos los datos se hayan ingresado";
                WarningTbk.Visibility = Visibility.Visible;
            }
            else if (Cost <= 0)
            {
                WarningTbk.Text       = "Verifique que todos los datos se hayan ingresado";
                WarningTbk.Visibility = Visibility.Visible;
            }
            else
            {
                if (_product != null)
                {
                    try
                    {
                        if (weight != 1)
                        {
                            var yieldPercent  = yield / 100;
                            var yieldByWeight = 1 / yieldPercent;
                            var priceByOne    = Math.Round(price / weight, 2);
                            var costByOne     = Math.Round(yieldByWeight * priceByOne, 2);
                            using (var db = App.DbFactory.Open())
                            {
                                db.Update(new Products
                                {
                                    Id       = _product.Id,
                                    Name     = name,
                                    Category = category,
                                    Price    = priceByOne,
                                    Unit     = packageUnit,
                                    Weight   = 1,
                                    Waste    = waste,
                                    Yield    = yield,
                                    Cost     = costByOne
                                });
                            }
                        }
                        else
                        {
                            using (var db = App.DbFactory.Open())
                            {
                                db.Update(new Products
                                {
                                    Id       = _product.Id,
                                    Name     = name,
                                    Category = category,
                                    Price    = price,
                                    Unit     = packageUnit,
                                    Weight   = weight,
                                    Waste    = waste,
                                    Yield    = yield,
                                    Cost     = Cost
                                });
                            }
                        }
                        ParentView.Show_MessageView("El producto se ha actualizado con éxito\n¿Deseas guardar uno nuevo?",
                                                    //affirmative action
                                                    delegate
                        {
                            ParentView.Show_NewProductView();
                        },
                                                    null,
                                                    //negative action
                                                    delegate
                        {
                            ParentView.Show_ProductsView();
                        },
                                                    null,
                                                    FontAwesome.WPF.FontAwesomeIcon.CheckCircle
                                                    );
                    }
                    catch (Exception)
                    {
                        ParentView.Show_MessageView("Hubo un problema al actualizar el producto\nComuniquese a soporte técnico",
                                                    //affirmative action
                                                    delegate
                        {
                            ParentView.Show_NewProductView();
                        },
                                                    "Aceptar",
                                                    //negative action
                                                    null,
                                                    null,
                                                    FontAwesome.WPF.FontAwesomeIcon.ExclamationCircle
                                                    );
                    }
                }
                else
                {
                    Products product;
                    if (weight != 1)
                    {
                        var yieldPercent  = yield / 100;
                        var yieldByWeight = 1 / yieldPercent;
                        var priceByOne    = Math.Round(price / weight, 2);
                        var costByOne     = Math.Round(yieldByWeight * priceByOne, 2);
                        product = new Products
                        {
                            Name     = name,
                            Category = category,
                            Price    = priceByOne,
                            Unit     = packageUnit,
                            Weight   = 1,
                            Waste    = waste,
                            Yield    = yield,
                            Cost     = costByOne
                        };
                    }
                    else
                    {
                        product = new Products
                        {
                            Name     = name,
                            Category = category,
                            Price    = price,
                            Unit     = packageUnit,
                            Weight   = weight,
                            Waste    = waste,
                            Yield    = yield,
                            Cost     = Cost
                        };
                    }

                    try
                    {
                        using (var db = App.DbFactory.Open())
                        {
                            db.Save(product);
                        }
                        ParentView.Show_MessageView("El producto se ha guardado con éxito\n¿Deseas guardar otro?",
                                                    //affirmative action
                                                    delegate
                        {
                            ParentView.Show_NewProductView();
                        },
                                                    null,
                                                    //negative action
                                                    delegate
                        {
                            ParentView.Show_ProductsView();
                        },
                                                    null,
                                                    FontAwesome.WPF.FontAwesomeIcon.CheckCircle
                                                    );
                    }
                    catch (Exception)
                    {
                        ParentView.Show_MessageView("Hubo un problema al agregar el producto\nComuniquese a soporte técnico",
                                                    //affirmative action
                                                    delegate
                        {
                            ParentView.Show_NewProductView();
                        },
                                                    "Aceptar",
                                                    //negative action
                                                    null,
                                                    null,
                                                    FontAwesome.WPF.FontAwesomeIcon.ExclamationCircle
                                                    );
                    }
                }
            }
        }