private void BtnDeletePupilAbsenceCancel_Click(object sender, RoutedEventArgs e) { // Reset the form data and return to the search view Stk_DeletePupilAbsenceForm.Visibility = Visibility.Hidden; TbxDeletePupilFullName.Clear(); TbxDeleteAbsenceReason.Clear(); TbxPupilAbsenceClassID.Clear(); TbxPupilAbsenceID.Clear(); Stk_SearchPupil.Visibility = Visibility.Visible; }
private void BtnDeletePupilAbsenceReturn_Click(object sender, RoutedEventArgs e) { // Reset the delete absence form and return to the pupil absence search view TbxDeletePupilFullName.Clear(); TbxPupilAbsenceClassID.Clear(); TbxPupilAbsenceID.Clear(); TbxDeleteAbsenceReason.Clear(); TbxDeleteAbsenceDate.Clear(); TbxAbsenceID.Clear(); // Refresh the listview RefreshPupilAbsences(); Stk_SearchPupilAbsence.Visibility = Visibility.Visible; Stk_DeletePupilAbsenceForm.Visibility = Visibility.Hidden; }
private void BtnDeletePupilAbsence_Click(object sender, RoutedEventArgs e) { // Warn the user that the delete cannot be undone bool confirmDelete = MessageBox.Show("This action cannot be undone", "Confirm Deletion", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK; // Deletion confirmed if (confirmDelete) { try { int absenceDeleted = pupilUtils.DeletePupilAbsence(Convert.ToInt16(LstPupilAbsenceSearch.SelectedValue.ToString()), Convert.ToInt16(LstPupilSearch.SelectedValue.ToString()), pupilAbsence.AbsenceDate); if (absenceDeleted == 1) { Lbl_PupilDeleteAbsenceSuccessLabel.Visibility = Visibility.Visible; BtnDeletePupilAbsenceReturn.Visibility = Visibility.Visible; BtnDeletePupilAbsence.Visibility = Visibility.Collapsed; BtnDeletePupilAbsenceCancel.Visibility = Visibility.Collapsed; // Update the system logs if the record was successfully deleted try { systemEventUtils.AddSystemEvent(new SystemEvent { UserId = systemUser.UserId, EventTypeId = 6, EventDateTime = DateTime.Now, EventData = $"PupilAbsence record deleted at { DateTime.Now} , by {systemUser.Username}" }); } catch (EntityException) { // Show an error on failure MessageBox.Show("System Database Error, Please contact the System Administrator", "Database Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { // Deletion failed, show the errror and reset the form, try to log the event to the system logs Lbl_PupilDeleteAbsenceErrorLabel.Visibility = Visibility.Visible; BtnDeletePupilAbsenceReturn.Visibility = Visibility.Visible; // Update the system logs if the record wasn't successfully deleted try { systemEventUtils.AddSystemEvent(new SystemEvent { UserId = systemUser.UserId, EventTypeId = 1006, EventDateTime = DateTime.Now, EventData = $"Error deleting PupilAbsence record { DateTime.Now} , by {systemUser.Username}" }); } catch (EntityException) { // Show an error on failure MessageBox.Show("System Database Error, Please contact the System Administrator", "Database Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } catch (Exception) { // Show an error on failure MessageBox.Show($"System Database Error, Please contact the System Administrator", "Database Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { // Reset the delete absence form and return to the main pupil search view TbxDeletePupilFullName.Clear(); TbxPupilAbsenceClassID.Clear(); TbxPupilAbsenceID.Clear(); TbxDeleteAbsenceReason.Clear(); TbxDeleteAbsenceDate.Clear(); TbxAbsenceID.Clear(); Stk_SearchPupilAbsence.Visibility = Visibility.Hidden; Stk_DeletePupilAbsenceForm.Visibility = Visibility.Hidden; Stk_SearchPupil.Visibility = Visibility.Visible; } }