void appBarCheckButton_Click(object sender, EventArgs e) { // Check for erroneous input and display appropriate error messages int num; if (!int.TryParse(MaxBunksTextbox.Text, out num)) { MessageBox.Show("Maximum bunks must be an integer value between 0-99.", "Looks like you made a booboo.", MessageBoxButton.OK); return; } Subject subject = new Subject(); subject.Name = SubjectNameTextbox.Text; subject.ShortCode = SubjectCodeTextbox.Text; subject.MaxBunks = Convert.ToInt32(MaxBunksTextbox.Text); // Add the subject data to local storage App.ViewModel.Subjects.Add(subject); App.ViewModel.SaveModel(); if (this.NavigationService.CanGoBack) { this.NavigationService.GoBack(); } }
private void appBarCheckButton_Click(object sender, EventArgs e) { // Check for erroneous input int num; if (!int.TryParse(IntBunkCounterTextBox.Text, out num)) { MessageBox.Show("Bunk Counter value must be an integer between 0-99", "Looks like you made a booboo.", MessageBoxButton.OK); return; } if (!int.TryParse(MaxBunksTextBox.Text, out num)) { MessageBox.Show("Bunk Counter value must be an integer between 0-99", "Looks like you made a booboo.", MessageBoxButton.OK); return; } // Remove the old subject App.ViewModel.Subjects.Remove(DataContext as Subject); // Create a new subject Subject newSubject = new Subject(); newSubject.Name = SubjectNameTextBox.Text; newSubject.IntBunkCounter = Convert.ToInt32(IntBunkCounterTextBox.Text); newSubject.ShortCode = ShortCodeTextBox.Text; newSubject.MaxBunks = Convert.ToInt32(MaxBunksTextBox.Text); if (newSubject.IntBunkCounter < 10) newSubject.BunkCounter = "0" + Convert.ToString(newSubject.IntBunkCounter); else newSubject.BunkCounter = Convert.ToString(newSubject.IntBunkCounter); newSubject.PercentageBunked = Convert.ToString(Convert.ToInt32((float)newSubject.IntBunkCounter / (float)newSubject.MaxBunks * 100)) + "% Bunked"; if (Convert.ToInt32((float)newSubject.IntBunkCounter / (float)newSubject.MaxBunks * 100) <= 40) { newSubject.BunkCounterColor = "Green"; } else if (Convert.ToInt32((float)newSubject.IntBunkCounter / (float)newSubject.MaxBunks * 100) <= 75) { newSubject.BunkCounterColor = "Orange"; } else { newSubject.BunkCounterColor = "Red"; } // Add it to the ViewModel App.ViewModel.Subjects.Add(newSubject); // Update the IsolatedStorage App.ViewModel.SaveModel(); if (this.NavigationService.CanGoBack) { this.NavigationService.GoBack(); } }