Exemple #1
0
        public void CustomerReceipt()
        {
            scroll                 = new ScrollViewer();
            scroll.Content         = cartGrid;
            cartGrid.ShowGridLines = true;

            cartGrid.Background    = Brushes.Pink;
            cartGrid.ShowGridLines = false;
            cartGrid.ColumnDefinitions.Add(new ColumnDefinition());
            cartGrid.ColumnDefinitions.Add(new ColumnDefinition());
            cartGrid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            cartGrid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            cartGrid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            cartGrid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            cartGrid.RowDefinitions.Add(new RowDefinition());

            Label companyName = new Label
            {
                Content             = "SaMic",
                HorizontalAlignment = HorizontalAlignment.Center,
                Background          = Brushes.AliceBlue,
                FontSize            = 35,
            };

            cartGrid.Children.Add(companyName);
            Grid.SetRow(companyName, 0);
            Grid.SetColumnSpan(companyName, 2);

            Label name = new Label
            {
                Content  = "Your product:",
                FontSize = 25,
            };

            cartGrid.Children.Add(name);
            Grid.SetRow(name, 1);
            Grid.SetColumn(name, 0);

            itemGrid = new Grid();
            Grid.SetRow(itemGrid, 2);
            Grid.SetColumnSpan(itemGrid, 2);
            cartGrid.Children.Add(itemGrid);

            string[] tmpProd = FileManager.ShowCuredProducts();
            foreach (var item in ProductCollection)
            {
                for (int i = 0; i < tmpProd.Length; i++)
                {
                    string[] splitTmp = tmpProd[i].Split(';');

                    if (item.Key.Contains(splitTmp[1]))
                    {
                        int cost = int.Parse(splitTmp[3]);
                        CartItems.Add(new CartItem(item.Key, item.Value, cost));
                    }
                }
            }

            for (int i = 0; i < CartItems.Count; i++)
            {
                CartItems[i].InitializeGrid();
                CartItems[i].Btn.Click += RemoveItem_Click;
                itemGrid.RowDefinitions.Add(new RowDefinition());
                Grid.SetRow(CartItems[i].ReturnGrid(), i);
                itemGrid.Children.Add(CartItems[i].ReturnGrid());
            }

            StackPanel discountPanel = new StackPanel
            {
                Orientation = Orientation.Vertical
            };

            Grid.SetRow(discountPanel, 3);
            Grid.SetColumn(discountPanel, 0);
            cartGrid.Children.Add(discountPanel);

            Label discountLabel = new Label
            {
                Content    = "Select a discount code",
                FontSize   = commonFontSize,
                FontWeight = FontWeights.SemiBold,
                Margin     = new Thickness(0, 10, 0, 3)
            };

            discountPanel.Children.Add(discountLabel);

            combo = new ComboBox
            {
                Width = 300,
                HorizontalAlignment = HorizontalAlignment.Left,
                FontSize            = commonFontSize,
                Margin = new Thickness(0, 0, 0, 10)
            };
            discountPanel.Children.Add(combo);
            combo.SelectionChanged += Combo_SelectionChanged;

            StackPanel summaryPanel = new StackPanel
            {
                Orientation         = Orientation.Vertical,
                HorizontalAlignment = HorizontalAlignment.Left
            };

            Grid.SetRow(summaryPanel, 3);
            Grid.SetColumn(summaryPanel, 1);
            cartGrid.Children.Add(summaryPanel);

            foreach (CartItem c in CartItems)
            {
                totalPrice += c.singlePrice * c.Amount;
            }

            totalPriceText = new Label
            {
                Content    = "Total Price:\t" + totalPrice + " SEK",
                FontSize   = commonFontSize,
                FontWeight = FontWeights.SemiBold,
                Margin     = new Thickness(0, 10, 0, 0)
            };
            summaryPanel.Children.Add(totalPriceText);

            showDiscountText = new Label
            {
                Content    = "Discount:\t",
                FontSize   = commonFontSize,
                FontWeight = FontWeights.SemiBold
            };
            summaryPanel.Children.Add(showDiscountText);

            discountedAmntText = new Label
            {
                Content    = "Subtotal:\t" + totalPrice + " SEK",
                FontSize   = commonFontSize,
                FontWeight = FontWeights.SemiBold
            };
            summaryPanel.Children.Add(discountedAmntText);

            List <string> voucherCode = FileManager.ShowCuredVouchers().ToList();
            int           index       = 0;

            while (index < voucherCode.Count)
            {
                string[] info = voucherCode[index].Split(';');
                combo.Items.Add(info[0] + "\t" + info.Last() + "%");
                index++;
            }

            StackPanel botLeftPanel = new StackPanel
            {
                Orientation = Orientation.Horizontal,
            };

            Grid.SetRow(botLeftPanel, 4);
            Grid.SetColumn(botLeftPanel, 0);
            cartGrid.Children.Add(botLeftPanel);

            Button keepShopping = new Button
            {
                Content             = "<< Keep Shopping",
                FontWeight          = FontWeights.SemiBold,
                Margin              = new Thickness(0, 0, 20, 0),
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Top,
                MinWidth            = 150,
                Height              = 40,
                Foreground          = Brushes.Black,
                Background          = Brushes.Gold,
                FontSize            = 15,
            };

            keepShopping.Click += KeepShopping_Click;
            botLeftPanel.Children.Add(keepShopping);

            Button saveCart = new Button
            {
                Content             = "Download Cart",
                FontWeight          = FontWeights.SemiBold,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Top,
                MinWidth            = 150,
                Height     = 40,
                Foreground = Brushes.Black,
                Background = Brushes.DodgerBlue,
                FontSize   = 15,
            };

            saveCart.Click += SaveCart_Click;
            botLeftPanel.Children.Add(saveCart);

            pay = new Button
            {
                Content             = "Pay",
                FontWeight          = FontWeights.SemiBold,
                MinWidth            = 150,
                Height              = 40,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Foreground          = Brushes.White,
                Background          = Brushes.Green,
                FontSize            = 15
            };
            pay.Click += Pay_Click;
            Grid.SetRow(pay, 4);
            Grid.SetColumn(pay, 1);
            cartGrid.Children.Add(pay);
        }