Beispiel #1
0
        private void OrderNowButton_Click(object sender, RoutedEventArgs e)
        {
            Double   productPrice = 0;
            Products product      = (Products)lbProducts.SelectedItem;
            List <OrderDetailAdOns>   orderDetailAdonList    = new List <OrderDetailAdOns>();
            List <OrderDetailOptions> orderDetailOptionsList = new List <OrderDetailOptions>();

            if (UserOrder == null)
            {
                UserOrder = new Orders();
            }
            if (_optionPrice == 0)
            {
                productPrice = product.DefaultBranchProductPrice;
            }
            else
            {
                productPrice = _optionPrice;
            }

            if (UserOrder.OrderDetailsList == null)
            {
                UserOrder.OrderDetailsList = new List <BusinessEntities.OrderDetails>();
                //SessionOrderAdonList = new List<List<BusinessEntities.OrderDetailAdOns>>();
                //SessionOrderDetailOptionList = new List<List<BusinessEntities.OrderDetailOptions>>();
                UserOrder.OrderStatusID = BusinessEntities.OrderStatus.NewOrder;
            }
            BusinessEntities.OrderDetails orderdetail = new BusinessEntities.OrderDetails();
            if (!product.IsSpecial)
            {
                if (_optionPrice > 0)
                {
                    orderdetail.Price = _optionPrice;
                }
                else
                {
                    orderdetail.Price = Convert.ToDouble(product.DefaultBranchProductPrice);
                }
            }
            orderdetail.CategoryName = _category.Name;
            orderdetail.ProductName  = product.Name;
            orderdetail.ProductID    = product.ProductID;
            orderdetail.ProductImage = product.Image;
            orderdetail.Quantity     = 1;
            if (product.IsSpecial)
            {
                MultiPorductControl control = (MultiPorductControl)MultiProductPanel.Children[0];
                orderdetail.Price = control.GetPrice();
                orderdetail.OrderDetailSubProducts = control.GetOrderDetailSubProducts();
                orderdetail.IsGroupProduct         = true;
            }
            else
            {
                #region Get Selected Option


                for (int i = 0; i < lbOptions.Items.Count; i++)
                {
                    DependencyObject obj = lbOptions.ItemContainerGenerator.ContainerFromIndex(i);
                    ContentPresenter optionTypeContentPresenter = FindVisualChild <ContentPresenter>(obj);
                    OptionType       optionType = (OptionType)optionTypeContentPresenter.Content;
                    ListBox          OptionList = FindVisualChild <ListBox>(obj);
                    if (optionType.IsSamePrice && !optionType.IsMultiSelect)
                    {
                        for (int j = 0; j < OptionList.Items.Count; j++)
                        {
                            DependencyObject obj1 = OptionList.ItemContainerGenerator.ContainerFromIndex(j);
                            // Getting the ContentPresenter of myListBoxItem
                            ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(obj1);
                            // Finding textBlock from the DataTemplate that is set on that ContentPresenter
                            DataTemplate myDataTemplate = myContentPresenter.ContentTemplate;
                            RadioButton  selectedOption = (RadioButton)myDataTemplate.FindName("SelectedOption", myContentPresenter);
                            if (selectedOption.IsChecked.Value)
                            {
                                ProductOptions     productOptions    = (ProductOptions)myContentPresenter.Content;
                                OrderDetailOptions orderdetailoption = new OrderDetailOptions();
                                orderdetailoption.ProductOptionId   = productOptions.OptionID;
                                orderdetailoption.ProductOptionName = productOptions.OptionName;
                                orderdetailoption.Price             = Convert.ToDouble(productOptions.Price);
                                orderDetailOptionsList.Add(orderdetailoption);
                                orderdetail.Price = productOptions.Price;
                            }
                        }
                    }
                    else if (!optionType.IsSamePrice && !optionType.IsMultiSelect)
                    {
                        for (int j = 0; j < OptionList.Items.Count; j++)
                        {
                            DependencyObject obj1 = OptionList.ItemContainerGenerator.ContainerFromIndex(j);
                            // Getting the ContentPresenter of myListBoxItem
                            ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(obj1);
                            // Finding textBlock from the DataTemplate that is set on that ContentPresenter
                            DataTemplate myDataTemplate = myContentPresenter.ContentTemplate;
                            RadioButton  selectedOption = (RadioButton)myDataTemplate.FindName("SelectedOption", myContentPresenter);
                            if (selectedOption.IsChecked.Value)
                            {
                                ProductOptions     productOptions    = (ProductOptions)myContentPresenter.Content;
                                OrderDetailOptions orderdetailoption = new OrderDetailOptions();
                                orderdetailoption.ProductOptionId   = productOptions.OptionID;
                                orderdetailoption.ProductOptionName = productOptions.OptionName;
                                orderdetailoption.Price             = productOptions.Price;
                                orderDetailOptionsList.Add(orderdetailoption);
                                orderdetail.Price = productOptions.Price;
                            }
                        }
                    }
                }

                #endregion


                #region Get Selected Toppings


                for (int i = 0; i < lbToppings.Items.Count; i++)
                {
                    DependencyObject obj = lbToppings.ItemContainerGenerator.ContainerFromIndex(i);
                    ContentPresenter adonTypeContentPresenter = FindVisualChild <ContentPresenter>(obj);
                    AdonType         adonType = (AdonType)adonTypeContentPresenter.Content;
                    ListBox          AdonList = FindVisualChild <ListBox>(obj);
                    for (int j = 0; j < AdonList.Items.Count; j++)
                    {
                        DependencyObject obj1 = AdonList.ItemContainerGenerator.ContainerFromIndex(j);
                        // Getting the ContentPresenter of myListBoxItem
                        ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(obj1);
                        // Finding textBlock from the DataTemplate that is set on that ContentPresenter
                        DataTemplate myDataTemplate  = myContentPresenter.ContentTemplate;
                        Int16        SelectedTopping = Convert.ToInt16(((TextBlock)myDataTemplate.FindName("SelectedTopping", myContentPresenter)).Text);
                        if (SelectedTopping != 0)
                        {
                            if (!adonType.IsFreeAdonType)
                            {
                                Adon adon = (Adon)myContentPresenter.Content;

                                OrderDetailAdOns orderdetailadon = new OrderDetailAdOns();
                                orderdetailadon.AdOnId             = adon.AdOnID;
                                orderdetailadon.AdonName           = adon.AdOnName;
                                orderdetailadon.AdonTypeName       = adon.AdOnTypeName;
                                orderdetailadon.SelectedAdonOption = (SelectedOption)SelectedTopping;

                                orderDetailAdonList.Add(orderdetailadon);
                                if (adon.DefaultSelected != SelectedTopping)
                                {
                                    if (_defaultAdonPrice > 0)
                                    {
                                        productPrice += _defaultAdonPrice;
                                    }
                                    else
                                    {
                                        productPrice += (Double)adonType.Price;
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion
            }
            double discountPrice = 0;
            Double.TryParse(txtDiscount.Text, out discountPrice);
            if (discountPrice > 0)
            {
                orderdetail.Price = discountPrice;
            }
            else if (orderdetail.Price == 0)
            {
                orderdetail.Price = productPrice;
            }

            UserOrder.OrderDetailsList.Add(orderdetail);
            UserOrder.OrderTotal += orderdetail.Price;
            OrderDetailOptionList.Add(orderDetailOptionsList);
            OrderDetailAdonList.Add(orderDetailAdonList);

            lbOptions.ItemsSource  = null;
            lbToppings.ItemsSource = null;
            _defaultAdonPrice      = 0;
            _optionPrice           = 0;
            SelectedAdons.Text     = string.Empty;
            txtDiscount.Text       = String.Empty;
            Price.Content          = String.Empty;
            lbProducts.UnselectAll();
            this.Close();
        }
Beispiel #2
0
        private void control_OnUpdatePrice(object sender, EventArgs e)
        {
            MultiPorductControl control = (MultiPorductControl)MultiProductPanel.Children[0];

            Price.Content = control.GetPrice().ToString("C", CultureInfo.CurrentCulture);
        }