/// <summary> /// When user Changes Address /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddressOfBeginningTestTextBox_TextChanged(object sender, EventArgs e) { try { //Reset all selections licenseTypeComBox.SelectionChanged -= LicenseTypeComBox_OnSelectionChanged; testerIdComboBox.SelectedIndex = -1; licenseTypeComBox.SelectedIndex = -1; TimePickerTest.ResetSelection(); testerIdComboBox.ItemsSource = null; licenseTypeComBox.SelectionChanged += LicenseTypeComBox_OnSelectionChanged; //Show Message ClearAllMessages(); AddMessage("Please Select license."); //Disable all the controls testerIdComboBox.IsEnabled = false; TimePickerTest.IsEnabled = false; testTimeDatePicker.IsEnabled = false; Save.IsEnabled = false; } catch { // ignored } }
/// <summary> /// When user Selects Date /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TestTimeDatePicker_OnCalendarOpened(object sender, RoutedEventArgs e) { try { //Reset old selections TimePickerTest.ResetSelection(); if (testTimeDatePicker.SelectedDate != null) { var date = (DateTime)testTimeDatePicker.SelectedDate; var tester = (Tester)testerIdComboBox.SelectedItem; var hours = (bool[])((Tester)testerIdComboBox.SelectedItem).Schedule .Days[(int)date.DayOfWeek].Hours.Clone(); //disable hours today that passed if (date.DayOfYear == DateTime.Now.DayOfYear && date.Year == DateTime.Now.Year) { for (var i = DateTime.Now.Hour; i > 0; i--) { hours[i] = false; } } //disable hours that the tester has a test already var hourNum = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }; foreach (var h in hourNum) { if (FactoryBl.GetObject.AllTests.Any(x => date.Year == x.TestTime.Year && date.DayOfYear == x.TestTime.DayOfYear && x.TestTime.Hour == h && x.TesterId == tester.Id)) { hours[h] = false; } } //Set The hours according to the schedule TimePickerTest.HourToShow = hours; } //Enable Time Picker TimePickerTest.IsEnabled = true; Save.IsEnabled = false; //Set new Message ClearAllMessages(); AddMessage("Please Select Test Time."); //Focus on Time Picker TimePickerTest.Focus(); } catch { // ignored } }
/// <summary> /// When user Selects License type /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LicenseTypeComBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { try { //if the selection is the same if ((LicenseType)licenseTypeComBox.SelectedItem == _test.LicenseType) { return; } //Show wait message ClearAllMessages(); AddMessage("Searching for Tester. Please wait."); //enable and disable controls licenseTypeComBox.IsEnabled = false; addressOfBeginningTestTextBox.IsEnabled = false; ProgressRing.IsActive = true; testTimeDatePicker.IsEnabled = false; TimePickerTest.IsEnabled = false; TimePickerTest.ResetSelection(); //Get the data var address = addressOfBeginningTestTextBox.Address; var license = (LicenseType)licenseTypeComBox.SelectedItem; _test.LicenseType = license; //find all available testers and choose the first new Thread(() => { try { //get the tester IEnumerable <Tester> testers = FactoryBl.GetObject .GetTestersByDistance(address, license ).Where(x => x.LicenseTypeTeaching.Any(y => y == license)).ToList(); _test.TesterId = testers.First().Id; _tester = testers.First(); void Action() { //Set new Message ClearAllMessages(); AddMessage("Please Select Test Date."); //Blackout the Time Picker according to the Schedule SetSelectableDates(testers.First().Schedule); //Enable tester comBox and disable the rest addressOfBeginningTestTextBox.IsEnabled = true; licenseTypeComBox.IsEnabled = true; testTimeDatePicker.IsEnabled = true; TimePickerTest.IsEnabled = false; Save.IsEnabled = false; ProgressRing.IsActive = false; testTimeDatePicker.Focus(); } Dispatcher.BeginInvoke((Action)Action); } catch (Exception ex) { void Act() { ProgressRing.IsActive = false; licenseTypeComBox.IsEnabled = true; ExceptionMessage.Show("Sorry We Couldn't Find A Tester.", ex.Message); } Dispatcher.BeginInvoke((Action)Act); } }).Start(); } catch { // ignored } }