/// <summary>
 /// Add Button Click
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AddButton_Click(object sender, RoutedEventArgs e)
 {
     if (errorMessages.Any())
     {
         string err = ":יש לתקן את השגיאות";
         foreach (var item in errorMessages)
         {
             err += "\n" + item;
         }
         MessageBox.Show(err);
         return;
     }
     try
     {
         this.Closing -= Window_Closing;
         bl.AddTrainee(trainee);
         DialogResult = true;
         this.Close();
     }
     catch (Exception ex)
     {
         this.Closing += Window_Closing;
         MessageBox.Show(ex.Message);
     }
 }
예제 #2
0
        private void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (passwordBoxNew.Password != passwordBoxAuthentication.Password)
                {
                    throw new CasingException(true, new Exception("The authentication password not correct."));
                }

                if (bl.GetTrainee(iDTextBox.Text) != null)
                {
                    throw new CasingException(true, new Exception("This id already exists in the system"));
                }

                try
                {
                    trainee.Name        = new Person.PersonName(lastNameTextBox.Text, firstNameTextBox.Text);
                    trainee.TeacherName = new Person.PersonName(TeacherLastNameTextBox.Text, TeacherFirstNameTextBox.Text);
                    trainee.Address     = new Address(Street.Text, uint.Parse(HouseNumber.Text), City.Text);
                    trainee.Password    = passwordBoxNew.Password;
                }
                catch (Exception ex)
                {
                    throw new CasingException(true, ex);
                }


                foreach (string expertise in vehicleListBox.SelectedItems)
                {
                    trainee.VehicleTypeTraining |= (Vehicle)Tools.GetEnumAccordingToUserDisplay(typeof(Vehicle), expertise);  //tester.VehicleTypeExpertise = tester.VehicleTypeExpertise.AddFlag(expertise);
                }
                bl.AddTrainee(trainee);

                new TraineeWindow(trainee).Show();
                Close();
            }
            catch (CasingException ex) when(ex.DisplayToUser)
            {
                Functions.ShowMessageToUser(ex);
            }
            catch (Exception ex)
            {
                Functions.SendMailToAdmin(ex);
                Close();
            }
        }
예제 #3
0
        private void CheckAndAdd()
        {
            try
            {
                if (TempTrainee.Id.Length != 9)
                {
                    MessageBox.Show("תעודת זהות צריכה  להכיל  9 ספרות", "", MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult.OK, MessageBoxOptions.RtlReading);
                    idTextBox.Clear();
                    return;
                }
                if (string.IsNullOrEmpty(firstNameTextBox.Text))
                {
                    MessageBox.Show("אנא מלא שם פרטי", "", MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult.OK, MessageBoxOptions.RtlReading);
                    idTextBox.Clear();
                    return;
                }

                if (string.IsNullOrEmpty(lastNameTextBox.Text))
                {
                    MessageBox.Show("אנא מלא שם משפחה", "", MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult.OK, MessageBoxOptions.RtlReading);
                    idTextBox.Clear();
                    return;
                }

                if (string.IsNullOrEmpty(GenderComboBox.Text))
                {
                    MessageBox.Show("אנא מלא את המגדר", "", MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult.OK, MessageBoxOptions.RtlReading);
                    idTextBox.Clear();
                    return;
                }
                TimeSpan a = DateTime.Now - birthDateDatePicker.SelectedDate.Value;
                if (a.Days / 365 < 18)
                {
                    MessageBox.Show("אין אפשרות להוסיף תלמיד שטרם מלאו לו 18 שנים", "", MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult.OK, MessageBoxOptions.RtlReading);
                    birthDateDatePicker.SelectedDate = DateTime.Parse("01 01 2000");

                    return;
                }
                if (string.IsNullOrEmpty(phoneNumberTextBox.Text))
                {
                    MessageBox.Show("נא להכניס טלפון", "", MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult.OK, MessageBoxOptions.RtlReading);
                    return;
                }
                if (TempTrainee.PhoneNumber.Length < 10)
                {
                    MessageBox.Show("טלפון צריך להיות בן 10 ספרות", "", MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult.OK, MessageBoxOptions.RtlReading);
                    idTextBox.Clear();
                    return;
                }
                if (string.IsNullOrEmpty(schoolNameTextBox.Text))
                {
                    MessageBox.Show("נא להכניס שם בית הספר", "", MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult.OK, MessageBoxOptions.RtlReading);
                    return;
                }
                if (string.IsNullOrEmpty(teacherNameTextBox.Text))
                {
                    MessageBox.Show("נא להכניס שם מורה", "", MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult.OK, MessageBoxOptions.RtlReading);
                    return;
                }
                if (string.IsNullOrEmpty(numLessonsTextBox.Text))
                {
                    MessageBox.Show("נא להכניס מספר שיעורים", "", MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult.OK, MessageBoxOptions.RtlReading);
                    return;
                }
                if (string.IsNullOrEmpty(cityTextBox1.Text))
                {
                    MessageBox.Show("נא להכניס את שם העיר", "", MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult.OK, MessageBoxOptions.RtlReading);
                    return;
                }
                if (string.IsNullOrEmpty(streetTextBox1.Text))
                {
                    MessageBox.Show("נא להכניס את שם הרחוב", "", MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult.OK, MessageBoxOptions.RtlReading);
                    return;
                }
                if (string.IsNullOrEmpty(buildingNumberTextBox1.Text))
                {
                    MessageBox.Show("נא להכניס את מספר בנין", "", MessageBoxButton.OK, MessageBoxImage.None,
                                    MessageBoxResult.OK, MessageBoxOptions.RtlReading);
                    return;
                }
                try
                {
                    TempTrainee.Address = address;
                    bl.AddTrainee(TempTrainee);
                }
                catch (Exception c)
                {
                    if (c is MyExceptions b)
                    {
                        MessageBox.Show(b._message);
                        return;
                    }
                    MessageBox.Show(c.Message);
                    return;
                }

                if (Data.UserType == Data.Usertype.תלמיד)
                {
                    MessageBox.Show("התלמיד נוסף בהצלחה!", "", MessageBoxButton.OK, MessageBoxImage.Asterisk, MessageBoxResult.OK,
                                    MessageBoxOptions.RtlReading);
                    Data.UserID          = TempTrainee.Id;
                    Data.MainUserControl = new HomePanel();

                    return;
                }

                int choice = (int)MessageBox.Show("התלמיד נוסף בהצלחה , האם ברצונך להוסיף עוד תלמיד?", "", MessageBoxButton.YesNo,
                                                  MessageBoxImage.Asterisk, MessageBoxResult.None, MessageBoxOptions.RtlReading);
                if (choice == 6)
                {
                    Data.MainUserControl = new AddStudent();
                }
                else
                {
                    Data.MainUserControl = new HomePanel();
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }
예제 #4
0
        public static void AddTrainee()
        {
            string   Id, FirstName, LastName, Phone, Email, City, Street, TeacherName, driveSchool;
            int      DrivingLessons, year, month, day, NumberHouse;
            DateTime Date; DateTime temp = DateTime.Now;

            Console.WriteLine("Enter: All Information");
            Id             = Console.ReadLine();
            Id             = CheckId(Id);
            FirstName      = Console.ReadLine();
            LastName       = Console.ReadLine();
            Phone          = Console.ReadLine();
            Phone          = CheckPhone(Phone);
            Email          = Console.ReadLine();
            City           = Console.ReadLine();
            Street         = Console.ReadLine();
            NumberHouse    = int.Parse(Console.ReadLine());
            year           = int.Parse(Console.ReadLine());
            month          = int.Parse(Console.ReadLine());
            day            = int.Parse(Console.ReadLine());
            Date           = CheckDate(year, month, day);
            DrivingLessons = int.Parse(Console.ReadLine());
            TeacherName    = Console.ReadLine();
            driveSchool    = Console.ReadLine();
            int age = temp.Year - Date.Year;

            if (age < Configuration.MINTraineeAge)
            {
                throw new Exception("You're too young to be a trainee");
            }
            int  gen, typeGearbox, typeOfcar;
            bool glasses, internalTest;

            do
            {
                Console.WriteLine("Male=0 Female=1");
                gen = int.Parse(Console.ReadLine());
            } while ((gen < 0) || (gen > 1));
            do
            {
                Console.WriteLine("Private Car = 0, Two Wheeled Vehicles = 1, Medium Truck = 2, Heavy Truck = 3, CarService = 4, SecurityVehicl = 5");
                typeOfcar = int.Parse(Console.ReadLine());
            } while ((typeOfcar < 0) || (typeOfcar > 5));
            do
            {
                Console.WriteLine("Manual = 0,  Automatic = 1");
                typeGearbox = int.Parse(Console.ReadLine());
            } while ((typeGearbox < 0) || (typeGearbox > 1));
            Console.WriteLine("If has glasses 1, else 0");
            glasses = bool.Parse(Console.ReadLine());
            Console.WriteLine("Enter 1 if passed the internal test, else 0");
            internalTest = bool.Parse(Console.ReadLine());
            Trainee myTrainee = new Trainee
            {
                TraineeId           = Id,
                TraineeFirstName    = FirstName,
                TraineeLastName     = LastName,
                TraineeGender       = (Gender)gen,
                TraineePhoneNumber  = Phone,
                TraineeEmailAddress = Email,
                //TraineeAddress = new Address(Street, NumberHouse, City),
                TraineeDateOfBirth            = Date,
                TraineeLearingCar             = (TypeOfCar)typeOfcar,
                TraineeGearbox                = (TypeOfGearbox)typeGearbox,
                TraineeNameOfSchool           = driveSchool,
                TraineeNameOfTeacher          = TeacherName,
                TraineeNumOfDrivingLessons    = DrivingLessons,
                TraineeHasGlasses             = glasses,
                IfTraineePassedAnInternalTest = internalTest
                                                //TraineeImageSource*/
            };

            try
            {
                bl.AddTrainee(myTrainee);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }