예제 #1
0
        /// <summary>
        /// Function to add a trainee to the system
        /// </summary>
        /// <param name="NewTrainee">Trainee to add</param>
        public void AddTrainee(Trainee NewTrainee)
        {
            if (NewTrainee.Age() < Configuration.MinimumTraineeAge)
            {
                throw new Exception("Trainee is too young.");
            }
            int Sum  = 0;
            int Temp = int.Parse(NewTrainee.IDNumber) / 10;

            for (int i = 0; i < 8; i++)
            {
                Sum  += (Temp % 10) * (Utilities.FuncForID(i)) / 10 + ((Temp % 10) * Utilities.FuncForID(i)) % 10;
                Temp /= 10;
            }
            Temp = (((Sum / 10) * 10 + 10) - Sum) % 10;
            if (Temp != int.Parse(NewTrainee.IDNumber) % 10)
            {
                throw new Exception("The ID number is not valid.");
            }
            try
            {
                FactoryDAL.Instance.AddTrainee(NewTrainee);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        /// <summary>
        /// Function to update a trainee in the system
        /// </summary>
        /// <param name="updatedTrainee">Trainee to update</param>
        public void UpdateTrainee(Trainee updatedTrainee)
        {
            Trainee trainee = (from t in ReturnTrainees()
                               where t.IDNumber == updatedTrainee.IDNumber
                               select t).FirstOrDefault();

            if (trainee == null)
            {
                throw new Exception(trainee.Name.ToString() + " does not exist.");
            }
            if (updatedTrainee.Age() < Configuration.MinimumTraineeAge)
            {
                throw new Exception(trainee.Name.ToString() + " is too young.");
            }
            int Sum  = 0;
            int Temp = int.Parse(updatedTrainee.IDNumber) / 10;

            for (int i = 0; i < 8; i++)
            {
                Sum  += ((Temp % 10) * (Utilities.FuncForID(i))) / 10 + ((Temp % 10) * (Utilities.FuncForID(i)) % 10);
                Temp /= 10;
            }
            Temp = (((Sum / 10) * 10 + 10) - Sum) % 10;
            if (Temp != int.Parse(updatedTrainee.IDNumber) % 10)
            {
                throw new Exception("The ID number is not valid.");
            }
            //if (trainee.HaveTest != updatedTrainee.HaveTest)
            //{
            //    throw new Exception(trainee.Name.ToString() + " has a test in the system.");
            //}
            if (trainee.TraineeVehicle.GearBoxType != updatedTrainee.TraineeVehicle.GearBoxType && trainee.TraineeVehicle.VehicleType != updatedTrainee.TraineeVehicle.VehicleType && trainee.HaveTest)
            {
                throw new Exception(trainee.Name.ToString() + " has a test in the system on a specific vehicle. In order to change the vehicle, please update the test.");
            }
            List <Test> testList = new List <Test>();

            try
            {
                testList = ReturnTests();
            }
            catch
            {
                testList = new List <Test>();
            }
            Test test = (from t in testList
                         where t.TraineeId == trainee.IDNumber
                         select t).FirstOrDefault();

            if (test != null && updatedTrainee.AmountOfClasses[test.TestVehicle.Index()] < Configuration.MinimumClasses)
            {
                throw new Exception("With this change, " + trainee.Name.ToString() + " will not have enough classes to do the test he has in the system.");
            }
            try
            {
                FactoryDAL.Instance.UpdateTrainee(updatedTrainee);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }