Advertisement
Guest User

Loading Names

a guest
Feb 15th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Shapes;
  12. using Microsoft.Phone.Controls;
  13. using System.IO.IsolatedStorage;
  14. using System.Xml.Serialization;
  15. using System.IO;
  16. using System.Xml.Linq;
  17.  
  18. namespace LasnaoloAppsi
  19. {
  20.     public partial class LasnaoloLista : PhoneApplicationPage
  21.     {
  22.         string id = string.Empty;
  23.         XDocument lista = XDocument.Load("NykyisetKurssit.xml");
  24.  
  25.         public LasnaoloLista()
  26.         {
  27.             InitializeComponent();
  28.         }
  29.  
  30.         protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
  31.         {
  32.             const string id1 = "504T11";
  33.             const string id2 = "504T12";
  34.             const string id3 = "504T10";
  35.             const string id4 = "504T09";
  36.  
  37.             string r504T11 = "People.xml";
  38.             string r504T12 = "People2.xml";
  39.             string r504T10 = "People3.xml";
  40.             string r504T09 = "People4.xml";
  41.  
  42.             if (NavigationContext.QueryString.TryGetValue("id", out id))
  43.             {
  44.                 var ryhma = (from ryhmaInfo in lista.Descendants("Kurssi")
  45.                              where ryhmaInfo.Attribute("id").Value == id
  46.                              select new Kurssit
  47.                              {
  48.                                  RyhmanNimi = (string)ryhmaInfo.Element("tunnus").Value
  49.  
  50.                              }).FirstOrDefault();
  51.  
  52.                 PageTitle.Text = ryhma.RyhmanNimi;
  53.  
  54.                 switch (id)
  55.                 {
  56.                     case id1:
  57.  
  58.                         LoadLasnaolot(r504T11);
  59.                         break;
  60.  
  61.                     case id2:
  62.  
  63.                         LoadLasnaolot(r504T12);
  64.                         break;
  65.  
  66.                     case id3:
  67.                         LoadLasnaolot(r504T10);  
  68.                         break;
  69.  
  70.                     case id4:
  71.                         LoadLasnaolot(r504T09);
  72.                         break;
  73.                 }
  74.             }
  75.  
  76.            
  77.             base.OnNavigatedTo(e);
  78.         }
  79.  
  80.         public void LoadLasnaolot(string filename)
  81.         {
  82.             try
  83.             {
  84.                 using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
  85.                 {
  86.                     using (IsolatedStorageFileStream str = ISF.OpenFile(filename, FileMode.Open))
  87.                     {
  88.                         XmlSerializer serializer = new XmlSerializer(typeof(List<Kurssit>));
  89.                         List<Kurssit> l1 = (List<Kurssit>)serializer.Deserialize(str);
  90.                         this.LasnaoloListax.ItemsSource = l1;
  91.                     }
  92.                 }
  93.             }
  94.             catch
  95.             {
  96.                 //add some code here
  97.             }
  98.  
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement