示例#1
0
        public void updateTrainee(BE.Trainee trainee)
        {
            bool trainee_exists = false;
            bool canupdate      = false;

            foreach (Trainee item in getAllTrainees())
            {
                if (item.id == trainee.id)
                {
                    trainee_exists = true;
                    if (item.BirthDate == trainee.BirthDate && item.TraineeGender == trainee.TraineeGender)
                    {
                        canupdate = true;
                    }
                }
            }
            if (!trainee_exists)
            {
                throw new Exception("tried updating a trainee not in database");
            }
            if (canupdate)
            {
                d.updateTrainee(trainee);
            }
            else
            {
                throw new Exception("cant change birth date & gender");
            }
        }
 /// <summary>
 /// Add Trainee to xml
 /// </summary>
 /// <param name="trainee"></param>
 public void AddTrainee(BE.Trainee trainee)
 {
     if (GetTrainee(trainee.ID) != null)
     {
         throw new Exception("התלמיד כבר קיים במערכת");
     }
     try
     {
         XElement t = new XElement("Trainee");
         t.Add(new XElement("ID", trainee.ID),
               new XElement("FirstName", trainee.FirstName),
               new XElement("LastName", trainee.LastName),
               new XElement("BirthDate", trainee.BirthDate.ToString()),
               new XElement("Gender", trainee.Gender.ToString()),
               new XElement("PhoneNumber", trainee.PhoneNumber),
               new XElement("MailAddress", trainee.MailAddress.ToString()),
               new XElement("Address", trainee.Address),
               new XElement("Vehicle", trainee.Vehicle.ToString()),
               new XElement("GearBoxType", trainee.GearBoxType.ToString()),
               new XElement("DrivingSchoolName", trainee.DrivingSchoolName),
               new XElement("TeacherName", trainee.TeacherName),
               new XElement("NumOfDrivingLessons", trainee.NumOfDrivingLessons.ToString()),
               new XElement("OnlyMyGender", trainee.OnlyMyGender.ToString()));
         traineesRoot.Add(t);
         traineesRoot.Save(traineesPath);
         traineesListChainged = true;
     }
     catch (Exception)
     { }
 }
示例#3
0
        public void addTrainee(BE.Trainee trainee)
        {
            int    traineeBirthYear = trainee.BirthDate.Year;
            bool   canaddtrainee    = true;
            int    currentYear      = DateTime.Now.Year;
            string exception        = "";

            foreach (Trainee item in getAllTrainees())
            {
                if (trainee.id == item.id)
                {
                    exception    += "trainee with the same id already exists\n";
                    canaddtrainee = false;
                }
            }
            if (currentYear - traineeBirthYear < Configuration.MIN_TRAINEE_AGE)
            {
                canaddtrainee = false;
                exception    += "tried to insert trainee younger than 18.\n";
            }
            if (canaddtrainee)
            {
                d.addTrainee(trainee);
            }
            else
            {
                throw new Exception(exception);
            }
        }
示例#4
0
 public AddTrainee()
 {
     InitializeComponent();
     trainee = new BE.Trainee();
     _bl     = FactorySingletonBl.GetBl();
     init();
 }
 /// <summary>
 /// Update Trainee to xml
 /// </summary>
 /// <param name="trainee"></param>
 public void UpdateTrainee(BE.Trainee trainee)
 {
     try
     {
         XElement t = (from item in traineesRoot.Elements()
                       where item.Element("ID").Value == trainee.ID
                       select item).FirstOrDefault();
         t.Element("FirstName").Value           = trainee.FirstName;
         t.Element("LastName").Value            = trainee.LastName;
         t.Element("BirthDate").Value           = trainee.BirthDate.ToString();
         t.Element("Gender").Value              = trainee.Gender.ToString();
         t.Element("PhoneNumber").Value         = trainee.PhoneNumber;
         t.Element("MailAddress").Value         = trainee.MailAddress.ToString();
         t.Element("Address").Value             = trainee.Address;
         t.Element("Vehicle").Value             = trainee.Vehicle.ToString();
         t.Element("GearBoxType").Value         = trainee.GearBoxType.ToString();
         t.Element("DrivingSchoolName").Value   = trainee.DrivingSchoolName;
         t.Element("TeacherName").Value         = trainee.TeacherName;
         t.Element("NumOfDrivingLessons").Value = trainee.NumOfDrivingLessons.ToString();
         t.Element("OnlyMyGender").Value        = trainee.OnlyMyGender.ToString();
         traineesRoot.Save(traineesPath);
         traineesListChainged = true;
     }
     catch (Exception)
     {
         throw new KeyNotFoundException("שגיאה בעדכון התלמיד " + trainee.ID);
     }
 }
示例#6
0
 private void TraineeIdTextBox_OnLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
 {
     try
     {
         bl.CheckId(TraineeForPL.TraineeId);
         //make a check if in system- make a messege box option for update/delete then "select" the combox option.
         if (bl.TraineeInSystem(TraineeForPL.TraineeId))
         {
             MessageBoxResult dialogResult =
                 MessageBox.Show("Trainee alredy exists in the system! Do you want to update?", "Warning",
                                 MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
             if (dialogResult == MessageBoxResult.Yes)
             {
                 TraineeComboBox.Visibility    = Visibility.Visible;
                 traineeIdTextBox.Visibility   = Visibility.Hidden;
                 TraineeComboBox.SelectedValue = (object)TraineeForPL.TraineeId;
                 TraineeForPL = bl.GetListOfTrainees()
                                .FirstOrDefault(x => x.TraineeId == traineeIdTextBox.Text);
             }
             else if (dialogResult == MessageBoxResult.No)
             {
                 TraineeForPL            = new Trainee();
                 TraineeGrid.DataContext = TraineeForPL;
             }
         }
     }
     catch (Exception ex)
     {
         IdErrors.Text                = ex.Message;
         IdErrors.Foreground          = Brushes.Red;
         traineeIdTextBox.BorderBrush = Brushes.Red;
     }
 }
示例#7
0
 private void DeleteTrainee_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         removewarnings();
         Save.Content = "Delete";
         TraineeForPL = new Trainee();
         TraineeComboBox.Visibility   = Visibility.Visible;
         traineeIdTextBox.Visibility  = Visibility.Hidden;
         TraineeComboBox.SelectedItem = null;
         TraineeGrid.DataContext      = TraineeForPL;
         closeAlmostAll();
         Save.IsEnabled   = false;
         IdErrors.Text    = "First Select ID";
         TraineeListForPL = bl.GetListOfTrainees();
         if (TraineeListForPL == null)
         {
             throw new Exception("There are no trainees to delete.");
         }
         if (TraineeListForPL.Count == 0)
         {
             throw new Exception("There are no trainees to delete.");
         }
         TraineeGrid.Visibility      = Visibility.Visible;
         TraineeComboBox.ItemsSource = bl.GetListOfTrainees().Select(x => x.TraineeId);
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
 public numberOfTestForTraineeWindow(BE.Trainee t)
 {
     InitializeComponent();
     WindowStartupLocation = WindowStartupLocation.CenterScreen;
     bl      = BL.FactoryBL.getBL();
     trainee = t;
     comboBox.ItemsSource = Enum.GetValues(typeof(CarType));
 }
        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);
        }
示例#10
0
 public AddTrainee(BE.Trainee traineeToUp)//update send an existing trainee
 {
     InitializeComponent();
     trainee = traineeToUp;
     this.IDTBox.IsReadOnly = true;
     _bl = FactorySingletonBl.GetBl();
     init();
     this.AddTraineeButton.Content = "Update";
 }
示例#11
0
        public AddTrainee()
        {
            InitializeComponent();

            trainee = new BE.Trainee();
            this.gridAddTrainee.DataContext = trainee;
            bl = BL.FactoryBL.getBL();
            Gender.ItemsSource   = Enum.GetValues(typeof(BE.Gender));
            GearType.ItemsSource = Enum.GetValues(typeof(BE.GearType));
        }
 private void AddLesson_Click(object sender, RoutedEventArgs e)
 {
     BE.Trainee t = trainee.SelectionBoxItem as Trainee;
     if (t != null)
     {
         t.LessonsNumber += 1;
         factoryBL.FactoryBL.GetBL().UpdateTrainee(t);
         addLesson.Content = t.LessonsNumber;
     }
 }
示例#13
0
 public AddTrainee()
 {
     InitializeComponent();
     trainee = new BE.Trainee {
         DayOfBirth = new DateTime(2000, 1, 1), Address = new Address(), CarTrained = new CarType(), Name = new Name(), Instructor = new Name()
     };
     this.DataContext = trainee;
     this.genderComboBox.ItemsSource   = Enum.GetValues(typeof(BE.Gender));
     this.carTypeComboBox.ItemsSource  = Enum.GetValues(typeof(BE.carType));
     this.gearTypeComboBox.ItemsSource = Enum.GetValues(typeof(BE.GearType));
 }
示例#14
0
 /// <summary>
 /// this function recieves a trainee and returns if he had passed the test
 /// </summary>
 /// <param name="t">the trainee</param>
 /// <returns>true-if the trainee passed, else-false</returns>
 public bool DeserveDriversLicence(BE.Trainee t)
 {
     foreach (Test test in dal.GetTests())
     {
         if (test.TraineeId.CompareTo(t.TraineeId) == 0 && test.Grade)
         {
             return(true);
         }
     }
     return(false);
 }
示例#15
0
        public UpdateTrainee()
        {
            InitializeComponent();
            trainee          = new BE.Trainee();
            this.DataContext = trainee;
            bl = BL.FactoryBL.getBL();
            IDComboBox.ItemsSource = from item in bl.getAllTrainee()
                                     select item.branchNumber;

            Gendr.ItemsSource    = Enum.GetValues(typeof(BE.Gender));
            GearType.ItemsSource = Enum.GetValues(typeof(BE.GearType));
        }
        public MainWindow()
        {
            InitializeComponent();

            bl = BL.factoryBL.getBL();

            currentTesters  = bl.testersList();
            currentTrainees = bl.traineesList();

            myTester  = new BE.Tester();
            myTrainee = new BE.Trainee();
        }
示例#17
0
        public AddTrainee1()
        {
            InitializeComponent();
            trainee          = new BE.Trainee();
            this.DataContext = trainee;
            bl = BL.FactoryBL.GetBL();
            trainee.BirthDay = DateTime.Now.AddYears(-(int)Configuration.MinAgeOfTrainee);
            trainee.BirthDay = trainee.BirthDay.AddDays(-1);

            sexComboBox.ItemsSource            = Enum.GetValues(typeof(BE.Gender));
            gearTypeComboBox.ItemsSource       = Enum.GetValues(typeof(BE.GearType));
            currentCarTypeComboBox.ItemsSource = Enum.GetValues(typeof(BE.VehicleType));
        }
        /// <summary>
        /// this function recieves a trainee and returns the amount of tests that he did
        /// </summary>
        /// <param name="t">the trainee</param>
        /// <returns>amount of tests that the trainee did </returns>
        public int TraineeNumOfTests(BE.Trainee t)
        {
            int count = 0;

            foreach (Test test in dal.GetTests())
            {
                if (test.TraineeId.CompareTo(t.traineeId) == 0)
                {
                    count++;
                }
            }
            return(count);
        }
示例#19
0
 private void Add_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         bl.addTrainee(trainee);
         MessageBox.Show("the trainee " + trainee.FirstName + trainee.FamilyName + " was added", "");
         trainee = new BE.Trainee();
         this.gridAddTrainee.DataContext = trainee;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#20
0
 private void Update_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         bl.updateTrainee(trainee);
         trainee = new BE.Trainee();
         MessageBox.Show("the trainee " + trainee.FirstName + " update ", "");
         this.DataContext = trainee;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        /// <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()));

            ;
        }
示例#22
0
 private void AddTrainee_Click(object sender, RoutedEventArgs e)
 {
     removewarnings();
     // TraineeComboBox.ItemsSource = bl.GetListOfTrainees().Select(x => x.TraineeId);
     TraineeForPL = new Trainee();
     openAll();
     TraineeGrid.DataContext     = TraineeForPL;
     IdErrors.Text               = "";
     traineeIdTextBox.Visibility = Visibility.Visible;
     TraineeGrid.Visibility      = Visibility.Visible;
     TraineeComboBox.Visibility  = Visibility.Hidden;
     TraineeGrid.IsEnabled       = true;
     Save.Content   = "Check";
     Save.IsEnabled = true;
 }
 /// <summary>
 /// Update relevant properties of Trainee
 /// </summary>
 /// <param name="trainee"></param>
 public void UpdateTrainee(Trainee trainee)
 {
     BE.Trainee ExistTrainee = IDAL.GetTraineeCopy(trainee.ID);
     if (ExistTrainee == null)
     {
         throw new KeyNotFoundException("לא נמצא תלמיד שמספרו " + trainee.ID);
     }
     if (ExistTrainee.Gender != trainee.Gender || ExistTrainee.BirthDate != trainee.BirthDate ||
         ExistTrainee.Vehicle != trainee.Vehicle || ExistTrainee.GearBoxType != trainee.GearBoxType ||
         ExistTrainee.DrivingSchoolName != trainee.DrivingSchoolName || ExistTrainee.TeacherName != trainee.TeacherName)
     {
         throw new KeyNotFoundException("לא ניתן לשנות מידע בסיסי של תלמיד");
     }
     IDAL.UpdateTrainee(trainee);
 }
        /// <summary>
        /// Remove Trainee from the DataBase
        /// </summary>
        /// <param name="ID">the ID fo Trainee to remove</param>
        public void RemoveTrainee(string ID)
        {
            BE.Trainee trainee = IDAL.GetTraineeCopy(ID);
            if (trainee == null)
            {
                throw new KeyNotFoundException("לא נמצא תלמיד שמספרו " + ID);
            }
            IDAL.RemoveTrainee(ID);
            var listToRemove = IDAL.GetAllTests(t => t.TraineeID == ID && t.Time > DateTime.Now).Select(t => t.TestID).ToArray();

            foreach (var item in listToRemove)
            {
                IDAL.RemoveTest(item);
            }
        }
        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       = "הת.ז. שהוזן לא נמצא במערכת ";
            }
        }
示例#26
0
文件: Trainee.cs 项目: AviK311/WPF
 public Trainee(Trainee other)
 {
     notifications = new List <Notification>(other.notifications);
     foreach (PropertyInfo property in other.GetType().GetProperties())
     {
         if (property.CanWrite)
         {
             property.SetValue(this, property.GetValue(other));
         }
     }
     carTypeStats = new Dictionary <VehicleType, Stats>();
     foreach (var item in other.carTypeStats)
     {
         carTypeStats.Add(item.Key, new Stats(item.Value));
     }
 }
 //Copy Constructor to Trainee
 public Trainee(Trainee traineeToCopy)
 {
     ID                   = traineeToCopy._ID;
     lastName             = traineeToCopy.last_name;
     firstName            = traineeToCopy.first_name;
     dateOfBirth          = traineeToCopy.birth;
     genderOfTrainee      = traineeToCopy.gender;
     phoneNumber          = traineeToCopy._phoneNumber;
     adressOfTrainee      = traineeToCopy._adressOfTrainee;
     carTypeOfTrainee     = traineeToCopy._typeCarOfTrainee;
     gearboxTypeOfTrainee = traineeToCopy._gearboxTypeOfTrainee;
     drivingSchool        = traineeToCopy._drivingSchool;
     nameOfTeacher        = traineeToCopy._nameOfTeacher;
     numberOfLessons      = traineeToCopy._lessons;
     password             = traineeToCopy._password;
 }
示例#28
0
        public void updateTrainee(BE.Trainee trainee)
        {
            trainees = LoadFromXML <List <Trainee> >(traineespath);
            Trainee t = new Trainee();

            foreach (Trainee item in trainees)
            {
                if (item.id == trainee.id)
                {
                    t = item;
                }
            }
            trainees.Remove(t);
            trainees.Add(trainee);
            SaveToXML(trainees, traineespath);
        }
 /// <summary>
 /// add Trainee to the DataBase
 /// </summary>
 /// <param name="trainee"></param>
 public void AddTrainee(Trainee trainee)
 {
     if (trainee.Address == null || trainee.Address == "" || trainee.BirthDate == default(DateTime) ||
         trainee.FirstName == null || trainee.FirstName == "" ||
         trainee.LastName == null || trainee.LastName == "" || trainee.PhoneNumber == null || trainee.PhoneNumber == "" ||
         trainee.TeacherName == null || trainee.TeacherName == "" ||
         trainee.DrivingSchoolName == null || trainee.DrivingSchoolName == "")
     {
         throw new Exception("חובה למלא את כל הפרטים");
     }
     BE.Trainee ExsistTrainee = IDAL.GetTraineeCopy(trainee.ID);
     if (ExsistTrainee != null)
     {
         throw new Exception("התלמיד כבר קיים במערכת");
     }
     IDAL.AddTrainee(trainee);
 }
示例#30
0
 public Trainee(Trainee trainee)
 {
     id                   = trainee.id;
     FamilyName           = trainee.FamilyName;
     PrivateName          = trainee.PrivateName;
     BirthDate            = trainee.BirthDate;
     TraineeGender        = trainee.TraineeGender;
     PhoneNumber          = trainee.PhoneNumber;
     TraineeAdress        = trainee.TraineeAdress;
     TraineeVehicle       = trainee.TraineeVehicle;
     TraineeGearbox       = trainee.TraineeGearbox;
     DrivingSchool        = trainee.DrivingSchool;
     TeacherName          = trainee.TeacherName;
     DrivingLessonsNumber = trainee.DrivingLessonsNumber;
     TestDay              = trainee.TestDay;
     passedTheTest        = trainee.passedTheTest;
 }//copy constructor