Пример #1
0
        /// <summary>
        /// Acción al añadir un descuento en una venta.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddDiscount_Click(object sender, RoutedEventArgs e)
        {
            // Obtener contenedor.
            DataTemplate auxDT = (FormGrid.Children[0] as ContentPresenter).ContentTemplate;

            // Obtener elementos de la GUI
            TextBox    searchDiscounts = (TextBox)auxDT.FindName("DiscountSearch", (ContentPresenter)FormGrid.Children[0]);
            StackPanel discountSP      = (StackPanel)auxDT.FindName("Discounts", (ContentPresenter)FormGrid.Children[0]);

            // Crear variable y conexión para el descuento.
            DiscountsConn dc = new DiscountsConn();

            // Discount discount;

            try
            {
                selDisc = dc.Get(int.Parse(searchDiscounts.Text)); // Intentar buscar el ID transformado.
                if (selDisc == null)
                {
                    throw new Exception();
                }
                relationDisc[(ActivityList.SelectedItem as ContentPresenter)] = selDisc;
            }
            catch
            {
                Error error = new Error("El ID del descuento introducido no esta aceptado.");
                error.Show(); // Si da algún error mostrar que ha fallado.
                return;
            }

            // Crear y añadir elemento a la lista visual.
            ContentPresenter discountItem = new ContentPresenter();

            discountItem.ContentTemplate = (DataTemplate)Resources["DiscountItem"];
            discountItem.Content         = searchDiscounts.Text;
            discountSP.Children.Clear(); // Solo se permite uno, limpiar antes siempre.
            discountSP.Children.Add(discountItem);

            // Refrescar contador de Total.

            // Si es null Product ser 0.
            float paying;

            if (selProd == null)
            {
                paying = 0;
            }
            else
            {
                paying = selProd.ProdPrice;
            }

            float discounting = selDisc.PricePerc;

            float result = paying - (paying * discounting / 100);

            (auxDT.FindName("Discounted", (ContentPresenter)FormGrid.Children[0]) as TextBox).Text  = discounting.ToString();
            (auxDT.FindName("TotalCost", (ContentPresenter)FormGrid.Children[0]) as TextBlock).Text = "Total: " + result + "€";
        }
Пример #2
0
        /// <summary>
        /// Botón que lanza una petición al servidor para que guarde
        /// el objeto de documento, a traves de la interfaz RESTful.
        /// </summary>
        /// <param name="sender">Objeto pasado por parametro</param>
        /// <param name="e">Evento pasado por parametro</param>
        private void SaveDiscounts_Click(object sender, RoutedEventArgs e)
        {
            Discount discount = new Discount
            {
                Code      = CodeText.Text,
                Desc      = DiscountText.Text,
                PricePerc = float.Parse(PriceDiscountText.Text)
            };

            try
            {
                DiscountsConn discountsConn = new DiscountsConn();
                discountsConn.Add(discount);

                Info infoWindow = new Info("Se ha guardado correctamente, en el servidor, el descuento " + discount.Code);
                infoWindow.Show();
            }
            catch (AdminForbiddenException ex)
            {
                Error errorWindow = new Error(ex.Message);
                errorWindow.Show();
            }
            catch (ExpiredLoginException ex)
            {
                Warning warningWindow = new Warning(ex.Message, "¿Deseas iniciar la sesión?");
                warningWindow.Show();

                warningWindow.Acceptance += (o, i) =>
                {
                    warningWindow.Close();

                    Login loginWindow = new Login();
                    loginWindow.Show();
                };

                warningWindow.Cancellation += (o, i) =>
                {
                    ManagerWindow.Close();
                };
            }
            catch (ServerException ex)
            {
                Error errorWindow = new Error(ex.Message);
                errorWindow.Show();
            }
        }
Пример #3
0
        private void Update()
        {
            ActivityList.Items.Clear();
            FormGrid.Children.Clear();

            SalesConn   sc = new SalesConn();
            RefundsConn rc = new RefundsConn();

            ProductsConn  pc = new ProductsConn();
            DiscountsConn dc = new DiscountsConn();

            List <Sale>   sales   = sc.List;
            List <Refund> refunds = rc.List;

            history.Clear();
            relationProd.Clear();
            relationDisc.Clear();

            selProd = null;
            selDisc = null;

            // Crear elementos.
            Sale     selSale;
            Product  selProduct;
            Discount selDiscount;

            // Recuperar todas las ventas.
            for (int j = 0; j < sales.Count; j++)
            {
                ContentPresenter conItem = new ContentPresenter();
                conItem.Content = sales[j].Id.ToString();

                conItem.ContentTemplate = (DataTemplate)Resources["SaleMenuItem"];

                int max = refunds.Count;

                // Si coincide con alguna devolución convertir elemento de menu en Return.
                for (int k = 0; k < max; k++)
                {
                    if (sales[j].Id == refunds[k].SaleId)
                    {
                        conItem.ContentTemplate = (DataTemplate)Resources["ReturnMenuItem"];
                    }
                }

                // Añadimos el elemento.
                ActivityList.Items.Add(conItem);

                // Obtener Sale, Product y Discount.
                selSale = sales[j];

                try
                {
                    selProduct = pc.Get(selSale.ProdId.Value);
                }
                catch
                {
                    selProduct = null;
                }

                try
                {
                    selDiscount = dc.Get(selSale.DiscId.Value);
                }
                catch
                {
                    selDiscount = null;
                }

                // Se crea su formulario
                ContentPresenter conForm = new ContentPresenter();
                conForm.IsEnabled       = false;
                conForm.ContentTemplate = (DataTemplate)Resources["SaleForm"];
                conForm.ApplyTemplate();

                // Obtener contenedor.
                DataTemplate auxDT = conForm.ContentTemplate;

                // Obtener elementos de la GUI
                StackPanel products  = (StackPanel)auxDT.FindName("Products", conForm);
                StackPanel discounts = (StackPanel)auxDT.FindName("Discounts", conForm);

                float paying = 0;
                // Agregar producto
                if (selSale.ProdId != null && selSale.ProdId != 0)
                {
                    ContentPresenter productItem = new ContentPresenter();
                    productItem.Content         = selSale.ProdId;
                    productItem.ContentTemplate = (DataTemplate)Resources["ProductItem"];

                    products.Children.Clear();
                    products.Children.Add(productItem);

                    Product tmpProduct = pc.Get(int.Parse(productItem.Content.ToString()));
                    paying = tmpProduct.ProdPrice;
                }

                float discounting = 0;
                // Agregar descuento
                if (selSale.DiscId != null && selSale.DiscId != 0)
                {
                    ContentPresenter discountItem = new ContentPresenter();
                    discountItem.Content         = selSale.DiscId;
                    discountItem.ContentTemplate = (DataTemplate)Resources["DiscountItem"];

                    discounts.Children.Clear();
                    discounts.Children.Add(discountItem);

                    Discount tmpDiscount = dc.Get(int.Parse(discountItem.Content.ToString()));
                    discounting = tmpDiscount.PricePerc;

                    (auxDT.FindName("Discounted", conForm) as TextBox).Text = discounting.ToString();
                }

                // INSERTAR TODOS LOS DATOS NUMERICOS

                float result = paying - (paying * discounting / 100);
                (auxDT.FindName("TotalCost", conForm) as TextBlock).Text = "Total: " + result + "€";

                // Dar de alta en History y Relations
                history.Add(conItem, conForm);
                relationProd.Add(conItem, selProduct);
                relationDisc.Add(conItem, selDiscount);
            }
        }