void DownloadXMLStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) return; XDocument doc = XDocument.Parse(e.Result); //MessageBox.Show(doc.Document.ToString()); XNode firstChild = doc.FirstNode; var rootElement = doc.Elements(); //create a menu StoreMenu theMenu = new StoreMenu(); theMenu.theTableID = tableID; //loop though the XML. EXTRACT string theCats = ""; foreach (XElement root in rootElement) {//at document root theCats += root.Name+" "; var cats = root.Elements(); //Create Catogry List //moved to top to make access in this class everywqhere //at each catagory foreach (XElement cat in cats) {//for each catgory theCats += cat.Attribute("Name").Value + " "; //add categories name to list category tmpCat = new category(cat.Attribute("Name").Value); //get teh childen (items) var catItems = cat.Elements(); List<Items> itemsList = new List<Items>(); foreach (XElement item in catItems) { Items tmpItem = new Items(item.Attribute("Name").Value, item.Attribute("Desciption").Value, item.Attribute("Price").Value, item.Attribute("ID").Value); itemsList.Add(tmpItem); theCats += item.Attribute("Name").Value + " "; } tmpCat.theItems = itemsList; theCategoriesList.Add(tmpCat); } int lawlfake = theCategoriesList.Count; //Application.Current.ApplicationLifetimeObjects.Add(theCategoriesList); //NavigationService.Navigate(new Uri("/PanoramaPage1.xaml", UriKind.Relative)); //ObjectNav.NavigationExtensions.Navigate(this, "/PanoramaPage1.xaml", theCategoriesList); //List<AlphaKeyGroup<category>> DataSource = AlphaKeyGroup<category>.CreateGroups(theCategoriesList, //System.Threading.Thread.CurrentThread.CurrentUICulture, //(category s) => { return s.theName; }, true); //catLongList.ItemsSource = DataSource; //theCats += cat.FirstAttribute.Value; //populate pano with menu //List<string> tmpstringlist = new List<string>(); int count=0; foreach (category TMPCAT in theCategoriesList) { List<string> tmpstringlist = new List<string>(); foreach (Items tmpitems in TMPCAT.theItems) { tmpstringlist.Add("+ "+tmpitems.theName); tmpstringlist.Add(" " + tmpitems.theDescription); } switch (count) { case 0: llDrinks.ItemsSource = tmpstringlist.ToList(); break; case 1: llStarter.ItemsSource = tmpstringlist.ToList(); break; case 2: llMain.ItemsSource = tmpstringlist.ToList(); break; case 3: llDesert.ItemsSource = tmpstringlist.ToList(); break; } count++; } //foreach (category cat in theCategoriesList) //{ // panoPaneDrinks.Header = cat.theName; // foreach (Items item in cat.theItems) // { // List<AlphaKeyGroup<Items>> DataSource = AlphaKeyGroup<Items>.CreateGroups(cat.theItems, // System.Threading.Thread.CurrentThread.CurrentUICulture, // (Items s) => { return s.theName; }, true); // } //} } //MessageBox.Show(theCats); updateSummary(); }
void DownloadXMLStringCompleted2(object sender, DownloadStringCompletedEventArgs e) { if (e.Error != null) return; XDocument doc = XDocument.Parse(e.Result); var cats = doc.Descendants("category"); foreach (var category in cats) { int count = 0; foreach (category catry in theCategoriesList) { if (catry.theName == category.Value) { count++; } } if (count == 0) { theCategoriesList.Add(new category(category.Value)); } } int yes = theCategoriesList.Count; //now add items to right categori var items = doc.Descendants("item"); foreach (category catry in theCategoriesList) { List<Items> IList = new List<Items>(); foreach (var item in items) { XElement catergory = (XElement)item.FirstNode.NextNode; string catgory = catergory.Value; if(catgory == catry.theName) {//PROCEED Items tmpItem = new Items(); XElement IDEl = (XElement)item.FirstNode; int id = int.Parse(IDEl.Value); tmpItem.theID = id; XElement Price = (XElement)item.FirstNode.NextNode.NextNode; float price = float.Parse(Price.Value); tmpItem.thePrice = price; XElement Name = (XElement)item.FirstNode.NextNode.NextNode.NextNode; string name = Name.Value; tmpItem.theName = name; XElement Des = (XElement)item.FirstNode.NextNode.NextNode.NextNode.NextNode; string des = Des.Value; tmpItem.theDescription = des; IList.Add(tmpItem); } } catry.theItems = IList; } yes = theCategoriesList.Count; int count2 = 0; foreach (category TMPCAT in theCategoriesList) { List<string> tmpstringlist = new List<string>(); foreach (Items tmpitems in TMPCAT.theItems) { tmpstringlist.Add("+ " + tmpitems.theName); //tmpstringlist.Add(" " + tmpitems.theDescription); } switch (count2) { case 0: llStarter.ItemsSource = tmpstringlist.ToList(); break; case 1: llDesert.ItemsSource = tmpstringlist.ToList(); break; case 2: llMain.ItemsSource = tmpstringlist.ToList(); break; case 3: llDrinks.ItemsSource = tmpstringlist.ToList(); break; } count2++; } updateSummary(); }