Пример #1
0
        private TotalItem CreateTotalItem(ILineItem item, ICart cart)
        {
            var lineItemPrices = item.GetLineItemPrices(cart.Currency);

            //TODO: Implement taxes if they are needed per item. For taxes to work, order needs to have shipping adress set as the address is needed by epi to calculate tax.
            var totalItem = new TotalItem
            {
                ItemId                   = item.LineItemId,
                Price                    = item.PlacedPrice,
                BasePrice                = item.PlacedPrice,
                Qty                      = item.Quantity,
                RowTotal                 = item.Quantity * item.PlacedPrice,
                BaseRowTotal             = item.Quantity * item.PlacedPrice,
                RowTotalWithDiscount     = lineItemPrices.DiscountedPrice.Amount,
                TaxAmount                = 0,
                BaseTaxAmount            = 0,
                TaxPercent               = 0,
                DiscountAmount           = item.GetDiscountTotal(cart.Currency).Amount,
                BaseDiscountAmount       = item.GetDiscountTotal(cart.Currency).Amount,
                DiscountPercent          = 0,
                PriceIncludingTax        = 0,
                BasePriceIncludingTax    = 0,
                RowTotalIncludingTax     = item.Quantity * item.PlacedPrice,
                BaseRowTotalIncludingTax = item.Quantity * item.PlacedPrice,
                Options                  = "",
                WeeeTaxAppliedAmount     = null,
                WeeeTaxApplied           = null,
                Name                     = item.DisplayName,
                ProductOption            = new ProductOption()
            };

            return(totalItem);
        }
Пример #2
0
        private void getXmlDocumentItem(string fileName)
        {
            xDoc = XDocument.Load(fileName);

            lb_xmlItems.DataSource = null;
            if (lb_xmlItems.Items.Count > 0)
            {
                lb_xmlItems.Items.Clear();
            }

            var q        = xDoc.DescendantNodes().OfType <XCData>().FirstOrDefault();
            var xmlItems =
                from item in xDoc.Descendants("item")
                select new
            {
                Title       = item.Element("title").Value,
                Description = item.Element("description").Value,
                pubDate     = item.Element("pubDate").Value,
                ID          = item.Element("id").Value,
            };

            if (xmlItemList.Count > 0)
            {
                xmlItemList = new List <xmlItem>();
            }

            foreach (var item in xmlItems)
            {
                xmlItemList.Add(new xmlItem(item.ID, item.Title, item.Description, item.pubDate));
            }
            bs.DataSource = xmlItemList;

            TotalItem = xmlItems.Count();
            MaxNum    = 0;
            foreach (var x in xmlItems)
            {
                if (MaxNum < Convert.ToInt32(x.ID))
                {
                    MaxNum = Convert.ToInt32(x.ID);
                }
            }
            label1.Text               = MaxNum.ToString() + ' ' + TotalItem.ToString();
            lb_xmlItems.ValueMember   = "ID";
            lb_xmlItems.DisplayMember = "title";
            lb_xmlItems.DataSource    = bs;
        }
Пример #3
0
        private void AddToCartClicked(object obj)
        {
            ObservableCollection <Account> AccountList;

            AnimalCollection = PostgreSQL.getAllPets();
            AccountList      = PostgreSQL.getAllAccounts();

            lb = obj as ListBox;
            Animal selectedAnimal = lb.SelectedItem as Animal;

            isCartEmpty = (Cart.Count == 0) ? true : false;

            if (Quantity == null)
            {
                MessageBox.Show("Please enter a valid quantity to add to your cart", "Invalid Quantity");
            }
            else
            {
                int purchAmt = int.Parse(Quantity);

                if (selectedAnimal == null)
                {
                    MessageBox.Show("Please select an animal before adding it to your cart", "Invalid Selection");
                }
                else if (selectedAnimal.Price == "Pricele$$")
                {
                    MessageBox.Show("This item cannot be purchased", "The Rock Says:");
                }
                else
                {
                    if (isCartEmpty)
                    {
                        if ((int.Parse(selectedAnimal.Quantity) - purchAmt) < 0)
                        {
                            MessageBox.Show($"Requested Quantity Exceeds the number of {selectedAnimal.Type}s in stock", "Invalid Quantity");
                        }
                        else
                        {
                            selectedAnimal.Quantity        = (int.Parse(selectedAnimal.Quantity) - purchAmt).ToString();
                            selectedAnimal.PurchasedAmount = purchAmt.ToString();
                            Cart.Add(selectedAnimal as object);

                            TotalCost += double.Parse(selectedAnimal.Price.Replace("$", "")) * purchAmt;
                            TotalItem += double.Parse(selectedAnimal.PurchasedAmount);
                            CollectionViewSource.GetDefaultView(lb.ItemsSource).Refresh();

                            foreach (Account a in AccountList)
                            {
                                if (a.id == LoggedInUser.id)   // CHANGE THIS TO ACCOUNT ID
                                {
                                    if (LoggedInUser.CartContent == null)
                                    {
                                        LoggedInUser.CartContent = new ObservableCollection <Animal>();
                                    }
                                    LoggedInUser.CartContent.Add(selectedAnimal);
                                    LoggedInUser.CartTotal = TotalCost.ToString();
                                    LoggedInUser.CartItems = TotalItem.ToString();
                                }
                            }
                            CollectionViewSource.GetDefaultView(selectedAnimal.Quantity).Refresh();
                            PostgreSQL.addShopper(LoggedInUser, selectedAnimal);
                        }
                    }
                    else
                    {
                        foreach (object o in Cart.ToList())
                        {
                            Animal amal = o as Animal;
                            if (amal.Type == selectedAnimal.Type)
                            {
                                MessageBox.Show("You already have that animal in your shopping cart. Click Review Order to change the quantity", "Oopsies");
                            }
                            else
                            {
                                selectedAnimal.Quantity        = (int.Parse(selectedAnimal.Quantity) - purchAmt).ToString();
                                selectedAnimal.PurchasedAmount = purchAmt.ToString();
                                Cart.Add(selectedAnimal as object);

                                TotalCost += double.Parse(selectedAnimal.Price.Replace("$", "")) * purchAmt;
                                TotalItem += double.Parse(selectedAnimal.PurchasedAmount);
                                CollectionViewSource.GetDefaultView(lb.ItemsSource).Refresh();

                                foreach (Account a in AccountList)
                                {
                                    if (a.id == LoggedInUser.id)
                                    {
                                        LoggedInUser.CartContent.Add(selectedAnimal);
                                        LoggedInUser.CartTotal = TotalCost.ToString();
                                        LoggedInUser.CartItems = TotalItem.ToString();
                                    }
                                }
                                CollectionViewSource.GetDefaultView(selectedAnimal.Quantity).Refresh();
                                PostgreSQL.addShopper(LoggedInUser, selectedAnimal);
                            }
                        }
                    }
                }
            }
        }