//Fields' Value Changed Events private void IdTb_TextChanged(object sender, TextChangedEventArgs e) { if (IdTb.Validator == null) { return; } IdTb.Validator.Visibility = Visibility.Visible; if (IdTb.IsHintVisible == true || IdTb.Text == "") { IdTb.Validator.Validate(false); IdTb.Validator.ToolTip = "Id field can't be empty"; } else { IdTb.Validator.Validate(BlValidations.IsIdFormatValid(IdTb.Text)); if (BlValidations.IsIdFormatValid(IdTb.Text) == false) { IdTb.Validator.ToolTip = "Id format isn't valid"; } else { IdTb.Validator.ToolTip = "Good"; } } ValidateValidators(); }
private void ValidateTesterIdField() { if (testerIdTb.Validator == null) { return; } testerIdTb.Validator.Visibility = Visibility.Visible; if (testerIdTb.IsHintVisible == true || GetTesterId() == "") { testerIdTb.Validator.Validate(false); testerNameTb.Text = ""; testerIdTb.Validator.ToolTip = "Tester's Id field can't be empty"; } else { testerIdTb.Validator.Validate(BlValidations.IsIdFormatValid(GetTesterId())); if (BlValidations.IsIdFormatValid(GetTesterId()) == false) { testerIdTb.Validator.ToolTip = "Id format isn't valid"; testerNameTb.Text = ""; } else if (GetTesterId() == GetTraineeId()) { testerIdTb.Validator.ToolTip = "Tester and trainee can't have the same Id"; testerIdTb.Validator.Validate(false); testerNameTb.Text = ""; } else if (GetTesterById(GetTesterId()) == null) { testerIdTb.Validator.ToolTip = "Couldn't find tester with Id " + GetTesterId(); testerIdTb.Validator.Validate(false); testerNameTb.Text = ""; } else if (GetTraineeById(GetTesterId()) != null) { testerIdTb.Validator.ToolTip = "This Id belongs to an existing trainee"; testerIdTb.Validator.Validate(false); testerNameTb.Text = ""; } else { testerIdTb.Validator.ToolTip = "Good"; testerNameTb.Text = GetTesterById(GetTesterId()).GetName(); } } }
//Validations private void ValidateTraineeIdField() { if (traineeIdTb.Validator == null) { return; } Trainee trainee = GetTrainee(); traineeIdTb.Validator.Visibility = Visibility.Visible; try { if (traineeIdTb.IsHintVisible == true || GetTraineeId() == "") { throw new Exception("trainee's Id field can't be empty"); } else if (BlValidations.IsIdFormatValid(GetTraineeId()) == false) { throw new Exception("Id " + trainee.Id + "'s format is not valid"); } else if (trainee == null) { throw new Exception("Couldn't find trainee with Id " + GetTraineeId()); } else if (GetTesterById(GetTraineeId()) != null) { throw new Exception("This Id belongs to an existing Tester"); } else if (trainee.DaysPassedSinceLastTest < Configuration.MinimalDaysBetweenTests) { throw new Exception("Test can only be scheduled at least " + Configuration.MinimalDaysBetweenTests + " days after the trainee's last test."); } else if (trainee.DrivingLessonsCount < Configuration.MinimalLessonsCount) { throw new Exception(trainee.GetName() + " must do at least " + Configuration.MinimalLessonsCount + " driving lessons before doing a test"); } else if (BlValidations.IsLisenceOwned(trainee.OwnedLisences, trainee.WantedLisence) == true) { throw new Exception("Lisence " + trainee.CarType + " is already owned by " + trainee.GetName()); } else if (BlValidations.IsCarTypeExist(trainee.ScheduleList, trainee.CarType) == true) { throw new Exception("trainee with Id " + trainee.Id + " is already have an upcomming test for " + trainee.CarType); } else { traineeIdTb.Validator.Validate(true); traineeIdTb.Validator.ToolTip = "Good"; traineeNameTb.Text = trainee.GetName(); traineeCarTypeCb.ComboBox.SelectedItem = trainee.CarType; } } catch (Exception e) { traineeIdTb.Validator.ToolTip = e.Message; traineeIdTb.Validator.Validate(false); traineeNameTb.Text = ""; traineeCarTypeCb.Text = ""; } }