private void SaveButton_Click(object sender, EventArgs e) { XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Indent = true; using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { Profile updated = new Profile(); updated.Name = NameTbx.Text; updated.Course = CourseTbx.Text; updated.Insti = InstiTbx.Text; updated.Sem = SemTbx.Text; updated.Work = WorkTbx.Text; using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("Profile.xml", FileMode.Create, myIsolatedStorage)) { XmlSerializer serializer = new XmlSerializer(typeof(Profile)); using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings)) { serializer.Serialize(xmlWriter, updated); } } NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); } }
private void OnLoad(object sender, RoutedEventArgs e) { using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { Profile current = new Profile(); if (myIsolatedStorage.FileExists("Profile.xml")) { using (IsolatedStorageFileStream stream1 = new IsolatedStorageFileStream("Profile.xml", FileMode.Open, FileAccess.Read, myIsolatedStorage)) { XmlSerializer serializer = new XmlSerializer(typeof(Profile)); current = (Profile)serializer.Deserialize(stream1); } NameTbx.Text = current.Name; CourseTbx.Text = current.Course; InstiTbx.Text = current.Insti; SemTbx.Text = current.Sem; WorkTbx.Text = current.Work; } else WorkTbx.Text = "Student"; } }
//public System.Windows.Data.CollectionViewSource eSorter { get; set; } //to sort exam listbox view //public System.Windows.Data.CollectionViewSource aSorter { get; set; } //to sort assn listbox view // Load data for the ViewModel Items private void MainPage_Loaded(object sender, RoutedEventArgs e) { //Load all Data using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { //Load all exams List<Exam> temp = new List<Exam>(); if (myIsolatedStorage.FileExists("Exams.xml")) { using (IsolatedStorageFileStream stream1 = new IsolatedStorageFileStream("Exams.xml", FileMode.Open, FileAccess.Read, myIsolatedStorage)) { XmlSerializer serializer = new XmlSerializer(typeof(List<Exam>)); temp = (List<Exam>)serializer.Deserialize(stream1); /* use for debugging xml using (StreamReader reader = new StreamReader(stream1)) { this.tbx.Text = reader.ReadToEnd(); }*/ } GlobalVars.UserExams = temp; /* eSorter = new System.Windows.Data.CollectionViewSource(); eSorter.Source = GlobalVars.UserExams; eSorter.SortDescriptions.Clear(); eSorter.SortDescriptions.Add(new SortDescription("Edate", ListSortDirection.Descending));*/ examListbx.ItemsSource = GlobalVars.UserExams; } //else disp graphic //Load all assignments List<Assignment> temp2 = new List<Assignment>(); if (myIsolatedStorage.FileExists("Assignments.xml")) { using (IsolatedStorageFileStream stream1 = new IsolatedStorageFileStream("Assignments.xml", FileMode.Open, FileAccess.Read, myIsolatedStorage)) { XmlSerializer serializer = new XmlSerializer(typeof(List<Assignment>)); temp2 = (List<Assignment>)serializer.Deserialize(stream1); /* use for debugging xml using (StreamReader reader = new StreamReader(stream1)) { this.tbx.Text = reader.ReadToEnd(); }*/ } GlobalVars.UserAssns = temp2; /* aSorter = new System.Windows.Data.CollectionViewSource(); aSorter.Source=GlobalVars.UserAssns; aSorter.SortDescriptions.Clear(); aSorter.SortDescriptions.Add(new SortDescription("Edate", ListSortDirection.Descending));*/ assnListbx.ItemsSource = GlobalVars.UserAssns; } /*else : implement. display graphic*/ //Load Profile Profile current = new Profile(); if (myIsolatedStorage.FileExists("Profile.xml")) { using (IsolatedStorageFileStream stream1 = new IsolatedStorageFileStream("Profile.xml", FileMode.Open, FileAccess.Read, myIsolatedStorage)) { XmlSerializer serializer = new XmlSerializer(typeof(Profile)); current = (Profile)serializer.Deserialize(stream1); } NameTbl.DataContext = current.Name; CourseTbl.DataContext = String.Concat("Studying ", current.Course, " at "); InstiTbl.DataContext = current.Insti; SemTbl.DataContext = current.Sem; WorkTbl.DataContext = String.Concat("Currently working as ",current.Work); } //else disp graphic //Load Gradecard List<Gradecard> tempgc = new List<Gradecard>(); if (myIsolatedStorage.FileExists("Gradecards.xml")) { using (IsolatedStorageFileStream stream1 = new IsolatedStorageFileStream("Gradecards.xml", FileMode.Open, FileAccess.Read, myIsolatedStorage)) { XmlSerializer serializer = new XmlSerializer(typeof(List<Gradecard>)); tempgc = (List<Gradecard>)serializer.Deserialize(stream1); } GlobalVars.UserGc = tempgc; /* aSorter = new System.Windows.Data.CollectionViewSource(); aSorter.Source=GlobalVars.UserGc; aSorter.SortDescriptions.Clear(); aSorter.SortDescriptions.Add(new SortDescription("Edate", ListSortDirection.Descending));*/ gcListbx.ItemsSource = GlobalVars.UserGc; } /*else : implement. display graphic*/ if (myIsolatedStorage.FileExists("Point.txt")) { using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("Point.txt", FileMode.Open, FileAccess.Read, myIsolatedStorage)) { StreamReader rd = new StreamReader(stream); string[] tmp = rd.ReadLine().Split(','); GlobalVars.SGPA = Double.Parse(tmp[0]); GlobalVars.CGPA = Double.Parse(tmp[1]); rd.Close(); } } SGPATbl.DataContext = String.Concat("SGPA = ", GlobalVars.SGPA.ToString()); CGPATbl.DataContext = String.Concat("CGPA = ", GlobalVars.CGPA.ToString()); } }