コード例 #1
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;
        }
コード例 #2
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);
                            }
                        }
                    }
                }
            }
        }