Exemplo n.º 1
0
        /// <summary>
        /// checks for free units a a spacifec time ???(is this correct?)
        /// </summary>
        /// <exception cref="NoItemsFound"></exception>
        /// <param name="startdate"></param>
        /// <param name="numOfDaysForVacatrion"></param>
        /// <returns></returns>
        ///
        public List <HostingUnit> FreeUnits(DateTime startdate, int numOfDaysForVacatrion)
        {
            List <HostingUnit> L   = new List <HostingUnit>();
            DateTime           end = FactoryBL.getIBL().CalcEndDate(startdate, numOfDaysForVacatrion);
            var v = from item in dal.GetAllHostingUnits()
                    where checkDates(startdate, end, item) == true
                    select item;


            if (v.Count() == 0)
            {
                throw new NoItemsFound("There are no Free units in these dates");
            }
            foreach (var item in v)
            {
                L.Add(item);
            }
            return(L);
        }
Exemplo n.º 2
0
 public void AddTest(Test test)
 {
     try
     {
         if (test.DayAndHour.DAY != test.DateTest.DayOfWeek)
         {
             throw new Exception("Exception: DateTest and day dont match");
         }
         if (test.DayAndHour.DAY == DayOfWeek.Saturday || test.DayAndHour.DAY == DayOfWeek.Friday)
         {
             throw new Exception("Exception: test cannot be in Saturday or Friday");
         }
         if (!checkID(test.IdTrainee))
         {
             throw new Exception("Exception: trainee id error");
         }
         Trainee trainee = dal.FindTraineeByID(test.IdTrainee);
         if (trainee == null)
         {
             throw new ArgumentException("Exception: trainee don't found");
         }
         if (trainee.LessonNum < Configuration.MinTestLesson)
         {
             throw new ArgumentException("Exception: less than minimum lessons");
         }
         if ((DateTime.Now - trainee.LastTest).Days <= Configuration.MinRangeTest)
         {
             throw new ArgumentException("Exception: lass than 7 days from the last test of trainee");
         }
         List <Test> toCheck = FactoryBL.Instance().GetTestsList();
         bool        check   = true;
         foreach (Test Ttest in toCheck)
         {
             if (Ttest.IdTrainee == test.IdTrainee && Ttest.DateTest == test.DateTest)
             {
                 check = false;
             }
         }
         if (check)
         {
             var findtester = dal.GetTestersList().Where(tester => tester.Sched[test.DayAndHour.DAY.GetHashCode(), test.DayAndHour.HOUR - 9] &&
                                                         tester.CarType == trainee.CarType &&
                                                         tester.Tests < tester.MaxTest);
             ArrayList array = new ArrayList();
             test.GoodDistance = false;
             test.IdTester     = 0;
             foreach (Tester theTester in findtester)
             {
                 array.Add(test);
                 array.Add(theTester);
                 Thread thread = new Thread(CalculateDistance);
                 thread.Start(array);
                 thread.Join();
                 if (test.GoodDistance == true)
                 {
                     test.IdTester = theTester.ID;
                     break;
                 }
                 else
                 {
                     throw new Exception("There is no suitable tester");
                 }
             }
         }
         else
         {
             //Console.WriteLine("this trainee already have a test in the {0}", test.DateTest);
             throw new Exception("this trainee already have a test in " + test.DateTest.ToShortDateString());
         }
     }
     catch (System.Exception e)
     {
         throw e;
     }
     dal.AddTest(test);
 }