예제 #1
0
        /// <summary>
        /// Odebrat aktuální výrobek.
        /// </summary>
        private void btnRemove_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBoxResult.Yes;

            if (lbProducts.SelectedItem != null && (result == MessageBox.Show("Skutečně odstranit zvolenou položku? \n" + lbProducts.SelectedItem.ToString(), "Odstranění položky", MessageBoxButton.YesNo, MessageBoxImage.Question)))
            {
                ShoppingSession.DeleteItemFromShoppingCart(lbProducts.Items.IndexOf(lbProducts.SelectedItem));
                tbPrice.Text = ShoppingSession.SumString;
                lbProducts.Items.RemoveAt(lbProducts.Items.IndexOf(lbProducts.SelectedItem));

                lbProducts.SelectedIndex = -1;
                btnRemove.Visibility     = Visibility.Hidden;
                SetStornoButton();
            }
        }
예제 #2
0
        /// <summary>
        /// Tlačítko pro potvrzení zvoleného výrobku a jeho množství.
        /// </summary>
        private void btnEnter_Click(object sender, RoutedEventArgs e)
        {
            if (ShoppingSession.CurrentProduct == null)
            {
                int code = 0;
                try
                {
                    code = Convert.ToInt32(tbProductCode.Text);
                }
                catch
                {
                    tbProductCode.Background = Brushes.LightPink;
                    return;
                }


                Product p = StorageSetup.GetProduct(code);
                ShoppingSession.CurrentProduct = p;

                if (p == null)
                {
                    tbProductCode.Background = Brushes.LightPink;
                    return;
                }
                else
                {
                    tbProductCode.ClearValue(TextBox.BackgroundProperty);

                    if (!ShoppingSession.CurrentProduct.priceForUnit)
                    {
                        tbProductCode.Text += " - " + StorageSetup.GetProductFullName(ShoppingSession.CurrentProduct);
                    }
                    else
                    {
                        tbProductCode.Text += " - " + ShoppingSession.CurrentProduct.name.Trim();
                    }
                }
            }


            if (!_quantityFill)
            {
                tbQuantity.IsEnabled    = true;
                tbProductCode.IsEnabled = false;
                tbQuantity.Focus();
                _quantityFill = true;

                if (ShoppingSession.CurrentProduct.priceForUnit)
                {
                    lblQuantity.Content = "Množství (" + StorageSetup.GetProductUnitName(ShoppingSession.CurrentProduct) + ")";
                }
                else
                {
                    lblQuantity.Content = "Množství";
                }
            }
            else
            {
                decimal quantity = 0;
                try
                {
                    // Při účtování za kus není možné zadat desetinné číslo
                    if (!ShoppingSession.CurrentProduct.priceForUnit && !HelperClass.IsInteger(tbQuantity.Text))
                    {
                        throw new NotImplementedException();
                    }


                    quantity = Convert.ToDecimal(tbQuantity.Text);

                    // Nenulovost a nezápornost množství
                    if (quantity <= 0)
                    {
                        throw new NotImplementedException();
                    }


                    tbQuantity.ClearValue(TextBox.BackgroundProperty);
                }
                catch
                {
                    tbQuantity.Background = Brushes.LightPink;
                    return;
                }



                decimal?price = quantity * ShoppingSession.CurrentProduct.price;
                ShoppingSession.Sum += price;

                string productDesc = null;
                if (ShoppingSession.CurrentProduct.priceForUnit)
                {
                    productDesc = ShoppingSession.CurrentProduct.name.Trim() + " " + quantity.ToString() + StorageSetup.GetProductUnitName(ShoppingSession.CurrentProduct) + " - " + ShoppingSession.CurrentProduct.price + " Kč/" + StorageSetup.GetProductUnitName(ShoppingSession.CurrentProduct) + " [Celkem: " + price.ToString() + " Kč]";
                }
                else
                {
                    productDesc = StorageSetup.GetProductFullName(ShoppingSession.CurrentProduct) + " - " + ShoppingSession.CurrentProduct.price + " Kč/Kus " + "(" + tbQuantity.Text + "x)" + " [Celkem: " + price.ToString() + " Kč]";
                }
                lbProducts.Items.Add(productDesc);

                ScrollToBottom(lbProducts);

                ShoppingSession.AddItemToShoppingCart(ShoppingSession.CurrentProduct, quantity, productDesc, lbProducts.Items.Count - 1, price, StorageSetup.GetProductUnitName(ShoppingSession.CurrentProduct));


                tbProductCode.Text             = "";
                tbQuantity.Text                = "";
                ShoppingSession.CurrentProduct = null;
                _quantityFill = false;

                tbQuantity.IsEnabled    = false;
                tbProductCode.IsEnabled = true;
                tbProductCode.Focus();
                tbPrice.Text        = ShoppingSession.SumString;
                lblQuantity.Content = "Množství";
            }



            SetStornoButton();
        }