Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Shapes;
- using Microsoft.Phone.Controls;
- using System.Xml.Linq;
- using System.Collections.ObjectModel;
- using System.IO.IsolatedStorage;
- using System.IO;
- using System.Xml;
- using System.Xml.Serialization;
- namespace LasnaoloAppsi
- {
- public partial class OppilasLista : PhoneApplicationPage
- {
- XDocument lista = XDocument.Load("NykyisetKurssit.xml");
- XDocument oppilasInfo = XDocument.Load("Oppilaat.xml");
- private ObservableCollection<Kurssit> _Kurssit = new ObservableCollection<Kurssit>();
- List<Kurssit> selected = new List<Kurssit>();
- string id = string.Empty;
- public OppilasLista()
- {
- InitializeComponent();
- }
- protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
- {
- if (NavigationContext.QueryString.TryGetValue("id", out id))
- {
- var ryhma = (from ryhmaInfo in lista.Descendants("Kurssi")
- where ryhmaInfo.Attribute("id").Value == id
- select new Kurssit
- {
- RyhmanNimi = (string)ryhmaInfo.Element("tunnus").Value
- }).FirstOrDefault();
- PageTitle.Text = ryhma.RyhmanNimi;
- var oppilas = (from oppilaat in oppilasInfo.Descendants("Oppilas")
- where oppilaat.Attribute("ryhma").Value == id
- select new Kurssit
- {
- OppilaanNimi = (string)oppilaat.Element("nimi").Value
- });
- foreach (var item in oppilas)
- _Kurssit.Add(item);
- OppilaidenLista.ItemsSource = _Kurssit;
- }
- base.OnNavigatedTo(e);
- }
- private void Tallenna_Button_Click(object sender, RoutedEventArgs e)
- {
- selected = _Kurssit.Where(x => x.IsChecked == true).ToList();
- const string id1 = "504T11";
- const string id2 = "504T12";
- const string id3 = "504T10";
- const string id4 = "504T09";
- string r504T11 = "People.xml";
- string r504T12 = "People2.xml";
- string r504T10 = "People3.xml";
- string r504T09 = "People4.xml";
- string d504T11 = "CurrentDate504T110";
- string d504T12 = "CurrentDate504T120";
- string d504T10 = "CurrentDate504T100";
- string d504T09 = "CurrentDate504T090";
- switch (id)
- {
- case id1:
- saveLasnaolot(r504T11);
- saveLasnaoloDate(d504T11);
- break;
- case id2:
- saveLasnaolot(r504T12);
- saveLasnaoloDate(d504T12);
- break;
- case id3:
- saveLasnaolot(r504T10);
- saveLasnaoloDate(d504T10);
- break;
- case id4:
- saveLasnaolot(r504T09);
- saveLasnaoloDate(d504T09);
- break;
- }
- }
- public void saveLasnaoloDate(string currentDate)
- {
- int i = 1;
- var settings = IsolatedStorageSettings.ApplicationSettings;
- Kurssit date = new Kurssit()
- {
- Aika = DateTime.Now.ToString("dd/MM/yyyy") + string.Format(" {0}", i.ToString())
- };
- if (settings.Contains(currentDate))
- {
- string findFileNumber = currentDate.Substring(17, 1);
- int foundNum = int.Parse(findFileNumber);
- int newNum = foundNum++;
- string newFilename = currentDate + newNum.ToString();
- settings[newFilename] = date;
- }
- else
- settings.Add(currentDate, date);
- settings.Save();
- }
- public void saveLasnaolot(string fileName)
- {
- // Write to the Isolated Storage
- XmlWriterSettings x_W_Settings = new XmlWriterSettings();
- x_W_Settings.Indent = true;
- using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
- {
- using (IsolatedStorageFileStream stream = ISF.OpenFile(fileName, FileMode.Create))
- {
- XmlSerializer serializer = new XmlSerializer(typeof(List<Kurssit>));
- using (XmlWriter xmlWriter = XmlWriter.Create(stream, x_W_Settings))
- serializer.Serialize(xmlWriter, selected);
- MessageBox.Show("Läsnäolot Tallennettu Arkistoon!!!! " + DateTime.Now.ToString("dd/MM/yyyy"));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement