Ejemplo n.º 1
0
        public void addTest(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))))
                                             );

            testsroot.Add(xelement);
            testsroot.Save(testspath);
            configroot = new XElement("config", new XElement("TEST_ID", Configuration.TEST_ID));
            configroot.Save(configpath);
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                switch (saveButton.Content.ToString())
                {
                case "Save":
                    fillFields();
                    bl.UpdateTest(TestForPL);
                    TestForPL = new Test();
                    this.TestDetailsGrid.DataContext  = TestForPL;
                    this.commentsGroupBox.DataContext = TestForPL;
                    MessageBox.Show("Test saved successfully", "", MessageBoxButton.OK, MessageBoxImage.Information);
                    keptDistanceCheckBox.IsChecked = false;
                    testPassedCheckBox.IsChecked   = false;
                    closeAlmostAll();
                    break;

                case "Check":
                    saveButton.Content = "Save";
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " Test not saved.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                saveButton.Content = "Check";
            }
        }
Ejemplo n.º 3
0
Archivo: BL.cs Proyecto: asafJct/MINI
 public void updateTest(BE.Test o)
 {
     if (dal.findTest(o.studentId))
     {
         dal.updateTest(o);
     }
 }
        public SortedSet <DateTime> avalibleDateTimes(Test test)
        {
            BE.Trainee trainee = IDAL.GetTraineeCopy(test.TraineeID);
            var        result  = new SortedSet <DateTime>();
            DateTime   time    = DateTime.Now.AddDays(2);

            time = time.AddMinutes(120 - time.Minute);
            while (time <= DateTime.Now.AddDays(BE.Configuration.AllowToAddTest_DaysInAdvance))
            {
                try
                {
                    test.Time = time;

                    BE.Test LastPreviusTest = null, FirstNextTest = null;
                    foreach (var item in IDAL.GetAllTests(t => t.TraineeID == test.TraineeID))
                    {
                        if (item.Time < test.Time && (LastPreviusTest == null || LastPreviusTest.Time < item.Time))
                        {
                            LastPreviusTest = item;
                        }
                        else if (item.Time >= test.Time && (FirstNextTest == null || LastPreviusTest.Time < item.Time))
                        {
                            FirstNextTest = item;
                        }
                    }
                    if (LastPreviusTest != null && (test.Time - LastPreviusTest.Time).Days < BE.Configuration.MinimumDaysBetweenTests ||
                        FirstNextTest != null && (FirstNextTest.Time - test.Time).Days < BE.Configuration.MinimumDaysBetweenTests)
                    {
                        throw new Exception("לתלמיד זה קיים מבחן בהפרש של פחות משבעה ימים.");
                    }
                    if (test.Time != NextWorkTime(test.Time))
                    {
                        throw new Exception("מועד הטסט מחוץ לשעות העבודה. \nשעות העבודה בימי השבוע הם: " + BE.Configuration.WorkStartHour + " עד " + BE.Configuration.WorkEndHour);
                    }

                    BE.Tester tester = (from item in GetAllTesters(test.Time)
                                        where item.Vehicle == trainee.Vehicle &&
                                        BE.Tools.Maps_DrivingDistance(item.Address, test.Address) < item.MaxDistanceInMeters &&
                                        (!trainee.OnlyMyGender || item.Gender == trainee.Gender) &&
                                        item.GearBoxType == trainee.GearBoxType &&
                                        NumOfTestsInWeek(item, test.Time) < item.MaxTestsInWeek
                                        select item).FirstOrDefault();
                    if (tester == null)
                    {
                        throw new Exception("הזמן המבוקש תפוס");
                    }
                    result.Add(time);
                    time = time.AddDays(1);
                    time = time.AddHours(-time.Hour + BE.Configuration.WorkStartHour);
                }
                catch (Exception)
                {
                    time = time.AddMinutes(15);
                }
                time = NextWorkTime(time);
            }
            return(result);
        }
 /// <summary>
 /// Remove Test
 /// </summary>
 /// <param name="ID"></param>
 public void RemoveTest(int ID)
 {
     BE.Test Existtest = IDAL.GetTestCopy(ID);
     if (Existtest == null)
     {
         throw new KeyNotFoundException("לא נמצא מבחן שמספרו " + ID);
     }
     SendEmail(ID, EmailType.TestCancelation);
     IDAL.RemoveTest(ID);
 }
 /// <summary>
 /// Remove Test
 /// </summary>
 /// <param name="ID"></param>
 public void RemoveTest(int ID)
 {
     BE.Test test = GetTest(ID);
     if (test == null)
     {
         throw new KeyNotFoundException("לא נמצא טסט שמספרו " + ID);
     }
     tests.Remove(test);
     SaveToXML <List <Test> >(tests, testsPath);
 }
        /// <summary>
        /// Update Test Result
        /// </summary>
        /// <param name="test"></param>
        public void UpdateTestResult(BE.Test test)
        {
            int indexTest = tests.FindIndex(t => t.TestID == test.TestID);

            if (indexTest == -1)
            {
                throw new KeyNotFoundException("לא נמצא מבחן שמספרו " + test.TestID);
            }
            tests[indexTest] = test.Clone();
            SaveToXML <List <Test> >(tests, testsPath);
        }
Ejemplo n.º 8
0
        public AddTest()
        {
            InitializeComponent();
            test             = new Test();
            this.DataContext = test;
            bl = BL.FactoryBL.getBL();
            TraineeIDcomboBox.ItemsSource = from item in bl.getAllTrainee()
                                            select item.branchNumber;

            TesterIDcomboBox.ItemsSource = from item in bl.getAllTester()
                                           select item.TesterID;
        }
 private void TestIdComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (testIdComboBox.SelectedItem != null)
     {
         string id = ((Test)testIdComboBox.SelectedItem).TestId;
         TestForPL = bl.GetListOfTests().FirstOrDefault(a => a.TestId == id);
         setChecks();
         testPassedCheckBox.IsChecked = TestForPL.TestPassed;
         testerIdTextBox.Text         = TestForPL.TesterId;
         traineeIdTextBox.Text        = TestForPL.TraineeId;
         testDateDatePicker.Text      = TestForPL.TestDate.ToString();
         openAll();
     }
 }
        /// <summary>
        /// Update test results when done.
        /// </summary>
        /// <param name="test"></param>
        public void UpdateTestResult(BE.Test test)
        {
            if (test.Time > DateTime.Now)
            {
                throw new Exception("לא ניתן לעדכן תוצאות לטסט שעדיין לא התבצע.");
            }
            int sum = 0;

            foreach (var pair in test.Indices)
            {
                sum += (int)pair.Value;
            }
            test.Passed = (100 * sum / (3 * test.Indices.Count) >= BE.Configuration.PassingGrade && !test.Indices.Any(pair => pair.Value == BE.Score.נכשל));
            IDAL.UpdateTestResult(test);
        }
 public testUpdateWindow(Test test)
 {
     testcontrol = test;
     InitializeComponent();
     testUpdateGrid.DataContext = testcontrol;
     par1.ItemsSource           = Enum.GetValues(typeof(Rating));
     par2.ItemsSource           = Enum.GetValues(typeof(Rating));
     par3.ItemsSource           = Enum.GetValues(typeof(Rating));
     par4.ItemsSource           = Enum.GetValues(typeof(Rating));
     par5.ItemsSource           = Enum.GetValues(typeof(Rating));
     par6.ItemsSource           = Enum.GetValues(typeof(Rating));
     par7.ItemsSource           = Enum.GetValues(typeof(Rating));
     par8.ItemsSource           = Enum.GetValues(typeof(Rating));
     par9.ItemsSource           = Enum.GetValues(typeof(Rating));
 }
        /// <summary>
        /// Get Email Temltate Test Remeinder
        /// </summary>
        /// <param name="TestID"></param>
        /// <param name="NoteToAdd"></param>
        /// <returns></returns>
        public string GetEmailTemltateTestRemeinder(int TestID, string NoteToAdd = "")
        {
            BE.Test    test    = GetTest(TestID);
            BE.Trainee trainee = GetTrainee(test.TraineeID);
            return(RemeinderEmailHTML
                   .Replace("@@Name@@", trainee.FirstName + (trainee.Gender == BE.Gender.זכר ? " היקר " : " היקרה "))
                   .Replace("@@DATE@@", test.Time.ToString("dd/MM/yyyy"))
                   .Replace("@@TIME@@", test.Time.ToString("HH:mm"))
                   .Replace("@@ADDRESS@@", test.Address)
                   .Replace("@@LINK@@", "https://www.google.com/maps/search/" + test.Address)
                   .Replace("@@NOTES@@", NoteToAdd.Replace("\n", "<br>"))
                   .Replace("@@TESTID@@", test.TestID.ToString()));

            ;
        }
Ejemplo n.º 13
0
        public void DisplayResult(Object sender, EventArgs e)
        {
            BL.IBL bl    = BL.FactoryBL.GetBL();
            var    bc    = new BrushConverter();
            string id    = this.checkId.Text;
            int    newid = int.Parse(id);

            BE.Trainee isExistTrainee = bl.getTraineeBL(newid);
            if (isExistTrainee != null)
            {
                BE.Test testOfnumber = bl.getTestByNumber((checkTestNumber.Text));
                if (testOfnumber != null)
                {
                    if (isExistTrainee.Id == testOfnumber.TraineeId)
                    {
                        details.Foreground = (Brush)bc.ConvertFrom("#019EAA");

                        if (testOfnumber.PassedTheTest == true)
                        {
                            details.Text = "!מזל טוב עברת את הטסט בהצלחה \nהודעה רישמית תשלח אליך בהקדם\n\nתודה שבחרתם בטסט דרייב\n\n\n";
                        }
                        else
                        {
                            details.Text = "לצערנו לא עברת את המבחן\nלא נורא פעם הבאה תצליח\n\n\n";
                        }

                        string help = ":הערת הבוחן";
                        help         += testOfnumber.TesterComment;
                        details.Text += help;
                    }
                    else
                    {
                        details.Foreground = (Brush)bc.ConvertFrom("Red");
                        details.Text       = "הת.ז. לא מתאים למספר מבחן שהוזן ";
                    }
                }
                else
                {
                    details.Foreground = (Brush)bc.ConvertFrom("Red");
                    details.Text       = "המספר מבחן שהוזן לא נמצא במערכת";
                }
            }
            else
            {
                details.Foreground = (Brush)bc.ConvertFrom("Red");
                details.Text       = "הת.ז. שהוזן לא נמצא במערכת ";
            }
        }
Ejemplo n.º 14
0
 private void Add_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         ++oN;
         test.TestID = oN;
         bl.addTest(test);
         MessageBox.Show(test.TraineeID + " your Test Added successfully, test number is " + test.TestID, " ");
         test             = new BE.Test();
         this.DataContext = test;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 /// <summary>
 /// update address and time fo test
 /// </summary>
 /// <param name="test"></param>
 public void UpdateTest(Test test)
 {
     if (test.Time < DateTime.Now)
     {
         throw new Exception("לא ניתן לעדכן פרטי טסט שכבר התבצע.");
     }
     BE.Test ExistTest = IDAL.GetTestCopy(test.TestID);
     RemoveTest(ExistTest.TestID);
     try
     {
         AddTest(test);
     }
     catch (Exception ex)
     {
         IDAL.AddTest(ExistTest);
         throw ex;
     }
 }
        public UpdateTest()
        {
            InitializeComponent();
            try
            {
                testerIdTextBox.IsReadOnly  = true;
                traineeIdTextBox.IsReadOnly = true;

                checkMirrorsCheckBox.Checked          += CheckBox_Checked;
                imediateStopCheckBox.Checked          += CheckBox_Checked;
                keptDistanceCheckBox.Checked          += CheckBox_Checked;
                keptRightofPresidenceCheckBox.Checked += CheckBox_Checked;
                parkingCheckBox.Checked            += CheckBox_Checked;
                reverseParkingCheckBox.Checked     += CheckBox_Checked;
                rightTurnCheckBox.Checked          += CheckBox_Checked;
                stoppedAtcrossWalkCheckBox.Checked += CheckBox_Checked;
                stoppedAtRedCheckBox.Checked       += CheckBox_Checked;
                usedSignalCheckBox.Checked         += CheckBox_Checked;

                bl        = IBL_imp.Instance;
                TestForPL = new Test();
                this.TestDetailsGrid.DataContext  = TestForPL;
                this.commentsGroupBox.DataContext = TestForPL;
                this.testPassedGrid.DataContext   = TestForPL;
                this.BoolItemsGrid.DataContext    = TestForPL;
                TestListForPL = bl.GetListOfTests();
                if (TestListForPL == null)
                {
                    throw new Exception("There are no Tests to update");
                }
                this.DataContext = TestForPL;
                this.testIdComboBox.ItemsSource = bl.GetListOfTests().OrderByDescending(x => x.TestId);
                closeAlmostAll();
                if (TestListForPL.Count == 0)
                {
                    throw new Exception("There are no Tests to update");
                }
            }
            catch (Exception ex)
            {
                testIdComboBox.IsEnabled = false;
                noTests.Visibility       = Visibility.Visible;
            }
        }
