public AddTraineePage() { bl = FactoryBL.GetBL(); InitializeComponent(); temp_trainee = new Trainee(); InitializeComponent(); this.GendercomboBox.ItemsSource = Enum.GetValues(typeof(BE.Gender)); this.CarcomboBox.ItemsSource = Enum.GetValues(typeof(BE.TypeOfCar)); this.GearcomboBox.ItemsSource = Enum.GetValues(typeof(BE.TypeOfGearbox)); this.comboBox.ItemsSource = (from item in bl.GetAllTeachers() select item.DrivingSchool).Distinct(); DataContext = temp_trainee; }
private void AddTraineeButtonClicked(object sender, RoutedEventArgs e) { try { if (id.Text != "" && firstName.Text != "" && lastName.Text != "" && dateOfbirth.Text != "" && genderComboBox.Text != "" && phone.Text != "" && street.Text != "" && houseNumber.Text != "" && city.Text != "" && carTypeComboBox.Text != "" && gearBoxComboBox.Text != "" && schoolName.Text != "" && teacherName.Text != "" && numOfLessons.Text != "" ) { Trainee inputTrainee = new Trainee( Int32.Parse(id.Text), lastName.Text, firstName.Text, (DateTime)dateOfbirth.SelectedDate, (Gender)genderComboBox.SelectedItem, phone.Text, new Address(street.Text, int.Parse(houseNumber.Text), city.Text), (VehicleType)carTypeComboBox.SelectedItem, (GearBox)gearBoxComboBox.SelectedItem, schoolName.Text, teacherName.Text, int.Parse(numOfLessons.Text), new List <TraineeTest>()); bl.addTrainee(inputTrainee); MessageBox.Show("Your details have successfully recorded in the system.\nUse your ID number to log in any time you wish.", "Success!", MessageBoxButton.OK, MessageBoxImage.Information); Close(); } else { MessageBox.Show("Please fill all the fields before registerring", "Missing Input Data", MessageBoxButton.OK, MessageBoxImage.Hand); return; } } catch (Exception exception) { HandleExceptions.Handle(exception, this); } }
public UpdateTraineePage() { bl = FactoryBL.GetBL(); temp_trainee = new Trainee(); InitializeComponent(); this.GendercomboBox.ItemsSource = Enum.GetValues(typeof(BE.Gender)); this.CarcomboBox.ItemsSource = Enum.GetValues(typeof(BE.TypeOfCar)); this.CarcomboBox.SelectedValue = TypeOfCar.PrivateCar; this.GearcomboBox.ItemsSource = Enum.GetValues(typeof(BE.TypeOfGearbox)); this.comboBox.ItemsSource = (from item in bl.GetAllTeachers() select item.DrivingSchool).Distinct(); this.comboBox1.ItemsSource = (from item in bl.GetAllTeachers() select item.TeacherName); grid1.IsEnabled = false; }
private void Add_Click(object sender, RoutedEventArgs e) { try { bl.AddTrainee(trainee); trainee = new Trainee(); grid1.DataContext = trainee; MessageBox.Show("added"); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Trainee window /// </summary> /// <param name="id"></param> public TraineeWin(int id) { InitializeComponent(); try { //try to add trainee _trainee = _blimp.AllTrainees.First(x => x.Id == id); TextBoxHi.Content = "Welcome " + _trainee.FirstName + " " + _trainee.LastName; Refresh(); } catch { Close(); } }
/// <summary> /// This function will insert the appropriate values into the corresponding fields when we press on the button "submit" /// This is a sighnup function for a click event /// </summary> /// <param name="sender">Who is sensing the event</param> /// <param name="e">Details of the event occurred</param> private void SubmitBtn_Click(object sender, RoutedEventArgs e) { MessageBox.Show(currentTrainee.ToString()); try { BL.UpdateTrainee(currentTrainee); currentTrainee = new Trainee(); //creates a new trainee for current trainee so that the update can work again well DataContext = currentTrainee; //sets the current trainee in DataContext so that the update can work again well traineeIdTextBox.IsEnabled = true; } catch (Exception exc) { MessageBox.Show(exc.Message); } }
private void trainee_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (trainee.SelectedIndex != -1) { Trainee t = (trainee.SelectedValue as Trainee); if (t != null) { addLesson.Content = t.LessonsNumber; if (trainee.SelectedIndex != -1) { addLesson.Visibility = Visibility.Visible; } } } }
private void OKbutton_Click(object sender, RoutedEventArgs e) { try { if (IdtextBox.Text.Length < 9) { IdtextBox.BorderBrush = Brushes.Red; throw new Exception("id - Not enough digits"); } if (PhoneNumbertextBox.Text.Length < 10) { PhoneNumbertextBox.BorderBrush = Brushes.Red; throw new Exception("Phone Number - Not enough digits"); } if (EmailtextBox.Text.Length == 0) { EmailtextBox.BorderBrush = Brushes.Red; throw new Exception("Not enough digits"); } if (EmailtextBox.Text.IndexOf('@') != EmailtextBox.Text.LastIndexOf('@') || EmailtextBox.Text.IndexOf('@') == -1) { EmailtextBox.BorderBrush = Brushes.Red; throw new Exception("The email is not currect - does not contain the value @"); } if (EmailtextBox.Text.IndexOf(".") == -1) { EmailtextBox.BorderBrush = Brushes.Red; throw new Exception("The email is not currect"); } temp_trainee.TraineeNumOfDrivingLessons = (int)numOfLesson.Value; bl.UpdateTrainee(temp_trainee); temp_trainee = new BE.Trainee(); grid1.DataContext = temp_trainee; grid1.IsEnabled = false; IdtextBox.IsEnabled = true; IdtextBox.Text = ""; CarcomboBox.IsEnabled = true; OKbutton.IsEnabled = false; throw new Exception("Your details have been updated on the system"); } catch (Exception message) { MessageBox.Show(message.Message); IdtextBox.BorderBrush = Brushes.Black; PhoneNumbertextBox.BorderBrush = Brushes.Black; EmailtextBox.BorderBrush = Brushes.Black; } }
/// <summary> /// This function will insert the appropriate values into the corresponding fields when we press on the button "submit" /// This is a sighnup function for a click event /// </summary> /// <param name="sender">Who is sensing the event</param> /// <param name="e">Details of the event occurred</param> private void SubmitBtn_Click(object sender, RoutedEventArgs e) { MessageBox.Show(" " + currentTrainee); try { BL.DeleteTrainee(currentTrainee); Console.WriteLine("the trainee that was deleted is" + currentTrainee); currentTrainee = new Trainee(); //creates a new trainee for current trainee so the delete can work again well DataContext = currentTrainee; //sets the current trainee in DataContext traineeIdTextBox.IsEnabled = true; //the delete can work again well } catch (Exception exc) { MessageBox.Show(exc.Message); } }
}//tester signin window private void traineeClick(object sender, RoutedEventArgs e) { int tid; if (int.TryParse(comboBoxTraineeId.SelectedItem.ToString(), out tid))//check the user entered a number { Trainee trainee = bl.getAllTrainees().Where(item => item.id == tid).FirstOrDefault(); traineeWindow traineew = new traineeWindow(trainee); traineew.Show(); this.Close(); } else { MessageBox.Show("must enter number in tester id!", "ERROR!"); } }//trainee signin window
private void add_test_button_Click(object sender, RoutedEventArgs e) { Test atest = new Test(); trainee = (Trainee)this.DataContext; atest.Trainee_ID = trainee.ID; atest.Date = DateTime.Today; atest.Date = atest.Date.AddHours(9); addTest window = new addTest(); window.DataContext = atest; window.Show(); }
public UpdateTrainee() { bl = FactoryBL.GetBL(); temp_trainee = new Trainee(); InitializeComponent(); this.GendercomboBox.ItemsSource = Enum.GetValues(typeof(BE.Gender)); this.CarcomboBox.ItemsSource = Enum.GetValues(typeof(BE.TypeOfCar)); this.CarcomboBox.SelectedValue = TypeOfCar.PrivateCar; this.GearcomboBox.ItemsSource = Enum.GetValues(typeof(BE.TypeOfGearbox)); this.comboBox.ItemsSource = bl.GetAllTeachers(); this.comboBox1.ItemsSource = bl.GetAllTeachers(); this.comboBox1.DisplayMemberPath = "TeacherName"; this.comboBox.DisplayMemberPath = "DrivingSchool"; this.comboBox.SelectedValuePath = "TeacherName"; this.comboBox.SelectedValuePath = "DrivingSchool"; grid1.IsEnabled = false; }
public AddTrainee() { bl = FactoryBL.GetBL(); InitializeComponent(); temp_trainee = new Trainee(); InitializeComponent(); this.GendercomboBox.ItemsSource = Enum.GetValues(typeof(BE.Gender)); this.CarcomboBox.ItemsSource = Enum.GetValues(typeof(BE.TypeOfCar)); this.GearcomboBox.ItemsSource = Enum.GetValues(typeof(BE.TypeOfGearbox)); this.comboBox.ItemsSource = bl.GetAllTeachers(); this.comboBox1.ItemsSource = bl.GetAllTeachers(); this.comboBox1.DisplayMemberPath = "TeacherName"; this.comboBox.DisplayMemberPath = "DrivingSchool"; this.comboBox.SelectedValuePath = "TeacherName"; this.comboBox.SelectedValuePath = "DrivingSchool"; DataContext = temp_trainee; }
private void CarcomboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { comboBoxGear.Items.Clear(); string ezer = (CarcomboBox.SelectedItem as ComboBoxItem).Content.ToString(); TypeOfCar car = TypeOfCar.PrivateCar; if (ezer == "PrivateCar") { car = TypeOfCar.PrivateCar; } if (ezer == "TwoWheeledVehicles") { car = TypeOfCar.TwoWheeledVehicles; } if (ezer == "MediumTruck") { car = TypeOfCar.MediumTruck; } if (ezer == "HeavyTruck") { car = TypeOfCar.HeavyTruck; } if (ezer == "CarService") { car = TypeOfCar.CarService; } if (ezer == "SecurityVehicle") { car = TypeOfCar.SecurityVehicle; } IEnumerable <Trainee> myTests = bl.GetAllTrainee(t => t.TraineeLearingCar == car && t.TraineeId == TraineeId.Text); if (myTests.Count() != 0) { Trainee temp = myTests.First(); comboBoxGear.IsEnabled = true; ComboBoxItem newItem = new ComboBoxItem(); newItem.Content = temp.TraineeGearbox; comboBoxGear.Items.Add(newItem); } else { MessageBox.Show("Error"); } }
private void search() { try { if (IdtextBox.Text.Length < 9) { IdtextBox.BorderBrush = Brushes.Red; label1.Content = ""; button.IsEnabled = false; throw new Exception("Id - Not enough digits"); } if (IdtextBox.Text.Length > 9) { IdtextBox.BorderBrush = Brushes.Red; throw new Exception("Id - To much digits"); } object temp = comboBox.SelectedItem; if (temp == null) { label1.Content = ""; button.IsEnabled = false; throw new Exception("The trainee does not lerning on this type of car"); } temp_trainee = bl.SearchTrainee(IdtextBox.Text, (TypeOfCar)comboBox.SelectionBoxItem); if (temp_trainee == null) { label1.Content = ""; button.IsEnabled = false; throw new Exception("The trainee does not exist in the database"); } button.IsEnabled = true; label1.Content = temp_trainee.ToString(); } catch (Exception message) { MessageBox.Show(message.Message); IdtextBox.Text = ""; IdtextBox.BorderBrush = Brushes.Black; comboBox.SelectedValue = TypeOfCar.PrivateCar; } }
private void Button_Click_2(object sender, RoutedEventArgs e) { int tid; if (int.TryParse(traineeid.Text, out tid)) { Trainee trainee = bl.getAllTrainees().Where(item => item.id == tid).First(); if (trainee != null) { traineeWindow traineew = new traineeWindow(trainee); traineew.Show(); this.Close(); } } else { MessageBox.Show("must enter number in tester id!", "ERROR!"); } }
public trainee(string content, int id = 0) { InitializeComponent(); btnOk.Content = content; Title = (content + " " + "trainee");//the title of the window MyTrainee = new Trainee(); bl = FactoryBL.GetBL(); if (id != 0)//when we update, delete or view trainee we get the id and search it. { MyTrainee = (Trainee)bl.findById(id); } this.DataContext = MyTrainee; //fill the data in the window this.DataContext = MyTrainee; //fill the data in the window this.cmbGearbox.ItemsSource = Enum.GetValues(typeof(BE.Gearbox)); //fill cmb by enums?? this.cmbTraineeGender.ItemsSource = Enum.GetValues(typeof(BE.Gender)); this.cmbKindV.ItemsSource = Enum.GetValues(typeof(BE.TypeCar)); this.cmbSchool.ItemsSource = Enum.GetValues(typeof(BE.School)); if (content == "Remove" || content == "View")//cant change datacontext only view { txtid.IsEnabled = false; txtlastName.IsEnabled = false; txtfirstName.IsEnabled = false; datePickerTraineeBirth.IsEnabled = false; txtStreet.IsEnabled = false; txtBuilding.IsEnabled = false; txtCity.IsEnabled = false; cmbKindV.IsEnabled = false; cmbTraineeGender.IsEnabled = false; cmbGearbox.IsEnabled = false; txtphone.IsEnabled = false; txtLessons.IsEnabled = false; txtNumOfTest.IsEnabled = false; txtTeacher.IsEnabled = false; cmbSchool.IsEnabled = false; DateOfTheLastTest.IsEnabled = false; } if (content == "Update")//cant update id of trainee { txtid.IsEnabled = false; } }
public ResultPage(Test temp) { bl = FactoryBL.GetBL(); InitializeComponent(); Trainee t = bl.SearchTrainee(temp.TraineeId, temp.TestTypeOfCar); label3.Content = t.TraineeId; label4.Content = t.TraineeFirstName + " " + t.TraineeLastName; textBox.Text = temp.TesterNote; if (temp.TestResult == PassOrFail.Fail) { Resultlabel5.Foreground = Brushes.Red; Resultlabel5.Content = "FAILED"; } if (temp.TestResult == PassOrFail.Pass) { Resultlabel5.Foreground = Brushes.Green; Resultlabel5.Content = "PASSED"; } }
private void DeleteTestClicked(object sender, RoutedEventArgs e) { try { MessageBoxResult result = MessageBox.Show("Are you sure you want abort this test?", "Delete Test", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { Button button = sender as Button; int testNumber = (int)button.Tag; bl.removeTest(testNumber); MessageBox.Show("The test is aborted.\nYou can appoint a new test by the \"Order Test\" button.", "Test Deleted", MessageBoxButton.OK, MessageBoxImage.Information); Trainee = bl.getTrainee(Trainee.ID); DataContext = Trainee; } } catch (Exception exception) { HandleExceptions.Handle(exception, this); } }
public TraineeMainWindow(User user) { InitializeComponent(); if (user.role == User.RoleTypes.Admin) { trainee = user.ConnectTo as Trainee; title.user = user; if (trainee == null) { throw new Exception("worng user sended to trainee"); } } else if (user.role != User.RoleTypes.Trainee || !(user.ConnectTo is Trainee)) { throw new Exception("worng user sended to trainee"); } else { trainee = new Trainee(user.ConnectTo as Trainee); } details.DataContext = trainee; updateTrainee_uc.Trainee = trainee; updateTrainee_uc.idTextBox.IsEnabled = false; updateTrainee_uc.button.Click += updateTrainee_click; //set view tests only for this tester var list = new List <Trainee>(); list.Add(trainee); viewTests_uc.setTraineeExist = list; viewTests_uc.trainee.SelectedValue = trainee; viewTests_uc.trainee.IsEnabled = false; //set trainee for add lesson AddLessonToTrainee_uc.setTrainee(trainee); setTestModeAndThUsercontrol(); title.user = user; }
private void Button_Click(object sender, RoutedEventArgs e) { try { Trainee trainee = new Trainee(traineeIdList.SelectionBoxItem as Trainee); Tester tester = new Tester(testerIdList.SelectionBoxItem as Tester); MessageBoxResult answer = MessageBox.Show("Verify test scheduling", "are you sure you want to add a test for " + trainee.Id + " with " + tester.Id + "?", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (MessageBoxResult.Yes == answer) { bl.AddFutureTest(tester, trainee, DateTime.Parse(dateOfTestDatePicker.Text), new Address(city.Text, int.Parse(building_number.Text), street.Text)); MessageBox.Show("added test"); } else { MessageBox.Show("canceled"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// event of create new trainee that happen when the button is click /// </summary> private void Button_Click(object sender, RoutedEventArgs e) { try { bool oneOrMoreEmpty = false; string whoEmpty = ""; foreach (Control txtbxs in this.input.Children) { if (txtbxs is TextBox) { var TBox = (TextBox)txtbxs; if (TBox.Text == string.Empty) { TBox.Background = new SolidColorBrush(Colors.Red); oneOrMoreEmpty = true; whoEmpty += TBox.Name + " "; } } } if (oneOrMoreEmpty) { MainWindow.ErrorMessage(string.Format("you have a cells {0} is empty, fill all and try again", whoEmpty)); return; } trainee.Address = new Address(street_name.Text, int.Parse(building_number.Text), city.Text); bl.AddTrainee(trainee); traineeAdded?.Invoke(sender, new EventArgs()); trainee = new Trainee(); DataContext = trainee; city.Text = ""; building_number.Text = ""; street_name.Text = ""; errorMessage.Text = "Successfully added!"; errorMessage.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF3CBA54")); } catch (Exception ex) { errorMessage.Text = ex.Message; errorMessage.Foreground = Brushes.Red; } }
}//tester signin window private void traineeClick(object sender, RoutedEventArgs e) { int tid; if (int.TryParse(traineeid.Text, out tid))//check the user entered a number { Trainee trainee = bl.getAllTrainees().Where(item => item.id == tid).FirstOrDefault(); if (trainee != null) { traineeWindow traineew = new traineeWindow(trainee); traineew.Show(); this.Close(); }//check that the trainee exists else { MessageBox.Show("trainee does not exist!"); } } else { MessageBox.Show("must enter number in tester id!", "ERROR!"); } }//trainee signin window
private void removeTrainee_Click(object sender, RoutedEventArgs e) { int id; if (int.TryParse(comboBox.SelectedItem.ToString(), out id)) { Trainee trainee = new Trainee(); trainee = bl.getAllTrainees().Where(x => x.id == id).FirstOrDefault(); try { bl.removeTrainee(trainee); } catch (Exception e1) { MessageBox.Show(e1.Message); } } else { MessageBox.Show("must choose a trainee"); } this.Close(); }
private void IncreaseLessonsCounterClicked(object sender, RoutedEventArgs e) { try { MessageBoxResult result = MessageBox.Show( "You added one more driving lesson to the counter.\nThe updated sum of lessons is: " + (Trainee.NumberOfLessons + 1).ToString(), "Adding a Lesson", MessageBoxButton.OKCancel, MessageBoxImage.Information); if (result == MessageBoxResult.OK) { Trainee.NumberOfLessons++; bl.updateTrainee(Trainee.ID, Trainee); Trainee = bl.getTrainee(Trainee.ID); DataContext = Trainee; } } catch (Exception exception) { HandleExceptions.Handle(exception, this); } }
private void OkButton_Click(object sender, RoutedEventArgs e) { try { BE.Tester tester = My_bl.GetAllTesters().Find(x => x.Id == TesterIDTextBox.Text); if (tester == null) { throw new Exception("Tester " + TesterIDTextBox.Text + "not found!!"); } if (tester.Password == YourPasswordBox.Password) { List <Test> myTests = My_bl.GetAllTests().FindAll(x => x.TesterId == TesterIDTextBox.Text && x.TestDate <= DateTime.Now && x.ISUpdated == false); if (myTests.Any() == false) { throw new Exception("You don't have any tests to update"); } ListIndex = 0; StudentIDTB.Text = myTests[0].TraineeId; Trainee trainee = My_bl.GetAllTrainees().Find(x => x.Id == StudentIDTB.Text); studentDetails.Content = trainee.Name + " " + trainee.FamilyName; TestDateDP.SelectedDate = myTests[ListIndex].TestDate; HourDispalyLabel.Content = "Hour:" + myTests[ListIndex].TestDate.Hour + ":00"; TestsNumberTB.Text = myTests[ListIndex].TestNumber; ActiveFildes(); } else { throw new Exception("Worng password!!"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR"); } }
private void DeleteTrainee_Click(object sender, RoutedEventArgs e) { try { if (traineesListView.SelectedItem == null) { MessageBox.Show("Please select a trainee to delete from the list"); return; } Trainee trainee = traineesListView.SelectedItem as Trainee; MessageBoxResult result = MessageBox.Show("Are you sure you want dealete this trainee?", "Delete Ttainee", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { bl.removeTrainee(trainee.ID); MessageBox.Show("The trainee is deleted.\n", "Trainee Deleted", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { HandleExceptions.Handle(ex, this); } }
private void Trainee_Click(object sender, RoutedEventArgs e) //הגדרת פתיחת חלון התלמיד בלחיצה על הכפתור { Window traineeWindow = new Trainee(); traineeWindow.Show(); }
private void inputlist(IBL bl) { Tester tester1 = new Tester(); tester1.ID = 311525836; tester1.Phone = "050"; tester1.Seniority = 15; tester1.MaxTest = 9999; tester1.FName = "yotam"; tester1.LName = "bocker"; tester1.CarType = CarType.PrivateCar; tester1.Gender = Gender.Male; tester1.MyAddress = new Address("city", "street", 1); tester1.MaxD = 1; tester1.BDate = new DateTime(1934, 08, 17); bl.AddTester(tester1); Trainee trainee1 = new Trainee(); trainee1.ID = 123456782; trainee1.Phone = "050"; trainee1.LessonNum = 40; trainee1.School = "dasds"; trainee1.FName = "sadasd"; trainee1.LName = "asdsads"; trainee1.CarType = CarType.PrivateCar; trainee1.Gender = Gender.Male; trainee1.MyAddress = new Address("ss", "ddss", 44); trainee1.Gear = Gearbox.Automatic; trainee1.BDate = new DateTime(1995, 06, 17); trainee1.HaveGlasses = true; // trainee1.LastTest = new DateTime(1934, 08, 17); bl.AddTrainee(trainee1); Test test1 = new Test(); test1.IdTrainee = 123456782; test1.IdTester = 311525836; test1.DateTest = new DateTime(2018, 12, 26); test1.AddressTest = new Address("jerusalem", "golomb", 38); test1.DayAndHour.Set(DayOfWeek.Sunday, 11); bl.AddTest(test1); Tester tester2 = new Tester(); tester2.ID = 314699554; tester2.Phone = "050"; tester2.Seniority = 25; tester2.MaxTest = 24; tester2.FName = "bsasas"; tester2.LName = "basasb"; tester2.CarType = CarType.PrivateCar; tester2.Gender = Gender.Male; tester2.MyAddress = new Address("ciasaty", "stasreet", 2); tester2.MaxD = 2; tester2.BDate = new DateTime(1934, 08, 27); bl.AddTester(tester2); Trainee trainee2 = new Trainee(); trainee2.ID = 322675562; trainee2.Phone = "050"; trainee2.LessonNum = 40; trainee2.School = "sasab"; trainee2.FName = "bdsds"; trainee2.LName = "bsdsb"; trainee2.CarType = CarType.PrivateCar; trainee2.Gender = Gender.Male; trainee2.MyAddress = new Address("city", "street", 22); trainee2.Gear = Gearbox.Automatic; trainee2.BDate = new DateTime(1995, 06, 27); // trainee2.LastTest = new DateTime(1934, 08, 27); bl.AddTrainee(trainee2); Test test2 = new Test(); test2.IdTrainee = 322675562; test2.IdTester = 314699554; test2.DateTest = new DateTime(2018, 11, 26); test2.AddressTest = new Address("jerusalem", "golomb", 38); test2.DayAndHour.Set(DayOfWeek.Monday, 14); bl.AddTest(test2); /* Trainee trainee3 = new Trainee(); * trainee3.ID = 11; * trainee3.Phone = "050"; * trainee3.LessonNum = 40; * trainee3.School = "c"; * trainee3.FName = "c"; * trainee3.LName = "cc"; * trainee3.CarType = CarType.PrivateCar; * trainee3.Gender = Gender.Male; * trainee3.MyAddress = new Address("city", "street", 2); * trainee3.Gear = Gearbox.Automatic; * trainee3.BDate = new DateTime(1995, 06, 27); * // trainee2.LastTest = new DateTime(1934, 08, 27); * bl.AddTrainee(trainee3); * */ }
private void button_Click(object sender, RoutedEventArgs e) { TraineeMenu mytraineeMenu = new TraineeMenu(); try { if ((string)btnOk.Content == "Add") { int numId = Convert.ToInt32(txtid.Text); if (numId < 100000000 || numId > 999999999) { //check if id is legal throw new Exception("Non-valid Id. Please enter a valid Id."); } if ((txtfirstName.Text == "") || (txtCity.Text == "") || (txtBuilding.Text == "") || (txtLessons.Text == "") || (txtNumOfTest.Text == "") || (txtTeacher.Text == "") || (txtlastName.Text == "") || (txtStreet.Text == "") || (txtphone.Text == "") || (cmbSchool.Text == "") || (cmbGearbox.Text == "") || (cmbKindV.Text == "") || (cmbTraineeGender.Text == "")) //chech the texts box are not empty { throw new Exception("Not all fields are filled in."); } DateTime temp = (MyTrainee.TraineeBirth.AddYears(Configuration.MinAgeForTrainee)); if (temp > DateTime.Today) { throw new Exception("too young to be a trainee"); } if (datePickerTraineeBirth.SelectedDate > DateTime.Today) { throw new Exception("Please, enter a passed date"); } if (DateOfTheLastTest.SelectedDate > DateTime.Today) { throw new Exception("Please, enter a passed date"); } bl.addTrainee(MyTrainee); //ask him if he sure he wants to add? MyTrainee = new Trainee(); //clean the datacontext this.DataContext = MyTrainee; this.Close(); mytraineeMenu.Show(); } else if ((string)btnOk.Content == "Remove") { var mbResult = MessageBox.Show("Are you sure you want to remove this trainee?", "", MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Yes); if (mbResult == MessageBoxResult.OK) { bl.deleteTrainee(MyTrainee); MyTrainee = new Trainee();//clean the datacontext this.DataContext = MyTrainee; this.Close(); MessageBox.Show("Trainee removed"); mytraineeMenu.Show(); } } else if ((string)btnOk.Content == "Update") { var mbResult = MessageBox.Show("Are you sure you want to update this trainee?", "", MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Yes); if (mbResult == MessageBoxResult.OK) { bl.updateTrainee(MyTrainee); MyTrainee = new Trainee(); this.DataContext = MyTrainee; this.Close(); MessageBox.Show("Trainee updated"); mytraineeMenu.Show(); } else { this.Close(); mytraineeMenu.Show(); } } else { MyTrainee = new Trainee(); this.DataContext = MyTrainee; this.Close(); mytraineeMenu.Show(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }