DepartmentPage.xaml.cs CampusAppWP8::Pages::Departments::DepartmentPage CampusAppWP8::Pages::Departments //----------------------------------------------------------------------- //<copyrightfile="DepartmentPage.xaml.cs"company="BTU/IIT"> //Companycopyrighttag. //</copyright> //<author>fiedlchr</author> //<sience>24.06.2013</sience> //---------------------------------------------------------------------- namespaceCampusAppWP8.Pages.Departments { usingSystem; usingSystem.Linq; usingSystem.Windows; usingSystem.Windows.Controls; usingSystem.Windows.Navigation; usingCampusAppWP8.Model.Departments; usingCampusAppWP8.Resources; usingMicrosoft.Phone.Controls; publicpartialclassDepartmentPage:PhoneApplicationPage { privateboolisSourceSet=false; privateFrameworkElementlastClickedBtn=null; privateboolisNewInstance=false; publicDepartmentPage() { this.InitializeComponent(); this.isNewInstance=true; } protectedoverridevoidOnNavigatedTo(NavigationEventArgse) { base.OnNavigatedTo(e); if(this.isNewInstance) { if((DepartmentIndexPage.Feed==null)||(DepartmentIndexPage.Feed.GetModel()==null)) { DepartmentModeltempModel=null; if((tempModel=App.LoadFromIsolatedStorage<DepartmentModel>(Constants.IsolatedStorage_DepartmentModel))!=null) { if(DepartmentIndexPage.Feed==null) { DepartmentIndexPage.Feed=newFeed.Departments.DepartmentFeed(false); } DepartmentIndexPage.Feed.Model=tempModel; this.isSourceSet=false; } } this.isNewInstance=false; } if(this.isSourceSet==false) { this.DepartmentPivot.ItemsSource=DepartmentIndexPage.GetFeed().GetModel().Faculties; this.isSourceSet=true; } stringpivotIndex=string.Empty; //Navigatetotheselectedpivotitem if(NavigationContext.QueryString.TryGetValue("pivotindex",outpivotIndex)) { intpivotIndexInt=int.Parse(pivotIndex)-1; //iftheindexisintherangeofthearray if((pivotIndexInt>=0)&&(pivotIndexInt<DepartmentIndexPage.GetFeed().GetModel().Faculties.Count())) { DepartmentPivot.SelectedIndex=pivotIndexInt; } else { MessageBox.Show("ERROR:pivotIndexoutofrange!!!"); } } } protectedoverridevoidOnNavigatedFrom(NavigationEventArgse) { base.OnNavigatedFrom(e); if(e.NavigationMode!=System.Windows.Navigation.NavigationMode.Back) { App.SaveToIsolatedStorage<DepartmentModel>(Constants.IsolatedStorage_DepartmentModel,DepartmentIndexPage.Feed.GetModel()); } } privatevoidPhoneApplicationPage_OrientationChanged(objectsender,OrientationChangedEventArgse) { } privatevoidChairTB_Click(objectsender,RoutedEventArgse) { FrameworkElementtempBtn=senderasFrameworkElement; StackPaneltempParent=null; if(this.lastClickedBtn!=tempBtn) { if(this.lastClickedBtn!=null) { tempParent=this.lastClickedBtn.ParentasStackPanel; tempParent.Children[1].Visibility=Visibility.Collapsed; } tempParent=tempBtn.ParentasStackPanel; tempParent.Children[1].Visibility=Visibility.Visible; this.lastClickedBtn=tempBtn; } else { tempParent=this.lastClickedBtn.ParentasStackPanel; tempParent.Children[1].Visibility=Visibility.Collapsed; this.lastClickedBtn=null; } } privatevoidAddBtn_Click(objectsender,RoutedEventArgse) { Buttonbtn=this.lastClickedBtnasButton; TextBlockbtnText=btn.ContentasTextBlock; Model.Departments.ChairModeltempModel=DepartmentIndexPage.GetFeed().GetModel().Faculties[this.DepartmentPivot.SelectedIndex].GetChairModel(btnText.Text); if(tempModel!=null) { DepartmentIndexPage.GetFavoriteFeed().GetModel().Faculties[0].AddChair(tempModel); } } privatevoidInfoBtn_Click(objectsender,RoutedEventArgse) { FrameworkElementinfoBtn=senderasFrameworkElement; stringchairName=((this.lastClickedBtnasButton).ContentasTextBlock).Text.ToString(); NavigationService.Navigate(newUri(Constants.PathDepartment_DepartmentInfoPage+"?url="+infoBtn.Tag.ToString()+"&name="+chairName,UriKind.Relative)); } } }