Ejemplo n.º 17
0
        public CreateTestWin()
        {
            InitializeComponent();
            _bl              = FactorySingletonBl.GetBl();
            test             = new BE.Test();
            this.DataContext = test;


            this.exitPointCityComboBox.ItemsSource = Enum.GetValues(typeof(Cities));

            this.traineeIDComboBox.ItemsSource       = _bl.GetTrainees();
            this.traineeIDComboBox.DisplayMemberPath = "ID";
            //test hour
            for (int i = 9; i < 15; i++)
            {
                string str = i + ":00";
                this.testHourComboBox.Items.Add(str);
            }



            findTesterButton.Visibility     = Visibility.Visible;
            availabilityDataGrid.Visibility = Visibility.Hidden;
            testerDetailsLabel.Visibility   = Visibility.Hidden;
            this.AddTestButton.Visibility   = Visibility.Hidden;


            //set the time picker to next 1000 days; friday & saturday will be unavailable;
            testDayDatePicker.DisplayDateStart = DateTime.Now;
            testDayDatePicker.DisplayDateEnd   = DateTime.Now + TimeSpan.FromDays(1000);
            var minDate = testDayDatePicker.DisplayDateStart ?? DateTime.MinValue;
            var maxDate = testDayDatePicker.DisplayDateEnd ?? DateTime.MaxValue;

            for (var d = minDate; d <= maxDate && DateTime.MaxValue > d; d = d.AddDays(1))
            {
                if (d.DayOfWeek == DayOfWeek.Saturday || d.DayOfWeek == DayOfWeek.Friday)
                {
                    testDayDatePicker.BlackoutDates.Add(new CalendarDateRange(d));
                }
            }
        }
Ejemplo n.º 18
0
        public object findById(int num)//return the object(trianee/ tester/ test) according to id/code of test
        {
            BE.Tester tester = getTestersList().Find(x => x.ID == num);
            if (tester != null)
            {
                return(tester);
            }
            BE.Trainee trainee = getTraineeList().Find(x => x.ID == num);
            if (trainee != null)
            {
                return(trainee);
            }
            BE.Test test = getTestsList().Find(x => x.numOfTest == num);
            if (test != null)
            {
                return(test);
            }

            else
            {
                throw new Exception("No such Id in our database.");
            }
        }
Ejemplo n.º 19
0
        public void updateTestOnFinish(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))))
                                           ));
            }

            testsroot.Save(testspath);//run over the existing file
        }
        /// <summary>
        /// add Test to the DataBase
        /// </summary>
        /// <param name="test"></param>
        public void AddTest(BE.Test test)
        {
            if (test.Address == null || test.Address == "" || test.TraineeID == null || test.TraineeID == "")
            {
                throw new Exception("חובה למלא את כל השדות");
            }
            BE.Trainee trainee = IDAL.GetTraineeCopy(test.TraineeID);
            if (trainee == null)
            {
                throw new KeyNotFoundException("לא נמצא תלמיד שמספרו " + test.TraineeID);
            }
            if (trainee.NumOfDrivingLessons < BE.Configuration.MinimumDrivingLessons)
            {
                throw new Exception("אין אפשרות להוסיף מבחן לתלמיד שעשה פחות מ-." + BE.Configuration.MinimumDrivingLessons + " שיעורים.");
            }

            BE.Test LastPreviusTest = null, FirstNextTest = null;
            foreach (var item in IDAL.GetAllTests(t => t.TraineeID == test.TraineeID))
            {
                if (item.Time < test.Time && (LastPreviusTest == null || LastPreviusTest.Time < item.Time))
                {
                    LastPreviusTest = item;
                }
                else if (item.Time >= test.Time && (FirstNextTest == null || LastPreviusTest.Time < item.Time))
                {
                    FirstNextTest = item;
                }
            }
            if (LastPreviusTest != null && (test.Time - LastPreviusTest.Time).Days < BE.Configuration.MinimumDaysBetweenTests ||
                FirstNextTest != null && (FirstNextTest.Time - test.Time).Days < BE.Configuration.MinimumDaysBetweenTests)
            {
                throw new Exception("לתלמיד זה קיים מבחן בהפרש של פחות משבעה ימים.");
            }
            if (test.Time < DateTime.Now)
            {
                throw new Exception("מועד הטסט חלף");
            }
            if (test.Time != NextWorkTime(test.Time))
            {
                throw new Exception("מועד הטסט מחוץ לשעות העבודה. \nשעות העבודה בימי השבוע הם: " + BE.Configuration.WorkStartHour + " עד " + BE.Configuration.WorkEndHour);
            }

            BE.Tester tester = (from item in GetAllTesters(test.Time)
                                where item.Vehicle == trainee.Vehicle &&
                                BE.Tools.Maps_DrivingDistance(item.Address, test.Address) < item.MaxDistanceInMeters &&
                                (!trainee.OnlyMyGender || item.Gender == trainee.Gender) &&
                                item.GearBoxType == trainee.GearBoxType &&
                                NumOfTestsInWeek(item, test.Time) < item.MaxTestsInWeek
                                select item).FirstOrDefault();
            DateTime time = test.Time;

            if (tester == null)
            {
                time = time.AddMinutes(-time.Minute);
                while (!(from item in GetAllTesters(time)
                         where item.Vehicle == trainee.Vehicle &&
                         (!trainee.OnlyMyGender || item.Gender == trainee.Gender) &&
                         item.GearBoxType == trainee.GearBoxType &&
                         BE.Tools.Maps_DrivingDistance(item.Address, test.Address) < item.MaxDistanceInMeters
                         select item).Any() && time.Subtract(DateTime.Now).TotalDays < 30)
                {
                    time += new TimeSpan(0, 30, 0);
                    time  = NextWorkTime(time);
                }
                if (time.Subtract(DateTime.Now).TotalDays >= 30)
                {
                    throw new Exception("הזמן המבוקש תפוס. לא קיים זמן פנוי בשלושת החודשים הקרובים.");
                }
                else
                {
                    throw new Exception("הזמן המבוקש תפוס, אבל יש לנו זמן אחר להציע לך: " + time.Day + '/' + time.Month + '/'
                                        + time.Year + ' ' + time.Hour + ':' + time.Minute);
                }
            }
            test.TesterID = tester.ID;
            IDAL.AddTest(test);
        }
Ejemplo n.º 21
0
        public void addTest(BE.Test test)
        {
            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";
            }
            if (test.TestDate.Hour < 9 || test.TestDate.Hour >= 15)
            {
                canDoTest  = false;
                exception += "the testers work between 09:00-15:00 only";
            }
            if (test.TestDate <= DateTime.Now)
            {
                canDoTest  = false;
                exception += "test date must be in the future";
            }
            foreach (var item in getAllTrainees())//check if trainee is valid for test
            {
                if (item.id == test.TraineeId)
                {
                    newTrainee = item;
                    if (newTrainee.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.TraineeVehicle != test.TraineeVehicle)
                    {
                        canDoTest  = false;
                        exception += "The Trainee is tested on other vehicles\n";
                    }//trainee vehicle is the same as test vehicle
                    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 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
                }
            }
            if (newTrainee == null)
            {
                canDoTest = false;
                throw new Exception("trainee does not exist\n");
            }
            foreach (var item in getAllTesters())
            {
                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 not taken
                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)
            {
                ++BE.Configuration.TEST_ID;
                test.TestNumber = (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);
            }
        }
Ejemplo n.º 22
0
        public void updateTestOnFinish(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 (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);
                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
Ejemplo n.º 23
0
 public void deleteTest(BE.Test t)
 {
     dal.deleteTest(t);
 }
 /// <summary>
 /// Add Test
 /// </summary>
 /// <param name="test"></param>
 public void AddTest(BE.Test test)
 {
     tests.Add(test.Clone());
     SaveToXML <List <Test> >(tests, testsPath);
 }