private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            string navigationFrom;
            if (NavigationContext.QueryString.TryGetValue("navigationFrom", out navigationFrom))
            {
                NavigationService.RemoveBackEntry();
                NavigationService.RemoveBackEntry();
            }
            string name;

            string category;
            var settings = IsolatedStorageSettings.ApplicationSettings;
            if (NavigationContext.QueryString.TryGetValue("name", out name))
            {
                ObservableCollection<Class> classes;
                if (settings.TryGetValue<ObservableCollection<Class>>("classCollection", out classes))
                {
                    foreach (Class temp in classes)
                    {
                        if (temp.Name == name)
                        {
                            currentClass = temp;
                        }
                    }
                    ObservableCollection<Category> categories = new ObservableCollection<Category>();
                    categories = currentClass.Categories;
                    if (NavigationContext.QueryString.TryGetValue("category", out category))
                        foreach (Category temp in categories)
                        {
                            if (temp.Name == category)
                            {
                                currentCategory = temp;
                                break;
                            }
                        }
                }
            }
            PageTitle.Text = currentCategory.Name;
            grades = currentCategory.Assignments;
            recomputeAverage();

            App ap = (App)Application.Current;
            if (ap.isTrial)
            {
                adControl1.Visibility = Visibility.Visible;
            }
            else
            {
                adControl1.Visibility = Visibility.Collapsed;
            }






        }
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (categories.Count > 0)
                {
                    foreach (Category temp in categories)
                    {
                        if (catNameBox.Text == temp.Name)
                        {
                            throw new System.ArgumentException();
                        }
                    }
                }

                Category newCategory = new Category()
                {
                    Name = catNameBox.Text,
                    Weight = int.Parse(catPercBox.Text),
                    Assignments = new ObservableCollection<Assignments>(),
                    TotalEarned = 0,
                    TotalMax = 0,
                    Average = 0,
                    AverageString="N/A"
                };
                categories.Add(newCategory);
                categoryStrings.Add("" + newCategory.Name + "-" + newCategory.Weight + "%");
                catBox.ItemsSource = categoryStrings;
                catNameBox.Text = "";
                catPercBox.Text = "";
            }
            catch (System.ArgumentException argex)
            {
                MessageBox.Show("There is already a category named " + catNameBox.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invalid Category Data. Is your percentage a whole number?");
            }

        }
        private void removeButton_Click(object sender, RoutedEventArgs e)
        {
           
            
                string input = catBox.SelectedItem.ToString();
                categoryStrings.Remove(input);
                string[] inputarr = input.Split('-');
                Category toRemove = new Category();
                foreach (Category temp in categories)
                {
                    if (temp.Name == inputarr[0])
                    {
                        toRemove = temp;
                    }
                }
                categories.Remove(toRemove);


                catBox.ItemsSource = categoryStrings;
            
        }
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            string name;
            string category;
            string assignment;
            var settings = IsolatedStorageSettings.ApplicationSettings;
            if (NavigationContext.QueryString.TryGetValue("name", out name))
            {
                if (settings.TryGetValue<ObservableCollection<Class>>("classCollection", out classes))
                {
                    foreach (Class temp in classes)
                    {
                        if (temp.Name == name)
                            currentClass = temp;
                    }
                    ObservableCollection<Category> categories = new ObservableCollection<Category>();
                    categories = currentClass.Categories;
                    if (NavigationContext.QueryString.TryGetValue("category", out category))
                    {
                        foreach (Category temp in categories)
                        {
                            if (temp.Name == category)
                            {
                                currentCategory = temp;
                                break;
                            }
                        }
                        if (NavigationContext.QueryString.TryGetValue("assignment", out assignment))
                        {
                            grades = currentCategory.Assignments;
                            foreach (Assignments temp in grades)
                            {
                                if (temp.Name == assignment)
                                {
                                    currentAssignment = temp;

                                    break;
                                }
                            }
                        }


                    }
                }
            }
            PageTitle.Text = currentAssignment.Name;
            nameBox.Text = currentAssignment.Name;
            dateBox.Value = currentAssignment.Date;
            earnedBox.Text = currentAssignment.EarnedPoints.ToString();
            maxBox.Text = currentAssignment.MaxPoints.ToString();
            weightBox.Text = currentAssignment.Weight.ToString();



            App ap = (App)Application.Current;
            if (ap.isTrial)
            {
                adControl1.Visibility = Visibility.Visible;
            }
            else
            {
                adControl1.Visibility = Visibility.Collapsed;
            }

        }
示例#5
0
        private void removeButton_Click(object sender, RoutedEventArgs e)
        {
            var result = MessageBox.Show("You will lose any assignments associated with this category. Continue?", "Are you sure?", MessageBoxButton.OKCancel);
            if (result == MessageBoxResult.OK)
            {
                string input = catBox.SelectedItem.ToString();
                categoryStrings.Remove(input);
                string[] inputarr = input.Split('-');
                Category toRemove = new Category();
                foreach (Category temp in categories)
                {
                    if (temp.Name == inputarr[0])
                    {
                        toRemove = temp;
                    }
                }
                categories.Remove(toRemove);


                catBox.ItemsSource = categoryStrings;
            }
        }
        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            try
            {
                string name;
                string category;
                var settings = IsolatedStorageSettings.ApplicationSettings;
                if (NavigationContext.QueryString.TryGetValue("name", out name))
                {
                    ObservableCollection<Class> classes;
                    if (settings.TryGetValue<ObservableCollection<Class>>("classCollection", out classes))
                    {
                        foreach (Class temp in classes)
                        {
                            if (temp.Name == name)
                            {
                                currentClass = temp;
                            }
                        }
                        ObservableCollection<Category> categories = new ObservableCollection<Category>();
                        categories = currentClass.Categories;
                        if (NavigationContext.QueryString.TryGetValue("category", out category))
                            foreach (Category temp in categories)
                            {
                                if (temp.Name == category)
                                {
                                    currentCategory = temp;
                                    break;
                                }
                            }
                    }
                }
                grades = currentCategory.Assignments;
                string assgnname = nameBox.Text;
                string earned = earnedBox.Text;
                string max = maxBox.Text;
                string weight = weightBox.Text;
                if (assgnname == "" || earned == "" || earned == "" || max == "" | weight == "")
                {
                    throw new System.ArgumentNullException();
                }
                foreach (Assignments temp in grades)
                {
                    if (temp.Name == assgnname)
                    {
                        throw new System.ArgumentException();
                    }
                }

                Assignments newAssignment = new Assignments()
                {
                    Name = nameBox.Text,
                    Date = (DateTime)dateBox.Value,
                    EarnedPoints = int.Parse(earnedBox.Text),
                    MaxPoints = int.Parse(maxBox.Text),
                    Weight = int.Parse(weightBox.Text)
                };
                newAssignment.DateString = newAssignment.Date.ToShortDateString();
                currentCategory.TotalEarned += newAssignment.EarnedPoints*newAssignment.Weight;
                currentCategory.TotalMax += newAssignment.MaxPoints*newAssignment.Weight;
                
                grades.Add(newAssignment);
                currentCategory.Assignments = grades;
                NavigationService.GoBack();
            }
            catch (System.ArgumentNullException argnex)
            {
                MessageBox.Show("Every box must have a value");
            }
            catch (System.ArgumentException argex)
            {
                MessageBox.Show("There is already an assignment called " + nameBox.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Your data is improperly entered. Points and weights can only be whole numbers");
            }

        }