private void Button_AcceptCalendarClick(object sender, RoutedEventArgs e) { ClassCalendar calendar = GetCalendarForSelectedCalendarInComboboxFromDataBase(); foreach (ClassCalendarDay day in days) { if (day.IsWorkingDay == true) { int dayId = ClassSqlCalendar.GetDayIdForCalendarDate(calendar.CalendarId, day.DateInDateTime.Day); ClassSqlCalendar.CreateTerm(day.StartTime, day.EndTime, ClassSqlCalendar.GetCalendarIdForDoctor(ClassLoggedDoctor.Doctor_Id, calendar.CalendarId), dayId, ClassSQLConnections.GetOfficeIdForDoctor(ClassLoggedDoctor.Doctor_Id), ClassLoggedDoctor.Doctor_Id, day.Date); } } ClassSqlCalendar.UpdateCalendarStatus(ClassSqlCalendar.SelectStatusId(EnumStatus.AcceptedByTheDoctor), calendar.CalendarId); NavigationService.Navigate(new WindowDoctorNewCalendarEmpty()); }
//Remove calendar private void ButtonRemoveCalendar_Click(object sender, RoutedEventArgs e) { try { ClassCalendar callendar = GetCalendarForSelectedCalendarInComboboxFromDataBase(); if (callendar.Status.StatusId != ClassSqlCalendar.SelectStatusId(EnumStatus.New)) { throw new Exception("To remove calendar status must be new"); } ClassSqlCalendar.DeleteCalendarAndApropriateCalendarDays(callendar.CalendarId); MessageBox.Show("Calendar succesfully deleted"); ComboBoxPickDate.ItemsSource = ClassSqlCalendar.AlreadyCreatedCalendars(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//Add or edit calendar day private void ButtonAdd_Click(object sender, RoutedEventArgs e) { ClassCalendar calendar; ClassCalendarDay day; try { calendar = GetCalendarForSelectedCalendarInComboboxFromDataBase(); if (calendar.Status.StatusId != ClassSqlCalendar.SelectStatusId(EnumStatus.New)) { throw new Exception("Calendar status must be new"); } day = GetCalendarDayOrGenerateIt(sender, calendar); WindowCalendarDayEdition window = new WindowCalendarDayEdition(day, calendar.Year, calendar.Month, ClassSqlCalendar.ListOfCalendarDays(calendar.CalendarId)); if (!(sender is Button)) { window.createNew = false; } bool update = (bool)window.ShowDialog(); if (!update) { throw new Exception("Operation canceled"); } if (sender is Button) { ClassSqlCalendar.CreateCalendarDay(day.Day, calendar.CalendarId, day.StartTime, day.EndTime); MessageBox.Show("Calendar day succesfully added"); ReloadData(); return; } ClassSqlCalendar.UpdateCalendarDay(day.Day, day.CalendarDayId, day.StartTime, day.EndTime); MessageBox.Show("Calendar day succesfully edited"); ReloadData(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); return; } }
//Remove calendar day private void ButtonRemove_Click(object sender, RoutedEventArgs e) { try { ClassCalendar calendar = GetCalendarForSelectedCalendarInComboboxFromDataBase(); if (calendar.Status.StatusId != ClassSqlCalendar.SelectStatusId(EnumStatus.New)) { throw new Exception("Calendar status must be new"); } ClassCalendarDay day = GetCalendarDayForSelectedCalendarDayInDataGridFromDataBase(calendar.CalendarId); if (!(MessageBox.Show("Are you sure you want to delete this day?", "Continue?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)) { return; } ClassSqlCalendar.DeleteCalendarDay(day.CalendarDayId); ReloadData(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//Share calendar private void ButtonShare_Click(object sender, RoutedEventArgs e) { try { ClassCalendar calendar = GetCalendarForSelectedCalendarInComboboxFromDataBase(); if (calendar.Status.StatusId != ClassSqlCalendar.SelectStatusId(EnumStatus.New)) { throw new Exception("Calendar status must be new"); } ClassGenerateCalendar.ShareCalendar(calendar); MessageBox.Show("Succesfully shared calendar"); ComboBoxPickDate.ItemsSource = ClassSqlCalendar.AlreadyCreatedCalendars(); if (ComboBoxPickDate.Items.Count == 0) { return; } ComboBoxPickDate.SelectedIndex = ComboBoxPickDate.Items.Count - 1; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }