Advertisement
Guest User

Loading Dates

a guest
Feb 15th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.25 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.Collections.ObjectModel;
  15. using System.Xml.Linq;
  16.  
  17. namespace LasnaoloAppsi
  18. {
  19.     public partial class LasnaoloAjat : PhoneApplicationPage
  20.     {
  21.         XDocument lista = XDocument.Load("NykyisetKurssit.xml");
  22.  
  23.         private ObservableCollection<Kurssit> _Lasnaolot = new ObservableCollection<Kurssit>();
  24.  
  25.         const string id1 = "504T11";
  26.         const string id2 = "504T12";
  27.         const string id3 = "504T10";
  28.         const string id4 = "504T09";
  29.  
  30.         string d504T11 = "CurrentDate504T110";
  31.         string d504T12 = "CurrentDate504T120";
  32.         string d504T10 = "CurrentDate504T100";
  33.         string d504T09 = "CurrentDate504T090";
  34.  
  35.         string id = string.Empty;
  36.  
  37.         public LasnaoloAjat()
  38.         {
  39.             InitializeComponent();
  40.         }
  41.  
  42.         protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
  43.         {
  44.             if (NavigationContext.QueryString.TryGetValue("id", out id))
  45.             {
  46.                 var ryhma = (from ryhmaInfo in lista.Descendants("Kurssi")
  47.                              where ryhmaInfo.Attribute("id").Value == id
  48.                              select new Kurssit
  49.                              {
  50.                                  RyhmanNimi = (string)ryhmaInfo.Element("tunnus").Value
  51.  
  52.                              }).FirstOrDefault();
  53.  
  54.                 PageTitle.Text = ryhma.RyhmanNimi;
  55.  
  56.                 if (LasnaoloAikojenLista.ItemsSource != null)
  57.                 {
  58.                     return;
  59.                 }
  60.  
  61.                 switch (id)
  62.                 {
  63.                     case id1:
  64.  
  65.                         LoadLasnaoloDate(d504T11);
  66.                         break;
  67.  
  68.                     case id2:
  69.  
  70.                         LoadLasnaoloDate(d504T12);
  71.                         break;
  72.  
  73.                     case id3:
  74.  
  75.                         LoadLasnaoloDate(d504T10);
  76.                         break;
  77.  
  78.                     case id4:
  79.  
  80.                         LoadLasnaoloDate(d504T09);
  81.                         break;
  82.  
  83.                 }
  84.             }
  85.  
  86.             base.OnNavigatedTo(e);
  87.         }
  88.  
  89.         public void LoadLasnaoloDate(string currentDate)
  90.         {
  91.             var settings = IsolatedStorageSettings.ApplicationSettings;
  92.  
  93.             Kurssit date;
  94.  
  95.             if (settings.TryGetValue<Kurssit>(currentDate, out date))
  96.             {
  97.                     foreach (string s in settings.Keys)
  98.                         _Lasnaolot.Add(date);
  99.  
  100.                     LasnaoloAikojenLista.ItemsSource = _Lasnaolot;
  101.  
  102.             }
  103.         }
  104.  
  105.         private void LasnaoloAika_HBTN_Click(object sender, RoutedEventArgs e)
  106.         {
  107.             var button2 = (HyperlinkButton)sender;
  108.             var selectedApp2 = (Kurssit)button2.Tag;
  109.  
  110.             NavigationService.Navigate(new Uri("/LasnaoloLista.xaml?id=" + id, UriKind.Relative));
  111.         }
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement