示例#1
0
 async void StartPage_Loaded(object sender, RoutedEventArgs e)
 {
     //calling the fill method if a new StudentDataBundle was created
     box.OnCreate += Fill;
     //load the data folder
     if (await CoreData.Initialize())
     {
         //iterate through the folder and get all timetables
         if (await CoreData.GetTimetables())
         {
             Fill();
         }
     }
     else
     {
         //if something happened then suggest a fix for the user
         MessageDialog dialog = new MessageDialog("There was a problem initializing the data storage.\nTry closing and reopening the app.", "Oops");
         await dialog.ShowAsync();
     }
 }
        /// <summary>
        /// Invoked when the application is activated to display search results.
        /// </summary>
        /// <param name="args">Details about the activation request.</param>
        protected async override void OnSearchActivated(Windows.ApplicationModel.Activation.SearchActivatedEventArgs args)
        {
            // TODO: Register the Windows.ApplicationModel.Search.SearchPane.GetForCurrentView().QuerySubmitted
            // event in OnWindowCreated to speed up searches once the application is already running
            if (await CoreData.Initialize())
            {
                //iterate through the folder and get all timetables
                if (await CoreData.GetTimetables())
                {
                }
            }
            else
            {
                //if something happened then suggest a fix for the user
                MessageDialog dialog = new MessageDialog("There was a problem initializing the data storage.\nTry closing and reopening the app.", "Oops");
                await dialog.ShowAsync();
            }
            // If the Window isn't already using Frame navigation, insert our own Frame
            var previousContent = Window.Current.Content;
            var frame           = previousContent as Frame;

            // If the app does not contain a top-level frame, it is possible that this
            // is the initial launch of the app. Typically this method and OnLaunched
            // in App.xaml.cs can call a common method.
            if (frame == null)
            {
                // Create a Frame to act as the navigation context and associate it with
                // a SuspensionManager key
                frame = new Frame();
            }

            frame.Navigate(typeof(SearchResultsPage), args.QueryText);
            Window.Current.Content = frame;

            // Ensure the current window is active
            Window.Current.Activate();
        }
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected async override void OnLaunched(LaunchActivatedEventArgs args)
        {
            // Do not repeat app initialization when already running, just ensure that
            // the window is active

            if (args.PreviousExecutionState == ApplicationExecutionState.Running && string.IsNullOrEmpty(args.Arguments))
            {
                Window.Current.Activate();
                return;
            }

            if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                //TODO: Load state from previously suspended application
            }

            // Create a Frame to act navigation context and navigate to the first page
            var rootFrame = new Frame();

            if (string.IsNullOrEmpty(args.Arguments))
            {
                bool first = false;
                if (ApplicationData.Current.LocalSettings.Values.ContainsKey("first"))
                {
                }
                else
                {
                    ApplicationData.Current.LocalSettings.Values.Add(new KeyValuePair <string, object>("first", true));
                    first = true;
                }

                Type tp = (first) ? typeof(Intro) : typeof(StartPage);
                if (!rootFrame.Navigate(tp))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            else
            {
                if (await CoreData.Initialize())
                {
                    //iterate through the folder and get all timetables
                    if (await CoreData.GetTimetables())
                    {
                    }
                }
                else
                {
                    //if something happened then suggest a fix for the user
                    MessageDialog dialog = new MessageDialog("There was a problem initializing the data storage.\nTry closing and reopening the app.", "Oops");
                    await dialog.ShowAsync();
                }
                //if there are aguments go to the appropiate page
                if (args.Arguments.StartsWith("definitions"))
                {
                    string targetTB = args.Arguments.Split(',')[1]; //name of target timetable
                    string target   = args.Arguments.Split(',')[2]; //name of target course
                    //do a linear search
                    foreach (StudentDataBundle tb in CoreData.Timetables)
                    {
                        if (tb.Name == targetTB)
                        {
                            foreach (Course model in tb.Courses)
                            {
                                if (model.Name == target)
                                {
                                    rootFrame.Navigate(typeof(DefinitionsEditor), new object[2] {
                                        tb, model
                                    });
                                }
                            }
                        }
                    }
                }

                if (args.Arguments.StartsWith("homework"))
                {
                    string targetTB = args.Arguments.Split(',')[1];
                    string target   = args.Arguments.Split(',')[2];
                    foreach (StudentDataBundle tb in CoreData.Timetables)
                    {
                        if (tb.Name == targetTB)
                        {
                            foreach (Course model in tb.Courses)
                            {
                                if (model.Name == target)
                                {
                                    rootFrame.Navigate(typeof(HomeworkEditor), new object[2] {
                                        tb, model
                                    });
                                }
                            }
                        }
                    }
                }

                if (args.Arguments.StartsWith("topics"))
                {
                    string targetTB = args.Arguments.Split(',')[1];
                    string target   = args.Arguments.Split(',')[2];
                    foreach (StudentDataBundle tb in CoreData.Timetables)
                    {
                        if (tb.Name == targetTB)
                        {
                            foreach (Course model in tb.Courses)
                            {
                                if (model.Name == target)
                                {
                                    rootFrame.Navigate(typeof(TopicsEditor), new object[2] {
                                        tb, model
                                    });
                                }
                            }
                        }
                    }
                }

                if (args.Arguments.StartsWith("notes"))
                {
                    string targetTB = args.Arguments.Split(',')[1];
                    string target   = args.Arguments.Split(',')[2];
                    foreach (StudentDataBundle tb in CoreData.Timetables)
                    {
                        if (tb.Name == targetTB)
                        {
                            foreach (Course model in tb.Courses)
                            {
                                if (model.Name == target)
                                {
                                    rootFrame.Navigate(typeof(NotesEditor), new object[2] {
                                        tb, model
                                    });
                                }
                            }
                        }
                    }
                }
            }
            // Place the frame in the current Window and ensure that it is active
            Window.Current.Content = rootFrame;
            Window.Current.Activate();
        }
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (await CoreData.Initialize())
            {
                //iterate through the folder and get all timetables
                if (await CoreData.GetTimetables())
                {
                }
            }
            else
            {
                //if something happened then suggest a fix for the user
                MessageDialog dialog = new MessageDialog("There was a problem initializing the data storage.\nTry closing and reopening the app.", "Oops");
                await dialog.ShowAsync();
            }

            back.Tapped += (a, b) => Frame.Navigate(typeof(StartPage));
            query        = e.Parameter as string;
            header.Text  = "Search results for " + '"' + query + '"';
            foreach (StudentDataBundle tb in CoreData.Timetables)
            {
                ComboBoxItem item = new ComboBoxItem {
                    Content = tb.Name, Tag = tb
                };
                timetables.Items.Add(item);
            }

            timetables.SelectedIndex = 0;

            foreach (Course model in ((timetables.SelectedItem as FrameworkElement).Tag as StudentDataBundle).Courses)
            {
                ComboBoxItem item = new ComboBoxItem {
                    Content = model.Name, Tag = model, Foreground = new SolidColorBrush(model.TileColor)
                };
                classes.Items.Add(item);
            }
            classes.SelectedIndex = 0;


            timetables.SelectionChanged += (a, b) =>
            {
                classes.Items.Clear();
                foreach (Course model in ((timetables.SelectedItem as FrameworkElement).Tag as StudentDataBundle).Courses)
                {
                    ComboBoxItem item = new ComboBoxItem {
                        Content = model.Name, Tag = model, Foreground = new SolidColorBrush(model.TileColor)
                    };
                    classes.Items.Add(item);
                }
                if (classes.Items.Count > 0)
                {
                    classes.SelectedIndex = 0;
                }
                Search();
            };



            foreach (Module module in ((classes.SelectedItem as FrameworkElement).Tag as Course).Modules)
            {
                ComboBoxItem item = new ComboBoxItem {
                    Content = module.Name, Tag = module
                };
                modules.Items.Add(item);
            }
            if (modules.Items.Count > 0)
            {
                modules.SelectedIndex = 0;
            }

            classes.SelectionChanged += (a, b) =>
            {
                modules.Items.Clear();
                foreach (Module module in ((classes.SelectedItem as FrameworkElement).Tag as Course).Modules)
                {
                    ComboBoxItem item = new ComboBoxItem {
                        Content = module.Name, Tag = module
                    };
                    modules.Items.Add(item);
                }
                if (modules.Items.Count > 0)
                {
                    modules.SelectedIndex = 0;
                }
                Search();
            };

            target.SelectionChanged += (a, b) => Search();
            everywhere.Tapped       += (a, b) =>
            {
                foreach (FrameworkElement elem in filters.Children)
                {
                    if (elem != in_timetable && elem != timetables)
                    {
                        elem.Visibility = (everywhere.IsChecked.Value) ? Visibility.Collapsed : Visibility.Visible;
                    }
                }
                Search();
            };
        }