public void addTest(MY_BE.Test test)
        {
            tests.Add(test);
            //testsroot = XElement.Load(testspath);
            XElement xelement = new XElement("test",
                                             new XElement("TesterId", test.TesterId),
                                             new XElement("TraineeId", test.TraineeId),
                                             new XElement("TestAdress",
                                                          new XElement("City", test.TestAdress.City),
                                                          new XElement("Street", test.TestAdress.Street),
                                                          new XElement("HouseNumber", test.TestAdress.HouseNumber)),
                                             new XElement("TesterNote", test.TesterNote),
                                             new XElement("TestNumber", test.TestNumber),
                                             new XElement("TraineeVehicle", test.TraineeVehicle),
                                             new XElement("TestDate", test.TestDate),
                                             new XElement("BoolTestParams", test.BoolTestParams.Select(x => new XElement("dict",
                                                                                                                         new XElement("Key", x.Key), new XElement("Value", x.Value)))),
                                             new XElement("TestParams", test.TestParams.Select(x => new XElement("dict",
                                                                                                                 new XElement("Key", x.Key), new XElement("Value", x.Value)))),
                                             new XElement("isCheacked", test.isCheacked)
                                             );

            testsroot.Add(xelement);
            testsroot.Save(testspath);
            configroot = new XElement("config", new XElement("TEST_ID", Configuration.TEST_ID));
            configroot.Save(configpath);
        }
 public testUpdateUserControl(Test test)
 {
     testcontrol = test;
     InitializeComponent();
     testUpdateGrid.DataContext = test;
     par1.ItemsSource           = Enum.GetValues(typeof(Rating));
     par2.ItemsSource           = Enum.GetValues(typeof(Rating));
     par3.ItemsSource           = Enum.GetValues(typeof(Rating));
     par4.ItemsSource           = Enum.GetValues(typeof(Rating));
 }
Esempio n. 3
0
        public void updateTestOnFinish(MY_BE.Test test)
        {
            bool canupdatetest = true;
            bool testpassed    = true;

            foreach (var item in test.TestParams)//check if all testparams was entered false\true
            {
                if (item.Value == null)
                {
                    canupdatetest = false;
                }
            }
            if (canupdatetest)
            {
                d.updateTestOnFinish(test);
            }
        }
        public void updateTestOnFinish(MY_BE.Test test)
        {
            Test t = new Test();

            foreach (Test item in tests)
            {
                if (item.TestNumber == test.TestNumber)
                {
                    t = item;
                    break;
                }
            }
            tests.Remove(t);
            tests.Add(test);
            testsroot = new XElement("tests");
            foreach (Test item in tests)
            {
                testsroot.Add(new XElement("test",
                                           new XElement("TesterId", item.TesterId),
                                           new XElement("TraineeId", item.TraineeId),
                                           new XElement("TestAdress",
                                                        new XElement("City", item.TestAdress.City),
                                                        new XElement("Street", item.TestAdress.Street),
                                                        new XElement("HouseNumber", item.TestAdress.HouseNumber)),
                                           new XElement("TesterNote", item.TesterNote),
                                           new XElement("TestNumber", item.TestNumber),
                                           new XElement("TraineeVehicle", item.TraineeVehicle),
                                           new XElement("TestDate", item.TestDate),
                                           new XElement("BoolTestParams", item.BoolTestParams.Select(x => new XElement("dict",
                                                                                                                       new XElement("Key", x.Key), new XElement("Value", x.Value)))),
                                           new XElement("TestParams", item.TestParams.Select(x => new XElement("dict",
                                                                                                               new XElement("Key", x.Key), new XElement("Value", x.Value)))),
                                           new XElement("isCheacked", item.isCheacked)
                                           ));
            }

            testsroot.Save(testspath);//run over the existing file
        }
