Exemple #1
0
        private List <ClassCalendarDay> ListOfOriginalDays()
        {
            ClassCalendar           calendar    = GetCalendarForCurrentDate();
            List <ClassCalendarDay> orignalDays = ClassSqlCalendar.ListOfCalendarDays(calendar.CalendarId);

            return(orignalDays);
        }
Exemple #2
0
        private void workingDayFrom_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (workingDayFrom.SelectedItem != null)
            {
                lastSelectedTerm.StartTime = (TimeSpan)workingDayFrom.SelectedItem;
                ListOfTerms.RemoveAt(CurrentMonthDataGrid.SelectedIndex);
                ListOfTerms.Insert(CurrentMonthDataGrid.SelectedIndex, lastSelectedTerm);

                RefreshDataGrid();

                if (workingDayFrom.SelectedIndex == workingDayFrom.Items.Count - 1)
                {
                    workingDayTo.ItemsSource = ClassHelpers.GenerateListOfHours((TimeSpan)workingDayFrom.Items[workingDayFrom.SelectedIndex], ListOfOriginalDays()[lastSelectedIndex].EndTime);
                }
                else
                {
                    workingDayTo.ItemsSource = ClassHelpers.GenerateListOfHours((TimeSpan)workingDayFrom.Items[workingDayFrom.SelectedIndex + 1], ListOfOriginalDays()[lastSelectedIndex].EndTime);
                }

                if ((TimeSpan)workingDayFrom.SelectedItem > lastSelectedTerm.EndTime)
                {
                    workingDayTo.ItemsSource   = ClassHelpers.GenerateListOfHours((TimeSpan)workingDayFrom.Items[workingDayFrom.SelectedIndex + 1], ListOfOriginalDays()[lastSelectedIndex].EndTime);
                    workingDayTo.SelectedIndex = 0;
                }

                ClassSqlCalendar.UpdateTerm(lastSelectedTerm.TermId, lastSelectedTerm.StartTime, lastSelectedTerm.EndTime);
            }
        }
        //Generate calendar
        private void ButtonGenerate_Click(object sender, RoutedEventArgs e)
        {
            int year  = DateTime.Now.Year;
            int month = DateTime.Now.Month;

            try
            {
                IEnumerable <ClassCalendar> query =
                    from elem in ClassSqlCalendar.AlreadyCreatedCalendars()
                    where elem.Year == year && elem.Month == month
                    select elem;
                if (query.Any())
                {
                    throw new Exception("Calendar already created");
                }

                ClassGenerateCalendar.GenerateCalendar(DateTime.Now.Year, DateTime.Now.Month + 1);
                MessageBox.Show("Succesfully generated 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");
            }
        }
        private void OverlappingCalendar()
        {
            ClassCalendar calendar = GetCalendarForSelectedCalendarInComboboxFromDataBase();
            List <ClassOverlappingCalendar> list = ClassSqlCalendar.OverlappingTerms(calendar.CalendarId);

            if (list.Count != 0)
            {
                //Need changes in offices
                WindowOverlapping windowOverlapping = new WindowOverlapping(list, calendar.CalendarId);
                bool update = (bool)windowOverlapping.ShowDialog();
                if (!update)
                {
                    return;
                }
                foreach (var item in list)
                {
                    if (item.NewOfficeNumber == 0)
                    {
                        continue;
                    }
                    ClassSqlCalendar.UpdateOffice(item.TermId, item.NewOfficeId);
                }
                return;
            }
            //Calendar verified
            ClassSqlCalendar.UpdateCalendarStatus(4, calendar.CalendarId);
            MessageBox.Show("Succesfully veryfied", "Succes");
            ComboBoxPickDate.ItemsSource = ClassSqlCalendar.AlreadyCreatedCalendars();
            if (ComboBoxPickDate.Items.Count == 0)
            {
                return;
            }
            ComboBoxPickDate.SelectedIndex = ComboBoxPickDate.Items.Count - 1;
            return;
        }
        public WindowDoctorNewCalendar()
        {
            InitializeComponent();

            #region Load calendars to ComboBox
            try
            {
                ComboBoxPickCalendar.ItemsSource = ClassSqlCalendar.AlreadyCreatedCalendarsForDoctor();
                if (ComboBoxPickCalendar.Items.Count == 0)
                {
                    this.Loaded += (a, b) => NavigationService.Navigate(new WindowDoctorNewCalendarEmpty());
                }
                ComboBoxPickCalendar.SelectedIndex = ComboBoxPickCalendar.Items.Count - 1;
                LoadDateToGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            #endregion

            if (CurrentMonthDataGrid.SelectedIndex == -1)
            {
                workingDay.IsEnabled = false;
            }

            PreviousMonthDataGrid.ItemsSource = ClassSqlCalendar.GetListOfWorkingDayInCurrentMonth(ClassLoggedDoctor.Doctor_Id);
        }
        private void LoadStatusToLabel(ClassCalendar calendar)
        {
            IEnumerable <ClassStatus> query =
                from elem in ClassSqlCalendar.StatusList()
                where elem.StatusId == calendar.Status.StatusId
                select elem;

            if (!query.Any())
            {
                throw new Exception("Unable to find apropriate status in database");
            }
            Status_Label.Text = query.First().Status;

            //Check if update status to Waitng to Veryfy
            if (Status_Label.Text == ClassStatus.StatusString(EnumStatus.SharedForDoctors))
            {
                ClassSqlCalendar.UpdateCalendar(calendar.CalendarId);
                List <ClassCalendar> list = ClassSqlCalendar.AlreadyCreatedCalendars();
                if (calendar.Status.StatusId != GetCalendarForSelectedCalendarInComboboxFromDataBase().Status.StatusId)
                {
                    ComboBoxPickDate.ItemsSource = ClassSqlCalendar.AlreadyCreatedCalendars();
                    if (ComboBoxPickDate.Items.Count == 0)
                    {
                        return;
                    }
                    ComboBoxPickDate.SelectedIndex = ComboBoxPickDate.Items.Count - 1;
                }
            }
        }
        private List <ClassCalendarDay> ListOfOriginalDays()
        {
            ClassCalendar           calendar    = GetCalendarForSelectedCalendarInComboboxFromDataBase();
            List <ClassCalendarDay> orignalDays = ClassSqlCalendar.ListOfCalendarDays(calendar.CalendarId);

            return(orignalDays);
        }
Exemple #8
0
        public bool ConditionDeleteOffice()
        {
            IEnumerable <ClassTerm> query =
                from elem in ClassSqlCalendar.ListOfTerms()
                where elem.Office.OfficeId == ((ClassOffice)DataGridListOfOffice.SelectedItem).OfficeId
                select elem;

            if (query.Any())
            {
                string data = "This office cannot be removed because at this days meetings are being hosted in said of it: \n";
                foreach (ClassTerm queryResult in query)
                {
                    data += queryResult.Date.ToShortDateString() + "\n";
                }
                MessageBox.Show(data);
                return(false);
            }

            IEnumerable <ClassDoctor> query2 =
                from elem in ClassSQLConnections.DoctorList()
                where elem.OfficeNumber == ((ClassOffice)DataGridListOfOffice.SelectedItem).OfficeId
                select elem;

            if (query2.Any())
            {
                MessageBox.Show("This Office is currently occupied by " + query2.First().Name + " " + query2.First().Surname);
                return(false);
            }
            return(true);
        }
Exemple #9
0
        public WindowDoctorNewCalendar()
        {
            InitializeComponent();

            #region Load calendars to ComboBox
            try
            {
                ComboBoxPickCalendar.ItemsSource = ClassSqlCalendar.AlreadyCreatedCalendarsForDoctor();
                if (ComboBoxPickCalendar.Items.Count == 0)
                {
                    return;
                }
                ComboBoxPickCalendar.SelectedIndex = ComboBoxPickCalendar.Items.Count - 1;
                LoadDateToGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            #endregion

            if (CurrentMonthDataGrid.SelectedIndex == -1)
            {
                workingDay.IsEnabled = false;
            }
        }
Exemple #10
0
        public WindowDoctorEditCalendar()
        {
            InitializeComponent();

            List <ClassTerm> ListOfTerms = ClassSqlCalendar.GetListOfWorkingDayInCurrentMonth(ClassLoggedDoctor.Doctor_Id);

            CurrentMonthDataGrid.ItemsSource   = ListOfTerms;
            CurrentMonthDataGrid.SelectedIndex = 0;
        }
Exemple #11
0
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            WindowDoctorEditCalendarAdd windowDoctorEditCalendarAdd = new WindowDoctorEditCalendarAdd();
            var dialogResult = windowDoctorEditCalendarAdd.ShowDialog();

            if (windowDoctorEditCalendarAdd.DialogResult == true)
            {
                ListOfTerms = ClassSqlCalendar.GetListOfWorkingDayInCurrentMonth(ClassLoggedDoctor.Doctor_Id);
                RefreshDataGrid();
            }
        }
Exemple #12
0
        private void workingDayTo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (workingDayTo.SelectedItem != null)
            {
                lastSelectedTerm.EndTime = (TimeSpan)workingDayTo.SelectedItem;

                ListOfTerms.RemoveAt(CurrentMonthDataGrid.SelectedIndex);
                ListOfTerms.Insert(CurrentMonthDataGrid.SelectedIndex, lastSelectedTerm);

                RefreshDataGrid();
            }
            ClassSqlCalendar.UpdateTerm(lastSelectedTerm.TermId, lastSelectedTerm.StartTime, lastSelectedTerm.EndTime);
        }
Exemple #13
0
 private void acceptChanges_Click(object sender, RoutedEventArgs e)
 {
     foreach (ClassTerm term in ListOfTerms)
     {
         if (term.IsWorkingDay == false)
         {
             ClassSqlCalendar.DeleteTerm(term.TermId);
         }
     }
     RefreshList();
     RefreshDataGrid();
     CurrentMonthDataGrid.SelectedIndex = 0;
 }
 private void DataGridListOfCalendarDoctor_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     try
     {
         ClassCalendar       calendar          = GetCalendarForSelectedCalendarInComboboxFromDataBase();
         ClassCalendarDoctor calendarDoctor    = GetCalendarDoctorForSelectedCalendarDoctorInDataGridFromDataBase(calendar.CalendarId);
         WindowDoctorTerms   windowDoctorTerms = new WindowDoctorTerms(ClassSqlCalendar.TermLisTSelectedDoctor(calendar.CalendarId, calendarDoctor.Doctor.Doctor_id), calendar.Year, calendar.Month);
         windowDoctorTerms.ShowDialog();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error");
     }
 }
        private ClassCalendar GetCalendarForCurrentDate()
        {
            //Get calendar from data base
            IEnumerable <ClassCalendar> query =
                from elem in ClassSqlCalendar.AlreadyCreatedCalendars()
                where elem.Month == DateTime.Now.Month
                select elem;

            if (!query.Any())
            {
                throw new Exception("Unable to find selected calendar in database");
            }
            return(query.First());
        }
Exemple #16
0
        private void availableDates_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (availableDates.SelectedItem != null)
            {
                ClassTerm term = (ClassTerm)CurrentMonthDataGrid.SelectedItem;
                RefreshLastSelectedItems(term);

                ClassSqlCalendar.UpdateTerm(((ClassCalendarDay)availableDates.SelectedItem).CalendarDayId, ((ClassCalendarDay)availableDates.SelectedItem).Date, lastSelectedTerm.TermId);

                CurrentMonthDataGrid.ItemsSource   = ClassSqlCalendar.GetListOfWorkingDayInCurrentMonth(ClassLoggedDoctor.Doctor_Id);
                CurrentMonthDataGrid.SelectedIndex = lastSelectedIndex;

                checkBoxChangeDay.IsChecked = false;
            }
        }
        private void ButtonAdd_Click(object sender, RoutedEventArgs e)
        {
            if (workingDayFrom.SelectedItem == null || workingDayTo.SelectedItem == null || AvailableDate.SelectedItem == null)
            {
                MessageBox.Show("You cannot leave any empty combobox!");
                return;
            }

            ClassCalendar calendar = GetCalendarForCurrentDate();
            int           dayId    = ClassSqlCalendar.GetDayIdForCalendarDate(calendar.CalendarId, ((ClassCalendarDay)AvailableDate.SelectedItem).DateInDateTime.Day);

            ClassSqlCalendar.CreateTerm((TimeSpan)workingDayFrom.SelectedItem, (TimeSpan)workingDayTo.SelectedItem, ClassSqlCalendar.GetCalendarIdForDoctor(ClassLoggedDoctor.Doctor_Id, calendar.CalendarId), dayId, ClassSQLConnections.GetOfficeIdForDoctor(ClassLoggedDoctor.Doctor_Id), ClassLoggedDoctor.Doctor_Id, ((ClassCalendarDay)AvailableDate.SelectedItem).Date);
            this.DialogResult = true;
            this.Close();
        }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         ComboBoxOffice.ItemsSource = ClassSqlCalendar.ListOfAvailableOfficeForSelectedDay(calendar.CalendarDayId);
         if (ComboBoxOffice.Items.Count == 0)
         {
             throw new Exception("No available office for selected day \nContact with doctor needed");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error");
         this.Close();
     }
 }
 //Verify calendar
 private void ButtonVerified_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         ClassCalendar calendar = GetCalendarForSelectedCalendarInComboboxFromDataBase();
         if (!(calendar.Status.StatusId == ClassSqlCalendar.SelectStatusId(EnumStatus.DuringVerification)))
         {
             throw new Exception("Calendar status must be during verification");
         }
         OverlappingCalendar();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error");
     }
 }
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         ComboBoxPickDate.ItemsSource = ClassSqlCalendar.AlreadyCreatedCalendars();
         if (ComboBoxPickDate.Items.Count == 0)
         {
             return;
         }
         ComboBoxPickDate.SelectedIndex = ComboBoxPickDate.Items.Count - 1;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        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);
     }
 }
        private void copyPreviousMonth_Click(object sender, RoutedEventArgs e)
        {
            List <ClassTerm> previousDays = ClassSqlCalendar.GetListOfWorkingDayInCurrentMonth(ClassLoggedDoctor.Doctor_Id);

            foreach (ClassTerm previousDay in previousDays)
            {
                var date = previousDay.Date.AddDays(28);
                foreach (ClassCalendarDay day in days)
                {
                    if (day.DateInDateTime == date)
                    {
                        day.IsWorkingDay = true;
                    }
                }
            }

            RefreshDataGrid();
        }
        private ClassCalendarDoctor GetCalendarDoctorForSelectedCalendarDoctorInDataGridFromDataBase(int calendarId)
        {
            if (DataGridListOfCalendarDoctor.SelectedIndex == -1)
            {
                throw new Exception("Data grid row isn't selected");
            }
            //Get calendar from data base
            IEnumerable <ClassCalendarDoctor> query =
                from elem in ClassSqlCalendar.ListOfCalendarDoctor(calendarId)
                where elem.CalendarDoctorId == ((ClassCalendarDoctor)DataGridListOfCalendarDoctor.SelectedItem).CalendarDoctorId
                select elem;

            if (!query.Any())
            {
                throw new Exception("Unable to find selected calendar doctor in database");
            }
            return(query.First());
        }
        private ClassOverlappingCalendar GetCalendarForSelectedCalendarInComboboxFromDataBase()
        {
            if (DataGridListOfDoctors.SelectedIndex == -1)
            {
                throw new Exception("Day isn't selected");
            }
            //Get overlapping from data base
            IEnumerable <ClassOverlappingCalendar> query =
                from elem in ClassSqlCalendar.OverlappingTerms(calendarId)
                where elem.TermId == (((ClassOverlappingCalendar)DataGridListOfDoctors.SelectedItem)).TermId
                select elem;

            if (!query.Any())
            {
                throw new Exception("Unable to find selected day in database");
            }
            return(query.First());
        }
        private ClassCalendar GetCalendarForSelectedCalendarInComboboxFromDataBase()
        {
            if (ComboBoxPickCalendar.SelectedIndex == -1)
            {
                throw new Exception("Calendar isn't selected");
            }

            //Get calendar from data base
            IEnumerable <ClassCalendar> query =
                from elem in ClassSqlCalendar.AlreadyCreatedCalendars()
                where elem.CalendarId == ((ClassCalendar)ComboBoxPickCalendar.SelectedItem).CalendarId
                select elem;

            if (!query.Any())
            {
                throw new Exception("Unable to find selected calendar in database");
            }
            return(query.First());
        }
        private void LoadDateToGrid()
        {
            if (ComboBoxPickCalendar.SelectedIndex == -1)
            {
                CurrentMonthDataGrid.ItemsSource = null;
                return;
            }
            try
            {
                ClassCalendar calendar = GetCalendarForSelectedCalendarInComboboxFromDataBase();

                CurrentMonthDataGrid.ItemsSource = ClassSqlCalendar.ListOfCalendarDays(calendar.CalendarId);
                days = ClassSqlCalendar.ListOfCalendarDays(calendar.CalendarId);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private void ReloadData()
 {
     if (ComboBoxPickDate.SelectedIndex == -1)
     {
         DataGridListOfDoctors.ItemsSource        = null;
         DataGridListOfCalendarDoctor.ItemsSource = null;
         Status_Label.Text = "...";
         return;
     }
     try
     {
         ClassCalendar calendar = GetCalendarForSelectedCalendarInComboboxFromDataBase();
         DataGridListOfDoctors.ItemsSource        = ClassSqlCalendar.ListOfCalendarDays(calendar.CalendarId);
         DataGridListOfCalendarDoctor.ItemsSource = ClassSqlCalendar.ListOfCalendarDoctor(calendar.CalendarId);
         LoadStatusToLabel(calendar);
     }
     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);
     }
 }