//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;
        }
        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 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());
        }
 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);
     }
 }
 //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 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());
        }
        //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");
            }
        }