Exemplo n.º 1
0
        public void ReadDiscountCuopones()
        {
            string[] discount = File.ReadAllLines("Discount.csv");

            foreach (var item in discount)
            {
                readCouponesArray = item.Split(',');
                DiscountCoupone coupone = new DiscountCoupone()
                {
                    Code       = readCouponesArray[0],
                    Percentage = double.Parse(readCouponesArray[1]),
                    IsUsed     = false
                };
                discountCouponesList.Add(coupone);
            }
        }
Exemplo n.º 2
0
        public void CalculateDiscount(string input, Label totalprice)
        {
            bool Valid = false;

            foreach (var code in discountCouponesList)
            {
                if (input == code.Code && code.IsUsed == false)
                {
                    Valid       = true;
                    code.IsUsed = true;

                    break;
                }
            }

            if (discountCouponesList.Where(s => s.Code == input).Select(s => s).FirstOrDefault() != null)
            {
                Coupone = discountCouponesList.Where(s => s.Code == input).Select(s => s).FirstOrDefault();

                if (Coupone.IsUsed == true && Valid == false)
                {
                    MessageBox.Show("Den kod är redan använd");
                }
                else if (Valid == true && total > 0)
                {
                    double discountedTotal = Math.Round(total - (total * Coupone.Percentage / 100), 2);
                    totalprice.Content = "Ditt totala belopp är: " + discountedTotal + " kr";
                    total = discountedTotal;

                    basketStackPanel.Children.Remove(totalPriceLabel);
                    basketStackPanel.Children.Add(totalPriceLabel);
                    basketStackPanel.Children.Remove(buttonsPanel);
                    basketStackPanel.Children.Add(buttonsPanel);
                    Valid = false;

                    MessageBox.Show("Din rabatt kod är accepterad!");
                }
            }

            if (discountCouponesList.Count(a => a.Code == input) == 0)
            {
                MessageBox.Show("Ogiltig rabatt kod!");
            }

            discountTextBox.Clear();
        }