private void Hyperlink_Click(object sender, RoutedEventArgs e) { if (Student != null) { long id = Student.Id; bool?success = new StudentIDForm(Student).ShowDialog(); if (success != null && (bool)success) { //fetch the new student Student = Student.GetStudent(Student.Username); RefreshInfo(); if (Student.Id == id) { MessageBox.Show("User ID matched the previously entered ID no edits will take place ", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } else { MessageBox.Show("Successfully changed your id"); } } else { MessageBox.Show("Your id did not change."); } } }
private void Application_Startup(object sender, StartupEventArgs e) { //Stop the program if classroom isn't defined if (string.IsNullOrWhiteSpace(Settings.Default.Classroom)) { MessageBox.Show("Classroom not found. Please check the configuration files.", "404 error", MessageBoxButton.OK, MessageBoxImage.Error); Shutdown(0); return; } MainWindow = new MainWindow(); ((MainWindow)MainWindow).HideWin(); string userName = Environment.UserName; DateTime now = DateTime.Now; Course course = null; Student student = null; try { //may throw a sql exception course = Course.GetCoursesByTime(Settings.Default.Classroom, now); //may throw a sql exception student = Student.GetStudent(userName); if (student == null) { //ask for student id StudentIDForm stuIdForm = new StudentIDForm(userName); bool? success = stuIdForm.ShowDialog(); if (success != null && (bool)success) { student = Student.GetStudent(userName); if (student == null) { MessageBox.Show("Sorry, some error has occurered, and you will not be counted as attended. Please try agian.", "Internal error", MessageBoxButton.OK, MessageBoxImage.Error); } } } } catch (MySqlException ex) { MessageBox.Show(ex.Message, "Server Error", MessageBoxButton.OK, MessageBoxImage.Error); } if (student != null && RegisterAttendance(course, student, now)) { ((MainWindow)MainWindow).Course = course; ((MainWindow)MainWindow).Student = student; ((MainWindow)MainWindow).ShowWin(); } else { //Shutdown(); MainWindow.Close(); } }