private void PhoneApplicationPage_LayoutUpdated(object sender, EventArgs e) { try { if (bFocused && (null != focusedElement)) { bFocused = false; focusedElement.Focus(); focusedElement = null; } } catch (Exception ex) { //Trace the exception for debug purposes Utils.Trace(String.Format("Exception = {0}.", ex.GetType()) + "\n"); } TravelReportInfo travelReportInfo = ((App.Current.RootVisual as PhoneApplicationFrame).DataContext as TravelReportInfo); txtFromDate.Value = travelReportInfo.FirstDay; bFromDateChangedNavigateTo = false; txtToDate.Value = travelReportInfo.LastDay; bToDateChangedNavigateTo = false; }
// Code to execute when the application is activated (brought to foreground) // This code will not execute when the application is first launched private void Application_Activated(object sender, ActivatedEventArgs e) { //Trace the event for debug purposes Utils.Trace("Application Activated"); //Create new data object variable TravelReportInfo travelReportInfo = null; //Try to locate previous data in transient state of the application if (PhoneApplicationService.Current.State.ContainsKey("UnsavedTravelReportInfo")) { //If found, initialize the data variable and remove in from application's state travelReportInfo = PhoneApplicationService.Current.State["UnsavedTravelReportInfo"] as TravelReportInfo; PhoneApplicationService.Current.State.Remove("UnsavedTravelReportInfo"); } //If found set it as a DataContext for all the pages of the application //An application is not guaranteed to be activated after it has been tombstoned, //thus if not found create new data object if (null != travelReportInfo) { RootFrame.DataContext = travelReportInfo; } else { RootFrame.DataContext = new TravelReportInfo(); } }
private void txtFromDate_ValueChanged(object sender, DateTimeValueChangedEventArgs e) { TravelReportInfo travelReportInfo = ((App.Current.RootVisual as PhoneApplicationFrame).DataContext as TravelReportInfo); travelReportInfo.FirstDay = DateTime.Parse(txtFromDate.ValueString); bFromDateChangedNavigateTo = true; }
public static void ClearTravelReport(TravelReportInfo travelReportInfo) { travelReportInfo.Clear(); if (MessageBox.Show("Clear all saved reports also?", "Clead Data", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { //Check if file exits if (isf.FileExists("TravelReportInfo.dat")) isf.DeleteFile("TravelReportInfo.dat"); } } }
public static void SaveTravelReport(TravelReportInfo travelReportInfo, string fileName, bool isExiting) { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { //If user choose to save, create a new file using (IsolatedStorageFileStream fs = isf.CreateFile(fileName)) { //and serialize data XmlSerializer ser = new XmlSerializer(typeof(TravelReportInfo)); ser.Serialize(fs, travelReportInfo); } } if (!isExiting) MessageBox.Show("Travel report saved successfully", "Save Complete", MessageBoxButton.OK); }
public static void ClearTravelReport(TravelReportInfo travelReportInfo) { if (MessageBox.Show("Clear all saved reports also?", "Clead Data", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { travelReportInfo.Clear(); using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { //Check if file exits if (isf.FileExists("TravelReportInfo.dat")) { isf.DeleteFile("TravelReportInfo.dat"); } } } }
public static void SaveTravelReport(TravelReportInfo travelReportInfo, string fileName, bool isExiting) { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { //If user choose to save, create a new file using (IsolatedStorageFileStream fs = isf.CreateFile(fileName)) { //and serialize data XmlSerializer ser = new XmlSerializer(typeof(TravelReportInfo)); ser.Serialize(fs, travelReportInfo); } } if (!isExiting) { MessageBox.Show("Travel report saved successfully", "Save Complete", MessageBoxButton.OK); } }
// Code to execute when the application is launching (eg, from Start) // This code will not execute when the application is reactivated private void Application_Launching(object sender, LaunchingEventArgs e) { //Trace the event for debug purposes Utils.Trace("Application Launching"); //Create new data object variable TravelReportInfo travelReportInfo = null; //Try to load previously saved data from IsolatedStorage using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { //Check if file exits if (isf.FileExists("TravelReportInfo.dat")) { using (IsolatedStorageFileStream fs = isf.OpenFile("TravelReportInfo.dat", System.IO.FileMode.Open)) { //Read the file contents and try to deserialize it back to data object XmlSerializer ser = new XmlSerializer(typeof(TravelReportInfo)); object obj = ser.Deserialize(fs); //If successfully deserialized, initialize data object variable with it if (null != obj && obj is TravelReportInfo) { travelReportInfo = obj as TravelReportInfo; } else { travelReportInfo = new TravelReportInfo(); } } } else { //If previous data not found, create new instance travelReportInfo = new TravelReportInfo(); } } //Set data variable (either recovered or new) as a DataContext for all the pages of the application RootFrame.DataContext = travelReportInfo; }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { //Trace the event for debug purposes Utils.Trace("Navigated To MainPage"); //Check if page state has saved focus and apply it back if (State.ContainsKey("FocusedElement")) { Control focusedElement = this.FindName(State["FocusedElement"] as string) as Control; if (null != focusedElement) { focusedElement.Focus(); } } TravelReportInfo travelReportInfo = ((App.Current.RootVisual as PhoneApplicationFrame).DataContext as TravelReportInfo); if (State.ContainsKey("txtDestination")) { travelReportInfo.Destination = State["txtDestination"] as string; } if (State.ContainsKey("txtJustification")) { travelReportInfo.Justification = State["txtJustification"] as string; } if (State.ContainsKey("txtToDate")) { travelReportInfo.FirstDay = DateTime.Parse(State["txtToDate"] as string); } if (State.ContainsKey("txtFromDate")) { travelReportInfo.LastDay = DateTime.Parse(State["txtFromDate"] as string); } base.OnNavigatedTo(e); }
// Code to execute when the application is launching (eg, from Start) // This code will not execute when the application is reactivated private void Application_Launching(object sender, LaunchingEventArgs e) { //Trace the event for debug purposes Utils.Trace("Application Launching"); //Create new data object variable TravelReportInfo travelReportInfo = null; //Try to load previously saved data from IsolatedStorage using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { //Check if file exits if (isf.FileExists("TravelReportInfo.dat")) { using (IsolatedStorageFileStream fs = isf.OpenFile("TravelReportInfo.dat", System.IO.FileMode.Open)) { //Read the file contents and try to deserialize it back to data object XmlSerializer ser = new XmlSerializer(typeof(TravelReportInfo)); object obj = ser.Deserialize(fs); //If successfully deserialized, initialize data object variable with it if (null != obj && obj is TravelReportInfo) travelReportInfo = obj as TravelReportInfo; else travelReportInfo = new TravelReportInfo(); } } else //If previous data not found, create new instance travelReportInfo = new TravelReportInfo(); } //Set data variable (either recovered or new) as a DataContext for all the pages of the application RootFrame.DataContext = travelReportInfo; }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { //Trace the event for debug purposes Utils.Trace("Navigated To MainPage"); //Check if page state has saved focus and apply it back if (State.ContainsKey("FocusedElement")) { focusedElement = this.FindName(State["FocusedElement"] as string) as Control; bFocused = true; //if (null != focusedElement) // focusedElement.Focus(); } else { bFocused = false; } TravelReportInfo travelReportInfo = ((App.Current.RootVisual as PhoneApplicationFrame).DataContext as TravelReportInfo); if (State.ContainsKey("txtDestination")) { travelReportInfo.Destination = State["txtDestination"] as string; } if (State.ContainsKey("txtJustification")) { travelReportInfo.Justification = State["txtJustification"] as string; } if (State.ContainsKey("txtToDate")) { if (!bToDateChangedNavigateTo) { travelReportInfo.LastDay = DateTime.Parse(State["txtToDate"] as string); txtToDate.Value = travelReportInfo.LastDay;//this operation call txtFromDate_ValueChanged event bToDateChangedNavigateTo = false; } else { bToDateChangedNavigateTo = false; } } else { //format todata txtToDate.Value = travelReportInfo.LastDay; bToDateChangedNavigateTo = false; } if (State.ContainsKey("txtFromDate")) { if (!bFromDateChangedNavigateTo) { travelReportInfo.FirstDay = DateTime.Parse(State["txtFromDate"] as string); txtFromDate.Value = travelReportInfo.FirstDay;//this operation call txtFromDate_ValueChanged event bFromDateChangedNavigateTo = false; } else { bFromDateChangedNavigateTo = false; } } else { // format fromdata txtFromDate.Value = travelReportInfo.FirstDay; bFromDateChangedNavigateTo = false; } base.OnNavigatedTo(e); }
// Code to execute when the application is launching (eg, from Start) // This code will not execute when the application is reactivated private void Application_Launching(object sender, LaunchingEventArgs e) { Utils.Trace("Application Launching"); TravelReportInfo trf = null; using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { Utils.ListStorageFiles(); if (isf.FileExists(_fileName)) { using (IsolatedStorageFileStream fs = isf.OpenFile(_fileName, System.IO.FileMode.Open)) { XmlSerializer ser = new XmlSerializer(typeof(TravelReportInfo)); object obj = ser.Deserialize(fs); if (null != obj && obj is TravelReportInfo) trf = obj as TravelReportInfo; else trf = new TravelReportInfo(); } } else trf = new TravelReportInfo(); } RootFrame.DataContext = trf; }