Esempio n. 5
0
        public void addTest(MY_BE.Test test)
        {
            bool    canDoTest  = true;
            string  exception  = "";
            Trainee newTrainee = new Trainee();
            Tester  newTester  = new Tester();

            foreach (var item in getAllTrainees())//check if trainee is valid for test
            {
                if (item.id == test.TraineeId)
                {
                    newTrainee = item;
                    if (item.TraineeVehicle != test.TraineeVehicle)
                    {
                        canDoTest  = false;
                        exception += "The Trainee is tested on other vehicles\n";
                    }//trainee vehicle is the same as test vehicle
                    else if (item.TraineeVehicle == test.TraineeVehicle && item.passedTheTest == true)
                    {
                        canDoTest  = false;
                        exception += "The Trainee has already passed the test\n";
                    }//if the trainee already passed the test
                    if ((test.TestDateTime - item.TestDay).TotalDays <= Configuration.TEST_TO_TEST_TIME_RANGE)
                    {
                        canDoTest  = false;
                        exception += "you need to wait 7 days between tests\n";
                    }//a week between the last test and current test
                    if (item.DrivingLessonsNumber < Configuration.MIN_CLASS_NUM)
                    {
                        canDoTest  = false;
                        exception += "atleast 20 lessons required to make a test\n";
                    }//check if the trainee did less than 20 lessons
                    break;//only one student with matching id in the list
                }
            }
            //var arr = getAllTesters().Where(x => x.weekdays[test.TestDateTime.DayOfWeek, test.TestDateTime.Hour]);

            foreach (var item in getAllTesters())
            {
                canDoTest = true;
                if (!item.weekdays[test.TestDateTime.DayOfWeek, test.TestDateTime.Hour])
                {
                    canDoTest = false;

                    /*try
                     * {
                     *  //item.nextAvailableTest();
                     * }
                     * catch(Exception e)
                     * {
                     *  exception += "the selected hour is already taken.\n" + e.Message;
                     * }*/
                }//check if the test hour is not taken
                if (item.MaxWeeklyTests <= item.weekdays.currentWeeklyTests)
                {
                    canDoTest  = false;
                    exception += "passed the max number of tests this week\n";
                }//check if the tester passed the max weekly tests
                if (newTrainee.TraineeVehicle != item.TesterVehicle)
                {
                    canDoTest  = false;
                    exception += "The tester can test on another type of vehicle";
                }//check if the tester test on the trainee vehicle
                if (canDoTest)
                {
                    newTester     = item;
                    test.TesterId = item.id;
                    break;
                } //if the tester is available for testing assign the tester for the test
            }     //look for available tester

            if (canDoTest)
            {
                d.addTest(test);
                newTrainee.TestDay = test.TestDate;
                newTester.weekdays[test.TestDate.DayOfWeek, test.TestDateTime.Hour] = false;
                newTester.weekdays.currentWeeklyTests++;
            }
        }
        public void updateTestOnFinish(MY_BE.Test test)
        {
            if (test.TestDate >= DateTime.Now)
            {
                throw new Exception("the test wasnt conducted yet");
            }//you cant update test before it started

            //if (getAllTests().Where(x => x.TestNumber == test.TestNumber && x.TestParams["distance"] == 0) == null)
            //{
            //    throw new Exception("test already checked!");
            //}//check that the test wasn't checked

            if (test.isCheacked)
            {
                throw new Exception("test already checked!");
            }
            //check that the test wasn't checked


            //if (getAllTrainees().Where(x => x.id == test.TraineeId).First().passedTheTest == true)
            //{
            //    throw new Exception("Trainee already passed the test!");
            //}//check if trainee already passed the test



            bool   canupdatetest = true;
            string myException   = "";
            bool   testpassed    = true;
            int    sum           = 0;

            foreach (var item in test.TestParams)
            {
                if (item.Value == 0)
                {
                    canupdatetest = false;
                    myException  += "you must rate all the fields\n";
                    break;
                }
            }//check if the tester rated all relevant fields
            if (!test.BoolTestParams["stopped"])
            {
                testpassed = false;
            }//if the trainee didnt stop in red light/stop sign, he can't pass the test.
            else
            {
                foreach (var item in test.BoolTestParams)
                {
                    if (item.Value == true)
                    {
                        sum += 10;
                    }
                }
                foreach (var item in test.TestParams)
                {
                    sum += (int)item.Value;
                }
                testpassed = (sum >= 65);
            }//rate the trainee performence in the test and grade him
            if (canupdatetest)
            {
                //Tester tester = getAllTesters().Where(x => x.id == test.TesterId).First();
                //tester.weekdays[test.TestDate.DayOfWeek, test.TestDate.Hour] = true;
                //tester.weekdays.currentWeeklyTests--;
                //updateTester(tester);
                test.isCheacked = true;
                d.updateTestOnFinish(test);
            }
            else
            {
                throw new Exception(myException);
            }
            if (testpassed)
            {
                Trainee trainee = getAllTrainees().Where(x => x.id == test.TraineeId).First();
                trainee.passedTheTest = true;
                d.updateTrainee(trainee);
            }
        }//update the test and check if the trainee passed
        public void addTest(MY_BE.Test test)
        {
            bool    myFlag     = true;
            bool    canDoTest  = true;
            string  exception  = "";
            Trainee newTrainee = null;
            Tester  newTester  = null;

            if (test.TestDate.DayOfWeek >= DayOfWeek.Friday)
            {
                canDoTest  = false;
                exception += "you cant do a test on the weekend.\n";
            }
            if (test.TestDate.Hour < 9 || test.TestDate.Hour >= 15)
            {
                canDoTest  = false;
                exception += "the testers work between 09:00-15:00 only.\n";
            }
            if (test.TestDate <= DateTime.Now)
            {
                canDoTest  = false;
                exception += "test date must be in the future.\n";
            }
            foreach (var item in getAllTrainees())//check if trainee is valid for test
            {
                if (item.id == test.TraineeId)
                {
                    newTrainee          = item;
                    test.TraineeVehicle = item.TraineeVehicle;
                    if (item.TestDay >= DateTime.Now)
                    {
                        canDoTest  = false;
                        exception += "cant set test when you have an upcoming test.\n";
                    }//cant set a test when the trainee already have an upcoming test
                    if (item.passedTheTest == true)
                    {
                        canDoTest  = false;
                        exception += "The Trainee has already passed the test.\n";
                    }//if the trainee already passed the test
                    if ((test.TestDate - item.TestDay).TotalDays <= Configuration.TEST_TO_TEST_TIME_RANGE)
                    {
                        canDoTest  = false;
                        exception += "you need to wait " + Configuration.TEST_TO_TEST_TIME_RANGE + " days between tests.\n";
                    }//a 'Configuration.TEST_TO_TEST_TIME_RANGE' between the last test and current test
                    if (item.DrivingLessonsNumber < Configuration.MIN_CLASS_NUM)
                    {
                        canDoTest  = false;
                        exception += "atleast " + Configuration.MIN_CLASS_NUM + " lessons required to make a test.\n";
                    }//check if the trainee did less than 'Configuration.MIN_CLASS_NUM' lessons
                    break;//only one student with matching id in the list
                }
            }
            if (newTrainee == null)
            {
                throw new Exception("trainee does not exist.\n");
            }
            foreach (var item in getAllTesters())//check if tester is available for test
            {
                if (!canDoTest)
                {
                    break;
                }//if you cant do the test it wont look for tester
                if (!item.weekdays[test.TestDate.DayOfWeek, test.TestDate.Hour])
                {
                    continue;
                }//check if the test hour is available
                var v = from t in d.getAllTests()
                        where t.TesterId == item.id
                        select t;
                foreach (Test _test in v)
                {
                    if (_test.TestDate == test.TestDate)
                    {
                        myFlag = false;
                    }
                }
                if (!myFlag)
                {
                    continue;
                }//check if the tester not had test in this time
                if (item.MaxWeeklyTests == item.weekdays.currentWeeklyTests)
                {
                    continue;
                }//check if the tester passed the max weekly tests
                if (newTrainee.TraineeVehicle != item.TesterVehicle)
                {
                    continue;
                }//check if the tester test on the trainee vehicle
                if (getDistance(test.TestAdress, item.TesterAdress) > item.MaxDistance)
                {
                    continue;
                }//check if the tester is close enough to the test location
                newTester     = item; //if the tester is available for testing assign the tester for the test
                test.TesterId = item.id;
                break;
            }//look for available tester
            if (newTester == null)
            {
                canDoTest  = false;
                exception += "no available tester.\n";
            }//check if there was an available tester for the test
            if (canDoTest)
            {
                ++MY_BE.Configuration.TEST_ID;
                test.TestNumber = (MY_BE.Configuration.TEST_ID).ToString("00000000");
                d.addTest(test);
                newTrainee.TestDay = test.TestDate;
                //newTester.weekdays[test.TestDate.DayOfWeek, test.TestDate.Hour] = false;
                newTester.weekdays.currentWeeklyTests++;
                updateTester(newTester);
                updateTrainee(newTrainee);
            }
            else
            {
                throw new Exception(exception);
            }
        }