private void EmailTb_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (EmailTb.Validator == null)
            {
                return;
            }

            EmailTb.Validator.Visibility = System.Windows.Visibility.Visible;
            EmailTb.Validator.Validate(BlValidations.IsEmailAddressFormatValid(EmailTb.Text));

            //ToolTip
            if (EmailTb.Text == "")
            {
                EmailTb.Validator.ToolTip = "Email field can't be empty";
            }
            else if (BlValidations.IsPhoneNumberFormatValid(PhoneNumberTb.Text) == false)
            {
                EmailTb.Validator.ToolTip = "Email address format isn't valid";
            }
            else
            {
                EmailTb.Validator.ToolTip = "Good";
            }

            ValidateValidators();
        }
        private void LastNameTb_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (LastNameTb.Validator == null)
            {
                return;
            }

            LastNameTb.Validator.Visibility = Visibility.Visible;

            if (LastNameTb.IsHintVisible == true || LastNameTb.Text == "")
            {
                LastNameTb.Validator.Validate(false);
                LastNameTb.Validator.ToolTip = "Last name field can't be empty";
            }
            else
            {
                LastNameTb.Validator.Validate(BlValidations.IsNameFormatValid(LastNameTb.Text));

                if (BlValidations.IsNameFormatValid(LastNameTb.Text) == false)
                {
                    LastNameTb.Validator.ToolTip = "Last name must contain only letters";
                }
                else
                {
                    LastNameTb.Validator.ToolTip = "Good";
                }
            }



            ValidateValidators();
        }
        //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();
        }
Пример #4
0
        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            AccessLevelEnum accessLevel = BlValidations.IsLoginValid(idTb.Text, passwordPb.Password);

            if (accessLevel == AccessLevelEnum.DeniedAccess)
            {
                MessageBox.Show("Wrong Details");
            }

            m_mainWin.AccessLevel = accessLevel;
            Close();
        }
Пример #5
0
        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();
                }
            }
        }
Пример #6
0
        private List <Tester> GetAvailableTestersByDateTime()
        {
            if (GetTestDateAndTime() == null || GetTestDateAndTime() == new DateTime())
            {
                return(TestersList);
            }

            DateTime testDateTime = GetTestDateAndTime();

            var result = from tester in TestersList
                         where BlValidations.IsTesterFreeForTest(tester, testDateTime) == true
                         select tester;

            return(result.ToList());
        }
Пример #7
0
        private void ValidateTestDate()
        {
            if (testDateDp.Validator == null)
            {
                return;
            }

            Tester tester = GetTesterById(GetTesterId());

            testDateDp.Validator.Visibility = Visibility.Visible;

            if (tester == null)
            {
                testDateDp.Validator.Validate(false);
                testDateDp.Validator.ToolTip = "You must enter a tester Id first";
                return;
            }

            DateTime date = GetTestDateAndTime();

            if (testDateDp.SelectedDate == null)
            {
                testDateDp.Validator.Validate(false);
                testDateDp.Validator.ToolTip = "You must select a date for the test";
            }
            else if (BlValidations.IsTesterFreeForTest(tester, date) == false)
            {
                testDateDp.Validator.Validate(false);
                testDateDp.Validator.ToolTip = "Tester with Id " + GetTesterId() + " is not free at this date and time";
            }
            else
            {
                testDateDp.Validator.ToolTip = "Good";
                testDateDp.Validator.Validate(true);
            }

            ValidateValidators();
        }
Пример #8
0
        //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 = "";
            }
        }